Exemplo n.º 1
0
void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel,
                                     bool MunchSemi) {
  assert(FormatTok->Tok.is(tok::l_brace) && "'{' expected");
  unsigned InitialLevel = Line->Level;
  nextToken();

  addUnwrappedLine();

  ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
                                          MustBeDeclaration);
  if (AddLevel)
    ++Line->Level;
  parseLevel(/*HasOpeningBrace=*/true);

  if (!FormatTok->Tok.is(tok::r_brace)) {
    Line->Level = InitialLevel;
    StructuralError = true;
    return;
  }

  nextToken(); // Munch the closing brace.
  if (MunchSemi && FormatTok->Tok.is(tok::semi))
    nextToken();
  Line->Level = InitialLevel;
}
Exemplo n.º 2
0
void UnwrappedLineParser::parseParens() {
  assert(FormatTok->Tok.is(tok::l_paren) && "'(' expected.");
  nextToken();
  do {
    switch (FormatTok->Tok.getKind()) {
    case tok::l_paren:
      parseParens();
      break;
    case tok::r_paren:
      nextToken();
      return;
    case tok::l_brace: {
      if (!tryToParseBracedList()) {
        nextToken();
        ScopedLineState LineState(*this);
        ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
                                                /*MustBeDeclaration=*/ false);
        Line->Level += 1;
        parseLevel(/*HasOpeningBrace=*/ true);
        Line->Level -= 1;
      }
      break;
    }
    case tok::at:
      nextToken();
      if (FormatTok->Tok.is(tok::l_brace))
        parseBracedList();
      break;
    default:
      nextToken();
      break;
    }
  } while (!eof());
}
Exemplo n.º 3
0
void UnwrappedLineParser::parseFile() {
  ScopedDeclarationState DeclarationState(
      *Line, DeclarationScopeStack,
      /*MustBeDeclaration=*/ !Line->InPPDirective);
  parseLevel(/*HasOpeningBrace=*/false);
  // Make sure to format the remaining tokens.
  flushComments(true);
  addUnwrappedLine();
}
Exemplo n.º 4
0
bool Paper::initFromFile(File& dataFile) {
    //Line 1: name
    if (dataFile.available()) {
        name = readLine(dataFile);
    }
    String line;
    //Line 2: Max/focus brightness
    line = readLine(dataFile);
    int delim = line.indexOf(',');
    maxBrightnessSoft = parseLevel(line.substring(0, delim));
    maxBrightnessHard = parseLevel(line.substring(delim + 1));
    
    //Line 3: Min Grade
    minGrade = parseLevel(readLine(dataFile));
    //Line 4: Max Grade
    maxGrade = parseLevel(readLine(dataFile));

    //Line 5+: Brightness pairs
    for (int pos = 0; pos < GRADES; pos++) {
        line = readLine(dataFile);

        int delim = line.indexOf(',');
        amountsSoft[pos] = parseLevel(line.substring(0, delim));
        amountsHard[pos] = parseLevel(line.substring(delim + 1));
    }
    
    return true;
}
Exemplo n.º 5
0
void UnwrappedLineParser::parseChildBlock() {
  FormatTok->BlockKind = BK_Block;
  nextToken();
  {
    ScopedLineState LineState(*this);
    ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
                                            /*MustBeDeclaration=*/false);
    Line->Level += 1;
    parseLevel(/*HasOpeningBrace=*/true);
    Line->Level -= 1;
  }
  nextToken();
}
Exemplo n.º 6
0
void UnwrappedLineParser::parseChildBlock() {
  FormatTok->BlockKind = BK_Block;
  nextToken();
  {
    bool GoogScope =
        Style.Language == FormatStyle::LK_JavaScript && IsGoogScope(*Line);
    ScopedLineState LineState(*this);
    ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
                                            /*MustBeDeclaration=*/false);
    Line->Level += GoogScope ? 0 : 1;
    parseLevel(/*HasOpeningBrace=*/true);
    Line->Level -= GoogScope ? 0 : 1;
  }
  nextToken();
}
void
LoggerFactory::setSeverityLevelsImpl(const std::string& config)
{
  std::stringstream ss(config);
  std::string configModule;
  while (std::getline(ss, configModule, ':')) {
    size_t ind = configModule.find('=');
    if (ind == std::string::npos)
      BOOST_THROW_EXCEPTION(std::invalid_argument("wrong log configuration"));

    std::string moduleName = configModule.substr(0, ind);
    LogLevel level = parseLevel(configModule.substr(ind+1));

    this->setSeverityLevelImpl(moduleName, level);
  }
}
Exemplo n.º 8
0
LogLevel
LoggerFactory::extractLevel(const ConfigSection& item, const std::string& key)
{
  std::string levelString;
  try {
    levelString = item.get_value<std::string>();
  }
  catch (const boost::property_tree::ptree_error& error) {
  }

  if (levelString.empty()) {
    BOOST_THROW_EXCEPTION(LoggerFactory::Error("No logging level found for option \"" + key + "\""));
  }

  return parseLevel(levelString);
}
Exemplo n.º 9
0
bool UnwrappedLineParser::parseBlock(unsigned AddLevels) {
  assert(FormatTok.Tok.is(tok::l_brace) && "'{' expected");
  nextToken();

  addUnwrappedLine();

  Line.Level += AddLevels;
  parseLevel();
  Line.Level -= AddLevels;

  // FIXME: Add error handling.
  if (!FormatTok.Tok.is(tok::r_brace))
    return true;

  nextToken();
  if (FormatTok.Tok.is(tok::semi))
    nextToken();
  return false;
}
Exemplo n.º 10
0
void UnwrappedLineParser::parseBlock(bool MustBeDeclaration,
                                     unsigned AddLevels) {
  assert(FormatTok->Tok.is(tok::l_brace) && "'{' expected");
  nextToken();

  addUnwrappedLine();

  ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
                                          MustBeDeclaration);
  Line->Level += AddLevels;
  parseLevel(/*HasOpeningBrace=*/ true);

  if (!FormatTok->Tok.is(tok::r_brace)) {
    Line->Level -= AddLevels;
    StructuralError = true;
    return;
  }

  nextToken(); // Munch the closing brace.
  Line->Level -= AddLevels;
}
Exemplo n.º 11
0
void LevelModel::initFromXML (const QString & aXmlContent)
{
    QXmlStreamReader reader(aXmlContent);
    while (!reader.atEnd()) {
        reader.readNext();
        if (reader.isStartDocument()) {
            continue;
        } else if (reader.isStartElement()) {
            if (reader.name() == "database") {
                continue;
            } else if (reader.name() == "game") {
                continue;
            } else if (reader.name() == "level") {
                _levels.push_back(parseLevel(&reader));
            }
        }
    }
    if (reader.hasError()) {
        qDebug() << "LevelManager::initFromXML error " << reader.error();
    } else {
        reset();
    }
}
Exemplo n.º 12
0
void *doInput(void *details)
{
	prodcons *toProg;
	Action action;
	const size_t BUFF_INC = 1000;
	char inputBuffer[BUFF_INC], *wholeBuffer, *newline, *stripped, *theinput,
		*firstspace, *command;
	char *rest;
	int temp, xboardmode = 0, done = 0;
	size_t commandLength, currentMaxLength, currentBufferLength;


#ifdef DEBUG	
	FILE *debugFile;
	debugFile = fopen("iolog.log","w");
	setlinebuf(debugFile);
#endif
	newline = NULL;
	toProg = ((threadParameter *) details)->input;
	wholeBuffer = (char *) xmalloc(BUFF_INC);
	currentMaxLength = BUFF_INC;
	while (done == 0) {
		currentBufferLength = 0;
		memset((void *) wholeBuffer, '\0', currentMaxLength);
		do {
			if (fgets(inputBuffer, BUFF_INC, stdin) == NULL) {
				done = -1;
				break;
			}
			currentBufferLength += BUFF_INC;
			if (currentBufferLength > currentMaxLength) {
				wholeBuffer = (char *) xrealloc((void *) wholeBuffer, currentBufferLength);
				currentMaxLength = currentBufferLength;
			}
			wholeBuffer = strcat(wholeBuffer, inputBuffer);
			newline = strchr(wholeBuffer, '\n');
		} while (newline == NULL);

		if (newline == NULL) {
			fprintf(stderr, "Error reading from input\n");
			continue;
		}
		*newline = '\0';
#ifdef DEBUG		
		fprintf(debugFile,"%s\n",wholeBuffer);
#endif
		stripped = strip(wholeBuffer);
		action.command = xstrdup(stripped);
		theinput = uppercase(stripped);
		free(stripped);
		if ((theinput != NULL) && (strlen(theinput) > 0)) {
			firstspace = strchr(theinput, ' ');
			if (firstspace == NULL) {
				commandLength = strlen(theinput);
				rest = NULL;
			} else {
				commandLength = firstspace - theinput;
				rest = xstrdup(firstspace + 1);
			}
			/* if (rest != NULL) {
			 * printf("rest: %s\n",rest);
			 * } */
			command = (char *) xmalloc(commandLength + 1);
			memcpy(command, theinput, commandLength);
			command[commandLength] = '\0';

			if (strcmp(command, "USERMOVE") == 0) {
				action.theType = USERMOVE;
				if (parseMove(rest, &action.data.move) < 0) {
					action.data.move.from = -1;
				}
				putAction(toProg, &action);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}

			if ((strcmp(command, "SP_SANMOVE") == 0) || 
			((!xboardmode) && (strcmp(command, "SANMOVE") == 0))) {
				action.theType = SP_SANMOVE;
				action.data.message = (char *) xstrdup(action.command + commandLength + 1);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}

			if (strcmp(command, "XBOARD") == 0) {
				xboardmode = 1;
				action.theType = XBOARD;
				putAction(toProg, &action);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}
			if (strcmp(command, "PROTOVER") == 0) {
				action.theType = PROTOVER;
				action.data.message = rest;
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "ACCEPTED") == 0) {
				action.theType = ACCEPTED;
				action.data.feature = stringToFeature(rest);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}

				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "REJECTED") == 0) {
				action.theType = REJECTED;
				action.data.feature = stringToFeature(rest);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}

				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "NEW") == 0) {
				action.theType = NEW;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}

				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "VARIANT") == 0) {
				action.theType = VARIANT;
				action.data.message = rest;
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "QUIT") == 0) {
				action.theType = QUIT;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}

				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "RANDOM") == 0) {
				action.theType = RANDOM;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "FORCE") == 0) {
				action.theType = FORCE;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}

				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "GO") == 0) {
				action.theType = GO;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "PLAYOTHER") == 0) {
				action.theType = PLAYOTHER;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "WHITE") == 0) {
				action.theType = WHITE;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "BLACK") == 0) {
				action.theType = BLACK;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "LEVEL") == 0) {
				action.theType = LEVEL;
				if (parseLevel(rest, &action.data.timecontrol) == 0) {
					putAction(toProg, &action);
				}
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}
			if (strcmp(command, "SD") == 0) {
				action.theType = SD;
				action.data.depth = parseInteger(rest);
				putAction(toProg, &action);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}
			if (strcmp(command, "ST") == 0) {
				action.theType = ST;
				action.data.time = parseInteger(rest) * 100;
				putAction(toProg, &action);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}
			if (strcmp(command, "TIME") == 0) {
				action.theType = TIME;
				action.data.time = parseInteger(rest);
				putAction(toProg, &action);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}
			if (strcmp(command, "OTIM") == 0) {
				action.theType = OTIM;
				action.data.time = parseInteger(rest);
				putAction(toProg, &action);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}
			if (strcmp(command, "?") == 0) {
				action.theType = MOVENOW;
				putAction(toProg, &action);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}
			if (strcmp(command, "PING") == 0) {
				action.theType = PING;
				action.data.time = parseInteger(rest);
				putAction(toProg, &action);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}
			if (strcmp(command, "DRAW") == 0) {
				action.theType = DRAW;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "RESULT") == 0) {
				action.theType = RESULT;
				if (parseResult(rest, &action.data.result) == 0) {
					putAction(toProg, &action);
				}
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}
			if (strcmp(command, "SETBOARD") == 0) {
				action.theType = SETBOARD;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				action.data.message =
					(char *) xstrdup(action.command + commandLength + 1);
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "EDIT") == 0) {
				action.theType = EDIT;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "HINT") == 0) {
				action.theType = HINT;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "BK") == 0) {
				action.theType = BK;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "UNDO") == 0) {
				action.theType = UNDO;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "REMOVE") == 0) {
				action.theType = REMOVE;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "HARD") == 0) {
				action.theType = HARD;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "EASY") == 0) {
				action.theType = EASY;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "POST") == 0) {
				action.theType = POST;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "NOPOST") == 0) {
				action.theType = NOPOST;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "EXIT") == 0) {
				action.theType = EXIT;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}

			if (strcmp(command, "ANALYZE") == 0) {
				action.theType = ANALYZE;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}

			if (strcmp(command, ".") == 0) {
				action.theType = UPDATESTATUS;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}

			if (strcmp(command, "NAME") == 0) {
				action.theType = NAME;
				action.data.message = rest;
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "RATING") == 0) {
				action.theType = RATING;
				temp = parseRatings(rest, &action.data.ratings);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				if (temp == 0) {
					putAction(toProg, &action);
				} else {
					free(action.command);
				}
				goto ENDPARSE;
			}
			if (strcmp(command, "ICS") == 0) {
				action.theType = ICS;
				action.data.message = rest;
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if (strcmp(command, "COMPUTER") == 0) {
				action.theType = COMPUTER;
				putAction(toProg, &action);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}
			if ((strcmp(command, "SP_DEBUG") == 0) || 
			((!xboardmode) && (strcmp(command, "DEBUG") == 0))){
				action.theType = DEBUG;
				action.data.message = rest;
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			if ((strcmp(command, "SP_MOVETOSAN") == 0) || 
			((!xboardmode) && (strcmp(command, "MOVETOSAN") == 0))){
				action.theType = SP_MOVETOSAN;
				if (parseMove(rest, &action.data.move) < 0) {
					action.data.move.from = -1;
				}
				putAction(toProg, &action);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}

			if ((strcmp(command, "SP_BENCHMOVEUNMOVE") == 0) || 
			((!xboardmode) && (strcmp(command, "BENCHMOVEUNMOVE") == 0)))  {
				action.theType = SP_BENCHMOVEUNMOVE;
				if (parseMove(rest, &action.data.move) < 0) {
					action.data.move.from = -1;
				}
				putAction(toProg, &action);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}

			if ((strcmp(command, "SP_BENCHMOVEGEN") == 0) || 
			((!xboardmode) && (strcmp(command, "BENCHMOVEGEN") == 0))){
				action.theType = SP_BENCHMOVEGEN;
				action.data.time = parseInteger(rest);				
				putAction(toProg, &action);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}

			if ((strcmp(command, "SP_BENCHMOVECYCLE") == 0) || 
			((!xboardmode) && (strcmp(command, "BENCHMOVECYCLE") == 0))) {
				action.theType = SP_BENCHMOVECYCLE;
				action.data.time = parseInteger(rest);				
				putAction(toProg, &action);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}

			if ((strcmp(command, "SP_BENCHEVAL") == 0) || 
			((!xboardmode) && (strcmp(command, "BENCHEVAL") == 0))) {
				action.theType = SP_BENCHEVAL;
				action.data.time = parseInteger(rest);				
				putAction(toProg, &action);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}



			if ((strcmp(command, "SP_PERFT") == 0) || 
			((!xboardmode) && (strcmp(command, "PERFT") == 0))) {
				action.theType = SP_PERFT;
				action.data.depth = parseInteger(rest);				
				putAction(toProg, &action);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}

			if ((strcmp(command, "SP_EPDSUITE") == 0) || 
			((!xboardmode) && (strcmp(command, "EPDSUITE") == 0))) {
				action.theType = SP_EPDSUITE;
				action.data.message = (char *) xstrdup(action.command  + commandLength + 1);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}				
				putAction(toProg, &action);
				goto ENDPARSE;
			}

			if ((strcmp(command, "SP_EPDLINE") == 0) || 
			((!xboardmode) && (strcmp(command, "EPDLINE") == 0))) {
				action.theType = SP_EPDLINE;
				action.data.message = (char *) xstrdup(action.command  + commandLength + 1);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}				
				putAction(toProg, &action);
				goto ENDPARSE;
			}

			if ((strcmp(command, "SP_MODIFYBOOK") == 0) || 
			((!xboardmode) && (strcmp(command, "MODIFYBOOK") == 0))) {
				action.theType = SP_MODIFYBOOK;
				action.data.message = (char *) xstrdup(action.command  + commandLength + 1);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}				
				putAction(toProg, &action);
				goto ENDPARSE;
			}
			
			if ((strcmp(command, "SP_CLOSEBOOK") == 0) || 
			((!xboardmode) && (strcmp(command, "CLOSEBOOK") == 0))) {
				action.theType = SP_CLOSEBOOK;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}

			if ((strcmp(command, "SP_SHOWMOVES") == 0) || 
			((!xboardmode) && (strcmp(command, "SHOWMOVES") == 0))) {
				action.theType = SP_SHOWMOVES;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}

			if ((strcmp(command, "SP_EVALUATE") == 0) || 
			((!xboardmode) && (strcmp(command, "EVALUATE") == 0))) {
				action.theType = SP_EVALUATE;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}

			if (strcmp(command, "HELP") == 0) {
				action.theType = HELP;
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				putAction(toProg, &action);
				goto ENDPARSE;
			}

			if ((strcmp(command, "SP_EPDMINDEPTH") == 0) || 
			((!xboardmode) && (strcmp(command, "EPDMINDEPTH") == 0))) {
				action.theType = SP_EPDMINDEPTH;
				action.data.depth = parseInteger(rest);				
				putAction(toProg, &action);
				if (rest != NULL) {
					free(rest);
					rest = NULL;
				}
				goto ENDPARSE;
			}


			action.theType = UNKNOWN_COMMAND;
			if (rest != NULL) {
				free(rest);
				rest = NULL;
			}
			putAction(toProg, &action);
			

		 ENDPARSE:;
		}
		free(theinput);
		theinput = NULL;
	}
	free(wholeBuffer);
#ifdef DEBUG		
	fclose(debugFile);  
#endif
	return NULL;
}
Exemplo n.º 13
0
void Logger::setLevel(const std::string& level)
{
	setLevel(parseLevel(level));
}
Exemplo n.º 14
0
  static bool eval(int argc, char **argv) {
    static const MeCab::Option long_options[] = {
      { "level",  'l',  "0 -1",    "STR",    "set level of evaluations" },
      { "output", 'o',  0,         "FILE",   "set the output file name" },
      { "version",  'v',  0,   0,    "show the version and exit"   },
      { "help",  'h',  0,   0,    "show this help and exit."   },
      { 0, 0, 0, 0 }
    };

    MeCab::Param param;
    param.open(argc, argv, long_options);

    if (!param.open(argc, argv, long_options)) {
      std::cout << param.what() << "\n\n" <<  COPYRIGHT
                << "\ntry '--help' for more information." << std::endl;
      return -1;
    }

    if (!param.help_version()) return 0;

    const std::vector<std::string> &files = param.rest_args();
    if (files.size() < 2) {
      std::cout << "Usage: " <<
          param.program_name() << " output answer" << std::endl;
      return -1;
    }

    std::string output = param.get<std::string>("output");
    if (output.empty()) output = "-";
    MeCab::ostream_wrapper ofs(output.c_str());
    CHECK_DIE(*ofs) << "no such file or directory: " << output;

    const std::string system = files[0];
    const std::string answer = files[1];

    const std::string level_str = param.get<std::string>("level");

    std::ifstream ifs1(files[0].c_str());
    std::ifstream ifs2(files[1].c_str());

    CHECK_DIE(ifs1) << "no such file or directory: " << files[0].c_str();
    CHECK_DIE(ifs2) << "no such file or directory: " << files[0].c_str();
    CHECK_DIE(!level_str.empty()) << "level_str is NULL";

    std::vector<int> level;
    parseLevel(level_str.c_str(), &level);
    CHECK_DIE(level.size()) << "level_str is empty: " << level_str;
    std::vector<size_t> result_tbl(level.size());
    std::fill(result_tbl.begin(), result_tbl.end(), 0);

    size_t prec = 0;
    size_t recall = 0;

    std::vector<std::vector<std::string> > r1;
    std::vector<std::vector<std::string> > r2;

    while (true) {
      if (!read(&ifs1, &r1, level) || !read(&ifs2, &r2, level))
        break;

      size_t i1 = 0;
      size_t i2 = 0;
      size_t p1 = 0;
      size_t p2 = 0;

      while (i1 < r1.size() && i2 < r2.size()) {
        if (p1 == p2) {
          for (size_t i = 0; i < result_tbl.size(); ++i) {
            if (r1[i1][i] == r2[i2][i]) {
              result_tbl[i]++;
            }
          }
          p1 += r1[i1][0].size();
          p2 += r2[i2][0].size();
          ++i1;
          ++i2;
          ++prec;
          ++recall;
        } else if (p1 < p2) {
          p1 += r1[i1][0].size();
          ++i1;
          ++prec;
        } else {
          p2 += r2[i2][0].size();
          ++i2;
          ++recall;
        }
      }

      while (i1 < r1.size()) {
        ++prec;
        ++i1;
      }

      while (i2 < r2.size()) {
        ++recall;
        ++i2;
      }
    }

    *ofs <<  "              precision          recall         F"
         << std::endl;
    for (size_t i = 0; i < result_tbl.size(); ++i) {
      if (level[i] == -1) {
        *ofs << "LEVEL ALL: ";
      } else {
        *ofs << "LEVEL " << level[i] << ":    ";
      }
      printeval(&*ofs, result_tbl[i], prec, recall);
    }

    return true;
  }
Exemplo n.º 15
0
bool UnwrappedLineParser::parse() {
  FormatTok = Tokens.getNextToken();
  return parseLevel();
}
Exemplo n.º 16
0
bool UnwrappedLineParser::parseFile() {
  bool Error = parseLevel();
  // Make sure to format the remaining tokens.
  addUnwrappedLine();
  return Error;
}