diff --git a/Makefile b/Makefile index b8192b9..294bffb 100644 --- a/Makefile +++ b/Makefile @@ -76,7 +76,7 @@ update: printf "\\e[0m\\e[31;1mAre you sure? [y/N]:\\e[0m "; read -n 1 I; [ ! "$$I" == "" ] && printf "\\n" &&\ ([[ ! "$$I" =~ ^[^Yy]$$ ]] && sh -c 'git restore . && git pull' &> /dev/null && chmod +x *.sh) || exit 0 -install: +install: uninstall if [ ! -f $(BUILD_TO) ]; then $(BUILD__); fi $(INSTALL) diff --git a/README.md b/README.md index 84dc433..8c97485 100644 --- a/README.md +++ b/README.md @@ -72,5 +72,5 @@ To build CLIBASIC with support for VT escape codes, add `vt` before the rest of - Due to Windows not having proper fork() and exec\*() functions, EXEC, EXEC(), and EXEC$() are passed through system() under Windows and one issue out of the many with this is a space parsing issue where running `EXEC "test prog"` will attempt to execute `EXEC "test", "prog"` if `test prog` cannot be found in the current directory or %PATH%. - On Windows, pressing CTRL+C will not display a new prompt line due to the Windows version of readline catching and ignoring the CTRL+C. - If the file `.clibasic_history` is present in the user's home directory CLIBASIC will automatically save history there. Run `_AUTOCMDHIST`, `_SAVECMDHIST` (without any arguments), or create the file `.clibasic_history` in your home/user folder to enable this feature. Remove the file to disable this feature. -- CLIBASIC will look for `AUTORUN.BAS` (and `autorun.bas` on Linux) in the user's home directory and run the file if present. +- CLIBASIC will look for `~/.clibasicrc`, `autorun.bas`, then `.autorun.bas` in this order in the user's home directory and run the first file found. - The development scripts are `build.sh` which is for testing if CLIBASIC compiles correctly for Linux and Windows, `package.sh` which creates the zip files for making a CLIBASIC release, and `release-text.sh` which generates the text for making a CLIBASIC release. diff --git a/clibasic.c b/clibasic.c index 8c6cefd..93b4501 100644 --- a/clibasic.c +++ b/clibasic.c @@ -115,7 +115,7 @@ // Base defines -char VER[] = "0.22.3"; +char VER[] = "0.22.4"; #if defined(__linux__) char OSVER[] = "Linux"; @@ -242,6 +242,7 @@ bool inprompt = false; bool runfile = false; bool runc = false; +bool autorun = false; bool sh_silent = false; bool sh_clearAttrib = true; @@ -605,7 +606,7 @@ int main(int argc, char** argv) { #if defined(GUI_CHECK) && defined(__unix__) if (system("tty -s 1> /dev/null 2> /dev/null")) { char* command = malloc(CB_BUF_SIZE); - copyStr("xterm -T CLIBASIC -b 0 -bg black -bcn 200 -bcf 200 -e $'clear &&", command); + copyStr("xterm -T CLIBASIC -b 0 -bg black -bcn 200 -bcf 200 -e $'clear;", command); for (int i = 0; i < argc; ++i) { copyStrApnd(" $\\'", command); gpbuf[0] = 0; @@ -871,7 +872,11 @@ int main(int argc, char** argv) { FILE* tmpfile = fopen(HIST_FILE, "r"); if ((autohist = (tmpfile != NULL))) {fclose(tmpfile); read_history(HIST_FILE);} inProg = true; - if (!loadProg("AUTORUN.BAS")) if (!loadProg("autorun.bas")) inProg = false; + autorun = true; + if (!loadProg(".clibasicrc")) + if (!loadProg("autorun.bas")) + if (!loadProg(".autorun.bas")) + {autorun = false; inProg = false;} ret = chdir(tmpcwd); (void)ret; } @@ -977,20 +982,18 @@ int main(int argc, char** argv) { bool comment = false; while (1) { #ifdef _WIN32 - if (!textlock) { - char kbc; - int kbh = kbhit(); - for (int i = 0; i < kbh; ++i) { - kbc = _getch(); - kbinbuf[i] = kbc; - putchar(kbc); - if (kbc == 3) { - if (inProg) {goto brkproccmd;} - else {cmdIntHndl();} - } + char kbc; + int kbh = kbhit(); + for (int i = 0; i < kbh; ++i) { + kbc = _getch(); + kbinbuf[i] = kbc; + if (!textlock) putchar(kbc); + if (kbc == 3) { + if (inProg) {goto brkproccmd;} + else {cmdIntHndl();} } - fflush(stdout); } + fflush(stdout); #endif rechk:; if (progindex < 0) {inProg = false;} @@ -1076,20 +1079,18 @@ static inline void cb_wait(uint64_t d) { #else uint64_t t = d + usTime(); while (t > usTime() && !cmdint) { - if (!textlock) { - char kbc; - int kbh = kbhit(); - for (int i = 0; i < kbh; ++i) { - kbc = _getch(); - kbinbuf[i] = kbc; - putchar(kbc); - if (kbc == 3) { - cmdint = true; - return; - } + char kbc; + int kbh = kbhit(); + for (int i = 0; i < kbh; ++i) { + kbc = _getch(); + kbinbuf[i] = kbc; + if (!textlock) putchar(kbc); + if (kbc == 3) { + cmdint = true; + return; } - fflush(stdout); } + fflush(stdout); } #endif } @@ -1187,6 +1188,7 @@ void unloadProg() { proggotomaxct = (int*)realloc(proggotomaxct, progindex * sizeof(int)); progindex--; if (progindex < 0) inProg = false; + if (autorun) autorun = false; } void unloadAllProg() { @@ -1587,6 +1589,8 @@ static inline void getStr(char* str1, char* str2) { case 'v': c = '\v'; break; case 'b': c = '\b'; break; case 'e': c = '\e'; break; + case '[': c = 1; break; + case ']': c = 2; break; case 'x': h[0] = '0'; h[1] = 'x'; @@ -1689,7 +1693,7 @@ uint8_t getFunc(char* inbuf, char* outbuf) { ++getFuncIndex; { int32_t i; - for (i = 0; inbuf[i] != '('; ++i) {if (inbuf[i] >= 'a' && inbuf[i] <= 'z') inbuf[i] = inbuf[i] - 32;} + for (i = 0; inbuf[i] != '('; ++i) {} int32_t j = strlen(inbuf) - 1; copyStrSnip(inbuf, i + 1, j, gftmp[0]); fargct = getArgCt(gftmp[0]); @@ -2731,7 +2735,6 @@ bool runlogic() { while (cmd[j] != ' ' && cmd[j]) {++j;} h = j; while (cmd[h] == ' ') {++h;} - if (cmd[h] == '=') return false; copyStrSnip(cmd, i, j, ltmp[0]); copyStrFrom(cmd, i, cmd); j -= i; diff --git a/commands.c b/commands.c index 12e3cf1..fedbbee 100644 --- a/commands.c +++ b/commands.c @@ -87,14 +87,18 @@ if (chkCmd(3, "%", "GOTO", "GO")) { goto noerr; } if (chkCmd(1, "DIM")) { - if (argct != 3) {cerr = 3; goto cmderr;} + if (argct < 2 || argct > 3) {cerr = 3; goto cmderr;} cerr = 0; if (!solvearg(2)) goto cmderr; - if (!solvearg(3)) goto cmderr; + if (argct == 3 && !solvearg(3)) goto cmderr; if (argt[2] != 2) {cerr = 2; goto cmderr;} int32_t asize = atoi(arg[2]); if (asize < 0) {cerr = 16; goto cmderr;} - if (!setVar(tmpargs[1], arg[3], argt[3], asize)) goto cmderr; + if (!tmpargs[1][0]) {cerr = 4; seterrstr(""); goto cmderr;} + if (!setVar(tmpargs[1],\ + ((argct == 3) ? arg[3] : ((tmpargs[1][argl[1] - 1] == '$') ? "" : "0")),\ + ((argct == 3) ? argt[3] : 2 - (tmpargs[1][argl[1] - 1] == '$')),\ + asize)) goto cmderr; goto noerr; } if (chkCmd(1, "DEL")) { @@ -668,7 +672,7 @@ if (chkCmd(1, "_UNSETENV")) { goto noerr; } if (chkCmd(1, "_PROMPT")) { - if (inProg) {cerr = 254; goto cmderr;} + if (inProg && !autorun) {cerr = 254; goto cmderr;} if (argct != 1) {cerr = 3; goto cmderr;} cerr = 0; if (!solvearg(1)) goto cmderr; @@ -677,12 +681,13 @@ if (chkCmd(1, "_PROMPT")) { goto noerr; } if (chkCmd(1, "_PROMPTTAB")) { - if (inProg) {cerr = 254; goto cmderr;} + if (inProg && !autorun) {cerr = 254; goto cmderr;} if (argct != 1) {cerr = 3; goto cmderr;} cerr = 0; if (!solvearg(1)) goto cmderr; if (argt[1] != 2) {cerr = 2; goto cmderr;} tab_width = atoi(arg[1]); + goto noerr; } if (chkCmd(1, "_AUTOCMDHIST")) { if (inProg) {cerr = 254; goto cmderr;} diff --git a/docs/manual.odt b/docs/manual.odt index 3fd508d..456da07 100644 Binary files a/docs/manual.odt and b/docs/manual.odt differ diff --git a/docs/manual.pdf b/docs/manual.pdf index 837b018..ac1c864 100644 Binary files a/docs/manual.pdf and b/docs/manual.pdf differ diff --git a/examples/hello.bas b/examples/hello.bas new file mode 100644 index 0000000..1f0049f --- /dev/null +++ b/examples/hello.bas @@ -0,0 +1,26 @@ +_TXTLOCK +_TXTATTRIB "TRUECOLOR", 1 +OC = FGC() +R = CINT(RAND(255)): G = CINT(RAND(255)): B = CINT(RAND(255)) +X = 3: Y = RAND(0.5, 1): X = X - Y: Z = RAND(0.5, 1): X = X -Z +IF CINT(RAND(1)) = 1: X = X * -1: ENDIF +IF CINT(RAND(1)) = 1: Y = Y * -1: ENDIF +IF CINT(RAND(1)) = 1: Z = Z * -1: ENDIF +@ LOOP +COLOR RGB(LIMIT(R, 0, 255), LIMIT(G, 0, 255), LIMIT(B, 0, 255)) +PRINT "Hello, World!",, PAD$(CINT(R), 3), PAD$(CINT(G), 3), PAD$(CINT(B), 3),, PAD$(X, 9, " "), PAD$(Y, 9, " "), PAD$(Z, 9, " "); +COLOR OC +PRINT +R = R + X +G = G + Y +B = B + Z +IF R > 255: X = X * -1: ENDIF +IF R < 0: X = X * -1: ENDIF +IF G > 255: Y = Y * -1: ENDIF +IF G < 0: Y = Y * -1: ENDIF +IF B > 255: Z = Z * -1: ENDIF +IF B < 0: Z = Z * -1: ENDIF +WAIT 0.005 +PUT "\r" +LOCATE , CURY() - 1 +GOTO LOOP diff --git a/logic.c b/logic.c index 0f6bcc4..6032f60 100644 --- a/logic.c +++ b/logic.c @@ -12,6 +12,7 @@ if (chkCmd(2, "?", "PRINT")) { while (cmd[j] == ' ') j++; if (cmd[j] == 0) {putchar('\n'); return true;} else {j--;} + bool newline = false; bool inStr = false; bool lookingForSpChar = false; bool sawSpChar = false; @@ -35,9 +36,10 @@ if (chkCmd(2, "?", "PRINT")) { int32_t len = strlen(ltmp[1]); int tmpt; if (!(tmpt = getVal(ltmp[1], ltmp[1]))) return true; + newline = false; if (cmd[j] == ',') { - if (tmpt == 255) {putchar('\n');} - else {putchar('\t');} + if (tmpt == 255 && !cmd[j + 1]) {newline = false;} + putchar('\t'); } fputs(ltmp[1], stdout); if (cmd[i] == 0 && len > 0) putchar('\n'); @@ -57,6 +59,7 @@ if (chkCmd(2, "?", "PRINT")) { } } } + if (newline) putchar('\n'); if (pct || bct || inStr) {cerr = 1; return true;} fflush(stdout); return true;