html: add html output format
[ctxt.git] / ctxt.c
blob5d75d271f4d90dd8c6d259f4acfbcab2ad901281
1 #include <getopt.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <unistd.h>
6 #include "ctxt.h"
7 #include "util.h"
9 void file_put(int fd, char *s)
11 int c = 0;
12 int n = 0;
13 size_t size = strlen(s);
14 while (size > n && (c = write(fd, s + n, size - n)) >= 0)
15 n += c;
18 static struct fmt_ops *get_ops(char *name)
20 if (!strcmp(name, "latex"))
21 return &latex_ops;
22 if (!strcmp(name, "html"))
23 return &html_ops;
24 return NULL;
27 int main(int argc, char **argv)
29 struct txt *txt;
30 char *mode = "latex";
31 struct fmt_ops *ops;
32 int c;
33 while ((c = getopt(argc, argv, "m:")) != -1) {
34 switch (c) {
35 case 'm':
36 mode = optarg;
37 break;
38 case '?':
39 default:
40 fprintf(stderr, "bad command line option\n");
41 return 1;
44 if (!(ops = get_ops(mode))) {
45 fprintf(stderr, "unknown output format\n");
46 return 1;
48 txt = txt_alloc(STDIN_FILENO);
49 fmt(STDOUT_FILENO, txt, ops);
50 txt_free(txt);
51 return 0;