From: Robert Pengelly Date: Mon, 19 Oct 2026 03:19:18 +0000 (+0100) Subject: Fix COMSPEC path handling when launching DOS programs from another directory X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=228e49a317b29595808c8413a6029b3553767da8;p=dosemu.git Fix COMSPEC path handling when launching DOS programs from another directory --- diff --git a/interrupts.c b/interrupts.c index 4479304..86db1ae 100644 --- a/interrupts.c +++ b/interrupts.c @@ -1442,6 +1442,29 @@ static void dos_normalize_path (char *path) { static char dos_drive_root[260] = "."; +static char dos_initial_host_path[520]; +static char dos_initial_guest_path[260]; + +const char *dos_register_initial_program (const char *path) { + + const char *base = path; + const char *p; + + for (p = path; *p; p++) { + + if (*p == '/' || *p == '\\') { + base = p + 1; + } + + } + + snprintf (dos_initial_host_path, sizeof (dos_initial_host_path), "%s", path); + snprintf (dos_initial_guest_path, sizeof (dos_initial_guest_path), "C:\\%s", base); + + return dos_initial_guest_path; + +} + static int dos_is_drive_root_path (const char *path) { size_t len = strlen (path); @@ -1519,6 +1542,13 @@ static void dos_resolve_path (const char *in, char *out, size_t out_sz) { return; } + if (in && dos_initial_guest_path[0] && strcasecmp (in, dos_initial_guest_path) == 0) { + + snprintf (out, out_sz, "%s", dos_initial_host_path); + return; + + } + tmp[0] = '\0'; dos_append_bounded (tmp, sizeof (tmp), in ? in : ""); diff --git a/interrupts.h b/interrupts.h index 082e29b..03fca64 100644 --- a/interrupts.h +++ b/interrupts.h @@ -12,4 +12,6 @@ void init_ivt (CPU8086 *cpu); void handle_interrupt (CPU8086 *cpu, uint8_t interrupt_number); void native_interrupt (CPU8086 *cpu, uint8_t interrupt_number); +const char *dos_register_initial_program (const char *path); + #endif /* _INTERRUPTS_H */ diff --git a/main.c b/main.c index 57b6ce8..b806350 100644 --- a/main.c +++ b/main.c @@ -115,6 +115,8 @@ int main (int argc, char **argv) { CPU8086 cpu; const char *path = NULL; + const char *dos_path; + char cmd_tail[128] = {0}; int trace = 0, rc; @@ -169,11 +171,12 @@ int main (int argc, char **argv) { } cpu_reset (&cpu, mem, MEM_SIZE); + dos_path = dos_register_initial_program (path); if (load_mz_file (path, &cpu, EXE_LOAD_SEG << 4, (uint16_t) ((MEM_SIZE - ((uint32_t) (EXE_LOAD_SEG << 4) << 4)) / 16))) { - init_psp (path, &cpu, cmd_tail, EXE_LOAD_SEG); + init_psp (dos_path, &cpu, cmd_tail, EXE_LOAD_SEG); } else if (load_com_file (path, &cpu, mem, MEM_SIZE, EXE_LOAD_SEG, &loaded)) { - init_psp (path, &cpu, cmd_tail, EXE_LOAD_SEG); + init_psp (dos_path, &cpu, cmd_tail, EXE_LOAD_SEG); } else { fprintf (stderr, "Failed to load %s\n", path);