From ee0a2e7e1965200ec5968ec310bee429db819dde Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Sun, 3 Sep 2023 22:20:31 +0200 Subject: Remove const --- gen_inl.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 18 deletions(-) (limited to 'gen_inl.c') diff --git a/gen_inl.c b/gen_inl.c index 116c5f5..94256ab 100644 --- a/gen_inl.c +++ b/gen_inl.c @@ -8,27 +8,56 @@ exit #include #include -char const *const SOURCES[] = { - "./source/kit/status.h", "./source/kit/allocator.h", - "./source/kit/array_ref.h", "./source/kit/dynamic_array.h", - "./source/kit/string_ref.h", "./source/kit/file.h", - "./source/kit/allocator.c", "./source/kit/array_ref.c", - "./source/kit/dynamic_array.c", "./source/kit/file.c" -}; - -char const *repeat(int n, char c) { +char *HEADERS[] = { "source/kit/types.h", + "source/kit/status.h", + "source/kit/allocator.h", + "source/kit/thread_defs.h", + "source/kit/thread.h", + "source/kit/atomic.h", + "source/kit/mutex.h", + "source/kit/condition_variable.h", + "source/kit/array_ref.h", + "source/kit/string_ref.h", + "source/kit/dynamic_array.h", + "source/kit/lower_bound.h", + "source/kit/move_back.h", + "source/kit/bigint.h", + "source/kit/input_stream.h", + "source/kit/input_buffer.h", + "source/kit/async_function.h", + "source/kit/file.h", + "source/kit/mersenne_twister_64.h", + "source/kit/secure_random.h", + "source/kit/sha256.h", + "source/kit/sockets.h" }; + +char *IMPL[] = { "source/kit/allocator.c", + "source/kit/thread.posix.c", + "source/kit/thread.win32.c", + "source/kit/atomic.win32.c", + "source/kit/mutex.c", + "source/kit/condition_variable.c", + "source/kit/dynamic_array.c", + "source/kit/input_stream.c", + "source/kit/input_buffer.c", + "source/kit/file.c", + "source/kit/mersenne_twister_64.c", + "source/kit/secure_random.c", + "source/kit/sha256.c" }; + +char *repeat(int n, char c) { static char buf[200]; for (int i = 0; i < n && i < 199; i++) buf[i] = c; buf[n] = '\0'; return buf; } -int skip_whitespaces(char const *const line, int i) { +int skip_whitespaces(char *line, int i) { while (line[i] == ' ') i++; return i; } -int skip(char const *const line, int i, char const *const s) { +int skip(char *line, int i, char *s) { int j = 0; while (s[j] != '\0') { if (line[i] != s[j]) @@ -39,7 +68,7 @@ int skip(char const *const line, int i, char const *const s) { return i; } -int is_local_include(char const *const line) { +int is_local_include(char *line) { if (line[0] != '#') return 0; int i = skip_whitespaces(line, 1); @@ -52,12 +81,12 @@ int is_local_include(char const *const line) { return 1; } -int is_empty_line(char const *const line) { +int is_empty_line(char *line) { int i = skip_whitespaces(line, 0); return line[i] == '\0' || line[i] == '\n'; } -int write_file(FILE *out, char const *const source) { +int write_file(FILE *out, char *source) { assert(out != NULL); assert(source != NULL); @@ -99,8 +128,9 @@ int write_file(FILE *out, char const *const source) { } int main(int argc, char **argv) { - char const *const out_file = "./include/kit.inl.h"; - FILE *out = fopen(out_file, "wt"); + char *out_file = "./include/kit.inl.h"; + FILE *out = fopen(out_file, "wt"); + if (out == NULL) { fprintf(stderr, "Can't write: %s\n", out_file); return 1; @@ -109,12 +139,21 @@ int main(int argc, char **argv) { fprintf(out, "#ifndef KIT_INL_H\n"); fprintf(out, "#define KIT_INL_H\n"); - for (int i = 0; i < sizeof SOURCES / sizeof *SOURCES; i++) - if (write_file(out, SOURCES[i]) != 0) { + for (int i = 0; i < sizeof HEADERS / sizeof *HEADERS; i++) + if (write_file(out, HEADERS[i]) != 0) { fclose(out); return 1; } + fprintf(out, "#ifdef KIT_IMPLEMENTATION\n"); + + for (int i = 0; i < sizeof IMPL / sizeof *IMPL; i++) + if (write_file(out, IMPL[i]) != 0) { + fclose(out); + return 1; + } + + fprintf(out, "#endif\n"); fprintf(out, "#endif\n"); fclose(out); -- cgit v1.2.3