move the tests out of tree
[ctxt.git] / ctxt.c
blobd7cc48c0154d44ce98322648ac41d315fbb707f8
1 /*
2 * ctxt - a simple and fast plain text formatter
4 * Copyright (C) 2009-2010 Ali Gholami Rudi
6 * This program is released under GNU GPL version 2.
7 */
8 #include <stdlib.h>
9 #include <string.h>
10 #include <stdio.h>
11 #include <unistd.h>
12 #include "ctxt.h"
13 #include "util.h"
15 static struct fmt_ops *get_ops(char *name)
17 if (!strcmp(name, "troff"))
18 return &troff_ops;
19 if (!strcmp(name, "latex"))
20 return &latex_ops;
21 if (!strcmp(name, "html"))
22 return &html_ops;
23 return NULL;
26 static char *usage =
27 "usage: ctxt [-m mode] <plaintext >formatted\n\n"
28 " mode: latex, html or troff (default: latex)\n";
30 int main(int argc, char **argv)
32 struct txt *txt;
33 struct doc *doc;
34 char *mode = "latex";
35 struct fmt_ops *ops;
36 int i;
37 for (i = 1; i < argc; i++) {
38 if (!strcmp("-m", argv[i]) && i + 1 < argc) {
39 mode = argv[++i];
40 continue;
42 die(usage);
44 if (!(ops = get_ops(mode)))
45 die("unknown output format\n");
46 txt = txt_alloc(0);
47 doc = doc_alloc(1);
48 format(doc, txt, ops);
49 doc_free(doc);
50 txt_free(txt);
51 return 0;