From ab9a856bc1d7ea0bc34023cf947c26636fb0c489 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sun, 31 Dec 2023 11:45:06 +0000 Subject: [PATCH] Debugger: allow pathnames > CONSOLE_WIDTH(=80) for scripts run via CmdOutputrun() . specifically for the DebuggerAutoRun.txt script (which runs at AppleWin start-up) . internally changed MAX_ARG_LEN from 127 to MAX_PATH(260), which is used to size Arg_t::sArg[] --- source/Debugger/Debug.cpp | 38 ++++++++++++++++++++------------ source/Debugger/Debugger_Types.h | 6 ++--- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/source/Debugger/Debug.cpp b/source/Debugger/Debug.cpp index 7df7736c..1c80a1f4 100644 --- a/source/Debugger/Debug.cpp +++ b/source/Debugger/Debug.cpp @@ -6391,24 +6391,17 @@ Update_t CmdOutputRun (int nArgs) MemoryTextFile_t script; const std::string pFileName = g_aArgs[ 1 ].sArg; - std::string sFileName; - std::string sMiniFileName; // [CONSOLE_WIDTH]; - -// if (g_aArgs[1].bType & TYPE_QUOTED_2) - - sMiniFileName = pFileName.substr(0, MIN(pFileName.size(), CONSOLE_WIDTH)); -// strcat( sMiniFileName, ".aws" ); // HACK: MAGIC STRING if (pFileName[0] == PATH_SEPARATOR || pFileName[1] == ':') // NB. Any prefix quote has already been stripped { // Abs pathname - sFileName = sMiniFileName; + sFileName = pFileName; } else { // Rel pathname - sFileName = g_sCurrentDir + sMiniFileName; + sFileName = g_sCurrentDir + pFileName; } if (script.Read( sFileName )) @@ -6428,8 +6421,9 @@ Update_t CmdOutputRun (int nArgs) } else { + std::string sMiniFileName = sFileName.substr(0, MIN(sFileName.size(), CONSOLE_WIDTH)); ConsolePrintFormat("%sCouldn't load filename:", CHC_ERROR); - ConsolePrintFormat("%s%s", CHC_STRING, sFileName.c_str()); + ConsolePrintFormat("%s%s", CHC_STRING, sMiniFileName.c_str()); } return ConsoleUpdate(); @@ -9017,14 +9011,30 @@ void DebugInitialize () // Look in g_sCurrentDir, otherwise try g_sProgramDir std::string pathname = g_sCurrentDir + debuggerAutoRunName; - strncpy_s(g_aArgs[1].sArg, MAX_ARG_LEN, pathname.c_str(), _TRUNCATE); - CmdOutputRun(1); + if (pathname.size() >= MAX_PATH) + { + ConsolePrintFormat("%sPathname too long:", CHC_ERROR); + ConsolePrintFormat("%s%s", CHC_STRING, pathname.c_str()); + } + else + { + strncpy_s(g_aArgs[1].sArg, MAX_PATH, pathname.c_str(), _TRUNCATE); + CmdOutputRun(1); + } if (!g_bScriptReadOk) { pathname = g_sProgramDir + debuggerAutoRunName; - strncpy_s(g_aArgs[1].sArg, MAX_ARG_LEN, pathname.c_str(), _TRUNCATE); - CmdOutputRun(1); + if (pathname.size() >= MAX_PATH) + { + ConsolePrintFormat("%sPathname too long:", CHC_ERROR); + ConsolePrintFormat("%s%s", CHC_STRING, pathname.c_str()); + } + else + { + strncpy_s(g_aArgs[1].sArg, MAX_PATH, pathname.c_str(), _TRUNCATE); + CmdOutputRun(1); + } } } diff --git a/source/Debugger/Debugger_Types.h b/source/Debugger/Debugger_Types.h index 1813411a..71578936 100644 --- a/source/Debugger/Debugger_Types.h +++ b/source/Debugger/Debugger_Types.h @@ -266,9 +266,9 @@ { MAX_COMMAND_LEN = 12, - MAX_ARGS = 32, // was 40 + MAX_ARGS = 32, ARG_SYNTAX_ERROR= -1, - MAX_ARG_LEN = 127, // extended to allow font names, GH#481, any value is good > CONSOLE_WIDTH=80 + MAX_ARG_LEN = MAX_PATH, // extended to allow font names, GH#481, any value is good > CONSOLE_WIDTH(=80) }; // NOTE: All Commands return flags of what needs to be redrawn @@ -1023,7 +1023,7 @@ const DisasmData_t* pDisasmData; // If != NULL then bytes are marked up as data enum { - MAX_FONT_NAME = MAX_ARG_LEN // was 64 + MAX_FONT_NAME = MAX_ARG_LEN }; enum FontSpacing_e