enable disabling of reading #includes

This commit is contained in:
Jeremiah Orians 2022-04-09 18:09:27 -04:00
parent 9895dab8dd
commit 09d43f0538
No known key found for this signature in database
GPG Key ID: 6B3A3F198708F894
2 changed files with 14 additions and 9 deletions

13
cc.c
View File

@ -25,7 +25,7 @@ void populate_env(char** envp);
void setup_env(); void setup_env();
char* env_lookup(char* variable); char* env_lookup(char* variable);
void initialize_types(); 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); struct token_list* reverse_list(struct token_list* head);
void init_macro_env(char* sym, char* value, char* source, int num); 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; FILE* destination_file = stdout;
char* name; char* name;
int DUMP_MODE = FALSE; int DUMP_MODE = FALSE;
int follow_includes = TRUE;
/* Try to get our needed updates */ /* Try to get our needed updates */
prechecks(argc, argv); prechecks(argc, argv);
@ -172,7 +173,11 @@ int main(int argc, char** argv, char** envp)
DIRTY_MODE = TRUE; DIRTY_MODE = TRUE;
i+= 1; 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 */ /* Handled by precheck */
i+= 2; i+= 2;
@ -205,7 +210,7 @@ int main(int argc, char** argv, char** envp)
fputs("\n Aborting to avoid problems\n", stderr); fputs("\n Aborting to avoid problems\n", stderr);
exit(EXIT_FAILURE); 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); fclose(in);
i += 2; i += 2;
} }
@ -286,7 +291,7 @@ int main(int argc, char** argv, char** envp)
{ {
hold_string = calloc(MAX_STRING, sizeof(char)); hold_string = calloc(MAX_STRING, sizeof(char));
require(NULL != hold_string, "Impossible Exhaustion has occured\n"); 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) if(NULL == global_token)

View File

@ -327,8 +327,8 @@ void insert_file_header(char* name, int line)
new_token("\n", 3); new_token("\n", 3);
} }
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);
int include_file(int ch) int include_file(int ch, int include_file)
{ {
/* The old state to restore to */ /* The old state to restore to */
char* hold_filename = file; char* hold_filename = file;
@ -402,7 +402,7 @@ int include_file(int ch)
hold_number = line + 1; hold_number = line + 1;
/* Read the new file */ /* 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 */ /* put back old file info */
insert_file_header(hold_filename, hold_number); insert_file_header(hold_filename, hold_number);
@ -414,7 +414,7 @@ int include_file(int ch)
return 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; token = current;
insert_file_header(filename, 1); 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); ch = get_token(ch);
new_token(hold_string, string_index + 2); 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; return token;