Root/tools/ant-txt/ant-txt.c

Source at commit 0f17c404d2bf724b17d8443d6b76701f50be673d created 11 years 6 days ago.
By Werner Almesberger, BOOKSHELF: add data sheets of parts for next Tornado iteration
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 <unistd.h>
18#include <assert.h>
19#include <sys/types.h>
20
21#include <libant/libant.h>
22
23
24#define W 80
25#define H 16
26
27
28static void usage(const char *name)
29{
30    fprintf(stderr, "usage: %s [-b|-x] [-F font_dir ...] [text]\n", name);
31    exit(1);
32}
33
34
35int main(int argc, char **argv)
36{
37    struct edit *edits = NULL, **last = &edits;
38    uint8_t *canvas;
39    const char *err;
40    int binary = 0, xbm = 0;
41    int i, c, res;
42
43    while ((c = getopt(argc, argv, "bF:x")) != EOF)
44        switch (c) {
45        case 'b':
46            binary = 1;
47            break;
48        case 'x':
49            xbm = 1;
50            break;
51        case 'F':
52            add_font_dir(optarg);
53            break;
54        default:
55            usage(*argv);
56        }
57    if (binary && xbm)
58        usage(*argv);
59    for (i = optind; i != argc; i++) {
60        while (*last)
61            last = &(*last)->next;
62        if (edits) {
63            *last = malloc(sizeof(struct edit));
64            if (!*last)
65                abort();
66            (*last)->type = edit_nl;
67            last = &(*last)->next;
68        }
69        *last = text2edit(argv[i], &err);
70        if (!*last) {
71            fprintf(stderr, "\"%s\": %s\n", argv[i], err);
72            return 1;
73        }
74    }
75
76    canvas = apply_edits(W, H, edits, &err);
77    if (!canvas) {
78        fprintf(stderr, "%s\n", err);
79        return 1;
80    }
81    if (binary)
82        res = dump_binary(stdout, canvas, W, H);
83    else if (xbm)
84        res = dump_xbm(stdout, canvas, W, H);
85    else
86        res = dump_ascii(stdout, canvas, W, H);
87    if (res < 0) {
88        perror("write");
89        exit(1);
90    }
91    if (fflush(stdout) == EOF) {
92        perror("fflush");
93        exit(1);
94    }
95    return 0;
96}
97

Archive Download this file

Branches:
master
tornado-v1



interactive