commands.cc
/*
** search_forward - search forward for file or directory matching string.
**                  The search always starts with the file following
**                  the current file.  If a match occurs, the cursor
**                  is placed on the new current file, with that line
**                  placed at the top of the window.
*/
search forward for file or directory matching string.
The search always starts with the file following
the current file.  If a match occurs, the cursor
is placed on the new current file, with that line
placed at the top of the window.
search forward for file or directory matching string . The search always starts with the file following the current file . If a match occurs the cursor is placed on the new current file with that line placed at the top of the window .
static void search_forward(DirList *dl)
{
    const char *str = prompt("Search forward for: ");
    if (str == 0)
    {
        move_cursor(dl->savedYPos(), dl->savedXPos());
        synch_display();
        return;
    }                  
    DirLine *ln = dl->currLine();
    if (ln == dl->tail())
    {
        message("no match");
        move_cursor(dl->savedYPos(), dl->savedXPos());
        return;
    }
    int pos = dl->savedYPos()+1;
    DirLine *found = search(ln->next(), str, &pos);
    if (found)
    {
        if (dl->currLine()->length() > columns()) rightshift_current_line(dl);
        dl->setCurrLine(found);
    }
    if (found && pos < rows()-2)
    {
         We found a match in our current window.
         Only need to update the cursor position.
        dl->saveYXPos(pos, goal_column(dl));
        if (dl->currLine()->length() > columns())
            leftshift_current_line(dl);
        else
            move_cursor(pos, dl->savedXPos());
    }
    else if (found)
    {
         We found a match, but it is out of our current view.
         Place the matched line at the top of the window.
        ln = found;
        dl->setFirst(ln);
        cursor_home();
        for (int i = 0; i < rows() - 2 && ln; i++, ln = ln->next())
        {
            clear_to_end_of_line();
            display_string(ln->line(), ln->length());
        }
        move_cursor(i, 0);
        for (; i < rows() - 2; i++)
        {
            clear_to_end_of_line();
            cursor_down();
        }
        ln ? dl->setLast(ln->prev()) : dl->setLast(dl->tail());
        dl->saveYXPos(0, goal_column(dl));
        if (dl->currLine()->length() > columns())
            leftshift_current_line(dl);
        else
            move_cursor(0, dl->savedXPos());
    }
    else
    {
        message("no match");
        move_cursor(dl->savedYPos(), dl->savedXPos());
    }
    synch_display();
}
static void search_forward ( DirList * dl ) { const char * str = prompt ( " " ) ; if ( str == 0 ) { move_cursor ( dl -> savedYPos ( ) , dl -> savedXPos ( ) ) ; synch_display ( ) ; return ; } DirLine * ln = dl -> currLine ( ) ; if ( ln == dl -> tail ( ) ) { message ( " " ) ; move_cursor ( dl -> savedYPos ( ) , dl -> savedXPos ( ) ) ; return ; } int pos = dl -> savedYPos ( ) + 1 ; DirLine * found = search ( ln -> next ( ) , str , & pos ) ; if ( found ) { if ( dl -> currLine ( ) -> length ( ) > columns ( ) ) rightshift_current_line ( dl ) ; dl -> setCurrLine ( found ) ; } if ( found && pos < rows ( ) - 2 ) { dl -> saveYXPos ( pos , goal_column ( dl ) ) ; if ( dl -> currLine ( ) -> length ( ) > columns ( ) ) leftshift_current_line ( dl ) ; else move_cursor ( pos , dl -> savedXPos ( ) ) ; } else if ( found ) { ln = found ; dl -> setFirst ( ln ) ; cursor_home ( ) ; for ( int i = 0 ; i < rows ( ) - 2 && ln ; i ++ , ln = ln -> next ( ) ) { clear_to_end_of_line ( ) ; display_string ( ln -> line ( ) , ln -> length ( ) ) ; } move_cursor ( i , 0 ) ; for ( ; i < rows ( ) - 2 ; i ++ ) { clear_to_end_of_line ( ) ; cursor_down ( ) ; } ln ? dl -> setLast ( ln -> prev ( ) ) : dl -> setLast ( dl -> tail ( ) ) ; dl -> saveYXPos ( 0 , goal_column ( dl ) ) ; if ( dl -> currLine ( ) -> length ( ) > columns ( ) ) leftshift_current_line ( dl ) ; else move_cursor ( 0 , dl -> savedXPos ( ) ) ; } else { message ( " " ) ; move_cursor ( dl -> savedYPos ( ) , dl -> savedXPos ( ) ) ; } synch_display ( ) ; }
search_forward - search forward for file or directory matching string.
search_forward - search forward for file or directory matching string .
// // We found a match in our current window. // Only need to update the cursor position. // // // We found a match, but it is out of our current view. // Place the matched line at the top of the window. //