Ejemplo n.º 1
0
void processArgs(int numInputArgs, char *strings[]){
    if(numInputArgs < 2){
        printUsage(strings[0]);
    }
    int curLength = 0, i = 0, j = 0;
    // TODO - check for unknown arguments

    for(i = 0; i < numInputArgs; i++){
        if(strings[i][0] == '-'){
            curLength = strlen(strings[i]);
            for(j = 0; j < sizeof(simpleArgs) / sizeof(char); j++){
                if(findInString(simpleArgs[j], strings[i], strlen(strings[i])) > 0){
                    if(simpleArgs[j] == 'h'){
                        printHelpMessage(strings[0]);
                    }
                    mapper.setSimpleArg(simpleArgs[j], true);
                } else if(!mapper.getSimpleArg(simpleArgs[j])){  // don't unset
                    mapper.setSimpleArg(simpleArgs[j], false);
                }
            }
            for(j = 0; j < sizeof(compoundArgs) / sizeof(char); j++){
                // disallow compound args in clusters
                if(findInString(compoundArgs[j], strings[i], strlen(strings[i])) != -1){
                    if(curLength > 2 || i+1 == numInputArgs){
                        printUsage(strings[0]);
                    } else {
                        mapper.setCompoundArg(compoundArgs[j], strings[i+1]);
                    }
                }
            }
        }
    }
}
Ejemplo n.º 2
0
Juff::SearchResults* SearchEngine::performSearch(const Juff::SearchParams& params) {
	if ( curDoc_ == NULL || curDoc_->isNull() ) return NULL;
	
	QString text;
	curDoc_->getText(text);
	
	if ( text.isEmpty() )
		return NULL;
	
	if ( params.findWhat.isEmpty() )
		return NULL;
	
	Juff::SearchResults* results = NULL;
	if ( params.mode == Juff::SearchParams::MultiLineRegExp ) {
		// TODO : 
	}
	else {
		results = new Juff::SearchResults(params);
		
		QStringList lines = text.split(LineSeparatorRx);
		QStringList::iterator it = lines.begin();
		int lineIndex = 0;
		while ( it != lines.end() ) {
			QString lineStr = *it;
			int length;
			int indent = 0;
			int pos = findInString(lineStr, indent, params, length);
			while ( pos >= 0 ) {
				if ( length > 0 ) {
					results->addOccurence(lineIndex, pos, lineIndex, pos + length);
				}
				else {
					// to prevent infinite loop when search ends with an empty string
					length = 1;
				}
				
				indent = pos + length;
				
				pos = findInString(lineStr, indent, params, length);
			}
			
			lineIndex++;
			it++;
		}
	}
	
	return results;
}