]> git.gag.com Git - fw/sdcc/commitdiff
* src/SDCCmain.c: (setParseWithComma) substituted brain damaged strtok
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 17 Dec 2006 21:20:11 +0000 (21:20 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 17 Dec 2006 21:20:11 +0000 (21:20 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4516 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCC.lex
src/SDCCglobl.h
src/SDCCmain.c
src/SDCCutil.c

index f22c517f5dff8f8087cafcefe2a4cfb7ff46b91b..5030b36b266752eef6b19aa373f600ab8b9fe205 100644 (file)
--- 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 <rneider AT web.de>
 
index 41989a8545d052bf7ce0f6cc505acddc4b2e5e30..23e85bf6f76eff34ba05f399e965caa81dbd7727 100644 (file)
@@ -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 */
index 486cd8500a0fc0f50177c788d4363c20ff458db7..044fe65445f1b94df3f5e6260e702332df464257 100644 (file)
@@ -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.
index ac9385656809bc1652edb44083c02b23afe3bf5f..a04aa579de21549c9ab99546e09bd3c08bc955ca 100644 (file)
@@ -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);
 }
 
 /*-----------------------------------------------------------------*/
index 4fd505801e7b6e0c8fdee224fc870638c1488951..d4898f530e8025868af07e5cdb579b9f91412b76 100644 (file)
@@ -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 *