Example #1
0
void CmdLine::SetCmdLine(char *szCmdLine)
{
	int i;

	Reset();									// Reset any previous command lines


	// Command line parameters are separated by spaces
	// If spaces are required in a parameter, it should be surrounded by quotes
	// If quotes are required, they must be doubled up eg "" is one quote

	i			= 0;							// In string position
	int			iParam = 0;						// Out param position
	bool		bQuote = false;					// Quoting is inactive
	char		szParam[CMDLINE_MAXLEN+1];		// Store our temp parameter
	char		ch;

	// Whenever we hit a space and we are NOT in quote mode
	// - Store param
	// - Skip spaces

	// Skip leading spaces
	while ( (ch = szCmdLine[i]) == ' ' )
		i++;

	while ( ((ch = szCmdLine[i++]) != '\0')  &&  (iParam < CMDLINE_MAXLEN) )
	{
		if ( ch == ' ')
		{
			// Param separator found - are we in quote mode?
			if ( bQuote == true )
			{
				szParam[iParam++] = ch;			// Store as normal - not param separator
			}
			else
			{
				szParam[iParam] = '\0';
				StoreParam(szParam);
				iParam = 0;
				// We are starting a param, skip all spaces
				while ( (ch = szCmdLine[i]) == ' ' )
					i++;
			}
		}
		else
		{
			if ( ch == '"' )
			{
				if (szCmdLine[i] == '"')
				{
					szParam[iParam++] = '"';
					i++;
				}
				else
					bQuote = !bQuote;					// Quote found - toggle quote mode
			}
			else
				szParam[iParam++] = ch;				// Simply store character
		}

	} // End While

	// Check iParam, if there was a construct in progress, finish and store
	if ( iParam != 0 )
	{
		szParam[iParam] = '\0';
		StoreParam(szParam);
	}


} // SetCmdLine()
Example #2
0
void ParamBox::OnParamStore(wxCommandEvent& event)
{
	StoreParam();
}