static int parseLine (char *line, char **keyPtr, char **valuePtr) { char *sp = line; #define L_MAXLINELEN_4ENV (8*MAXLINELEN) static char key[L_MAXLINELEN_4ENV]; static char value[L_MAXLINELEN_4ENV]; char *word; char *cp; if (strlen (sp) >= L_MAXLINELEN_4ENV - 1) { lserrno = LSE_BAD_ENV; return -1; } *keyPtr = key; *valuePtr = value; word = getNextWord_ (&sp); strcpy (key, word); cp = strchr (key, '='); if (cp == NULL) { lserrno = LSE_CONF_SYNTAX; return -1; } *cp = '\0'; sp = strchr (line, '='); if (sp[1] == ' ' || sp[1] == '\t') { lserrno = LSE_CONF_SYNTAX; return -1; } if (sp[1] == '\0') { value[0] = '\0'; return 0; } sp++; word = getNextValueQ_ (&sp, '\"', '\"'); if (!word) return -1; strcpy (value, word); word = getNextValueQ_ (&sp, '\"', '\"'); if (word != NULL || lserrno != LSE_NO_ERR) { lserrno = LSE_CONF_SYNTAX; return -1; } return 0; }
char * getNextValue(char **line) { return (getNextValueQ_(line, '(', ')')); }
static int parseLine2(char *line, int *embedArgc, char ***embedArgv, int option) { #define INCREASE 40 static int parsing = TRUE; static char **argBuf = NULL, *key; static int bufSize = 0; char *sp, *sQuote, *dQuote, quoteMark; if (argBuf == NULL) { if ((argBuf = (char **) malloc(INCREASE * sizeof(char *))) == NULL) { fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,803 , "Unable to allocate memory for options"))); /* catgets 803 */ return -1; } bufSize = INCREASE; *embedArgc = 1; *embedArgv = argBuf; if (option & EMBED_BSUB) { argBuf[0] = "bsub"; key = "BSUB"; } else if (option & EMBED_RESTART) { argBuf[0] = "brestart"; key = "BRESTART"; } else if (option & EMBED_QSUB) { argBuf[0] = "qsub"; key = "QSUB"; } else { fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,804 , "Invalid option"))); /* catgets 804 */ return -1; } argBuf[1] = NULL; } if (!parsing && !emptyCmd) return 0; SKIPSPACE(line); if (*line == '\0') return 0; if (*line != '#') { emptyCmd = FALSE; return 0; } if (!parsing) return 0; ++line; SKIPSPACE(line); if (strncmp (line, key, strlen(key)) == 0) { line += strlen(key); SKIPSPACE(line); if (*line != '-') { parsing = FALSE; return 0; } while (TRUE) { quoteMark = '"'; if ((sQuote = strchr(line, '\'')) != NULL) if ((dQuote = strchr(line, '"')) == NULL || sQuote < dQuote) quoteMark = '\''; if ((sp = getNextValueQ_(&line, quoteMark, quoteMark)) == NULL) return 0; if (*sp == '#') return 0; if (*embedArgc + 2 > bufSize) { char **tmp; bufSize += INCREASE; if ((tmp = (char **) realloc(argBuf, bufSize * sizeof(char *))) == NULL) { fprintf(stderr, _i18n_msg_get(ls_catd, NL_SETN, 803, "Unable to allocate memory for options")); return -1; } argBuf = tmp; } argBuf[*embedArgc] = putstr_(sp); (*embedArgc)++; argBuf[*embedArgc] = NULL; } } return 0; }