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

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