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

Commit

Permalink
0.22
Browse files Browse the repository at this point in the history
Added file i/o
Improved CLS
Fixed a compiler warning when using clang
Improved program loader to prevent crashing when a virtual device is passed
Stopped CLIBASIC from tainting the terminal and breaking sudo and su input (bug in kbhit() function)
Updated dead links in README.md
Added line number support
Fixed a LABEL/GOTO bug
Added a manpage
Added local (non-root) install support to Makefile
  • Loading branch information
PQCraft authored Sep 19, 2021
1 parent 362c869 commit a4772c6
Show file tree
Hide file tree
Showing 22 changed files with 1,477 additions and 387 deletions.
109 changes: 81 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
BASE_CFLAGS = --std=c99 -Wall -Wextra -Ofast -lm -lreadline

ifdef OS
ifeq ($(findstring :/, $(PATH)), :/)
IS_LINUX = true
else
IS_LINUX = false
endif
else
IS_LINUX = true
endif

ifeq ($(IS_LINUX), true)
ifndef OS

C = gcc
CFLAGS = $(BASE_CFLAGS)
ifeq ($(shell uname -s), Darwin)
CFLAGS += -I/usr/local/opt/readline/include -L/usr/local/opt/readline/lib
ifeq ($(shell [ -d ~/.brew/opt/readline/include ] && echo true), true)
CFLAGS += -I~/.brew/opt/readline/include
endif
ifeq ($(shell [ -d /opt/homebrew/opt/readline/include ] && echo true), true)
CFLAGS += -I/opt/homebrew/opt/readline/include
endif
ifeq ($(shell [ -d /usr/local/opt/readline/include ] && echo true), true)
CFLAGS += -I/usr/local/opt/readline/include
endif
ifeq ($(shell [ -d ~/.brew/opt/readline/lib ] && echo true), true)
CFLAGS += -L~/.brew/opt/readline/lib
endif
ifeq ($(shell [ -d /opt/homebrew/opt/readline/lib ] && echo true), true)
CFLAGS += -L/opt/homebrew/opt/readline/lib
endif
ifeq ($(shell [ -d /usr/local/opt/readline/lib ] && echo true), true)
CFLAGS += -L/usr/local/opt/readline/lib
endif
else
ifeq ($(shell uname -o), Android)
CFLAGS += -s
Expand All @@ -26,17 +33,33 @@ endif

CBITS = $(shell getconf LONG_BIT)

BUILD_TO = "clibasic"
BUILD__ = $(C) clibasic.c $(CFLAGS) -DB$(CBITS) -o $(BUILD_TO) && chmod +x $(BUILD_TO)
BUILD_TO = clibasic
BUILD32 = $(C) clibasic.c -m32 $(CFLAGS) -DB32 -o $(BUILD_TO) && chmod +x $(BUILD_TO)
ifeq (,$(CBITS))
BUILD__ = $(BUILD32)
else
BUILD__ = $(C) clibasic.c $(CFLAGS) -DB$(CBITS) -o $(BUILD_TO) && chmod +x $(BUILD_TO)
endif

MAN_PATH = docs/clibasic.man

ifeq ($(shell id -u), 0)
MAN_INSTALL_PATH = /usr/share/man/man1/clibasic.1
INSTALL_TO = /usr/bin/clibasic
else
MAN_INSTALL_PATH = ~/.local/share/man/man1/clibasic.1
INSTALL_TO = ~/.local/bin/clibasic
endif
INSTALL = mkdir -p $(shell dirname -- $(INSTALL_TO)) $(shell dirname -- $(MAN_INSTALL_PATH)); cp $(BUILD_TO) $(INSTALL_TO); cp $(MAN_PATH) $(MAN_INSTALL_PATH); gzip -f $(MAN_INSTALL_PATH)

INSTALL_TO = "/usr/bin/clibasic"
INSTALL = if [ "$$(id -u)" -eq 0 ]; then cp $(BUILD_TO) $(INSTALL_TO); else echo "Root privileges are needed to install."; fi
UNINSTALL = rm -f $(INSTALL_TO) $(MAN_INSTALL_PATH).gz

RUN = ./clibasic
RUN = ./$(BUILD_TO)

CLEAN = rm -f clibasic

.ONESHELL:

.PHONY: all all32 build build32 update install install32 run clean cross

all: clean build run
Expand All @@ -54,38 +77,58 @@ update:
([[ ! "$$I" =~ ^[^Yy]$$ ]] && sh -c 'git restore . && git pull' &> /dev/null && chmod +x *.sh) || exit 0

install:
if [ ! -f $(INSTALL_TO) ]; then $(BUILD__); fi
if [ ! -f $(BUILD_TO) ]; then $(BUILD__); fi
$(INSTALL)

install32:
if [ ! -f $(INSTALL_TO) ]; then $(BUILD32); fi
if [ ! -f $(BUILD_TO) ]; then $(BUILD32); fi
$(INSTALL)

uninstall:
$(UNINSTALL)

run:
ifeq (32,$(CBITS))
[ ! -f "$(BUILD_TO)" ] && ($(BUILD32))
else
[ ! -f "$(BUILD_TO)" ] && ($(BUILD__))
endif
$(RUN)

clean:
$(CLEAN)

.ONESHELL:

cross:
ifeq ($(MAKECMDGOALS), cross)
@$(MAKE) cross all
else
@$(eval C = x86_64-w64-mingw32-gcc)
@$(eval C32 = i686-w64-mingw32-gcc)
@$(eval CFLAGS = $(BASE_CFLAGS) -Ilib)
@$(eval BUILD_TO = "clibasic.exe")
@$(eval BUILD__ = cp -f lib/win64/*.dll . && $(C) clibasic.c $(CFLAGS) -Llib/win64 -DB$(CBITS) -o $(BUILD_TO) && chmod -x ./clibasic.exe)
@$(eval BUILD32 = cp -f lib/win32/*.dll . && $(C32) clibasic.c -m32 $(CFLAGS) -Llib/win32 -DB32 -o $(BUILD_TO) && chmod -x ./clibasic.exe)
@$(eval INSTALL_TO = "$$HOME/.wine/drive_c/windows/system32")
@$(eval CFLAGS = $(BASE_CFLAGS) -s -Ilib)
@$(eval BUILD_TO = clibasic.exe)
@$(eval INSTALL_TO = "$$HOME/.wine/drive_c/windows/system32/")
@$(eval INSTALL = cp $(BUILD_TO) *.dll $(INSTALL_TO))
@$(eval RUN = wineconsole clibasic.exe)
@$(eval BUILD32 = cp -f lib/win32/*.dll . && $(C32) clibasic.c -m32 $(CFLAGS) -Llib/win32 -DB32 -o $(BUILD_TO) && chmod -x $(BUILD_TO))
ifeq (,$(CBITS))
@$(eval BUILD__ = $(BUILD32))
else
@$(eval BUILD__ = cp -f lib/win64/*.dll . && $(C) clibasic.c $(CFLAGS) -Llib/win64 -DB$(CBITS) -o $(BUILD_TO) && chmod -x $(BUILD_TO))
endif
@$(eval RUN = wineconsole .\\$(BUILD_TO))
@$(eval CLEAN = rm -f clibasic.exe *.dll)
endif
@true

vt:
@$(eval CFLAGS = $(CFLAGS) -DFORCE_VT)
@$(eval BUILD32 = cp -f lib/win32/*.dll . && $(C32) clibasic.c -m32 $(CFLAGS) -Llib/win32 -DB32 -o $(BUILD_TO) && chmod -x $(BUILD_TO))
ifeq (,$(CBITS))
@$(eval BUILD__ = $(BUILD32))
else
@$(eval BUILD__ = cp -f lib/win64/*.dll . && $(C) clibasic.c $(CFLAGS) -Llib/win64 -DB$(CBITS) -o $(BUILD_TO) && chmod -x $(BUILD_TO))
endif
@true

else

C = gcc
Expand All @@ -96,9 +139,11 @@ BUILD_TO = clibasic.exe
BUILD64 = xcopy lib\win64\*.dll . /Y && $(C) clibasic.c -m64 $(CFLAGS) -Llib\win64 -DB64 -o $(BUILD_TO)
BUILD32 = xcopy lib\win32\*.dll . /Y && $(C) clibasic.c -m32 $(CFLAGS) -Llib\win32 -DB32 -o $(BUILD_TO)

INSTALL_TO = "C:\\windows\\system32"
INSTALL_TO = C:\windows\system32
INSTALL = xcopy *.dll $(INSTALL_TO) /Y && xcopy $(BUILD_TO) $(INSTALL_TO) /Y

UNINSTALL = del $(INSTALL_TO)\\$(BUILD_TO)

.PHONY: all all32 build build32 update run clean

all: clean build run
Expand Down Expand Up @@ -128,5 +173,13 @@ run:
clean:
del /q /f $(BUILD_TO) *.dll

vt:
ifeq ($(MAKECMDGOALS), vt)
@$(MAKE) vt all
else
@$(eval CFLAGS = $(CFLAGS) -DFORCE_VT)
endif
@echo > nul

endif

27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Debian (`apt`): `build-essential`, `libreadline-dev` <br>
Arch (`pacman`): `base-devel`, `readline` <br>
Alpine (`apk`): `build-base`, `readline-dev` <br>
#### Windows <br>
NT - 10 (download): [`MinGW`](http://mingw-w64.org/doku.php/download/mingw-builds), [`Make for Windows`](http://gnuwin32.sourceforge.net/packages/make.htm) <br>
NT - 10 (download): [`MinGW`](http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe/download), [`Make for Windows`](http://gnuwin32.sourceforge.net/packages/make.htm) <br>
7 - 10 (`choco`): `mingw`, `make` <br>
#### MacOS <br>
Mojave - Big Sur (`brew`): `gcc`, `make`, `readline` <br>
Expand All @@ -31,15 +31,36 @@ Mojave - Big Sur (`brew`): `git` <br>

---
### Building and Running <br>
#### Linux/Windows/MacOS <br>
#### Linux/MacOS <br>
To build, use `make build`. <br>
To run, use `make run` or `./clibasic`. <br>
To build then run, use `make` (same as `make all`). <br>
#### Windows <br>
Make sure the bin of MinGW is in the %PATH%.
- Type `gcc` into CMD and if you received a "Can't recognize" message, MinGW is not in your %PATH%.
To add MinGW to the %PATH% if you used the downloaded installer:
1. Navigate to where you installed MinGW
2. Open the `mingw64` folder
3. Open the `bin` folder
4. Copy the location
5. Add the location you copied to the %PATH% environment variable
- For Windows 7 and older
1. Open the Start Menu
2. Right-click on Computer and click Properties
3. Click Advanced system settings
4. Click the Advanced tab
5. Click Environment Variables
6. Under System variables, find Path and click Edit
- For Windows 8 and newer
1. Open the Start Menu
2. Search for and run 'Edit the system environment variables'
3. Click Environment Variables
4. Under System variables, find Path and click Edit

---
### Notes <br>
- On Arch Linux, you can install CLIBASIC by installing either the [`clibasic`](https://aur.archlinux.org/packages/clibasic/) or [`clibasic-bin`](https://aur.archlinux.org/packages/clibasic-bin/) AUR package.
- If CLIBASIC is not run in a terminal on unix-like OSs it will, unless GUI_CHECK is not defined, attempt to open in XTerm and skip reading arguments.
- On unix-like OSs, if CLIBASIC is not run in a terminal it will attempt to open in XTerm unless GUI_CHECK is undefined.
- Due to Windows not having proper fork() and exec\*() functions, EXEC, EXEC(), and EXEC$() are passed through system() under Windows and one issue out of the many with this is a space parsing issue where running `EXEC "test prog"` will attempt to execute `EXEC "test", "prog"` if `test prog` cannot be found in the current directory or %PATH%.
- 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.
Expand Down
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# tests if clibasic build on linux and windows successfully
# tests if clibasic builds on linux and windows successfully

make build clean
make cross vt build clean
make cross build clean

Loading

0 comments on commit a4772c6

Please sign in to comment.