Example #1
0
// configure the design matrix from an xml element
bool RtDesignMatrix::configure(TiXmlElement *designEle,
                               const RtConfig &config) {
  string name;
  TiXmlElement *optionElmt;

  bool ret = true;

  // iterate over options
  for (TiXmlNode *option = 0;
       (option = designEle->IterateChildren("option", option));) {
    if (option->Type() != TiXmlNode::ELEMENT)
      continue;

    optionElmt = (TiXmlElement*) option;
    if (TIXML_SUCCESS != optionElmt->QueryValueAttribute("name", &name)) {
      continue;
    }

    // build the map between atrribute names and values
    map<string, string> attr = RtConfig::getAttributeMap(*optionElmt);

    // figure out which option we have and process it
    if (!processOption(name, optionElmt->GetText(), attr)) {
      ret = false;
    }
  }

  return ret;
}
Example #2
0
File: mtmtest.c Project: kulhos/pip
void main(int argc, char *argv[])
{
   int option;
   /* user's input */ 
   if (argc < 4)
   {
      /* no argument was passed in, go get it */
      getarg(argc,argv);
   }
   else
   {
      /* parse the passed in argument */
      parse(argc,argv);
   }
   /* verification purpose */
   printf("\nuserId is %s\n",userId);
   printf("password is %s\n",password);
   printf("ipAddress is %s\n",ipAddress);

   /* logging */
   /* ProfileLogging("/tmp/lyh.log",400000,1); */

   /* loop until user decides to break */
   while (continueFlag)
   {
       option = display_scr1();
       processOption(option);
   }
}
Example #3
0
bool CmdOption_parseString(const CommandLineOption *commandLineOption,
                           const char              *value
                          )
{
  assert(commandLineOption != NULL);


  return processOption(commandLineOption,"",commandLineOption->name,value,NULL,NULL);
}
Example #4
0
int main(int argc, char* argv[])
{
    struct sigaction action;
    action.sa_handler = signalHandler;
    sigemptyset(&action.sa_mask);
    action.sa_flags = 0;
    sigaction(SIGTERM, &action, NULL);

    srand(time(NULL));
    int i;
    i = isAppRunning(spAppNetflix, NULL );
    printf("Netflix is %s\n", i ? "Running":"Not Running");
    i = isAppRunning( spAppYouTube, spAppYouTubeMatch );
    printf("YouTube is %s\n", i ? "Running":"Not Running");

    // set all defaults
    setValue(spDefaultFriendlyName, spFriendlyName );
    setValue(spDefaultModelName, spModelName );
    setValue(spDefaultUuid, spUuid );
    setValue(spDefaultNetflix, spNetflix );
    setDataDir(spDefaultData);

    // Process command line options
    // Loop through pairs of command line options.
    for( i = 1; i < argc; i+=2 )
    {
        int numberOfOptions = sizeof(gDialOptions) / sizeof(dial_options_t);
        while( --numberOfOptions >= 0 )
        {
            int shortLen, longLen;
            shortLen = strlen(gDialOptions[numberOfOptions].pOption);
            longLen = strlen(gDialOptions[numberOfOptions].pLongOption);
            if( ( ( strncmp( argv[i], gDialOptions[numberOfOptions].pOption, shortLen ) == 0 ) ||
                ( strncmp( argv[i], gDialOptions[numberOfOptions].pLongOption, longLen ) == 0 ) ) &&
                ( (i+1) < argc ) )
            {
                processOption( numberOfOptions, argv[i+1] );
                break;
            }
        }
        // if we don't find an option in our list, bail out.
        if( numberOfOptions < 0 )
        {
            printUsage();
            exit(1);
        }
    }
    runDial();

    return 0;
}
void
cmd_processOptions(cmdlineParser   const cpP,
                   int             const argc,
                   const char **   const argv, 
                   const char **   const errorP) {

    struct optionx * longopts;

    longopts = createLongOptsArray(cpP->optionDescArray, cpP->numOptions);

    if (longopts == NULL) 
        casprintf(errorP, "Unable to get memory for longopts array");
    else {
        int endOfOptions;
        unsigned int i;

        *errorP = NULL;

        /* Set up initial assumption:  No options present */

        for (i = 0; i < cpP->numOptions; ++i)
            cpP->optionDescArray[i].present = false;

        endOfOptions = false;  /* initial value */
            
        while (!endOfOptions && !*errorP) {
            int const opterr0 = 0;
                /* Don't let getopt_long_only() print an error message */
            unsigned int longoptsIndex;
            const char * unrecognizedOption;
            const char * optarg;
            
            getopt_long_onlyx(argc, (char**) argv, "", longopts, 
                              &longoptsIndex, opterr0,
                              &endOfOptions, &optarg, &unrecognizedOption);
                              
            if (unrecognizedOption)
                casprintf(errorP, "Unrecognized option: '%s'", 
                          unrecognizedOption);
            else {
                if (!endOfOptions)
                    processOption(&cpP->optionDescArray[longoptsIndex], optarg,
                                  errorP);
            }
        }
        if (!*errorP)
            extractArguments(cpP, argc, argv);

        free(longopts);
    }
}
void ProgramOptions::process(const QStringList & appArguments)
{
    // built in preprocessing
    process(QSettings::SystemScope, orgName_s, QString());
    process(QSettings::SystemScope, orgName_s, appName_s);
    process(QSettings::UserScope,   orgName_s, QString());
    process(QSettings::UserScope,   orgName_s, appName_s);
    process("./" + orgName_s + ".INI");
    process("./" + appName_s + ".INI");

    // process args from the application for files or registry
    foreach(QString arg, appArguments)
    {
        if (arg.startsWith('$')) process(QSettings::SystemScope, arg.mid(1));
        if (arg.startsWith('%')) process(QSettings::UserScope, arg.mid(1));
        if (arg.startsWith('@')) process(arg.mid(1));
        if (arg.startsWith('/')) processOption(arg.mid(1));
    }
}
Example #7
0
bool CWorldMobPrototype::load(const String& resourceName)
{
	CLog::instance()->log(CLog::msgFlagResources,CLog::msgLvlInfo,"Loading mob prototype from '%s'.\n",resourceName.c_str());
	DataPtr dPtr = CResourceManager::instance()->load(resourceName);
	if( !dPtr )
	{
		CLog::instance()->log(CLog::msgLvlError,"Error loading mob prototype: resource not found.\n",resourceName.c_str());
		return false;
	}

	TiXmlDocument doc;
	std::stringstream buf;
	buf.write(dPtr->data(),dPtr->size());
	buf >> doc;

	if (doc.Error())
	{
		CLog::instance()->log(CLog::msgFlagResources, CLog::msgLvlError, _("Error loading mob prototype: XML parser returned an error: %s\n"), doc.ErrorDesc());
		return false;
	}

	TiXmlNode* root =  doc.FirstChild();
	while( root && root->Type() == TiXmlNode::DECLARATION )
		root = root->NextSibling();
	if( !root || root->Type() != TiXmlNode::ELEMENT || strcmp(root->ToElement()->Value(),"MobPrototype") )
	{
		CLog::instance()->log(CLog::msgFlagResources, CLog::msgLvlError, _("Error loading mob prototype: resource isn't mob prototype. %s\n"),root->Value());
		return false;
	};

	TiXmlNode* option;
	for( option = root->FirstChild(); option; option = option->NextSibling() )
		if( !processOption(option) )
		{
			CLog::instance()->log(CLog::msgFlagResources, CLog::msgLvlError, _("Error loading mob prototype: error in file near '%s'.\n"),option->Value());
			return false;
		};
	return true;
};
    bool compile(const char *wuid, const char *target, const char *targetCluster)
    {
        Owned<IConstWUQuery> query = workunit->getQuery();
        if (!query)
        {
            reportError("Workunit does not contain a query", 2);
            return false;
        }

        addTimeStamp(workunit, SSTglobal, NULL, StWhenCompiled);

        SCMStringBuffer mainDefinition;
        SCMStringBuffer eclQuery;
        query->getQueryText(eclQuery);
        query->getQueryMainDefinition(mainDefinition);

        StringBuffer eclccProgName;
        splitDirTail(queryCurrentProcessPath(), eclccProgName);
        eclccProgName.append("eclcc");
        StringBuffer eclccCmd(" -shared");
        if (eclQuery.length())
            eclccCmd.append(" -");
        if (mainDefinition.length())
            eclccCmd.append(" -main ").append(mainDefinition);
        eclccCmd.append(" --timings --xml");
        eclccCmd.append(" --nostdinc");
        if (globals->getPropBool("@enableEclccDali", true))
        {
            const char *daliServers = globals->queryProp("@daliServers");
            if (!daliServers)
                daliServers = ".";
            eclccCmd.appendf(" -dfs=%s", daliServers);
            const char *wuScope = workunit->queryWuScope();
            if (!isEmptyString(wuScope))
                eclccCmd.appendf(" -scope=%s", wuScope);
            eclccCmd.appendf(" -cluster=%s", targetCluster);
            SCMStringBuffer token;
            workunit->getSecurityToken(token);
            if (token.length())
                eclccCmd.appendf(" -wuid=%s -token=%s", workunit->queryWuid(), token.str());
        }
        Owned<IPipeProcess> pipe = createPipeProcess();
        pipe->setenv("ECLCCSERVER_THREAD_INDEX", idxStr.str());
        Owned<IPropertyTreeIterator> options = globals->getElements("./Option");
        ForEach(*options)
        {
            IPropertyTree &option = options->query();
            const char *name = option.queryProp("@name");
            const char *value = option.queryProp("@value");
            const char *cluster = option.queryProp("@cluster");                // if cluster is set it's specific to a particular target
            if (name && (cluster==NULL || cluster[0]==0 || strcmp(cluster, targetCluster)==0))
                processOption(name, value, eclccCmd, eclccProgName, *pipe, false);
        }
        eclccCmd.appendf(" -o%s", wuid);
        eclccCmd.appendf(" -platform=%s", target);
        eclccCmd.appendf(" --component=%s", queryStatisticsComponentName());

        Owned<IStringIterator> debugValues = &workunit->getDebugValues();
        ForEach (*debugValues)
        {
            SCMStringBuffer debugStr, valueStr;
            debugValues->str(debugStr);
            workunit->getDebugValue(debugStr.str(), valueStr);
            processOption(debugStr.str(), valueStr.str(), eclccCmd, eclccProgName, *pipe, true);
        }
        if (workunit->getResultLimit())
        {
            eclccCmd.appendf(" -fapplyInstantEclTransformations=1 -fapplyInstantEclTransformationsLimit=%u", workunit->getResultLimit());
        }
        try
        {
            cycle_t startCycles = get_cycles_now();
            Owned<ErrorReader> errorReader = new ErrorReader(pipe, this);
            Owned<AbortWaiter> abortWaiter = new AbortWaiter(pipe, workunit);
            eclccCmd.insert(0, eclccProgName);
            if (!pipe->run(eclccProgName, eclccCmd, ".", true, false, true, 0, true))
                throw makeStringExceptionV(999, "Failed to run eclcc command %s", eclccCmd.str());
            errorReader->start();
            abortWaiter->start();
            try
            {
                pipe->write(eclQuery.s.length(), eclQuery.s.str());
                pipe->closeInput();
            }
            catch (IException *e)
            {
                reportError(e);
                e->Release();
            }
            unsigned retcode = pipe->wait();
            errorReader->join();
            abortWaiter->stop();
            if (retcode == 0)
            {
                StringBuffer realdllname, dllurl;
                realdllname.append(SharedObjectPrefix).append(wuid).append(SharedObjectExtension);

                StringBuffer realdllfilename(dllPath);
                realdllfilename.append(SharedObjectPrefix).append(wuid).append(SharedObjectExtension);

                StringBuffer wuXML;
                if (!getWorkunitXMLFromFile(realdllfilename, wuXML))
                    throw makeStringException(999, "Failed to extract workunit from query dll");

                Owned<ILocalWorkUnit> embeddedWU = createLocalWorkUnit(wuXML);
                queryExtendedWU(workunit)->copyWorkUnit(embeddedWU, false, true);
                workunit->setIsClone(false);
                const char *jobname = embeddedWU->queryJobName();
                if (jobname && *jobname) //let ECL win naming job during initial compile
                    workunit->setJobName(jobname);
                if (!workunit->getDebugValueBool("obfuscateOutput", false))
                {
                    Owned<IWUQuery> query = workunit->updateQuery();
                    query->setQueryText(eclQuery.s.str());
                }

                createUNCFilename(realdllfilename.str(), dllurl);
                unsigned crc = crc_file(realdllfilename.str());

                Owned<IWUQuery> query = workunit->updateQuery();
                associateLocalFile(query, FileTypeDll, realdllfilename, "Workunit DLL", crc);
                queryDllServer().registerDll(realdllname.str(), "Workunit DLL", dllurl.str());

                cycle_t elapsedCycles = get_cycles_now() - startCycles;
                updateWorkunitTimeStat(workunit, SSTcompilestage, "compile", StTimeElapsed, NULL, cycle_to_nanosec(elapsedCycles));

                workunit->commit();
                return true;
            }
        }
        catch (IException * e)
        {
            reportError(e);
            e->Release();
        }
        return false;
    }
Example #9
0
bool CmdOption_parse(const char              *argv[],
                     int                     *argc,
                     const CommandLineOption commandLineOptions[],
                     uint                    commandLineOptionCount,
                     int                     commandPriority,
                     FILE                    *errorOutputHandle,
                     const char              *errorPrefix
                    )
{
  uint       z;
  uint       minPriority,maxPriority;
  uint       priority;
  bool       endOfOptionsFlag;
  const char *s;
  char       name[128];
  uint       i;
  const char *optionChars;
  const char *value;
  int        argumentsCount;

  assert(argv != NULL);
  assert(argc != NULL);
  assert((*argc) >= 1);
  assert(commandLineOptions != NULL);

  /* get min./max. option priority */
  if (commandPriority != CMD_PRIORITY_ANY)
  {
    minPriority = commandPriority;
    maxPriority = commandPriority;
  }
  else
  {
    minPriority = 0;
    maxPriority = 0;
    for (z = 0; z < commandLineOptionCount; z++)
    {
      maxPriority = MAX(maxPriority,commandLineOptions[z].priority);
    }
  }

  /* parse options */
  argumentsCount = 1;
  for (priority = minPriority; priority <= maxPriority; priority++)
  {
    endOfOptionsFlag = FALSE;
    z = 1;
    while (z < (*argc))
    {
      if      (!endOfOptionsFlag && (strcmp(argv[z],"--") == 0))
      {
        endOfOptionsFlag = TRUE;
      }
      else if (!endOfOptionsFlag && (strncmp(argv[z],"--",2) == 0))
      {
        /* get name */
        s = strchr(argv[z]+2,'=');
        if (s != NULL)
        {
          strncpy(name,argv[z]+2,MIN(s-(argv[z]+2),sizeof(name)-1));
          name[MIN(s-(argv[z]+2),sizeof(name)-1)] = '\0';
        }
        else
        {
          strncpy(name,argv[z]+2,sizeof(name)-1);
          name[sizeof(name)-1] = '\0';
        }

        /* find option */
        i = 0;
        while ((i < commandLineOptionCount) && (strcmp(commandLineOptions[i].name,name) != 0))
        {
          i++;
        }
        if (i < commandLineOptionCount)
        {
          /* get option value */
          value = NULL;
          if      (   (commandLineOptions[i].type == CMD_OPTION_TYPE_INTEGER  )
                   || (commandLineOptions[i].type == CMD_OPTION_TYPE_INTEGER64)
                   || (commandLineOptions[i].type == CMD_OPTION_TYPE_DOUBLE   )
                   || (commandLineOptions[i].type == CMD_OPTION_TYPE_SELECT   )
                   || (commandLineOptions[i].type == CMD_OPTION_TYPE_SET   )
                   || (commandLineOptions[i].type == CMD_OPTION_TYPE_STRING   )
                   || (commandLineOptions[i].type == CMD_OPTION_TYPE_SPECIAL  )
                  )
          {
            if (s != NULL)
            {
              /* skip '=' */
              s++;
              value = s;
            }
            else
            {
              if ((z+1) >= (*argc))
              {
                if (errorOutputHandle != NULL) fprintf(errorOutputHandle,"%sNo value given for option '--%s'!\n",(errorPrefix != NULL)?errorPrefix:"",name);
                return FALSE;
              }
              z++;
              value = argv[z];
            }
          }
          else if ((commandLineOptions[i].type == CMD_OPTION_TYPE_BOOLEAN))
          {
            if (s != NULL)
            {
              /* skip '=' */
              s++;
              value = s;
            }
          }

          if (commandLineOptions[i].priority == priority)
          {
            /* process option */
            if (!processOption(&commandLineOptions[i],"--",name,value,errorOutputHandle,errorPrefix))
            {
              return FALSE;
            }
          }
        }
        else
        {
          if (errorOutputHandle != NULL) fprintf(errorOutputHandle,"%sUnknown option '--%s'!\n",(errorPrefix != NULL)?errorPrefix:"",name);
          return FALSE;
        }
      }
      else if (!endOfOptionsFlag && (strncmp(argv[z],"-",1) == 0))
      {
        /* get option chars */
        optionChars = argv[z]+1;
        while ((optionChars != NULL) && (*optionChars) != '\0')
        {
          /* get name */
          name[0] = (*optionChars);
          name[1] = '\0';

          /* find option */
          i = 0;
          while ((i < commandLineOptionCount) && (commandLineOptions[i].shortName != name[0]))
          {
            i++;
          }
          if (i < commandLineOptionCount)
          {
            /* find optional value for option */
            if      (   (commandLineOptions[i].type == CMD_OPTION_TYPE_INTEGER  )
                     || (commandLineOptions[i].type == CMD_OPTION_TYPE_INTEGER64)
                     || (commandLineOptions[i].type == CMD_OPTION_TYPE_DOUBLE   )
                     || (commandLineOptions[i].type == CMD_OPTION_TYPE_SELECT   )
                     || (commandLineOptions[i].type == CMD_OPTION_TYPE_SET      )
                     || (commandLineOptions[i].type == CMD_OPTION_TYPE_STRING   )
                     || (commandLineOptions[i].type == CMD_OPTION_TYPE_SPECIAL  )
                    )
            {
              /* next argument is option value */
              if ((z+1) >= (*argc))
              {
                if (errorOutputHandle != NULL) fprintf(errorOutputHandle,"%sNo value given for option '-%s'!\n",(errorPrefix != NULL)?errorPrefix:"",name);
                return FALSE;
              }
              z++;
              s = argv[z];
              value = s;
            }
            else
            {
              s = NULL;
              value = NULL;
            }

            if (commandLineOptions[i].priority == priority)
            {
              /* process option */
              if (!processOption(&commandLineOptions[i],"-",name,value,errorOutputHandle,errorPrefix))
              {
                return FALSE;
              }
            }

            /* next option char */
            if (s == NULL)
            {
              optionChars++;
            }
            else
            {
              optionChars = NULL;
            }
          }
          else
          {
            if (errorOutputHandle != NULL) fprintf(errorOutputHandle,"%sUnknown option '-%s'!\n",(errorPrefix != NULL)?errorPrefix:"",name);
            return FALSE;
          }
        }
      }
      else
      {
        if ((commandPriority == CMD_PRIORITY_ANY) && (priority >= maxPriority))
        {
          /* add argument */
          argv[argumentsCount] = argv[z];
          argumentsCount++;
        }
      }

      z++;
    }
  }
  if (commandPriority == CMD_PRIORITY_ANY)
  {
    (*argc) = argumentsCount;
  }

  return TRUE;
}
Example #10
0
bool cmdOptions_parse(const char              *argv[],
                      int                     *argc,
                      const CommandLineOption commandLineOptions[],
                      uint                    commandLineOptionCount,
                      FILE                    *errorOutputHandle,
                      const char              *errorPrefix
                     )
{
  int        argumentsCount;
  bool       endOfOptionsFlag;
  uint       z;
  const char *s;
  char       name[128];
  const char *optionChars;
  const char *value;
  uint       i;

  assert(argv != NULL);
  assert(argc != NULL);
  assert((*argc) >= 1);
  assert(commandLineOptions != NULL);

  argumentsCount = 1;

  /* set default values */
  for (i = 0; i < commandLineOptionCount; i++)
  {
    switch (commandLineOptions[i].type)
    {
      case CMD_OPTION_TYPE_INTEGER:
        assert(commandLineOptions[i].variable.n != NULL);
        (*commandLineOptions[i].variable.n) = commandLineOptions[i].defaultValue.n;
        break;
      case CMD_OPTION_TYPE_DOUBLE:
        assert(commandLineOptions[i].variable.d != NULL);
        (*commandLineOptions[i].variable.d) = commandLineOptions[i].defaultValue.d;
        break;
      case CMD_OPTION_TYPE_BOOLEAN:
        assert(commandLineOptions[i].variable.b != NULL);
        (*commandLineOptions[i].variable.b) = commandLineOptions[i].defaultValue.b;
        break;
      case CMD_OPTION_TYPE_ENUM:
        assert(commandLineOptions[i].variable.enumeration != NULL);
        (*commandLineOptions[i].variable.enumeration) = commandLineOptions[i].defaultValue.enumeration;
        break;
      case CMD_OPTION_TYPE_SELECT:
        assert(commandLineOptions[i].variable.enumeration != NULL);
        (*commandLineOptions[i].variable.enumeration) = commandLineOptions[i].defaultValue.enumeration;
        break;
      case CMD_OPTION_TYPE_STRING:
        assert(commandLineOptions[i].variable.string != NULL);
        (*commandLineOptions[i].variable.string) = commandLineOptions[i].defaultValue.string;
        break;
      case CMD_OPTION_TYPE_SPECIAL:
        break;
    }
  }

  endOfOptionsFlag = FALSE;
  z = 1;
  while (z < (*argc))
  {
    if      (!endOfOptionsFlag && (strcmp(argv[z],"--") == 0))
    {
      endOfOptionsFlag = TRUE;
    }
    else if (!endOfOptionsFlag && (strncmp(argv[z],"--",2) == 0))
    {
      /* get name */
      s = strchr(argv[z]+2,'=');
      if (s != NULL)
      {
        strncpy(name,argv[z]+2,MIN(s-(argv[z]+2),sizeof(name)-1));
      }
      else
      {
        strncpy(name,argv[z]+2,sizeof(name)-1);
      }
      name[sizeof(name)-1] = '\0';

      /* find option */
      i = 0;
      while ((i < commandLineOptionCount) && (strcmp(commandLineOptions[i].name,name) != 0))
      {
        i++;
      }
      if (i >= commandLineOptionCount)
      {
        if (errorOutputHandle != NULL) fprintf(errorOutputHandle,"%sUnknown option '--%s'!\n",(errorPrefix != NULL)?errorPrefix:"",name);
        return FALSE;
      }

      /* get option value */
      if      (   (commandLineOptions[i].type == CMD_OPTION_TYPE_INTEGER)
               || (commandLineOptions[i].type == CMD_OPTION_TYPE_DOUBLE )
               || (commandLineOptions[i].type == CMD_OPTION_TYPE_SELECT )
               || (commandLineOptions[i].type == CMD_OPTION_TYPE_STRING )
               || (commandLineOptions[i].type == CMD_OPTION_TYPE_SPECIAL)
              )
      {
        if (s != NULL)
        {
          /* skip '=' */
          s++;
          value = s;
        }
        else
        {
          if ((z+1) >= (*argc))
          {
            if (errorOutputHandle != NULL) fprintf(errorOutputHandle,"%sNo value given to option '--%s'!\n",(errorPrefix != NULL)?errorPrefix:"",name);
            return FALSE;
          }
          z++;
          value = argv[z];
        }
      }
      else if ((commandLineOptions[i].type == CMD_OPTION_TYPE_BOOLEAN))
      {
        if (s != NULL)
        {
          /* skip '=' */
          s++;
          value = s;
        }
        else
        {
          value = NULL;
        }
      }

      /* process option */
      if (!processOption(&commandLineOptions[i],"--",name,value,errorOutputHandle,errorPrefix))
      {
        return FALSE;
      }
    }
    else if (!endOfOptionsFlag && (strncmp(argv[z],"-",1) == 0))
    {
      /* get option chars */
      optionChars = argv[z]+1;
      while ((optionChars != NULL) && (*optionChars) != '\0')
      {
        /* get name */
        name[0] = (*optionChars);
        name[1] = '\0';

        /* find option */
        i = 0;
        while ((i < commandLineOptionCount) && (commandLineOptions[i].shortName != name[0]))
        {
          i++;
        }
        if (i >= commandLineOptionCount)
        {
          if (errorOutputHandle != NULL) fprintf(errorOutputHandle,"%sUnknown option '-%s'!\n",(errorPrefix != NULL)?errorPrefix:"",name);
          return FALSE;
        }

        /* find optional value for option */
        if      (   (commandLineOptions[i].type == CMD_OPTION_TYPE_INTEGER)
                 || (commandLineOptions[i].type == CMD_OPTION_TYPE_DOUBLE )
                 || (commandLineOptions[i].type == CMD_OPTION_TYPE_SELECT )
                 || (commandLineOptions[i].type == CMD_OPTION_TYPE_STRING )
                 || (commandLineOptions[i].type == CMD_OPTION_TYPE_SPECIAL)
                )
        {
          /* next argument is option value */
          if ((z+1) >= (*argc))
          {
            if (errorOutputHandle != NULL) fprintf(errorOutputHandle,"%sNo value given to option '-%s'!\n",(errorPrefix != NULL)?errorPrefix:"",name);
            return FALSE;
          }
          z++;
          s = argv[z];
          value = s;
        }
        else
        {
          s = NULL;
          value = NULL;
        }

        /* process option */
        if (!processOption(&commandLineOptions[i],"-",name,value,errorOutputHandle,errorPrefix))
        {
          return FALSE;
        }

        /* next option char */
        if (s == NULL)
        {
          optionChars++;
        }
        else
        {
          optionChars = NULL;
        }
      }
    }
    else
    {
      /* add argument */
      argv[argumentsCount] = argv[z];
      argumentsCount++;
    }

    z++;
  }

  /* store new number of arguments */
  (*argc) = argumentsCount;

  return TRUE;
}
Example #11
0
Int32 main (Int32 argc, char *argv[])
{
  dovers(argc, argv);

  // check this before file_init_attach overwrites the user env
  NABoolean sync_with_stdio = (getenv("NO_SYNC_WITH_STDIO") == NULL);

  try
  {
    file_init_attach(&argc, &argv, TRUE, (char *)"");
    msg_debug_hook("sqlci", "sqlci.hook");
    file_mon_process_startup2(true, false);
    atexit(my_mpi_fclose);
  }
  catch (...)
  {
    cerr << "Error while initializing messaging system. Please make sure Trafodion is started and up. Exiting..." << endl;
    exit(1);
  }

  if (sync_with_stdio)
    ios::sync_with_stdio();


  // Establish app user id from the current NT process user identity.
  // This must be done explicitly until the "shadow-process" mechanism
  // is fully implemented.  (It is done too late in cli/Context.cpp.)
  // FX: I'm not sure whether the following code applies
  // 	 to NT only.

 
  // process command line options
  char * in_filename = NULL;
  char * input_string = NULL;
  char * out_filename = NULL;
  char * sock_port = NULL;
  NAString user_name("");
  Int32 i = 1;
  for (; i < argc; i++)
    processOption(argc, argv, 
                           i, 
                          (const char *&)in_filename, 
                          (const char *&)input_string,
                          (const char *&)out_filename,
                          (char *&)sock_port,
                          user_name
      );

  if (sock_port) 
  {
  }  

  // create a SQLCI object
  SqlciEnv * sqlci = new SqlciEnv();
  global_sqlci_env = sqlci;

  if (user_name.length() > 0)
    sqlci->setUserNameFromCommandLine(user_name);


  if (setjmp(ExportJmpBuf))
  {

    printf("\nSQLCI terminating due to assertion failure");
    delete sqlci;
    exit(1); // NAExit(1);
  } 

  ExportJmpBufPtr = &ExportJmpBuf;

  if ((!in_filename) &&
      (out_filename))
    {
      sqlci->setNoBanner(TRUE);

      // create a logfile with the name out_filename.
      // Do not do that if an in_filename is specified. Users should
      // put the log command in the input file.
      char * logf = new char[strlen("LOG ") + 
			    strlen(out_filename) + 
			    strlen(" clear;") +
			    1];
      sprintf(logf, "LOG %s clear;", out_filename);
      sqlci->run(NULL, logf);
      delete logf;

      sqlci->get_logfile()->setNoDisplay(TRUE);
    }

  // setup log4cxx, need to be done here so initLog4cxx can have access to
  // process information since it is needed to compose the log name
  QRLogger::initLog4cxx(QRLogger::QRL_MXEXE);

  // run it -- this is where the action is!
  if (in_filename || input_string)
    sqlci->run(in_filename, input_string);
  else
    sqlci->run();
    
  if ((!in_filename) &&
      (out_filename))
    {
      sqlci->run(NULL, (char *)"LOG;");
    }

  // Now we are done, delete SQLCI object
  delete sqlci;
#ifdef _DEBUG_RTS
  removeProcess();
#endif
#ifdef _DEBUG
  // Delete all contexts
  GetCliGlobals()->deleteContexts();
#endif  // _DEBUG
  return 0;
}
Example #12
0
void interpretCommands(void)
{
  short i, num, den, nbars;
  Char STR2[256];
  short FORLIM;

  strcpy(title_line, cline[(long)title]);
  strcpy(part_line, cline[(long)part]);
  if (*cline[(long)poet] != '\0' || *cline[(long)composer] != '\0')
    sprintf(composer_line, "\\mtxComposerLine{%s}{%s}",
	    cline[(long)poet], cline[(long)composer]);
  else
    *composer_line = '\0';
  strcpy(pmx_line, cline[(long)pmx]);
  GetNextWord(options_line, cline[(long)options], blank_, dummy);
  FORLIM = known_styles;
  for (i = 0; i <= FORLIM - 1; i++)
    style_used[i] = false;
  applyStyles();
  setVoices(voices);
  FORLIM = known_styles;
  for (i = old_known_styles; i <= FORLIM - 1; i++) {
    if (!style_used[i]) {
      warning("The following style was supplied but not used", !print);
      puts(known_style[i]);
    }
  }
  setClefs(clefs);
  if (!redefined[(long)meter]) {
    sprintf(STR2, "You have not defined Meter, assuming \"%s\" ",
	    cline[(long)meter]);
    warning(STR2, !print);
  }
  getMeter(cline[(long)meter], &meternum, &meterdenom, &pmnum, &pmdenom);
  setDefaultDuration(meterdenom);
  if (meternum == 0 &&
      !(redefined[(long)pages] || redefined[(long)systems] ||
	redefined[(long)bars])) {
    strcpy(cline[(long)bars], "1");
    redefined[(long)bars] = true;
  }
  if (redefined[(long)pages] || redefined[(long)systems]) {
    if (redefined[(long)bars])
      warning("BARS/LINE ignored since you specified PAGES or SYSTEMS", print);
    if (redefined[(long)systems])
      getNum(cline[(long)systems], &n_systems);
    else
      warning("PAGES specified but not SYSTEMS", !print);
    if (redefined[(long)pages])
      getNum(cline[(long)pages], &n_pages);
    else
      warning("SYSTEMS specified but not PAGES", !print);
  } else if (redefined[(long)bars]) {
    getNum(cline[(long)bars], &nbars);
    if (nbars > 0) {
      n_pages = 0;
      n_systems = nbars;
    }
  }
  getNum(cline[(long)sharps], &n_sharps);
  setSpace(cline[(long)space]);
  setSize(cline[(long)msize]);
  getTwoNums(cline[(long)shortnote], &num, &den);
  if (den == 0)
    den = 1;
  short_note = num * 64 / den;
  if (*cline[(long)flats] != '\0') {
    getNum(cline[(long)flats], &n_sharps);
    n_sharps = -n_sharps;
  }
  setName();
  setIndent();
  setInitOctave();
  setOnly(cline[(long)only]);
  setRange(cline[(long)range]);
  setDimension(cline[(long)width], width);
  setDimension(cline[(long)height], height);
  if (*options_line != '\0') {
    warning("\"Options\" is cryptic and obsolescent.", !print);
    printf("  Use \"Enable\" and \"Disable\" instead.\n");
  }
  FORLIM = strlen(options_line);
  for (i = 0; i <= FORLIM - 1; i++)
    processOption(options_line[i]);
}
Example #13
0
    bool compile(const char *wuid, const char *target, const char *targetCluster)
    {
        Owned<IConstWUQuery> query = workunit->getQuery();
        if (!query)
        {
            reportError("Workunit does not contain a query", 2);
            return false;
        }

        SCMStringBuffer mainDefinition;
        SCMStringBuffer eclQuery;
        query->getQueryText(eclQuery);
        query->getQueryMainDefinition(mainDefinition);

        StringBuffer eclccProgName("eclcc");
        StringBuffer eclccCmd(" -shared");
        if (eclQuery.length())
            eclccCmd.append(" -");
        if (mainDefinition.length())
            eclccCmd.append(" -main ").append(mainDefinition);
        if (workunit->getDebugValueBool("addTimingToWorkunit", true))
            eclccCmd.append(" --timings");

        Owned<IPipeProcess> pipe = createPipeProcess();
        pipe->setenv("ECLCCSERVER_THREAD_INDEX", idxStr.str());
        Owned<IPropertyTreeIterator> options = globals->getElements("./Option");
        ForEach(*options)
        {
            IPropertyTree &option = options->query();
            const char *name = option.queryProp("@name");
            const char *value = option.queryProp("@value");
            const char *cluster = option.queryProp("@cluster");                // if cluster is set it's specific to a particular target
            if (name && (cluster==NULL || cluster[0]==0 || strcmp(cluster, targetCluster)==0))
                processOption(name, value, eclccCmd, eclccProgName, *pipe, false);
        }
        eclccCmd.appendf(" -o%s", wuid);
        eclccCmd.appendf(" -platform=%s", target);

        Owned<IStringIterator> debugValues = &workunit->getDebugValues();
        ForEach (*debugValues)
        {
            SCMStringBuffer debugStr, valueStr;
            debugValues->str(debugStr);
            workunit->getDebugValue(debugStr.str(), valueStr);
            processOption(debugStr.str(), valueStr.str(), eclccCmd, eclccProgName, *pipe, true);
        }
        if (workunit->getResultLimit())
        {
            eclccCmd.appendf(" -fapplyInstantEclTransformations=1 -fapplyInstantEclTransformationsLimit=%u", workunit->getResultLimit());
        }
        try
        {
            unsigned time = msTick();
            Owned<ErrorReader> errorReader = new ErrorReader(pipe, this);
            eclccCmd.insert(0, eclccProgName);
            pipe->run(eclccProgName, eclccCmd, ".", true, false, true, 0);
            errorReader->start();
            try
            {
                pipe->write(eclQuery.s.length(), eclQuery.s.str());
                pipe->closeInput();
            }
            catch (IException *e)
            {
                reportError(e);
                e->Release();
            }
            unsigned retcode = pipe->wait();
            errorReader->join();
            if (retcode == 0)
            {
                StringBuffer realdllname, dllurl;
                realdllname.append(SharedObjectPrefix).append(wuid).append(SharedObjectExtension);

                StringBuffer realdllfilename(dllPath);
                realdllfilename.append(SharedObjectPrefix).append(wuid).append(SharedObjectExtension);

                StringBuffer wuXML;
                if (getWorkunitXMLFromFile(realdllfilename, wuXML))
                {
                    Owned<ILocalWorkUnit> embeddedWU = createLocalWorkUnit();
                    embeddedWU->loadXML(wuXML);
                    queryExtendedWU(workunit)->copyWorkUnit(embeddedWU, true);
                    workunit->setIsClone(false);
                    SCMStringBuffer jobname;
                    if (embeddedWU->getJobName(jobname).length()) //let ECL win naming job during initial compile
                        workunit->setJobName(jobname.str());
                    Owned<IWUQuery> query = workunit->updateQuery();
                    query->setQueryText(eclQuery.s.str());
                }

                createUNCFilename(realdllfilename.str(), dllurl);
                unsigned crc = crc_file(realdllfilename.str());

                Owned<IWUQuery> query = workunit->updateQuery();
                associateLocalFile(query, FileTypeDll, realdllfilename, "Workunit DLL", crc);
                queryDllServer().registerDll(realdllname.str(), "Workunit DLL", dllurl.str());
                time = msTick()-time;
                if (workunit->getDebugValueBool("addTimingToWorkunit", true))
                    workunit->setTimerInfo("eclccserver: create workunit", NULL, time, 1, 0);

                workunit->commit();
                return true;
            }
        }
        catch (IException * e)
        {
            reportError(e);
            e->Release();
        }
        return false;
    }