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

Commit

Permalink
0.15.7
Browse files Browse the repository at this point in the history
Fixed readline on MacOS (was linking libedit due to Apple/BSD magic)
Fixed warnings on MacOS
Merged Makefile and Makefile-Windows into one Makefile
  • Loading branch information
PQCraft authored Jun 17, 2021
1 parent fb730c4 commit 3deb8c0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 26 deletions.
40 changes: 38 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
C = gcc
ifndef OS

CFLAGS = -Wall -Wextra -O2 -s -no-pie -lm -lreadline --std=c99
C = gcc
CFLAGS = -Wall -Wextra -O2 -lm -lreadline --std=c99
ifeq ($(shell uname -s), Darwin)
CFLAGS += -I/usr/local/opt/readline/include -L/usr/local/opt/readline/lib
else
CFLAGS += -s -no-pie
endif

CBITS = $(shell getconf LONG_BIT)

Expand Down Expand Up @@ -41,3 +47,33 @@ debug:

clean:
rm -f ./clibasic

else

C = gcc

CFLAGS = -Wall -Wextra -O2 -Ilib -s -lm -lreadline --std=c99

BUILD64 = xcopy lib\win64\*.dll . /Y && $(C) clibasic.c -m64 $(CFLAGS) -Llib\win64 -DB64 -o clibasic.exe
BUILD32 = xcopy lib\win32\*.dll . /Y && $(C) clibasic.c -m32 $(CFLAGS) -Llib\win32 -DB32 -o clibasic.exe

all: clean build run

all32: clean build32 run

build:
$(BUILD64)

build32:
$(BUILD32)

run:
.\clibasic.exe

debug:
.\clibasic.exe --debug

clean:
del /q /f .\clibasic.exe

endif
39 changes: 15 additions & 24 deletions clibasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
#define SIGKILL 9
#endif

char VER[] = "0.15.6.1";
char VER[] = "0.15.7";

#if defined(__linux__)
char OSVER[] = "Linux";
Expand Down Expand Up @@ -235,9 +235,7 @@ int tab_end = 0;
void strApndChar(char* str, char c);
char* rl_get_tab(const char* text, int state) {
char* tab = NULL;
#ifndef __APPLE__
rl_filename_quoting_desired = 0;
#endif
if (!state) {
tab = malloc(strlen(text) + 5);
strcpy(tab, text);
Expand Down Expand Up @@ -360,55 +358,45 @@ int main(int argc, char** argv) {
exit(system(command));
}
#endif
if (!isatty(STDERR_FILENO)) {exit(EIO);}
if (!isatty(STDIN_FILENO)) {fputs("CLIBASIC does not support pipes.\n", stderr); exit(1);}
if (!isatty(STDOUT_FILENO)) {fputs("CLIBASIC does not support redirects.\n", stderr); exit(1);}
signal(SIGINT, cleanExit);
signal(SIGKILL, cleanExit);
signal(SIGTERM, cleanExit);
#ifndef __APPLE__
rl_readline_name = "CLIBASIC";
char* rl_tmpptr = calloc(1, 1);
#ifndef __APPLE__
rl_completion_entry_function = rl_get_tab;
#else
rl_completion_entry_function = (Function*)rl_get_tab;
#endif
#ifndef __APPLE__
rl_attempted_completion_function = (rl_completion_func_t*)rl_tab;
#else
rl_attempted_completion_function = rl_tab;
#endif
rl_getc_function = getc;
rl_special_prefixes = rl_tmpptr;
rl_completer_quote_characters = rl_tmpptr;
rl_completer_word_break_characters = rl_tmpptr;
#endif
#ifdef _WIN32
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (hOut == INVALID_HANDLE_VALUE) {
exit(GetLastError());
err = GetLastError();
cleanExit();
}
DWORD dwMode = 0;
if (!GetConsoleMode(hOut, &dwMode)){
exit(GetLastError());
err = GetLastError();
cleanExit();
}
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
if (!SetConsoleMode(hOut, dwMode)) {
exit(GetLastError());
err = GetLastError();
cleanExit();
}
#endif
getCurPos();
if (curx != 1) putchar('\n');
bool exit = false;
bool pexit = false;
for (int i = 1; i < argc; i++) {
if (argv[i][0] == '-' && strcmp(argv[i], "--file") && strcmp(argv[i], "-f")) {
if (!strcmp(argv[i], "--version") || !strcmp(argv[i], "-v")) {
if (argc > 2) {fputs("Incorrect number of options passed.\n", stderr); err = 1; cleanExit();}
printf("Command Line Interface BASIC version %s (%s %s-bit)\n", VER, OSVER, BVER);
puts("Copyright (C) 2021 PQCraft");
puts("This software is licensed under the GNU GPL v3.");
exit = true;
pexit = true;
} else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
if (argc > 2) {fputs("Incorrect number of options passed.\n", stderr); err = 1; cleanExit();}
printf("Usage: %s [options] [{--file|-f}] [file] [options]\n", argv[0]);
Expand All @@ -419,7 +407,7 @@ int main(int argc, char** argv) {
puts(" {-h|--help} Shows this help text.");
puts(" {-v|--version} Shows the version and license information.");
puts(" {-d|--debug} Enables the printing of debug information.");
exit = true;
pexit = true;
} else if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d")) {
if (debug) {fputs("Incorrect number of options passed.\n", stderr); err = 1; cleanExit();}
debug = true;
Expand Down Expand Up @@ -450,7 +438,10 @@ int main(int argc, char** argv) {
if (!isFile(progFilename)) {puts("Expected file instead of directory."); err = 1; cleanExit();}
}
}
if (exit) cleanExit();
if (pexit) cleanExit();
if (!isatty(STDERR_FILENO) && !inProg) {exit(1);}
if (!isatty(STDIN_FILENO) && !inProg) {fputs("CLIBASIC does not support piping in shell mode.\n", stderr); exit(1);}
if (!isatty(STDOUT_FILENO) && !inProg) {fputs("CLIBASIC does not support redirection in shell mode.\n", stderr); exit(1);}
updateTxtAttrib();
termargs = argv;
if (argv[0][0] == '.') {
Expand Down Expand Up @@ -521,7 +512,7 @@ int main(int argc, char** argv) {
}
}
resetTimer();
while (!exit) {
while (!pexit) {
fchkint:
conbuf[0] = 0;
if (chkinProg) {inProg = true; chkinProg = false;}
Expand Down

0 comments on commit 3deb8c0

Please sign in to comment.