ren: disable .char for diverted text
[neatroff.git] / roff.c
blob24d79e2c9248ad013524904feb6008018213d058
1 /*
2 * neatroff troff clone
4 * Copyright (C) 2012-2013 Ali Gholami Rudi <ali at rudi dot ir>
6 * This program is released under the modified BSD license.
7 */
8 #include <stdarg.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdlib.h>
12 #include "roff.h"
14 static void g_init(void)
16 n_o = SC_IN;
17 n_p = SC_IN * 11;
18 n_lg = 1;
19 n_kn = 0;
22 void errmsg(char *fmt, ...)
24 va_list ap;
25 va_start(ap, fmt);
26 vfprintf(stderr, fmt, ap);
27 va_end(ap);
30 void errdie(char *msg)
32 fprintf(stderr, msg);
33 exit(1);
36 static char *usage =
37 "Usage: neatcc [options] input\n"
38 "Options:\n"
39 " -mx \tinclude macro x\n"
40 " -C \tenable compatibility mode\n"
41 " -Tdev \tset output device\n"
42 " -Fdir \tset font directory (" TROFFFDIR ")\n"
43 " -Mdir \tset macro directory (" TROFFMDIR ")\n";
45 int main(int argc, char **argv)
47 char fontdir[PATHLEN] = TROFFFDIR;
48 char macrodir[PATHLEN] = TROFFMDIR;
49 char dev[PATHLEN] = "utf";
50 char path[PATHLEN];
51 int i;
52 int ret;
53 for (i = 1; i < argc; i++) {
54 if (argv[i][0] != '-' || !argv[i][1])
55 break;
56 switch (argv[i][1]) {
57 case 'C':
58 n_cp = 1;
59 break;
60 case 'm':
61 sprintf(path, "%s/tmac.%s", macrodir, argv[i] + 2);
62 in_queue(path);
63 break;
64 case 'F':
65 strcpy(fontdir, argv[i][2] ? argv[i] + 2 : argv[++i]);
66 break;
67 case 'M':
68 strcpy(macrodir, argv[i][2] ? argv[i] + 2 : argv[++i]);
69 break;
70 case 'T':
71 strcpy(dev, argv[i][2] ? argv[i] + 2 : argv[++i]);
72 break;
73 default:
74 printf("%s", usage);
75 return 0;
78 if (dev_open(fontdir, dev)) {
79 fprintf(stderr, "neatroff: cannot open device %s\n", dev);
80 return 1;
82 env_init();
83 tr_init();
84 g_init();
85 if (i == argc)
86 in_queue(NULL); /* reading from standard input */
87 for (; i < argc; i++)
88 in_queue(!strcmp("-", argv[i]) ? NULL : argv[i]);
89 str_set(map(".P"), macrodir);
90 out("s%d\n", n_s);
91 out("f%d\n", n_f);
92 ret = render();
93 out("V%d\n", n_p);
94 env_done();
95 dev_close();
96 return ret;