Change Details
tools/ant-txt/Makefile |
| 1 | # |
| 2 | # tools/ant-txt/Makefile - Build the Antorcha text composer |
| 3 | # |
| 4 | # Written 2012 by Werner Almesberger |
| 5 | # Copyright 2012 Werner Almesberger |
| 6 | # |
| 7 | # This program is free software; you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation; either version 2 of the License, or |
| 10 | # (at your option) any later version. |
| 11 | # |
| 12 | |
| 13 | |
| 14 | MAIN = ant-txt |
| 15 | |
| 16 | CFLAGS = -g -Wall -I.. \ |
| 17 | $(if $(BEN), -static) |
| 18 | |
| 19 | LDLIBS = -L../libtxt -ltxt |
| 20 | |
| 21 | OBJS = ant-txt.o |
| 22 | |
| 23 | .PHONY: all ben clean spotless |
| 24 | |
| 25 | all: $(MAIN) |
| 26 | |
| 27 | ben: |
| 28 | $(MAKE) BEN=y CC=mipsel-openwrt-linux-gcc |
| 29 | |
| 30 | $(MAIN): $(OBJS) |
| 31 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LDLIBS) |
| 32 | |
| 33 | clean: |
| 34 | rm -f $(OBJS) |
| 35 | |
| 36 | spotless: clean |
| 37 | rm -f $(MAIN) |
tools/ant-txt/ant-txt.c |
| 1 | /* |
| 2 | * tools/ant-txt/ant-txt.c - Antorcha text composer |
| 3 | * |
| 4 | * Written 2012 by Werner Almesberger |
| 5 | * Copyright 2012 Werner Almesberger |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | |
| 14 | #include <stdint.h> |
| 15 | #include <stdlib.h> |
| 16 | #include <stdio.h> |
| 17 | #include <assert.h> |
| 18 | |
| 19 | #include <libtxt/libtxt.h> |
| 20 | |
| 21 | |
| 22 | #define W 80 |
| 23 | #define H 16 |
| 24 | |
| 25 | |
| 26 | int main(int argc, char **argv) |
| 27 | { |
| 28 | struct edit *edits = NULL, **last = &edits; |
| 29 | uint8_t *canvas; |
| 30 | const char *err; |
| 31 | int i, x, y; |
| 32 | |
| 33 | for (i = 1; i != argc; i++) { |
| 34 | while (*last) |
| 35 | last = &(*last)->next; |
| 36 | if (edits) { |
| 37 | *last = malloc(sizeof(struct edit)); |
| 38 | if (!*last) |
| 39 | abort(); |
| 40 | (*last)->type = edit_nl; |
| 41 | last = &(*last)->next; |
| 42 | } |
| 43 | *last = text2edit(argv[i]); |
| 44 | if (!*last) { |
| 45 | fprintf(stderr, "\"%s\": compilation failed\n", |
| 46 | argv[i]); |
| 47 | return 1; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | canvas = apply_edits(W, H, edits, &err); |
| 52 | if (!canvas) { |
| 53 | fprintf(stderr, "%s\n", err); |
| 54 | return 1; |
| 55 | } |
| 56 | for (y = 0; y != H; y++) { |
| 57 | for (x = 0; x != W; x++) |
| 58 | if (canvas[(y*W+x) >> 3] & (1 << (x & 7))) |
| 59 | putchar('#'); |
| 60 | else |
| 61 | putchar('.'); |
| 62 | putchar('\n'); |
| 63 | } |
| 64 | return 0; |
| 65 | } |
Download the corresponding diff file