From 912b0d9e93876364e92909efc843dca0e9cb11a5 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Tue, 7 May 2013 00:47:37 +0200 Subject: [PATCH] Have cl65 run the binaries from its own directory. While ca65, cc65 and ld65 have built-in paths cl65 doesn't. That means that up to now cl65 depended on the binaries being found in the path env var. However it makes sense to presume that the binaries are located in the very same directory cl65 is located in. So whatever pathname was suitable to run cl65 should be suitable to run the other binaries too. But if for some reason there's no valid argv[0] or if it doesn't contain at least one directory delimiter ('/' or '\') then fall back to relying on the path env var. --- src/cl65/main.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/cl65/main.c b/src/cl65/main.c index 4cabbeb5e..59c35d80a 100644 --- a/src/cl65/main.c +++ b/src/cl65/main.c @@ -283,14 +283,22 @@ static void CmdAddFile (CmdDesc* Cmd, const char* File) -static void CmdInit (CmdDesc* Cmd, const char* Path) -/* Initialize the command using the given path to the executable */ +static void CmdInit (CmdDesc* Cmd, const char* Path, const char* Name) +/* Initialize the command using the given path and name of the executable */ { + char* FullName; + + FullName = (char*) xmalloc (strlen (Path) + strlen (Name) + 1); + strcpy (FullName, Path); + strcat (FullName, Name); + /* Remember the command */ - Cmd->Name = xstrdup (Path); + Cmd->Name = xstrdup (FullName); /* Use the command name as first argument */ - CmdAddArg (Cmd, Path); + CmdAddArg (Cmd, FullName); + + xfree (FullName); } @@ -1283,17 +1291,34 @@ int main (int argc, char* argv []) { "--zeropage-name", 1, OptZeropageName }, }; + char* CmdPath; unsigned I; /* Initialize the cmdline module */ InitCmdLine (&argc, &argv, "cl65"); /* Initialize the command descriptors */ - CmdInit (&CC65, "cc65"); - CmdInit (&CA65, "ca65"); - CmdInit (&CO65, "co65"); - CmdInit (&LD65, "ld65"); - CmdInit (&GRC, "grc65"); + if (argc == 0) { + CmdPath = xstrdup (""); + } else { + char* Ptr; + CmdPath = xstrdup (argv[0]); + Ptr = strrchr (CmdPath, '/'); + if (Ptr == 0) { + Ptr = strrchr (CmdPath, '\\'); + } + if (Ptr == 0) { + *CmdPath = '\0'; + } else { + *(Ptr + 1) = '\0'; + } + } + CmdInit (&CC65, CmdPath, "cc65"); + CmdInit (&CA65, CmdPath, "ca65"); + CmdInit (&CO65, CmdPath, "co65"); + CmdInit (&LD65, CmdPath, "ld65"); + CmdInit (&GRC, CmdPath, "grc65"); + xfree (CmdPath); /* Our default target is the C64 instead of "none" */ Target = TGT_C64; -- 2.39.5