-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathunify.c
51 lines (38 loc) · 762 Bytes
/
unify.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// merge latex files
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void emit(char *);
int
main(int argc, char *argv[])
{
int i;
system("cat preamble");
for (i = 1; i < argc; i++)
emit(argv[i]);
fputs("\\end{document}\n", stdout);
}
void
emit(char *filename)
{
FILE *f;
static char buf[1000];
fputs("\\newpage\n", stdout);
f = fopen(filename, "r");
if (f == NULL) {
fprintf(stderr, "cannot open %s\n", filename);
exit(1);
}
fgets(buf, sizeof buf, f); // skip first line
while (fgets(buf, sizeof buf, f)) {
if (strncmp(buf, "\\section*", 9) == 0) {
fputs("\\section", stdout);
fputs(buf + 9, stdout);
continue;
}
if (strcmp(buf, "\\end{document}\n") == 0)
break;
fputs(buf, stdout);
}
fclose(f);
}