Пример #1
0
/**
Parses through text.
Calls processComment when the opening of a comment is detected.

@return 100 if the input is empty, 101 if a comment is not terminated, 0 otherwise.
*/
int main(){
  char c = getchar();
  if (c == EOF){
    printf("Empty input\n");
    return BAD_RETURN;
  }
  totalChars++;
  while (c != EOF){
    if (c == '/'){
      c = getchar();
      totalChars++;
        if (c == '*'){
          int comm = processComment();
          if (comm == 0){
            printf("Unterminated comment\n");
            return BAD_RETURN + 1;
          }
        }
    }
    c = getchar();
    if (c != EOF){
      totalChars++;
    }
  }
  
  printf("Input characters: %d", totalChars);
  printf("\nComments: %d (%.2lf%%)\n", commentCount,
    ((double)commentChars/(double)totalChars)*PERCENTS_DOUBLE);

  return 0;
}
Пример #2
0
/**
   Starting point for the program, holds main cycle for reading characters in the file
   and code to pass to processComment if a comment is found. Prints information about the
   file to standard output.
 */
int main()
{  
  current = getchar();
  
  //Returns Error if file has no input
  if(current == EOF){
    printf("Empty input\n");
    exit(100);
  }
  
  //Continually read characters from file  
  while(current != EOF){
    last = current;
    current = getchar();
    totalChars++;
    
    //Sends to process comment if a comment is opened
    if(last == 47 && current == 42){
      processComment();
    }
  }
  
  //Variable for the percentage of characters that are comment characters
  double percentage = (double) commentChars / (double) totalChars * 100;
  
  //The printed output
  printf("Input characters: %d\n", totalChars);
  printf("Comments: %d (%.2f%)\n", commentCount, percentage);
  
  //Successful return
  exit(0);
}
void ActivationSequenceContextProcessor::process()
{
    goBackToStartOfName();
    processActivationSequence();

    if (m_completionKind != CPlusPlus::T_EOF_SYMBOL) {
        processStringLiteral();
        processComma();
        generateTokens();
        processDoxygenComment();
        processComment();
        processInclude();
        processSlashOutsideOfAString();
        processLeftParen();
        processPreprocessorInclude();
    }

    resetPositionsForEOFCompletionKind();
}
Пример #4
0
void Templateiser::processTemplate ( std::string &code, const std::string &templateText )
{
  std::string::const_iterator templateItr = templateText.begin();

  while ( templateItr != templateText.end() ) {
    if ( *templateItr != '[' ) {
      code += *templateItr;
      templateItr++;
    } else {
      templateItr++;

      if (templateItr == templateText.end()) {
	code += '[';
      } else {
	switch(*templateItr) {
	default: // it's not a code, so just let the next loop hit it and output it
	  break;

	case '$':
	  replaceVar(code,++templateItr,templateText);
	  break;

	case '*':
	  processLoop(code,++templateItr,templateText);
	  break;

	case '?':
	  processIF(code,++templateItr,templateText);
	  break;
	case '-':
	case '#': // treat metadata as comments when parsing
	  processComment(code,++templateItr,templateText);
	  break;
	case '!':
	  processInclude(code,++templateItr,templateText);
	  break;
	}
      }
    }
  }
}
Пример #5
0
bool Parser::ignorarChars()
{
    bool bFindChar = false;
    char cRead;

    do {
        if(m_fileEscena.get(cRead)) { // No estamos al final del archivo si pasamos de aqui.
			switch(cRead) {
				// Ignoramos saltos de linea, espacios y tabuladores.
                case '\n': m_nLine++;
                case '\r':
                case ' ':
                case '\t':
                    break;
                case '<': 
					// Encontrado inicio de etiqueta. Devolvermos el control
					// si no es un comentario.
					if(isComment()) {
						if(!processComment())
							return false;
					}
					else {
						bFindChar = true;
					}
                    break;
                default: // Caracter erroneo o no esperado.
					m_nError = 8;
                    return false;
                    break;
            }
        }
        else { // Fin de archivo.
            m_nError = 1;
            m_bEOF = true;
            return false;
        }
    }
    while(!bFindChar);
    return true;
}
Пример #6
0
void IniReader::readFile()
{
	std::fstream fh( m_fileName.c_str(), std::ios::in );

	CHECK( fh.is_open(), "INI file '%s' does not exist!", m_fileName.c_str() );

	char line[128];
	std::string currSection = "";

	while( !fh.eof() )
	{
		fh.getline( line, sizeof(line) );

		std::string str = line;

		if ( processComment(str) ) continue;		
		else if ( processSection(str, currSection) ) continue;
		else if ( processDataRow(str, currSection) ) continue;
	}

	fh.close();
}
Пример #7
0
void XMLTreeBuilder::processToken(const AtomicXMLToken& token)
{
    switch (token.type()) {
    case XMLTokenTypes::Uninitialized:
        ASSERT_NOT_REACHED();
        break;
    case XMLTokenTypes::ProcessingInstruction:
        processProcessingInstruction(token);
        break;
    case XMLTokenTypes::XMLDeclaration:
        processXMLDeclaration(token);
        break;
    case XMLTokenTypes::DOCTYPE:
        processDOCTYPE(token);
        break;
    case XMLTokenTypes::StartTag:
        processStartTag(token);
        break;
    case XMLTokenTypes::EndTag:
        processEndTag(token);
        break;
    case XMLTokenTypes::CDATA:
        processCDATA(token);
        break;
    case XMLTokenTypes::Character:
        processCharacter(token);
        break;
    case XMLTokenTypes::Comment:
        processComment(token);
        break;
    case XMLTokenTypes::Entity:
        processEntity(token);
        break;
    case XMLTokenTypes::EndOfFile:
        exitText();
        return;
    }
}