]> git.gag.com Git - fw/sdcc/commitdiff
* src/SDCC.lex, src/SDCCutil.[ch], src/SDCCval:
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 10 Mar 2007 17:31:55 +0000 (17:31 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 10 Mar 2007 17:31:55 +0000 (17:31 +0000)
  fixed RFE #1624219: double backslashes in filenames;
  functions hexEscape(), octalEscape() and copyStr() moved from
  SDCCval.c to SDCCutil.c and made them glovbally available

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4677 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCC.lex
src/SDCCutil.c
src/SDCCutil.h
src/SDCCval.c

index 58fd56cdca6a774d485e0a983049ad4411fc182e..ba5dea2b5f4881d1971d1a14c732336f1e3db01d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-03-10 Borut Razem <borut.razem AT siol.net>
+
+       * src/SDCC.lex, src/SDCCutil.[ch], src/SDCCval:
+         fixed RFE #1624219: double backslashes in filenames;
+         functions hexEscape(), octalEscape() and copyStr() moved from
+         SDCCval.c to SDCCutil.c and made them glovbally available
+
 2007-03-09 Borut Razem <borut.razem AT siol.net>
 
        * src/SDCC.lex, src/SDCCast.c. src/SDCCglobl.c, src/SDCCsymt.c,
index fbabe7031115955c54d871984f7c21ab0f1348ff..7785550391c404e85d0c53e24b5ef0b4ce249652 100644 (file)
@@ -332,14 +332,18 @@ static int checkCurrFile (const char *s)
   else
     {
       const char *sb = s;
+      char *tmpFname;
 
       /* find the end of the file name */
       while (*s && *s != '"')
         ++s;
 
+      tmpFname = Safe_malloc(s - sb + 1);
+      memcpy(tmpFname, sb, s - sb);
+      tmpFname[s - sb] = '\0';
+
       lexFilename = Safe_malloc(s - sb + 1);
-      memcpy(lexFilename, sb, s - sb);
-      lexFilename[s - sb] = '\0';
+      copyStr(lexFilename, tmpFname);
     }
   filename = lexFilename;
 
index d34ad73393fa6c7ec71da509ed0db1c7e9b10936..adfcff76c6a8e09308f25ec5efaff9b6f9f6608f 100644 (file)
@@ -383,7 +383,6 @@ char *strncatz(char *dest, const char *src, size_t n)
     return dest;
 }
 
-
 /*-----------------------------------------------------------------*/
 /* getBuildNumber - return build number                            */
 /*-----------------------------------------------------------------*/
@@ -482,3 +481,160 @@ free_pragma_token(struct pragma_token_s *token)
 {
   dbuf_destroy(&token->dbuf);
 }
+
+/*! /fn char hexEscape(char **src)
+
+    /param src Pointer to 'x' from start of hex character value
+*/
+
+unsigned char
+hexEscape (const char **src)
+{
+  char *s ;
+  unsigned long value ;
+
+  (*src)++ ;    /* Skip over the 'x' */
+
+  value = strtol (*src, &s, 16);
+
+  if (s == *src)
+    {
+      // no valid hex found
+      werror(E_INVALID_HEX);
+    }
+  else
+    {
+      if (value > 255)
+        {
+          werror(W_ESC_SEQ_OOR_FOR_CHAR);
+        }
+    }
+  *src = s;
+
+  return (char) value;
+}
+
+/*------------------------------------------------------------------*/
+/* octalEscape - process an octal constant of max three digits      */
+/* return the octal value, throw a warning for illegal octal        */
+/* adjust src to point at the last proccesed char                   */
+/*------------------------------------------------------------------*/
+
+unsigned char
+octalEscape (const char **str)
+{
+  int digits;
+  unsigned value=0;
+
+  for (digits = 0; digits < 3; digits++)
+    {
+      if (**str >='0' && **str <= '7')
+        {
+          value = value*8 + (**str - '0');
+          (*str)++;
+        }
+      else
+        {
+          break;
+        }
+    }
+  if (digits)
+    {
+      if (value > 255 /* || (**str>='0' && **str<='7') */ )
+        {
+          werror (W_ESC_SEQ_OOR_FOR_CHAR);
+        }
+    }
+  return value;
+}
+
+/*!
+  /fn int copyStr (char *dest, char *src)
+
+  Copies a source string to a dest buffer interpreting escape sequences
+  and special characters
+
+  /param dest Buffer to receive the resultant string
+  /param src  Buffer containing the source string with escape sequecnes
+  /return Number of characters in output string
+
+*/
+
+int
+copyStr (char *dest, const char *src)
+{
+  char *OriginalDest = dest ;
+
+  while (*src)
+    {
+      if (*src == '\"')
+        src++;
+      else if (*src == '\\')
+        {
+          src++;
+          switch (*src)
+            {
+            case 'n':
+              *dest++ = '\n';
+              break;
+            case 't':
+              *dest++ = '\t';
+              break;
+            case 'v':
+              *dest++ = '\v';
+              break;
+            case 'b':
+              *dest++ = '\b';
+              break;
+            case 'r':
+              *dest++ = '\r';
+              break;
+            case 'f':
+              *dest++ = '\f';
+              break;
+            case 'a':
+              *dest++ = '\a';
+              break;
+
+            case '0':
+            case '1':
+            case '2':
+            case '3':
+            case '4':
+            case '5':
+            case '6':
+            case '7':
+              *dest++ = octalEscape(&src);
+              src-- ;
+              break;
+
+            case 'x':
+              *dest++ = hexEscape(&src) ;
+              src-- ;
+              break ;
+
+            case '\\':
+              *dest++ = '\\';
+              break;
+            case '\?':
+              *dest++ = '\?';
+              break;
+            case '\'':
+              *dest++ = '\'';
+              break;
+            case '\"':
+              *dest++ = '\"';
+              break;
+            default:
+              *dest++ = *src;
+            }
+          src++;
+        }
+      else
+        *dest++ = *src++;
+    }
+
+  *dest++ = '\0';
+
+  return dest - OriginalDest ;
+}
index aa29272f18f1e9fb17e57a6144d07c96f19f3d3c..6e3800b764b759724f2fc1e8e4703a4e16c05e52 100644 (file)
 /** Given an array of name, value string pairs creates a new hash
     containing all of the pairs.
 */
-hTab *populateStringHash(const char **pin);
+hTab *populateStringHash (const char **pin);
 
 /** Prints elements of the set to the file, each element on new line
 */
-void fputStrSet(FILE *fp, set *list);
+void fputStrSet (FILE *fp, set *list);
 
 /** Prepend / append given strings to each item of string set. The result is in a
     new string set.
 */
-set *appendStrSet(set *list, const char *pre, const char *post);
+set *appendStrSet (set *list, const char *pre, const char *post);
 
 /** Given a set returns a string containing all of the strings seperated
     by spaces. The returned string is on the heap.
 */
-const char *joinStrSet(set *list);
+const char *joinStrSet (set *list);
 
 /** Split the path string to the directory and file name (including extension) components.
     The directory component doesn't contain trailing directory separator.
     Returns true if the path contains the directory separator. */
-int dbuf_splitPath(const char *path, struct dbuf_s *dir, struct dbuf_s *file);
+int dbuf_splitPath (const char *path, struct dbuf_s *dir, struct dbuf_s *file);
 
 /** Split the path string to the file name (including directory) and file extension components.
     The file name component doesn't contain trailing extension separator.
     Returns true if the path contains the extension separator. */
-int dbuf_splitFile(const char *path, struct dbuf_s *file, struct dbuf_s *ext);
+int dbuf_splitFile (const char *path, struct dbuf_s *file, struct dbuf_s *ext);
 
 /** Combile directory and the file name to a path string using the DIR_SEPARATOR_CHAR.
  */
-void dbuf_makePath(struct dbuf_s *path, const char *dir, const char *file);
+void dbuf_makePath (struct dbuf_s *path, const char *dir, const char *file);
 
 /** Given a file with path information in the binary files directory,
     returns the directory component. Used for discovery of bin
@@ -88,23 +88,22 @@ bool startsWith (const char *sz, const char *key);
 */
 void chomp (char *sz);
 
-hTab *
-getRuntimeVariables(void);
+hTab *getRuntimeVariables (void);
 
 /* strncpy() with guaranteed NULL termination. */
-char *strncpyz(char *dest, const char *src, size_t n);
+char *strncpyz (char *dest, const char *src, size_t n);
 
 /* like strncat() with guaranteed NULL termination
  * The passed size should be the size of the dest buffer, not the number of 
  * bytes to copy.
  */
-char *strncatz(char *dest, const char *src, size_t n);
+char *strncatz (char *dest, const char *src, size_t n);
 
 /* return SDCC build number */
-const char *getBuildNumber(void);
+const char *getBuildNumber (void);
 
 /* snprintf, by hook or by crook. */
-size_t SDCCsnprintf(char *, size_t, const char *, ...);
+size_t SDCCsnprintf (char *, size_t, const char *, ...);
 
 # if defined(HAVE_VSNPRINTF)
 
@@ -139,9 +138,13 @@ struct pragma_token_s {
   } val;
 };
 
-void init_pragma_token(struct pragma_token_s *token);
-char *get_pragma_token(const char *s, struct pragma_token_s *token);
-const char *get_pragma_string(struct pragma_token_s *token);
-void free_pragma_token(struct pragma_token_s *token);
+void init_pragma_token (struct pragma_token_s *token);
+char *get_pragma_token (const char *s, struct pragma_token_s *token);
+const char *get_pragma_string (struct pragma_token_s *token);
+void free_pragma_token (struct pragma_token_s *token);
+
+unsigned char hexEscape (const char **src);
+unsigned char octalEscape (const char **src);
+int copyStr (char *dest, const char *src);
 
 #endif
index df67d9c6e1ddd810155307fd9efa86d2e4b994da..70b166647529b791597009e4f7f1c606e8fb47d8 100644 (file)
@@ -805,151 +805,6 @@ value *constVal (const char *s)
   return val;
 }
 
-/*! /fn char hexEscape(char **src)
-
-    /param src Pointer to 'x' from start of hex character value
-*/
-
-unsigned char hexEscape(const char **src)
-{
-  char *s ;
-  unsigned long value ;
-
-  (*src)++ ;    /* Skip over the 'x' */
-
-  value = strtol (*src, &s, 16);
-
-  if (s == *src) {
-      // no valid hex found
-      werror(E_INVALID_HEX);
-  } else {
-    if (value > 255) {
-      werror(W_ESC_SEQ_OOR_FOR_CHAR);
-    }
-  }
-  *src = s;
-
-  return (char) value;
-}
-
-/*------------------------------------------------------------------*/
-/* octalEscape - process an octal constant of max three digits      */
-/* return the octal value, throw a warning for illegal octal        */
-/* adjust src to point at the last proccesed char                   */
-/*------------------------------------------------------------------*/
-
-unsigned char octalEscape (const char **str) {
-  int digits;
-  unsigned value=0;
-
-  for (digits=0; digits<3; digits++) {
-    if (**str>='0' && **str<='7') {
-      value = value*8 + (**str-'0');
-      (*str)++;
-    } else {
-      break;
-    }
-  }
-  if (digits) {
-    if (value > 255 /* || (**str>='0' && **str<='7') */ ) {
-      werror (W_ESC_SEQ_OOR_FOR_CHAR);
-    }
-  }
-  return value;
-}
-
-/*!
-  /fn int copyStr (char *dest, char *src)
-
-  Copies a source string to a dest buffer interpreting escape sequences
-  and special characters
-
-  /param dest Buffer to receive the resultant string
-  /param src  Buffer containing the source string with escape sequecnes
-  /return Number of characters in output string
-
-*/
-
-int
-copyStr (char *dest, const char *src)
-
-{
-  char *OriginalDest = dest ;
-
-  while (*src)
-    {
-      if (*src == '\"')
-        src++;
-      else if (*src == '\\')
-        {
-          src++;
-          switch (*src)
-            {
-            case 'n':
-              *dest++ = '\n';
-              break;
-            case 't':
-              *dest++ = '\t';
-              break;
-            case 'v':
-              *dest++ = '\v';
-              break;
-            case 'b':
-              *dest++ = '\b';
-              break;
-            case 'r':
-              *dest++ = '\r';
-              break;
-            case 'f':
-              *dest++ = '\f';
-              break;
-            case 'a':
-              *dest++ = '\a';
-              break;
-
-            case '0':
-            case '1':
-            case '2':
-            case '3':
-            case '4':
-            case '5':
-            case '6':
-            case '7':
-              *dest++ = octalEscape(&src);
-              src-- ;
-              break;
-
-            case 'x':
-              *dest++ = hexEscape(&src) ;
-              src-- ;
-              break ;
-
-            case '\\':
-              *dest++ = '\\';
-              break;
-            case '\?':
-              *dest++ = '\?';
-              break;
-            case '\'':
-              *dest++ = '\'';
-              break;
-            case '\"':
-              *dest++ = '\"';
-              break;
-            default:
-              *dest++ = *src;
-            }
-          src++;
-        }
-      else
-        *dest++ = *src++;
-    }
-
-  *dest++ = '\0';
-
-  return dest - OriginalDest ;
-}
-
 /*------------------------------------------------------------------*/
 /* strVal - converts a string constant to a value       */
 /*------------------------------------------------------------------*/