/** * Process all the options from our current position onward. (This allows * interspersed options and arguments for the few non-standard programs that * require it.) Thus, do not rewind option indexes because some programs * choose to re-invoke after a non-option. */ LOCAL tSuccess doRegularOpts(tOptions* pOpts) { for (;;) { tOptState optState = OPTSTATE_INITIALIZER(DEFINED); switch (nextOption(pOpts, &optState)) { case FAILURE: goto failed_option; case PROBLEM: return SUCCESS; /* no more args */ case SUCCESS: break; } /* * IF this is an immediate action option, * THEN skip it (unless we are supposed to do it a second time). */ if (! DO_NORMALLY(optState.flags)) { if (! DO_SECOND_TIME(optState.flags)) continue; optState.pOD->optOccCt--; /* don't count this repetition */ } if (! SUCCESSFUL(handle_opt(pOpts, &optState))) break; } failed_option:; if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE); return FAILURE; }
bool TCPOptions::doesContain(TCPOptions::Kind::Val argKind) { uint32_t optionTypeIdx = 0;// Used to verify that we're not in infinite loop // we'll run over the whole list of TLVs and check each relative to the time stamp // option kind value. do { Kind::Val theCurrentOptionKind; uint8_t theOptionLength; getCurrentOption(theCurrentOptionKind, theOptionLength); optionTypeIdx++; if( theCurrentOptionKind == argKind ) { return true; } } while( (nextOption() == true) && (optionTypeIdx < MaxOptionsInPacket)); if(optionTypeIdx >= MaxOptionsInPacket) { ourCounters.itsPossibleEndlessLoop++; } // none of the TLV was of type TimeStamp return false; }
/** * scan the command line for immediate action options. * This is only called the first time through. */ LOCAL tSuccess doImmediateOpts(tOptions* pOpts) { pOpts->curOptIdx = 1; /* start by skipping program name */ pOpts->pzCurOpt = NULL; /* * Examine all the options from the start. We process any options that * are marked for immediate processing. */ for (;;) { tOptState optState = OPTSTATE_INITIALIZER(PRESET); switch (nextOption(pOpts, &optState)) { case FAILURE: goto failed_option; case PROBLEM: return SUCCESS; /* no more args */ case SUCCESS: break; } /* * IF this is an immediate-attribute option, then do it. */ if (! DO_IMMEDIATELY(optState.flags)) continue; if (! SUCCESSFUL(handle_opt(pOpts, &optState))) break; } failed_option:; if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE); return FAILURE; }
static myOption_t *findOption(myOption_t *o, unsigned char shortArg) { while(o) { if (o->shortArg[0] == shortArg) return o; o = nextOption(o); } return o; }
static myOption_t *myOptionFree(myOption_t *o) { myOption_t *r; if(!o) return NULL; r = nextOption(o); if(o->longArg)free(o->longArg); if(o->help)free(o->help); free(o); return r; }
static MyOption* myOptionFree(MyOption* o) { MyOption* r; if(!o) return NULL; r = nextOption(o); if(o->longArg)free(o->longArg); if(o->help)free(o->help); free(o); return r; }
static void loadOptions() { int i; char * line; size_t zarySize; char * val; FILE * file = fopen(DEFAULT_OPTIONS_FILENAME, "r"); if (file == NULL) die("Unable to read default options.", 1); line = mallocZStr(); while (fgets(line, 257, file)) { val = nextOption(line); zarySize = (size_t) atoi(val); *valAry = mallocZAry(zarySize); *valAry[0] = val; for (i = 1; i < zarySize; ++i) { strcpy(*valAry[i], nextOption(line)); } ++(*valAry); } fclose(file); free(line); }
void printArgs() { myOption_t *o = myargs; char s[4096]; unsigned char *shortArg; printf("\n" " Arguments are: \n"); sprintf(s," --%%-%ds",longest); while(o) { if(o->shortArg[0]<0xFF) shortArg = o->shortArg; else shortArg = (unsigned char *) "---"; printf(s,o->longArg); printf(" -%c arg=%1d type=%c %s\n",shortArg[0],o->argFlag,o->type,o->help); o = nextOption(o); } printf("\n\n"); return; }
static MyOption* lastOption(MyOption* o) { if ( ! o) return o; while(nextOption(o)) o = nextOption(o); return o; }
void processArgs(int argc, char** argv) { MyOption* o; int n=0; int i; struct option* opts; char* sArgs; int c; if ( ! myargs) return; o = myargs; while(o) {n++,o=nextOption(o);} o = myargs; sArgs= (char*)comdCalloc(2*(n+2),sizeof(char)); opts = (struct option*)comdCalloc(n,sizeof(struct option)); for (i=0; i<n; i++) { opts[i].name = o->longArg; opts[i].has_arg = o->argFlag; opts[i].flag = 0; opts[i].val = o->shortArg[0]; strcat(sArgs,(char*) o->shortArg); if(o->argFlag) strcat(sArgs,":"); o = nextOption(o); } while(1) { int option_index = 0; c = getopt_long (argc, argv, sArgs, opts, &option_index); if ( c == -1) break; o = findOption(myargs,c); if ( ! o ) { fprintf(screenOut,"\n\n" " invalid switch : -%c in getopt()\n" "\n\n", c); break; } if(! o->argFlag) { int* i = (int*)o->ptr; *i = 1; } else { switch(o->type) { case 'i': sscanf(optarg,"%d",(int*)o->ptr); break; case 'f': sscanf(optarg,"%f",(float*)o->ptr); break; case 'd': sscanf(optarg,"%lf",(double*)o->ptr); break; case 's': strncpy((char*)o->ptr,(char*)optarg,o->sz); ((char*)o->ptr)[o->sz-1] = '\0'; break; case 'c': sscanf(optarg,"%c",(char*)o->ptr); break; default: fprintf(screenOut,"\n\n" " invalid type : %c in getopt()\n" " valid values are 'e', 'z'. 'i','d','f','s', and 'c'\n" "\n\n", c); } } } free(opts); free(sArgs); return; }
////////////////////////////////////////////////////// // Member "text" is used to communicate with the above processXxx methods; // the resulting string is returned to caller in parameter "fixed_data", // not in "text" ("text" not used elsewhere). // (Member "command" and the "pos/len" members -- same for them.) ////////////////////////////////////////////////////// InputStmt::Option InputStmt::fix_string(const char * in_data, char * fixed_data, size_t data_maxlen) { command = new char[data_maxlen + 1]; command_pos = 0; text_pos = 0; text = fixed_data; text_maxlen = strlen(in_data); #pragma nowarn(1506) // warning elimination str_pad(text, data_maxlen, ' '); #pragma warn(1506) // warning elimination #pragma nowarn(1506) // warning elimination str_cpy_all(text, in_data, strlen(in_data)); #pragma warn(1506) // warning elimination char c; Option option; cout << ">>" << in_data << endl; cout << ".."; #pragma nowarn(1506) // warning elimination if (cin.peek() != '\n') cin.get(command, data_maxlen, '\n'); else command[0] = '\0'; #pragma warn(1506) // warning elimination if (cin.eof()) { // Abort the "FC", not the whole SQLCI session CLEAR_STDIN_EOF; option = ABORT_O; } else { // consume the eol ('\n') cin.get(c); option = EMPTY_O; } while ((option != DONE_O) && (option != ABORT_O)) { option = nextOption(); switch (option) { case INSERT_O: processInsert(); break; case REPLACE_O: processReplace(); break; case EXPLICIT_REPLACE_O: processReplace(); text_pos++; break; case DELETE_O: processDelete(); break; case ADVANCE_O: text_pos += 1; break; case END_O: text_pos += 2; break; case ABORT_O: strncpy(text, in_data, strlen(in_data)); break; case DONE_O: text[text_maxlen] = 0; break; case AGAIN_O: text[text_maxlen] = 0; cout << ">>" << text << endl; text[text_maxlen] = ' '; cout << ".."; #pragma nowarn(1506) // warning elimination if (cin.peek() != '\n') cin.get(command, data_maxlen, '\n'); else command[0] = '\0'; #pragma warn(1506) // warning elimination if (cin.eof()) { CLEAR_STDIN_EOF; option = ABORT_O; } else { // consume the eol ('\n') cin.get(c); command_pos = 0; text_pos = 0; } break; default: break; } } delete [] command; command = 0; // delete text; // text points to fixed_data, memory owned by caller! text = 0; return option; } // fix_string()
static myOption_t *lastOption(myOption_t *o) { if ( ! o) return o; while(nextOption(o)) o = nextOption(o); return o; }