From: borutr Date: Sun, 17 Dec 2006 21:20:11 +0000 (+0000) Subject: * src/SDCCmain.c: (setParseWithComma) substituted brain damaged strtok X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=3f62134fe007ab1e88bb127fd3e92d00ce6fff5b;p=fw%2Fsdcc * src/SDCCmain.c: (setParseWithComma) substituted brain damaged strtok git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4516 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index f22c517f..5030b36b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ unified table driven pragma handling, pragma argument type checking * support/Util/dbuf.c: (dbuf_set_size) allow to set size equal to the current one - version 1.1.3 + * src/SDCCmain.c: (setParseWithComma) substituted brain damaged strtok 2006-12-13 Raphael Neider diff --git a/src/SDCC.lex b/src/SDCC.lex index 41989a85..23e85bf6 100644 --- a/src/SDCC.lex +++ b/src/SDCC.lex @@ -705,14 +705,14 @@ static int doPragma(int id, const char *name, const char *cp) case P_CALLEE_SAVES: /* append to the functions already listed in callee-saves */ - setParseWithComma(&options.calleeSavesSet, (char *)cp); + setParseWithComma(&options.calleeSavesSet, cp); err = -1; break; case P_EXCLUDE: { deleteSet(&options.excludeRegsSet); - setParseWithComma(&options.excludeRegsSet, (char *)cp); + setParseWithComma(&options.excludeRegsSet, cp); err = -1; } break; @@ -1010,6 +1010,7 @@ static int process_pragma(const char *s) if (0 != strcmp("#pragma", get_pragma_string(&token))) { /* Oops, womething went totally wrong - internal error */ + wassertl(0, "pragma parser internal error"); } /* skip spaces */ diff --git a/src/SDCCglobl.h b/src/SDCCglobl.h index 486cd850..044fe654 100644 --- a/src/SDCCglobl.h +++ b/src/SDCCglobl.h @@ -305,7 +305,7 @@ extern set *libFilesSet; extern set *libPathsSet; extern set *libDirsSet; /* list of lib search directories */ -void setParseWithComma (set **, char *); +void setParseWithComma (set **, const char *); /** Creates a temporary file a'la tmpfile which avoids the bugs in cygwin wrt c:\tmp. diff --git a/src/SDCCmain.c b/src/SDCCmain.c index ac938565..a04aa579 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -524,22 +524,35 @@ printUsage (void) /* setParseWithComma - separates string with comma to a set */ /*-----------------------------------------------------------------*/ void -setParseWithComma (set **dest, char *src) +setParseWithComma (set **dest, const char *src) { - char *p; - int length; + const char *p, *end; + struct dbuf_s dbuf; /* skip the initial white spaces */ while (isspace((unsigned char)*src)) - src++; + ++src; /* skip the trailing white spaces */ - length = strlen(src); - while (length && isspace((unsigned char)src[length-1])) - src[--length] = '\0'; + end = &src[strlen(src) - 1]; + while (end >= src && isspace((unsigned char)*end)) + --end; + ++end; + + dbuf_init(&dbuf, 16); + + p = src; + while (src < end) + { + while (p < end && ',' != *p) + ++p; + dbuf_append(&dbuf, src, p - src); + addSet(dest, Safe_strdup(dbuf_c_str(&dbuf))); + dbuf_set_size(&dbuf, 0); + src = ++p; + } - for (p = strtok(src, ","); p != NULL; p = strtok(NULL, ",")) - addSet(dest, Safe_strdup(p)); + dbuf_destroy(&dbuf); } /*-----------------------------------------------------------------*/ diff --git a/src/SDCCutil.c b/src/SDCCutil.c index 4fd50580..d4898f53 100644 --- a/src/SDCCutil.c +++ b/src/SDCCutil.c @@ -342,14 +342,14 @@ get_pragma_token(const char *s, struct pragma_token_s *token) dbuf_set_size(&token->dbuf, 0); /* skip leading spaces */ - while (*s != '\n' && isspace(*s)) + while ('\n' != *s && isspace(*s)) ++s; if ('\0' == *s || '\n' == *s) { token->type = TOKEN_EOL; } - else if (isdigit(*s)) + else { char *end; @@ -360,21 +360,21 @@ get_pragma_token(const char *s, struct pragma_token_s *token) token->val.int_val = val; token->type = TOKEN_INT; dbuf_append(&token->dbuf, s, end - s); + s = end; } - s = end; - } - else - { - while ('\0' != *s && !isspace(*s)) + else { - dbuf_append(&token->dbuf, s, 1); - ++s; - } + while ('\0' != *s && !isspace(*s)) + { + dbuf_append(&token->dbuf, s, 1); + ++s; + } - token->type = TOKEN_STR; + token->type = TOKEN_STR; + } } - return (char *)s; + return (char *)s; } const char *