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

Commit

Permalink
0.14.1
Browse files Browse the repository at this point in the history
Stopped CLIBASIC from trying to load directories.
  • Loading branch information
PQCraft authored Apr 28, 2021
1 parent af08cf6 commit 36adcbe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
22 changes: 20 additions & 2 deletions clibasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#include <setjmp.h>
#include <stdbool.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>

int tab_width = 4;

Expand Down Expand Up @@ -58,7 +60,7 @@ int tab_width = 4;
}
#endif

char VER[] = "0.14";
char VER[] = "0.14.1";

#ifndef CB_BUF_SIZE
#define CB_BUF_SIZE 32768
Expand Down Expand Up @@ -265,6 +267,7 @@ uint8_t getVal(char* inbuf, char* outbuf);
void resetTimer();
void loadProg();
void updateTxtAttrib();
bool isFile();

char* gethome() {
if (!homepath) {
Expand Down Expand Up @@ -345,6 +348,7 @@ int main(int argc, char* argv[]) {
progFilename = malloc(strlen(argv[i]) + 1);
copyStr(argv[i], progFilename);
if (!prog) {fprintf(stderr, "File not found: '%s'.\n", progFilename); free(progFilename); err = ENOENT; cleanExit();}
if (!isFile(progFilename)) {puts("Expected file instead of directory."); err = EISDIR; cleanExit();}
}
}
if (exit) cleanExit();
Expand Down Expand Up @@ -394,7 +398,9 @@ int main(int argc, char* argv[]) {
prog = fopen("AUTORUN.BAS", "r"); progFilename = malloc(12); strcpy(progFilename, "AUTORUN.BAS");
if (!prog) {prog = fopen("autorun.bas", "r"); strcpy(progFilename, "autorun.bas");}
if (!prog) {free(progFilename);}
else {loadProg(); inProg = true;}
else {
if (isFile(progFilename)) {loadProg(); inProg = true;}
}
ret = chdir(tmpcwd);
(void)ret;
}
Expand Down Expand Up @@ -530,6 +536,12 @@ void wait(uint64_t d) {
#endif
}

bool isFile(char *path) {
struct stat pathstat;
stat(path, &pathstat);
return (bool)(S_ISREG(pathstat.st_mode));
}

void getCurPos() {
fflush(stdout);
cury = 0; curx = 0;
Expand Down Expand Up @@ -1460,6 +1472,12 @@ void runcmd() {
case 17:
printf("Cannot change to directory '%s'", errstr);
break;
case 18:
fputs("Expected file instead of directory.", stdout);
break;
case 19:
fputs("Expected directory instead of file.", stdout);
break;
case 127:
printf("Not a function: '%s'", errstr);
break;
Expand Down
1 change: 1 addition & 0 deletions commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ if (chkCmd(1, arg[0], "RUN")) {
}
progFilename = malloc(argl[1] + 1);
copyStr(arg[1], progFilename);
if (!isFile(progFilename)) {cerr = 18; goto cmderr;}
loadProg();
chkinProg = true;
goto cmderr;
Expand Down

0 comments on commit 36adcbe

Please sign in to comment.