예제 #1
0
Path MapManager::match(int gridId1, int gridId2) {
    if (gridId1 == gridId2 || gridId1 < 0 || gridId2 < 0) {
        return Path();
    }

    Grid* g1 = getGrid(gridId1);
    Grid* g2 = getGrid(gridId2);

    if (g1 == NULL || g2 == NULL) {
        return Path();
    }

    if (g1->imageId != g2->imageId) {
        return Path();
    }

    if (matchLine(gridId1, gridId2)) {
        m_path.push_back(gridId1);
        m_path.push_back(gridId2);
        CCLog("MapManager::matchLine done");
    } else if (matchTwoLine(gridId1, gridId2)) {
        CCLog("MapManager::matchTwoLine done");
    } else if (matchThreeLine(gridId1, gridId2)) {
        CCLog("MapManager::matchThreeLine done");
    }

    return m_path;
}
예제 #2
0
void VMsgLog::editRequest( WMenuItem* )
{
    int index = _batcher->selected();
    if( index >= 0 ) {
        const char* text = *(WString*)_data[index];
        char file[101]; int line, offset; char help[51];
        if( matchLine( index, file, line, offset, help ) ) {
            WSystemHelp *sh;
            const char *hf;
            if( findHelpFile( file, &sh, 0 ) == 0 ) {
                hf = "";
            } else {
                hf = sh->getHelpFile();
            }
            WString msg;
            int resId = atoi( help ) + 1;
            WFileName filename( file );
            if( filename.needQuotes() ) {
                msg.printf( "EditFileAtPos -f\"%s\" %d %d 0 %d",
                            file, line, offset, resId );
            } else {
                msg.printf( "EditFileAtPos -f%s %d %d 0 %d",
                            file, line, offset, resId );
            }
            msg.concat( " \"" );
            msg.concat( text ); // error message
            msg.concat( "\" " );
            msg.concat( hf ); // help file
            _parent->executeCommand( msg, EXECUTE_EDITOR, "LogEdit" );
        } else {
            WMessageDialog::info( this, "Can't find a filename in '%s'", text );
        }
    }
}
예제 #3
0
bool MapManager::matchTwoLine(int gridId1, int gridId2) {
    //判断一次折线能否消除
    m_path.clear();

    Grid* g1 = this->getGrid(gridId1);
    Grid* g2 = this->getGrid(gridId2);

    if (g1 == NULL || g2 == NULL) {
        return false;
    }

    //得到矩形区域的另外两个点
    int pos = g2->col + g1->row * TOTAL_COl;
    Grid* g3 = m_grids[pos];
    if (g3->status != Grid::Empty) {
        return false;
    }
    if ( matchLine(g1->id, g3->id) && matchLine(g2->id, g3->id) ) {
        m_path.push_back(gridId1);
        m_path.push_back(g3->id);
        m_path.push_back(gridId2);
        return true;
    }

    pos = g1->col + g2->row * TOTAL_COl;
    Grid* g4 = m_grids[pos];
    if (g4->status != Grid::Empty) {
        return false;
    }
    if ( matchLine(g1->id, g4->id) && matchLine(g2->id, g4->id) ) {
        m_path.push_back(gridId1);
        m_path.push_back(g4->id);
        m_path.push_back(gridId2);
        return true;
    }

    return false;
}
예제 #4
0
// ScanForFunctions
_EXPORT
void
ScanForFunctions(CLanguageProxy& proxy)
{
	const char* text = proxy.Text();
	for(const char* pos = text; pos != NULL; ) {
		if (strncmp(pos, "--- ", 4) == 0 && !isdigit(*(pos+4))) {
			const char* displayPos = pos + 4;
				// skip to filename
			const char* lineEnd = strchr(pos, '\n');
			if (!lineEnd)
				lineEnd = pos + strlen(pos);
			const char* tabPos = strchr(pos, '\t');
			if (tabPos && tabPos < lineEnd)
				// cut line off at tab, in order to drop the date following the filename
				lineEnd = tabPos;
			BString matchLine(pos, lineEnd-pos);
			BString displayLine(displayPos, lineEnd-displayPos);
			proxy.SetNestLevel(0);
			proxy.AddFunction(displayLine.String(), matchLine.String(), pos-text, false);
		} else if (strncmp(pos, "@@", 2) == 0
			|| (strncmp(pos, "--- ", 4) == 0 && isdigit(*(pos+4)))) {
			const char* displayPos = pos + 2;
				// skip over "@@" or "--"
			const char* lineEnd = strchr(pos, '\n');
			if (!lineEnd)
				lineEnd = pos + strlen(pos);
			BString matchLine(pos, lineEnd-pos);
			BString displayLine(displayPos, lineEnd-2-displayPos);
				// -2 in order to skip back over '@@'
			proxy.SetNestLevel(1);
			proxy.AddFunction(displayLine.String(), matchLine.String(), pos-text, false);
		}
		if ((pos = strchr(pos+1, '\n')) != NULL)
			pos++;
	}
}
예제 #5
0
void VMsgLog::getState( bool& editOk, bool& helpOk )
{
    int index = _batcher->selected();
    if( index >= 0 ) {
        char file[101]; int line, offset; char help[51];
        if( matchLine( index, file, line, offset, help ) ) {
            if( strlen( file ) > 0 ) {
                editOk = TRUE;
            }
            int hcount = _helpList.count();
            if( hcount > 0 && strlen( help ) > 0 ) {
                helpOk = TRUE;
            }
        }
    }
}
예제 #6
0
void VMsgLog::helpRequest( WMenuItem* )
{
    int index = _batcher->selected();
    if( index >= 0 ) {
        char file[101];
        int line, offset;
        char help[51];
        if( matchLine( index, file, line, offset, help ) ) {
            WSystemHelp* hobj;
            int next = 0;
            while( (next = findHelpFile( file, &hobj, next )) != 0 ) {
                if( hobj->sysHelpId( atoi( help ) + hobj->getHelpOffset() ) ) {
                    return;
                }
            }
            WMessageDialog::info( this, "No help available for error %s.", help );
        }
    }
}
예제 #7
0
void Rules::load(const QString &filename)
{
    qDebug() << "Loading rules from" << filename;
    // initialize the regexps we will use
    QRegExp repoLine("create repository\\s+(\\S+)", Qt::CaseInsensitive);

    QString varRegex("[A-Za-z0-9_]+");

    QRegExp matchLine("match\\s+(.*)", Qt::CaseInsensitive);
    QRegExp matchActionLine("action\\s+(\\w+)", Qt::CaseInsensitive);
    QRegExp matchRepoLine("repository\\s+(\\S+)", Qt::CaseInsensitive);
    QRegExp matchDescLine("description\\s+(.+)$", Qt::CaseInsensitive);
    QRegExp matchRepoSubstLine("substitute repository\\s+(.+)$", Qt::CaseInsensitive);
    QRegExp matchBranchLine("branch\\s+(\\S+)", Qt::CaseInsensitive);
    QRegExp matchBranchSubstLine("substitute branch\\s+(.+)$", Qt::CaseInsensitive);
    QRegExp matchRevLine("(min|max) revision (\\d+)", Qt::CaseInsensitive);
    QRegExp matchAnnotateLine("annotated\\s+(\\S+)", Qt::CaseInsensitive);
    QRegExp matchPrefixLine("prefix\\s+(.*)$", Qt::CaseInsensitive);
    QRegExp declareLine("declare\\s+("+varRegex+")\\s*=\\s*(\\S+)", Qt::CaseInsensitive);
    QRegExp variableLine("\\$\\{("+varRegex+")(\\|[^}$]*)?\\}", Qt::CaseInsensitive);
    QRegExp includeLine("include\\s+(.*)", Qt::CaseInsensitive);

    enum { ReadingNone, ReadingRepository, ReadingMatch } state = ReadingNone;
    Repository repo;
    Match match;
    int lineNumber = 0;

    QFile file(filename);
    if (!file.open(QIODevice::ReadOnly))
        qFatal("Could not read the rules file: %s", qPrintable(filename));

    QTextStream s(&file);
    QStringList lines = s.readAll().split('\n', QString::KeepEmptyParts);

    QStringList::iterator it;
    for(it = lines.begin(); it != lines.end(); ++it) {
        ++lineNumber;
        QString origLine = *it;
        QString line = origLine;

        int hash = line.indexOf('#');
        if (hash != -1)
            line.truncate(hash);
        line = line.trimmed();
        if (line.isEmpty())
            continue;

        bool isIncludeRule = includeLine.exactMatch(line);
        if (isIncludeRule) {
            int index = filename.lastIndexOf("/");
            QString includeFile = filename.left( index + 1) + includeLine.cap(1);
            load(includeFile);
        } else {
            while( variableLine.indexIn(line) != -1 ) {
                QString replacement;
                if (m_variables.contains(variableLine.cap(1))) {
                    replacement = m_variables[variableLine.cap(1)];
                } else {
                    if (variableLine.cap(2).startsWith('|')) {
                        replacement = variableLine.cap(2).mid(1);
                    } else {
                        qFatal("Undeclared variable: %s", qPrintable(variableLine.cap(1)));
                    }
                }
                line = line.replace(variableLine.cap(0), replacement);
            }
            if (state == ReadingRepository) {
                if (matchBranchLine.exactMatch(line)) {
                    Repository::Branch branch;
                    branch.name = matchBranchLine.cap(1);

                    repo.branches += branch;
                    continue;
                } else if (matchDescLine.exactMatch(line)) {
                    repo.description = matchDescLine.cap(1);
                    continue;
                } else if (matchRepoLine.exactMatch(line)) {
                    repo.forwardTo = matchRepoLine.cap(1);
                    continue;
                } else if (matchPrefixLine.exactMatch(line)) {
                    repo.prefix = matchPrefixLine.cap(1);
                    continue;
                } else if (line == "end repository") {
                    if (!repo.forwardTo.isEmpty()
                        && !repo.description.isEmpty()) {

                        qFatal("Specifing repository and description on repository is invalid on line %d", lineNumber);
                    }

                    if (!repo.forwardTo.isEmpty()
                        && !repo.branches.isEmpty()) {

                        qFatal("Specifing repository and branches on repository is invalid on line %d", lineNumber);
                    }

                    m_repositories += repo;
                    {
                        // clear out 'repo'
                        Repository temp;
                        std::swap(repo, temp);
                    }
                    state = ReadingNone;
                    continue;
                }
            } else if (state == ReadingMatch) {
                if (matchRepoLine.exactMatch(line)) {
                    match.repository = matchRepoLine.cap(1);
                    continue;
                } else if (matchBranchLine.exactMatch(line)) {
                    match.branch = matchBranchLine.cap(1);
                    continue;
                } else if (matchRepoSubstLine.exactMatch(line)) {
                    Match::Substitution subst = parseSubstitution(matchRepoSubstLine.cap(1));
                    if (!subst.isValid()) {
                        qFatal("Malformed substitution in rules file: line %d: %s",
                            lineNumber, qPrintable(origLine));
                    }
                    match.repo_substs += subst;
                    continue;
                } else if (matchBranchSubstLine.exactMatch(line)) {
                    Match::Substitution subst = parseSubstitution(matchBranchSubstLine.cap(1));
                    if (!subst.isValid()) {
                        qFatal("Malformed substitution in rules file: line %d: %s",
                            lineNumber, qPrintable(origLine));
                    }
                    match.branch_substs += subst;
                    continue;
                } else if (matchRevLine.exactMatch(line)) {
                    if (matchRevLine.cap(1) == "min")
                        match.minRevision = matchRevLine.cap(2).toInt();
                    else            // must be max
                        match.maxRevision = matchRevLine.cap(2).toInt();
                    continue;
                } else if (matchPrefixLine.exactMatch(line)) {
                    match.prefix = matchPrefixLine.cap(1);
                    if( match.prefix.startsWith('/'))
                        match.prefix = match.prefix.mid(1);
                    continue;
                } else if (matchActionLine.exactMatch(line)) {
                    QString action = matchActionLine.cap(1);
                    if (action == "export")
                        match.action = Match::Export;
                    else if (action == "ignore")
                        match.action = Match::Ignore;
                    else if (action == "recurse")
                        match.action = Match::Recurse;
                    else
                        qFatal("Invalid action \"%s\" on line %d", qPrintable(action), lineNumber);
                    continue;
                } else if (matchAnnotateLine.exactMatch(line)) {
                    match.annotate = matchAnnotateLine.cap(1) == "true";
                    continue;
                } else if (line == "end match") {
                    if (!match.repository.isEmpty())
                        match.action = Match::Export;
                    m_matchRules += match;
                    Stats::instance()->addRule(match);
                    state = ReadingNone;
                    continue;
                }
            }

            bool isRepositoryRule = repoLine.exactMatch(line);
            bool isMatchRule = matchLine.exactMatch(line);
            bool isVariableRule = declareLine.exactMatch(line);

            if (isRepositoryRule) {
                // repository rule
                state = ReadingRepository;
                repo = Repository(); // clear
                repo.name = repoLine.cap(1);
                repo.lineNumber = lineNumber;
                repo.filename = filename;
            } else if (isMatchRule) {
                // match rule
                state = ReadingMatch;
                match = Match();
                match.rx = QRegExp(matchLine.cap(1), Qt::CaseSensitive, QRegExp::RegExp2);
                if( !match.rx.isValid() )
                    qFatal("Malformed regular expression '%s' in file:'%s':%d, Error: %s",
                           qPrintable(matchLine.cap(1)), qPrintable(filename), lineNumber,
                           qPrintable(match.rx.errorString()));
                match.lineNumber = lineNumber;
                match.filename = filename;
            } else if (isVariableRule) {
                QString variable = declareLine.cap(1);
                QString value = declareLine.cap(2);
                m_variables.insert(variable, value);
            } else {
                qFatal("Malformed line in rules file: line %d: %s",
                       lineNumber, qPrintable(origLine));
            }
        }
    }
}
예제 #8
0
bool StructureParser::onSyntactic (char c) {
	// Special handling for special C++ tokens which do not necessary finish a line
	// 1. private/public/protected handling
	if (c == ':') {
		if (mIncomingLine.size() == 1){
			const std::string & last (mIncomingLine.back());
			if (last == "public" || last == "private" || last == "protected"){
				// must be inside a class definition
				if (mStack.empty()) {
					fprintf (stderr, "visibility operator outside of any class definition\n");
					return false;
				}
				StackElement * element = mStack.top();
				if (element->type != StackElement::Class){
					fprintf (stderr, "visiblity operator outside of any class definition (current=%s)\n", sf::toJSON(element).c_str());
					return false;
				}
				ClassElement * celement = static_cast<ClassElement*> (element);
				Visibility v = Public;
				if (last == "public")    v = Public;
				if (last == "private")   v = Private;
				if (last == "protected") v = Protected;
				celement->currentVisibility = v;
				mIncomingLine.pop_back(); // removing this modifer
				return true;
			}
		}
	}

	// 2. Enum Values
	if ((c == ',' || c == '}') && mStack.top ()->type == StackElement::Enum){
		// when c equals '}' we also have to call matchLine to pop the enum from the stack
		// this causes the folling if (c == ',') return calls.

		size_t size = mIncomingLine.size();
		if (size == 3 && mIncomingLine[1] == "="){
			// 2.a value with (simple) initializer
			EnumElement::Value v;
			v.first  = mIncomingLine[0];
			v.second = mIncomingLine[2];
			EnumElement * e = static_cast<EnumElement*> (mStack.top());
			e->values.push_back (v);
			mIncomingLine.clear();
			if (c == ',') return true;
		} else if (size == 1){
			// 2.b plain value
			EnumElement::Value v;
			v.first = mIncomingLine[0];
			EnumElement * e = static_cast<EnumElement*> (mStack.top());
			e->values.push_back (v);
			mIncomingLine.clear();
			if (c == ',') return true;
		} else if (size == 0){
			// 3. Allowed, Empty enum ?
			if (c == ',') return true;
		} else {
			fprintf (stderr, "(Internal?) Error on parsing enum value\n");
			return false;
		}
	}

	// Finisher of one line or block
	if (c == '{' || c == '}' || c == ';'){
		bool suc = matchLine (c);
		if (!suc) return false;
		mIncomingLine.clear();
		return true;
	}

	// Just doing it into current line
	std::string s (&c, 1);
	mIncomingLine.push_back (s);
	return true;
}
예제 #9
0
파일: main.c 프로젝트: Palmr/PVCS-merge
int main (int argc, char* argv[]) {
  FILE* mergeFile;
  FILE* configFile;
  char lineBuffer[MAX_LINE_SIZE];
  char *fileA, *descA, *fileB, *descB;
  size_t fileStart, fileEnd, descStart, descEnd;
  char* runCommand;

  //Open merge file from pvcs, last argument
  if (argc > 1 && (mergeFile = fopen(argv[argc-1], "r")) != NULL) {
    //Loop through line by line looking for matches
    while (fgets(lineBuffer, MAX_LINE_SIZE, mergeFile) != NULL) {
      //Find the lines we want and get the data from them
      int lineMatch = matchLine(lineBuffer);
      if (lineMatch == 1) {
        fileStart = strpos(lineBuffer, '"', 0);
        fileEnd = strpos(lineBuffer, '"', fileStart + 1) - fileStart;
        fileA = substr(lineBuffer, fileStart + 1, fileEnd - 1);
        descStart = strpos(lineBuffer,'"',  fileEnd + fileStart + 1);
        descEnd = strpos(lineBuffer, '"', descStart + 1) - descStart;
        descA = substr(lineBuffer, descStart + 1, descEnd - 1);
      }
      else if (lineMatch == 2) {
        fileStart = strpos(lineBuffer, '"', 0);
        fileEnd = strpos(lineBuffer, '"', fileStart + 1) - fileStart;
        fileB = substr(lineBuffer, fileStart + 1, fileEnd - 1);
        descStart = strpos(lineBuffer, '"', fileEnd + fileStart + 1);
        descEnd = strpos(lineBuffer, '"', descStart + 1) - descStart;
        descB = substr(lineBuffer, descStart + 1, descEnd - 1);
      }
    }

    fclose(mergeFile);

    //Open the custom merge command config
    if ((configFile = fopen("pvcsmerge.cfg", "r")) != NULL) {
      //Read the line in and replace the arguments
      fgets(lineBuffer, MAX_LINE_SIZE, configFile);
      runCommand = str_replace(lineBuffer, "(leftDesc)", descA);
      runCommand = str_replace(runCommand, "(rightDesc)", descB);
      runCommand = str_replace(runCommand, "(leftPath)", fileA);
      runCommand = str_replace(runCommand, "(rightPath)", fileB);
      //Run the command
      if (system(runCommand) != 0) {
        //Error handling bits...
        logIssue("Failed to run command? Check you don't have spaces in the exe path:\n");
        logIssue("  ");
        logIssue(runCommand);
        return 1;
      }
    }
    else {
      makeDefaultConfig();

      if ((configFile = fopen("pvcsmerge.cfg", "r")) != NULL) {
        //Read the line in and replace the arguments
        fgets(lineBuffer, MAX_LINE_SIZE, configFile);
        runCommand = str_replace(lineBuffer, "(leftDesc)", descA);
        runCommand = str_replace(runCommand, "(rightDesc)", descB);
        runCommand = str_replace(runCommand, "(leftPath)", fileA);
        runCommand = str_replace(runCommand, "(rightPath)", fileB);
        //Run the command
        if (system(runCommand) != 0) {
          //Error handling bits...
          logIssue("Failed to run command? Check you don't have spaces in the exe path:\n");
          logIssue("  ");
          logIssue(runCommand);
          return 1;
        }
      }
      else {
        logIssue("Config file not found:\n");
        logIssue("  ");
        logIssue("./pvcsmerge.cfg - not readable, nor can it be generated?!\n");
        return 1;
      }
    }
  }
  else if (argc <= 1) {
    logIssue("Merge config file not specified!\n");
    return 1;
  }
  else {
    logIssue("Merge config file not found:\n");
    logIssue("  ");
    logIssue(argv[argc-1]);
    logIssue(" - not readable\n");
    return 1;
  }

  return 0;
}