[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.11

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.11    ! deraadt    27: static char rcsid[] = "$OpenBSD: arch.c,v 1.10 2004/03/08 19:02:00 deraadt 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>
1.9       david      35: #include <stdlib.h>
                     36: #include <string.h>
1.2       tholo      37: #include <unistd.h>
                     38:
1.6       millert    39: static void usage(void);
1.1       tholo      40:
1.3       niklas     41: static int machine;
                     42:
1.1       tholo      43: int
1.8       deraadt    44: main(int argc, char *argv[])
1.1       tholo      45: {
1.4       millert    46:        extern char *__progname;
1.11    ! deraadt    47:        int short_form = 0, c;
        !            48:        char *arch, *opts;
1.2       tholo      49:
                     50:        setlocale(LC_ALL, "");
                     51:
1.4       millert    52:        machine = strcmp(__progname, "machine") == 0;
1.3       niklas     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)
1.2       tholo      62:                switch (c) {
1.10      deraadt    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 */
1.2       tholo      75:                }
                     76:        if (optind != argc) {
                     77:                usage();
                     78:                /* NOTREACHED */
                     79:        }
1.3       niklas     80:        if (!short_form) {
                     81:                fputs("OpenBSD", stdout);
                     82:                fputc('.', stdout);
1.2       tholo      83:        }
                     84:        fputs(arch, stdout);
                     85:        fputc('\n', stdout);
1.1       tholo      86:        exit(0);
1.2       tholo      87: }
                     88:
                     89: static void
1.8       deraadt    90: usage(void)
1.2       tholo      91: {
1.3       niklas     92:        if (machine)
                     93:                fprintf(stderr, "usage: machine [-a]\n");
                     94:        else
                     95:                fprintf(stderr, "usage: arch [-ks]\n");
1.2       tholo      96:        exit(1);
1.1       tholo      97: }