Solved coding style
This commit is contained in:
parent
da30ee17ab
commit
a7809eb683
|
@ -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;
|
||||
|
|
10
hashmap.c
10
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;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "hashmap.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
#include "str_dyn_arr.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
#include "str_dyn_arr.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
#include "hashmap.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
#include "str_dyn_arr.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
#include "str_dyn_arr.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
#include "str_dyn_arr.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
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);
|
||||
|
|
|
@ -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;
|
||||
|
|
2
pp.c
2
pp.c
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
|
|
12
pp_args.c
12
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;
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
#include <string.h>
|
||||
|
||||
|
||||
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;
|
||||
|
||||
|
|
2
pp_if.c
2
pp_if.c
|
@ -5,7 +5,7 @@
|
|||
#include "expand_line.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
#include "line_handler.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
|
|
6
pp_inc.c
6
pp_inc.c
|
@ -6,9 +6,9 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
|
||||
|
|
12
so-cpp.c
12
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);
|
||||
|
|
Loading…
Reference in New Issue