# 2.11BSD#431 - /usr/src/lib/libc/stdlib/getopt.c

##### Functions

    getopt            X

##### Variables

    optarg            X
    opterr            X

##### Macros

    BADARG            X
    BADCH             X
    EMSG              X

       1: /*
       2:  * Copyright (c) 1987, 1993, 1994
       3:  *	The Regents of the University of California.  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:  * 3. All advertising materials mentioning features or use of this software
      14:  *    must display the following acknowledgement:
      15:  *	This product includes software developed by the University of
      16:  *	California, Berkeley and its contributors.
      17:  * 4. Neither the name of the University nor the names of its contributors
      18:  *    may be used to endorse or promote products derived from this software
      19:  *    without specific prior written permission.
      20:  *
      21:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
      22:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
      23:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
      24:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
      25:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
      26:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
      27:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      28:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
      29:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
      30:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
      31:  * SUCH DAMAGE.
      32:  */
      33:
      34: #if defined(LIBC_SCCS) && !defined(lint)
      35: static char sccsid[] = "@(#)getopt.c	8.2.1 (2.11BSD) 1996/1/11";
      36: #endif /* LIBC_SCCS and not lint */
      37:
      38: #include <stdio.h>
      39: #include <stdlib.h>
      40: #include <string.h>
      41:
      42: int opterr = 1,     /* if error message should be printed */
      43:     optind = 1,     /* index into parent argv vector */
      44:     optopt,         /* character checked for validity */
      45:     optreset;       /* reset getopt */
      46: char    *optarg;        /* argument associated with option */
      47:
      48: #define BADCH   (int)'?'
      49: #define BADARG  (int)':'
      50: #define EMSG    ""
      51:
      52: /*
      53:  * getopt --
      54:  *	Parse argc/argv argument vector.
      55:  */
      56: int
      57: getopt(nargc, nargv, ostr)
      58:     int nargc;
      59:     char **nargv;
      60:     char *ostr;
      61: {
      62:     extern char *__progname;
      63:     static char *place = EMSG;      /* option letter processing */
      64:     char *oli;              /* option letter list index */
      65:
      66:     if (optreset || !*place) {      /* update scanning pointer */
      67:         optreset = 0;
      68:         if (optind >= nargc || *(place = nargv[optind]) != '-') {
      69:             place = EMSG;
      70:             return (EOF);
      71:         }
      72:         if (place[1] && *++place == '-') {  /* found "--" */
      73:             ++optind;
      74:             place = EMSG;
      75:             return (EOF);
      76:         }
      77:     }                   /* option letter okay? */
      78:     if ((optopt = (int)*place++) == (int)':' ||
      79:         !(oli = strchr(ostr, optopt))) {
      80:         /*
      81: 		 * if the user didn't specify '-' as an option,
      82: 		 * assume it means EOF.
      83: 		 */
      84:         if (optopt == (int)'-')
      85:             return (EOF);
      86:         if (!*place)
      87:             ++optind;
      88:         if (opterr && *ostr != ':')
      89:             (void)fprintf(stderr,
      90:                 "%s: illegal option -- %c\n", __progname, optopt);
      91:         return (BADCH);
      92:     }
      93:     if (*++oli != ':') {            /* don't need argument */
      94:         optarg = NULL;
      95:         if (!*place)
      96:             ++optind;
      97:     }
      98:     else {                  /* need an argument */
      99:         if (*place)         /* no white space */
     100:             optarg = place;
     101:         else if (nargc <= ++optind) {   /* no arg */
     102:             place = EMSG;
     103:             if (*ostr == ':')
     104:                 return (BADARG);
     105:             if (opterr)
     106:                 (void)fprintf(stderr,
     107:                     "%s: option requires an argument -- %c\n",
     108:                     __progname, optopt);
     109:             return (BADCH);
     110:         }
     111:         else                /* white space */
     112:             optarg = nargv[optind];
     113:         place = EMSG;
     114:         ++optind;
     115:     }
     116:     return (optopt);            /* dump back option letter */
     117: }

#### Defined functions

getopt defined in line 56; used 79 times

- in /usr/include/stdlib.h line 100
- in /usr/src/bin/ar/ar.c line 96
- in /usr/src/bin/chflags/chflags.c line 37
- in /usr/src/bin/chpass/chpass.c line 86
- in /usr/src/bin/cmp.c line 52
- in /usr/src/bin/date.c line 62
- in /usr/src/bin/df.c line 77
- in /usr/src/bin/disklabel/disklabel.c line 122
- in /usr/src/bin/hostname/hostname.c line 61
- in /usr/src/bin/login/login.c line 123
- in /usr/src/bin/ls/ls.c line 92
- in /usr/src/bin/mkdir.c line 58
- in /usr/src/bin/ping/ping.c line 160
- in /usr/src/bin/rcp.c line 100
- in /usr/src/bin/stty/stty.c line 178
- in /usr/src/bin/sysctl/sysctl.c line 114
- in /usr/src/libexec/acctd/acctd.c line 64
- in /usr/src/libexec/fingerd/fingerd.c line 77
- in /usr/src/libexec/popper/pop_init.c line 60
- in /usr/src/libexec/rlogind/rlogind.c line 90
- in /usr/src/libexec/rshd/rshd.c line 76
- in /usr/src/libexec/tcpd/tcpdchk.c line 98
- in /usr/src/libexec/tcpd/tcpdmatch.c line 79
- in /usr/src/local/mtools/mcopy.c line 33
- in /usr/src/local/mtools/mformat.c line 44
- in /usr/src/local/mtools/mread.c line 59
- in /usr/src/local/mtools/mtype.c line 41
- in /usr/src/local/mtools/mwrite.c line 56
- in /usr/src/new/PORT/hexdump/hexsyntax.c line 42
- in /usr/src/new/PORT/hexdump/odsyntax.c line 44
- in /usr/src/new/pathalias/arpatxt.c line 76
- in /usr/src/new/pathalias/main.c line 65
- in /usr/src/new/pathalias/makedb.c line 26
- in /usr/src/new/vmsbackup/vmsbackup.c line 767
- in /usr/src/sbin/gt307/gt307.c line 119
- in /usr/src/sbin/mkfs/mkfs.c line 85
- in /usr/src/sbin/mkpasswd/mkpasswd.c line 66
- in /usr/src/sbin/mount/mount.c line 102
- in /usr/src/sbin/mount/mount_ufs.c line 73
- in /usr/src/sbin/newfs/newfs.c line 67
- in /usr/src/sbin/quotacheck/quotacheck.c line 125
- in /usr/src/sbin/reboot/reboot.c line 59
- in /usr/src/sbin/umount/umount.c line 76
- in /usr/src/share/zoneinfo/zdump.c line 67
- in /usr/src/share/zoneinfo/zic.c line 368
- in /usr/src/sys/autoconfig/main.c line 38
- in /usr/src/sys/pdpstand/makesimtape.c line 41
- in /usr/src/ucb/Mail/main.c line 62, 88
- in /usr/src/ucb/finger/finger.c line 62
- in /usr/src/ucb/lock/lock.c line 72
- in /usr/src/ucb/man/apropos.c line 63
- in /usr/src/ucb/man/man.c line 66
- in /usr/src/usr.bin/fstat/fstat.c line 136
- in /usr/src/usr.bin/id/id.c line 73
- in /usr/src/usr.bin/m4/main.c line 141, 160
- in /usr/src/usr.bin/mkerrlst/mkerrlst.c line 50
- in /usr/src/usr.bin/printf/printf.c line 109
- in /usr/src/usr.bin/ranlib/ranlib.c line 62
- in /usr/src/usr.bin/shar/shar.c line 81
- in /usr/src/usr.bin/uname/uname.c line 68
- in /usr/src/usr.bin/whereis/whereis.c line 63
- in /usr/src/usr.bin/xargs/xargs.c line 100
- in /usr/src/usr.bin/xinstall/xinstall.c line 88
- in /usr/src/usr.sbin/accton/accton.c line 72
- in /usr/src/usr.sbin/cron/cron.c line 267
- in /usr/src/usr.sbin/cron/crontab.c line 131
- in /usr/src/usr.sbin/dev_mkdb/dev_mkdb.c line 76
- in /usr/src/usr.sbin/edquota/edquota.c line 94
- in /usr/src/usr.sbin/inetd/inetd.c line 253
- in /usr/src/usr.sbin/ntp/ntp.c line 159
- in /usr/src/usr.sbin/ntp/ntpd.c line 191
- in /usr/src/usr.sbin/quotaon/quotaon.c line 80
- in /usr/src/usr.sbin/repquota/repquota.c line 88
- in /usr/src/usr.sbin/sa/sa.c line 291
- in /usr/src/usr.sbin/sendmail.MX/aux/mailstats.c line 41
- in /usr/src/usr.sbin/sendmail.MX/aux/mconnect.c line 66
- in /usr/src/usr.sbin/sendmail.MX/aux/praliases.c line 38

#### Defined variables

optarg defined in line 46; used 79 times

- in line 94, 100, 112
- in /usr/src/bin/chpass/chpass.c line 74, 94
- in /usr/src/bin/date.c line 65, 71
- in /usr/src/bin/disklabel/disklabel.c line 128
- in /usr/src/bin/stty/stty.c line 187-189(2)
- in /usr/src/lib/libc/stdlib/getopt.c line 94, 100, 112
- in /usr/src/libexec/fingerd/fingerd.c line 83
- in /usr/src/libexec/tcpd/tcpdchk.c line 108
- in /usr/src/libexec/tcpd/tcpdmatch.c line 86
- in /usr/src/new/pathalias/main.c line 68, 74-78(3), 88, 94-100(3)
- in /usr/src/sbin/gt307/gt307.c line 122
- in /usr/src/sbin/mkfs/mkfs.c line 90-99(4)
- in /usr/src/sbin/mount/mount.c line 116-117(2), 126-127(2)
- in /usr/src/sbin/mount/mount_ufs.c line 76
- in /usr/src/sbin/newfs/newfs.c line 75-85(4), 91-103(5)
- in /usr/src/sbin/quotacheck/quotacheck.c line 134
- in /usr/src/sbin/umount/umount.c line 90
- in /usr/src/share/zoneinfo/zdump.c line 70
- in /usr/src/share/zoneinfo/zic.c line 374, 384
- in /usr/src/sys/pdpstand/makesimtape.c line 46-49(2)
- in /usr/src/ucb/lastcomm.c line 51
- in /usr/src/usr.bin/m4/main.c line 164-172(3)
- in /usr/src/usr.bin/mkerrlst/mkerrlst.c line 55-58(2)
- in /usr/src/usr.bin/xargs/xargs.c line 104-108(2)
- in /usr/src/usr.bin/xinstall/xinstall.c line 94, 100-108(4)
- in /usr/src/usr.sbin/accton/accton.c line 77-81(2), 88, 95
- in /usr/src/usr.sbin/cron/cron.c line 272
- in /usr/src/usr.sbin/cron/crontab.c line 134, 144-150(3)
- in /usr/src/usr.sbin/edquota/edquota.c line 81, 97
- in /usr/src/usr.sbin/inetd/inetd.c line 262-266(2)
- in /usr/src/usr.sbin/sa/sa.c line 349, 361-364(2)

opterr defined in line 42; used 8 times

- in line 88, 105
- in /usr/src/bin/stty/stty.c line 176
- in /usr/src/lib/libc/stdlib/getopt.c line 88, 105
- in /usr/src/libexec/acctd/acctd.c line 63
- in /usr/src/libexec/fingerd/fingerd.c line 76
- in /usr/src/libexec/rshd/rshd.c line 75

sccsid defined in line 35; never used

#### Defined macros

BADARG defined in line 49; used 1 times

- in line 104

BADCH defined in line 48; used 2 times

- in line 91, 109

EMSG defined in line 50; used 5 times

- in line 63, 69-74(2), 102, 113

Last modified: 1996-01-12 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1604 |