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

Commit

Permalink
0.11.1
Browse files Browse the repository at this point in the history
Bug fixes
Added more text formatting commands
  • Loading branch information
PQCraft authored Mar 6, 2021
1 parent c044240 commit 76d2cd7
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 26 deletions.
65 changes: 40 additions & 25 deletions clibasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@
#include <editline.h>
#include <readline/history.h>

char VER[] = "0.11";
char VER[] = "0.11.1";

FILE *prog;
FILE *f[256];

int err = 0;
int cerr;
int err = 0;
int cerr;

bool inProg = false;
char *progFilename;
int progLine = 1;

int *varlen;
char **varstr;
char **varname;
bool *varinuse;
int *varlen;
char **varstr;
char **varname;
bool *varinuse;
uint8_t *vartype;
int varmaxct;
int varmaxct;

char *cmd;
int cmdl;
char *cmd;
int cmdl;
char **tmpargs;
char **arg;
uint8_t *argt;
int *argl;
int argct = 0;
char **arg;
uint8_t *argt;
int *argl;
int argct = 0;

int cmdpos;

Expand Down Expand Up @@ -75,18 +75,24 @@ bool cmdint = false;
bool debug = false;
bool runfile = false;

bool textlock = false;
struct termios term, restore;

void forceExit() {
//printf("\n");
if (textlock) {tcsetattr(0, TCSANOW, &restore); textlock = false;}
exit(0);
}

void getCurPos();

void cleanExit() {
if (textlock) {tcsetattr(0, TCSANOW, &restore); textlock = false;}
signal(SIGINT, forceExit);
signal(SIGKILL, forceExit);
signal(SIGTERM, forceExit);
printf("\e[0m");
fflush(stdout);
fflush(stdin);
getCurPos();
if (curx != 1) printf("\n");
exit(err);
Expand All @@ -108,6 +114,8 @@ int main(int argc, char *argv[]) {
signal(SIGINT, cleanExit);
signal(SIGKILL, cleanExit);
signal(SIGTERM, cleanExit);
getCurPos();
if (curx != 1) printf("\n");
bool exit = false;
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "--version") || !strcmp(argv[i], "-v")) {
Expand Down Expand Up @@ -155,7 +163,7 @@ int main(int argc, char *argv[]) {
while (!exit) {
for (int i = 0; i < 32768; i++) conbuf[i] = 0;
if (!inProg) {
if (runfile) cleanExit();
if (runfile) {if (textlock) {tcsetattr(0, TCSANOW, &restore); textlock = false;} cleanExit();}
char *tmpstr = NULL;
int tmpt = getVal(prompt, pstr);
if (tmpt != 1) strcpy(pstr, "CLIBASIC> ");
Expand Down Expand Up @@ -184,7 +192,7 @@ int main(int argc, char *argv[]) {
progLine = 1;
while (true) {
if (!inProg) {
if (cmdint) {cmdint = false; goto brkproccmd;}
if (cmdint) {if (textlock) {tcsetattr(0, TCSANOW, &restore); textlock = false;} cmdint = false; goto brkproccmd;}
if (conbuf[cp] == '"') {inStr = !inStr; cmdl++;} else
if ((conbuf[cp] == ':' && !inStr) || conbuf[cp] == '\0') {
while ((conbuf[cp - cmdl] == ' ') && cmdl > 0) {cmdl--;}
Expand All @@ -205,6 +213,10 @@ int main(int argc, char *argv[]) {
if (fgrabc(prog, cp - cmdl - 1) == '\n' && !lockpl) {progLine++; if (debug) printf("found nl: [%ld]\n", cp);}
if (lockpl) lockpl = false;
while ((fgrabc(prog, cp - cmdl) == ' ' || (fgrabc(prog, cp) == '\r' && fgrabc(prog, cp - cmdl) == '\n')) && cmdl > 0) {cmdl--;}
if (fgrabc(prog, cp - cmdl) == '\'') {
while (fgrabc(prog, cp - cmdl) != '\r' && fgrabc(prog, cp - cmdl) != '\n' && fgrabc(prog, cp - cmdl) != -1 && fgrabc(prog, cp - cmdl) != 4 && fgrabc(prog, cp - cmdl) != 0) {cmdl--;}
if (fgrabc(prog, cp - cmdl) == '\r') {cmdl--;}
}
cmd = realloc(cmd, (cmdl + 1) * sizeof(char));
cmdpos = cp - cmdl;
copyFileSnip(prog, cp - cmdl, cp, cmd);
Expand All @@ -219,7 +231,9 @@ int main(int argc, char *argv[]) {
}
brkproccmd:
signal(SIGINT, cleanExit);
if (textlock) {tcsetattr(0, TCSANOW, &restore); textlock = false;}
}
if (textlock) {tcsetattr(0, TCSANOW, &restore); textlock = false;}
cleanExit();
return 0;
}
Expand All @@ -230,22 +244,23 @@ void getCurPos() {
char ch;
fflush(stdout);
cury = 0; curx = 0;
struct termios term, restore;
tcgetattr(0, &term);
tcgetattr(0, &restore);
term.c_lflag &= ~(ICANON|ECHO);
tcsetattr(0, TCSANOW, &term);
if (!textlock) {
tcgetattr(0, &term);
tcgetattr(0, &restore);
term.c_lflag &= ~(ICANON|ECHO);
tcsetattr(0, TCSANOW, &term);
}
while (write(1, "\e[6n", 4) == -1) {}
for (i = 0, ch = 0; ch != 'R'; i++) {
ret = read(1, &ch, 1);
if (!ret) {
tcsetattr(0, TCSANOW, &restore);
if (!textlock) tcsetattr(0, TCSANOW, &restore);
return;
}
buf[i] = ch;
}
if (i < 2) {
tcsetattr(0, TCSANOW, &restore);
if (!textlock) tcsetattr(0, TCSANOW, &restore);
return;
}
for (i -= 2, pow = 1; buf[i] != ';'; i--, pow *= 10) {
Expand All @@ -254,7 +269,7 @@ void getCurPos() {
for(i--, pow = 1; buf[i] != '['; i--, pow *= 10) {
cury += (buf[i] - '0') * pow;
}
tcsetattr(0, TCSANOW, &restore);
if (!textlock) tcsetattr(0, TCSANOW, &restore);
return;
}

Expand Down
46 changes: 45 additions & 1 deletion commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,37 @@ if (!strcmp(arg[0], "$TXTITAL")) {
printf("\e[3m");
goto cmderr;
}
if (!strcmp(arg[0], "$TXTUNDER")) {
if (!strcmp(arg[0], "$TXTUNDRLN")) {
cerr = 0;
if (argct != 0) {cerr = 3; goto cmderr;}
printf("\e[4m");
goto cmderr;
}
if (!strcmp(arg[0], "$TXTULCLR")) {
cerr = 0;
if (argct != 1) {cerr = 3; goto cmderr;}
if (argt[1] != 2) {cerr = 2; goto cmderr;}
printf("\e[58:5:%um", (uint8_t)atoi(arg[1]));
goto cmderr;
}
if (!strcmp(arg[0], "$TXTOVERLN")) {
cerr = 0;
if (argct != 0) {cerr = 3; goto cmderr;}
printf("\e[53m");
goto cmderr;
}
if (!strcmp(arg[0], "$TXTDBLUL")) {
cerr = 0;
if (argct != 0) {cerr = 3; goto cmderr;}
printf("\e[21m");
goto cmderr;
}
if (!strcmp(arg[0], "$TXTSQGUL")) {
cerr = 0;
if (argct != 0) {cerr = 3; goto cmderr;}
printf("\e[4:3m");
goto cmderr;
}
if (!strcmp(arg[0], "$TXTBLINK")) {
cerr = 0;
if (argct != 0) {cerr = 3; goto cmderr;}
Expand All @@ -169,3 +194,22 @@ if (!strcmp(arg[0], "$TXTSTRIKE")) {
printf("\e[9m");
goto cmderr;
}
if (!strcmp(arg[0], "$TXTLOCK")) {
cerr = 0;
if (argct != 0) {cerr = 3; goto cmderr;}
if (!textlock) {
tcgetattr(0, &term);
tcgetattr(0, &restore);
term.c_lflag &= ~(ICANON|ECHO);
tcsetattr(0, TCSANOW, &term);
}
textlock = true;
goto cmderr;
}
if (!strcmp(arg[0], "$TXTUNLOCK")) {
cerr = 0;
if (argct != 0) {cerr = 3; goto cmderr;}
if (textlock) tcsetattr(0, TCSANOW, &restore);
textlock = false;
goto cmderr;
}
14 changes: 14 additions & 0 deletions functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ if (!strcmp(farg[0], "VAL")) {
if (ftype == 1) {cerr = 2; goto fexit;}
goto fexit;
}
if (!strcmp(farg[0], "INPUT$")) {
cerr = 0;
ftype = 1;
if (fargct > 1) {cerr = 3; goto fexit;}
if (fargct == 1 && fargt[1] != 1) {cerr = 2; goto fexit;}
char *tmp = NULL;
if (fargct == 1) {
while (tmp == NULL) {tmp = readline(farg[1]);}
} else {
while (tmp == NULL) {tmp = readline("?: ");}
}
copyStr(tmp, outbuf);
goto fexit;
}
if (!strcmp(farg[0], "$PROMPT$")) {
cerr = 0;
ftype = 1;
Expand Down

0 comments on commit 76d2cd7

Please sign in to comment.