comparison terminal.c @ 2425:794ba17f0716

Make termhelper work when current working directory is not the one that contains blastem
author Michael Pavone <pavone@retrodev.com>
date Wed, 24 Jan 2024 20:18:17 -0800
parents 0433fdd9ba66
children
comparison
equal deleted inserted replaced
2424:767ec72acca7 2425:794ba17f0716
24 init_done = 1; 24 init_done = 1;
25 } 25 }
26 26
27 void init_terminal() 27 void init_terminal()
28 { 28 {
29 #ifndef IS_LIB
29 if (!init_done) { 30 if (!init_done) {
30 if (!(isatty(STDIN_FILENO) && isatty(STDOUT_FILENO))) { 31 if (!(isatty(STDIN_FILENO) && isatty(STDOUT_FILENO))) {
31 #ifndef __APPLE__ 32 #ifndef __APPLE__
32 //check to see if x-terminal-emulator exists, just use xterm if it doesn't 33 //check to see if x-terminal-emulator exists, just use xterm if it doesn't
33 char *term = system("which x-terminal-emulator > /dev/null") ? "xterm" : "x-terminal-emulator"; 34 char *term = system("which x-terminal-emulator > /dev/null") ? "xterm" : "x-terminal-emulator";
48 if (child == -1) { 49 if (child == -1) {
49 //error, oh well 50 //error, oh well
50 warning("Failed to fork for terminal spawn"); 51 warning("Failed to fork for terminal spawn");
51 } else if (!child) { 52 } else if (!child) {
52 //child process, exec our terminal emulator 53 //child process, exec our terminal emulator
54 char *termhelper = bundled_file_path("termhelper");
53 #ifdef __APPLE__ 55 #ifdef __APPLE__
54 execlp("open", "open", "./termhelper", NULL); 56 execlp("open", "open", termhelper, NULL);
55 #else 57 #else
56 execlp(term, term, "-title", "BlastEm Debugger", "-e", "./termhelper", NULL); 58 execlp(term, term, "-title", "BlastEm Debugger", "-e", termhelper, NULL);
57 #endif 59 #endif
60 free(termhelper);
58 } else { 61 } else {
59 //connect to the FIFOs, these will block so order is important 62 //connect to the FIFOs, these will block so order is important
60 open(INPUT_PATH, O_RDONLY); 63 open(INPUT_PATH, O_RDONLY);
61 open(OUTPUT_PATH, O_WRONLY); 64 open(OUTPUT_PATH, O_WRONLY);
62 atexit(cleanup_terminal); 65 atexit(cleanup_terminal);
66 } 69 }
67 } 70 }
68 71
69 init_done = 1; 72 init_done = 1;
70 } 73 }
74 #endif
71 } 75 }