Annotation of src/usr.bin/arch/arch.c, Revision 1.4
1.1 tholo 1: /*
2: * Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms, with or without
6: * modification, are permitted provided that the following conditions
7: * are met:
8: * 1. Redistributions of source code must retain the above copyright
9: * notice, this list of conditions and the following disclaimer.
10: * 2. Redistributions in binary form must reproduce the above copyright
11: * notice, this list of conditions and the following disclaimer in the
12: * documentation and/or other materials provided with the distribution.
13: * 3. All advertising materials mentioning features or use of this software
14: * must display the following acknowledgement:
15: * This product includes software developed by SigmaSoft, Th. Lockert.
16: * 4. The name of the author may not be used to endorse or promote products
17: * derived from this software without specific prior written permission.
18: *
19: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22: * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29: */
30:
31: #ifndef lint
1.4 ! millert 32: static char rcsid[] = "$OpenBSD: arch.c,v 1.3 1999/08/19 22:17:38 niklas Exp $";
1.1 tholo 33: #endif /* not lint */
34:
1.4 ! millert 35: #include <sys/param.h>
! 36:
! 37: #include <err.h>
! 38: #include <locale.h>
1.2 tholo 39: #include <stdio.h>
40: #include <unistd.h>
41:
42: static void usage __P((void));
1.1 tholo 43:
1.3 niklas 44: static int machine;
45:
1.1 tholo 46: int
47: main(argc, argv)
48: int argc;
49: char *argv[];
50: {
1.2 tholo 51: struct utsname uts;
52: char *arch;
1.3 niklas 53: char *opts;
1.2 tholo 54: int c;
1.3 niklas 55: int short_form = 0;
1.4 ! millert 56: extern char *__progname;
1.2 tholo 57:
58: setlocale(LC_ALL, "");
59:
1.4 ! millert 60: machine = strcmp(__progname, "machine") == 0;
1.3 niklas 61: if (machine) {
62: arch = MACHINE;
63: opts = "a";
64: short_form++;
65: } else {
66: arch = MACHINE_ARCH;
67: opts = "ks";
68: }
69: while ((c = getopt(argc, argv, opts)) != -1)
1.2 tholo 70: switch (c) {
1.3 niklas 71: case 'a':
72: arch = MACHINE_ARCH;
73: break;
1.2 tholo 74: case 'k':
75: arch = MACHINE;
76: break;
1.3 niklas 77: case 's':
78: short_form++;
79: break;
1.2 tholo 80: default:
81: usage();
1.4 ! millert 82: /* NOTREACHED */
1.2 tholo 83: }
84: if (optind != argc) {
85: usage();
86: /* NOTREACHED */
87: }
1.3 niklas 88: if (!short_form) {
89: fputs("OpenBSD", stdout);
90: fputc('.', stdout);
1.2 tholo 91: }
92: fputs(arch, stdout);
93: fputc('\n', stdout);
1.1 tholo 94: exit(0);
1.2 tholo 95: }
96:
97: static void
98: usage()
99: {
1.3 niklas 100: if (machine)
101: fprintf(stderr, "usage: machine [-a]\n");
102: else
103: fprintf(stderr, "usage: arch [-ks]\n");
1.2 tholo 104: exit(1);
1.1 tholo 105: }