/* Add a parameter to the current element */ void addpar(M_NOPAR) { PARAMETER *paramp, *last = NULL ; int length ; parcount++ ; pcount++ ; for (paramp = plist ; paramp ; paramp = paramp->next) { if (w_strcmp(name, paramp->paramname) == 0) warning2("Multiple definition of parameter %s for element %s", name, thisrule) ; last = paramp ; } newpar = (PARAMETER *) m_malloc(sizeof(PARAMETER), "parameter") ; if (! plist) plist = newpar ; else last->next = newpar ; *nextpar = newpar ; nextpar = &newpar->nextptr ; *nextpar = NULL ; newpar->next = NULL ; newpar->deftype = NULLDEF ; newpar->defval = M_NULLVAL ; newpar->defstring = NULL ; newpar->kwlist = M_NULLVAL ; length = w_strlen(name) + 1 ; pnamelen += length ; newpar->paramname = (M_WCHAR *) m_malloc(length, "parameter name") ; w_strcpy(newpar->paramname, name) ; newpar->ptypep = NULL ; }
/* Add a keyword to the list of possible values of a keyword parameter for the current element */ void addkeyword(M_NOPAR) { int length ; PARAMETER *par ; PTYPE *kw ; /* Check if duplicate keyword for this parameter */ for (kw = newpar->ptypep ; kw ; kw = kw->nextptr) if (w_strcmp(kw->keyword, name) == 0) { warning3("Warning: Repeated keyword %s in parameter %s of %s", name, newpar->paramname, thisrule) ; return ; } /* Check if duplicate keyword within parameters of this element */ for (par = plist ; par != newpar ; par = par->next) for (kw = par->ptypep ; kw ; kw = kw->nextptr) { if (w_strcmp(kw->keyword, name) == 0) warning4("Keyword %s used in parameters %s and %s of %s", name, par->paramname, newpar->paramname, thisrule) ; if (! kw->next) break ; } *nextptype = (PTYPE *) m_malloc(sizeof(PTYPE), "ptype") ; if (newpar->kwlist) thisptype->next = ptypelen + 1 ; else { newpar->kwlist = ptypelen + 1 ; newpar->ptypep = *nextptype ; } thisptype = *nextptype ; thisptype->next = M_NULLVAL ; thisptype->nextptr = NULL ; nextptype = &(thisptype->nextptr) ; length = w_strlen(name) + 1 ; thisptype->keyword = (M_WCHAR *) m_malloc(length, "keyword") ; w_strcpy(thisptype->keyword, name) ; kwlen += length ; ptypelen++ ; }
WPUBLIC warc_i32_t WGetOpt_parse (void * const _self, warc_i32_t argc, const char ** argv) { struct WGetOpt * const self = _self; const warc_u8_t * cp = NIL; warc_i32_t c = 0; warc_i32_t opterr = 1; /* preconditions */ CASSERT (self); assert (argc > 1); assert (argv); if (SP == 1) { if (OPTIND >= argc || argv [OPTIND][0] != '-' || argv [OPTIND][1] == '\0') { return (-1); } else if (w_strcmp ( (warc_u8_t *) argv [OPTIND], (warc_u8_t *) "--") == 0) { ++ OPTIND; return (-1); } } c = argv [OPTIND][SP]; if (c == ':' || (cp = w_index (WString_getText (FLAGS), c) ) == 0) { ERR ("illegal option -- ", c); if (argv [OPTIND][++ SP] == '\0') { ++ OPTIND; SP = 1; } return ('?'); } if (* ++ cp == ':') { if (argv [OPTIND][SP + 1] != '\0') { OPTARG = (char *) (& argv [OPTIND ++][SP+1]); } else if (++ OPTIND >= argc) { ERR ("option requires an argument -- ", c); SP = 1; return ('?'); } else OPTARG = (char *) (argv [OPTIND ++]); SP = 1; } else { if (argv [OPTIND][++ SP] == '\0') { SP = 1; ++ OPTIND; } OPTARG = 0; } return (c); }