From: Peter Johnson Date: Mon, 21 May 2001 18:31:43 +0000 (-0000) Subject: Implemented dynamic argument types for error and warning messages. X-Git-Tag: v0.1.0~492 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7ae09b88b76f986ea798a61a76f4ffb3fafbcb0e;p=yasm Implemented dynamic argument types for error and warning messages. svn path=/trunk/yasm/; revision=19 --- diff --git a/libyasm/errwarn.c b/libyasm/errwarn.c index 78319c65..45bc6101 100644 --- a/libyasm/errwarn.c +++ b/libyasm/errwarn.c @@ -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) diff --git a/modules/parsers/nasm/bison.y.in b/modules/parsers/nasm/bison.y.in index f1c045be..2ebe4bcc 100644 --- a/modules/parsers/nasm/bison.y.in +++ b/modules/parsers/nasm/bison.y.in @@ -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); diff --git a/modules/parsers/nasm/nasm-bison.y b/modules/parsers/nasm/nasm-bison.y index 8a983ddb..f7576f1e 100644 --- a/modules/parsers/nasm/nasm-bison.y +++ b/modules/parsers/nasm/nasm-bison.y @@ -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); diff --git a/src/bison.y b/src/bison.y index 84de4e8d..f4e22f6d 100644 --- a/src/bison.y +++ b/src/bison.y @@ -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); diff --git a/src/bison.y.in b/src/bison.y.in index f1c045be..2ebe4bcc 100644 --- a/src/bison.y.in +++ b/src/bison.y.in @@ -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); diff --git a/src/errwarn.c b/src/errwarn.c index 78319c65..45bc6101 100644 --- a/src/errwarn.c +++ b/src/errwarn.c @@ -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) diff --git a/src/parsers/nasm/bison.y.in b/src/parsers/nasm/bison.y.in index f1c045be..2ebe4bcc 100644 --- a/src/parsers/nasm/bison.y.in +++ b/src/parsers/nasm/bison.y.in @@ -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); diff --git a/src/parsers/nasm/nasm-bison.y b/src/parsers/nasm/nasm-bison.y index 8a983ddb..f7576f1e 100644 --- a/src/parsers/nasm/nasm-bison.y +++ b/src/parsers/nasm/nasm-bison.y @@ -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);