Logo Search packages:      
Sourcecode: qtoctave version File versions  Download package

bool GenerateMenu::process_menu_file ( QString  _file,
QStringList &  input_labels,
QStringList &  input_parameters,
QStringList &  output_labels,
QStringList &  output_parameters,
QString &  command,
QString &  menu_name,
QString &  help,
bool &  accept_blank_parameters 
) [private]

Parse files with .menu extension.

Definition at line 107 of file generate_menu.cpp.

{
      QFile file(_file);
      if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return false;
      
      accept_blank_parameters=false;
      
      ParseState state=PARAMETER;
      QString block_label;
      
      //Regular expession for parameters
      QRegExp rp("([A-Za-z_]+)[ \\t]*=(.*)\\n");
      //Regular expession for comments
      QRegExp rc("[ \\t]*#.*\\n");
      //Regular expession for blocks -> start
      QRegExp rbb("begin\\{([A-Za-z_]+)\\}\\n");
      //Regular expession for blocks -> end
      QRegExp rbe("end\\{([A-Za-z_]+)\\}\\n");
      
      while (!file.atEnd())
      {
            QString line(file.readLine());
            
            //printf("Estado %d Linea: %s", state, line.toLocal8Bit().data());
            
            switch(state)
            {
                  case PARAMETER:
                        if(!rp.exactMatch(line) && !rc.exactMatch(line) && !rbb.exactMatch(line) && !rbe.exactMatch(line)) continue;
                        
                        /*
                        {
                              int pos;
                              pos=rp.indexIn(line);
                              QStringList list = rp.capturedTexts();
                              for(int i=0;i<list.size();i++)
                                    printf("%d %s\n", i, list.at(i).toLocal8Bit().data() );
                        }
                        
                        {
                              int pos;
                              pos=rbb.indexIn(line);
                              QStringList list = rbb.capturedTexts();
                              for(int i=0;i<list.size();i++)
                                    printf("%d %s\n", i, list.at(i).toLocal8Bit().data() );
                        }
                        */
                        
                        //Matchs parameter
                        if(rp.exactMatch(line))
                        {
                              QString type = rp.cap(1);
                              
                              if(type=="input")
                              {
                                    input_parameters << rp.cap(2).trimmed();
                              }
                              if(type=="input_label")
                              {
                                    input_labels << rp.cap(2).trimmed();
                              }
                              else if(type=="output")
                              {
                                    output_parameters << rp.cap(2).trimmed();
                              }
                              if(type=="output_label")
                              {
                                    output_labels << rp.cap(2).trimmed();
                              }
                              else if(type=="menu_name")
                              {
                                    menu_name = rp.cap(2).trimmed();
                              }
                              else if(type=="accept_blank_parameters")
                              {
                                    if (rp.cap(2).trimmed()=="true") accept_blank_parameters=true;
                              }
                        }
                        else if(rbb.exactMatch(line)) {block_label=rbb.cap(1);state=BLOCK;}
                        else if(rbe.exactMatch(line)) state=PARAMETER;
                        //Comments are ignored.
                  break;
                  
                  case BLOCK:
                        if(rbe.exactMatch(line) && block_label==rbe.cap(1)) state=PARAMETER;
                        else if(block_label=="help") help+=line;
                        else if(block_label=="command") command+=line;
                  break;
            }
      }
      
      file.close();
      
      if(input_parameters.size()!=input_labels.size())
      {
            printf("Error in %s\n", _file.toLocal8Bit().data());
            printf("input must have same size than input_labels\n");
            return false;
      }
      
      if(output_parameters.size()!=output_labels.size())
      {
            printf("Error in %s\n", _file.toLocal8Bit().data());
            printf("output must have same size than output_parameters\n");
            return false;
      }
      
      return true;
}


Generated by  Doxygen 1.6.0   Back to index