-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmakedoc.c
78 lines (62 loc) · 1.45 KB
/
makedoc.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* <<<<Last Modified: Tue Jan 16 11:15:24 1996>>>>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LINELEN 256
int main () {
const char help_name[] = "cpcfs.hlp";
const char template_name[] = "template.doc";
const char doc_name[] = "doc";
char line[LINELEN];
char topic[20];
FILE *help, *template, *doc;
int found; /* as bool */
help = fopen(help_name,"r");
if (help==NULL) {
fprintf(stderr,"I cannot open \"%s\"",help_name);
exit(1);
}
template = fopen(template_name,"r");
if (template==NULL) {
fprintf(stderr,"I cannot open \"%s\"",template_name);
exit(1);
}
doc = fopen(doc_name,"w");
if (doc==NULL) {
fprintf(stderr,"I cannot open \"%s\"",doc_name);
exit(1);
}
while (fgets(line,LINELEN,template) != NULL) {
if (line[0]=='~') {
strncpy(topic,line,20);
if (topic[strlen(topic)-1]=='\n') {
topic[strlen(topic)-1] = 0;
}
fseek(help,0L,SEEK_SET);
found = 0;
while (fgets(line,LINELEN,help) != NULL) {
if (found && line[0]!='~')
fputs(line,doc);
if (found && line[0]=='~') {
found=0;
continue;
}
if (!found&& line[0]!='~')
continue;
if (!found&& line[0]=='~')
found = (strstr(line,topic)!=NULL);
}
} else {
fputs(line,doc);
}
}
fclose(doc);
fclose(template);
fclose(help);
printf("Merged \"%s\" and \"%s\" to \"%s\"\n",
template_name, help_name, doc_name);
printf("You can now copy \"%s\" to \"cpcfs.doc\"\n",
doc_name);
return 0;
}