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 *
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
16 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
17 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include <sys/param.h>
27
28 #include <err.h>
29 #include <locale.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <unistd.h>
34
35 __RCSID("$MirOS: src/usr.bin/arch/arch.c,v 1.3 2007/07/05 23:09:35 tg Exp $");
36
37 static void usage(void);
38
39 static int machine;
40
41 int
main(int argc,char * argv[])42 main(int argc, char *argv[])
43 {
44 extern char *__progname;
45 int short_form = 0, c;
46 char *arch, *opts;
47
48 #ifndef __MirBSD__
49 setlocale(LC_ALL, "");
50 #endif
51
52 machine = strcmp(__progname, "machine") == 0;
53 if (machine) {
54 arch = MACHINE;
55 opts = "a";
56 short_form++;
57 } else {
58 arch = MACHINE_ARCH;
59 opts = "ks";
60 }
61 while ((c = getopt(argc, argv, opts)) != -1)
62 switch (c) {
63 case 'a':
64 arch = MACHINE_ARCH;
65 break;
66 case 'k':
67 arch = MACHINE;
68 break;
69 case 's':
70 short_form++;
71 break;
72 default:
73 usage();
74 /* NOTREACHED */
75 }
76 if (optind != argc) {
77 usage();
78 /* NOTREACHED */
79 }
80 if (!short_form)
81 #if defined(MirBSD)
82 fputs("MirBSD.", stdout);
83 #else
84 #error "fix here for MirInterix & co."
85 #endif
86 fputs(arch, stdout);
87 fputc('\n', stdout);
88 exit(0);
89 }
90
91 static void
usage(void)92 usage(void)
93 {
94 if (machine)
95 fprintf(stderr, "usage: machine [-a]\n");
96 else
97 fprintf(stderr, "usage: arch [-ks]\n");
98 exit(1);
99 }
100