From d1f7167ce21da3e3f4ee051b2fdd24fc9607bbdc Mon Sep 17 00:00:00 2001 From: Toby Goodwin Date: Thu, 4 Oct 2012 22:54:20 +0100 Subject: more errors --- lex.c | 4 ++-- trip.rc | 24 ++++++++++++------------ which.c | 31 +++++++++++++------------------ 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/lex.c b/lex.c index 09add71..4a61b40 100644 --- a/lex.c +++ b/lex.c @@ -329,9 +329,9 @@ extern void yyerror(const char *s) { tok = "end of line"; else tok = nprint((lastchar < 32 || lastchar > 126) ? "(decimal %d)" : "'%c'", lastchar); - fprint(2, "line %d: %s near %s\n", lineno - (lastchar == '\n'), s, tok); + fprint(2, "rc: line %d: %s near %s\n", lineno - (lastchar == '\n'), s, tok); } else - fprint(2, "%s\n", s); + fprint(2, "rc: %s\n", s); } extern void scanerror(char *s) { diff --git a/trip.rc b/trip.rc index 1d47813..9c3cbc3 100644 --- a/trip.rc +++ b/trip.rc @@ -140,11 +140,11 @@ eof } '$') fail quoting '$' in heredoc -submatch 'cat<[2=1]} 'line 1: '*' error near if') +prompt='' if (!~ `` $nl {$rc -cif>[2=1]} 'rc: line 1: '*' error near if') fail print syntax error prompt='' if (!~ `` $nl {$rc -icif>[2=1]} *' error') @@ -459,7 +459,7 @@ foo=nest *=nest { ~ $* bar || fail restore of '$*' after local group ~ `{exec>[2=1];$rc -xc 'foo=()'} 'foo=()' || fail -x echo of variable deletion -fn_ff='{' prompt='' if (!~ `` $nl {$rc -cff>[2=1]} 'line 1: '*' error near eof') +fn_ff='{' prompt='' if (!~ `` $nl {$rc -cff>[2=1]} 'rc: line 1: '*' error near eof') fail 'bogus function in environment' # diff --git a/which.c b/which.c index 1dd08f6..0e60a5b 100644 --- a/which.c +++ b/which.c @@ -70,25 +70,17 @@ static bool rc_access(char *path, bool verbose) { return FALSE; } -/* 2012-10-01 I don't know where this routine came from. Obviously I can - * see what it's doing, and were it implemented properly it might be a - * good thing. */ +/* replace non-printing characters with question marks in a freshly + * allocated string */ static char *protect(char *in) { - char *out = ealloc(strlen(in) * 2 + 1); - + int l = strlen(in); + char *out = ealloc(l + 1); int i; - int p = 0; - for (i = 0; i < strlen(in); ++i) { - if (isprint(in[i])) { - out[p++] = in[i]; - } else { - out[p++] = '\\'; - out[p++] = '?'; - } - } - out[p] = '\0'; - return out; /* XXXX */ + for (i = 0; i < l; ++i) + out[i] = isprint(in[i]) ? in[i] : '?'; + out[i] = '\0'; + return out; } /* return a full pathname by searching $path, and by checking the status of the file */ @@ -140,7 +132,10 @@ extern char *which(char *name, bool verbose) { if (rc_access(test, FALSE)) return test; } - if (verbose) - fprint(2, "rc: cannot find `%s'\n", protect(name)); + if (verbose) { + char *n = protect(name); + fprint(2, "rc: cannot find `%s'\n", n); + efree(n); + } return NULL; } -- cgit v1.2.3