From a7809eb68373b55ff8dbc6fe1b8355b150433cd5 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 24 Mar 2021 13:44:57 +0200 Subject: [PATCH] Solved coding style --- expand_line.c | 18 +++++++++--------- hashmap.c | 10 +++++----- include/expand_line.h | 4 ++-- include/hashmap.h | 12 +++++------- include/line_handler.h | 2 +- include/pp.h | 2 +- include/pp_args.h | 2 +- include/pp_define.h | 4 ++-- include/pp_if.h | 2 +- include/pp_ifdef.h | 2 +- include/pp_inc.h | 2 +- include/utils.h | 4 ++-- line_handler.c | 2 +- pp.c | 2 +- pp_args.c | 12 ++++++------ pp_define.c | 8 ++++---- pp_if.c | 2 +- pp_ifdef.c | 6 +++--- pp_inc.c | 6 +++--- so-cpp.c | 12 ++++++------ 20 files changed, 56 insertions(+), 58 deletions(-) diff --git a/expand_line.c b/expand_line.c index ab0c56e..fde0547 100644 --- a/expand_line.c +++ b/expand_line.c @@ -5,17 +5,17 @@ #define DELIMS "\t []{}<>=+-*/%!&|^.,:;()\\" -char *_compute_expanded_line(string_map_t def_map, char *line); -int _concat_expanded_token_to_line(string_map_t def_map, char *token, char **line); +char *_compute_expanded_line(void *def_map, char *line); +int _concat_expanded_token_to_line(void *def_map, char *token, char **line); int _concat_delim_to_line(char *delim, int delim_size, char **line); -char *_get_expanded_token(string_map_t def_map, char *token); +char *_get_expanded_token(void *def_map, char *token); int _concat_delim_to_line(char *delim, int delim_size, char **line); -int _concat_expanded_token_to_line(string_map_t def_map, char *token, char **line); +int _concat_expanded_token_to_line(void *def_map, char *token, char **line); int _is_delim_at_str_start(char *token, char *str_start); int _compute_delim_start(char *token, char *line); int _compute_delim_end(char *token, char *line, char *line_copy); -int write_expanded_line(string_map_t def_map, char *line, FILE *out) +int write_expanded_line(void *def_map, char *line, FILE *out) { char *exp_line; int line_len; @@ -35,7 +35,7 @@ int write_expanded_line(string_map_t def_map, char *line, FILE *out) return ret == line_len ? PP_OK : PP_FAILED; } -char *get_expanded_line(string_map_t def_map, char *line) +char *get_expanded_line(void *def_map, char *line) { char *exp_line; char *prev_exp_line; @@ -69,7 +69,7 @@ free_and_exit: return NULL; } -char *_compute_expanded_line(string_map_t def_map, char *line) +char *_compute_expanded_line(void *def_map, char *line) { char *_line; char *line_start; @@ -151,7 +151,7 @@ free_and_exit: return NULL; } -char *_get_expanded_token(string_map_t def_map, char *token) +char *_get_expanded_token(void *def_map, char *token) { char *exp; char *exp_copy; @@ -204,7 +204,7 @@ int _concat_delim_to_line(char *delim, int delim_size, char **line) return ret == -1 ? PP_FAILED : PP_OK; } -int _concat_expanded_token_to_line(string_map_t def_map, char *token, char **line) +int _concat_expanded_token_to_line(void *def_map, char *token, char **line) { char *exp; int ret; diff --git a/hashmap.c b/hashmap.c index 7a92d60..facf351 100644 --- a/hashmap.c +++ b/hashmap.c @@ -19,7 +19,7 @@ struct hashmap_map { struct hashmap_elem *data; }; -string_map_t hashmap_new(void) +void *hashmap_new(void) { struct hashmap_map *m; @@ -107,7 +107,7 @@ int _rehash(struct hashmap_map *m) return MAP_OK; } -int hashmap_put(string_map_t map, char *key, char *value) +int hashmap_put(void *map, char *key, char *value) { int pos; struct hashmap_map *m; @@ -141,7 +141,7 @@ int _is_desired_pos(struct hashmap_map *m, char *key, int pos) return m->data[pos].key && key && !strcmp(m->data[pos].key, key) && m->data[pos].in_use; } -int hashmap_get(string_map_t map, char *key, char **ret_val) +int hashmap_get(void *map, char *key, char **ret_val) { int pos; int i; @@ -168,7 +168,7 @@ int hashmap_get(string_map_t map, char *key, char **ret_val) return MAP_MISSING; } -int hashmap_del(string_map_t map, char *key) +int hashmap_del(void *map, char *key) { int pos; int i; @@ -200,7 +200,7 @@ int hashmap_del(string_map_t map, char *key) return MAP_MISSING; } -void hashmap_free(string_map_t map) +void hashmap_free(void *map) { struct hashmap_map *m; int i; diff --git a/include/expand_line.h b/include/expand_line.h index 4a18156..5e2f49b 100644 --- a/include/expand_line.h +++ b/include/expand_line.h @@ -5,7 +5,7 @@ #include "hashmap.h" #include -extern int write_expanded_line(string_map_t def_map, char *line, FILE *out); -extern char *get_expanded_line(string_map_t def_map, char *line); +extern int write_expanded_line(void *def_map, char *line, FILE*); +extern char *get_expanded_line(void *def_map, char *line); #endif diff --git a/include/hashmap.h b/include/hashmap.h index 571bf11..326ad7c 100644 --- a/include/hashmap.h +++ b/include/hashmap.h @@ -10,13 +10,11 @@ #define MAP_BAD_ARGS -4 #define MAP_ALREADY_USED -5 -typedef void *string_map_t; +extern void *hashmap_new(void); +extern void hashmap_free(void *map); -extern string_map_t hashmap_new(void); -extern void hashmap_free(string_map_t map); - -extern int hashmap_put(string_map_t map, char *key, char *val); -extern int hashmap_get(string_map_t map, char *key, char **ret_val); -extern int hashmap_del(string_map_t map, char *key); +extern int hashmap_put(void *map, char *key, char *val); +extern int hashmap_get(void *map, char *key, char **ret_val); +extern int hashmap_del(void *map, char *key); #endif diff --git a/include/line_handler.h b/include/line_handler.h index f193466..4dfbc3d 100644 --- a/include/line_handler.h +++ b/include/line_handler.h @@ -6,6 +6,6 @@ #include "str_dyn_arr.h" #include -extern int line_handler(char *line, string_map_t def_map, const struct str_dyn_arr *inc_dirs, FILE *source, FILE *out); +extern int line_handler(char *line, void*, const struct str_dyn_arr *inc_dirs, FILE*, FILE*); #endif diff --git a/include/pp.h b/include/pp.h index 912d6bd..6f1b6fd 100644 --- a/include/pp.h +++ b/include/pp.h @@ -5,6 +5,6 @@ #include "str_dyn_arr.h" #include -extern int pp_compute(string_map_t def_map, const struct str_dyn_arr *inc_dirs, FILE *source, FILE *out); +extern int pp_compute(void*, const struct str_dyn_arr *inc_dirs, FILE*, FILE*); #endif diff --git a/include/pp_args.h b/include/pp_args.h index 69efb4a..e93f00e 100644 --- a/include/pp_args.h +++ b/include/pp_args.h @@ -13,6 +13,6 @@ struct args { }; extern void pp_free_args(struct args *args); -extern struct args *pp_parse_args(int argc, char **argv, string_map_t define_map); +extern struct args *pp_parse_args(int argc, char **argv, void *def_map); #endif diff --git a/include/pp_define.h b/include/pp_define.h index db43299..5f916cb 100644 --- a/include/pp_define.h +++ b/include/pp_define.h @@ -6,8 +6,8 @@ #include "hashmap.h" #include -extern int collect_def(char *line, string_map_t def_map, FILE *source); -extern int apply_undef(char *line, string_map_t def_map); +extern int collect_def(char *line, void *def_map, FILE*); +extern int apply_undef(char *line, void *def_map); #endif diff --git a/include/pp_if.h b/include/pp_if.h index 2bebd32..3d680b1 100644 --- a/include/pp_if.h +++ b/include/pp_if.h @@ -6,6 +6,6 @@ #include "str_dyn_arr.h" #include -extern int expand_if(string_map_t def_map, const struct str_dyn_arr *inc_dirs, FILE *source, FILE *out); +extern int expand_if(void*, const struct str_dyn_arr *inc_dirs, FILE*, FILE*); #endif diff --git a/include/pp_ifdef.h b/include/pp_ifdef.h index 2efbff7..3617fb8 100644 --- a/include/pp_ifdef.h +++ b/include/pp_ifdef.h @@ -6,6 +6,6 @@ #include "str_dyn_arr.h" #include -extern int expand_ifdef(string_map_t def_map, const struct str_dyn_arr *inc_dirs, FILE *source, FILE *out); +extern int expand_ifdef(void*, const struct str_dyn_arr *inc_dirs, FILE*, FILE*); #endif diff --git a/include/pp_inc.h b/include/pp_inc.h index acb0e67..63d44b4 100644 --- a/include/pp_inc.h +++ b/include/pp_inc.h @@ -6,6 +6,6 @@ #include "str_dyn_arr.h" #include -extern int expand_inc(string_map_t def_map, const struct str_dyn_arr *inc_dirs, FILE *source, FILE *out); +extern int expand_inc(void*, const struct str_dyn_arr *inc_dirs, FILE*, FILE*); #endif diff --git a/include/utils.h b/include/utils.h index 20e181f..9525df6 100644 --- a/include/utils.h +++ b/include/utils.h @@ -3,8 +3,8 @@ #include -extern int write_line_to_file(FILE *f, char *line); -extern char *l_strdup(char *str); +extern int write_line_to_file(FILE*, char *line); +extern char *l_strdup(char *str); extern void strip_spaces_in_def(char *def); extern int a_strcat(char **dest, char *src); diff --git a/line_handler.c b/line_handler.c index dcd9cdb..bbfdf93 100644 --- a/line_handler.c +++ b/line_handler.c @@ -6,7 +6,7 @@ #include "pp_ifdef.h" #include "pp_inc.h" -int line_handler(char *line, string_map_t def_map, const struct str_dyn_arr *inc_dirs, FILE *source, FILE *out) +int line_handler(char *line, void *def_map, const struct str_dyn_arr *inc_dirs, FILE *source, FILE *out) { int ret; int line_len; diff --git a/pp.c b/pp.c index ef14d5d..a60a98c 100644 --- a/pp.c +++ b/pp.c @@ -4,7 +4,7 @@ #include -int pp_compute(string_map_t def_map, const struct str_dyn_arr *inc_dirs, FILE *source, FILE *out) +int pp_compute(void *def_map, const struct str_dyn_arr *inc_dirs, FILE *source, FILE *out) { char line[PP_LINE_LEN + 1]; int read_lines; diff --git a/pp_args.c b/pp_args.c index b18eb5c..f484405 100644 --- a/pp_args.c +++ b/pp_args.c @@ -60,7 +60,7 @@ int _calloc_and_check(char **p, int sz) return PP_OK; } -int _add_sym_mapp_to_map(string_map_t define_map, char *sym_mapp) +int _add_sym_mapp_to_map(void *def_map, char *sym_mapp) { char *sym; char *mapp; @@ -92,7 +92,7 @@ int _add_sym_mapp_to_map(string_map_t define_map, char *sym_mapp) strncpy(sym, sym_mapp, sym_len); - res = hashmap_put(define_map, sym, mapp); + res = hashmap_put(def_map, sym, mapp); if (res != MAP_OK) return PP_FAILED; @@ -118,7 +118,7 @@ int _add_sym_mapp_to_map(string_map_t define_map, char *sym_mapp) strncpy(mapp, eq_pos, mapp_len); - ret = hashmap_put(define_map, sym, mapp); + ret = hashmap_put(def_map, sym, mapp); if (ret == MAP_OK) return PP_OK; @@ -207,7 +207,7 @@ int _add_out_file_to_args(struct args *args, char *out_file) return PP_OK; } -struct args *pp_parse_args(int argc, char **argv, string_map_t define_map) +struct args *pp_parse_args(int argc, char **argv, void *def_map) { struct args *args; @@ -234,7 +234,7 @@ struct args *pp_parse_args(int argc, char **argv, string_map_t define_map) if (_is_split_define_flag(argv[i])) { if (i + 1 < argc) { - res = _add_sym_mapp_to_map(define_map, argv[i + 1]); + res = _add_sym_mapp_to_map(def_map, argv[i + 1]); if (res == PP_FAILED) goto free_and_exit; is_flag = 1; @@ -248,7 +248,7 @@ struct args *pp_parse_args(int argc, char **argv, string_map_t define_map) if (_is_tied_define_flag(argv[i])) { sym_mapp = argv[i] + DEFINE_FLAG_SZ; - res = _add_sym_mapp_to_map(define_map, sym_mapp); + res = _add_sym_mapp_to_map(def_map, sym_mapp); if (res == PP_FAILED) goto free_and_exit; is_flag = 1; diff --git a/pp_define.c b/pp_define.c index 86edfb1..8926a87 100644 --- a/pp_define.c +++ b/pp_define.c @@ -7,11 +7,11 @@ #include -int _collect_sym_mapp(string_map_t def_map, char *def_line); +int _collect_sym_mapp(void *def_map, char *def_line); char *_get_sym(char *def_line); char *_get_mapp(char *def_line); -int collect_def(char *line, string_map_t def_map, FILE *source) +int collect_def(char *line, void *def_map, FILE *source) { char *def_multiline; char read_line[PP_LINE_LEN + 1]; @@ -67,7 +67,7 @@ free_and_exit: return ret; } -int apply_undef(char *line, string_map_t map) +int apply_undef(char *line, void *map) { char *sym; int sym_len; @@ -92,7 +92,7 @@ restore_undef_line_and_exit: return ret; } -int _collect_sym_mapp(string_map_t def_map, char *def_line) +int _collect_sym_mapp(void *def_map, char *def_line) { int ret; diff --git a/pp_if.c b/pp_if.c index bcbbadf..e6b2f09 100644 --- a/pp_if.c +++ b/pp_if.c @@ -5,7 +5,7 @@ #include "expand_line.h" #include -int expand_if(string_map_t def_map, const struct str_dyn_arr *inc_dirs, FILE *source, FILE *out) +int expand_if(void *def_map, const struct str_dyn_arr *inc_dirs, FILE *source, FILE *out) { char line[PP_LINE_LEN + 1]; char *exp_line; diff --git a/pp_ifdef.c b/pp_ifdef.c index 6936eeb..71c4793 100644 --- a/pp_ifdef.c +++ b/pp_ifdef.c @@ -6,9 +6,9 @@ #include "line_handler.h" #include -int _is_sym_defined(string_map_t define_map, char *ifdef_line); +int _is_sym_defined(void *def_map, char *ifdef_line); -int expand_ifdef(string_map_t def_map, const struct str_dyn_arr *inc_dirs, FILE *source, FILE *out) +int expand_ifdef(void *def_map, const struct str_dyn_arr *inc_dirs, FILE *source, FILE *out) { char line[PP_LINE_LEN + 1]; char *exp_line; @@ -107,7 +107,7 @@ int expand_ifdef(string_map_t def_map, const struct str_dyn_arr *inc_dirs, FILE return PP_OK; } -int _is_sym_defined(string_map_t def_map, char *ifdef_line) +int _is_sym_defined(void *def_map, char *ifdef_line) { char *sym; char *mapp; diff --git a/pp_inc.c b/pp_inc.c index 496b204..5798512 100644 --- a/pp_inc.c +++ b/pp_inc.c @@ -6,9 +6,9 @@ #include char *_get_filename_from_inc(char *inc); -int _compute_inc_file(string_map_t def_map, const struct str_dyn_arr *inc_dirs, char *inc_filename, FILE *out); +int _compute_inc_file(void *def_map, const struct str_dyn_arr *inc_dirs, char *inc_filename, FILE *out); -int expand_inc(string_map_t def_map, const struct str_dyn_arr *inc_dirs, FILE *source, FILE *out) +int expand_inc(void *def_map, const struct str_dyn_arr *inc_dirs, FILE *source, FILE *out) { char line[PP_LINE_LEN + 1]; char *fgets_ret; @@ -70,7 +70,7 @@ char *_get_filename_from_inc(char *inc) return filename; } -int _compute_inc_file(string_map_t def_map, const struct str_dyn_arr *inc_dirs, char *inc_filename, FILE *out) +int _compute_inc_file(void *def_map, const struct str_dyn_arr *inc_dirs, char *inc_filename, FILE *out) { FILE *inc_file; diff --git a/so-cpp.c b/so-cpp.c index ffdb7fb..578e4e3 100644 --- a/so-cpp.c +++ b/so-cpp.c @@ -10,20 +10,20 @@ int main(int argc, char **argv) { - string_map_t define_map; + void *def_map; struct args *args; FILE *source; FILE *out; int ret; - define_map = NULL; + def_map = NULL; args = NULL; source = NULL; out = NULL; - define_map = hashmap_new(); - args = pp_parse_args(argc, argv, define_map); + def_map = hashmap_new(); + args = pp_parse_args(argc, argv, def_map); if (!args) { if (errno) @@ -53,7 +53,7 @@ int main(int argc, char **argv) out = stdout; } - ret = pp_compute(define_map, args->inc_dirs, source, out); + ret = pp_compute(def_map, args->inc_dirs, source, out); if (ret == PP_FAILED && errno == ENOMEM) { ret = ENOMEM; @@ -72,7 +72,7 @@ int main(int argc, char **argv) ret = errno; free_and_exit: - hashmap_free(define_map); + hashmap_free(def_map); pp_free_args(args); if (source) fclose(source);