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

Commit

Permalink
0.28.1
Browse files Browse the repository at this point in the history
Fixed small error in docs
Fixed possible bug in getFunc
Fixed a bug in GOTO
Miscellaneous bugfixes
Run autorun before everything
  • Loading branch information
PQCraft committed Oct 27, 2021
1 parent 5d695ea commit 15502b5
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 70 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ To build, use `make build`. <br>
To run, use `make run` or `./clibasic`. <br>
To build then run, use `make` (same as `make all`). <br>
#### Windows <br>
Make sure you have downloaded the readline lib folder from [here](https://github.com/PQCraft/clibasic-winrllib)
Make sure you have downloaded the readline lib folder from [here](https://github.com/PQCraft/clibasic-winrllib).
1. Download the ZIP
2. Go into the .zip file you downloaded
3. Copy the `lib` folder in `clibasic-winrllib-master`
Expand Down
121 changes: 54 additions & 67 deletions clibasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@

// Base defines

char VER[] = "0.28";
char VER[] = "0.28.1";

#if defined(__linux__)
char OSVER[] = "Linux";
Expand Down Expand Up @@ -257,6 +257,7 @@ bool redirection = false;
bool checknl = false;
bool esc = true;
bool cpos = true;
bool skip = false;

bool sh_silent = false;
bool sh_clearAttrib = true;
Expand Down Expand Up @@ -751,6 +752,27 @@ static inline void readyTerm() {
enablevt();
#endif
#endif
if (!gethome()) {
#ifndef _WIN32
fputs("Could not find home folder! Please set the 'HOME' environment variable.\n", stderr);
#else
fputs("Could not find home folder!\n", stderr);
#endif
} else if (!skip) {
char* tmpcwd = getcwd(NULL, 0);
int ret = chdir(homepath);
bool tmp_inProg = inProg;
inProg = true;
autorun = true;
argslater = false;
if (!loadProg(".clibasicrc"))
if (!loadProg("autorun.bas"))
if (!loadProg(".autorun.bas"))
{autorun = false; inProg = tmp_inProg;}
ret = chdir(tmpcwd);
nfree(tmpcwd);
(void)ret;
}
}

uint8_t roptptr = 1;
Expand All @@ -762,7 +784,6 @@ char roptstr[16] = "-";

int main(int argc, char** argv) {
bool pexit = false;
bool skip = false;
bool info = false;
#ifndef _WIN32
tcgetattr(0, &initterm);
Expand Down Expand Up @@ -818,7 +839,6 @@ int main(int argc, char** argv) {
if (runfile) {unloadProg(); IOCT(); exit(1);}
++i;
if (!argv[i]) {fputs("No filename provided.\n", stderr); exit(1);}
readyTerm();
argslater = true;
if (!loadProg(argv[i])) {printError(cerr); exit(1);}
inProg = true;
Expand Down Expand Up @@ -867,28 +887,12 @@ int main(int argc, char** argv) {
} else if (!strcmp(argv[i], "--command") || (shortopt && argv[i][shortopti] == 'c')) {
if (shortopt && argv[i][shortopti + 1]) {RARG(); exit(1);}
if (runfile) {fputs("Cannot run file and command.\n", stderr); exit(1);}
readyTerm();
if (runc) {IOCT(); exit(1);}
i++;
if (!argv[i]) {fputs( "No command provided.\n", stderr); exit(1);}
runc = true;
runfile = true;
copyStr(argv[i], conbuf);
bool inStr = false;
bool sawCmd = false;
for (int32_t i = 0; conbuf[i]; ++i) {
switch (conbuf[i]) {
case 'a' ... 'z':;
if (!inStr) conbuf[i] = conbuf[i] - 32;
break;
case '"':;
inStr = !inStr;
break;
case ' ':;
if (!sawCmd) {sawCmd = true; inStr = false;}
break;
}
}
} else {
if (shortopt) {
fprintf(stderr, "Invalid short option '%c'.\n", argv[i][shortopti]); exit(1);
Expand All @@ -900,7 +904,6 @@ int main(int argc, char** argv) {
if (runc) {fputs("Cannot run command and file.\n", stderr); exit(1);}
if (runfile) {unloadProg(); IOCT(); exit(1);}
if (!argv[i]) {fputs("No filename provided.\n", stderr); exit(1);}
readyTerm();
argslater = true;
if (!loadProg(argv[i])) {printError(cerr); exit(1);}
inProg = true;
Expand Down Expand Up @@ -999,8 +1002,6 @@ int main(int argc, char** argv) {
startcmd = argv[0];
}
skipscargv:;
getCurPos();
if (curx != 1) putchar('\n');
txtattrib.fgce = true;
txtattrib.fgc = 15;
txtattrib.truefgc = 0xFFFFFF;
Expand All @@ -1027,34 +1028,19 @@ int main(int argc, char** argv) {
arg = NULL;
srand(usTime());
if (!runfile) {
if (!gethome()) {
#ifndef _WIN32
fputs("Could not find home folder! Please set the 'HOME' environment variable.\n", stderr);
#else
fputs("Could not find home folder!\n", stderr);
#endif
} else if (!skip) {
char* tmpcwd = getcwd(NULL, 0);
int ret = chdir(homepath);
FILE* tmpfile = fopen(HIST_FILE, "r");
if ((autohist = (tmpfile != NULL))) {
fclose(tmpfile);
read_history(HIST_FILE);
history_set_pos(history_length);
HIST_ENTRY* tmphist = history_get(where_history());
if (tmphist) copyStr(tmphist->line, cmpstr);
}
inProg = true;
autorun = true;
argslater = true;
if (!loadProg(".clibasicrc"))
if (!loadProg("autorun.bas"))
if (!loadProg(".autorun.bas"))
{autorun = false; inProg = false; argslater = false;}
ret = chdir(tmpcwd);
nfree(tmpcwd);
(void)ret;
char* tmpcwd = getcwd(NULL, 0);
int ret = chdir(homepath);
FILE* tmpfile = fopen(HIST_FILE, "r");
if ((autohist = (tmpfile != NULL))) {
fclose(tmpfile);
read_history(HIST_FILE);
history_set_pos(history_length);
HIST_ENTRY* tmphist = history_get(where_history());
if (tmphist) copyStr(tmphist->line, cmpstr);
}
ret = chdir(tmpcwd);
free(tmpcwd);
(void)ret;
}
cerr = 0;
initBaseMem();
Expand Down Expand Up @@ -1807,23 +1793,24 @@ uint8_t getFunc(char* inbuf, char* outbuf) {
flen[0] = i;
farg[0] = (char*)malloc(flen[0] + 1);
copyStrTo(inbuf, i, farg[0]);
if (!strcmp(farg[0], "~") || !strcmp(farg[0], "_TEST")) {
ftype = 2;
if (fargct != 1) {cerr = 3; goto fexit;}
cerr = 0;
if (getArgO(0, gftmp[0], gftmp[1], 0) == -1) {outbuf[0] = 0; goto fexit;}
int ret = logictest(gftmp[1]);
if (ret == -1) {outbuf[0] = 0; goto fexit;}
outbuf[0] = '0' + ret;
outbuf[1] = 0;
goto fexit;
} else if (!strcmp(farg[0], "EXECA") || !strcmp(farg[0], "EXECA$")) {
skipfargsolve = true;
} else {
for (int i = extmaxct - 1; i > -1; --i) {
if (extdata[i].inuse && extdata[i].chkfuncsolve) {
if ((skipfargsolve = extdata[i].chkfuncsolve(farg[0]))) {extsas = i; break;}
}
for (int i = extmaxct - 1; i > -1; --i) {
if (extdata[i].inuse && extdata[i].chkfuncsolve) {
if ((skipfargsolve = extdata[i].chkfuncsolve(farg[0]))) {extsas = i; break;}
}
}
if (extsas == -1) {
if (!strcmp(farg[0], "~") || !strcmp(farg[0], "_TEST")) {
ftype = 2;
if (fargct != 1) {cerr = 3; goto fexit;}
cerr = 0;
if (getArgO(0, gftmp[0], gftmp[1], 0) == -1) {outbuf[0] = 0; goto fexit;}
int ret = logictest(gftmp[1]);
if (ret == -1) {outbuf[0] = 0; goto fexit;}
outbuf[0] = '0' + ret;
outbuf[1] = 0;
goto fexit;
} else if (!strcmp(farg[0], "EXECA") || !strcmp(farg[0], "EXECA$")) {
skipfargsolve = true;
}
}
} else {
Expand Down Expand Up @@ -2273,7 +2260,7 @@ uint8_t getVal(char* inbuf, char* outbuf) {
case '[': bct++; break;
case ']': bct--; break;
default:;
if (inbuf[jp] != '-' && isSpChar(inbuf[jp]) && !pct && !bct) goto gvwhileexit1;
if ((inbuf[jp] != '-' || jp > 0) && isSpChar(inbuf[jp]) && !pct && !bct) goto gvwhileexit1;
break;
}
}
Expand Down
3 changes: 3 additions & 0 deletions commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ if (chkCmd(3, "%", "GOTO", "GO")) {
concp = gotodata[i].cp;
}
progLine = gotodata[i].pl;
dlstackp = gotodata[i].dlsp;
fnstackp = gotodata[i].fnsp;
itstackp = gotodata[i].itsp;
gotodata[i].used = false;
bool r = false;
while (gotomaxct > 0 && !gotodata[gotomaxct - 1].used) {--gotomaxct; r = true;}
Expand Down
2 changes: 1 addition & 1 deletion docs
Submodule docs updated 2 files
+ manual.odt
+ manual.pdf
2 changes: 1 addition & 1 deletion examples
Submodule examples updated 2 files
+1 −2 blockpix.bas
+0 −1 snake.bas

0 comments on commit 15502b5

Please sign in to comment.