rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit d1f7167ce21da3e3f4ee051b2fdd24fc9607bbdc
parent 826eea2e08a9ec4254ccbd4d12fcd7828f8c413d
Author: Toby Goodwin <LibreSoftwareDesign@gmail.com>
Date:   Thu,  4 Oct 2012 22:54:20 +0100

more errors

Diffstat:
Mlex.c | 4++--
Mtrip.rc | 24++++++++++++------------
Mwhich.c | 31+++++++++++++------------------
3 files changed, 27 insertions(+), 32 deletions(-)

diff --git 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 @@ -140,11 +140,11 @@ eof } '$') fail quoting '$' in heredoc -submatch 'cat<<eof' 'heredoc incomplete' 'incomplete heredoc' +submatch 'cat<<eof' 'rc: heredoc incomplete' 'incomplete heredoc' submatch 'cat<<eof -' 'heredoc incomplete' 'incomplete heredoc' +' 'rc: heredoc incomplete' 'incomplete heredoc' -submatch 'cat<<(eof eof)' 'eof-marker not a single literal word' 'bad heredoc marker' +submatch 'cat<<(eof eof)' 'rc: eof-marker not a single literal word' 'bad heredoc marker' # # lexical analysis @@ -169,13 +169,13 @@ if (! x=`{wc -c /tmp/$pid.lq} ~ $x(1) 1088) rm /tmp/$pid.lw rm /tmp/$pid.lq -submatch 'echo hi |[2' 'expected ''='' or '']'' after digit' 'scan error' -submatch 'echo hi |[92=]' 'expected digit after ''=''' 'scan error' -submatch 'echo hi |[a]' 'expected digit after ''[''' 'scan error' -submatch 'echo hi |[2-' 'expected ''='' or '']'' after digit' 'scan error' -submatch 'echo hi |[2=99a]' 'expected '']'' after digit' 'scan error' -submatch 'echo hi |[2=a99]' 'expected digit or '']'' after ''=''' 'scan error' -submatch 'echo ''hi' 'eof in quoted string' 'scan error' +submatch 'echo hi |[2' 'rc: expected ''='' or '']'' after digit' 'scan error' +submatch 'echo hi |[92=]' 'rc: expected digit after ''=''' 'scan error' +submatch 'echo hi |[a]' 'rc: expected digit after ''[''' 'scan error' +submatch 'echo hi |[2-' 'rc: expected ''='' or '']'' after digit' 'scan error' +submatch 'echo hi |[2=99a]' 'rc: expected '']'' after digit' 'scan error' +submatch 'echo hi |[2=a99]' 'rc: expected digit or '']'' after ''=''' 'scan error' +submatch 'echo ''hi' 'rc: eof in quoted string' 'scan error' ifs='' { if (!~ 'h i' `{echo -n h\ @@ -197,7 +197,7 @@ if (! $rc -c '# eof in comment') # test the syntax error printer -prompt='' if (!~ `` $nl {$rc -cif>[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 @@ -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; }