From 32c34ab174f1dd93985831926241ed3f20f4d0c7 Mon Sep 17 00:00:00 2001 From: jaseg Date: Sun, 22 Jul 2018 18:38:00 +0200 Subject: Remove fmemopen altogether since it just doesn't work. Closes #9. --- .gitmodules | 6 ------ Makefile | 38 ++++++++++--------------------------- Makefile.musl | 28 ---------------------------- README.md | 16 +--------------- lolcat.c | 60 +++++++++++++++++++++++++++++++++++++---------------------- memorymapping | 1 - musl | 1 - 7 files changed, 49 insertions(+), 101 deletions(-) delete mode 100644 Makefile.musl delete mode 160000 memorymapping delete mode 160000 musl diff --git a/.gitmodules b/.gitmodules index a956631..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +0,0 @@ -[submodule "musl"] - path = musl - url = git://git.musl-libc.org/musl -[submodule "memorymapping"] - path = memorymapping - url = https://github.com/NimbusKit/memorymapping diff --git a/Makefile b/Makefile index 1cd5cc8..1be84e5 100644 --- a/Makefile +++ b/Makefile @@ -1,43 +1,25 @@ +CC ?= gcc LOLCAT_SRC ?= lolcat.c CENSOR_SRC ?= censor.c -CFLAGS ?= -std=c11 -Wall -g +CFLAGS ?= -std=c11 -Wall -Wextra -g DESTDIR ?= /usr/local/bin -all: lolcat-static censor-static +all: lolcat censor -include Makefile.musl - -ifeq ($(shell uname -s),Darwin) - LOLCAT_SRC += memorymapping/src/fmemopen.c - CENSOR_SRC += memorymapping/src/fmemopen.c - CFLAGS += -Imemorymapping/src -endif - -.PHONY: install clean static - -static: lolcat-static censor-static - -lolcat-static: lolcat.c - gcc -c $(CFLAGS) -I$(MUSLDIR)/include -o lolcat.o $< - gcc -s -nostartfiles -nodefaultlibs -nostdinc -static -ffunction-sections -fdata-sections -Wl,--gc-sections -o $@ lolcat.o $(MUSLDIR)/lib/crt1.o $(MUSLDIR)/lib/libc.a - -censor-static: censor.c - gcc -c $(CFLAGS) -I$(MUSLDIR)/include -o censor.o $< - gcc -s -nostartfiles -nodefaultlibs -nostdinc -static -ffunction-sections -fdata-sections -Wl,--gc-sections -o $@ censor.o $(MUSLDIR)/lib/crt1.o $(MUSLDIR)/lib/libc.a +.PHONY: install clean lolcat: $(LOLCAT_SRC) - gcc $(CFLAGS) -o $@ $^ + $(CC) $(CFLAGS) -o $@ $^ censor: $(CENSOR_SRC) - gcc $(CFLAGS) -o $@ $^ + $(CC) $(CFLAGS) -o $@ $^ -install: lolcat-static censor-static - install lolcat-static $(DESTDIR)/lolcat - install censor-static $(DESTDIR)/censor +install: lolcat censor + install lolcat $(DESTDIR)/lolcat + install censor $(DESTDIR)/censor clean: - rm -f lolcat lolcat-static.o lolcat-static censor censor-static.o censor-static - # make -C musl clean + rm -f lolcat censor diff --git a/Makefile.musl b/Makefile.musl deleted file mode 100644 index d50de24..0000000 --- a/Makefile.musl +++ /dev/null @@ -1,28 +0,0 @@ - -ifneq (,$(wildcard /usr/local/musl)) -MUSLDIR ?= /usr/local/musl -else ifneq (,$(wildcard /usr/lib/musl)) -MUSLDIR ?= /usr/lib/musl -else ifneq (,$(wildcard musl/Makefile)) -MUSLDIR ?= musl -lolcat-static: musl -censor-static: musl -else -$(info "musl not found. If the build does not go through, consider either installing") -$(info "musl system-wide using your favorite package manager or fetching and building a") -$(info "local copy using:") -$(info "$ git submodule init") -$(info "$ git submodule update") -$(info "$ make musl") -endif -$(info "Using musl at $(MUSLDIR)") - -musl/lib/libc.a musl/lib/crt1.o: musl/config.mak - make -C musl - -musl/config.mak: - cd musl; ./configure - -.PHONY: musl -musl: musl/lib/libc.a musl/lib/crt1.o - diff --git a/README.md b/README.md index b7083f9..a4e9560 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ $ snap install lolcat-c ### Mac -Build the system-libc version (instead of the statically linked version) with: +Build loclcat with: ``` $ make lolcat ``` @@ -40,20 +40,6 @@ $ make lolcat $ make && sudo make install ``` -If this can't find musl and you have it installed somewhere, run -```bash -$ make MUSLDIR=/path/to/musl -``` - -If you don't have a musl around yet, the easiest way to build is to run -```bash -$ git submodule init -$ git submodule update -$ make -``` - -This will checkout and build musl in this repository's ```musl``` dir. - ## Why? This `lolcat` clone is an attempt to reduce the world's carbon dioxide emissions by optimizing inefficient code. It's >10x as fast and <0.1% as large as the original one. diff --git a/lolcat.c b/lolcat.c index 687f259..ad1893b 100644 --- a/lolcat.c +++ b/lolcat.c @@ -13,6 +13,8 @@ * 0. You just DO WHAT THE FUCK YOU WANT TO. */ +#define _XOPEN_SOURCE + #include #include #include @@ -25,13 +27,6 @@ #include #include -#ifdef __APPLE__ -#include "fmemopen.h" -#else // __APPLE__ -#define _GNU_SOURCE //for fmemopen -#endif // __APPLE__ - - static char helpstr[] = "\n" "Usage: lolcat [-h horizontal_speed] [-v vertical_speed] [--] [FILES...]\n" "\n" @@ -79,7 +74,8 @@ void version(){ } int main(int argc, char **argv){ - int c, cc=-1, i, l=0; + int cc=-1, i, l=0; + wint_t c; int colors=1; double freq_h = 0.23, freq_v = 0.1; @@ -128,20 +124,38 @@ int main(int argc, char **argv){ i=0; for(char **filename=inputs; filename 0){ + while((c = this_file_read_wchar(f)) != WEOF) { if(colors){ find_escape_sequences(c, &escape_state); @@ -165,11 +179,13 @@ int main(int argc, char **argv){ printf("\n\033[0m"); cc = -1; - fclose(f); + if (f) { + fclose(f); - if(c != WEOF && c != 0){ - fprintf(stderr, "Error reading input file \"%s\": %s\n", *filename, strerror(errno)); - return 2; + if(ferror(f)){ + fprintf(stderr, "Error reading input file \"%s\": %s\n", *filename, strerror(errno)); + return 2; + } } } } diff --git a/memorymapping b/memorymapping deleted file mode 160000 index 79ce0dd..0000000 --- a/memorymapping +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 79ce0ddd0de4b11e4944625eb866290368f867c0 diff --git a/musl b/musl deleted file mode 160000 index fb58545..0000000 --- a/musl +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fb58545f8d1c5fa32122244caeaf3625c12ddc01 -- cgit