|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
#include<stdio.h> |
|
|
|
|
#include<assert.h> |
|
|
|
|
#include<string.h> |
|
|
|
|
|
|
|
|
|
#define ARRSIZE 80 |
|
|
|
|
|
|
|
|
@ -7,17 +8,20 @@ int main(int argc, char **argv) { |
|
|
|
|
char arr[ARRSIZE]; |
|
|
|
|
char *ofilename; |
|
|
|
|
char *ifilename; |
|
|
|
|
char *dfilename; |
|
|
|
|
FILE *ifile; |
|
|
|
|
FILE *ofile; |
|
|
|
|
FILE *depfile; |
|
|
|
|
size_t bytes; |
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
if(argc != 3) { |
|
|
|
|
fprintf(stderr, "%s <input file> <output file>\n", argv[0]); |
|
|
|
|
if(argc != 4) { |
|
|
|
|
fprintf(stderr, "%s <input file> <output file> <dependency file>\n", argv[0]); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
ifilename = argv[1]; |
|
|
|
|
ofilename = argv[2]; |
|
|
|
|
printf("%s\n", ifilename); |
|
|
|
|
dfilename = argv[3]; |
|
|
|
|
ifile = fopen(argv[1], "r"); |
|
|
|
|
if(!ifile) { |
|
|
|
|
fprintf(stderr, "Could not open source file %s.\n", argv[1]); |
|
|
|
@ -34,7 +38,32 @@ int main(int argc, char **argv) { |
|
|
|
|
assert(bytes > 0); |
|
|
|
|
fwrite(arr, 1, bytes, ofile); |
|
|
|
|
|
|
|
|
|
depfile = fopen(dfilename, "w"); |
|
|
|
|
if(!depfile) { |
|
|
|
|
fprintf(stderr, "Could not open depfile %s\n", ofilename); |
|
|
|
|
fclose(ifile); |
|
|
|
|
fclose(ofile); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
for(i=0; i<strlen(ofilename); i++) { |
|
|
|
|
if(ofilename[i] == ' ') { |
|
|
|
|
fwrite("\\ ", 1, 2, depfile); |
|
|
|
|
} else { |
|
|
|
|
fwrite(&ofilename[i], 1, 1, depfile); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
fwrite(": ", 1, 2, depfile); |
|
|
|
|
for(i=0; i<strlen(ifilename); i++) { |
|
|
|
|
if(ifilename[i] == ' ') { |
|
|
|
|
fwrite("\\ ", 1, 2, depfile); |
|
|
|
|
} else { |
|
|
|
|
fwrite(&ifilename[i], 1, 1, depfile); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
fwrite("\n", 1, 1, depfile); |
|
|
|
|
|
|
|
|
|
fclose(ifile); |
|
|
|
|
fclose(ofile); |
|
|
|
|
fclose(depfile); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|