-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathimport.c
More file actions
36 lines (34 loc) · 791 Bytes
/
import.c
File metadata and controls
36 lines (34 loc) · 791 Bytes
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
#include <stdio.h>
#include <string.h>
#define LINESIZE 1024
int readFile(char name[], FILE * ofp)
{
FILE *fp;
char line[LINESIZE], word[LINESIZE], word2[LINESIZE];
size_t len = strlen(name);
if (name[len - 1] == '"')
name[len - 1] = '\0';
if (name[0] == '"') {
name++;
}
if ((fp = fopen(name, "r")) == 0) {
perror("open");
return 1;
}
while (fgets(line, LINESIZE, fp)) {
if (sscanf(line, "%s%s", word, word2) == 2 && strcmp(word, "import") == 0) {
readFile(word2, ofp);
} else
fprintf(ofp, "%s", line);
}
}
int main(void)
{
FILE *fp = fopen("/tmp/abc.xxx", "w");
if (fp == 0) {
perror("fopen");
return 1;
}
readFile("abc", fp);
return 0;
}