00001 /* 00002 * Copyright (c) 1987, 1993, 1994 00003 * The Regents of the University of California. All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. All advertising materials mentioning features or use of this software 00014 * must display the following acknowledgement: 00015 * This product includes software developed by the University of 00016 * California, Berkeley and its contributors. 00017 * 4. Neither the name of the University nor the names of its contributors 00018 * may be used to endorse or promote products derived from this software 00019 * without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00022 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00024 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00025 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00026 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00027 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00028 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00029 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00030 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00031 * SUCH DAMAGE. 00032 */ 00033 00034 // getopt() is not present in Win32 00035 00036 #ifdef WIN32 00037 #include <stdio.h> 00038 #include <string.h> // for getc() 00039 00040 int opterr = 1, /* if error message should be printed */ 00041 optind = 1, /* index into parent argv vector */ 00042 optopt, /* character checked for validity */ 00043 optreset; /* reset getopt */ 00044 char *optarg; /* argument associated with option */ 00045 00046 #define BADCH (int)'?' 00047 #define BADARG (int)':' 00048 #define EMSG "" 00049 00050 #ifdef WIN32 00051 char *__progname = "rpcapd"; 00052 #endif 00053 00054 /* 00055 * getopt -- 00056 * Parse argc/argv argument vector. 00057 */ 00058 int 00059 getopt(nargc, nargv, ostr) 00060 int nargc; 00061 char * const *nargv; 00062 const char *ostr; 00063 { 00064 // WIN32 extern char *__progname; 00065 static char *place = EMSG; /* option letter processing */ 00066 char *oli; /* option letter list index */ 00067 int ret; 00068 00069 if (optreset || !*place) { /* update scanning pointer */ 00070 optreset = 0; 00071 if (optind >= nargc || *(place = nargv[optind]) != '-') { 00072 place = EMSG; 00073 return (-1); 00074 } 00075 if (place[1] && *++place == '-') { /* found "--" */ 00076 ++optind; 00077 place = EMSG; 00078 return (-1); 00079 } 00080 } /* option letter okay? */ 00081 if ((optopt = (int)*place++) == (int)':' || 00082 !(oli = strchr(ostr, optopt))) { 00083 /* 00084 * if the user didn't specify '-' as an option, 00085 * assume it means -1. 00086 */ 00087 if (optopt == (int)'-') 00088 return (-1); 00089 if (!*place) 00090 ++optind; 00091 if (opterr && *ostr != ':' && optopt != BADCH) 00092 (void)fprintf(stderr, 00093 "%s: illegal option -- %c\n", __progname, optopt); 00094 return (BADCH); 00095 } 00096 if (*++oli != ':') { /* don't need argument */ 00097 optarg = NULL; 00098 if (!*place) 00099 ++optind; 00100 } 00101 else { /* need an argument */ 00102 if (*place) /* no white space */ 00103 optarg = place; 00104 else if (nargc <= ++optind) { /* no arg */ 00105 place = EMSG; 00106 if (*ostr == ':') 00107 ret = BADARG; 00108 else 00109 ret = BADCH; 00110 if (opterr) 00111 (void)fprintf(stderr, 00112 "%s: option requires an argument -- %c\n", 00113 __progname, optopt); 00114 return (ret); 00115 } 00116 else /* white space */ 00117 optarg = nargv[optind]; 00118 place = EMSG; 00119 ++optind; 00120 } 00121 return (optopt); /* dump back option letter */ 00122 } 00123 00124 #endif 00125
documentation. Copyright (c) 2002-2003 Politecnico di Torino. All rights reserved.