Beispiel #1
0
//-----------------------------------------------------------------------------
// TemplateFileParsor::ReadHeader
//-----------------------------------------------------------------------------
void TemplateFileParsor::ReadHeader(const string &strTemplateName, String *pstrParams)
{
  // Build template lines list
  ifstream fs(PSZ(strTemplateName));
  int iLine = 0;
  
  while( !fs.eof() )
  {
    iLine++;
    fs.getline(g_acScratchBuf, g_iScratchLen);
    String strLine = g_acScratchBuf;
    strLine.Trim();

    if( !strLine.StartWith("#") )
      // End of header reached
      return;

    // Header parsing
    // Search for lines begining with "# @param..."
    strLine.erase(0, 1);
    strLine.Trim();
    if( strLine.StartWith("@param") )
    {
      strLine.erase(0, strlen("@param"));
      strLine.Trim();

      // Get name
      String strName;
      strLine.ExtractToken(' ', &strName);
      strName.Trim();
      strLine.Trim();
      
      // Pass type;
      String strTmp;
      strLine.ExtractToken(' ', &strTmp);
      strLine.Trim();

      // Pass description
      strLine.ExtractToken('\'', '\'', &strTmp);
      strLine.Trim();
      *pstrParams += strName + string("=") + strLine + string(",");
    }
  }
}
void  ParameterSearchBinaryCombo::ProcessCmdLineStr  (String  cmdLine)
{
  char*  arguments[60];
  int    argCount = 0;

  arguments[0] = strdup ("ParameterSearchBinaryCombo");
  argCount++;

  while  (!cmdLine.Empty ())
  {
    String  parmField = cmdLine.ExtractToken (" ");
    arguments[argCount] = strdup (parmField.Str ());
    argCount++;
  }

  ParseCommandLine (argCount, arguments);
}  /* CommandLineStr */
Beispiel #3
0
//-----------------------------------------------------------------------------
// TemplateFileParsor::ParseExpression
//-----------------------------------------------------------------------------
ExpressionPtr TemplateFileParsor::ParseExpression(const String &_strExpr)
{
  // Very basic math expression parsor:
  // - can only parse expression like 'a + b - c * d / e' without parenthesis
  // - spaces characters must enclose operators
  ExpressionPtr ptrExpression = new Expression();

  String strExpr = _strExpr;
  Expression::Operation opPrevious = Expression::CharToOp('N');
  uint uiStartSearch = 0;
  while( !strExpr.empty() )
  {
    int iOpPos = strExpr.find_first_of("+-/*", uiStartSearch);

    if( string::npos != iOpPos )
    {
      String strMatching = strExpr.substr(iOpPos-1,3);
      // Operator must be enclosed by spaces characters
      if( strMatching.Match(" * ") )
      { 
        char cOp = strExpr[iOpPos];
        String strToken;
        // Extract first operand
        strExpr.ExtractToken(cOp, &strToken);
        strToken.Trim();
        ptrExpression->AddFragment(new Expression::Fragment(new Expression::Constant(strToken), opPrevious));
        opPrevious = Expression::CharToOp(cOp);
      }
      else
      { // Look forward
        uiStartSearch = iOpPos + 1;
      }
    }
    else
    {
      strExpr.Trim();
      ptrExpression->AddFragment(new Expression::Fragment(new Expression::Constant(strExpr), opPrevious));
      break;
    }
  }
  return ptrExpression;
}
Beispiel #4
0
//-----------------------------------------------------------------------------
// ExtractorApp::AddParameters
//-----------------------------------------------------------------------------
void ExtractorApp::AddParameters(const String &strParamList)
{
    String strList = strParamList;
    String strParamDef, strParamName, strParamSubtitution;
    while( !strList.empty() )
    {
        strList.ExtractToken(',', &strParamDef);
        if( strParamDef.find('=') != string::npos )
        {
            strParamDef.ExtractToken('=', &strParamName);
            strParamSubtitution = strParamDef;
        }
        else
        {
            strParamName = strParamDef;
            strParamSubtitution = "<defined>";
        }
        // Add paramater only if not always defined
        if( !m_dictParam.HasKey(strParamName) )
            m_dictParam.insert(StringDict::value_type(strParamName, strParamSubtitution));
    }
}
Beispiel #5
0
ParameterJob::ParameterJob (RunLog&    _log,
                            String     _desc
                           ):
  log (_log)
{
  accuracy     = 0;
  startTime    = 0;

  _desc.TrimLeft ();

  curStatus = _desc.ExtractChar ();
 
  if  ((curStatus == '0')  ||  
       (curStatus == '1')  ||  
       (curStatus == '2')  ||  
       (curStatus == '3')
      )
  {
    // We Are Ok
  }
  else
  {
    log.Level (-1) << endl 
                   << "ParameterJob:  We have an invalid Cur Status."
                   << endl;
    osWaitForEnter ();
  }


  {
    String  processsNumField = _desc.ExtractToken (" ,\t");
    processNum = atoi (processsNumField.Str ());
  }


  {
    String  jobIdField = _desc.ExtractToken (" ,\t");
    jobId = atoi (jobIdField.Str ());
  }


  {
    String  cParmStr = _desc.ExtractToken (" ,\t");
    cParm = atoi (cParmStr.Str ());
  }


  {
    String  gammaParmStr = _desc.ExtractToken (" ,\t");
    gammaParm = atof (gammaParmStr.Str ());
  }


  {
    String  aParmStr = _desc.ExtractToken (" ,\t");
    aParm = atoi (aParmStr.Str ());
  }


  {
    String  accuracyField = _desc.ExtractToken (" ,\t");
    accuracy = atof (accuracyField.Str ());
  }
}
Beispiel #6
0
ParameterProcess::ParameterProcess (RunLog&          _log,
                                    ImageClassList&  imageClasses,
                                    String           _desc
                                   ):
  log (_log)
{
  highestAccuracy  = (FFLOAT)0.0;
  startTime        = 0;

  _desc.TrimLeft ();

  curStatus = _desc.ExtractChar ();
 
  if  ((curStatus == '0')  ||  
       (curStatus == '1')  ||  
       (curStatus == '2')
      )
  {
    // We Are Ok
  }
  else
  {
    log.Level (-1) << endl 
                   << "ParameterProcess:  We have an invalid Cur Status[" << curStatus << "]."
                   << endl;
    exit (-1);
  }


  {
    String  processsNumField = _desc.ExtractToken (" ,\t");
    processNum = atoi (processsNumField.Str ());
  }


  {
    String  jobIdField = _desc.ExtractToken (" ,\t");
    jobId = atoi (jobIdField.Str ());
  }


  {
    // Lets get the two Classes that we are running for

    String  class0Name = _desc.ExtractToken (" ,\t");
    String  class1Name = _desc.ExtractToken (" ,\t");


    if  (class0Name == "NoName")
    {
      class0 = class1 = NULL;
    }
    else
    {
      class0 = imageClasses.LookUpByName (class0Name);
      class1 = imageClasses.LookUpByName (class1Name);

      if  (!class0)
      {
        cerr << endl
             << "*** ERROR ***   ParameterProcess,  Invalid Class0[" << class0Name << "]." << endl
             << endl;
        exit (-1);
      }

      if  (!class1)
      {
        cerr << endl
             << "*** ERROR ***   ParameterProcess,  Invalid Class0[" << class1Name << "]." << endl
             << endl;
        exit (-1);
      }
    }
  }


  {
    String  cParmStr = _desc.ExtractToken (" ,\t");
    cParm = atoi (cParmStr.Str ());
  }


  {
    String  gammaParmStr = _desc.ExtractToken (" ,\t");
    gammaParm = atof (gammaParmStr.Str ());
  }


  {
    String  aParmStr = _desc.ExtractToken (" ,\t");
    aParm = atoi (aParmStr.Str ());
  }


  {
    String  highestAccuracyField = _desc.ExtractToken (" ,\t");
    highestAccuracy = (FFLOAT)atof (highestAccuracyField.Str ());
  }
}
void  ParameterSearchBinaryCombo::LoadCurrentStatusFile ()
{
  log.Level (10) << "ParameterSearchBinaryCombo::LoadCurrentStatusFile - Loading current Status File." << endl;

  char  buff[10240];

  statusFile = fopen (statusFileName, "r");
  if  (!statusFile)
  {
     log.Level (-1) << endl
                    << "ParameterSearchBinaryCombo::LoadCurrentStatusFile - *** ERROR ***  Can not open Status File[" 
                    << statusFileName << "]." 
                    << endl;
     EndBlock ();
     exit (1);

     osWaitForEnter ();
  }

  {
    fgets (buff, sizeof (buff), statusFile);
    String  cmdLine (buff);
    cmdLine.TrimRight ();
    ProcessCmdLineStr  (cmdLine);
  }

  {
    // If images are not loadted then we need 2 load trhem now.

    if  (images.QueueSize () < 1)
    {
      ReadProblem ();
    }
  }


  {
    fgets (buff, sizeof (buff), statusFile);
    String  buffStr (buff);

    numOfProcesses       = buffStr.ExtractTokenInt    (" ,\n\t");
    highestAccuracySoFar = buffStr.ExtractTokenDouble (" ,\n\t");
  }


  {
    // Get Master Class List
    delete  masterClassList;

    fgets (buff, sizeof (buff), statusFile);
    String  buffStr (buff);

    numOfClasses = buffStr.ExtractTokenInt    (" ,\n\t");
    masterClassList = new ImageClassPtr[numOfClasses];
    for  (int idx = 0;  idx < numOfClasses;  idx++)
    {
      String  className = buffStr.ExtractToken (" ,\n\t");
      masterClassList[idx] = imageClasses.LookUpByName (className);
      if  (!masterClassList[idx])
      {
        cerr << endl
             << "*** ERROR ***,   Class[" << className << "]  is not one of the classes in the data file." << endl
             << endl;
        exit (-1);
      }
    }
  }


  {
    // Lets get next Class IDX's to perform

    fgets (buff, sizeof (buff), statusFile);
    String  buffStr (buff);

    nextClass0IDX = buffStr.ExtractTokenInt    (" ,\n\t");
    nextClass1IDX = buffStr.ExtractTokenInt    (" ,\n\t");
  }

  
  if  (processes)
  {
    delete  processes;
    processes = NULL;
  }

  processes = new ParameterProcessList (true);

  for  (int  processLineNum = 0;  processLineNum < numOfProcesses;  processLineNum++)
  {
    fgets (buff, sizeof (buff), statusFile);
    String  buffStr (buff);
    processes->PushOnBack (new ParameterProcess (log, imageClasses, buffStr));
  }

  fclose (statusFile);
  statusFile = NULL;
  return;
}  /* LoadCurrentStatusFile */
Beispiel #8
0
//-----------------------------------------------------------------------------
// TemplateFileParsor::ParsePrintData
//-----------------------------------------------------------------------------
void TemplateFileParsor::ParsePrintData(String *pstrLine, int iLine)
{
  pstrLine->Trim();
  String strToPrint;
  int iRc = pstrLine->ExtractToken('"', '"', &strToPrint);

  CTemplateProcessor VarProc(CTemplateProcessor::EMPTY_STRING);
  if( m_pVarEval )
    VarProc.AddEvaluator(m_pVarEval);
  CEnvVariableEvaluator EnvVar;
  VarProc.AddEvaluator(&EnvVar);

  // Variable substitution in quoted strings !!
  VarProc.Process(&strToPrint);

  uint uiPos = 0;
  // looking for new line characters.
  for( uiPos = strToPrint.find("\\n"); uiPos != String::npos; uiPos = strToPrint.find("\\n"))
    strToPrint.replace(uiPos, 2, "\n");

  // looking for carriage return characters.
  for( uiPos = strToPrint.find("\\r"); uiPos != String::npos; uiPos = strToPrint.find("\\r"))
    strToPrint.replace(uiPos, 2, "\r");

  // looking for tab characters.
  for( uiPos = strToPrint.find("\\t"); uiPos != String::npos; uiPos = strToPrint.find("\\t"))
    strToPrint.replace(uiPos, 2, "\t");

  if( 1 == iRc )
  {
    while( !strToPrint.empty() )
    {
      String strTxt, strTmp;
      // Search for next format directive
      bool bParse = true;
      while( bParse )
      {
        iRc = strToPrint.ExtractToken('%', &strTmp);
        // Skip directive indicator if it's a '%%' pair
        if( strToPrint.StartWith('%') )
        {
          strTmp += '%';
          strToPrint.erase(0, 1);
        }
        else
          bParse = false;
        strTxt += strTmp;
      }

      if( !strTxt.empty() )
      {
        // Text to print before format directive
        TemplateTokenPtr ptrToken(new TemplateToken);
        ptrToken->m_iTemplateLine = iLine;
        ptrToken->m_TokenType = TemplateToken::PRINT_TEXT;
        ptrToken->m_strData = strTxt;
        ptrToken->m_Format.Set("%s");
        m_vecToken.push_back(ptrToken);
      }

      if( 1 == iRc )
      {
        // A format directive was found
        SuppressComments(pstrLine);
        String strArgument;
        int iRc2 = pstrLine->ExtractToken(',', &strArgument);
        if( 0 == iRc2 )
        {
          cerr << "Error: Argument missing at line " << iLine << " in file " << m_strCurrentTemplateFile << "." << endl;
          exit(1);
        }
        // Remove blanks
        strArgument.Trim();

        // Check argument type
        if( strArgument.Match("[nxs:*<*>]*") )
        {
          // This is a array type argument
          // Erase '[' and ']' enclosers
          strArgument.erase(0, 1); // '['
          uint uiMatchingPos = strArgument.find(']');
          strArgument.erase(uiMatchingPos, 1); // ']'

          // Insert a loop/end-loop couple
          TemplateTokenPtr ptrLoopToken(new TemplateToken);
          ptrLoopToken->m_iTemplateLine = iLine;
          ptrLoopToken->m_TokenType = TemplateToken::LOOP_OVER;
          ptrLoopToken->m_strParam1 = "loopvar";

          // Extract loop part of the argument
          String strLastPart;
          int iLastPart = strArgument.rfind('>');
          strLastPart = strArgument.substr(iLastPart+1);
          ptrLoopToken->m_strParam2 = strArgument.substr(0, iLastPart+1);
          ptrLoopToken->m_iEndBlockPos = m_vecToken.size() + 1;
          // Add 'loop' Token
          m_vecToken.push_back(ptrLoopToken);

          // Replace loop element with variable access
          String strTmp;
          strArgument.ExtractTokenRight('<', '>', &strTmp);
          strArgument += "$(loopvar_name)" + strLastPart;
        }
        else if( strArgument.Match("*[$(*)]*") )
        {
          uint uiMatchingPos = strArgument.find("[$(");
          uint uiLastPos = strArgument.find("]", uiMatchingPos);
          String strBeforePattern = strArgument.substr(0, uiMatchingPos);
          String strAfterPattern = strArgument.substr(uiLastPos + 1);
          String strMatchedPattern = strArgument.substr(uiMatchingPos + 1, uiLastPos - uiMatchingPos - 1);

          // Insert a loop/end-loop couple
          TemplateTokenPtr ptrLoopToken(new TemplateToken);
          ptrLoopToken->m_iTemplateLine = iLine;
          ptrLoopToken->m_TokenType = TemplateToken::LOOP_OVER;
          ptrLoopToken->m_strParam1 = "loopvar";

          ptrLoopToken->m_strParam2 = strMatchedPattern;
          ptrLoopToken->m_iEndBlockPos = m_vecToken.size() + 1;
          // Add 'loop' Token
          m_vecToken.push_back(ptrLoopToken);
          // Rebuild argument for next token (inside loop)
          strArgument = strBeforePattern + "$(loopvar_name)" + strAfterPattern;
        }

        TemplateTokenPtr ptrToken(new TemplateToken);
        ptrToken->m_iTemplateLine = iLine;
        ptrToken->m_TokenType = TemplateToken::PRINT_DATA;

        if( false == BuildDataFragments(ptrToken.ObjectPtr(), strArgument) )
          // If no variable are presents in the argument string then fill strData member
          ptrToken->m_strData = strArgument;
        
        // Extend format string up to next format directive
        int iPos = strToPrint.find('%');
        // Parse format
        ptrToken->m_Format.Set('%' + strToPrint.substr(0, iPos));
        // Search for format type in first 10 characters
        DataBuf::Type eType = GetTypeFromFormat(ptrToken->m_Format.Type(), ptrToken->m_Format.Modifier());
        if( DataBuf::NO_TYPE == eType )
        {
          cerr << "Error: Bad type specification at line " << iLine << " in file " << m_strCurrentTemplateFile << "." << endl;
          exit(1);
        }
        ptrToken->m_eOutputType = eType;
        ptrToken->m_strPrintFmt = ptrToken->m_Format.Get();

        m_vecToken.push_back(ptrToken);
        strToPrint.erase(0, iPos);
      }
    }
  }
  else
  {
    cerr << "Error: Missed '\"' at line " << iLine << " in file " << m_strCurrentTemplateFile << "." << endl;
    exit(1);
  }
}