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

Commit

Permalink
0.12.10
Browse files Browse the repository at this point in the history
Modified examples
Attempted to fix INKEY$() on Windows
  • Loading branch information
PQCraft authored Apr 2, 2021
1 parent 0877495 commit 24cb96b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 48 deletions.
20 changes: 9 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
C = gcc

CFLAGS = -Wall -Wextra -O2 -ffreestanding -lm -lreadline --std=c99

CBITS = $(shell getconf LONG_BIT)

BUILD__ = $(C) clibasic.c $(CFLAGS) -D B$(CBITS) -o clibasic && chmod +x ./clibasic
BUILD32 = $(C) clibasic.c -m32 $(CFLAGS) -D B32 -o clibasic && chmod +x ./clibasic

all:
rm -f ./clibasic
$(C) clibasic.c $(CFLAGS) -D B$(CBITS) -o clibasic
chmod +x ./clibasic
$(BUILD__)
./clibasic

all32:
rm -f ./clibasic
$(C) clibasic.c -m32 $(CFLAGS) -D B32 -o clibasic
chmod +x ./clibasic
$(BUILD32)
./clibasic

build:
$(C) clibasic.c $(CFLAGS) -D B$(CBITS) -o clibasic
chmod +x ./clibasic
$(BUILD__)

build32:
$(C) clibasic.c -m32 $(CFLAGS) -D B32 -o clibasic
chmod +x ./clibasic
$(BUILD32)

update:
curl https://raw.githubusercontent.com/PQCraft/clibasic/master/clibasic.c > .tmp
Expand All @@ -42,11 +40,11 @@ update:
mv .tmp Makefile

install:
if [ ! -f ./clibasic ]; then $(C) clibasic.c $(CFLAGS) -D B$(CBITS) -o clibasic; chmod +x ./clibasic; fi
if [ ! -f ./clibasic ]; then $(BUILD__); fi
sudo rm -f /usr/bin/clibasic; sudo cp ./clibasic /usr/bin/clibasic

install32:
if [ ! -f ./clibasic ]; then $(C) clibasic.c -m32 $(CFLAGS) -D B32 -o clibasic; chmod +x ./clibasic; fi
if [ ! -f ./clibasic ]; then $(BUILD32); fi
sudo rm -f /usr/bin/clibasic; sudo cp ./clibasic /usr/bin/clibasic

run:
Expand Down
22 changes: 8 additions & 14 deletions Makefile-Windows
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
C = gcc

CFLAGS = -Werror -O2 -ffreestanding -lm --std=c99
CFLAGS = -O2 -ffreestanding -lm --std=c99

BUILD64 = $(C) clibasic.c -m64 $(CFLAGS) -D B64 -o clibasic.exe
BUILD32 = $(C) clibasic.c -m32 $(CFLAGS) -D B32 -o clibasic.exe

all:
del /q /f clibasic.exe
$(C) clibasic.c -m64 $(CFLAGS) -D B64 -o clibasic.exe
$(BUILD64)
.\clibasic.exe

all32:
del /q /f clibasic.exe
$(C) clibasic.c -m32 $(CFLAGS) -D B32 -o clibasic.exe
$(BUILD32)
.\clibasic.exe

build:
$(C) clibasic.c -m64 $(CFLAGS) -D B64 -o clibasic.exe
$(BUILD64)

build32:
$(C) clibasic.c -m32 $(CFLAGS) -D B32 -o clibasic.exe

#update:


#install:


#install32:

$(BUILD32)

run:
.\clibasic.exe
Expand Down
34 changes: 17 additions & 17 deletions clibasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#include <readline/history.h>
#endif

char VER[] = "0.12.9";
char VER[] = "0.12.10";

#ifndef BUFSIZE
#define BUFSIZE 32768
#ifndef CB_BUF_SIZE
#define CB_BUF_SIZE 32768
#endif

#if defined(__linux__)
Expand All @@ -32,6 +32,7 @@ char VER[] = "0.12.9";
char OSVER[] = "Windows";
//(https://pbs.twimg.com/media/CRcU7BKWwAEQZIE.jpg)
#include <windows.h>
#include <conio.h>
#define SIGKILL 9
char* rlptr;
void cleanExit();
Expand All @@ -45,7 +46,7 @@ char VER[] = "0.12.9";
//(https://theenglishfarm.com/sites/default/files/styles/featured_image/public/harold_2.jpg?itok=uo6h4hz4)
printf(prompt);
fflush(stdout);
char buf[BUFSIZE];
char buf[CB_BUF_SIZE];
buf[0] = 0;
int inct = scanf("%[^\n]s", &buf);
if (inct != 1 && inct != 0) raise(SIGINT);
Expand Down Expand Up @@ -123,10 +124,10 @@ int fnstackp = -1;
*/
char* errstr;

char conbuf[BUFSIZE];
char lastcb[BUFSIZE];
char prompt[BUFSIZE];
char pstr[BUFSIZE];
char conbuf[CB_BUF_SIZE];
char lastcb[CB_BUF_SIZE];
char prompt[CB_BUF_SIZE];
char pstr[CB_BUF_SIZE];

uint8_t fgc = 15;
uint8_t bgc = 0;
Expand Down Expand Up @@ -267,7 +268,6 @@ int main(int argc, char* argv[]) {
resetTimer();
#ifndef _WIN32
rl_getc_function = getc;
signal(SIGWINCH, (__sighandler_t)rl_resize_terminal);
#endif
while (!exit) {
fchkint:
Expand Down Expand Up @@ -541,7 +541,7 @@ void updateTxtAttrib() {
}

void getStr(char* str1, char* str2) {
char buf[BUFSIZE];
char buf[CB_BUF_SIZE];
int j = 0, i;
for (i = 0; str1[i] != 0; i++) {
char c = str1[i];
Expand Down Expand Up @@ -592,7 +592,7 @@ int getArgCt(char* inbuf);

uint8_t getFunc(char* inbuf, char* outbuf) {
if (debug) printf("getFunc(\"%s\", \"%s\");\n", inbuf, outbuf);
char tmp[2][BUFSIZE];
char tmp[2][CB_BUF_SIZE];
char** farg;
uint8_t *fargt;
int* flen;
Expand Down Expand Up @@ -738,11 +738,11 @@ bool gvchkchar(char* tmp, int i) {
uint8_t getVal(char* tmpinbuf, char* outbuf) {
if (debug) printf("getVal(\"%s\", \"%s\");\n", tmpinbuf, outbuf);
if (tmpinbuf[0] == 0) {return 255;}
char inbuf[BUFSIZE];
char inbuf[CB_BUF_SIZE];
copyStr(tmpinbuf, inbuf);
outbuf[0] = 0;
int ip = 0, jp = 0;
char tmp[4][BUFSIZE];
char tmp[4][CB_BUF_SIZE];
uint8_t t = 0;
uint8_t dt = 0;
bool inStr = false;
Expand Down Expand Up @@ -927,7 +927,7 @@ uint8_t getVal(char* tmpinbuf, char* outbuf) {
}

bool solvearg(int i) {
char tmpbuf[BUFSIZE];
char tmpbuf[CB_BUF_SIZE];
if (i == 0) {
argt[0] = 0;
arg[0] = tmpargs[0];
Expand Down Expand Up @@ -979,7 +979,7 @@ int getArg(int num, char* inbuf, char* outbuf) {
}

void mkargs() {
char tmpbuf[2][BUFSIZE];
char tmpbuf[2][CB_BUF_SIZE];
int j = 0;
while (cmd[j] == ' ') {j++;}
int h = j;
Expand Down Expand Up @@ -1026,7 +1026,7 @@ void mkargs() {

uint8_t logictest(char* inbuf) {
if (debug) printf("logictest(\"%s\");\n", inbuf);
char tmp[3][BUFSIZE];
char tmp[3][CB_BUF_SIZE];
int tmpp = 0;
uint8_t t1 = 0;
uint8_t t2 = 0;
Expand Down Expand Up @@ -1114,7 +1114,7 @@ uint8_t logictest(char* inbuf) {
}

bool runlogic() {
char tmp[2][BUFSIZE];
char tmp[2][CB_BUF_SIZE];
tmp[0][0] = 0; tmp[1][0] = 0;
int i = 0;
while (cmd[i] == ' ') {i++;}
Expand Down
7 changes: 4 additions & 3 deletions examples/test3.bas
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
_txtlock
do
k$ = inkey$()
if asc(k$) <> 0
print k$
print "Polling..."
k = asc(inkey$())
if k <> 0
print k
endif
loop
8 changes: 5 additions & 3 deletions functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,18 @@ if (chkCmd(1, farg[0], "INKEY$")) {
while ((outbuf[0] == 27 && tmp != 0) || outbuf[0] == 0) {
obp++;
tmp = read(1, &outbuf[obp], 1);
if (tmp == 0) {outbuf[obp] = 0; break;}
if (tmp == -1) {outbuf[obp] = 0; break;}
if (tmp < 1) {outbuf[obp] = 0; break;}
if (obp == 2 && !(outbuf[obp] >= 49 && outbuf[obp] <= 51)) {outbuf[obp + 1] = 0; break;}
if (obp == 3 && outbuf[obp] >= 126) {outbuf[obp + 1] = 0; break;}
if (obp == 4 && outbuf[obp] >= 126) {outbuf[obp + 1] = 0; break;}
if (outbuf[obp] == 3) {outbuf[obp] = 0; cmdint = true; break;}
}
obp++;
outbuf[obp] = 0;
disableRawMode();
#else
fflush(stdin);
outbuf[0] = getchar();
outbuf[0] = _getch();
outbuf[1] = 0;
#endif
goto fexit;
Expand Down

0 comments on commit 24cb96b

Please sign in to comment.