6 #define max(a, b) ((a) > (b) ? (a) : (b))
10 write_if_change(char* outbuf
, char* filename
)
17 out
= fopen(filename
, "rb");
20 out
= fopen(filename
, "wb");
23 fprintf(stderr
, "Unable to create output file\n");
31 fseek(out
, 0, SEEK_END
);
36 fprintf(stderr
, "Out of memory\n");
41 fseek(out
, 0, SEEK_SET
);
42 stat
= fread(cmpbuf
, 1, end
, out
);
45 fprintf(stderr
, "Failed to read data\n");
50 if (end
== strlen(outbuf
) && memcmp(cmpbuf
, outbuf
, end
) == 0)
59 out
= fopen(filename
, "wb");
62 fprintf(stderr
, "Unable to create output file\n");
66 stat
= fwrite(outbuf
, 1, strlen(outbuf
), out
);
67 if (strlen(outbuf
) != stat
)
69 fprintf(stderr
, "Unable to write output file\n");
78 main(int argc
, char* argv
[])
88 fprintf(stderr
, "Not enough arguments\n");
92 outbuf
= malloc(256 * 1024);
95 fprintf(stderr
, "Out of memory 1\n");
100 s
= s
+ sprintf(s
, "/* Automatically generated, ");
101 s
= s
+ sprintf(s
, "Edit the Makefile to change configuration */\n");
102 s
= s
+ sprintf(s
, "#ifndef __INCLUDE_CONFIG_H\n");
103 s
= s
+ sprintf(s
, "#define __INCLUDE_CONFIG_H\n");
106 for (i
= 2; i
< argc
; i
++)
108 if (strcmp(argv
[i
], "REGTESTS") == 0)
114 s
= s
+ sprintf(s
, "#ifndef %s\n", argv
[i
]);
115 s
= s
+ sprintf(s
, "#define %s\n", argv
[i
]);
116 s
= s
+ sprintf(s
, "#endif /* %s */\n", argv
[i
]);
118 strcat(config
, argv
[i
]);
126 s
= s
+ sprintf(s
, "#ifndef __ASM__\n");
127 s
= s
+ sprintf(s
, "extern void PrepareTests();\n");
128 s
= s
+ sprintf(s
, "#define PREPARE_TESTS PrepareTests();\n");
129 s
= s
+ sprintf(s
, "#endif /* __ASM__ */\n");
133 s
= s
+ sprintf(s
, "#define PREPARE_TESTS\n");
135 s
= s
+ sprintf(s
, "#define CONFIG \"%s\"\n", config
);
136 s
= s
+ sprintf(s
, "#endif /* __INCLUDE_CONFIG_H */\n");
138 return(write_if_change(outbuf
, argv
[1]));