Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
0.22.4
Browse files Browse the repository at this point in the history
Fixed a bug in Windows which caused _txtlock to break inkey$()
Added \[ and \] support for colored prompt strings
Allowed _PROMPT and _PROMPTTAB to be called in an autorun
Changed the autorun files
  • Loading branch information
PQCraft authored Sep 24, 2021
1 parent 9df8726 commit e14a1ed
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
61 changes: 32 additions & 29 deletions clibasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@

// Base defines

char VER[] = "0.22.3";
char VER[] = "0.22.4";

#if defined(__linux__)
char OSVER[] = "Linux";
Expand Down Expand Up @@ -242,6 +242,7 @@ bool inprompt = false;

bool runfile = false;
bool runc = false;
bool autorun = false;

bool sh_silent = false;
bool sh_clearAttrib = true;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 10 additions & 5 deletions commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;}
Expand Down
Binary file modified docs/manual.odt
Binary file not shown.
Binary file modified docs/manual.pdf
Binary file not shown.
26 changes: 26 additions & 0 deletions examples/hello.bas
Original file line number Diff line number Diff line change
@@ -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
7 changes: 5 additions & 2 deletions logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
Expand All @@ -57,6 +59,7 @@ if (chkCmd(2, "?", "PRINT")) {
}
}
}
if (newline) putchar('\n');
if (pct || bct || inStr) {cerr = 1; return true;}
fflush(stdout);
return true;
Expand Down

0 comments on commit e14a1ed

Please sign in to comment.