Skip to content

Commit

Permalink
report lineno while meet the error
Browse files Browse the repository at this point in the history
  • Loading branch information
dongyx committed May 6, 2022
1 parent 5749e94 commit 432f604
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 7 deletions.
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.PHONY: all install test clean

version = 0.0.0
prefix = /usr/local
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
Expand Down Expand Up @@ -33,15 +32,18 @@ test: all
bname=`basename $${in%%.*}`; \
echo running test $${bname}...; \
out=testenv/$${bname}.out; \
ans=test/$${bname}.out; \
<$$in ./shsub >$$out; \
diff -u $$ans $$out; \
err=testenv/$${bname}.err; \
ansout=test/$${bname}.out; \
anserr=test/$${bname}.err; \
<$$in ./shsub >$$out 2>$$err; \
[ -f $$ansout ] && diff -u $$ansout $$out; \
[ -f $$anserr ] && diff -u $$anserr $$err; \
done; \
echo all tests passed

shsub: shsub.sh usage LICENSE
shsub: shsub.sh usage LICENSE version
m4 \
-D__version__='$(version)' \
-D__version__="`cat version`" \
-D__license__="`cat LICENSE`" \
-D__usage__="`cat usage`" \
shsub.sh > shsub
Expand Down
6 changes: 5 additions & 1 deletion tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ int cstack[TOKSIZ], cssize;
int popc(void);
int pushc(int c);

int lineno = 1;
char token[TOKSIZ];
enum token gettok(void);
int dryread(char *s);
Expand All @@ -68,6 +69,8 @@ main()
puts("set -e");
for (st = SINIT; st != STERM && st != SERR; st = next) {
in = gettok();
if (token[0] == '\n')
lineno++;
if (in == ESCOPEN)
strcpy(token, "<%");
if (in == ESCCLS)
Expand Down Expand Up @@ -117,7 +120,8 @@ void entrexp(enum state from, enum token in)

void entrerr(enum state from, enum token in)
{
fprintf(stderr, "illegal token: %s", token);
fprintf(stderr, "shsub: illegal token %s at line %d\n",
token, lineno);
exit(ESYNTAX);
}

Expand Down
1 change: 1 addition & 0 deletions test/5.err
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shsub: illegal token %> at line 2
2 changes: 2 additions & 0 deletions test/5.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<% echo hello world %>
%> this line has an error
1 change: 1 addition & 0 deletions test/6.err
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shsub: illegal token %> at line 1
4 changes: 4 additions & 0 deletions test/6.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%>
<%
<% echo hello world %>
%> this line has an error
1 change: 1 addition & 0 deletions version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1

0 comments on commit 432f604

Please sign in to comment.