void parse_session_arguments (int *argcp, char *argv[]) { int argc = *argcp; int arg_index = 1; /* Gobble up and act on arguments that we understand. Move other arguments around so that the caller can still read the remaining ones. */ while (arg_index < argc) { char *arg = argv[arg_index++]; if ((strcmp (arg, "-f") == 0) || (strcmp (arg, "--filename") == 0)) { --arg_index; remove_arg (arg_index, argv); --argc; set_session_database_location (argv[arg_index]); remove_arg (arg_index, argv); --argc; } } *argcp = argc; }
/* * Main parse routine. Scans for '-', then scan for arguments and * delete from the argv[] array if so. */ BOOLEAN parse_args(int *argc, char *argv[], BOOLEAN case_sensitive) { int pos = 0; BOOLEAN retval = TRUE; use_case = case_sensitive; while (++pos < *argc) { if ((argv[pos][0] == ARG_SEPSWITCH) || (argv[pos][0] == ARG_SEPFALSE) || (argv[pos][0] == ARG_SEPTRUE)) { if (argv[pos][1] == '!') { // skip the silence arg } else { int argmode; int index = 1; BOOLEAN done = FALSE; do { /* Scan the present arg */ if (pos < *argc - 1) argmode = scan_args(argv[pos], index, argv[pos + 1]); else argmode = scan_args(argv[pos], index, 0); switch (argmode) { case ARG_NEXTCHAR: /* If it was a char, go to the next one */ if (!argv[pos][++index]) done = TRUE; break; case ARG_NEXTNOCAT: /* Otherwise if it was a nocat, remove the extra arg */ remove_arg(pos, argc, argv); /* Fall through to NEXTARG */ case ARG_NEXTARG: /* Just a next arg, go do it */ done = TRUE; break; case ARG_NOMATCH: /* No such arg, spit an error */ #ifndef CPREPROCESSOR #ifdef XXXXX switch( parseParam(argv[pos][index] != ARG_SEPFALSE, &argv[pos][index + 1])) { case 0: #endif #endif fprintf(stderr, "Invalid Arg: %s\n", argv[pos]); retval = FALSE; done = TRUE; #ifndef CPREPROCESSORXX #ifdef XXXXX break ; case 1: if (!argv[pos][++index]) done = TRUE; break ; case 2: done = TRUE; break; } #endif #endif break; case ARG_NOARG: /* Missing the arg for a CONCAT type, spit the error */ fprintf(stderr, "Missing string for Arg %s\n", argv[pos]); done = TRUE; retval = FALSE; break; }; } while (!done); } /* We'll always get rid of the present arg * And back up one */ remove_arg(pos--, argc, argv); } } return (retval); }