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

Commit

Permalink
0.22.2
Browse files Browse the repository at this point in the history
Commented out some unused code that may be used later to avoid a warning when using clang
Made the program line that caused an error appear on a separate line
Fixed Windows VT build not enabling escape codes in time
Added a redirection override option
  • Loading branch information
PQCraft authored Sep 20, 2021
1 parent e39f408 commit 55f6cab
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ To build CLIBASIC with support for VT escape codes, add `vt` before the rest of
- 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.
- The development scripts are `build.sh` which is for testing if CLIBASIC compiles correctly for Linux and Windows, and `package.sh` which creates the zip files for making a CLIBASIC release.
- 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.
50 changes: 34 additions & 16 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.1";
char VER[] = "0.22.2";

#if defined(__linux__)
char OSVER[] = "Linux";
Expand Down Expand Up @@ -331,7 +331,7 @@ static inline void* setsig(int sig, void* func) {
sigemptyset(&act.sa_mask);
sigaddset(&act.sa_mask, sig);
act.sa_handler = func;
//act.sa_flags = SA_RESTART;
act.sa_flags = SA_RESTART;
sigaction(sig, &act, &old);
return old.sa_handler;
#else
Expand Down Expand Up @@ -382,6 +382,23 @@ void rl_sigh(int sig) {
rl_redisplay();
}
void txtqunlock() {}
#ifndef _WIN_NO_VT
bool vtenabled = false;
void enablevt() {
if (vtenabled) return;
vtenabled = true;
DWORD dwMode = 0;
if (!GetConsoleMode(hConsole, &dwMode)){
fputs("Failed to get the console mode.\n", stderr);
exit(GetLastError());
}
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
if (!SetConsoleMode(hConsole, dwMode)) {
fputs("Failed to set the console mode.\n", stderr);
exit(GetLastError());
}
}
#endif
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 4
#endif
Expand Down Expand Up @@ -428,6 +445,7 @@ uint64_t tval;

void* oldsigh = NULL;

#if 0
static inline void nokill() {
if (!oldsigh) oldsigh = setsig(SIGINT, nokill);
}
Expand All @@ -436,6 +454,7 @@ static inline void yeskill() {
setsig(SIGINT, oldsigh);
oldsigh = NULL;
}
#endif

void forceExit() {
#ifndef _WIN32
Expand Down Expand Up @@ -573,7 +592,10 @@ static inline char* pathfilename(char* fn) {
return bfnbuf;
}

bool redirection = false;

static inline void ttycheck() {
if (redirection) return;
if (!isatty(STDERR_FILENO)) {exit(1);}
if (!isatty(STDIN_FILENO)) {fputs("CLIBASIC does not support STDIN redirection.\n", stderr); exit(1);}
if (!isatty(STDOUT_FILENO)) {fputs("CLIBASIC does not support STDOUT redirection.\n", stderr); exit(1);}
Expand Down Expand Up @@ -633,6 +655,7 @@ int main(int argc, char** argv) {
puts(" -k, --keep Stops CLIBASIC from resetting text attributes before exiting.");
puts(" -s, --skip Skips searching for autorun programs.");
puts(" -i, --info Displays an info string when starting in shell mode.");
puts(" -r, --redirection Allows for redirection (this may cause issues).");
pexit = true;
} else if (!strcmp(argv[i], "--args")) {
if (runc || !runfile) {fputs("Args can only be passed when running a program.\n", stderr); exit(1);}
Expand Down Expand Up @@ -668,6 +691,10 @@ int main(int argc, char** argv) {
if (info) {fputs("Incorrect number of options passed.\n", stderr); exit(1);}
info = true;
if (shortopt) goto chkshortopt;
} else if (!strcmp(argv[i], "--redirection") || (shortopt && argv[i][shortopti] == 'r')) {
if (info) {fputs("Incorrect number of options passed.\n", stderr); exit(1);}
redirection = true;
if (shortopt) goto chkshortopt;
} else if (!strcmp(argv[i], "--command") || !strcmp(argv[i], "-c")) {
if (runfile) {fputs("Cannot run file and command.\n", stderr); exit(1);}
ttycheck();
Expand Down Expand Up @@ -737,16 +764,7 @@ int main(int argc, char** argv) {
exit(GetLastError());
}
#ifndef _WIN_NO_VT
DWORD dwMode = 0;
if (!GetConsoleMode(hConsole, &dwMode)){
fputs("Failed to get the console mode.\n", stderr);
exit(GetLastError());
}
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
if (!SetConsoleMode(hConsole, dwMode)) {
fputs("Failed to set the console mode.\n", stderr);
exit(GetLastError());
}
enablevt();
#else
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hConsole, &csbi);
Expand Down Expand Up @@ -1105,7 +1123,6 @@ static inline void getCurPos() {
#ifndef _WIN32
char buf[16];
register int i;
//nokill();
if (gcp_sig) pthread_sigmask(SIG_SETMASK, &intmask, &oldmask);
i = kbhit();
while (i > 0) {getchar(); i--;}
Expand All @@ -1129,8 +1146,6 @@ static inline void getCurPos() {
}
i = kbhit();
while (i > 0) {getchar(); i--;}
//yeskill();
//if (cmdint) {cmdint = false; return;}
if (gcpret != gcpi) {gcp_sig = false; getCurPos(); gcp_sig = true;}
else {sscanf(buf, "\e[%d;%dR", &cury, &curx);}
if (gcp_sig) pthread_sigmask(SIG_SETMASK, &oldmask, NULL);
Expand Down Expand Up @@ -1181,6 +1196,9 @@ void unloadAllProg() {
}

bool loadProg(char* filename) {
#if defined(_WIN32) && !defined(_WIN_NO_VT)
enablevt();
#endif
retval = 0;
fputs("Loading...", stdout);
fflush(stdout);
Expand Down Expand Up @@ -2756,7 +2774,7 @@ static inline void freeBaseMem() {
static inline void printError(int error) {
getCurPos();
if (curx != 1) putchar('\n');
if (inProg) {printf("Error %d on line %d of '%s': '%s': ", error, progLine, basefilename(progfnstr), cmd);}
if (inProg) {printf("Error %d on line %d of '%s':\n%s\n", error, progLine, basefilename(progfnstr), cmd);}
else {printf("Error %d: ", error);}
switch (error) {
default:
Expand Down
24 changes: 24 additions & 0 deletions release-text.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
if [ -z "$*" ]; then
FILE=".changelog"
if [ ! -f '.changelog' ]; then echo "Not a file: .changelog"; exit 1; fi
else
for FILE in "$@"; do
if [ ! -f "$FILE" ]; then echo "Not a file: $FILE"; exit 1; fi
done
FILE=""
fi
echo "**Changes:**
$(sed 's/^/- /' "$@" "$FILE")
<br>
**(Compressed) Executables:**
- Linux x86 64-bit: \`clibasic-linux-x64.zip\`
- Linux x86 32-bit: \`clibasic-linux-x86.zip\`
- Windows x86 64-bit using VT escape codes: \`clibasic-windows-vt-x64.zip\`
- Windows x86 32-bit using VT escape codes: \`clibasic-windows-vt-x86.zip\`
- Windows x86 64-bit using legacy API calls: \`clibasic-windows-x64.zip\`
- Windows x86 32-bit using legacy API calls: \`clibasic-windows-x86.zip\`
<br>
**Extras:**
- Example programs: \`examples.zip\`"

0 comments on commit 55f6cab

Please sign in to comment.