From c1380abe3b136685db16af7a409f6287a0eff05e Mon Sep 17 00:00:00 2001 From: Tyrann Date: Mon, 9 Oct 2006 22:52:02 +0930 Subject: [PATCH] [PATCH] qbsp: Allow arbitrary length command lines The options are currently parsed as a big text array, so that the parsing function can be shared with the code to load options from a file. Anyway, dynamically allocate the array to copy in the command line arguments rather than restricting it to 512 bytes. Signed-off-by: Tyrann --- qbsp/qbsp.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/qbsp/qbsp.c b/qbsp/qbsp.c index 0ac09982..9e5a54b2 100644 --- a/qbsp/qbsp.c +++ b/qbsp/qbsp.c @@ -453,7 +453,6 @@ static void InitQBSP(int argc, char **argv) { int i; - char szArgs[512]; char *szBuf; int length; @@ -477,20 +476,28 @@ InitQBSP(int argc, char **argv) FreeMem(szBuf, OTHER, length + 1); } - // Concatenate command line args - szArgs[0] = 0; - for (i = 1; i < argc; i++) { - // Toss " around filenames to preserve LFNs in the Parsing function - if (argv[i][0] != '-') - strcat(szArgs, "\""); - strcat(szArgs, argv[i]); - if (argv[i][0] != '-') - strcat(szArgs, "\" "); - else - strcat(szArgs, " "); - } - ParseOptions(szArgs); + // Concatenate command line args + length = 0; + for (i = 1; i < argc; i++) { + length += strlen(argv[i]) + 1; + if (argv[i][0] != '-') + length += 2; /* quotes */ + } + szBuf = AllocMem(OTHER, length, true); + for (i = 1; i < argc; i++) { + /* Quote filenames for the parsing function */ + if (argv[i][0] != '-') + strcat(szBuf, "\""); + strcat(szBuf, argv[i]); + if (argv[i][0] != '-') + strcat(szBuf, "\" "); + else + strcat(szBuf, " "); + } + szBuf[length - 1] = 0; + ParseOptions(szBuf); + FreeMem(szBuf, OTHER, length); if (options.szMapName[0] == 0) PrintOptions();