Header And Logo

PostgreSQL
| The world's most advanced open source database.

Defines | Functions | Variables

getopt.c File Reference

#include "c.h"
Include dependency graph for getopt.c:

Go to the source code of this file.

Defines

#define BADCH   (int)'?'
#define BADARG   (int)':'
#define EMSG   ""

Functions

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

Variables

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

Define Documentation

#define BADARG   (int)':'

Definition at line 61 of file getopt.c.

#define BADCH   (int)'?'

Definition at line 60 of file getopt.c.

#define EMSG   ""

Definition at line 62 of file getopt.c.


Function Documentation

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

Definition at line 77 of file getopt.c.

References optarg, opterr, optind, and optopt.

Referenced by AuxiliaryProcessMain(), get_opts(), main(), PostmasterMain(), and process_postgres_switches().

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

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


Variable Documentation

char* optarg
int opterr = 1

Definition at line 48 of file getopt.c.

Referenced by getopt(), getopt_long(), PostmasterMain(), and process_postgres_switches().

int optind = 1
int optopt

Definition at line 49 of file getopt.c.

Referenced by getopt(), getopt_long(), and main().