xref: /openbsd-src/usr.bin/arch/arch.c (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
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
32 static char rcsid[] = "$OpenBSD: arch.c,v 1.5 1999/08/21 18:02:29 espie Exp $";
33 #endif /* not lint */
34 
35 #include <sys/param.h>
36 
37 #include <err.h>
38 #include <locale.h>
39 #include <stdio.h>
40 #include <unistd.h>
41 
42 static void usage __P((void));
43 
44 static int machine;
45 
46 int
47 main(argc, argv)
48 	int argc;
49 	char *argv[];
50 {
51 	char *arch;
52 	char *opts;
53 	int c;
54 	int short_form = 0;
55 	extern char *__progname;
56 
57 	setlocale(LC_ALL, "");
58 
59 	machine = strcmp(__progname, "machine") == 0;
60 	if (machine) {
61 		arch = MACHINE;
62 		opts = "a";
63 		short_form++;
64 	} else {
65 		arch = MACHINE_ARCH;
66 		opts = "ks";
67 	}
68 	while ((c = getopt(argc, argv, opts)) != -1)
69 		switch (c) {
70 			case 'a':
71 				arch = MACHINE_ARCH;
72 				break;
73 			case 'k':
74 				arch = MACHINE;
75 				break;
76 			case 's':
77 				short_form++;
78 				break;
79 			default:
80 				usage();
81 				/* NOTREACHED */
82 		}
83 	if (optind != argc) {
84 		usage();
85 		/* NOTREACHED */
86 	}
87 	if (!short_form) {
88 		fputs("OpenBSD", stdout);
89 		fputc('.', stdout);
90 	}
91 	fputs(arch, stdout);
92 	fputc('\n', stdout);
93 	exit(0);
94 }
95 
96 static void
97 usage()
98 {
99 	if (machine)
100 		fprintf(stderr, "usage: machine [-a]\n");
101 	else
102 		fprintf(stderr, "usage: arch [-ks]\n");
103 	exit(1);
104 }
105