00001 /* 00002 * See the dyninst/COPYRIGHT file for copyright information. 00003 * 00004 * We provide the Paradyn Tools (below described as "Paradyn") 00005 * on an AS IS basis, and do not warrant its validity or performance. 00006 * We reserve the right to update, modify, or discontinue this 00007 * software at any time. We shall have no obligation to supply such 00008 * updates or modifications or any other form of support to you. 00009 * 00010 * By your use of Paradyn, you understand and agree that we (or any 00011 * other person or entity with proprietary rights in Paradyn) are 00012 * under no obligation to provide either maintenance services, 00013 * update services, notices of latent defects, or correction of 00014 * defects for Paradyn. 00015 * 00016 * This library is free software; you can redistribute it and/or 00017 * modify it under the terms of the GNU Lesser General Public 00018 * License as published by the Free Software Foundation; either 00019 * version 2.1 of the License, or (at your option) any later version. 00020 * 00021 * This library is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00024 * Lesser General Public License for more details. 00025 * 00026 * You should have received a copy of the GNU Lesser General Public 00027 * License along with this library; if not, write to the Free Software 00028 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00029 */ 00030 00031 // Contains definitions for functions which NT does not give you 00032 // The argument given is returned here 00033 00034 #include <stdio.h> 00035 #include "common/h/headers.h" 00036 00037 char *optarg; 00038 int P_getopt(int argc, char *argv[], const char *optstring) 00039 { 00040 int i; 00041 char arg_found = (char) 0; 00042 static int lastArgSeen = 0; 00043 if (lastArgSeen >= argc) return EOF; 00044 for (i = lastArgSeen; i < argc; i++) { 00045 unsigned int opt_index = 0; 00046 char *nextArg = argv[i]; 00047 if (nextArg[0] != '-') continue; 00048 for (opt_index = 0; opt_index < P_strlen(optstring); opt_index++) 00049 if (optstring[opt_index] == nextArg[1]) { 00050 arg_found = optstring[opt_index]; 00051 // We may have an argument value 00052 if ((opt_index < strlen(optstring)-1) // overflow bad 00053 && (optstring[opt_index+1] == ':')) { 00054 // Argument. Either the last part of the string, or the 00055 // next item in the argv set 00056 if (strlen(nextArg) > 2) { // Last part of the argument 00057 optarg = (char *)(nextArg + 2); 00058 } 00059 else 00060 if (i < argc - 1) { 00061 optarg = argv[i + 1]; 00062 } 00063 else { 00064 optarg = (char *)0; 00065 } 00066 } // argument found 00067 break; 00068 } 00069 if (opt_index == strlen(optstring)) // Nothing found 00070 break; 00071 if (arg_found) 00072 break; 00073 } 00074 lastArgSeen = i+1; 00075 if (!arg_found) 00076 return EOF; 00077 return arg_found; 00078 }
1.6.1