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