/*************************************************************************** Routine to access the command line argument and interpret them: Return ARG_OK (0) is case of successful parsing, error code else... ***************************************************************************/ bool GAGetArgs(int argc, char **argv, char *CtrlStr, ...) { int i, ParamCount = 0; bool Error = false; int *Parameters[MAX_PARAM]; /* Save here parameter addresses. */ char *Option, CtrlStrCopy[CTRL_STR_MAX_LEN]; va_list ap; strncpy(CtrlStrCopy, CtrlStr, sizeof(CtrlStrCopy)-1); va_start(ap, CtrlStr); for (i = 1; i <= MAX_PARAM; i++) Parameters[i - 1] = va_arg(ap, int *); va_end(ap); --argc; argv++; /* Skip the program name (first in argv/c list). */ while (argc >= 0) { if (!GAOptionExists(argc, argv)) break; /* The loop. */ argc--; Option = *argv++; if ((Error = GAUpdateParameters(Parameters, &ParamCount, Option, CtrlStrCopy, CtrlStr, &argc, &argv)) != false) return Error; } /* Check for results and update trail of command line: */ return GATestAllSatis(CtrlStrCopy, CtrlStr, &argc, &argv, Parameters, &ParamCount) != ARG_OK; }
//#ifdef HAVE_STDARG_H int GAGetArgs(int argc, char **argv, char *CtrlStr, ...) { int i, Error = FALSE, ParamCount = 0; int *Parameters[MAX_PARAM]; /* Save here parameter addresses. */ char *Option, CtrlStrCopy[CTRL_STR_MAX_LEN]; va_list ap; strcpy(CtrlStrCopy, CtrlStr); va_start(ap, CtrlStr); for (i = 1; i <= MAX_PARAM; i++) Parameters[i - 1] = va_arg(ap, int *); va_end(ap); #if 0//#elif defined(HAVE_VARARGS_H) int GAGetArgs(va_alist) va_dcl { va_list ap; int argc, i, Error = FALSE, ParamCount = 0; int *Parameters[MAX_PARAM]; /* Save here parameter addresses. */ char **argv, *CtrlStr, *Option, CtrlStrCopy[CTRL_STR_MAX_LEN]; va_start(ap); argc = va_arg(ap, int); argv = va_arg(ap, char **); CtrlStr = va_arg(ap, char *); va_end(ap); strcpy(CtrlStrCopy, CtrlStr); /* Using base address of parameters we access other parameters addr: * Note that me (for sure!) samples data beyond the current function * frame, but we accesson these set address only by demand. */ for (i = 1; i <= MAX_PARAM; i++) Parameters[i - 1] = va_arg(ap, int *); #endif /* HAVE_STDARG_H */ --argc; argv++; /* Skip the program name (first in argv/c list). */ while (argc >= 0) { if (!GAOptionExists(argc, argv)) break; /* The loop. */ argc--; Option = *argv++; if ((Error = GAUpdateParameters(Parameters, &ParamCount, Option, CtrlStrCopy, CtrlStr, &argc, &argv)) != FALSE) return Error; } /* Check for results and update trail of command line: */ return GATestAllSatis(CtrlStrCopy, CtrlStr, &argc, &argv, Parameters, &ParamCount); } /*************************************************************************** * Routine to search for unsatisfied flags - simply scan the list for !- * sequence. Before this scan, this routine updates the rest of the command * line into the last two parameters if it is requested by the CtrlStr * (last item in CtrlStr is NOT an option). * Return ARG_OK if all satisfied, CMD_ERR_AllSatis error else. **************************************************************************/ static int GATestAllSatis(char *CtrlStrCopy, char *CtrlStr, int *argc, char ***argv, int *Parameters[MAX_PARAM], int *ParamCount) { int i; static char *LocalToken = NULL; /* If LocalToken is not initialized - do it now. Note that this string * should be writable as well so we can not assign it directly. */ if (LocalToken == NULL) { LocalToken = (char *)malloc(3); strcpy(LocalToken, "-?"); } /* Check if last item is an option. If not then copy rest of command * line into it as 1. NumOfprm, 2. pointer to block of pointers. */ for (i = strlen(CtrlStr) - 1; i > 0 && !ISSPACE(CtrlStr[i]); i--) ; if (!ISCTRLCHAR(CtrlStr[i + 2])) { GASetParamCount(CtrlStr, i, ParamCount); /* Point in correct param. */ *Parameters[(*ParamCount)++] = *argc; GAByteCopy((char *)Parameters[(*ParamCount)++], (char *)argv, sizeof(char *)); } i = 0; while (++i < (int)strlen(CtrlStrCopy)) if ((CtrlStrCopy[i] == '-') && (CtrlStrCopy[i - 1] == '!')) { GAErrorToken = LocalToken; LocalToken[1] = CtrlStrCopy[i - 2]; /* Set the correct flag. */ return CMD_ERR_AllSatis; } return ARG_OK; }