]> granicus.if.org Git - yasm/commitdiff
Implemented dynamic argument types for error and warning messages.
authorPeter Johnson <peter@tortall.net>
Mon, 21 May 2001 18:31:43 +0000 (18:31 -0000)
committerPeter Johnson <peter@tortall.net>
Mon, 21 May 2001 18:31:43 +0000 (18:31 -0000)
svn path=/trunk/yasm/; revision=19

libyasm/errwarn.c
modules/parsers/nasm/bison.y.in
modules/parsers/nasm/nasm-bison.y
src/bison.y
src/bison.y.in
src/errwarn.c
src/parsers/nasm/bison.y.in
src/parsers/nasm/nasm-bison.y

index 78319c65a08298382a3d1f92cec499099369cecb..45bc61010aa0cfb913534bbb28786a6615ca4057 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: errwarn.c,v 1.1 2001/05/20 08:28:57 peter Exp $
+/* $Id: errwarn.c,v 1.2 2001/05/21 18:31:43 peter Exp $
  * Error and warning reporting and related functions.
  *
  *  Copyright (C) 2001  Peter Johnson
@@ -82,15 +82,39 @@ void Fatal(fatal_num num)
     exit(EXIT_FAILURE);
 }
 
+/* replace %1, %2, etc in src with %c, %s, etc. in argtypes. */
+/* currently limits maximum number of args to 9 (%1-%9). */
 static char *process_argtypes(char *src, char *argtypes)
 {
     char *dest;
+    char *argtype[9];
+    int at_num;
+    char *destp, *srcp, *argtypep;
 
     if(argtypes) {
        dest = malloc(strlen(src) + strlen(argtypes));
        if(!dest)
            Fatal(FATAL_NOMEM);
-       /* TODO: Implement */
+       /* split argtypes by % */
+       at_num = 0;
+       while((argtypes = strchr(argtypes, '%')) && at_num < 9)
+           argtype[at_num++] = ++argtypes;
+       /* search through src for %, copying as we go */
+       destp = dest;
+       srcp = src;
+       while(*srcp != '\0') {
+           *(destp++) = *srcp;
+           if(*(srcp++) == '%') {
+               if(isdigit(*srcp)) {
+                   /* %1, %2, etc */
+                   argtypep = argtype[*srcp-'1'];
+                   while((*argtypep != '%') && (*argtypep != '\0'))
+                       *(destp++) = *(argtypep++);
+               } else
+                   *(destp++) = *srcp;
+               srcp++;
+           }
+       }
     } else {
        dest = strdup(src);
        if(!dest)
index f1c045beb417730ee4b18a7e0dcf26c1a45e1e7b..2ebe4bcc17a634bd7383621f43bf6203dc712c64 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: bison.y.in,v 1.3 2001/05/20 08:35:18 peter Exp $
+/* $Id: bison.y.in,v 1.4 2001/05/21 18:31:42 peter Exp $
  * Main bison parser
  *
  *  Copyright (C) 2001  Peter Johnson
@@ -101,8 +101,7 @@ directive: '[' DIRECTIVE_NAME DIRECTIVE_VAL ']' {
        printf("Directive: Name='%s' Value='%s'\n", $2, $3);
     }
     | '[' DIRECTIVE_NAME DIRECTIVE_VAL error {
-       /*Error(ERR_MISSING, "%c", ']');*/
-       fprintf(stderr, "missing ']'\n");
+       Error(ERR_MISSING, "%c", ']');
     }
     | '[' DIRECTIVE_NAME error {
        Error(ERR_MISSING_ARG, (char *)NULL, $2);
index 8a983ddb6f1477e72966d9f1354710fc75b2abc2..f7576f1e2a399cf294c5eb0102ff6df1f7ccd9ab 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: nasm-bison.y,v 1.3 2001/05/20 08:35:18 peter Exp $
+/* $Id: nasm-bison.y,v 1.4 2001/05/21 18:31:42 peter Exp $
  * Main bison parser
  *
  *  Copyright (C) 2001  Peter Johnson
@@ -101,8 +101,7 @@ directive: '[' DIRECTIVE_NAME DIRECTIVE_VAL ']' {
        printf("Directive: Name='%s' Value='%s'\n", $2, $3);
     }
     | '[' DIRECTIVE_NAME DIRECTIVE_VAL error {
-       /*Error(ERR_MISSING, "%c", ']');*/
-       fprintf(stderr, "missing ']'\n");
+       Error(ERR_MISSING, "%c", ']');
     }
     | '[' DIRECTIVE_NAME error {
        Error(ERR_MISSING_ARG, (char *)NULL, $2);
index 84de4e8d841624160c0d296ab310f45f6c22a721..f4e22f6d143fed439a5eb3595eab6a1a30042ffc 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: bison.y,v 1.3 2001/05/20 08:35:18 peter Exp $
+/* $Id: bison.y,v 1.4 2001/05/21 18:31:42 peter Exp $
  * Main bison parser
  *
  *  Copyright (C) 2001  Peter Johnson
@@ -101,8 +101,7 @@ directive: '[' DIRECTIVE_NAME DIRECTIVE_VAL ']' {
        printf("Directive: Name='%s' Value='%s'\n", $2, $3);
     }
     | '[' DIRECTIVE_NAME DIRECTIVE_VAL error {
-       /*Error(ERR_MISSING, "%c", ']');*/
-       fprintf(stderr, "missing ']'\n");
+       Error(ERR_MISSING, "%c", ']');
     }
     | '[' DIRECTIVE_NAME error {
        Error(ERR_MISSING_ARG, (char *)NULL, $2);
index f1c045beb417730ee4b18a7e0dcf26c1a45e1e7b..2ebe4bcc17a634bd7383621f43bf6203dc712c64 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: bison.y.in,v 1.3 2001/05/20 08:35:18 peter Exp $
+/* $Id: bison.y.in,v 1.4 2001/05/21 18:31:42 peter Exp $
  * Main bison parser
  *
  *  Copyright (C) 2001  Peter Johnson
@@ -101,8 +101,7 @@ directive: '[' DIRECTIVE_NAME DIRECTIVE_VAL ']' {
        printf("Directive: Name='%s' Value='%s'\n", $2, $3);
     }
     | '[' DIRECTIVE_NAME DIRECTIVE_VAL error {
-       /*Error(ERR_MISSING, "%c", ']');*/
-       fprintf(stderr, "missing ']'\n");
+       Error(ERR_MISSING, "%c", ']');
     }
     | '[' DIRECTIVE_NAME error {
        Error(ERR_MISSING_ARG, (char *)NULL, $2);
index 78319c65a08298382a3d1f92cec499099369cecb..45bc61010aa0cfb913534bbb28786a6615ca4057 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: errwarn.c,v 1.1 2001/05/20 08:28:57 peter Exp $
+/* $Id: errwarn.c,v 1.2 2001/05/21 18:31:43 peter Exp $
  * Error and warning reporting and related functions.
  *
  *  Copyright (C) 2001  Peter Johnson
@@ -82,15 +82,39 @@ void Fatal(fatal_num num)
     exit(EXIT_FAILURE);
 }
 
+/* replace %1, %2, etc in src with %c, %s, etc. in argtypes. */
+/* currently limits maximum number of args to 9 (%1-%9). */
 static char *process_argtypes(char *src, char *argtypes)
 {
     char *dest;
+    char *argtype[9];
+    int at_num;
+    char *destp, *srcp, *argtypep;
 
     if(argtypes) {
        dest = malloc(strlen(src) + strlen(argtypes));
        if(!dest)
            Fatal(FATAL_NOMEM);
-       /* TODO: Implement */
+       /* split argtypes by % */
+       at_num = 0;
+       while((argtypes = strchr(argtypes, '%')) && at_num < 9)
+           argtype[at_num++] = ++argtypes;
+       /* search through src for %, copying as we go */
+       destp = dest;
+       srcp = src;
+       while(*srcp != '\0') {
+           *(destp++) = *srcp;
+           if(*(srcp++) == '%') {
+               if(isdigit(*srcp)) {
+                   /* %1, %2, etc */
+                   argtypep = argtype[*srcp-'1'];
+                   while((*argtypep != '%') && (*argtypep != '\0'))
+                       *(destp++) = *(argtypep++);
+               } else
+                   *(destp++) = *srcp;
+               srcp++;
+           }
+       }
     } else {
        dest = strdup(src);
        if(!dest)
index f1c045beb417730ee4b18a7e0dcf26c1a45e1e7b..2ebe4bcc17a634bd7383621f43bf6203dc712c64 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: bison.y.in,v 1.3 2001/05/20 08:35:18 peter Exp $
+/* $Id: bison.y.in,v 1.4 2001/05/21 18:31:42 peter Exp $
  * Main bison parser
  *
  *  Copyright (C) 2001  Peter Johnson
@@ -101,8 +101,7 @@ directive: '[' DIRECTIVE_NAME DIRECTIVE_VAL ']' {
        printf("Directive: Name='%s' Value='%s'\n", $2, $3);
     }
     | '[' DIRECTIVE_NAME DIRECTIVE_VAL error {
-       /*Error(ERR_MISSING, "%c", ']');*/
-       fprintf(stderr, "missing ']'\n");
+       Error(ERR_MISSING, "%c", ']');
     }
     | '[' DIRECTIVE_NAME error {
        Error(ERR_MISSING_ARG, (char *)NULL, $2);
index 8a983ddb6f1477e72966d9f1354710fc75b2abc2..f7576f1e2a399cf294c5eb0102ff6df1f7ccd9ab 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: nasm-bison.y,v 1.3 2001/05/20 08:35:18 peter Exp $
+/* $Id: nasm-bison.y,v 1.4 2001/05/21 18:31:42 peter Exp $
  * Main bison parser
  *
  *  Copyright (C) 2001  Peter Johnson
@@ -101,8 +101,7 @@ directive: '[' DIRECTIVE_NAME DIRECTIVE_VAL ']' {
        printf("Directive: Name='%s' Value='%s'\n", $2, $3);
     }
     | '[' DIRECTIVE_NAME DIRECTIVE_VAL error {
-       /*Error(ERR_MISSING, "%c", ']');*/
-       fprintf(stderr, "missing ']'\n");
+       Error(ERR_MISSING, "%c", ']');
     }
     | '[' DIRECTIVE_NAME error {
        Error(ERR_MISSING_ARG, (char *)NULL, $2);