ploot-text.c - ploot - simple plotting tools
(HTM) git clone git://bitreich.org/ploot git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/ploot
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) README
(DIR) LICENSE
---
ploot-text.c (1094B)
---
1 #include <assert.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <errno.h>
7
8 #ifndef __OpenBSD__
9 #define pledge(...) 0
10 #endif
11
12 #include "drawille.h"
13 #include "font.h"
14 #include "util.h"
15
16 void
17 usage(void)
18 {
19 fprintf(stderr, "usage: %s [-12] text\n", arg0);
20 exit(100);
21 }
22
23 int
24 main(int argc, char **argv)
25 {
26 struct font *ft;
27 struct drawille *drw;
28 char *text;
29 size_t h, w;
30 int c, row;
31
32 if (pledge("stdio", "") < 0)
33 err(1, "pledge: %s", strerror(errno));
34
35 ft = &font8;
36 arg0 = *argv;
37 while ((c = getopt(argc, argv, "12")) > -1) {
38 switch (c) {
39 case '1':
40 ft = &font8;
41 break;
42 case '2':
43 ft = &font13;
44 break;
45 default:
46 usage();
47 }
48 }
49 argc -= optind;
50 argv += optind;
51
52 if (argc != 1)
53 usage();
54
55 text = *argv;
56
57 h = (ft->height + 3) / 4;
58 w = font_strlen(ft, text) / 2;
59 if ((drw = drawille_new(h, w)) == NULL)
60 err(1, "drawille_new: %s", strerror(errno));
61 drawille_text(drw, 0, 0, ft, text);
62
63 for (row = 0; row < drw->row; row++) {
64 drawille_put_row(stdout, drw, row);
65 fprintf(stdout, "\n");
66 }
67
68 free(drw);
69 return 0;
70 }