void CCommandLine::CreateCmdLine(const char *commandline) { if (m_pszCmdLine) delete [] m_pszCmdLine; char szFull[4096]; int len = strlen(commandline) + 1; char *pOrig = new char [len]; memcpy(pOrig, commandline, len); char *pSrc, *pDst; pDst = szFull; pSrc = pOrig; bool bContinue = true; while (*pSrc) { if (bContinue && *pSrc == '@') { LoadParametersFromFile(pSrc, pDst); continue; } bContinue = (isspace(*pSrc) != false); *pDst++ = *pSrc++; } *pDst = '\0'; len = strlen(szFull) + 1; m_pszCmdLine = new char [len]; memcpy(m_pszCmdLine, szFull, len); }
//----------------------------------------------------------------------------- // Purpose: Create a command line from the passed in string // Note that if you pass in a @filename, then the routine will read settings // from a file instead of the command line //----------------------------------------------------------------------------- void CCommandLine::CreateCmdLine( const char *commandline ) { if ( m_pszCmdLine ) { delete[] m_pszCmdLine; } char szFull[ 4096 ]; char *pDst = szFull; const char *pSrc = commandline; bool bInQuotes = false; const char *pInQuotesStart = 0; while ( *pSrc ) { // Is this an unslashed quote? if ( *pSrc == '"' ) { if ( pSrc == commandline || ( pSrc[-1] != '/' && pSrc[-1] != '\\' ) ) { bInQuotes = !bInQuotes; pInQuotesStart = pSrc + 1; } } if ( *pSrc == '@' ) { if ( pSrc == commandline || (!bInQuotes && isspace( pSrc[-1] )) || (bInQuotes && pSrc == pInQuotesStart) ) { LoadParametersFromFile( pSrc, pDst, sizeof( szFull ) - (pDst - szFull), bInQuotes ); continue; } } // Don't go past the end. if ( (pDst - szFull) >= (sizeof( szFull ) - 1) ) break; *pDst++ = *pSrc++; } *pDst = '\0'; int len = strlen( szFull ) + 1; m_pszCmdLine = new char[len]; memcpy( m_pszCmdLine, szFull, len ); ParseCommandLine(); }