make cc_reader.c respect M2LIBC_PATH

This commit is contained in:
Jeremiah Orians 2022-01-23 21:22:54 -05:00
parent f16fcccb44
commit 11c45ed475
No known key found for this signature in database
GPG Key ID: 6B3A3F198708F894
2 changed files with 44 additions and 21 deletions

51
cc.c
View File

@ -35,24 +35,47 @@ void spawn_processes(int debug_flag, char* preprocessed_file, char* destination,
int main(int argc, char** argv, char** envp)
{
/****************************************************************************
* Manually change debug level if you need testing of functionality prior *
* to --debug-mode functionality. *
* Zero means no debugging messages and larger positive values means more *
* chatty output. Level 15 means EVERYTHING but 7 should cover most magic *
****************************************************************************/
DEBUG_LEVEL = 0;
/* Setup __M2__ (It is very very special *DO NOT MESS WITH IT* ) */
init_macro_env("__M2__", "__M2__", "__INTERNAL_M2__", 0);
/* Our fun globals */
FUZZING = FALSE;
MAX_STRING = 65536;
PREPROCESSOR_MODE = FALSE;
STDIO_USED = FALSE;
DIRTY_MODE = FALSE;
/* Our fun locals */
int debug_flag = TRUE;
FILE* in = stdin;
FILE* tempfile;
char* destination_name = "a.out";
FILE* destination_file = stdout;
init_macro_env("__M2__", "__M2__", "__INTERNAL_M2__", 0); /* Setup __M2__ */
char* name;
char* hold;
int DUMP_MODE = FALSE;
DIRTY_MODE = FALSE;
int SPECIFIED_LIBRARY = FALSE;
/* Assume no debugging by default */
DEBUG_LEVEL = 0;
/* Get the environmental bits */
if(1 <= DEBUG_LEVEL) fputs("Starting to setup Environment\n", stderr);
populate_env(envp);
setup_env();
if(1 <= DEBUG_LEVEL) fputs("Environment setup\n", stderr);
M2LIBC_PATH = env_lookup("M2LIBC_PATH");
if(NULL == M2LIBC_PATH) M2LIBC_PATH = "./M2libc";
else if(1 <= DEBUG_LEVEL)
{
fputs("M2LIBC_PATH set by environment variable to ", stderr);
fputs(M2LIBC_PATH, stderr);
fputc('\n', stderr);
}
int i = 1;
while(i <= argc)
@ -145,7 +168,12 @@ int main(int argc, char** argv, char** envp)
fputs("-I requires a PATH\n", stderr);
exit(EXIT_FAILURE);
}
SPECIFIED_LIBRARY = TRUE;
if(1 <= DEBUG_LEVEL)
{
fputs("M2LIBC_PATH set by -I to ", stderr);
fputs(M2LIBC_PATH, stderr);
fputc('\n', stderr);
}
M2LIBC_PATH = hold;
i += 2;
}
@ -198,17 +226,6 @@ int main(int argc, char** argv, char** envp)
global_token = reverse_list(global_token);
if(1 <= DEBUG_LEVEL) fputs("List reversed\n", stderr);
/* Get the environmental bits */
if(1 <= DEBUG_LEVEL) fputs("Starting to setup Environment\n", stderr);
populate_env(envp);
setup_env();
if(!SPECIFIED_LIBRARY)
{
M2LIBC_PATH = env_lookup("M2LIBC_PATH");
if(NULL == M2LIBC_PATH) M2LIBC_PATH = "./M2libc";
}
if(1 <= DEBUG_LEVEL) fputs("Environment setup\n", stderr);
if(DUMP_MODE)
{
output_tokens(global_token, destination_file);

View File

@ -344,11 +344,9 @@ int include_file(int ch)
/* Try to open the file */
if('<' == new_filename[0])
{
char* path = env_lookup("M2LIBC_PATH");
if(NULL == path) path = "./M2libc";
if(match("stdio.h", new_filename + 1)) STDIO_USED = TRUE;
reset_hold_string();
strcat(hold_string, path);
strcat(hold_string, M2LIBC_PATH);
strcat(hold_string, "/");
strcat(hold_string, new_filename + 1);
strcat(new_filename, ">");
@ -356,7 +354,15 @@ int include_file(int ch)
}
else
{
new_file = fopen(new_filename+1, "r");
if(match("M2libc/bootstrappable.h", new_filename+1))
{
reset_hold_string();
strcat(hold_string, M2LIBC_PATH);
strcat(hold_string, "/bootstrappable.h");
new_file = fopen(hold_string, "r");
}
else new_file = fopen(new_filename+1, "r");
strcat(new_filename, "\"");
}