From: Ben Pfaff Date: Tue, 3 May 2005 06:36:17 +0000 (+0000) Subject: Improve lex_error() error messages. X-Git-Tag: v0.4.0~97 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9eb49ba79d7178c565e4447c5fd26eb050d35d63;p=pspp-builds.git Improve lex_error() error messages. --- diff --git a/TODO b/TODO index 0f765330..97afc2b5 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -Time-stamp: <2005-03-02 16:08:59 blp> +Time-stamp: <2005-05-02 23:31:38 blp> What Ben's working on now. -------------------------- @@ -18,6 +18,8 @@ other procedures). TODO ---- +lex_token_representation() should take a buffer to fill. + Make valgrind --leak-check=yes --show-reachable=yes work. Add NOT_REACHED() macro. diff --git a/src/ChangeLog b/src/ChangeLog index a2ae0c91..66c76f13 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +Mon May 2 23:27:28 2005 Ben Pfaff + + * lexer.c: (lex_error) Improve error messages. + Mon May 2 22:28:17 2005 Ben Pfaff * get.c: (cmd_match_files) Check token type before trying to match diff --git a/src/lexer.c b/src/lexer.c index 575e917b..53b702c4 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -386,11 +386,18 @@ void lex_error (const char *message, ...) { char *token_rep; + char where[128]; token_rep = lex_token_representation (); - if (token_rep[0] == 0) - msg (SE, _("Syntax error at end of file.")); - else if (message) + if (token == T_STOP) + strcpy (where, "end of file"); + else if (token == '.') + strcpy (where, "end of command"); + else + snprintf (where, sizeof where, "`%s'", token_rep); + free (token_rep); + + if (message) { char buf[1024]; va_list args; @@ -399,12 +406,10 @@ lex_error (const char *message, ...) vsnprintf (buf, 1024, message, args); va_end (args); - msg (SE, _("Syntax error %s at `%s'."), buf, token_rep); + msg (SE, _("Syntax error %s at %s."), buf, where); } else - msg (SE, _("Syntax error at `%s'."), token_rep); - - free (token_rep); + msg (SE, _("Syntax error at %s."), where); } /* Checks that we're at end of command. @@ -539,7 +544,7 @@ lex_force_match (int t) } else { - lex_error (_("expecting %s"), lex_token_name (t)); + lex_error (_("expecting `%s'"), lex_token_name (t)); return 0; } }