diff --git a/cc.c b/cc.c index bc69a8a..4f2a491 100644 --- a/cc.c +++ b/cc.c @@ -42,8 +42,10 @@ int main(int argc, char** argv, char** envp) FUZZING = FALSE; MAX_STRING = 4096; PREPROCESSOR_MODE = FALSE; + int debug_flag = TRUE; FILE* in = stdin; FILE* tempfile; + char* destination_name = "/dev/stdout"; FILE* destination_file = stdout; init_macro_env("__M2__", "42", "__INTERNAL_M2__", 0); /* Setup __M2__ */ char* name; @@ -172,13 +174,21 @@ int main(int argc, char** argv, char** envp) } else { - char* filename = calloc(100, sizeof(char)); - strcpy(filename, "/tmp/M2-Mesoplanet-XXXXXX"); - i = mkstemp(filename); - tempfile = fdopen(i, "rw"); + name = calloc(100, sizeof(char)); + strcpy(name, "/tmp/M2-Mesoplanet-XXXXXX"); + i = mkstemp(name); + tempfile = fdopen(i, "w+"); if(NULL != tempfile) { + /* Our preprocessed crap */ output_tokens(global_token, tempfile); + fclose(tempfile); + + /* Make me a real binary */ + spawn_processes(debug_flag, name, destination_name, envp); + + /* And clean up the donkey */ + remove(name); } else { diff --git a/cc_globals.c b/cc_globals.c index 2bed24f..14dfefd 100644 --- a/cc_globals.c +++ b/cc_globals.c @@ -38,7 +38,6 @@ int MAX_STRING; int PREPROCESSOR_MODE; /* enable spawn behavior to be effective */ -char* PATH; char* M2LIBC_PATH; /* So we don't shoot ourself in the face */ diff --git a/cc_globals.h b/cc_globals.h index b714df1..b94c397 100644 --- a/cc_globals.h +++ b/cc_globals.h @@ -39,7 +39,6 @@ extern long MAX_STRING; extern int PREPROCESSOR_MODE; /* enable spawn behavior to be effective */ -extern char* PATH; extern char* M2LIBC_PATH; extern char* Architecture; extern int WORDSIZE; diff --git a/cc_spawn.c b/cc_spawn.c index 7c52a16..878bbd5 100644 --- a/cc_spawn.c +++ b/cc_spawn.c @@ -47,6 +47,8 @@ char* find_char(char* string, char a) /* Find the full path to an executable */ char* find_executable(char* name) { + char* PATH = env_lookup("PATH"); + require(NULL != PATH, "No PATH found\nAborting\n"); if(match("", name)) { return NULL; @@ -186,12 +188,13 @@ int spawn_hex2(char* input, char* output, char* architecture, char** envp, int d { /* TODO FINISH */ char** array = calloc(MAX_ARRAY, sizeof(char*)); - insert_array(array, 0, "--file"); - insert_array(array, 1, input); - insert_array(array, 2, "--output"); - insert_array(array, 3, output); - insert_array(array, 4, "--architecture"); - insert_array(array, 5, architecture); + insert_array(array, 0, "hex2"); + insert_array(array, 1, "--file"); + insert_array(array, 2, input); + insert_array(array, 3, "--output"); + insert_array(array, 4, output); + insert_array(array, 5, "--architecture"); + insert_array(array, 6, architecture); int r = _execute("hex2", array, envp); return r; } @@ -200,23 +203,24 @@ int spawn_hex2(char* input, char* output, char* architecture, char** envp, int d int spawn_M1(char* input, char* debug_file, char* output, char* architecture, char** envp, int debug_flag) { char** array = calloc(MAX_ARRAY, sizeof(char*)); - insert_array(array, 0, "--file"); - insert_array(array, 1, input); + insert_array(array, 0, "M1"); + insert_array(array, 1, "--file"); + insert_array(array, 2, input); if(debug_flag) { - insert_array(array, 2, "--file"); - insert_array(array, 3, debug_file); - insert_array(array, 4, "--output"); - insert_array(array, 5, output); - insert_array(array, 6, "--architecture"); - insert_array(array, 7, architecture); + insert_array(array, 3, "--file"); + insert_array(array, 4, debug_file); + insert_array(array, 5, "--output"); + insert_array(array, 6, output); + insert_array(array, 7, "--architecture"); + insert_array(array, 8, architecture); } else { - insert_array(array, 2, "--output"); - insert_array(array, 3, output); - insert_array(array, 4, "--architecture"); - insert_array(array, 5, architecture); + insert_array(array, 3, "--output"); + insert_array(array, 4, output); + insert_array(array, 5, "--architecture"); + insert_array(array, 6, architecture); } int r = _execute("M1", array, envp); return r; @@ -226,13 +230,14 @@ int spawn_M1(char* input, char* debug_file, char* output, char* architecture, ch int spawn_blood_elf(char* input, char* output, char* architecture, char** envp, int large_flag) { char** array = calloc(MAX_ARRAY, sizeof(char*)); - insert_array(array, 0, "--file"); - insert_array(array, 1, input); - insert_array(array, 2, "--output"); - insert_array(array, 3, output); - insert_array(array, 4, "--architecture"); - insert_array(array, 5, architecture); - if(large_flag) insert_array(array, 6, "--64"); + insert_array(array, 0, "blood-elf"); + insert_array(array, 1, "--file"); + insert_array(array, 2, input); + insert_array(array, 3, "--output"); + insert_array(array, 4, output); + insert_array(array, 5, "--architecture"); + insert_array(array, 6, architecture); + if(large_flag) insert_array(array, 7, "--64"); int r = _execute("blood-elf", array, envp); return r; } @@ -240,13 +245,14 @@ int spawn_blood_elf(char* input, char* output, char* architecture, char** envp, int spawn_M2(char* input, char* output, char* architecture, char** envp, int debug_flag) { char** array = calloc(MAX_ARRAY, sizeof(char*)); - insert_array(array, 0, "--file"); - insert_array(array, 1, input); - insert_array(array, 2, "--output"); - insert_array(array, 3, output); - insert_array(array, 4, "--architecture"); - insert_array(array, 5, architecture); - if(debug_flag) insert_array(array, 6, "--debug"); + insert_array(array, 0, "M2-Planet"); + insert_array(array, 1, "--file"); + insert_array(array, 2, input); + insert_array(array, 3, "--output"); + insert_array(array, 4, output); + insert_array(array, 5, "--architecture"); + insert_array(array, 6, architecture); + if(debug_flag) insert_array(array, 7, "--debug"); int r = _execute("M2-Planet", array, envp); return r; } diff --git a/makefile b/makefile index bd4088b..9a17780 100644 --- a/makefile +++ b/makefile @@ -25,13 +25,14 @@ CFLAGS:=$(CFLAGS) -D_GNU_SOURCE -O0 -std=c99 -ggdb all: M2-Mesoplanet -M2-Mesoplanet: bin results cc.h cc_reader.c cc_core.c cc.c cc_globals.c cc_globals.h +M2-Mesoplanet: bin results cc.h cc_reader.c cc_core.c cc_macro.c cc_env.c cc_spawn.c cc.c cc_globals.c cc_globals.h $(CC) $(CFLAGS) \ M2libc/bootstrappable.c \ cc_reader.c \ cc_core.c \ cc_macro.c \ cc_env.c \ + cc_spawn.c \ cc.c \ cc.h \ cc_globals.c \