From 09d43f0538c87501dcb55889772e024deb4869a4 Mon Sep 17 00:00:00 2001 From: Jeremiah Orians Date: Sat, 9 Apr 2022 18:09:27 -0400 Subject: [PATCH] enable disabling of reading #includes --- cc.c | 13 +++++++++---- cc_reader.c | 10 +++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cc.c b/cc.c index f3178cb..b9e9d3a 100644 --- a/cc.c +++ b/cc.c @@ -25,7 +25,7 @@ void populate_env(char** envp); void setup_env(); char* env_lookup(char* variable); void initialize_types(); -struct token_list* read_all_tokens(FILE* a, struct token_list* current, char* filename); +struct token_list* read_all_tokens(FILE* a, struct token_list* current, char* filename, int include); struct token_list* reverse_list(struct token_list* head); void init_macro_env(char* sym, char* value, char* source, int num); @@ -122,6 +122,7 @@ int main(int argc, char** argv, char** envp) FILE* destination_file = stdout; char* name; int DUMP_MODE = FALSE; + int follow_includes = TRUE; /* Try to get our needed updates */ prechecks(argc, argv); @@ -172,7 +173,11 @@ int main(int argc, char** argv, char** envp) DIRTY_MODE = TRUE; i+= 1; } - else if(match(argv[i], "--debug-mode")) + else if(match(argv[i], "--no-includes")) + { + follow_includes = FALSE; + i+= 1; + }else if(match(argv[i], "--debug-mode")) { /* Handled by precheck */ i+= 2; @@ -205,7 +210,7 @@ int main(int argc, char** argv, char** envp) fputs("\n Aborting to avoid problems\n", stderr); exit(EXIT_FAILURE); } - global_token = read_all_tokens(in, global_token, name); + global_token = read_all_tokens(in, global_token, name, follow_includes); fclose(in); i += 2; } @@ -286,7 +291,7 @@ int main(int argc, char** argv, char** envp) { hold_string = calloc(MAX_STRING, sizeof(char)); require(NULL != hold_string, "Impossible Exhaustion has occured\n"); - global_token = read_all_tokens(in, global_token, "STDIN"); + global_token = read_all_tokens(in, global_token, "STDIN", follow_includes); } if(NULL == global_token) diff --git a/cc_reader.c b/cc_reader.c index 3b6fe07..6b787d5 100644 --- a/cc_reader.c +++ b/cc_reader.c @@ -327,8 +327,8 @@ void insert_file_header(char* name, int line) new_token("\n", 3); } -struct token_list* read_all_tokens(FILE* a, struct token_list* current, char* filename); -int include_file(int ch) +struct token_list* read_all_tokens(FILE* a, struct token_list* current, char* filename, int include); +int include_file(int ch, int include_file) { /* The old state to restore to */ char* hold_filename = file; @@ -402,7 +402,7 @@ int include_file(int ch) hold_number = line + 1; /* Read the new file */ - read_all_tokens(new_file, token, new_filename); + if(include_file) read_all_tokens(new_file, token, new_filename, include_file); /* put back old file info */ insert_file_header(hold_filename, hold_number); @@ -414,7 +414,7 @@ int include_file(int ch) return ch; } -struct token_list* read_all_tokens(FILE* a, struct token_list* current, char* filename) +struct token_list* read_all_tokens(FILE* a, struct token_list* current, char* filename, int include) { token = current; insert_file_header(filename, 1); @@ -426,7 +426,7 @@ struct token_list* read_all_tokens(FILE* a, struct token_list* current, char* fi { ch = get_token(ch); new_token(hold_string, string_index + 2); - if(match("#include", token->s)) ch = include_file(ch); + if(match("#include", token->s)) ch = include_file(ch, include); } return token;