fmt: consider the whole paragraphs before traps
[neatroff.git] / roff.c
blobc2e8f151469e7304dbf3426eff543a493e5e7d0f
1 /*
2 * neatroff troff clone
4 * Copyright (C) 2012-2014 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 void errmsg(char *fmt, ...)
16 va_list ap;
17 va_start(ap, fmt);
18 vfprintf(stderr, fmt, ap);
19 va_end(ap);
22 void errdie(char *msg)
24 fprintf(stderr, msg);
25 exit(1);
28 static char *usage =
29 "Usage: neatroff [options] input\n\n"
30 "Options:\n"
31 " -mx \tinclude macro x\n"
32 " -C \tenable compatibility mode\n"
33 " -Tdev \tset output device\n"
34 " -Fdir \tset font directory (" TROFFFDIR ")\n"
35 " -Mdir \tset macro directory (" TROFFMDIR ")\n";
37 int main(int argc, char **argv)
39 char fontdir[PATHLEN] = TROFFFDIR;
40 char macrodir[PATHLEN] = TROFFMDIR;
41 char dev[PATHLEN] = "utf";
42 char path[PATHLEN];
43 int i;
44 int ret;
45 for (i = 1; i < argc; i++) {
46 if (argv[i][0] != '-' || !argv[i][1])
47 break;
48 switch (argv[i][1]) {
49 case 'C':
50 n_cp = 1;
51 break;
52 case 'm':
53 sprintf(path, "%s/tmac.%s", macrodir, argv[i] + 2);
54 in_queue(path);
55 break;
56 case 'F':
57 strcpy(fontdir, argv[i][2] ? argv[i] + 2 : argv[++i]);
58 break;
59 case 'M':
60 strcpy(macrodir, argv[i][2] ? argv[i] + 2 : argv[++i]);
61 break;
62 case 'T':
63 strcpy(dev, argv[i][2] ? argv[i] + 2 : argv[++i]);
64 break;
65 default:
66 printf("%s", usage);
67 return 0;
70 if (dev_open(fontdir, dev)) {
71 fprintf(stderr, "neatroff: cannot open device %s\n", dev);
72 return 1;
74 env_init();
75 tr_init();
76 if (i == argc)
77 in_queue(NULL); /* reading from standard input */
78 for (; i < argc; i++)
79 in_queue(!strcmp("-", argv[i]) ? NULL : argv[i]);
80 str_set(map(".P"), macrodir);
81 out("s%d\n", n_s);
82 out("f%d\n", n_f);
83 ret = render();
84 out("V%d\n", n_p);
85 env_done();
86 dev_close();
87 return ret;