Exemplo n.º 1
0
struct reply* searchRecursively(struct node* head, int n){
	static int index = 0;
	//static struct node *t = NULL;
	struct reply *r = NULL;
		index++;
	if(head == NULL || head->data == n ){
		free(r);
		r = (struct reply*)malloc(sizeof(struct reply));
		if(head!=NULL){
			r->response = 1;
			r->data = index;
			r->ptr = head;
			r->prevptr = temp;
		}
		else{
			r->response = 0;
			r->data = 0;
			r->ptr = NULL;
			r->prevptr = NULL;
		}
	}else{
		temp = head;
		r = searchRecursively(head->next,n);
	}
	index = 0;
	return r;
}
Exemplo n.º 2
0
void swapByLinks(){
	struct reply *r = NULL,*r1 = NULL;
	temp = NULL;
	struct node *temp1 = NULL;
	int x = getInput();
	int y = getInput();
	r = searchRecursively(head,x);
	r1 = searchRecursively(head,y);
	if(r->response == 1 && r1->response == 1){
		temp = r1->ptr->next;
		temp1 = r1->prevptr;
		if(abs(r->data - r1->data) > 1){
			r1->ptr->next = r->ptr->next;
			r->ptr->next = temp;
			if(r->prevptr != NULL)
				r->prevptr->next = r1->ptr;
			if(temp1!=NULL)
				temp1->next = r->ptr;
			if(checkHead(x))
				head = r1->ptr;
			else if(checkHead(y))
				head = r->ptr;
		}else if(abs(r->data - r1->data) == 1){
			r1->ptr->next = r->ptr;
			r->ptr->next = temp;
			if(r->prevptr != NULL)
				r->prevptr->next = r1->ptr;
			/*if(temp1!=NULL)
				temp1->next = r->ptr;*/
			if(checkHead(x))
				head = r1->ptr;
			else if(checkHead(y))
				head = r->ptr;
		}
		else{
			printf("\n1st element should appear before 2nd element in LL.\n");
		}
	}else{
		printf("\nElement not found.\n");
	}
	display();
}
void SearchWorker::run()
{
    while ( m_profile.isWhiteList() ) {
        m_directory = m_profile.getNextFromWhiteList();
        QString errMsg = searchRecursively(m_directory, m_searchTerm);
        if (!errMsg.isEmpty())
            emit errorOccurred(errMsg, m_currentDirectory);
    }
    emit progressChanged("");
    emit done();
}
Exemplo n.º 4
0
int main(){
	int option = 999;
	char *menuStr = getScrOp();
	while(option!=11){
		printf("%sEnter an Option :",menuStr);
		scanf("%d",&option);
		switch(option){
			case 1:
				insert();
				break;
			case 10:
				display();
				break;
			case 2:
				InsertBegin();
				break;
			case 3:
				InsertAnywhere();
				break;
			case 11:
				printf("Exited.");
				break;
			case 4:
				deleteNode();
				break;
			case 5:
				countIteratively();
				break;
			case 6:
				getNth();
				break;
			case 7:
				searchIteratively();
				break;
			case 8:
				searchRecursively(head,getInput());
				break;
			case 9:
				swapByLinks();
				break;
			default :
				printf("Enter an valid option");
		}
	}
	return 0;
}
QString SearchWorker::searchRecursively(QString directory, QString searchTerm)
{
    // skip some system folders - they don't really have any interesting stuff
    if (directory.startsWith("/proc") ||
            directory.startsWith("/sys/block"))
        return QString();

    QDir dir(directory);
    if (!dir.exists())  // skip "non-existent" directories (found in /dev)
        return QString();

    // update progress
    m_currentDirectory = directory;
    emit progressChanged(m_currentDirectory);

    //profile settings;
    bool enableRegEx = m_profile.getBoolOption(Profile::EnableRegEx);
    bool hiddenSetting = m_profile.getBoolOption(Profile::SearchHiddenFiles);
    bool enableSymlinks = m_profile.getBoolOption(Profile::EnableSymlinks);
    bool singleMatchSetting = m_profile.getBoolOption(Profile::SingleMatchSetting);
    bool enableNotes = m_profile.getBoolOption(Profile::EnableNotes);
    bool enableFileDir = m_profile.getBoolOption(Profile::EnableFileDir);
    
    QHash<SearchWorker::WorkSet, bool> enabler;
    enabler[SearchWorker::EnableMimeType] = m_profile.getBoolOption(Profile::EnableMimeType);
    enabler[SearchWorker::EnableTxt] = m_profile.getBoolOption(Profile::EnableTxt);
    enabler[SearchWorker::EnableHtml] = m_profile.getBoolOption(Profile::EnableHtml);
    enabler[SearchWorker::EnableSrc] = m_profile.getBoolOption(Profile::EnableSrc);
    enabler[SearchWorker::EnableApps] = m_profile.getBoolOption(Profile::EnableApps);
    enabler[SearchWorker::EnableSqlite] = m_profile.getBoolOption(Profile::EnableSqlite);

    //prepare for regEx
    const QRegularExpression searchExpr(searchTerm, QRegularExpression::UseUnicodePropertiesOption);
    if(!searchExpr.isValid()) enableRegEx=false;

    QDir::Filter hidden = hiddenSetting ? QDir::Hidden : (QDir::Filter)0;

    // search dirs
    QString searchtype = "DIR";
    QString matchline = "";
    QStringList names = dir.entryList(QDir::NoDotAndDotDot | QDir::AllDirs | QDir::System | hidden);
    for (int i = 0 ; i < names.count() ; ++i) {
        // stop if cancelled
        if (m_cancelled.loadAcquire() == Cancelled)
            return QString();

        QString filename = names.at(i);
        QString fullpath = dir.absoluteFilePath(filename);

        if (enableFileDir)
            if ( enableRegEx ? filename.contains(searchExpr) : filename.contains(searchTerm, Qt::CaseInsensitive) )
                emit matchFound(fullpath, searchtype, "", matchline, 0);

        if (enableSymlinks) {
            //skip deep subdirs when symlinks enabled
            if (fullpath.count("/") > MAXDIRDEPTH) continue;
        }
        else {
            QFileInfo info(fullpath);
            // skip symlinks to prevent infinite loops
            if (info.isSymLink()) continue;
        }
        if ( !m_profile.isInBlackList(fullpath) ) {
            QString errmsg = searchRecursively(fullpath, searchTerm);
            if (!errmsg.isEmpty())
                return errmsg;
        }
    }

    // search files
    if (enableFileDir) {
        searchtype = "FILE";
        matchline = "";
        names = dir.entryList(QDir::Files | hidden);
        for (int i = 0 ; i < names.count() ; ++i) {
            // stop if cancelled
            if (m_cancelled.loadAcquire() == Cancelled)
                return QString();

            QString filename = names.at(i);
            QString fullpath = dir.absoluteFilePath(filename);

            if ( enableRegEx ? filename.contains(searchExpr) : filename.contains(searchTerm, Qt::CaseInsensitive) )
                emit matchFound(fullpath, searchtype, "", matchline, 0);
        }
    }
    
    // create table of file lists qualified for search
    QHash<SearchWorker::WorkSet, QStringList> filesTab = createFileTable(dir,hidden,enabler);

    // search inside filtered files (*.txt)
    if (enabler[SearchWorker::EnableTxt])
        if ( addSearchTXT("TXT", searchTerm, dir, filesTab, singleMatchSetting) == QString() ) return QString();

    // search inside filtered files (*.html)
    if (enabler[SearchWorker::EnableHtml])
        if ( addSearchTXT("HTML", searchTerm, dir, filesTab, singleMatchSetting) == QString() ) return QString();

    // search inside filtered files (*.cpp, *.c, *.h, *.py, *.sh, *.qml, *.js)
    if (enabler[SearchWorker::EnableSrc])
        if ( addSearchTXT("SRC", searchTerm, dir, filesTab, singleMatchSetting) == QString() ) return QString();

    // search inside filtered files (*.desktop)
    if (enabler[SearchWorker::EnableApps])
        if ( addSearchTXT("APPS", searchTerm, dir, filesTab, singleMatchSetting) == QString() ) return QString();

    // search inside raw sqlite files (*.sqlite, *.sqlite3, *db)
    if (enabler[SearchWorker::EnableSqlite])
        if ( addSearchSqlite("SQLITE", searchTerm, dir, filesTab, singleMatchSetting) == QString() ) return QString();

    // search inside Notes sqlite db

    if ( !m_alreadySearchedNotes ) {
        if (enableNotes)
            if ( addSearchNotes("NOTES", searchTerm, singleMatchSetting) == QString() ) return QString();
        m_alreadySearchedNotes = true;
    }

    return QString();
}