/* parseUsage() */ static int parseUsage(char *usageReq, struct resVal *resVal, struct lsInfo *lsInfo) { int i; int m; int entry; float value; char *token; link_t *link; linkiter_t iter; struct _rusage_ *r; char *s; int *rusage_bit_map; float *val; char *usageReq2; char *s2; if ((i = strlen(usageReq)) == 0) return PARSE_OK; for (m = 0; m < i; m++) if (usageReq[m] != ' ') break; if (m == i) return PARSE_OK; s2 = usageReq2 = strip_spaces(usageReq); resVal->rl = make_link(); link = get_rusage_entries(usageReq2); i = 0; traverse_init(link, &iter); while ((s = traverse_link(&iter))) { /* Allocate for each element of the link */ rusage_bit_map = calloc(GET_INTNUM(lsInfo->nRes), sizeof(int)); val = calloc(lsInfo->nRes, sizeof(float)); resVal->genClass = 0; while ((token = getNextToken(&s)) != NULL) { if (token[0] == '-') token++; entry = getKeyEntry(token); if (entry > 0) { if (entry != KEY_DURATION && entry != KEY_DECAY) goto pryc; if (s[0] == '=') { int returnValue; if (entry == KEY_DURATION) returnValue = getTimeVal(&s, &value); else returnValue = getVal(&s, &value); if (returnValue < 0 || value < 0.0) return PARSE_BAD_VAL; if (entry == KEY_DURATION) resVal->duration = value; else resVal->decay = value; continue; } } entry = getResEntry(token); if (entry < 0) goto pryc; if (!(lsInfo->resTable[entry].flags & RESF_DYNAMIC) && (lsInfo->resTable[entry].valueType != LS_NUMERIC)) { if (s[0] == '=') { if (getVal(&s, &value) < 0 || value < 0.0) goto pryc; } continue; } if (entry < MAXSRES) resVal->genClass |= 1 << entry; SET_BIT(entry, rusage_bit_map); if (s[0] == '=') { if (getVal(&s, &value) < 0 || value < 0.0) goto pryc; val[entry] = value; } } /* Save the current rusage block */ r = calloc(1, sizeof(struct _rusage_)); r->bitmap = rusage_bit_map; r->val = val; enqueue_link(resVal->rl, r); if (i == 0) { /* The entry 0 is both in the link and * in the resVal. The default values * were allocated in setDefaults() */ _free_(resVal->rusage_bit_map); _free_(resVal->val); /* Copy the values as later we free them separately */ resVal->rusage_bit_map = calloc(GET_INTNUM(lsInfo->nRes), sizeof(int)); memcpy(resVal->rusage_bit_map, rusage_bit_map, GET_INTNUM(lsInfo->nRes) * sizeof(int)); resVal->val = calloc(lsInfo->nRes, sizeof(float)); memcpy(resVal->val, r->val, lsInfo->nRes * sizeof(float)); } ++i; } /* while (s = traverse_link()) */ resVal->options |= PR_RUSAGE; while ((s = pop_link(link))) _free_(s); fin_link(link); _free_(s2); return PARSE_OK; pryc: _free_(rusage_bit_map); _free_(val); while ((s = pop_link(link))) _free_(s); fin_link(link); while ((r = pop_link(resVal->rl))) { _free_(r->bitmap); _free_(r->val); _free_(r); } fin_link(resVal->rl); resVal->rl = NULL; _free_(s2); return PARSE_BAD_NAME; }
static int parseUsage (char *usageReq, struct resVal *resVal, struct lsInfo *lsInfo) { int i, m, entry; float value; char *token; if ((i=strlen(usageReq)) == 0) return PARSE_OK; for(m=0; m<i; m++) if (usageReq[m] != ' ') break; if (m == i) return PARSE_OK; resVal->genClass = 0; while ((token = getNextToken(&usageReq)) != NULL) { if (token[0] == '-') token++; entry = getKeyEntry (token); if (entry > 0) { if (entry != KEY_DURATION && entry != KEY_DECAY) return(PARSE_BAD_NAME); if (usageReq[0] == '=') { int returnValue; if (entry == KEY_DURATION) returnValue = getTimeVal(&usageReq, &value); else returnValue = getVal(&usageReq, &value); if (returnValue < 0 || value < 0.0) return PARSE_BAD_VAL; if (entry == KEY_DURATION) resVal->duration = value; else resVal->decay = value; continue; } } entry = getResEntry (token); if (entry < 0) return(PARSE_BAD_NAME); if (!(lsInfo->resTable[entry].flags & RESF_DYNAMIC) && (lsInfo->resTable[entry].valueType != LS_NUMERIC)) { if (usageReq[0] == '=') { if (getVal(&usageReq, &value) < 0 || value < 0.0) return PARSE_BAD_VAL; } continue; } if (entry < MAXSRES) resVal->genClass |= 1 << entry; SET_BIT(entry, resVal->rusgBitMaps); if (usageReq[0] == '=') { if (getVal(&usageReq, &value) < 0 || value < 0.0) return PARSE_BAD_VAL; resVal->val[entry] = value; } } resVal->options |= PR_RUSAGE; return(PARSE_OK); }