Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
getopt.c File Reference
#include <stdio.h>
#include <string.h>
#include "ldap-macos.h"

Go to the source code of this file.

Defines

#define index   strchr
#define rindex   strrchr
#define BADCH   (int)'?'
#define EMSG   ""

Functions

 getopt (int nargc, char **nargv, char *ostr)

Variables

int opterr = 1
int optind = 1
int optopt
char * optarg

Define Documentation

#define BADCH   (int)'?'

Definition at line 74 of file getopt.c.

#define EMSG   ""

Definition at line 75 of file getopt.c.

Definition at line 63 of file getopt.c.

#define rindex   strrchr

Definition at line 64 of file getopt.c.


Function Documentation

getopt ( int  nargc,
char **  nargv,
char *  ostr 
)

Definition at line 77 of file getopt.c.

{
       static char *place = EMSG;              /* option letter processing */
       register char *oli;                     /* option letter list index */
       char *p;

       if (!*place) {                          /* update scanning pointer */
              if (optind >= nargc || *(place = nargv[optind]) != '-') {
                     place = EMSG;
                     return(EOF);
              }
              if (place[1] && *++place == '-') {      /* found "--" */
                     ++optind;
                     place = EMSG;
                     return(EOF);
              }
       }                                       /* option letter okay? */
       if ((optopt = (int)*place++) == (int)':' ||
           !(oli = index(ostr, optopt))) {
              /*
               * if the user didn't specify '-' as an option,
               * assume it means EOF.
               */
              if (optopt == (int)'-')
                     return(EOF);
              if (!*place)
                     ++optind;
              if (opterr) {
                     if (!(p = rindex(*nargv, '/')))
                            p = *nargv;
                     else
                            ++p;
                     (void)fprintf(stderr, "%s: illegal option -- %c\n",
                         p, optopt);
              }
              return(BADCH);
       }
       if (*++oli != ':') {                    /* don't need argument */
              optarg = NULL;
              if (!*place)
                     ++optind;
       }
       else {                                  /* need an argument */
              if (*place)                     /* no white space */
                     optarg = place;
              else if (nargc <= ++optind) {   /* no arg */
                     place = EMSG;
                     if (!(p = rindex(*nargv, '/')))
                            p = *nargv;
                     else
                            ++p;
                     if (opterr)
                            (void)fprintf(stderr,
                                "%s: option requires an argument -- %c\n",
                                p, optopt);
                     return(BADCH);
              }
              else                            /* white space */
                     optarg = nargv[optind];
              place = EMSG;
              ++optind;
       }
       return(optopt);                         /* dump back option letter */
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char* optarg

Definition at line 72 of file getopt.c.

int opterr = 1

Definition at line 69 of file getopt.c.

int optind = 1

Definition at line 70 of file getopt.c.

Definition at line 70 of file getopt.c.