[BACK]Return to arch.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / arch

Annotation of src/usr.bin/arch/arch.c, Revision 1.7

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