Compare commits

..

No commits in common. "main" and "v1.3" have entirely different histories.
main ... v1.3

7 changed files with 26 additions and 94 deletions

2
.gitignore vendored
View file

@ -1,4 +1,2 @@
lolcat.o lolcat.o
censor.o censor.o
lolcat
censor

View file

@ -3,7 +3,7 @@ CC ?= gcc
CFLAGS ?= -std=c11 -Wall -Wextra -O3 -Wno-sign-compare CFLAGS ?= -std=c11 -Wall -Wextra -O3 -Wno-sign-compare
LIBS := -lm LIBS := -lm
PREFIX ?= /usr/local DESTDIR ?= /usr/local/bin
all: lolcat censor all: lolcat censor
@ -16,14 +16,14 @@ xterm256lut.h: xterm256lut_gen.py
python $< > $@ python $< > $@
lolcat: lolcat.c xterm256lut.h lolcat: lolcat.c xterm256lut.h
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(CC) $(CFLAGS) -o $@ $< $(LIBS)
censor: censor.c censor: censor.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(CC) $(CFLAGS) -o $@ $< $(LIBS)
install: lolcat censor install: lolcat censor
install lolcat $(DESTDIR)$(PREFIX)/bin/lolcat install lolcat $(DESTDIR)/lolcat
install censor $(DESTDIR)$(PREFIX)/bin/censor install censor $(DESTDIR)/censor
clean: clean:
rm -f lolcat censor rm -f lolcat censor

View file

@ -1,7 +1,7 @@
# Maintainer: Ricardo (XenGi) Band <email@ricardo.band> # Maintainer: Ricardo (XenGi) Band <email@ricardo.band>
pkgname=c-lolcat pkgname=c-lolcat
pkgver=v1.5 pkgver=v1.3
pkgrel=1 pkgrel=1
pkgdesc="High-performance implementation of lolcat" pkgdesc="High-performance implementation of lolcat"
arch=('i686' 'x86_64') arch=('i686' 'x86_64')

View file

@ -1,10 +1,10 @@
# What? # What?
![](./LOLCat-Rainbow.jpg) ![](https://raw.githubusercontent.com/jaseg/lolcat/master/LOLCat-Rainbow.jpg)
## Screenshot ## Screenshot
![](./screenshot.png) ![](https://raw.githubusercontent.com/jaseg/lolcat/master/screenshot.png)
![](./sl.gif) ![](./sl.gif)
@ -44,8 +44,6 @@ $ make lolcat
### Others ### Others
Note: Debian users may need the `python-is-python3` package.
```bash ```bash
$ make && sudo make install $ make && sudo make install
``` ```

View file

@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script. # Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69]) AC_PREREQ([2.69])
AC_INIT([lolcat], [1.5], [jaseg <github@jaseg.de>]) AC_INIT([lolcat], [1.3], [jaseg <github@jaseg.de>])
AC_CONFIG_SRCDIR([../lolcat.c]) AC_CONFIG_SRCDIR([../lolcat.c])
AC_CONFIG_HEADERS([config.h]) AC_CONFIG_HEADERS([config.h])
AC_CONFIG_AUX_DIR([autoscripts]) AC_CONFIG_AUX_DIR([autoscripts])

View file

@ -1,31 +0,0 @@
#!/bin/sh
set -e
if [ $# -lt 1 ]; then
echo "do_release.sh must be called with a version number as its first argument."
exit 1
fi
if [ -n "$(git status --porcelain|grep -v '^??')" ]; then
echo "do_release.sh must be called from a clean working directory."
exit 2
fi
VER="$1"
if echo "$VER" | grep -v '^[0-9]\+\.[0-9]\+$'; then
echo "do_release.sh must be called with a version number formatted like "1.23" as its first argument, with no leading \"v\"."
exit 1
fi
echo "Updating files for version v$VER"
sed -i "/L\"lolcat version [0-9.]\+, (c) [0-9]\+ jaseg\\\\n\"/s/version [0-9.]\+/version $VER/" lolcat.c
sed -i "s/^pkgver=v[0-9.]\+/pkgver=v$VER/" PKGBUILD
sed -i "/^AC_INIT/s/\[[0-9.]\+\]/[$VER]/" autotools/configure.ac
git add lolcat.c PKGBUILD autotools/configure.ac
git commit -m 'Bump version to v$VER'
git tag "v$VER"
echo "Success."

View file

@ -110,28 +110,12 @@ enum esc_st {
ST_ESC_STRING_TERM, ST_ESC_STRING_TERM,
ST_ESC_CSI_TERM, ST_ESC_CSI_TERM,
ST_ESC_TERM, ST_ESC_TERM,
NUM_ST
};
const char * esc_st_names[NUM_ST] = {
[ST_NONE] = "NONE",
[ST_ESC_BEGIN] = "BEGIN",
[ST_ESC_STRING] = "STRING",
[ST_ESC_CSI] = "CSI",
[ST_ESC_STRING_TERM] = "STRING_TERM",
[ST_ESC_CSI_TERM] = "CSI_TERM",
[ST_ESC_TERM] = "TERM",
}; };
static enum esc_st find_escape_sequences(wint_t c, enum esc_st st) static enum esc_st find_escape_sequences(wint_t c, enum esc_st st)
{ {
if (st == ST_NONE && c == '\033') { /* Escape sequence YAY */
if (st == ST_NONE || st == ST_ESC_CSI_TERM) { return ST_ESC_BEGIN;
if (c == '\033') { /* Escape sequence YAY */
return ST_ESC_BEGIN;
} else {
return ST_NONE;
}
} else if (st == ST_ESC_BEGIN) { } else if (st == ST_ESC_BEGIN) {
if (c == '[') { if (c == '[') {
@ -150,9 +134,7 @@ static enum esc_st find_escape_sequences(wint_t c, enum esc_st st)
} }
} else if (st == ST_ESC_STRING) { } else if (st == ST_ESC_STRING) {
if (c == '\007') { if (c == '\033') {
return ST_NONE;
} else if (c == '\033') {
return ST_ESC_STRING_TERM; return ST_ESC_STRING_TERM;
} else { } else {
return st; return st;
@ -160,7 +142,7 @@ static enum esc_st find_escape_sequences(wint_t c, enum esc_st st)
} else if (st == ST_ESC_STRING_TERM) { } else if (st == ST_ESC_STRING_TERM) {
if (c == '\\') { if (c == '\\') {
return ST_NONE; return ST_ESC_TERM;
} else { } else {
return ST_ESC_STRING; return ST_ESC_STRING;
} }
@ -173,14 +155,12 @@ static enum esc_st find_escape_sequences(wint_t c, enum esc_st st)
static void usage(void) static void usage(void)
{ {
wprintf(L"Usage: lolcat [-h horizontal_speed] [-v vertical_speed] [--] [FILES...]\n"); wprintf(L"Usage: lolcat [-h horizontal_speed] [-v vertical_speed] [--] [FILES...]\n");
wprintf(L"\n");
wprintf(L"Use lolcat --help to print the full help text.\n");
exit(2); exit(2);
} }
static void version(void) static void version(void)
{ {
wprintf(L"lolcat version 1.5, (c) 2024 jaseg\n"); wprintf(L"lolcat version 1.3, (c) 2020 jaseg\n");
exit(0); exit(0);
} }
@ -375,34 +355,19 @@ int main(int argc, char** argv)
while ((c = this_file_read_wchar(f)) != WEOF) { while ((c = this_file_read_wchar(f)) != WEOF) {
if (colors) { if (colors) {
escape_state = find_escape_sequences(c, escape_state); escape_state = find_escape_sequences(c, escape_state);
#ifdef ESC_DEBUG
fprintf(stderr, "%02x %c %s\n", c, c > 32 ? c : '.', esc_st_names[escape_state]);
#endif
if (escape_state == ST_ESC_CSI_TERM) { if (!escape_state) {
putwchar(c);
}
if (escape_state == ST_NONE || escape_state == ST_ESC_CSI_TERM) {
if (c == '\n') { if (c == '\n') {
l++; l++;
i = 0; i = 0;
cc = -1;
if (invert) { if (invert) {
wprintf(L"\033[49m"); wprintf(L"\033[49m");
} else {
wprintf(L"\033[0m");
} }
} else { } else {
if (escape_state == ST_NONE) {
i += wcwidth(c);
}
if (rgb) { if (rgb) {
i += wcwidth(c);
float theta = i * freq_h / 5.0f + l * freq_v + (offx + 2.0f * (rand_offset + start_color) / RAND_MAX)*M_PI; float theta = i * freq_h / 5.0f + l * freq_v + (offx + 2.0f * (rand_offset + start_color) / RAND_MAX)*M_PI;
union rgb_c c; union rgb_c c;
@ -421,15 +386,15 @@ int main(int argc, char** argv)
wprintf(L"\033[%d;2;%d;%d;%dm", (invert ? 48 : 38), c.r, c.g, c.b); wprintf(L"\033[%d;2;%d;%d;%dm", (invert ? 48 : 38), c.r, c.g, c.b);
} else if (ansi16) { } else if (ansi16) {
int ncc = offx * ARRAY_SIZE(codes16) + (int)(i * freq_h + l * freq_v); int ncc = offx * ARRAY_SIZE(codes16) + (int)((i += wcwidth(c)) * freq_h + l * freq_v);
if (cc != ncc || escape_state == ST_ESC_CSI_TERM) { if (cc != ncc) {
wprintf(L"\033[%hhum", (invert ? 10 : 0) + codes16[(rand_offset + start_color + (cc = ncc)) % ARRAY_SIZE(codes16)]); wprintf(L"\033[%hhum", (invert ? 10 : 0) + codes16[(rand_offset + start_color + (cc = ncc)) % ARRAY_SIZE(codes16)]);
} }
} else { } else {
if (gradient) { if (gradient) {
int ncc = offx * ARRAY_SIZE(codes_gradient) + (int)(i * freq_h + l * freq_v); int ncc = offx * ARRAY_SIZE(codes_gradient) + (int)((i += wcwidth(c)) * freq_h + l * freq_v);
if (cc != ncc || escape_state == ST_ESC_CSI_TERM) { if (cc != ncc) {
size_t lookup = (rand_offset + start_color + (cc = ncc)) % (2*ARRAY_SIZE(codes_gradient)); size_t lookup = (rand_offset + start_color + (cc = ncc)) % (2*ARRAY_SIZE(codes_gradient));
if (lookup >= ARRAY_SIZE(codes_gradient)) { if (lookup >= ARRAY_SIZE(codes_gradient)) {
lookup = 2*ARRAY_SIZE(codes_gradient) - 1 - lookup; lookup = 2*ARRAY_SIZE(codes_gradient) - 1 - lookup;
@ -438,8 +403,8 @@ int main(int argc, char** argv)
} }
} else { } else {
int ncc = offx * ARRAY_SIZE(codes) + (int)(i * freq_h + l * freq_v); int ncc = offx * ARRAY_SIZE(codes) + (int)((i += wcwidth(c)) * freq_h + l * freq_v);
if (cc != ncc || escape_state == ST_ESC_CSI_TERM) { if (cc != ncc) {
wprintf(L"\033[%d;5;%hhum", (invert ? 48 : 38), codes[(rand_offset + start_color + (cc = ncc)) % ARRAY_SIZE(codes)]); wprintf(L"\033[%d;5;%hhum", (invert ? 48 : 38), codes[(rand_offset + start_color + (cc = ncc)) % ARRAY_SIZE(codes)]);
} }
} }
@ -448,8 +413,10 @@ int main(int argc, char** argv)
} }
} }
if (escape_state != ST_ESC_CSI_TERM) { putwchar(c);
putwchar(c);
if (escape_state == ST_ESC_CSI_TERM) { /* implies "colors" */
wprintf(L"\033[38;5;%hhum", codes[(rand_offset + start_color + cc) % ARRAY_SIZE(codes)]);
} }
} }