commands.cc
/*
** search_backward - search backward 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 backward 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 backward 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_backward(DirList *dl)
{
    const char *str = prompt("Search backward for: ");
    if (str == 0)
    {
        move_cursor(dl->savedYPos(), dl->savedXPos());
        synch_display();
        return;
    }
    DirLine *ln = dl->currLine();
    if (ln == dl->head()) return;
    int pos = dl->savedYPos()-1;
    DirLine *found = search(ln->prev(), str, &pos, 0);
    if (found)
    {
        if (dl->currLine()->length() > columns()) rightshift_current_line(dl);
        dl->setCurrLine(found);
    }
    if (found && pos >= 0)
    {
         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.  Since we\'re searching backwards
         and the match is out of our present window, we
         must have a whole new window to display.
        dl->setFirst(ln = found);
        cursor_home();
        for (int i = 0; i < rows() - 2 && ln->next(); i++, ln = ln->next())
        {
            clear_to_end_of_line();
            display_string(ln->line(), ln->length());
        }
        dl->setLast(ln->prev());
        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_backward ( 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 -> head ( ) ) return ; int pos = dl -> savedYPos ( ) - 1 ; DirLine * found = search ( ln -> prev ( ) , str , & pos , 0 ) ; if ( found ) { if ( dl -> currLine ( ) -> length ( ) > columns ( ) ) rightshift_current_line ( dl ) ; dl -> setCurrLine ( found ) ; } if ( found && pos >= 0 ) { dl -> saveYXPos ( pos , goal_column ( dl ) ) ; if ( dl -> currLine ( ) -> length ( ) > columns ( ) ) leftshift_current_line ( dl ) ; else move_cursor ( pos , dl -> savedXPos ( ) ) ; } else if ( found ) { dl -> setFirst ( ln = found ) ; cursor_home ( ) ; for ( int i = 0 ; i < rows ( ) - 2 && ln -> next ( ) ; i ++ , ln = ln -> next ( ) ) { clear_to_end_of_line ( ) ; display_string ( ln -> line ( ) , ln -> length ( ) ) ; } dl -> setLast ( ln -> prev ( ) ) ; 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_backward - search backward for file or directory matching string.
search_backward - search backward 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.  Since we\'re searching backwards // and the match is out of our present window, we // must have a whole new window to display. //