Debian Codegraph @

vendored-meson/meson/test cases/native/3 pipeline/srcgen.c

raw
1 #include<stdio.h>
2 #include<assert.h>
3 #include<string.h>
4
5 #define ARRSIZE 80
6
7 int main(int argc, char **argv) {
8 char arr[ARRSIZE];
9 char *ofilename;
10 char *ifilename;
11 char *dfilename;
12 FILE *ifile;
13 FILE *ofile;
14 FILE *depfile;
15 size_t bytes;
16 int i;
17
18 if(argc != 4) {
19 fprintf(stderr, "%s <input file> <output file> <dependency file>\n", argv[0]);
20 return 1;
21 }
22 ifilename = argv[1];
23 ofilename = argv[2];
24 dfilename = argv[3];
25 ifile = fopen(argv[1], "r");
26 if(!ifile) {
27 fprintf(stderr, "Could not open source file %s.\n", argv[1]);
28 return 1;
29 }
30 ofile = fopen(ofilename, "w");
31 if(!ofile) {
32 fprintf(stderr, "Could not open target file %s\n", ofilename);
33 fclose(ifile);
34 return 1;
35 }
36 bytes = fread(arr, 1, ARRSIZE, ifile);
37 assert(bytes < 80);
38 assert(bytes > 0);
39 fwrite(arr, 1, bytes, ofile);
40
41 depfile = fopen(dfilename, "w");
42 if(!depfile) {
43 fprintf(stderr, "Could not open depfile %s\n", ofilename);
44 fclose(ifile);
45 fclose(ofile);
46 return 1;
47 }
48 for(i=0; i<strlen(ofilename); i++) {
49 if(ofilename[i] == ' ') {
50 fwrite("\\ ", 1, 2, depfile);
51 } else {
52 fwrite(&ofilename[i], 1, 1, depfile);
53 }
54 }
55 fwrite(": ", 1, 2, depfile);
56 for(i=0; i<strlen(ifilename); i++) {
57 if(ifilename[i] == ' ') {
58 fwrite("\\ ", 1, 2, depfile);
59 } else {
60 fwrite(&ifilename[i], 1, 1, depfile);
61 }
62 }
63 fwrite("\n", 1, 1, depfile);
64
65 fclose(ifile);
66 fclose(ofile);
67 fclose(depfile);
68 return 0;
69 }