From 45df22d110fb8cbbbb5c5b29b79c91eb7ef0c3e5 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 30 Aug 2001 03:45:26 +0000 Subject: [PATCH] Convert to using gettext instead of the ugly errwarn constant strings. NOTE: gettextize now needs to be run before building. svn path=/trunk/yasm/; revision=153 --- .cvsignore | 2 + Makefile.am | 2 +- acconfig.h | 9 +- acinclude.m4 | 18 +++ configure.ac | 5 +- configure.in | 5 +- libyasm/bytecode.c | 34 +++--- libyasm/errwarn.c | 182 +++++++---------------------- libyasm/errwarn.h | 49 ++------ libyasm/symrec.c | 10 +- modules/objfmts/dbg/Makefile.am | 4 +- modules/parsers/nasm/Makefile.am | 4 +- modules/parsers/nasm/bison.y.in | 20 ++-- modules/parsers/nasm/gen_instr.pl | 4 +- modules/parsers/nasm/nasm-bison.y | 20 ++-- modules/parsers/nasm/token.l.in | 24 ++-- modules/preprocs/raw/Makefile.am | 4 +- modules/preprocs/raw/preproc.c | 11 +- modules/preprocs/raw/raw-preproc.c | 11 +- po/.cvsignore | 7 ++ po/ChangeLog | 0 po/POTFILES.in | 11 ++ src/Makefile.am | 5 +- src/bytecode.c | 34 +++--- src/errwarn.c | 182 +++++++---------------------- src/errwarn.h | 49 ++------ src/objfmts/dbg/Makefile.am | 4 +- src/parsers/nasm/Makefile.am | 4 +- src/parsers/nasm/bison.y.in | 20 ++-- src/parsers/nasm/gen_instr.pl | 4 +- src/parsers/nasm/nasm-bison.y | 20 ++-- src/parsers/nasm/token.l.in | 24 ++-- src/preprocs/raw/Makefile.am | 4 +- src/preprocs/raw/preproc.c | 11 +- src/preprocs/raw/raw-preproc.c | 11 +- src/symrec.c | 10 +- 36 files changed, 341 insertions(+), 477 deletions(-) create mode 100644 acinclude.m4 create mode 100644 po/.cvsignore create mode 100644 po/ChangeLog create mode 100644 po/POTFILES.in diff --git a/.cvsignore b/.cvsignore index cb425235..b1015989 100644 --- a/.cvsignore +++ b/.cvsignore @@ -4,3 +4,5 @@ Makefile config.* stamp-h* aclocal.m4 +intl +ABOUT-NLS diff --git a/Makefile.am b/Makefile.am index 59deea70..e63c1c66 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,2 +1,2 @@ -SUBDIRS = src +SUBDIRS = intl src po EXTRA_DIST = config/install-sh config/missing config/mkinstalldirs diff --git a/acconfig.h b/acconfig.h index a2e1ad77..5e930667 100644 --- a/acconfig.h +++ b/acconfig.h @@ -1,4 +1,4 @@ -/* $Id: acconfig.h,v 1.1 2001/08/19 04:25:18 peter Exp $ */ +/* $Id: acconfig.h,v 1.2 2001/08/30 03:45:16 peter Exp $ */ #ifndef YASM_CONFIG_H #define YASM_CONFIG_H @@ -11,6 +11,13 @@ /* Workaround for bad implementations. */ #undef HAVE_BOGUS_SYS_QUEUE_H +/* gettext tests */ +#undef ENABLE_NLS +#undef HAVE_CATGETS +#undef HAVE_GETTEXT +#undef HAVE_LC_MESSAGES +#undef HAVE_STPCPY + @BOTTOM@ #endif /* YASM_CONFIG_H */ diff --git a/acinclude.m4 b/acinclude.m4 new file mode 100644 index 00000000..21ccf800 --- /dev/null +++ b/acinclude.m4 @@ -0,0 +1,18 @@ +# $Id: acinclude.m4,v 1.1 2001/08/30 03:45:16 peter Exp $ + +# This test replaces the one in autoconf. +# Currently this macro should have the same name as the autoconf macro +# because gettext's gettext.m4 (distributed in the automake package) +# still uses it. Otherwise, the use in gettext.m4 makes autoheader +# give these diagnostics: +# configure.in:##: AC_TRY_COMPILE was called before AC_ISC_POSIX + +undefine([AC_ISC_POSIX]) + +AC_DEFUN([AC_ISC_POSIX], + [ + dnl This test replaces the obsolescent AC_ISC_POSIX kludge. + AC_CHECK_LIB(cposix, strerror, [LIBS="$LIBS -lcposix"]) + ] +) + diff --git a/configure.ac b/configure.ac index 763f343f..8d77c738 100644 --- a/configure.ac +++ b/configure.ac @@ -17,6 +17,9 @@ AC_PATH_PROGS(PERL, perl perl5.004 perl5.003 perl5.002 perl5.001 perl5) AM_PROG_CC_STDC +ALL_LINGUAS="" +AM_GNU_GETTEXT + AM_PROG_LEX AC_PROG_YACC AC_PROG_INSTALL @@ -49,4 +52,4 @@ case "$host" in ;; esac -AC_OUTPUT(Makefile src/Makefile src/parsers/Makefile src/parsers/nasm/Makefile src/preprocs/Makefile src/preprocs/raw/Makefile src/outfmts/Makefile src/outfmts/dbg/Makefile) +AC_OUTPUT(Makefile intl/Makefile po/Makefile.in src/Makefile src/parsers/Makefile src/parsers/nasm/Makefile src/preprocs/Makefile src/preprocs/raw/Makefile src/outfmts/Makefile src/outfmts/dbg/Makefile) diff --git a/configure.in b/configure.in index 763f343f..8d77c738 100644 --- a/configure.in +++ b/configure.in @@ -17,6 +17,9 @@ AC_PATH_PROGS(PERL, perl perl5.004 perl5.003 perl5.002 perl5.001 perl5) AM_PROG_CC_STDC +ALL_LINGUAS="" +AM_GNU_GETTEXT + AM_PROG_LEX AC_PROG_YACC AC_PROG_INSTALL @@ -49,4 +52,4 @@ case "$host" in ;; esac -AC_OUTPUT(Makefile src/Makefile src/parsers/Makefile src/parsers/nasm/Makefile src/preprocs/Makefile src/preprocs/raw/Makefile src/outfmts/Makefile src/outfmts/dbg/Makefile) +AC_OUTPUT(Makefile intl/Makefile po/Makefile.in src/Makefile src/parsers/Makefile src/parsers/nasm/Makefile src/preprocs/Makefile src/preprocs/raw/Makefile src/outfmts/Makefile src/outfmts/dbg/Makefile) diff --git a/libyasm/bytecode.c b/libyasm/bytecode.c index 347a45eb..2765a251 100644 --- a/libyasm/bytecode.c +++ b/libyasm/bytecode.c @@ -1,4 +1,4 @@ -/* $Id: bytecode.c,v 1.19 2001/08/19 07:46:52 peter Exp $ +/* $Id: bytecode.c,v 1.20 2001/08/30 03:45:26 peter Exp $ * Bytecode utility functions * * Copyright (C) 2001 Peter Johnson @@ -32,13 +32,16 @@ # include #endif +#include +#define _(String) gettext(String) + #include "globals.h" #include "errwarn.h" #include "expr.h" #include "bytecode.h" -RCSID("$Id: bytecode.c,v 1.19 2001/08/19 07:46:52 peter Exp $"); +RCSID("$Id: bytecode.c,v 1.20 2001/08/30 03:45:26 peter Exp $"); /* Static structures for when NULL is passed to conversion functions. */ /* for Convert*ToEA() */ @@ -95,7 +98,7 @@ ConvertImmToEA(effaddr *ptr, immval *im_ptr, unsigned char im_len) ptr->disp = im_ptr->val; if (im_ptr->len > im_len) - Warning(WARN_VALUE_EXCEEDS_BOUNDS, (char *)NULL, "word"); + Warning(_("%s value exceeds bounds"), "word"); ptr->len = im_len; ptr->segment = 0; ptr->valid_modrm = 0; @@ -147,7 +150,7 @@ SetEASegment(effaddr *ptr, unsigned char segment) return; if (ptr->segment != 0) - Warning(WARN_MULT_SEG_OVERRIDE, (char *)NULL); + Warning(_("multiple segment overrides, using leftmost")); ptr->segment = segment; } @@ -180,7 +183,7 @@ SetInsnOperSizeOverride(bytecode *bc, unsigned char opersize) break; default: InternalError(__LINE__, __FILE__, - "OperSize override applied to non-instruction"); + _("OperSize override applied to non-instruction")); return; } } @@ -200,7 +203,7 @@ SetInsnAddrSizeOverride(bytecode *bc, unsigned char addrsize) break; default: InternalError(__LINE__, __FILE__, - "AddrSize override applied to non-instruction"); + _("AddrSize override applied to non-instruction")); return; } } @@ -222,12 +225,12 @@ SetInsnLockRepPrefix(bytecode *bc, unsigned char prefix) break; default: InternalError(__LINE__, __FILE__, - "LockRep prefix applied to non-instruction"); + _("LockRep prefix applied to non-instruction")); return; } if (*lockrep_pre != 0) - Warning(WARN_MULT_LOCKREP_PREFIX, (char *)NULL); + Warning(_("multiple LOCK or REP prefixes, using leftmost")); *lockrep_pre = prefix; } @@ -239,7 +242,7 @@ SetOpcodeSel(jmprel_opcode_sel *old_sel, jmprel_opcode_sel new_sel) return; if ((*old_sel == JR_SHORT_FORCED) || (*old_sel == JR_NEAR_FORCED)) - Warning(WARN_MULT_SHORTNEAR, (char *)NULL); + Warning(_("multiple SHORT or NEAR specifiers, using leftmost")); *old_sel = new_sel; } @@ -324,9 +327,9 @@ BuildBC_JmpRel(bytecode *bc, bc->data.jmprel.op_sel = target->op_sel; if ((target->op_sel == JR_SHORT_FORCED) && (!short_valid)) - Error(ERR_NO_JMPREL_FORM, (char *)NULL, "SHORT"); + Error(_("no SHORT form of that jump instruction exists")); if ((target->op_sel == JR_NEAR_FORCED) && (!near_valid)) - Error(ERR_NO_JMPREL_FORM, (char *)NULL, "NEAR"); + Error(_("no NEAR form of that jump instruction exists")); bc->data.jmprel.shortop.valid = short_valid; if (short_valid) { @@ -378,13 +381,16 @@ BuildBC_Data(bytecode *bc, datavalhead *datahead, unsigned long size) break; case DV_FLOAT: if (size == 1) - Error(ERR_DECLDATA_FLOAT, (char *)NULL, "DB"); + Error(_("floating-point constant encountered in `%s'"), + "DB"); else if (size == 2) - Error(ERR_DECLDATA_FLOAT, (char *)NULL, "DW"); + Error(_("floating-point constant encountered in `%s'"), + "DW"); break; case DV_EXPR: if (size == 10) - Error(ERR_DECLDATA_EXPR, (char *)NULL, "DT"); + Error(_("non-floating-point value encountered in `%s'"), + "DT"); break; } } diff --git a/libyasm/errwarn.c b/libyasm/errwarn.c index c802a9a4..63f25929 100644 --- a/libyasm/errwarn.c +++ b/libyasm/errwarn.c @@ -1,4 +1,4 @@ -/* $Id: errwarn.c,v 1.22 2001/08/19 07:46:52 peter Exp $ +/* $Id: errwarn.c,v 1.23 2001/08/30 03:45:26 peter Exp $ * Error and warning reporting and related functions. * * Copyright (C) 2001 Peter Johnson @@ -34,10 +34,18 @@ # include #endif +#include +#define _(String) gettext(String) +#ifdef gettext_noop +#define N_(String) gettext_noop(String) +#else +#define N_(String) (String) +#endif + #include "globals.h" #include "errwarn.h" -RCSID("$Id: errwarn.c,v 1.22 2001/08/19 07:46:52 peter Exp $"); +RCSID("$Id: errwarn.c,v 1.23 2001/08/30 03:45:26 peter Exp $"); /* Total error count for entire assembler run. * Assembler should exit with EXIT_FAILURE if this is >= 0 on finish. */ @@ -52,42 +60,8 @@ unsigned int warning_count = 0; /* Fatal error messages. Match up with fatal_num enum in errwarn.h. */ static char *fatal_msgs[] = { - "unknown", - "out of memory" -}; - -/* Error messages. Match up with err_num enum in errwarn.h. */ -static char *err_msgs[] = { - "", - "parser error: %s", - "missing '%1'", - "missing argument to %s", - "invalid argument to %s", - "invalid effective address", - "label or instruction expected at start of line", - "expression syntax error", - "duplicate definition of `%1'; previously defined line %2", - "mismatch in operand sizes", - "no %s form of that jump instruction exists", - "unterminated string", - "unexpected end of file in string", - "expression syntax error", - "floating-point constant encountered in `%s'", - "non-floating-point value encountered in `%s'", - "could not open file `%s'", - "error when reading from file" -}; - -/* Warning messages. Match up with warn_num enum in errwarn.h. */ -static char *warn_msgs[] = { - "", - "ignoring unrecognized character '%s'", - "%s value exceeds bounds", - "multiple segment overrides, using leftmost", - "multiple LOCK or REP prefixes, using leftmost", - "no non-local label before '%s'", - "multiple SHORT or NEAR specifiers, using leftmost", - "character constant too large, ignoring trailing characters" + N_("unknown"), + N_("out of memory") }; /* I hate to define these strings as static buffers; a better solution would be @@ -100,12 +74,17 @@ static char last_err[1024]; /* Last warning message string. Set by Warning(), read by OutputWarning(). */ static char last_warn[1024]; -/* Last error number. Set by Error(), read and reset by OutputError(). */ -static err_num last_err_num = ERR_NONE; +/* Has there been an error since the last time we output one? Set by Error(), + * read and reset by OutputError(). */ +static int new_error = 0; + +/* Is the last error a parser error? Error() lets other errors override parser + * errors. Set by yyerror(), read and reset by Error(). */ +static int parser_error = 0; -/* Last warning number. Set by Warning(), read and reset by - * OutputWarning(). */ -static warn_num last_warn_num = WARN_NONE; +/* Has there been a warning since the last time we output one? Set by + * Warning(), read and reset by OutputWarning(). */ +static int new_warning = 0; /* Static buffer for use by conv_unprint(). */ static char unprint[5]; @@ -134,9 +113,10 @@ conv_unprint(char ch) /* Parser error handler. Moves error into our error handling system. */ void -yyerror(char *s) +ParserError(char *s) { - Error(ERR_PARSER, (char *)NULL, s); + Error("%s %s", _("parser error:"), s); + parser_error = 1; } /* Report an internal error. Essentially a fatal error with trace info. @@ -144,7 +124,7 @@ yyerror(char *s) void InternalError(unsigned int line, char *file, char *message) { - fprintf(stderr, "INTERNAL ERROR at %s, line %d: %s\n", file, line, + fprintf(stderr, _("INTERNAL ERROR at %s, line %d: %s\n"), file, line, message); exit(EXIT_FAILURE); } @@ -154,97 +134,28 @@ InternalError(unsigned int line, char *file, char *message) void Fatal(fatal_num num) { - fprintf(stderr, "FATAL: %s\n", fatal_msgs[num]); + fprintf(stderr, "%s %s\n", _("FATAL:"), gettext(fatal_msgs[num])); exit(EXIT_FAILURE); } -/* Argument replacement function for use in error messages. - * Replaces %1, %2, etc in src with %c, %s, etc. in argtypes. - * Currently limits maximum number of args to 9 (%1-%9). - * - * We need this because messages that take multiple arguments become dependent - * on the order and type of the arguments passed to Error()/Warning(). - * - * i.e. an error string "'%d' is not a valid specifier for '%s'" would require - * that the arguments passed to Error() always be an int and a char *, in that - * order. If the string was changed to be "'%s': invalid specifier '%d'", all - * the times Error() was called for that string would need to be changed to - * reorder the arguments. Or if the %d was not right in some circumstances, - * we'd have to add another string for that type. - * - * This function fixes this problem by allowing the string to be specified as - * "'%1' is not a valid specifier for '%2'" and then specifying at the time of - * the Error() call what the types of %1 and %2 are by passing a argtype string - * "%d%s" (to emulate the first behavior). If the string was changed to be - * "'%2': invalid specifier '%1'", no change would need to be made to the - * Error calls using that string. And as the type is specified with the - * argument list, mismatches are far less likely. - * - * For strings that only have one argument of a fixed type, it can be directly - * specified and NULL passed for the argtypes parameter when Error() is - * called. */ -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); - /* 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) - Fatal(FATAL_NOMEM); - } - return dest; -} - /* Register an error. Uses argtypes as described above to specify the * argument types. Does not print the error, only stores it for * OutputError() to print. */ void -Error(err_num num, char *argtypes, ...) +Error(char *fmt, ...) { va_list ap; - char *printf_str; - if ((last_err_num != ERR_NONE) && (last_err_num != ERR_PARSER)) + if (new_error && !parser_error) return; - last_err_num = num; + new_error = 1; + parser_error = 0; - printf_str = process_argtypes(err_msgs[num], argtypes); - - va_start(ap, argtypes); - vsprintf(last_err, printf_str, ap); + va_start(ap, fmt); + vsprintf(last_err, fmt, ap); va_end(ap); - free(printf_str); - error_count++; } @@ -252,24 +163,19 @@ Error(err_num num, char *argtypes, ...) * argument types. Does not print the warning, only stores it for * OutputWarning() to print. */ void -Warning(warn_num num, char *argtypes, ...) +Warning(char *fmt, ...) { va_list ap; - char *printf_str; - if (last_warn_num != WARN_NONE) + if (new_warning) return; - last_warn_num = num; + new_warning = 1; - printf_str = process_argtypes(warn_msgs[num], argtypes); - - va_start(ap, argtypes); - vsprintf(last_warn, printf_str, ap); + va_start(ap, fmt); + vsprintf(last_warn, fmt, ap); va_end(ap); - free(printf_str); - warning_count++; } @@ -277,17 +183,17 @@ Warning(warn_num num, char *argtypes, ...) void OutputError(void) { - if (last_err_num != ERR_NONE) + if (new_error) fprintf(stderr, "%s:%u: %s\n", filename, line_number, last_err); - last_err_num = ERR_NONE; + new_error = 0; } /* Output a previously stored warning (if any) to stderr. */ void OutputWarning(void) { - if (last_warn_num != WARN_NONE) - fprintf(stderr, "%s:%u: warning: %s\n", filename, line_number, - last_warn); - last_warn_num = WARN_NONE; + if (new_warning) + fprintf(stderr, "%s:%u: %s %s\n", filename, line_number, + _("warning:"), last_warn); + new_warning = 0; } diff --git a/libyasm/errwarn.h b/libyasm/errwarn.h index 13a2d751..bd9e41ed 100644 --- a/libyasm/errwarn.h +++ b/libyasm/errwarn.h @@ -1,4 +1,4 @@ -/* $Id: errwarn.h,v 1.13 2001/08/18 23:05:37 peter Exp $ +/* $Id: errwarn.h,v 1.14 2001/08/30 03:45:26 peter Exp $ * Error and warning reporting and related functions header file. * * Copyright (C) 2001 Peter Johnson @@ -22,58 +22,23 @@ #ifndef YASM_ERRWARN_H #define YASM_ERRWARN_H -/* See errwarn.c for strings that match up to these constants. +/* Fatal error constants. + * See fatal_msgs in errwarn.c for strings that match up to these constants. * When adding a constant here, keep errwarn.c in sync! */ - -/* Fatal error constants. Match up with fatal_msgs in errwarn.c. */ typedef enum { FATAL_UNKNOWN = 0, FATAL_NOMEM } fatal_num; -/* Error constants. Match up with err_msgs in errwarn.c. */ -/* FIXME: These shouldn't be ERR_* because they'll violate namespace - * constraints if errno.h is included. */ -typedef enum { - ERR_NONE = 0, - ERR_PARSER, - ERR_MISSING, - ERR_MISSING_ARG, - ERR_INVALID_ARG, - ERR_INVALID_EA, - ERR_INVALID_LINE, - ERR_EXP_SYNTAX, - ERR_DUPLICATE_DEF, - ERR_OP_SIZE_MISMATCH, - ERR_NO_JMPREL_FORM, - ERR_STRING_UNTERM, - ERR_STRING_EOF, - ERR_EXPR_SYNTAX, - ERR_DECLDATA_FLOAT, - ERR_DECLDATA_EXPR, - ERR_FILE_OPEN, - ERR_FILE_READ -} err_num; - -/* Warning constants. Match up with warn_msgs in errwarn.c. */ -typedef enum { - WARN_NONE = 0, - WARN_UNREC_CHAR, - WARN_VALUE_EXCEEDS_BOUNDS, - WARN_MULT_SEG_OVERRIDE, - WARN_MULT_LOCKREP_PREFIX, - WARN_NO_BASE_LABEL, - WARN_MULT_SHORTNEAR, - WARN_CHAR_CONST_TOO_BIG -} warn_num; - char *conv_unprint(char ch); +void ParserError(char *); + void InternalError(unsigned int line, char *file, char *message); void Fatal(fatal_num); -void Error(err_num, char *, ...); -void Warning(warn_num, char *, ...); +void Error(char *, ...); +void Warning(char *, ...); void OutputError(void); void OutputWarning(void); diff --git a/libyasm/symrec.c b/libyasm/symrec.c index 153607bd..d1ccf838 100644 --- a/libyasm/symrec.c +++ b/libyasm/symrec.c @@ -1,4 +1,4 @@ -/* $Id: symrec.c,v 1.8 2001/08/19 07:46:52 peter Exp $ +/* $Id: symrec.c,v 1.9 2001/08/30 03:45:26 peter Exp $ * Symbol table handling * * Copyright (C) 2001 Michael Urman @@ -30,11 +30,14 @@ # include #endif +#include +#define _(String) gettext(String) + #include "globals.h" #include "errwarn.h" #include "symrec.h" -RCSID("$Id: symrec.c,v 1.8 2001/08/19 07:46:52 peter Exp $"); +RCSID("$Id: symrec.c,v 1.9 2001/08/30 03:45:26 peter Exp $"); /* private functions */ static symtab *symtab_get(char *); @@ -134,7 +137,8 @@ sym_def_get(char *name, SymType type) tab = symtab_get_or_new(name, type); if (tab->rec.status & SYM_DECLARED) - Error(ERR_DUPLICATE_DEF, "%s%d", tab->rec.name, tab->rec.line); + Error(_("duplicate definition of `%s'; previously defined on line %d"), + tab->rec.name, tab->rec.line); tab->rec.status |= SYM_DECLARED; return &(tab->rec); } diff --git a/modules/objfmts/dbg/Makefile.am b/modules/objfmts/dbg/Makefile.am index 43e24e63..0ab845cb 100644 --- a/modules/objfmts/dbg/Makefile.am +++ b/modules/objfmts/dbg/Makefile.am @@ -3,7 +3,9 @@ noinst_LIBRARIES = liboutfmt.a liboutfmt_a_SOURCES = \ outfmt.c -INCLUDES=-I$(top_srcdir)/src +INCLUDES = \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/intl if DEV CFLAGS = -ansi -pedantic -Wall -g diff --git a/modules/parsers/nasm/Makefile.am b/modules/parsers/nasm/Makefile.am index 77519bc8..82bc7fb7 100644 --- a/modules/parsers/nasm/Makefile.am +++ b/modules/parsers/nasm/Makefile.am @@ -10,7 +10,9 @@ noinst_SCRIPTS = gen_instr.pl AM_YFLAGS = -d --name-prefix=nasm_parser_ AM_LFLAGS = -Pnasm_parser_ -olex.yy.c -INCLUDES=-I$(top_srcdir)/src +INCLUDES = \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/intl if DEV CFLAGS = -ansi -pedantic -Wall -g diff --git a/modules/parsers/nasm/bison.y.in b/modules/parsers/nasm/bison.y.in index 7c6667b8..c1cab314 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.27 2001/08/19 07:46:52 peter Exp $ +/* $Id: bison.y.in,v 1.28 2001/08/30 03:45:26 peter Exp $ * Main bison parser * * Copyright (C) 2001 Peter Johnson, Michael Urman @@ -31,6 +31,9 @@ # include #endif +#include +#define _(String) gettext(String) + #include "globals.h" #include "errwarn.h" #include "expr.h" @@ -38,13 +41,12 @@ #include "bytecode.h" -RCSID("$Id: bison.y.in,v 1.27 2001/08/19 07:46:52 peter Exp $"); +RCSID("$Id: bison.y.in,v 1.28 2001/08/30 03:45:26 peter Exp $"); #define YYDEBUG 1 void init_table(void); extern int nasm_parser_lex(void); -extern void yyerror(char *); static unsigned long ConvertCharConstToInt(char *); void nasm_parser_error(char *); @@ -126,7 +128,7 @@ line: '\n' { $$.type = BC_EMPTY; } | exp '\n' { DebugPrintBC(&$1); $$ = $1; } | directive '\n' { $$.type = BC_EMPTY; } | error '\n' { - Error(ERR_INVALID_LINE, (char *)NULL); + Error(_("label or instruction expected at start of line")); $$.type = BC_EMPTY; yyerrok; } @@ -153,7 +155,7 @@ dataval: expr_no_string { $$ = dataval_new_expr($1); } | FLTNUM { $$ = dataval_new_float($1); } | STRING { $$ = dataval_new_string($1); } | error { - Error(ERR_EXPR_SYNTAX, (char *)NULL); + Error(_("expression syntax error")); $$ = (dataval *)NULL; } ; @@ -172,10 +174,10 @@ directive: '[' DIRECTIVE_NAME DIRECTIVE_VAL ']' { printf("Directive: Name='%s' Value='%s'\n", $2, $3); } | '[' DIRECTIVE_NAME DIRECTIVE_VAL error { - Error(ERR_MISSING, "%c", ']'); + Error(_("missing `%c'"), ']'); } | '[' DIRECTIVE_NAME error { - Error(ERR_MISSING_ARG, (char *)NULL, $2); + Error(_("missing argument to `%s'"), $2); } ; @@ -415,7 +417,7 @@ ConvertCharConstToInt(char *cc) size_t len = strlen(cc); if(len > 4) - Warning(WARN_CHAR_CONST_TOO_BIG, (char *)NULL); + Warning(_("character constant too large, ignoring trailing characters")); switch(len) { case 4: @@ -437,6 +439,6 @@ ConvertCharConstToInt(char *cc) void nasm_parser_error(char *s) { - yyerror(s); + ParserError(s); } diff --git a/modules/parsers/nasm/gen_instr.pl b/modules/parsers/nasm/gen_instr.pl index a122e084..1428393c 100755 --- a/modules/parsers/nasm/gen_instr.pl +++ b/modules/parsers/nasm/gen_instr.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# $Id: gen_instr.pl,v 1.18 2001/07/11 04:07:11 peter Exp $ +# $Id: gen_instr.pl,v 1.19 2001/08/30 03:45:26 peter Exp $ # Generates bison.y and token.l from instrs.dat for YASM # # Copyright (C) 2001 Michael Urman @@ -802,7 +802,7 @@ sub output_yacc ($@) # print error action # ASSUMES: at least one previous action exists print GRAMMAR " | \Ugrp_$group\E error {\n"; - print GRAMMAR " Error (ERR_EXP_SYNTAX, (char *)NULL);\n"; + print GRAMMAR " Error (_(\"expression syntax error\"));\n"; print GRAMMAR " }\n"; # terminate the rule diff --git a/modules/parsers/nasm/nasm-bison.y b/modules/parsers/nasm/nasm-bison.y index 26aac799..84720ffb 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.27 2001/08/19 07:46:52 peter Exp $ +/* $Id: nasm-bison.y,v 1.28 2001/08/30 03:45:26 peter Exp $ * Main bison parser * * Copyright (C) 2001 Peter Johnson, Michael Urman @@ -31,6 +31,9 @@ # include #endif +#include +#define _(String) gettext(String) + #include "globals.h" #include "errwarn.h" #include "expr.h" @@ -38,13 +41,12 @@ #include "bytecode.h" -RCSID("$Id: nasm-bison.y,v 1.27 2001/08/19 07:46:52 peter Exp $"); +RCSID("$Id: nasm-bison.y,v 1.28 2001/08/30 03:45:26 peter Exp $"); #define YYDEBUG 1 void init_table(void); extern int nasm_parser_lex(void); -extern void yyerror(char *); static unsigned long ConvertCharConstToInt(char *); void nasm_parser_error(char *); @@ -126,7 +128,7 @@ line: '\n' { $$.type = BC_EMPTY; } | exp '\n' { DebugPrintBC(&$1); $$ = $1; } | directive '\n' { $$.type = BC_EMPTY; } | error '\n' { - Error(ERR_INVALID_LINE, (char *)NULL); + Error(_("label or instruction expected at start of line")); $$.type = BC_EMPTY; yyerrok; } @@ -153,7 +155,7 @@ dataval: expr_no_string { $$ = dataval_new_expr($1); } | FLTNUM { $$ = dataval_new_float($1); } | STRING { $$ = dataval_new_string($1); } | error { - Error(ERR_EXPR_SYNTAX, (char *)NULL); + Error(_("expression syntax error")); $$ = (dataval *)NULL; } ; @@ -172,10 +174,10 @@ directive: '[' DIRECTIVE_NAME DIRECTIVE_VAL ']' { printf("Directive: Name='%s' Value='%s'\n", $2, $3); } | '[' DIRECTIVE_NAME DIRECTIVE_VAL error { - Error(ERR_MISSING, "%c", ']'); + Error(_("missing `%c'"), ']'); } | '[' DIRECTIVE_NAME error { - Error(ERR_MISSING_ARG, (char *)NULL, $2); + Error(_("missing argument to `%s'"), $2); } ; @@ -415,7 +417,7 @@ ConvertCharConstToInt(char *cc) size_t len = strlen(cc); if(len > 4) - Warning(WARN_CHAR_CONST_TOO_BIG, (char *)NULL); + Warning(_("character constant too large, ignoring trailing characters")); switch(len) { case 4: @@ -437,6 +439,6 @@ ConvertCharConstToInt(char *cc) void nasm_parser_error(char *s) { - yyerror(s); + ParserError(s); } diff --git a/modules/parsers/nasm/token.l.in b/modules/parsers/nasm/token.l.in index 5cc850a5..137c596e 100644 --- a/modules/parsers/nasm/token.l.in +++ b/modules/parsers/nasm/token.l.in @@ -1,4 +1,4 @@ -/* $Id: token.l.in,v 1.15 2001/08/19 07:46:52 peter Exp $ +/* $Id: token.l.in,v 1.16 2001/08/30 03:45:26 peter Exp $ * Main lexer * * Copyright (C) 2001 Peter Johnson @@ -31,6 +31,9 @@ # include #endif +#include +#define _(String) gettext(String) + #include "errwarn.h" #include "expr.h" #include "symrec.h" @@ -39,7 +42,7 @@ #include "bison.h" -RCSID("$Id: token.l.in,v 1.15 2001/08/19 07:46:52 peter Exp $"); +RCSID("$Id: token.l.in,v 1.16 2001/08/30 03:45:26 peter Exp $"); #define yylval nasm_parser_lval @@ -133,9 +136,9 @@ WS [ \t\r] } if(inch == '\n') - Error(ERR_STRING_UNTERM, (char *)NULL); + Error(_("unterminated string")); else if(inch == EOF) - Error(ERR_STRING_EOF, (char *)NULL); + Error(_("unexpected end of file in string")); strbuf[count] = '\0'; @@ -166,10 +169,12 @@ WS [ \t\r] return DIRECTIVE_VAL; } . { - Warning(WARN_UNREC_CHAR, (char *)NULL, conv_unprint(yytext[0])); + Warning(_("ignoring unrecognized character `%s'"), + conv_unprint(yytext[0])); } . { - Warning(WARN_UNREC_CHAR, (char *)NULL, conv_unprint(yytext[0])); + Warning(_("ignoring unrecognized character `%s'"), + conv_unprint(yytext[0])); } /* size specifiers */ @@ -293,7 +298,7 @@ $$|$|\.\.[a-z0-9_$#@~.?]+ { \.[a-z0-9_$#@~?][a-z0-9_$#@~.?]* { if (locallabel_base == NULL) { - Warning (WARN_NO_BASE_LABEL, (char *)NULL, yytext); + Warning (_("no non-local label before `%s'"), yytext); yylval.syminfo.name = strdup (yytext); if (yylval.syminfo.name == NULL) Fatal (FATAL_NOMEM); } @@ -329,5 +334,8 @@ $$|$|\.\.[a-z0-9_$#@~.?]+ { \n return '\n'; -. { Warning(WARN_UNREC_CHAR, (char *)NULL, conv_unprint(yytext[0])); } +. { + Warning(_("ignoring unrecognized character `%s'"), + conv_unprint(yytext[0])); +} diff --git a/modules/preprocs/raw/Makefile.am b/modules/preprocs/raw/Makefile.am index 9e956333..5a554880 100644 --- a/modules/preprocs/raw/Makefile.am +++ b/modules/preprocs/raw/Makefile.am @@ -3,7 +3,9 @@ noinst_LIBRARIES = libpreproc.a libpreproc_a_SOURCES = \ preproc.c -INCLUDES=-I$(top_srcdir)/src +INCLUDES = \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/intl if DEV CFLAGS = -ansi -pedantic -Wall -g diff --git a/modules/preprocs/raw/preproc.c b/modules/preprocs/raw/preproc.c index c21980f4..f93d3b3d 100644 --- a/modules/preprocs/raw/preproc.c +++ b/modules/preprocs/raw/preproc.c @@ -1,4 +1,4 @@ -/* $Id: preproc.c,v 1.5 2001/08/19 07:46:52 peter Exp $ +/* $Id: preproc.c,v 1.6 2001/08/30 03:45:26 peter Exp $ * Raw preprocessor (preforms NO preprocessing) * * Copyright (C) 2001 Peter Johnson @@ -27,12 +27,15 @@ #include +#include +#define _(String) gettext(String) + #include "errwarn.h" #include "outfmt.h" #include "preproc.h" -RCSID("$Id: preproc.c,v 1.5 2001/08/19 07:46:52 peter Exp $"); +RCSID("$Id: preproc.c,v 1.6 2001/08/30 03:45:26 peter Exp $"); static int is_interactive; static FILE *in; @@ -57,9 +60,9 @@ input(char *buf, int max_size) if (c == '\n') buf[n++] = (char)c; if (c == EOF && ferror(in)) - Error(ERR_FILE_READ, (char *)NULL); + Error(_("error when reading from file")); } else if (((n = fread(buf, 1, max_size, in)) == 0) && ferror(in)) - Error(ERR_FILE_READ, (char *)NULL); + Error(_("error when reading from file")); return n; } diff --git a/modules/preprocs/raw/raw-preproc.c b/modules/preprocs/raw/raw-preproc.c index 319a4343..1bb5dc4c 100644 --- a/modules/preprocs/raw/raw-preproc.c +++ b/modules/preprocs/raw/raw-preproc.c @@ -1,4 +1,4 @@ -/* $Id: raw-preproc.c,v 1.5 2001/08/19 07:46:52 peter Exp $ +/* $Id: raw-preproc.c,v 1.6 2001/08/30 03:45:26 peter Exp $ * Raw preprocessor (preforms NO preprocessing) * * Copyright (C) 2001 Peter Johnson @@ -27,12 +27,15 @@ #include +#include +#define _(String) gettext(String) + #include "errwarn.h" #include "outfmt.h" #include "preproc.h" -RCSID("$Id: raw-preproc.c,v 1.5 2001/08/19 07:46:52 peter Exp $"); +RCSID("$Id: raw-preproc.c,v 1.6 2001/08/30 03:45:26 peter Exp $"); static int is_interactive; static FILE *in; @@ -57,9 +60,9 @@ input(char *buf, int max_size) if (c == '\n') buf[n++] = (char)c; if (c == EOF && ferror(in)) - Error(ERR_FILE_READ, (char *)NULL); + Error(_("error when reading from file")); } else if (((n = fread(buf, 1, max_size, in)) == 0) && ferror(in)) - Error(ERR_FILE_READ, (char *)NULL); + Error(_("error when reading from file")); return n; } diff --git a/po/.cvsignore b/po/.cvsignore new file mode 100644 index 00000000..5473340d --- /dev/null +++ b/po/.cvsignore @@ -0,0 +1,7 @@ +Makefile +Makefile.in +Makefile.in.in +POTFILES +cat-id-tbl.c +yasm.pot +stamp-cat-id diff --git a/po/ChangeLog b/po/ChangeLog new file mode 100644 index 00000000..e69de29b diff --git a/po/POTFILES.in b/po/POTFILES.in new file mode 100644 index 00000000..a19b1a4f --- /dev/null +++ b/po/POTFILES.in @@ -0,0 +1,11 @@ +# List of source files containing translatable strings. +# Copyright (c) 2001 Peter Johnson +# +# $Id: POTFILES.in,v 1.1 2001/08/30 03:45:16 peter Exp $ + +src/errwarn.c +src/bytecode.c +src/symrec.c +src/parsers/nasm/bison.c +src/parsers/nasm/token.c +src/preprocs/raw/preproc.c diff --git a/src/Makefile.am b/src/Makefile.am index 54886725..56433ef0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,7 @@ SUBDIRS = parsers preprocs outfmts +INCLUDES = -I$(top_srcdir)/intl + bin_PROGRAMS = yasm yasm_SOURCES = \ @@ -22,7 +24,8 @@ yasm_SOURCES = \ yasm_LDADD = \ parsers/nasm/libparser.a \ preprocs/raw/libpreproc.a \ - outfmts/dbg/liboutfmt.a + outfmts/dbg/liboutfmt.a \ + $(INTLLIBS) if DEV CFLAGS = -ansi -pedantic -Wall -g diff --git a/src/bytecode.c b/src/bytecode.c index 347a45eb..2765a251 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -1,4 +1,4 @@ -/* $Id: bytecode.c,v 1.19 2001/08/19 07:46:52 peter Exp $ +/* $Id: bytecode.c,v 1.20 2001/08/30 03:45:26 peter Exp $ * Bytecode utility functions * * Copyright (C) 2001 Peter Johnson @@ -32,13 +32,16 @@ # include #endif +#include +#define _(String) gettext(String) + #include "globals.h" #include "errwarn.h" #include "expr.h" #include "bytecode.h" -RCSID("$Id: bytecode.c,v 1.19 2001/08/19 07:46:52 peter Exp $"); +RCSID("$Id: bytecode.c,v 1.20 2001/08/30 03:45:26 peter Exp $"); /* Static structures for when NULL is passed to conversion functions. */ /* for Convert*ToEA() */ @@ -95,7 +98,7 @@ ConvertImmToEA(effaddr *ptr, immval *im_ptr, unsigned char im_len) ptr->disp = im_ptr->val; if (im_ptr->len > im_len) - Warning(WARN_VALUE_EXCEEDS_BOUNDS, (char *)NULL, "word"); + Warning(_("%s value exceeds bounds"), "word"); ptr->len = im_len; ptr->segment = 0; ptr->valid_modrm = 0; @@ -147,7 +150,7 @@ SetEASegment(effaddr *ptr, unsigned char segment) return; if (ptr->segment != 0) - Warning(WARN_MULT_SEG_OVERRIDE, (char *)NULL); + Warning(_("multiple segment overrides, using leftmost")); ptr->segment = segment; } @@ -180,7 +183,7 @@ SetInsnOperSizeOverride(bytecode *bc, unsigned char opersize) break; default: InternalError(__LINE__, __FILE__, - "OperSize override applied to non-instruction"); + _("OperSize override applied to non-instruction")); return; } } @@ -200,7 +203,7 @@ SetInsnAddrSizeOverride(bytecode *bc, unsigned char addrsize) break; default: InternalError(__LINE__, __FILE__, - "AddrSize override applied to non-instruction"); + _("AddrSize override applied to non-instruction")); return; } } @@ -222,12 +225,12 @@ SetInsnLockRepPrefix(bytecode *bc, unsigned char prefix) break; default: InternalError(__LINE__, __FILE__, - "LockRep prefix applied to non-instruction"); + _("LockRep prefix applied to non-instruction")); return; } if (*lockrep_pre != 0) - Warning(WARN_MULT_LOCKREP_PREFIX, (char *)NULL); + Warning(_("multiple LOCK or REP prefixes, using leftmost")); *lockrep_pre = prefix; } @@ -239,7 +242,7 @@ SetOpcodeSel(jmprel_opcode_sel *old_sel, jmprel_opcode_sel new_sel) return; if ((*old_sel == JR_SHORT_FORCED) || (*old_sel == JR_NEAR_FORCED)) - Warning(WARN_MULT_SHORTNEAR, (char *)NULL); + Warning(_("multiple SHORT or NEAR specifiers, using leftmost")); *old_sel = new_sel; } @@ -324,9 +327,9 @@ BuildBC_JmpRel(bytecode *bc, bc->data.jmprel.op_sel = target->op_sel; if ((target->op_sel == JR_SHORT_FORCED) && (!short_valid)) - Error(ERR_NO_JMPREL_FORM, (char *)NULL, "SHORT"); + Error(_("no SHORT form of that jump instruction exists")); if ((target->op_sel == JR_NEAR_FORCED) && (!near_valid)) - Error(ERR_NO_JMPREL_FORM, (char *)NULL, "NEAR"); + Error(_("no NEAR form of that jump instruction exists")); bc->data.jmprel.shortop.valid = short_valid; if (short_valid) { @@ -378,13 +381,16 @@ BuildBC_Data(bytecode *bc, datavalhead *datahead, unsigned long size) break; case DV_FLOAT: if (size == 1) - Error(ERR_DECLDATA_FLOAT, (char *)NULL, "DB"); + Error(_("floating-point constant encountered in `%s'"), + "DB"); else if (size == 2) - Error(ERR_DECLDATA_FLOAT, (char *)NULL, "DW"); + Error(_("floating-point constant encountered in `%s'"), + "DW"); break; case DV_EXPR: if (size == 10) - Error(ERR_DECLDATA_EXPR, (char *)NULL, "DT"); + Error(_("non-floating-point value encountered in `%s'"), + "DT"); break; } } diff --git a/src/errwarn.c b/src/errwarn.c index c802a9a4..63f25929 100644 --- a/src/errwarn.c +++ b/src/errwarn.c @@ -1,4 +1,4 @@ -/* $Id: errwarn.c,v 1.22 2001/08/19 07:46:52 peter Exp $ +/* $Id: errwarn.c,v 1.23 2001/08/30 03:45:26 peter Exp $ * Error and warning reporting and related functions. * * Copyright (C) 2001 Peter Johnson @@ -34,10 +34,18 @@ # include #endif +#include +#define _(String) gettext(String) +#ifdef gettext_noop +#define N_(String) gettext_noop(String) +#else +#define N_(String) (String) +#endif + #include "globals.h" #include "errwarn.h" -RCSID("$Id: errwarn.c,v 1.22 2001/08/19 07:46:52 peter Exp $"); +RCSID("$Id: errwarn.c,v 1.23 2001/08/30 03:45:26 peter Exp $"); /* Total error count for entire assembler run. * Assembler should exit with EXIT_FAILURE if this is >= 0 on finish. */ @@ -52,42 +60,8 @@ unsigned int warning_count = 0; /* Fatal error messages. Match up with fatal_num enum in errwarn.h. */ static char *fatal_msgs[] = { - "unknown", - "out of memory" -}; - -/* Error messages. Match up with err_num enum in errwarn.h. */ -static char *err_msgs[] = { - "", - "parser error: %s", - "missing '%1'", - "missing argument to %s", - "invalid argument to %s", - "invalid effective address", - "label or instruction expected at start of line", - "expression syntax error", - "duplicate definition of `%1'; previously defined line %2", - "mismatch in operand sizes", - "no %s form of that jump instruction exists", - "unterminated string", - "unexpected end of file in string", - "expression syntax error", - "floating-point constant encountered in `%s'", - "non-floating-point value encountered in `%s'", - "could not open file `%s'", - "error when reading from file" -}; - -/* Warning messages. Match up with warn_num enum in errwarn.h. */ -static char *warn_msgs[] = { - "", - "ignoring unrecognized character '%s'", - "%s value exceeds bounds", - "multiple segment overrides, using leftmost", - "multiple LOCK or REP prefixes, using leftmost", - "no non-local label before '%s'", - "multiple SHORT or NEAR specifiers, using leftmost", - "character constant too large, ignoring trailing characters" + N_("unknown"), + N_("out of memory") }; /* I hate to define these strings as static buffers; a better solution would be @@ -100,12 +74,17 @@ static char last_err[1024]; /* Last warning message string. Set by Warning(), read by OutputWarning(). */ static char last_warn[1024]; -/* Last error number. Set by Error(), read and reset by OutputError(). */ -static err_num last_err_num = ERR_NONE; +/* Has there been an error since the last time we output one? Set by Error(), + * read and reset by OutputError(). */ +static int new_error = 0; + +/* Is the last error a parser error? Error() lets other errors override parser + * errors. Set by yyerror(), read and reset by Error(). */ +static int parser_error = 0; -/* Last warning number. Set by Warning(), read and reset by - * OutputWarning(). */ -static warn_num last_warn_num = WARN_NONE; +/* Has there been a warning since the last time we output one? Set by + * Warning(), read and reset by OutputWarning(). */ +static int new_warning = 0; /* Static buffer for use by conv_unprint(). */ static char unprint[5]; @@ -134,9 +113,10 @@ conv_unprint(char ch) /* Parser error handler. Moves error into our error handling system. */ void -yyerror(char *s) +ParserError(char *s) { - Error(ERR_PARSER, (char *)NULL, s); + Error("%s %s", _("parser error:"), s); + parser_error = 1; } /* Report an internal error. Essentially a fatal error with trace info. @@ -144,7 +124,7 @@ yyerror(char *s) void InternalError(unsigned int line, char *file, char *message) { - fprintf(stderr, "INTERNAL ERROR at %s, line %d: %s\n", file, line, + fprintf(stderr, _("INTERNAL ERROR at %s, line %d: %s\n"), file, line, message); exit(EXIT_FAILURE); } @@ -154,97 +134,28 @@ InternalError(unsigned int line, char *file, char *message) void Fatal(fatal_num num) { - fprintf(stderr, "FATAL: %s\n", fatal_msgs[num]); + fprintf(stderr, "%s %s\n", _("FATAL:"), gettext(fatal_msgs[num])); exit(EXIT_FAILURE); } -/* Argument replacement function for use in error messages. - * Replaces %1, %2, etc in src with %c, %s, etc. in argtypes. - * Currently limits maximum number of args to 9 (%1-%9). - * - * We need this because messages that take multiple arguments become dependent - * on the order and type of the arguments passed to Error()/Warning(). - * - * i.e. an error string "'%d' is not a valid specifier for '%s'" would require - * that the arguments passed to Error() always be an int and a char *, in that - * order. If the string was changed to be "'%s': invalid specifier '%d'", all - * the times Error() was called for that string would need to be changed to - * reorder the arguments. Or if the %d was not right in some circumstances, - * we'd have to add another string for that type. - * - * This function fixes this problem by allowing the string to be specified as - * "'%1' is not a valid specifier for '%2'" and then specifying at the time of - * the Error() call what the types of %1 and %2 are by passing a argtype string - * "%d%s" (to emulate the first behavior). If the string was changed to be - * "'%2': invalid specifier '%1'", no change would need to be made to the - * Error calls using that string. And as the type is specified with the - * argument list, mismatches are far less likely. - * - * For strings that only have one argument of a fixed type, it can be directly - * specified and NULL passed for the argtypes parameter when Error() is - * called. */ -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); - /* 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) - Fatal(FATAL_NOMEM); - } - return dest; -} - /* Register an error. Uses argtypes as described above to specify the * argument types. Does not print the error, only stores it for * OutputError() to print. */ void -Error(err_num num, char *argtypes, ...) +Error(char *fmt, ...) { va_list ap; - char *printf_str; - if ((last_err_num != ERR_NONE) && (last_err_num != ERR_PARSER)) + if (new_error && !parser_error) return; - last_err_num = num; + new_error = 1; + parser_error = 0; - printf_str = process_argtypes(err_msgs[num], argtypes); - - va_start(ap, argtypes); - vsprintf(last_err, printf_str, ap); + va_start(ap, fmt); + vsprintf(last_err, fmt, ap); va_end(ap); - free(printf_str); - error_count++; } @@ -252,24 +163,19 @@ Error(err_num num, char *argtypes, ...) * argument types. Does not print the warning, only stores it for * OutputWarning() to print. */ void -Warning(warn_num num, char *argtypes, ...) +Warning(char *fmt, ...) { va_list ap; - char *printf_str; - if (last_warn_num != WARN_NONE) + if (new_warning) return; - last_warn_num = num; + new_warning = 1; - printf_str = process_argtypes(warn_msgs[num], argtypes); - - va_start(ap, argtypes); - vsprintf(last_warn, printf_str, ap); + va_start(ap, fmt); + vsprintf(last_warn, fmt, ap); va_end(ap); - free(printf_str); - warning_count++; } @@ -277,17 +183,17 @@ Warning(warn_num num, char *argtypes, ...) void OutputError(void) { - if (last_err_num != ERR_NONE) + if (new_error) fprintf(stderr, "%s:%u: %s\n", filename, line_number, last_err); - last_err_num = ERR_NONE; + new_error = 0; } /* Output a previously stored warning (if any) to stderr. */ void OutputWarning(void) { - if (last_warn_num != WARN_NONE) - fprintf(stderr, "%s:%u: warning: %s\n", filename, line_number, - last_warn); - last_warn_num = WARN_NONE; + if (new_warning) + fprintf(stderr, "%s:%u: %s %s\n", filename, line_number, + _("warning:"), last_warn); + new_warning = 0; } diff --git a/src/errwarn.h b/src/errwarn.h index 13a2d751..bd9e41ed 100644 --- a/src/errwarn.h +++ b/src/errwarn.h @@ -1,4 +1,4 @@ -/* $Id: errwarn.h,v 1.13 2001/08/18 23:05:37 peter Exp $ +/* $Id: errwarn.h,v 1.14 2001/08/30 03:45:26 peter Exp $ * Error and warning reporting and related functions header file. * * Copyright (C) 2001 Peter Johnson @@ -22,58 +22,23 @@ #ifndef YASM_ERRWARN_H #define YASM_ERRWARN_H -/* See errwarn.c for strings that match up to these constants. +/* Fatal error constants. + * See fatal_msgs in errwarn.c for strings that match up to these constants. * When adding a constant here, keep errwarn.c in sync! */ - -/* Fatal error constants. Match up with fatal_msgs in errwarn.c. */ typedef enum { FATAL_UNKNOWN = 0, FATAL_NOMEM } fatal_num; -/* Error constants. Match up with err_msgs in errwarn.c. */ -/* FIXME: These shouldn't be ERR_* because they'll violate namespace - * constraints if errno.h is included. */ -typedef enum { - ERR_NONE = 0, - ERR_PARSER, - ERR_MISSING, - ERR_MISSING_ARG, - ERR_INVALID_ARG, - ERR_INVALID_EA, - ERR_INVALID_LINE, - ERR_EXP_SYNTAX, - ERR_DUPLICATE_DEF, - ERR_OP_SIZE_MISMATCH, - ERR_NO_JMPREL_FORM, - ERR_STRING_UNTERM, - ERR_STRING_EOF, - ERR_EXPR_SYNTAX, - ERR_DECLDATA_FLOAT, - ERR_DECLDATA_EXPR, - ERR_FILE_OPEN, - ERR_FILE_READ -} err_num; - -/* Warning constants. Match up with warn_msgs in errwarn.c. */ -typedef enum { - WARN_NONE = 0, - WARN_UNREC_CHAR, - WARN_VALUE_EXCEEDS_BOUNDS, - WARN_MULT_SEG_OVERRIDE, - WARN_MULT_LOCKREP_PREFIX, - WARN_NO_BASE_LABEL, - WARN_MULT_SHORTNEAR, - WARN_CHAR_CONST_TOO_BIG -} warn_num; - char *conv_unprint(char ch); +void ParserError(char *); + void InternalError(unsigned int line, char *file, char *message); void Fatal(fatal_num); -void Error(err_num, char *, ...); -void Warning(warn_num, char *, ...); +void Error(char *, ...); +void Warning(char *, ...); void OutputError(void); void OutputWarning(void); diff --git a/src/objfmts/dbg/Makefile.am b/src/objfmts/dbg/Makefile.am index 43e24e63..0ab845cb 100644 --- a/src/objfmts/dbg/Makefile.am +++ b/src/objfmts/dbg/Makefile.am @@ -3,7 +3,9 @@ noinst_LIBRARIES = liboutfmt.a liboutfmt_a_SOURCES = \ outfmt.c -INCLUDES=-I$(top_srcdir)/src +INCLUDES = \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/intl if DEV CFLAGS = -ansi -pedantic -Wall -g diff --git a/src/parsers/nasm/Makefile.am b/src/parsers/nasm/Makefile.am index 77519bc8..82bc7fb7 100644 --- a/src/parsers/nasm/Makefile.am +++ b/src/parsers/nasm/Makefile.am @@ -10,7 +10,9 @@ noinst_SCRIPTS = gen_instr.pl AM_YFLAGS = -d --name-prefix=nasm_parser_ AM_LFLAGS = -Pnasm_parser_ -olex.yy.c -INCLUDES=-I$(top_srcdir)/src +INCLUDES = \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/intl if DEV CFLAGS = -ansi -pedantic -Wall -g diff --git a/src/parsers/nasm/bison.y.in b/src/parsers/nasm/bison.y.in index 7c6667b8..c1cab314 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.27 2001/08/19 07:46:52 peter Exp $ +/* $Id: bison.y.in,v 1.28 2001/08/30 03:45:26 peter Exp $ * Main bison parser * * Copyright (C) 2001 Peter Johnson, Michael Urman @@ -31,6 +31,9 @@ # include #endif +#include +#define _(String) gettext(String) + #include "globals.h" #include "errwarn.h" #include "expr.h" @@ -38,13 +41,12 @@ #include "bytecode.h" -RCSID("$Id: bison.y.in,v 1.27 2001/08/19 07:46:52 peter Exp $"); +RCSID("$Id: bison.y.in,v 1.28 2001/08/30 03:45:26 peter Exp $"); #define YYDEBUG 1 void init_table(void); extern int nasm_parser_lex(void); -extern void yyerror(char *); static unsigned long ConvertCharConstToInt(char *); void nasm_parser_error(char *); @@ -126,7 +128,7 @@ line: '\n' { $$.type = BC_EMPTY; } | exp '\n' { DebugPrintBC(&$1); $$ = $1; } | directive '\n' { $$.type = BC_EMPTY; } | error '\n' { - Error(ERR_INVALID_LINE, (char *)NULL); + Error(_("label or instruction expected at start of line")); $$.type = BC_EMPTY; yyerrok; } @@ -153,7 +155,7 @@ dataval: expr_no_string { $$ = dataval_new_expr($1); } | FLTNUM { $$ = dataval_new_float($1); } | STRING { $$ = dataval_new_string($1); } | error { - Error(ERR_EXPR_SYNTAX, (char *)NULL); + Error(_("expression syntax error")); $$ = (dataval *)NULL; } ; @@ -172,10 +174,10 @@ directive: '[' DIRECTIVE_NAME DIRECTIVE_VAL ']' { printf("Directive: Name='%s' Value='%s'\n", $2, $3); } | '[' DIRECTIVE_NAME DIRECTIVE_VAL error { - Error(ERR_MISSING, "%c", ']'); + Error(_("missing `%c'"), ']'); } | '[' DIRECTIVE_NAME error { - Error(ERR_MISSING_ARG, (char *)NULL, $2); + Error(_("missing argument to `%s'"), $2); } ; @@ -415,7 +417,7 @@ ConvertCharConstToInt(char *cc) size_t len = strlen(cc); if(len > 4) - Warning(WARN_CHAR_CONST_TOO_BIG, (char *)NULL); + Warning(_("character constant too large, ignoring trailing characters")); switch(len) { case 4: @@ -437,6 +439,6 @@ ConvertCharConstToInt(char *cc) void nasm_parser_error(char *s) { - yyerror(s); + ParserError(s); } diff --git a/src/parsers/nasm/gen_instr.pl b/src/parsers/nasm/gen_instr.pl index a122e084..1428393c 100755 --- a/src/parsers/nasm/gen_instr.pl +++ b/src/parsers/nasm/gen_instr.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# $Id: gen_instr.pl,v 1.18 2001/07/11 04:07:11 peter Exp $ +# $Id: gen_instr.pl,v 1.19 2001/08/30 03:45:26 peter Exp $ # Generates bison.y and token.l from instrs.dat for YASM # # Copyright (C) 2001 Michael Urman @@ -802,7 +802,7 @@ sub output_yacc ($@) # print error action # ASSUMES: at least one previous action exists print GRAMMAR " | \Ugrp_$group\E error {\n"; - print GRAMMAR " Error (ERR_EXP_SYNTAX, (char *)NULL);\n"; + print GRAMMAR " Error (_(\"expression syntax error\"));\n"; print GRAMMAR " }\n"; # terminate the rule diff --git a/src/parsers/nasm/nasm-bison.y b/src/parsers/nasm/nasm-bison.y index 26aac799..84720ffb 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.27 2001/08/19 07:46:52 peter Exp $ +/* $Id: nasm-bison.y,v 1.28 2001/08/30 03:45:26 peter Exp $ * Main bison parser * * Copyright (C) 2001 Peter Johnson, Michael Urman @@ -31,6 +31,9 @@ # include #endif +#include +#define _(String) gettext(String) + #include "globals.h" #include "errwarn.h" #include "expr.h" @@ -38,13 +41,12 @@ #include "bytecode.h" -RCSID("$Id: nasm-bison.y,v 1.27 2001/08/19 07:46:52 peter Exp $"); +RCSID("$Id: nasm-bison.y,v 1.28 2001/08/30 03:45:26 peter Exp $"); #define YYDEBUG 1 void init_table(void); extern int nasm_parser_lex(void); -extern void yyerror(char *); static unsigned long ConvertCharConstToInt(char *); void nasm_parser_error(char *); @@ -126,7 +128,7 @@ line: '\n' { $$.type = BC_EMPTY; } | exp '\n' { DebugPrintBC(&$1); $$ = $1; } | directive '\n' { $$.type = BC_EMPTY; } | error '\n' { - Error(ERR_INVALID_LINE, (char *)NULL); + Error(_("label or instruction expected at start of line")); $$.type = BC_EMPTY; yyerrok; } @@ -153,7 +155,7 @@ dataval: expr_no_string { $$ = dataval_new_expr($1); } | FLTNUM { $$ = dataval_new_float($1); } | STRING { $$ = dataval_new_string($1); } | error { - Error(ERR_EXPR_SYNTAX, (char *)NULL); + Error(_("expression syntax error")); $$ = (dataval *)NULL; } ; @@ -172,10 +174,10 @@ directive: '[' DIRECTIVE_NAME DIRECTIVE_VAL ']' { printf("Directive: Name='%s' Value='%s'\n", $2, $3); } | '[' DIRECTIVE_NAME DIRECTIVE_VAL error { - Error(ERR_MISSING, "%c", ']'); + Error(_("missing `%c'"), ']'); } | '[' DIRECTIVE_NAME error { - Error(ERR_MISSING_ARG, (char *)NULL, $2); + Error(_("missing argument to `%s'"), $2); } ; @@ -415,7 +417,7 @@ ConvertCharConstToInt(char *cc) size_t len = strlen(cc); if(len > 4) - Warning(WARN_CHAR_CONST_TOO_BIG, (char *)NULL); + Warning(_("character constant too large, ignoring trailing characters")); switch(len) { case 4: @@ -437,6 +439,6 @@ ConvertCharConstToInt(char *cc) void nasm_parser_error(char *s) { - yyerror(s); + ParserError(s); } diff --git a/src/parsers/nasm/token.l.in b/src/parsers/nasm/token.l.in index 5cc850a5..137c596e 100644 --- a/src/parsers/nasm/token.l.in +++ b/src/parsers/nasm/token.l.in @@ -1,4 +1,4 @@ -/* $Id: token.l.in,v 1.15 2001/08/19 07:46:52 peter Exp $ +/* $Id: token.l.in,v 1.16 2001/08/30 03:45:26 peter Exp $ * Main lexer * * Copyright (C) 2001 Peter Johnson @@ -31,6 +31,9 @@ # include #endif +#include +#define _(String) gettext(String) + #include "errwarn.h" #include "expr.h" #include "symrec.h" @@ -39,7 +42,7 @@ #include "bison.h" -RCSID("$Id: token.l.in,v 1.15 2001/08/19 07:46:52 peter Exp $"); +RCSID("$Id: token.l.in,v 1.16 2001/08/30 03:45:26 peter Exp $"); #define yylval nasm_parser_lval @@ -133,9 +136,9 @@ WS [ \t\r] } if(inch == '\n') - Error(ERR_STRING_UNTERM, (char *)NULL); + Error(_("unterminated string")); else if(inch == EOF) - Error(ERR_STRING_EOF, (char *)NULL); + Error(_("unexpected end of file in string")); strbuf[count] = '\0'; @@ -166,10 +169,12 @@ WS [ \t\r] return DIRECTIVE_VAL; } . { - Warning(WARN_UNREC_CHAR, (char *)NULL, conv_unprint(yytext[0])); + Warning(_("ignoring unrecognized character `%s'"), + conv_unprint(yytext[0])); } . { - Warning(WARN_UNREC_CHAR, (char *)NULL, conv_unprint(yytext[0])); + Warning(_("ignoring unrecognized character `%s'"), + conv_unprint(yytext[0])); } /* size specifiers */ @@ -293,7 +298,7 @@ $$|$|\.\.[a-z0-9_$#@~.?]+ { \.[a-z0-9_$#@~?][a-z0-9_$#@~.?]* { if (locallabel_base == NULL) { - Warning (WARN_NO_BASE_LABEL, (char *)NULL, yytext); + Warning (_("no non-local label before `%s'"), yytext); yylval.syminfo.name = strdup (yytext); if (yylval.syminfo.name == NULL) Fatal (FATAL_NOMEM); } @@ -329,5 +334,8 @@ $$|$|\.\.[a-z0-9_$#@~.?]+ { \n return '\n'; -. { Warning(WARN_UNREC_CHAR, (char *)NULL, conv_unprint(yytext[0])); } +. { + Warning(_("ignoring unrecognized character `%s'"), + conv_unprint(yytext[0])); +} diff --git a/src/preprocs/raw/Makefile.am b/src/preprocs/raw/Makefile.am index 9e956333..5a554880 100644 --- a/src/preprocs/raw/Makefile.am +++ b/src/preprocs/raw/Makefile.am @@ -3,7 +3,9 @@ noinst_LIBRARIES = libpreproc.a libpreproc_a_SOURCES = \ preproc.c -INCLUDES=-I$(top_srcdir)/src +INCLUDES = \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/intl if DEV CFLAGS = -ansi -pedantic -Wall -g diff --git a/src/preprocs/raw/preproc.c b/src/preprocs/raw/preproc.c index c21980f4..f93d3b3d 100644 --- a/src/preprocs/raw/preproc.c +++ b/src/preprocs/raw/preproc.c @@ -1,4 +1,4 @@ -/* $Id: preproc.c,v 1.5 2001/08/19 07:46:52 peter Exp $ +/* $Id: preproc.c,v 1.6 2001/08/30 03:45:26 peter Exp $ * Raw preprocessor (preforms NO preprocessing) * * Copyright (C) 2001 Peter Johnson @@ -27,12 +27,15 @@ #include +#include +#define _(String) gettext(String) + #include "errwarn.h" #include "outfmt.h" #include "preproc.h" -RCSID("$Id: preproc.c,v 1.5 2001/08/19 07:46:52 peter Exp $"); +RCSID("$Id: preproc.c,v 1.6 2001/08/30 03:45:26 peter Exp $"); static int is_interactive; static FILE *in; @@ -57,9 +60,9 @@ input(char *buf, int max_size) if (c == '\n') buf[n++] = (char)c; if (c == EOF && ferror(in)) - Error(ERR_FILE_READ, (char *)NULL); + Error(_("error when reading from file")); } else if (((n = fread(buf, 1, max_size, in)) == 0) && ferror(in)) - Error(ERR_FILE_READ, (char *)NULL); + Error(_("error when reading from file")); return n; } diff --git a/src/preprocs/raw/raw-preproc.c b/src/preprocs/raw/raw-preproc.c index 319a4343..1bb5dc4c 100644 --- a/src/preprocs/raw/raw-preproc.c +++ b/src/preprocs/raw/raw-preproc.c @@ -1,4 +1,4 @@ -/* $Id: raw-preproc.c,v 1.5 2001/08/19 07:46:52 peter Exp $ +/* $Id: raw-preproc.c,v 1.6 2001/08/30 03:45:26 peter Exp $ * Raw preprocessor (preforms NO preprocessing) * * Copyright (C) 2001 Peter Johnson @@ -27,12 +27,15 @@ #include +#include +#define _(String) gettext(String) + #include "errwarn.h" #include "outfmt.h" #include "preproc.h" -RCSID("$Id: raw-preproc.c,v 1.5 2001/08/19 07:46:52 peter Exp $"); +RCSID("$Id: raw-preproc.c,v 1.6 2001/08/30 03:45:26 peter Exp $"); static int is_interactive; static FILE *in; @@ -57,9 +60,9 @@ input(char *buf, int max_size) if (c == '\n') buf[n++] = (char)c; if (c == EOF && ferror(in)) - Error(ERR_FILE_READ, (char *)NULL); + Error(_("error when reading from file")); } else if (((n = fread(buf, 1, max_size, in)) == 0) && ferror(in)) - Error(ERR_FILE_READ, (char *)NULL); + Error(_("error when reading from file")); return n; } diff --git a/src/symrec.c b/src/symrec.c index 153607bd..d1ccf838 100644 --- a/src/symrec.c +++ b/src/symrec.c @@ -1,4 +1,4 @@ -/* $Id: symrec.c,v 1.8 2001/08/19 07:46:52 peter Exp $ +/* $Id: symrec.c,v 1.9 2001/08/30 03:45:26 peter Exp $ * Symbol table handling * * Copyright (C) 2001 Michael Urman @@ -30,11 +30,14 @@ # include #endif +#include +#define _(String) gettext(String) + #include "globals.h" #include "errwarn.h" #include "symrec.h" -RCSID("$Id: symrec.c,v 1.8 2001/08/19 07:46:52 peter Exp $"); +RCSID("$Id: symrec.c,v 1.9 2001/08/30 03:45:26 peter Exp $"); /* private functions */ static symtab *symtab_get(char *); @@ -134,7 +137,8 @@ sym_def_get(char *name, SymType type) tab = symtab_get_or_new(name, type); if (tab->rec.status & SYM_DECLARED) - Error(ERR_DUPLICATE_DEF, "%s%d", tab->rec.name, tab->rec.line); + Error(_("duplicate definition of `%s'; previously defined on line %d"), + tab->rec.name, tab->rec.line); tab->rec.status |= SYM_DECLARED; return &(tab->rec); } -- 2.50.1