Annotation of src/usr.bin/arch/arch.c, Revision 1.16
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: *
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:
1.13 deraadt 26: #include <sys/param.h> /* MACHINE MACHINE_ARCH */
1.4 millert 27:
28: #include <locale.h>
1.2 tholo 29: #include <stdio.h>
1.9 david 30: #include <stdlib.h>
31: #include <string.h>
1.2 tholo 32: #include <unistd.h>
33:
1.16 ! tedu 34: static void __dead usage(void);
1.1 tholo 35:
1.3 niklas 36: static int machine;
37:
1.1 tholo 38: int
1.8 deraadt 39: main(int argc, char *argv[])
1.1 tholo 40: {
1.4 millert 41: extern char *__progname;
1.11 deraadt 42: int short_form = 0, c;
43: char *arch, *opts;
1.2 tholo 44:
45: setlocale(LC_ALL, "");
46:
1.4 millert 47: machine = strcmp(__progname, "machine") == 0;
1.3 niklas 48: if (machine) {
49: arch = MACHINE;
50: opts = "a";
1.14 deraadt 51: short_form = 1;
1.3 niklas 52: } else {
53: arch = MACHINE_ARCH;
54: opts = "ks";
55: }
1.16 ! tedu 56: while ((c = getopt(argc, argv, opts)) != -1) {
1.2 tholo 57: switch (c) {
1.10 deraadt 58: case 'a':
59: arch = MACHINE_ARCH;
60: break;
61: case 'k':
62: arch = MACHINE;
63: break;
64: case 's':
1.14 deraadt 65: short_form = 1;
1.10 deraadt 66: break;
67: default:
68: usage();
1.2 tholo 69: }
1.16 ! tedu 70: }
! 71: if (optind != argc)
1.2 tholo 72: usage();
1.16 ! tedu 73:
! 74: printf("%s%s\n", short_form ? "" : "OpenBSD.", arch);
! 75: return (0);
1.2 tholo 76: }
77:
1.16 ! tedu 78: static void __dead
1.8 deraadt 79: usage(void)
1.2 tholo 80: {
1.3 niklas 81: if (machine)
82: fprintf(stderr, "usage: machine [-a]\n");
83: else
84: fprintf(stderr, "usage: arch [-ks]\n");
1.2 tholo 85: exit(1);
1.1 tholo 86: }