VARIANT CMUSHclientDoc::GetCurrentValue(LPCTSTR OptionName) 
{
	VARIANT vaResult;
	VariantInit(&vaResult);

  vaResult.vt = VT_NULL;    // default if not found

int i = GetOptionIndex (OptionName);

  if (i != -1)
    {
    if (m_CurrentPlugin &&
        (OptionsTable [i].iFlags & OPT_PLUGIN_CANNOT_READ))
    	return vaResult;  // not available to plugin
    SetUpVariantLong (vaResult, GetOptionItem (i));
    }  // end of found
  else
    {
    i = GetAlphaOptionIndex (OptionName);
    if (i != -1)
      {
      if (m_CurrentPlugin &&
          (AlphaOptionsTable [i].iFlags & OPT_PLUGIN_CANNOT_READ))
    	  return vaResult;  // not available to plugin
      SetUpVariantString (vaResult, GetAlphaOptionItem (i));
      }  // end of found
    }

	return vaResult;
}    // end of CMUSHclientDoc::GetCurrentValue
Exemple #2
0
bool CommandParser::GetFlag(char ID) {
	char **Out;
	bool exists=GetParameter(ID,0,Out);
	if (exists) {
		if (GetNumOptionParameters(GetOptionIndex(ID))!=0) {
			printf("Invalid number of parameters for option -%c.\n",ID);
			invalid_option_parameters=true;
		}
	}
	return exists;
}
Exemple #3
0
bool CommandParser::GetParameterE(char ID,char *type,...) {
	char **Out;

	int opt_index=GetOptionIndex(ID);
	if (opt_index==num_elements) return false;
	int n_param=GetNumOptionParameters(opt_index);


	int j=0;
	int lenght=(int)strlen(type);
	int num=-1;
	char *typeB=new char[strlen(type)+2];
	typeB[0]=0;

	for(int i=0;i<lenght;i++) {
		if (type[i]=='[') {
			if (j<=n_param) num=j;
			else break;
			continue;
		}
		if (type[i]==']') {
			if (j<=n_param) num=j;
			else break;
			continue;
		}
		typeB[j++]=type[i];
		typeB[j]=0;
	}
	if (j<=n_param) num=j;
	if (n_param!=num) {
		printf("Invalid number of parameters for option -%c.\n",ID);
		invalid_option_parameters=true;
		delete[]typeB;
		return false;
	}
	typeB[num]=0;

	if (!GetParameter(ID,1,Out)) {delete[]typeB;return false;}
	

	va_list marker;
	va_start(marker,type);
	for(int i=0;i<num;i++) {
		if (Out[i][0]=='-') {delete[]typeB;return false;}
		if (typeB[i]=='s') strcpy(va_arg(marker,char*),Out[i]);
		if (typeB[i]=='i') *va_arg(marker,int*)=atoi(Out[i]);
		if (typeB[i]=='c') *(va_arg(marker,char*))=Out[i][0];
		if (typeB[i]=='f') *(va_arg(marker,float*))=(float)atof(Out[i]);
		if (typeB[i]=='d') *(va_arg(marker,double*))=atof(Out[i]);
	}
	va_end(marker);
	delete[]typeB;
	return true;
}
Exemple #4
0
bool CommandParser::GetParameter(char ID,int param_index,char **&Out) {
	int index=GetOptionIndex(ID);
	if (index==num_elements) return false;
	if (param_index==0) {Out=NULL;return true;}

	for(int i=1;i<=param_index;i++) {
		if (index+i>=num_elements) return false;
		if (elements[index+i][0]=='-') return false;
	}

	Out=elements+index+param_index;
	return true;
}
long CMUSHclientDoc::GetOption(LPCTSTR OptionName) 
{

long i = GetOptionIndex (OptionName);

  if (i == -1)
    return -1;   // not found

  if (m_CurrentPlugin &&
      (OptionsTable [i].iFlags & OPT_PLUGIN_CANNOT_READ))
    return -1;  // not available to plugin

  return GetOptionItem (i);


} // end of CMUSHclientDoc::GetOption
double ezCommandLineUtils::GetFloatOption(const char* szOption, double fDefault, bool bCaseSensitive) const
{
  const ezInt32 iIndex = GetOptionIndex(szOption, bCaseSensitive);

  if (iIndex < 0)
    return fDefault;

  if (iIndex + 1 == m_Commands.GetCount()) // last command
    return fDefault;

  // try to convert the next option to a number
  double fRes = fDefault;
  ezConversionUtils::StringToFloat(m_Commands[iIndex + 1].GetData(), fRes);

  return fRes;
}
Exemple #7
0
int main( int argc, TEXTCHAR **argv )
{
	POPTION_TREE_NODE id_root = NULL;
	pvtSection = VarTextCreate();
	if( argc > 1 )
	{
		if( strcmp( argv[1], WIDE("-s") ) == 0 )
		{
			static TEXTCHAR tmp[256];
			if( argc > 2 )
			{
				SystemPrefix = argv[2];
			}
			else
			{
#ifdef __NO_NETWORK__
				snprintf( tmp, sizeof( tmp ), WIDE("/INI Store/localhost") );
#else
				snprintf( tmp, sizeof( tmp ), WIDE("/INI Store/%s"), GetSystemName() );
#endif
				SystemPrefix = tmp;
			}
			id_root = GetOptionIndex( id_root, WIDE("DEFAULT"), SystemPrefix, NULL );
			if( !id_root )
				return 0;
		}
	}

	{
		LISTFILL lf;
      MemSet( &lf, 0, sizeof( lf ) );
		EnumOptions( id_root, FillList, (uintptr_t)&lf );
	}
	{
		PTEXT pINI = VarTextGet( pvtIni );
		CRYPTOEncryptMemory( GetText( pINI ), GetTextSize( pINI ) );
		if( output )
		{
			fwrite( GetText(pINI), 1, GetTextSize( pINI ), output );
			LineRelease( pINI );
			fclose( output );
			output = NULL;
		}
	}
   return 0;
}
bool ezCommandLineUtils::GetBoolOption(const char* szOption, bool bDefault, bool bCaseSensitive) const
{
  const ezInt32 iIndex = GetOptionIndex(szOption, bCaseSensitive);

  if (iIndex < 0)
    return bDefault;

  if (iIndex + 1 == m_Commands.GetCount()) // last command, treat this as 'on'
    return true;

  if (m_Commands[iIndex + 1].StartsWith("-")) // next command is the next option -> treat this as 'on' as well
    return true;

  // otherwise try to convert the next option to a boolean
  bool bRes = bDefault;
  ezConversionUtils::StringToBool(m_Commands[iIndex + 1].GetData(), bRes);

  return bRes;
}
ezUInt32 ezCommandLineUtils::GetStringOptionArguments(const char* szOption, bool bCaseSensitive) const
{
  const ezInt32 iIndex = GetOptionIndex(szOption, bCaseSensitive);

  // not found -> no parameters
  if (iIndex < 0)
    return 0;

  ezUInt32 uiParamCount = 0;

  for (ezUInt32 uiParam = iIndex + 1; uiParam < m_Commands.GetCount(); ++uiParam)
  {
    if (m_Commands[uiParam].StartsWith("-")) // next command is the next option -> no parameters
      break;

    ++uiParamCount;
  }

  return uiParamCount;
}
const char* ezCommandLineUtils::GetStringOption(const char* szOption, ezUInt32 uiArgument, const char* szDefault, bool bCaseSensitive) const
{
  const ezInt32 iIndex = GetOptionIndex(szOption, bCaseSensitive);

  // not found -> no parameters
  if (iIndex < 0)
    return szDefault;

  ezUInt32 uiParamCount = 0;

  for (ezUInt32 uiParam = iIndex + 1; uiParam < m_Commands.GetCount(); ++uiParam)
  {
    if (m_Commands[uiParam].StartsWith("-")) // next command is the next option -> not enough parameters
      return szDefault;

    // found the right one, return it
    if (uiParamCount == uiArgument)
      return m_Commands[uiParam].GetData();

    ++uiParamCount;
  }

  return szDefault;
}
Exemple #11
0
ezResult ezTexConv2::ParseInputFiles()
{
  if (m_Processor.m_Descriptor.m_OutputType == ezTexConvOutputType::Atlas)
    return EZ_SUCCESS;

  ezStringBuilder tmp, res;
  const auto pCmd = ezCommandLineUtils::GetGlobalInstance();

  auto& files = m_Processor.m_Descriptor.m_InputFiles;

  for (ezUInt32 i = 0; i < 64; ++i)
  {
    tmp.Format("-in{0}", i);

    res = pCmd->GetStringOption(tmp);

    // stop once an option was not found
    if (res.IsEmpty())
      break;

    files.EnsureCount(i + 1);
    files[i] = res;
  }

  // if no numbered inputs were given, try '-in', ignore it otherwise
  if (files.IsEmpty())
  {
    // short version for -in1
    res = pCmd->GetStringOption("-in");

    if (!res.IsEmpty())
    {
      files.PushBack(res);
    }
  }

  if (m_Processor.m_Descriptor.m_OutputType == ezTexConvOutputType::Cubemap)
  {
    // 0 = +X = Right
    // 1 = -X = Left
    // 2 = +Y = Top
    // 3 = -Y = Bottom
    // 4 = +Z = Front
    // 5 = -Z = Back

    if (files.IsEmpty() && (pCmd->GetOptionIndex("-right") != -1 || pCmd->GetOptionIndex("-px") != -1))
    {
      files.SetCount(6);

      files[0] = pCmd->GetStringOption("-right", 0, files[0]);
      files[1] = pCmd->GetStringOption("-left", 0, files[1]);
      files[2] = pCmd->GetStringOption("-top", 0, files[2]);
      files[3] = pCmd->GetStringOption("-bottom", 0, files[3]);
      files[4] = pCmd->GetStringOption("-front", 0, files[4]);
      files[5] = pCmd->GetStringOption("-back", 0, files[5]);

      files[0] = pCmd->GetStringOption("-px", 0, files[0]);
      files[1] = pCmd->GetStringOption("-nx", 0, files[1]);
      files[2] = pCmd->GetStringOption("-py", 0, files[2]);
      files[3] = pCmd->GetStringOption("-ny", 0, files[3]);
      files[4] = pCmd->GetStringOption("-pz", 0, files[4]);
      files[5] = pCmd->GetStringOption("-nz", 0, files[5]);
    }
  }

  for (ezUInt32 i = 0; i < files.GetCount(); ++i)
  {
    if (files[i].IsEmpty())
    {
      ezLog::Error("Input file {} is not specified", i);
      return EZ_FAILURE;
    }

    ezLog::Info("Input file {}: '{}'", i, files[i]);
  }

  if (m_Processor.m_Descriptor.m_InputFiles.IsEmpty())
  {
    ezLog::Error("No input files were specified. Use \'-in \"path/to/file\"' to specify an input file. Use '-in0', '-in1' etc. to specify "
                 "multiple input files.");
    return EZ_FAILURE;
  }

  return EZ_SUCCESS;
}