getopt.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright (c) 1996 by Sun Microsystems, Inc.
* All Rights Reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* getopt - get option letter from argv
*
* This is a version of the public domain getopt() implementation by
* Henry Spencer, changed for 4.3BSD compatibility (in addition to System V).
* It allows rescanning of an option list by setting optind to 0 before
* calling, which is why we use it even if the system has its own (in fact,
* this one has a unique name so as not to conflict with the system's).
* Thanks to Dennis Ferguson for the appropriate modifications.
*
* This file is in the Public Domain.
*/
/*LINTLIBRARY*/
#include <stdio.h>
#include "ntp_stdlib.h"
#ifdef lint
#endif /* lint */
char *ntp_optarg; /* Global argument pointer. */
int ntp_optind = 0; /* Global argv index. */
int ntp_optopt; /* for compatibility, option character checked */
static const char *prog = "amnesia";
static int badopt P((char *, int));
/*
* Print message about a bad option.
*/
static int
char *mess;
int ch;
{
if (ntp_opterr) {
}
return ('?');
}
int
int argc;
char *argv[];
const char *optstring;
{
register char c;
register const char *place;
ntp_optarg = NULL;
if (ntp_optind == 0) {
ntp_optind++;
}
if (ntp_optind >= argc
return (EOF);
}
ntp_optind++;
return (EOF);
}
}
c = *scan++;
ntp_optopt = c & 0377;
if (*place == c)
break;
return (badopt(": unknown option -", c));
}
place++;
if (*place == ':') {
if (*scan != '\0') {
ntp_optarg = scan;
} else if (ntp_optind >= argc) {
return (badopt(": option requires argument -", c));
} else {
}
}
return (c & 0377);
}