neatroff.ms: add entry describing new .evc request
[neatroff_make.git] / soin / soin.c
blobb86b505bf7ad732511d64ab18774a17db84a1edd
1 /* soin: inline troff .so requests */
2 #include <ctype.h>
3 #include <stdio.h>
4 #include <stdlib.h>
6 #define LNLEN 2048
8 static int soin(char *path);
10 static int soin_cmd(char *s)
12 char path[LNLEN];
13 char *d = path;
14 if (s[0] != '.' || s[1] != 's' || s[2] != 'o' || s[3] != ' ')
15 return 1;
16 s += 3;
17 while (isspace((unsigned char) *s))
18 s++;
19 if (s[0] == '"') {
20 s++;
21 while (*s && *s != '\n' && *s != '"')
22 *d++ = *s++;
23 } else {
24 while (*s && *s != ' ' && *s != '\n')
25 *d++ = *s++;
27 *d = '\0';
28 return soin(path);
31 static int soin(char *path)
33 FILE *fp = path ? fopen(path, "r") : stdin;
34 int lineno = 1;
35 char ln[LNLEN];
36 if (!fp) {
37 fprintf(stderr, "soin: cannot open <%s>\n", path);
38 return 1;
40 printf(".lf %d %s\n", lineno, path ? path : "stdin");
41 while (fgets(ln, sizeof(ln), fp)) {
42 lineno++;
43 if (!soin_cmd(ln))
44 printf(".lf %d %s\n", lineno, path ? path : "stdin");
45 else
46 fputs(ln, stdout);
47 if (ln[0] == '.' && ln[1] == 'l' && ln[2] == 'f')
48 sscanf(ln, ".lf %d", &lineno);
50 if (path)
51 fclose(fp);
52 return 0;
55 int main(void)
57 soin(NULL);
58 return 0;