Compare commits

..

9 Commits
0.3 ... master

Author SHA1 Message Date
tater
0225b8881d better random seed 2018-08-24 03:20:33 -04:00
tater
e642b5ed76 fixed typo 2018-08-24 01:37:26 -04:00
tater
ba0a3ff879 updated docs 2018-08-24 01:34:11 -04:00
tater
ccc6e08596 added random option and dropped chars not in fonts 2018-08-24 01:29:31 -04:00
tater
b63560ab3e moved unused fonts 2018-08-20 14:00:28 -04:00
tater
09fbef581e bugchasing 2018-08-06 17:28:19 -04:00
tater
99997d2762 updated docs 2018-07-14 20:08:11 -04:00
tater
581374520e updated screenshot 2018-07-14 19:50:02 -04:00
tater
c0dcd2f731 updated docs 2018-07-14 19:24:37 -04:00
131 changed files with 131 additions and 40 deletions

View File

@ -5,11 +5,13 @@ FONTS := fonts/*
FONTDIR := $(PREFIX)/share/$(PROG)/fonts
CC ?= cc
CFLAGS += -DFONT_DIR=\"$(FONTDIR)\" -std=c99 -Wall
DFLAGS = -g
UNAME := $(shell sh -c 'uname -s 2>/dev/null')
ifeq ($(UNAME),Darwin)
ifeq ($(UNAME), Darwin)
CC = clang
CFLAGS += -Wunused-result -Wunused-value
DLAGS += -fsanitize=address -fsanitize=undefined -fsanitize=leak
LDFLAGS += -liconv
endif
@ -19,13 +21,15 @@ default: $(SRC)
.PHONY: debug clean install
install:
install -m 0755 -d $(PREFIX)/bin
install -m 0755 -d $(FONTDIR)
install -m 0755 $(PROG) $(PREFIX)/bin/$(PROG)
for i in $(FONTS) ; do install -m 0644 $$i $(FONTDIR) ; done
test -d $(PREFIX)/bin || mkdir -p $(PREFIX)/bin
cp $(PROG) $(PREFIX)/bin
test -d $(FONTDIR) || mkdir -p $(FONTDIR)
rm -f $(FONTDIR)/*.tdf
for i in $(FONTS) ; do cp -v $$i $(FONTDIR) ; done
chmod ugo+r $(FONTDIR)/*.tdf
debug: $(SRC)
$(CC) -DDEBUG -g $(CFLAGS) $(LDFLAGS) $(SRC) -o $(PROG)
$(CC) -DDEBUG $(CFLAGS) $(DFLAGS) $(LDFLAGS) $(SRC) -o $(PROG)
clean:
rm -rf $(PROG) $(PROG).dSYM

View File

@ -1,13 +1,31 @@
![screenshot](https://github.com/tat3r/tdfiglet/blob/master/screenshot.png?raw=true)
# tdfiglet
Because your ascii sucks.
Because your figlet ascii sucks.
![screenshot](https://git.trollforge.org/tdfiglet/plain/screenshot.png)
All known TDF fonts (1198) are included.
## Installation
run make and copy tdfiglet wherever you want.
```
make
sudo make install
```
## Usage
run tdfiglet -h for a list of options
If you're just trying to spam irc `tdfiglet -cm yes hello` will suffice.
```
usage: tdfiglet [options] -f [font] input
-f [font] Specify font file used.
-j l|r|c Justify left, right, or center. Default is left.
-w n Set screen width. Default is 80.
-c a|m Color format ANSI or mirc. Default is ANSI.
-e u|a Encode as unicode or ASCII. Default is unicode.
-i Print font details.
-r Use random font.
-h Print usage.
```

Binary file not shown.

Before

Width:  |  Height:  |  Size: 271 KiB

After

Width:  |  Height:  |  Size: 162 KiB

View File

@ -13,6 +13,7 @@
*/
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
@ -26,7 +27,9 @@
#include <unistd.h>
#include <sys/mman.h>
#include <sys/queue.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#ifdef DEBUG
@ -71,6 +74,7 @@ typedef struct opt_s {
uint8_t width;
uint8_t color;
uint8_t encoding;
bool random;
bool info;
} opt_t;
@ -97,9 +101,16 @@ typedef struct font_s {
uint8_t height;
} font_t;
struct dirname_s {
char *str;
SLIST_ENTRY(dirname_s) stuff;
};
const char *charlist = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO"
"PQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
opt_t opt;
void usage(void);
font_t *loadfont(char *fn);
void readchar(int i, glyph_t *glyph, font_t *font);
@ -115,7 +126,7 @@ void printstr(const char *str, font_t *font);
void
usage(void)
{
fprintf(stderr, "usage: tdfiglet [options] -f [font] input\n");
fprintf(stderr, "usage: tdfiglet [options] input\n");
fprintf(stderr, "\n");
fprintf(stderr, " -f [font] Specify font file used.\n");
fprintf(stderr, " -j l|r|c Justify left, right, or center. Default is left.\n");
@ -123,14 +134,12 @@ usage(void)
fprintf(stderr, " -c a|m Color format ANSI or mirc. Default is ANSI.\n");
fprintf(stderr, " -e u|a Encode as unicode or ASCII. Default is unicode.\n");
fprintf(stderr, " -i Print font details.\n");
fprintf(stderr, " -r Use random font.\n");
fprintf(stderr, " -h Print usage.\n");
fprintf(stderr, "\n");
exit(EX_USAGE);
}
opt_t opt;
int
main(int argc, char *argv[])
{
@ -141,13 +150,21 @@ main(int argc, char *argv[])
opt.width = 80;
opt.info = false;
opt.encoding = ENC_UNICODE;
opt.random = false;
char *fontfile = NULL;
if (argc < 2) {
usage();
}
struct timeval tv;
while((o = getopt(argc, argv, "f:w:j:c:e:i")) != -1) {
DIR *d;
struct dirent *dir;
SLIST_HEAD(, dirname_s) head = SLIST_HEAD_INITIALIZER(dirname_s);
SLIST_INIT(&head);
struct dirname_s *dp;
int r = 0;
int dll = 0;
while((o = getopt(argc, argv, "f:w:j:c:e:ir")) != -1) {
switch (o) {
case 'f':
fontfile = optarg;
@ -197,6 +214,9 @@ main(int argc, char *argv[])
case 'i':
opt.info = true;
break;
case 'r':
opt.random = true;
break;
case 'h':
/* fallthrough */
default:
@ -207,17 +227,52 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
if (argc < 1) {
usage();
}
if (!fontfile) {
fontfile = DEFAULT_FONT;
if (!opt.random) {
fontfile = DEFAULT_FONT;
} else {
d = opendir(FONT_DIR);
if (!d) {
fprintf(stderr, "Error: unable to read %s\n",
FONT_DIR);
exit(1);
}
while ((dir = readdir(d))) {
if (strstr(dir->d_name, FONT_EXT)) {
dp = malloc(sizeof(struct dirname_s));
dp->str = calloc(1, 1024);
strcpy(dp->str, dir->d_name);
SLIST_INSERT_HEAD(&head, dp, stuff);
dll++;
}
}
closedir(d);
gettimeofday(&tv, NULL);
srand(tv.tv_usec);
r = dll ? rand() % dll : 0;
dp = SLIST_FIRST(&head);
for (int i = 0; i < r; i++) {
dp = SLIST_NEXT(dp, stuff);
}
if (dp && dp->str) {
fontfile = dp->str;
} else {
fontfile = DEFAULT_FONT;
}
}
}
font = loadfont(fontfile);
/* TODO: add support for the others */
if (font->fonttype != COLOR_FNT) {
return 0;
}
printf("\n");
for (int i = 0; i < argc; i++) {
@ -229,7 +284,8 @@ main(int argc, char *argv[])
}
font_t
*loadfont(char *fn_arg) {
*loadfont(char *fn_arg)
{
font_t *font;
uint8_t *map = NULL;
@ -243,11 +299,11 @@ font_t
if (!strchr(fn_arg, '/')) {
if (strchr(fn_arg, '.')) {
fn = malloc(strlen(FONT_DIR) + strlen(fn_arg) + 1);
fn = malloc(strlen(FONT_DIR) + strlen(fn_arg) + 2);
sprintf(fn, "%s/%s", FONT_DIR, fn_arg);
} else {
fn = malloc(strlen(FONT_DIR) + strlen(fn_arg) + \
strlen(FONT_EXT) + 1);
strlen(FONT_EXT) + 3);
sprintf(fn, "%s/%s.%s", FONT_DIR, fn_arg, FONT_EXT);
}
} else {
@ -273,13 +329,11 @@ font_t
font = malloc(sizeof(font_t));
if (stat(fn, &st)) {
if (fstat(fd, &st)) {
perror(NULL);
exit(EX_OSERR);
}
free(fn);
len = st.st_size;
map = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0);
@ -305,11 +359,13 @@ font_t
font->data = &map[233];
font->height = 0;
if (strncmp(magic, (const char *)map, strlen(magic))) {
perror("Invalid font file");
if (strncmp(magic, (const char *)map, strlen(magic)) || font->fonttype != COLOR_FNT) {
fprintf(stderr, "Invalid font file: %s\n", fn);
exit(EX_NOINPUT);
}
free(fn);
if (opt.info) {
printf("font: %s\nchar list: ", font->name);
}
@ -340,7 +396,7 @@ font_t
for (int i = 0; i < NUM_CHARS; i++) {
if (lookupchar(charlist[i], font) > -1) {
if (lookupchar(charlist[i], font) != -1) {
font->glyphs[i] = calloc(1, sizeof(glyph_t));
@ -437,7 +493,7 @@ int
lookupchar(char c, const font_t *font)
{
for (int i = 0; i < NUM_CHARS; i++) {
if (c == charlist[i] && font->charlist[i] != 0xffff)
if (charlist[i] == c && font->charlist[i] != 0xffff)
return i;
}
@ -468,8 +524,8 @@ printcolor(uint8_t color)
uint8_t fg = color & 0x0f;
uint8_t bg = (color & 0xf0) >> 4;
/* thedraw colors DRK BRT BRT BRT RED BRT */
/* thedraw colors BLK BLU GRN CYN RED MAG BRN GRY GRY BLU GRN CYN RED PNK YLW WHT */
/* thedraw colors BRT BRT BRT BRT BRT BRT BRT BRT */
/* thedraw colors BLK BLU GRN CYN RED MAG BRN GRY BLK BLU GRN CYN RED PNK YLW WHT */
uint8_t fgacolors[] = {30, 34, 32, 36, 31, 35, 33, 37, 90, 94, 92, 96, 91, 95, 93, 97};
uint8_t bgacolors[] = {40, 44, 42, 46, 41, 45, 43, 47};
uint8_t fgmcolors[] = { 1, 2, 3, 10, 5, 6, 7, 15, 14, 12, 9, 11, 4, 13, 8, 0};
@ -495,7 +551,7 @@ printrow(const glyph_t *glyph, int row)
uint8_t lastcolor;
for (i = 0; i < glyph->width; i++) {
utfchar = glyph->cell[glyph->width * row + i].utfchar;
utfchar = glyph->cell[glyph->width * row + i].utfchar;
color = glyph->cell[glyph->width * row + i].color;
if (i == 0 || color != lastcolor) {
@ -520,11 +576,18 @@ printstr(const char *str, font_t *font)
int linewidth = 0;
int len = strlen(str);
int padding = 0;
int n = 0;
for (int i = 0; i < len; i++) {
glyph_t *g;
g = font->glyphs[lookupchar(str[i], font)];
n = lookupchar(str[i], font);
if (n == -1) {
continue;
}
g = font->glyphs[n];
if (g->height > maxheight) {
maxheight = g->height;
@ -548,7 +611,13 @@ printstr(const char *str, font_t *font)
}
for (int c = 0; c < strlen(str); c++) {
glyph_t *g = font->glyphs[lookupchar(str[c], font)];
n = lookupchar(str[c], font);
if (n == -1) {
continue;
}
glyph_t *g = font->glyphs[n];
printrow(g, i);
if (opt.color == COLOR_ANSI) {

Some files were not shown because too many files have changed in this diff Show More