diff --git a/lttb.awk b/lttb.awk index 86085d3..7613945 100644 --- a/lttb.awk +++ b/lttb.awk @@ -80,12 +80,12 @@ function expreval(expr, valbuf, c, prevc, i, l) { stackpush(VALSTACK, norm(valbuf)) valbuf = "" } - if(substr(toupper(expr), i+1, 3) == "RND") { + if(substr(expr, i+1, 3) == "RND") { stackpush(VALSTACK, 0) c = "$" i += 2 } - if(c ~ /[a-zA-Z]/) stackpush(VALSTACK, norm(VARS[toupper(c)])) + if(c ~ /[A-Z]/) stackpush(VALSTACK, norm(VARS[c])) else if(c == "(") stackpush(OPSTACK, "(") else if(c == ")") { while(stacktop(OPSTACK) != "(" && alen(OPSTACK) > 0) evalhelper() @@ -113,7 +113,7 @@ function do_GOS(stmt) {stackpush(CALLSTACK, IP); do_GO(stmt)} function do_RE(stmt) {IP = stackpop(CALLSTACK)} function do_LE(stmt, vname, eqp, expr) { - vname = toupper(substr(stmt, 1, 1)) + vname = substr(stmt, 1, 1) if(vname ~ /[A-Z]/) { eqp = index(stmt, "=") expr = substr(stmt, eqp + 1) @@ -136,7 +136,7 @@ function do_IF(stmt, ropos, roend, relop, thenpos, rest, restpos, kw, expr1, ex thenpos = 0 for(k=1; k<=10; k++) { kw = IF_KWS[k] - thenpos = index(toupper(rest), kw) + thenpos = index(rest, kw) if(thenpos > 0) { if(kw == "=") thenpos-- restpos = thenpos @@ -160,13 +160,13 @@ function do_IF(stmt, ropos, roend, relop, thenpos, rest, restpos, kw, expr1, ex function do_IN(stmt, v, i, l) { gsub("[[:space:]]+", "", stmt) - l = split(stmt, varlist, ",") + l = split(toupper(stmt), varlist, ",") printf "? " inputstr = ttyinput() gsub("[[:space:]]+", "", inputstr) split(toupper(inputstr), inputlist, ",") for(i=1;i<=l;i++) { - v = toupper(substr(varlist[i], 1, 1)) + v = substr(varlist[i], 1, 1) VARS[v] = expreval(inputlist[i]) } } @@ -206,7 +206,7 @@ function do_EN(stmt) {IP = -1; split("", CALLSTACK)} # Program line execution function function progexec(stmt, kw, ws, body) { - kw = toupper(substr(stmt, 1, 2)) + kw = substr(stmt, 1, 2) if(substr(kw, 2, 1) == "=") { kw = "LE" stmt = "LE " stmt @@ -217,7 +217,7 @@ function progexec(stmt, kw, ws, body) { if(ws > 0) body = wstrim(substr(stmt, ws)) else body = "" if(kw == "GO") { - if(substr(toupper(stmt), 3, 1) == "S") do_GOS(body) + if(substr(stmt, 3, 1) == "S") do_GOS(body) else do_GO(body) } else if(kw == "LE") do_LE(body) else if(kw == "IF") do_IF(body) @@ -240,7 +240,7 @@ function proginput(stmt, lno, i, l, c) { } stmt = substr(stmt, i+1) if(lno > 0) PROGMEM[lno] = stmt - else if(index(toupper(stmt), "REM") != 1) progexec(stmt) + else if(index(stmt, "REM") != 1) progexec(stmt) } # Clearing action @@ -259,8 +259,8 @@ function ext_LOAD(fname, err, s) { print "Error: File " fname " does not exist or cannot be read." return } - if(err > 0) proginput(wstrim(s)) - while((getline s < fname) > 0) proginput(wstrim(s)) + if(err > 0) proginput(toupper(wstrim(s))) + while((getline s < fname) > 0) proginput(toupper(wstrim(s))) close(fname) } @@ -279,7 +279,7 @@ function ext_LIST(fname, i, sep) { function ext_RUN() { for(IP = 1; IP > 0 && IP < 32768; IP++) - if(IP in PROGMEM && length(PROGMEM[IP]) > 0 && index(toupper(PROGMEM[IP]), "REM") != 1) + if(IP in PROGMEM && length(PROGMEM[IP]) > 0 && index(PROGMEM[IP], "REM") != 1) progexec(PROGMEM[IP]) } @@ -306,17 +306,17 @@ BEGIN { END { while(1) { printf "> " - cmd = wstrim(ttyinput()) + cmd = toupper(ttyinput()) if(length(cmd) > 0) { - if(toupper(cmd) == "BYE") {print "Bye!"; break} - else if(toupper(cmd) == "RUN") ext_RUN() - else if(toupper(cmd) == "LIST") ext_LIST("") - else if(toupper(cmd) == "NEW" || toupper(cmd) == "CLEAR") ext_CLEAR() - else if(toupper(cmd) == "LOAD") { + if(cmd == "BYE") {print "Bye!"; break} + else if(cmd == "RUN") ext_RUN() + else if(cmd == "LIST") ext_LIST("") + else if(cmd == "NEW" || cmd == "CLEAR") ext_CLEAR() + else if(cmd == "LOAD") { printf "File name: " ext_LOAD(ttyinput()) } - else if(toupper(cmd) == "SAVE") { + else if(cmd == "SAVE") { printf "File name: " ext_LIST(ttyinput()) } diff --git a/test.bas b/test.bas index ea7235a..8d3d63c 100644 --- a/test.bas +++ b/test.bas @@ -1,4 +1,6 @@ 5 rem This is a comment and should never be executed + +9 rem Program loaders should ignore empty lines correctly 10 print "Luxferre's Truly Tiny BASIC test suite" 15 print "" 20 print "All lines should end with OK to pass"