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");
49 if (end
== strlen(outbuf
) && memcmp(cmpbuf
, outbuf
, end
) == 0)
56 out
= fopen(filename
, "wb");
59 fprintf(stderr
, "Unable to create output file\n");
63 stat
= fwrite(outbuf
, 1, strlen(outbuf
), out
);
64 if (strlen(outbuf
) != stat
)
66 fprintf(stderr
, "Unable to write output file\n");
75 main(int argc
, char* argv
[])
85 fprintf(stderr
, "Not enough arguments\n");
89 outbuf
= malloc(256 * 1024);
92 fprintf(stderr
, "Out of memory 1\n");
97 s
= s
+ sprintf(s
, "/* Automatically generated, ");
98 s
= s
+ sprintf(s
, "Edit the Makefile to change configuration */\n");
99 s
= s
+ sprintf(s
, "#ifndef __INCLUDE_CONFIG_H\n");
100 s
= s
+ sprintf(s
, "#define __INCLUDE_CONFIG_H\n");
103 for (i
= 2; i
< argc
; i
++)
105 if (strcmp(argv
[i
], "REGTESTS") == 0)
111 s
= s
+ sprintf(s
, "#ifndef %s\n", argv
[i
]);
112 s
= s
+ sprintf(s
, "#define %s\n", argv
[i
]);
113 s
= s
+ sprintf(s
, "#endif /* %s */\n", argv
[i
]);
115 strcat(config
, argv
[i
]);
123 s
= s
+ sprintf(s
, "#ifndef __ASM__\n");
124 s
= s
+ sprintf(s
, "extern void PrepareTests();\n");
125 s
= s
+ sprintf(s
, "#define PREPARE_TESTS PrepareTests();\n");
126 s
= s
+ sprintf(s
, "#endif /* __ASM__ */\n");
130 s
= s
+ sprintf(s
, "#define PREPARE_TESTS\n");
132 s
= s
+ sprintf(s
, "#define CONFIG \"%s\"\n", config
);
133 s
= s
+ sprintf(s
, "#endif /* __INCLUDE_CONFIG_H */\n");
135 return(write_if_change(outbuf
, argv
[1]));