roff: add a basic troff backend
[ctxt.git] / ctxt.c
blob0a5f5a464aa17e837ebb6b99e1a635924bd29366
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 static struct fmt_ops *get_ops(char *name)
11 if (!strcmp(name, "troff"))
12 return &troff_ops;
13 if (!strcmp(name, "latex"))
14 return &latex_ops;
15 if (!strcmp(name, "html"))
16 return &html_ops;
17 return NULL;
20 static char *version =
21 "CTXT 0.1\n"
22 "Copyright (C) 2009 Ali Gholami Rudi\n"
23 "You can redistribute and/or modify ctxt under the terms\n"
24 "of GNU General Public License. For more information, see\n"
25 "COPYING.\n";
27 static char *help =
28 "usage: ctxt [-m mode] <plaintext >formatted\n\n"
29 " -m\t\toutput format: latex or html (default: latex)\n"
30 " -h\t\tshow this screen\n"
31 " -v\t\tshow version\n";
33 int main(int argc, char **argv)
35 struct txt *txt;
36 struct doc *doc;
37 char *mode = "latex";
38 struct fmt_ops *ops;
39 int c;
40 while ((c = getopt(argc, argv, "hvm:")) != -1) {
41 switch (c) {
42 case 'h':
43 puts(help);
44 return 0;
45 case 'v':
46 puts(version);
47 return 0;
48 case 'm':
49 mode = optarg;
50 break;
51 case '?':
52 return 1;
53 default:
54 die("bad command line option\n");
57 if (!(ops = get_ops(mode)))
58 die("unknown output format\n");
59 txt = txt_alloc(STDIN_FILENO);
60 doc = doc_alloc(STDOUT_FILENO);
61 format(doc, txt, ops);
62 doc_free(doc);
63 txt_free(txt);
64 return 0;