From fbe0767eb4301d60c7d55a494fb281e8599e1591 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sat, 30 Jun 2012 14:58:25 -0300 Subject: [PATCH] tools/ant-txt/: new utility to compose texts for Antorcha --- tools/ant-txt/Makefile | 37 +++++++++++++++++++++++ tools/ant-txt/ant-txt.c | 65 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 tools/ant-txt/Makefile create mode 100644 tools/ant-txt/ant-txt.c diff --git a/tools/ant-txt/Makefile b/tools/ant-txt/Makefile new file mode 100644 index 0000000..39d0e4c --- /dev/null +++ b/tools/ant-txt/Makefile @@ -0,0 +1,37 @@ +# +# tools/ant-txt/Makefile - Build the Antorcha text composer +# +# Written 2012 by Werner Almesberger +# Copyright 2012 Werner Almesberger +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# + + +MAIN = ant-txt + +CFLAGS = -g -Wall -I.. \ + $(if $(BEN), -static) + +LDLIBS = -L../libtxt -ltxt + +OBJS = ant-txt.o + +.PHONY: all ben clean spotless + +all: $(MAIN) + +ben: + $(MAKE) BEN=y CC=mipsel-openwrt-linux-gcc + +$(MAIN): $(OBJS) + $(CC) $(CFLAGS) -o $@ $(OBJS) $(LDLIBS) + +clean: + rm -f $(OBJS) + +spotless: clean + rm -f $(MAIN) diff --git a/tools/ant-txt/ant-txt.c b/tools/ant-txt/ant-txt.c new file mode 100644 index 0000000..9c03c4d --- /dev/null +++ b/tools/ant-txt/ant-txt.c @@ -0,0 +1,65 @@ +/* + * tools/ant-txt/ant-txt.c - Antorcha text composer + * + * Written 2012 by Werner Almesberger + * Copyright 2012 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + + +#include +#include +#include +#include + +#include + + +#define W 80 +#define H 16 + + +int main(int argc, char **argv) +{ + struct edit *edits = NULL, **last = &edits; + uint8_t *canvas; + const char *err; + int i, x, y; + + for (i = 1; i != argc; i++) { + while (*last) + last = &(*last)->next; + if (edits) { + *last = malloc(sizeof(struct edit)); + if (!*last) + abort(); + (*last)->type = edit_nl; + last = &(*last)->next; + } + *last = text2edit(argv[i]); + if (!*last) { + fprintf(stderr, "\"%s\": compilation failed\n", + argv[i]); + return 1; + } + } + + canvas = apply_edits(W, H, edits, &err); + if (!canvas) { + fprintf(stderr, "%s\n", err); + return 1; + } + for (y = 0; y != H; y++) { + for (x = 0; x != W; x++) + if (canvas[(y*W+x) >> 3] & (1 << (x & 7))) + putchar('#'); + else + putchar('.'); + putchar('\n'); + } + return 0; +}