]> git.gag.com Git - fw/sdcc/commitdiff
fixed the octal and hex escape sequences
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 19 May 2001 10:16:19 +0000 (10:16 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 19 May 2001 10:16:19 +0000 (10:16 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@826 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCglue.c
src/SDCCval.c
support/Util/SDCCerr.c
support/Util/SDCCerr.h

index 3a5e4e3a16eb51018eb3e8d7bc318c44333123df..733c0e6a563fe88c3d701d0e143d18f14d61f1a8 100644 (file)
@@ -400,7 +400,7 @@ printChar (FILE * ofile, char *s, int plen)
              *p = '\0';
              if (p != buf)
                tfprintf (ofile, "\t!ascii\n", buf);
-             tfprintf (ofile, "\t!db !constbyte\n", *s);
+             tfprintf (ofile, "\t!db !constbyte\n", (unsigned char)*s);
              p = buf;
            }
          else
index e70b7931b0a81203d8f84bae962653ba119517d6..8871a531f3c7df3840316397adfe8befce3bebca 100644 (file)
@@ -334,13 +334,39 @@ constVal (char *s)
 
 }
 
+/*------------------------------------------------------------------*/
+/* 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                   */
+/*------------------------------------------------------------------*/
+
+char octalEscape (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);
+    }
+    (*str)--;
+  }
+  return value;
+}
+
 /*------------------------------------------------------------------*/
 /* copyStr - copies src to dest ignoring leading & trailing \"s     */
 /*------------------------------------------------------------------*/
 void 
 copyStr (char *dest, char *src)
 {
-  unsigned int x;
   while (*src)
     {
       if (*src == '\"')
@@ -371,21 +397,35 @@ copyStr (char *dest, char *src)
            case 'a':
              *dest++ = '\a';
              break;
+
            case '0':
-             /* embedded octal or hex constant */
-             if (*(src + 1) == 'x' ||
-                 *(src + 1) == 'X')
-               {
-                 x = strtol (src, &src, 16);
-                 *dest++ = x;
-               }
-             else
-               {
-                 /* must be octal */
-                 x = strtol (src, &src, 8);
-                 *dest++ = x;
+           case '1':
+           case '2':
+           case '3':
+           case '4':
+           case '5':
+           case '6':
+           case '7':
+             *dest++ = octalEscape(&src);
+             break;
+
+           case 'x': {
+             char *s=++src;
+             unsigned long value=strtol (src, &src, 16);
+
+             if (s==src) {
+               // no valid hex found
+               werror(E_INVALID_HEX);
+             } else {
+               if (value>255) {
+                 werror(W_ESC_SEQ_OOR_FOR_CHAR);
+               } else {
+                 *dest++ = value;
                }
+               src--;
+             }
              break;
+           }
 
            case '\\':
              *dest++ = '\\';
index 59aef76aca0ce1261cfdba1909a6fd92c6423316..ed29f22c4defce2316eb380c2b50956eca9d9907 100644 (file)
@@ -186,7 +186,9 @@ struct  {
 { WARNING,"warning *** Model '%s' not supported for %s, ignored.\n"},
 { WARNING,"warning *** Both banked and nonbanked attributes used.  nonbanked wins.\n"},
 { WARNING,"warning *** Both banked and static used.  static wins.\n"},
-{ WARNING,"warning *** converting integer type to generic pointer: assuming XDATA\n"}
+{ WARNING,"warning *** converting integer type to generic pointer: assuming XDATA\n"},
+{ WARNING,"warning *** escape sequence out of range for char.\n"},
+{ ERROR  ,"error   *** \\x used with no following hex digits.\n"}
 };
 /*
 -------------------------------------------------------------------------------
index ee134615e3460f1a2d62609491a543b0d9372a4f..42090f57974e7598428297af8a06be102115866a 100644 (file)
@@ -152,6 +152,8 @@ SDCCERR - SDCC Standard error handler
 #define         W_BANKED_WITH_NONBANKED 134    /* banked and nonbanked attributes mixed */
 #define         W_BANKED_WITH_STATIC 135       /* banked and static mixed */
 #define  W_INT_TO_GEN_PTR_CAST 136     /* Converting integer type to generic pointer. */
+#define  W_ESC_SEQ_OOR_FOR_CHAR 137     /* Escape sequence of of range for char */
+#define  E_INVALID_HEX 138              /* \x used with no following hex digits */
 
 /** Describes the maximum error level that will be logged.  Any level
     includes all of the levels listed after it.