Example #1
0
void AppArgs::Parse(int argc, const char* const* argv)
{
  for (int i=1; i<argc; i++) {
    // this shouldn't occur
    if (argv[i] == NULL)
      return;
      
    if (IsOption(argv[i])) {
      if (IsLongOption(argv[i])) {
        std::string name, val;
        bool hasVal;
        if (ParseLong(argv[i], name, val, hasVal)) {
          AA_LONG_MAP::iterator it = s_longMap.find(name);
          if (it != s_longMap.end()) {
            AppArgOption_t* pOpt = (*it).second;
            pOpt->found = true;
            pOpt->hasVal = hasVal;
            pOpt->val = val;
          }
        }
      }
      else {
        char name;
        std::string val;
        bool hasVal;
        ParseShort(argv[i], name, val, hasVal);
        AA_SHORT_MAP::iterator it = s_shortMap.find(name);
        if (it != s_shortMap.end()) {
          AppArgOption_t* pOpt = (*it).second;
          pOpt->found = true;
          if (hasVal) {
            pOpt->hasVal = true;
            pOpt->val = val;
          }
          else {
            if (i+1 < argc && !IsOption(argv[i+1])) {
              pOpt->hasVal = true;
              pOpt->val = argv[i+1];
              i++;
            }
            else {
              pOpt->hasVal = false;
            }
          }
        }
      }
    }
    else {
      s_valList.push_back(argv[i]);
    }
  }
}
Example #2
0
void CProfileOptions::SetOptionValue(const char* command, const char* param, bool toPendingOptions)
{
	if (!command || !command[0])
		return;

	if (!param)
		return;
		
  if(!IsOption(command))
  {
    AddOption(command, param);
  }

  if (toPendingOptions)
  {
    AddOrReplacePendingOption(command, param);
    return;
  }

	ScopedSwitchToGlobalHeap globalHeap;

  std::vector<COption*>::const_iterator it = m_allOptions.begin();
  std::vector<COption*>::const_iterator end = m_allOptions.end();
  for(; it!=end; ++it)
  {
    if((*it)->GetName().compare(command)==0)
    {
      (*it)->Set(param);
    }
  }
}
Example #3
0
  bool XMLConversion::SetupWriter()
  {
    //Set up XML writer if one does not already exist
    if(_writer)
      return true;

    _buf = xmlOutputBufferCreateIO  (
                                     WriteStream, //xmlOutputWriteCallback
                                     NULL,         //xmlOutputCloseCallback
                                     this,        //context
                                     NULL);        //xmlCharEncodingHandlerPtr
    _writer = xmlNewTextWriter(_buf);

    if(!_buf || !_writer)
      {
        cerr << "Error setting up xml writer\n" << endl;
        return false;
      }

    int ret;
    if(IsOption("c"))
      ret = xmlTextWriterSetIndent(_writer,0);
    else
      {
        ret = xmlTextWriterSetIndent(_writer,1);
        ret = xmlTextWriterSetIndentString(_writer, BAD_CAST " ");
      }
    return ret==0;
  }
Example #4
0
bool CArgsParser::GetOption(LPCWSTR pszOption,FILETIME *pValue)
{
	if (IsOption(pszOption)) {
		if (Next())
			return GetValue(pValue);
	}
	return false;
}
Example #5
0
bool CArgsParser::GetDurationOption(LPCWSTR pszOption,int *pValue)
{
	if (IsOption(pszOption)) {
		if (Next())
			return GetDurationValue(pValue);
	}
	return false;
}
Example #6
0
bool CArgsParser::GetOption(LPCWSTR pszOption,CDynamicString *pValue)
{
	if (IsOption(pszOption)) {
		if (Next())
			return pValue->Set(GetText());
	}
	return false;
}
Example #7
0
bool CArgsParser::GetOption(LPCWSTR pszOption,bool *pValue)
{
	if (IsOption(pszOption)) {
		*pValue=true;
		return true;
	}
	return false;
}
Example #8
0
bool CArgsParser::GetOption(LPCWSTR pszOption,LPTSTR pszValue,int MaxLength)
{
	if (IsOption(pszOption)) {
		if (Next())
			return GetText(pszValue,MaxLength);
	}
	return false;
}
Example #9
0
bool CArgsParser::GetOption(LPCWSTR pszOption,TVTest::String *pValue)
{
	if (IsOption(pszOption)) {
		if (Next()) {
			TVTest::StringUtility::Assign(*pValue,GetText());
			return true;
		}
	}
	return false;
}
Example #10
0
string CProfileOptions::GetOptionValueOrCreate(const char* command, bool getDefault/*=false*/)
{
	CRY_ASSERT(command != NULL);
	if(!command || !command[0])
		return "";

	if(!IsOption(command))
	{
		AddOption(command, "");
	}

	return GetOptionValue(command, getDefault);
}
Example #11
0
string CProfileOptions::GetOptionValue(const char* command, bool getDefault/*=false*/)
{
	if(!command || !IsOption(command))
	{
		return "";
	}

	std::vector<COption*>::const_iterator it = m_allOptions.begin();
	std::vector<COption*>::const_iterator end = m_allOptions.end();
	for(; it!=end; ++it)
	{
		if((*it)->GetName().compare(command)==0)
		{
			return getDefault ? (*it)->GetDefault() : (*it)->Get();
		}
	}
	return "";
}
Example #12
0
void COptions::ParseOptions(std::vector<std::wstring>& optionVector, 
							Command** ppCommand)
{
	assert(ppCommand == NULL && *ppCommand == NULL);
	std::vector<std::wstring>::iterator option = optionVector.begin();
	std::wstring arg = *option;

	CUserInfo* pCurrentUser = CGoablInfo::GetInstance()->GetCurrentUser();
	if (IsOption(arg, L"login"))
	{
		++option;
		*ppCommand = new CLoginCommand(pCurrentUser, *option);
	}
	else if (IsOption(arg, L"set"))
	{
		++option;
		//todo
	}
	else if (IsOption(arg, L"quit"))
	{
		*ppCommand = new CLogoutCommand(pCurrentUser);
	}
	else if (IsOption(arg, L"users"))
	{
		*ppCommand = new CShowUsersCommand(pCurrentUser);
	}
	else if (IsOption(arg, L"msg"))
	{
		++option;
		CUserInfo* pOtherUser = COnlineUsers::GetInstance()->GetUserByName(*option);
		++option;
		*ppCommand = new CSendMessageCommand(pCurrentUser, pOtherUser, *option);
	}
	else if (IsOption(arg, L"show"))
	{
		++option;
		CUserInfo* pOtherUser = COnlineUsers::GetInstance()->GetUserByName(*option);
		*ppCommand = new CShowMessageHistoryCommand(pCurrentUser, pOtherUser, CMessageRepository::GetInstance());
	}

}
Example #13
0
static  int     Parse( char *cmd ) {
//==================================

    char        opt;
    char        *end;
    int         len;
    int         cmp_option;
    char        in_quotes;

    Flags.no_link = 0;
    Flags.link_for_sys = 0;
    Flags.quiet        = 0;
#if _CPU == 8086
    Flags.windows      = 0;
    Flags.link_for_dos = 0;
    Flags.link_for_os2 = 0;
#else
    Flags.default_win  = 0;
#endif
    Flags.do_cvpack    = 0;

    DebugFlag = 0;

    // "cmd" will always begin with at least one
    // non-space character if we get this far

    do {
        opt = *cmd;
        if( ( opt == '-' ) || ( opt == SwitchChars[1] ) ) {
            cmd++;
        } else {
            opt = ' ';
        }
        in_quotes = FALSE;
        end = cmd;
        for(;;) {
            if( *end == '\0' )
                break;
            if( *end == '"' ) {
                if( in_quotes )
                    break;
                in_quotes = TRUE;
            }
            if( !in_quotes ) {
                if( *end == ' '  )
                    break;
                if( *end == '-' )
                    break;
                if( *end == SwitchChars[1] ) {
                    break;
                }
            }
            ++end;
        }
        len = end - cmd;
        if( len != 0 ) {
            if( opt == ' ' ) {  // if filename, add to list
                strncpy( Word, cmd, len );
                Word[len] = '\0';
                strlwr( Word );
                if( strstr( Word, ".lib" ) != NULL ) {
                    AddFile( &LibList, Word );
                } else {
                    AddFile( &FileList, Word );
                }
            } else {            // otherwise, do option
                --len;
                strncpy( Word, cmd + 1, len );
                Word[len] = '\0';
                cmp_option = 1; // assume its a compiler option
                switch( tolower( *cmd ) ) {
                case 'f':       // files option
                    end = ScanFName( end, len );
                    switch( tolower( Word[0] ) ) {
                    case 'd':   // name of linker directive file
                        if( Word[1] == '\0' ) {
                            LinkName = TEMPFILE;
                            cmp_option = 0;
                        } else if( (Word[1] == '=') || (Word[1] == '#') ) {
                            MakeName( Word, ".lnk" );    // add extension
                            LinkName = strdup( Word + 2 );
                            cmp_option = 0;
                        }
                        break;
                    case 'e':   // name of exe file
                        if( ( Word[1] == '=' ) || ( Word[1] == '#' ) ) {
                            fputs( "name ", Fp );
                            Fputnl( Word + 2, Fp );
                            strcpy( ExeName, Word + 2 );
                            cmp_option = 0;
                        }
                        break;
                    case 'm':   // name of map file
                        if( Word[1] == '\0' ) {
                            fputs( "option map\n", Fp );
                            cmp_option = 0;
                        } else if( (Word[1] == '=') || (Word[1] == '#') ) {
                            fputs( "option map=", Fp );
                            Fputnl( Word + 2, Fp );
                            cmp_option = 0;
                        }
                        break;
                    case 'i':
                        if( ( Word[1] == '=' ) || ( Word[1] == '#' ) ) {
                            fputs( "@", Fp );
                            Fputnl( Word + 2, Fp );
                            cmp_option = 0;
                        }
                        break;
                    case 'o':   // name of object file
                        // parse off argument, so we get right filename
                        // in linker command file
                        if( ( Word[1] == '=' ) || ( Word[1] == '#' ) ) {
                            ObjName = strdup( &Word[2] );
                        }
                        break;
                    default:
                        break;
                    }
                    break;
                case 'k':       // stack size option
                    if( ( Word[0] == '=' ) || ( Word[0] == '#' ) ) {
                        fputs( "option stack=", Fp );
                        Fputnl( Word + 1, Fp );
                        cmp_option = 0;
                    }
                    break;
                case 'c':       // compile only
                    if( Word[0] == '\0' ) {
                        Flags.no_link = 1;
                        cmp_option = 0;
                    }
                    break;
                case 'y':
                    if( Word[0] == '\0' ) {
                        cmp_option = 0;
                    }
                    break;
                case 'p':
                    // ignore the /p option - we now only
                    // have a protect-mode compiler
                    if( Word[0] == '\0' ) {
                        cmp_option = 0;
                    }
                    break;
                case 'l':
                    if( ( Word[0] == '=' ) || ( Word[0] == '#' ) ) {
                        Flags.link_for_sys = 1;
                        SystemName = strdup( &Word[1] );
                        cmp_option = 0;
#if _CPU == 8086
                    } else if( stricmp( Word, "r" ) == 0 ) {
                        Flags.link_for_dos = 1;
                        Flags.link_for_os2 = 0;
                        cmp_option = 0;
                    } else if( stricmp( Word, "p" ) == 0 ) {
                        Flags.link_for_os2 = 1;
                        Flags.link_for_dos = 0;
                        cmp_option = 0;
#endif
                    }
                    break;
                case '"':
                    Fputnl( &Word[0], Fp );
                    ++end;      // skip over closing quote
                    cmp_option = 0;
                    break;

                // compiler options that affect the linker

#if _CPU != 8086
                case 'b':
                    if( stricmp( Word, "w" ) ) {
                        Flags.default_win = 1;
                    }
                    break;
#endif

                case 'q':
                    if( IsOption( cmd, len + sizeof(char), "Quiet" ) ) {
                        Flags.quiet = 1;
                    }
                    break;
                case 'd':
                    if( DebugFlag == 0 ) { // not set by -h yet
                        if( strcmp( Word, "1" ) == 0 ) {
                            DebugFlag = 1;
                        } else if( strcmp( Word, "2" ) == 0 ) {
                            DebugFlag = 2;
                        }
                    }
                    break;
                case 'h':
                    if( strcmp( Word, "w" ) == 0 ) {
                        DebugFlag = 3;
                    } else if( strcmp( Word, "c" ) == 0 ) {
                        Flags.do_cvpack = 1;
                        DebugFlag = 4;
                    } else if( strcmp( Word, "d" ) == 0 ) {
                        DebugFlag = 5;
                    }
                    break;
                case 's':
                    if( IsOption( cmd, len + sizeof( char ), "SYntax" ) ) {
                        Flags.no_link = 1;
                    }
                    break;
#if _CPU == 8086
                case 'w':
                    if( IsOption( cmd, len + sizeof( char ), "WIndows" ) ) {
                        Flags.windows = 1;
                    }
                    break;
#endif
                default:
                    break;
                }
                // don't add linker-specific options to compiler command line
                if( cmp_option != 0 ) {
                    len = strlen( CmpOpts );
                    CmpOpts[len++] = ' ';
                    CmpOpts[len++] = opt;
                    CmpOpts[len++] = *cmd;      // keep original case
                    CmpOpts[len] = '\0';
                    strcat( CmpOpts, Word );
                }
            }
            cmd = end;
        }
        cmd = SkipSpaces( cmd );
    } while( *cmd != '\0' );
    return( 0 );
}
Example #14
0
  bool XMLConversion::ReadXML(XMLBaseFormat* pFormat, OBBase* pOb)
  {
    if(_requestedpos)
      {
        //The initial stream position was not at the start, probably because of fastsearch
        //Read and discard the first object to synchronize the reader,
        //then continue getting the requested object.
        //Assumes the objects are all at the same level in the DOM tree.
        SetOneObjectOnly(); //probably already set
        streampos SavedReqestedPos = _requestedpos;
        _requestedpos=0;//don't do this again
        ReadXML(pFormat,pOb);
        GetInStream()->seekg(SavedReqestedPos);
      }

    //**Parse
    int result=1;
    while(GetInStream()->good() && (_SkipNextRead || (result=xmlTextReaderRead(_reader))==1)) //read may not be called
    {
      _SkipNextRead=false;
      if(_LookingForNamespace)
      {
        const xmlChar* puri = xmlTextReaderConstNamespaceUri(_reader);
        if(puri)
          {
            string uri((const char*)puri);
            //Look up appropriate format class from the namespace URI
            NsMapType::iterator nsiter;
            nsiter = Namespaces().find(uri);
            if(nsiter!=Namespaces().end())
              {
                XMLBaseFormat* pNewFormat = nsiter->second;
                //Must have same target, e.g. OBMol, as current format
                if(pNewFormat->GetType() == pFormat->GetType())
                  {
                    _LookingForNamespace=false;
                    _SkipNextRead=true;
                    SetInFormat(pNewFormat);
                    pNewFormat->ReadMolecule(pOb,this);
                    return true;
                  }
              }
          }
      }

      const xmlChar* pname = xmlTextReaderConstLocalName(_reader);
      int typ = xmlTextReaderNodeType(_reader);
      if(typ==XML_READER_TYPE_SIGNIFICANT_WHITESPACE || !pname)
        continue; //Text nodes handled in format class
      string ElName((const char*)pname);

      //Pass the node on to the appropriate format class
      bool ret;
      if(typ==XML_READER_TYPE_ELEMENT)
        ret= pFormat->DoElement(ElName);
      else if(typ==XML_READER_TYPE_END_ELEMENT)
        ret= pFormat->EndElement(ElName);
      else
        continue;
      _lastpos = GetInStream()->tellg();

      if(!ret)
        //derived format callback has stopped processing by returning false;
        //leave reader intact so it can be continued to be used.
        if(!IsOption("n",OBConversion::INOPTIONS))
          {
            _LookingForNamespace = true;
            return true;
          }
      }

    if(result==-1)
    {
      xmlError* perr = xmlGetLastError();
      if(perr && perr->level!=XML_ERR_NONE)
        {
          obErrorLog.ThrowError("XML Parser " + GetInFilename(),
                                perr->message, obError);
        }
      xmlResetError(perr);
      GetInStream()->setstate(ios::eofbit);
      return false;
    }
    return GetInStream()->good() && result!=0;
  }
Example #15
0
/**
Function to parse the command line options.
Responsible to
1. Parse the input values.
2. Print the usage note. 
3. Identify the valdations to be carried out.
4. Type of report needs to be generated.

@internalComponent
@released

@param aArgc - argument count
@param aArgv[] - argument values
*/
ReturnType CmdLineHandler::ProcessCommandLine(unsigned int aArgc, char* aArgv[])
{
	if(aArgc < 2)
	{
		std::cout << PrintVersion().c_str() << std::endl;
		std::cout << PrintUsage().c_str() << std::endl;
		return EQuit;
	}
	ArgumentList argumentList(&aArgv[0], aArgv + aArgc);
	int argCount = argumentList.size();

	 iInputCommand = KToolName;

	for( int i = 1; i < argCount; i++ ) //Skip tool name
	{
		String name = argumentList.at(i);
		iInputCommand += " ";
		iInputCommand += name;
		int longOptionFlag = 0;
		if(IsOption(name, longOptionFlag))
		{
			String optionName;
			bool optionValue = false;
			StringList optionValueList;
			ParseOption(name, optionName, optionValueList, optionValue);
			char shortOption = KNull;
			if(Validate(ReaderUtil::ToLower(optionName), optionValue, optionValueList.size()))
			{
				if(longOptionFlag)
				{
					shortOption = optionName.at(2);
				}
				else
				{
					shortOption = optionName.at(1);
				}
			}

			switch(shortOption)
			{
				case 'q':
					iCommmandFlag |= QuietMode;
					break;
				case 'a':
					iCommmandFlag |= KAll;
					break;
				case 'x':
					iCommmandFlag |= KXmlReport;
					break;
				case 'o':
					iXmlFileName.assign(optionValueList.front());
					NormaliseName();
					break;
				case 's':
					if((optionName == KShortSuppressOption) || (optionName == KLongSuppressOption))
					{
						String value;
						while(optionValueList.size() > 0)
						{
							value = optionValueList.front();
							if(iSuppressVal[value])
							{
								if(iValidations > 0) //Is any check enabled?
								{
									if(iValidations & iSuppressVal[value])
									{
										iValidations ^= iSuppressVal[value]; //Consider only 3 LSB's
									}
								}
								else //Is this valid value?
								{
									iSuppressions |= iSuppressVal[value];
								}
							}
							else
							{
								throw ExceptionReporter(UNKNOWNSUPPRESSVAL,(char*)(optionValueList.front().c_str()));
							}
							optionValueList.pop_front();
						}
					}
					else if(optionName == KLongEnableSidCheck)
					{
						iValidations |= KMarkEnable;
						iValidations |= ESid;
					}
					else if(optionName == KLongSidAllOption)
					{
						iCommmandFlag |= KSidAll;
					}
					break;
				case 'd':
					if(optionName == KLongEnableDbgFlagCheck)
					{
						iValidations |= KMarkEnable;
						iValidations |= EDbg;
						if(optionValueList.size() > 0)
						{
							if(optionValueList.front() == String("true"))
							{
								iDebuggableFlagVal = true;
							}
							else if (optionValueList.front() == String("false"))
							{
								iDebuggableFlagVal = false; 
							}
							else
							{
								throw ExceptionReporter(UNKNOWNDBGVALUE);
							}
						}
					}
					else if (optionName == KLongEnableDepCheck)
					{
						iValidations |= KMarkEnable;
						iValidations |= EDep;
					}
					break;

				case 'e':
					if (optionName == KLongE32InputOption)
					{
						iCommmandFlag |= KE32Input;
					}
					break;

				case 'v':
					if(optionName == KLongVidValOption)
					{
						StringListToUnIntList(optionValueList, iVidValList);
					}
					else if(optionName == KLongEnableVidCheck)
					{
						iValidations |= KMarkEnable;
						iValidations |= EVid;
					}
					else
					{
						iCommmandFlag |= KVerbose;
						/**Initialize ExceptionImplementation class with verbose mode flag
						to print all status information to standard output*/
						ExceptionImplementation::Instance(iCommmandFlag);
					}
					break;
				case 'n':
						iCommmandFlag |= KNoCheck;
					break;
				case 'h':
					std::cout << PrintVersion().c_str() << std::endl;
					std::cout << PrintUsage().c_str() << std::endl;
					return EQuit; //Don't proceed further
			}
		}
		else
		{
			if(!AlreadyReceived(name))
			{
				iImageNameList.push_back(name);
			}
			else
			{
				ExceptionReporter(IMAGENAMEALREADYRECEIVED, (char*)name.c_str()).Report();
			}

			iNoImage = false;
		}
	} //While loop ends here
	if((iCommmandFlag || iValidations || iSuppressions) && iNoImage)
	{
		PrintVersion();
		PrintUsage();
	}
	//Always log the version information into log file
	ExceptionImplementation::Instance(iCommmandFlag)->Log(iVersion);
	ValidateArguments();
	ValidateE32NoCheckArguments();
	if(iCommmandFlag & KE32Input)
	{
		ValidateImageNameList();
	}
	return ESuccess;
}
Example #16
0
int _tmain(int argc, _TCHAR* argv[])
{
	char bufOut[CMD_SIZE] = {0};
	TCHAR bufCmd[CMD_SIZE] = {0};
	TCHAR *intext = NULL;
	if(argc == 1)
		wcsncat_s(bufCmd, L"qrcode.exe -h", CMD_SIZE);
	else
		wcsncat_s(bufCmd, L"qrcode.exe", CMD_SIZE);

	int i;
	for(i = 1; i < argc; i++)
	{
		if(!IsOption(argv[i]))
			break;

		wcsncat_s(bufCmd, L" ", CMD_SIZE);
		wcsncat_s(bufCmd, argv[i], CMD_SIZE);
		if(IsOptionWithParameter(argv[i]) && (i + 1 < argc))
		{
			i++;
			wcsncat_s(bufCmd, L" ", CMD_SIZE);
			wcsncat_s(bufCmd, argv[i], CMD_SIZE);
		}
	}

	if(i < argc)
	{
		wcsncat_s(bufCmd, L" \"", CMD_SIZE);
		wcsncat_s(bufCmd, argv[i], CMD_SIZE);
		wcsncat_s(bufCmd, L"\"", CMD_SIZE);
	}
	else
	{
		intext = readStdin();
		wcsncat_s(bufCmd, L" \"", CMD_SIZE);
		wcsncat_s(bufCmd, intext, CMD_SIZE);
		wcsncat_s(bufCmd, L"\"", CMD_SIZE);
	}

	DWORD len = ::WideCharToMultiByte(CP_UTF8, 0, bufCmd, wcslen(bufCmd), bufOut, CMD_SIZE, NULL, NULL);

	STARTUPINFOA si;
	PROCESS_INFORMATION pi;

	ZeroMemory( &si, sizeof(si) );
	si.cb = sizeof(si);
	ZeroMemory( &pi, sizeof(pi) );

	// Start the child process. 
	if( !CreateProcessA( NULL,   // No module name (use command line)
						bufOut,        // Command line
						NULL,           // Process handle not inheritable
						NULL,           // Thread handle not inheritable
						TRUE,          // Set handle inheritance to FALSE
						0,
						NULL,           // Use parent's environment block
						NULL,           // Use parent's starting directory 
						&si,            // Pointer to STARTUPINFO structure
						&pi )           // Pointer to PROCESS_INFORMATION structure
	) 
	{
		return FALSE;
	}

	// Wait until child process exits.
	WaitForSingleObject( pi.hProcess, INFINITE );
	
	// Close process and thread handles. 
	CloseHandle( pi.hProcess );
	CloseHandle( pi.hThread );

	return 0;
}
Example #17
0
void COptionsManager::InitProfileOptions(bool switchProfiles)
{
	if(!m_pPlayerProfileManager)
		return;

	if(g_pGameCVars->g_useProfile==0) return;

	if(g_pGameCVars->g_startFirstTime==1)
	{
		ICVar *pCVar = gEnv->pConsole->GetCVar("g_startFirstTime");
		if(pCVar && pCVar->GetIVal()==1)
		{
			pCVar->Set(0);
			m_firstStart = true;
		}
		switchProfiles=true;
	}

	const char* user = m_pPlayerProfileManager->GetCurrentUser();
	IPlayerProfile *pProfile = m_pPlayerProfileManager->GetCurrentProfile(user);
	if(!pProfile)
		return;

	IAttributeEnumeratorPtr attribEnum = pProfile->CreateAttributeEnumerator();
	IAttributeEnumerator::SAttributeDescription attrib;

	m_profileOptions.clear();
	while(attribEnum->Next(attrib))
	{
		bool bWriteToCfg = false;
		const char* attribCVar = "";
		const bool bIsOption = IsOption(attrib.name, attribCVar, bWriteToCfg);

		if (bIsOption)
		{
			SOptionEntry entry (attrib.name, bWriteToCfg);
			m_profileOptions[attribCVar] = entry;
			if(!bWriteToCfg || switchProfiles)
			{
				string value;
				if(!strcmp(attribCVar, "pb_client"))
				{
					GetProfileValue(attrib.name, value);
					if(atoi(value)==0)
					{
						m_pbEnabled = false;
						gEnv->pConsole->ExecuteString("net_pb_cl_enable false");
					}
					else
					{
						m_pbEnabled = true;
						gEnv->pConsole->ExecuteString("net_pb_cl_enable true");
					}
					continue;
				}
				else if(!strcmp(attribCVar, "fsaa_mode"))
				{
					GetProfileValue(attrib.name, value);
					SetAntiAliasingMode(value.c_str());
				}
				else if(!strcmp(attribCVar, "g_difficultyLevel"))
				{
					GetProfileValue(attrib.name, value);
					SetDifficulty(value);
				}
				
				ICVar *pCVar = gEnv->pConsole->GetCVar(attribCVar);
				if(pCVar && GetProfileValue(attrib.name, value))
				{
					if(stricmp(pCVar->GetString(), value.c_str()))
					{
						//CryLogAlways("Inited, loaded and changed: %s = %s (was %s)", attrib.name, value, pCVar->GetString());
						pCVar->Set(value.c_str());
					}
					else
					{
						//CryLogAlways("Inited, loaded, but not changed: %s = %s", attrib.name, value);
					}
					if(!stricmp(attrib.name,"Option.hud_colorLine"))
					{
						SetCrysisProfileColor(value.c_str());
					}
				}
			}
		}
	}

	WriteGameCfg();
	
}
Example #18
0
void COptionsManager::ResetDefaults(const char* option)
{
	if(!m_pPlayerProfileManager)
		return;

	const char* user = m_pPlayerProfileManager->GetCurrentUser();
	IPlayerProfile *pProfile = m_pPlayerProfileManager->GetCurrentProfile(user);
	if(!pProfile)
		return;
	XmlNodeRef root = GetISystem()->LoadXmlFile("libs/config/profiles/default/attributes.xml");
	bool resetAll = (option==NULL);
	bool detectHardware = false;
	for (int i = 0; i < root->getChildCount(); ++i)
	{
		XmlNodeRef enumNameNode = root->getChild(i);
		const char *name = enumNameNode->getAttr("name");
		const char *value = enumNameNode->getAttr("value");
		if(name && value)
		{
			const char* attribCVar = "";
			bool bWriteToCfg = false;
			const bool bIsOption = IsOption(name, attribCVar, bWriteToCfg);
			if(bIsOption)
			{
				if(!resetAll && strcmp(attribCVar,option))
					continue;

				if(!strcmp(attribCVar, "sys_spec_Shadows"))
				{
					detectHardware = true;
				}

				if(!strcmp(attribCVar, "hud_colorLine"))
				{
					CryFixedStringT<32> color;
					color.Format("%d", g_pGameCVars->hud_colorLine);
					SetCrysisProfileColor(color.c_str());
				}

				if(!strcmp(attribCVar,"pb_client"))
				{
					if(atoi(value)==0)
					{
						m_pbEnabled = false;
						gEnv->pConsole->ExecuteString("net_pb_cl_enable false");
					}
					else
					{
						m_pbEnabled = true;
						gEnv->pConsole->ExecuteString("net_pb_cl_enable true");
					}
				}
				else if(!strcmp(attribCVar, "g_difficultyLevel"))
				{
					SetDifficulty(value);
				}
				else
				{
					ICVar *pCVar = gEnv->pConsole->GetCVar(attribCVar);
					if(pCVar)
					{
						pCVar->Set(value);
					}
				}
				if(!resetAll)
					break;
			}
		}
	}
	if(detectHardware)
		AutoDetectHardware("");
}
Example #19
0
static  int     Parse( int argc, char **argv ) {
//==================================

    char        opt;
    //char        *end;
    char        *cmd;
    size_t      len;
    int         cmp_option;
    int         opt_index;
    int         cmp_opt_index;

    Flags.no_link = 0;
    Flags.link_for_sys = 0;
    Flags.quiet        = 0;
#if _CPU == 8086
    Flags.windows      = 0;
    Flags.link_for_dos = 0;
    Flags.link_for_os2 = 0;
#else
    Flags.default_win  = 0;
#endif
    Flags.do_cvpack    = 0;

    DebugFlag = 0;

    // Skip the first entry - it's the current program's name
    opt_index = 1;
    cmp_opt_index = 0;

    while( opt_index < argc ) {
        cmd = argv[opt_index];
        opt = *cmd;

        if( ( opt == '-' ) || ( opt == SwitchChars[1] ) ) {
            cmd++;
        } else {
            opt = ' ';
        }

        len = strlen(cmd);
        if( len != 0 ) {
            if( opt == ' ' ) {  // if filename, add to list
                strncpy( Word, cmd, len );
                Word[len] = '\0';
                strlwr( Word );
                if( strstr( Word, ".lib" ) != NULL ) {
                    AddFile( &LibList, Word );
                } else {
                    AddFile( &FileList, Word );
                }
            } else {            // otherwise, do option
                --len;
                strncpy( Word, cmd + 1, len );
                Word[len] = '\0';
                cmp_option = 1; // assume its a compiler option
                switch( tolower( *cmd ) ) {
                case 'f':       // files option
                    switch( tolower( Word[0] ) ) {
                    case 'd':   // name of linker directive file
                        if( Word[1] == '\0' ) {
                            LinkName = TEMPFILE;
                            cmp_option = 0;
                        } else if( (Word[1] == '=') || (Word[1] == '#') ) {
                            MakeName( Word, ".lnk" );    // add extension
                            LinkName = strdup( Word + 2 );
                            cmp_option = 0;
                        }
                        break;
                    case 'e':   // name of exe file
                        if( ( Word[1] == '=' ) || ( Word[1] == '#' ) ) {
                            fputs( "name ", Fp );
                            Fputnl( Word + 2, Fp );
                            strcpy( ExeName, Word + 2 );
                            cmp_option = 0;
                        }
                        break;
                    case 'm':   // name of map file
                        if( Word[1] == '\0' ) {
                            fputs( "option map\n", Fp );
                            cmp_option = 0;
                        } else if( (Word[1] == '=') || (Word[1] == '#') ) {
                            fputs( "option map=", Fp );
                            Fputnl( Word + 2, Fp );
                            cmp_option = 0;
                        }
                        break;
                    case 'i':
                        if( ( Word[1] == '=' ) || ( Word[1] == '#' ) ) {
                            fputs( "@", Fp );
                            Fputnl( Word + 2, Fp );
                            cmp_option = 0;
                        }
                        break;
                    case 'o':   // name of object file
                        // parse off argument, so we get right filename
                        // in linker command file
                        if( ( Word[1] == '=' ) || ( Word[1] == '#' ) ) {
                            ObjName = strdup( &Word[2] );
                        }
                        break;
                    default:
                        break;
                    }
                    break;
                case 'k':       // stack size option
                    if( ( Word[0] == '=' ) || ( Word[0] == '#' ) ) {
                        fputs( "option stack=", Fp );
                        Fputnl( Word + 1, Fp );
                        cmp_option = 0;
                    }
                    break;
                case 'c':       // compile only
                    if( Word[0] == '\0' ) {
                        Flags.no_link = 1;
                        cmp_option = 0;
                    }
                    break;
                case 'y':
                    if( Word[0] == '\0' ) {
                        cmp_option = 0;
                    }
                    break;
                case 'p':
                    // ignore the /p option - we now only
                    // have a protect-mode compiler
                    if( Word[0] == '\0' ) {
                        cmp_option = 0;
                    }
                    break;
                case 'l':
                    if( ( Word[0] == '=' ) || ( Word[0] == '#' ) ) {
                        Flags.link_for_sys = 1;
                        SystemName = strdup( &Word[1] );
                        cmp_option = 0;
#if _CPU == 8086
                    } else if( stricmp( Word, "r" ) == 0 ) {
                        Flags.link_for_dos = 1;
                        Flags.link_for_os2 = 0;
                        cmp_option = 0;
                    } else if( stricmp( Word, "p" ) == 0 ) {
                        Flags.link_for_os2 = 1;
                        Flags.link_for_dos = 0;
                        cmp_option = 0;
#endif
                    }
                    break;
                case '"':
                    Fputnl( &Word[0], Fp );
                    cmp_option = 0;
                    break;

                // compiler options that affect the linker

#if _CPU != 8086
                case 'b':
                    if( stricmp( Word, "w" ) ) {
                        Flags.default_win = 1;
                    }
                    break;
#endif

                case 'q':
                    if( IsOption( cmd, len + sizeof( char ), "Quiet" ) ) {
                        Flags.quiet = 1;
                    }
                    break;
                case 'd':
                    if( DebugFlag == 0 ) { // not set by -h yet
                        if( strcmp( Word, "1" ) == 0 ) {
                            DebugFlag = 1;
                        } else if( strcmp( Word, "2" ) == 0 ) {
                            DebugFlag = 2;
                        }
                    }
                    break;
                case 'h':
                    if( strcmp( Word, "w" ) == 0 ) {
                        DebugFlag = 3;
                    } else if( strcmp( Word, "c" ) == 0 ) {
                        Flags.do_cvpack = 1;
                        DebugFlag = 4;
                    } else if( strcmp( Word, "d" ) == 0 ) {
                        DebugFlag = 5;
                    }
                    break;
                case 's':
                    if( IsOption( cmd, len + sizeof( char ), "SYntax" ) ) {
                        Flags.no_link = 1;
                    }
                    break;
#if _CPU == 8086
                case 'w':
                    if( IsOption( cmd, len + sizeof( char ), "WIndows" ) ) {
                        Flags.windows = 1;
                    }
                    break;
#endif
                default:
                    break;
                }

                // don't add linker-specific options to compiler command line
                if( cmp_option != 0 ) {
                    CmpOpts[cmp_opt_index] = (char *)MemAlloc((3+strlen(Word))*sizeof(char));
                    CmpOpts[cmp_opt_index][0] = opt;
                    CmpOpts[cmp_opt_index][1] = *cmd;
                    CmpOpts[cmp_opt_index][2] = '\0';
                    strcat( CmpOpts[cmp_opt_index], Word );
                    CmpOpts[++cmp_opt_index] = NULL;
                }
            }
        }
        opt_index++;
    }
    return( 0 );
}
Example #20
0
/*
 * Validate options against a white list. Also check the config_file is
 * inside the config_dir. The white list is defined in validate.c
 * Returns true on success
 */
static BOOL
ValidateOptions (HANDLE pipe, const WCHAR *workdir, const WCHAR *options)
{
    WCHAR **argv;
    int argc;
    WCHAR buf[256];
    BOOL ret = FALSE;
    int i;
    const WCHAR *msg1 = L"You have specified a config file location (%s relative to %s)"
                        " that requires admin approval. This error may be avoided"
                        " by adding your account to the \"%s\" group";

    const WCHAR *msg2 = L"You have specified an option (%s) that may be used"
                         " only with admin approval. This error may be avoided"
                         " by adding your account to the \"%s\" group";

    argv = CommandLineToArgvW (options, &argc);

    if (!argv)
    {
        ReturnLastError (pipe, L"CommandLineToArgvW");
        ReturnError (pipe, ERROR_STARTUP_DATA, L"Cannot validate options", 1, &exit_event);
        goto out;
    }

    /* Note: argv[0] is the first option */
    if (argc < 1)  /* no options */
    {
        ret = TRUE;
        goto out;
    }

    /*
     * If only one argument, it is the config file
     */
    if (argc == 1)
    {
        WCHAR *argv_tmp[2] = { L"--config", argv[0] };

        if (!CheckOption (workdir, 2, argv_tmp, &settings))
        {
            snwprintf (buf, _countof(buf), msg1, argv[0], workdir,
                       settings.ovpn_admin_group);
            buf[_countof(buf) - 1] = L'\0';
            ReturnError (pipe, ERROR_STARTUP_DATA, buf, 1, &exit_event);
        }
        goto out;
    }

    for (i = 0; i < argc; ++i)
    {
        if (!IsOption(argv[i]))
            continue;

        if (!CheckOption (workdir, argc-i, &argv[i], &settings))
        {
            if (wcscmp(L"--config", argv[i]) == 0 && argc-i > 1)
            {
                snwprintf (buf, _countof(buf), msg1, argv[i+1], workdir,
                            settings.ovpn_admin_group);
                buf[_countof(buf) - 1] = L'\0';
                ReturnError (pipe, ERROR_STARTUP_DATA, buf, 1, &exit_event);
            }
            else
            {
                snwprintf (buf, _countof(buf), msg2, argv[i],
                           settings.ovpn_admin_group);
                buf[_countof(buf) - 1] = L'\0';
                ReturnError (pipe, ERROR_STARTUP_DATA, buf, 1, &exit_event);
            }
            goto out;
        }
    }

    /* all options passed */
    ret = TRUE;

out:
    if (argv)
        LocalFree (argv);
    return ret;
}