openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/util-linux/2.33.2-r0/util-linux-2.33.2/text-utils/more.c
static void search(struct more_control* ctl, char buf[], FILE* file, int n)
{
    long startline = ctl->file_position;
    long line1 = startline;
    long line2 = startline;
    long line3;
    int lncount;
    int saveln, rc;
    regex_t re;

    ctl->context.line_num = saveln = ctl->current_line;
    ctl->context.row_num = startline;
    lncount = 0;
    if (!buf)
        goto notfound;
    if ((rc = regcomp(&re, buf, REG_NOSUB)) != 0)
    {
        char s[REGERR_BUF];
        regerror(rc, &re, s, sizeof s);
        more_error(ctl, s);
    }
    while (!feof(file))
    {
        line3 = line2;
        line2 = line1;
        line1 = ctl->file_position;
        read_line(ctl, file);
        lncount++;
        if (regexec(&re, ctl->line_buf, 0, NULL, 0) == 0)
        {
            if (--n == 0)
            {
                if (lncount > 3 || (lncount > 1 && ctl->no_tty_in))
                {
                    putchar('\n');
                    if (ctl->clear_line_ends)
                        putp(ctl->erase_line);
                    fputs(_("...skipping\n"), stdout);
                }
                if (!ctl->no_tty_in)
                {
                    ctl->current_line -= (lncount >= 3 ? 3 : lncount);
                    more_fseek(ctl, file, line3);
                    if (ctl->no_scroll)
                    {
                        if (ctl->clear_line_ends)
                        {
                            putp(ctl->go_home);
                            putp(ctl->erase_line);
                        }
                        else
                            more_clear_screen(ctl);
                    }
                }
                else
                {
                    kill_line(ctl);
                    if (ctl->no_scroll)
                    {
                        if (ctl->clear_line_ends)
                        {
                            putp(ctl->go_home);
                            putp(ctl->erase_line);
                        }
                        else
                            more_clear_screen(ctl);
                    }
                    puts(ctl->line_buf);
                }
                break;
            }
        }
    }
    regfree(&re);
    if (feof(file))
    {
        if (!ctl->no_tty_in)
        {
            ctl->current_line = saveln;
            more_fseek(ctl, file, startline);
        }
        else
        {
            fputs(_("\nPattern not found\n"), stdout);
            more_exit(0);
        }
        free(ctl->previous_search);
        ctl->previous_search = NULL;
    notfound:
        more_error(ctl, _("Pattern not found"));
    }
}
/* Search for nth occurrence of regular expression contained in buf in
 * the file */
Search for nth occurrence of regular expression contained in buf in
the file
Search for nth occurrence of regular expression contained in buf in the file
static void search(struct more_control* ctl, char buf[], FILE* file, int n)
{
    long startline = ctl->file_position;
    long line1 = startline;
    long line2 = startline;
    long line3;
    int lncount;
    int saveln, rc;
    regex_t re;
    ctl->context.line_num = saveln = ctl->current_line;
    ctl->context.row_num = startline;
    lncount = 0;
    if (!buf)
        goto notfound;
    if ((rc = regcomp(&re, buf, REG_NOSUB)) != 0)
    {
        char s[REGERR_BUF];
        regerror(rc, &re, s, sizeof s);
        more_error(ctl, s);
    }
    while (!feof(file))
    {
        line3 = line2;
        line2 = line1;
        line1 = ctl->file_position;
        read_line(ctl, file);
        lncount++;
        if (regexec(&re, ctl->line_buf, 0, NULL, 0) == 0)
        {
            if (--n == 0)
            {
                if (lncount > 3 || (lncount > 1 && ctl->no_tty_in))
                {
                    putchar('\n');
                    if (ctl->clear_line_ends)
                        putp(ctl->erase_line);
                    fputs(_("...skipping\n"), stdout);
                }
                if (!ctl->no_tty_in)
                {
                    ctl->current_line -= (lncount >= 3 ? 3 : lncount);
                    more_fseek(ctl, file, line3);
                    if (ctl->no_scroll)
                    {
                        if (ctl->clear_line_ends)
                        {
                            putp(ctl->go_home);
                            putp(ctl->erase_line);
                        }
                        else
                            more_clear_screen(ctl);
                    }
                }
                else
                {
                    kill_line(ctl);
                    if (ctl->no_scroll)
                    {
                        if (ctl->clear_line_ends)
                        {
                            putp(ctl->go_home);
                            putp(ctl->erase_line);
                        }
                        else
                            more_clear_screen(ctl);
                    }
                    puts(ctl->line_buf);
                }
                break;
            }
        }
    }
    regfree(&re);
    if (feof(file))
    {
        if (!ctl->no_tty_in)
        {
            ctl->current_line = saveln;
            more_fseek(ctl, file, startline);
        }
        else
        {
            fputs(_("\nPattern not found\n"), stdout);
            more_exit(0);
        }
        free(ctl->previous_search);
        ctl->previous_search = NULL;
    notfound:
        more_error(ctl, _("Pattern not found"));
    }
}
static void search ( struct more_control * ctl , char buf [ ] , FILE * file , int n ) { long startline = ctl -> file_position ; long line1 = startline ; long line2 = startline ; long line3 ; int lncount ; int saveln , rc ; regex_t re ; ctl -> context . line_num = saveln = ctl -> current_line ; ctl -> context . row_num = startline ; lncount = 0 ; if ( ! buf ) goto notfound ; if ( ( rc = regcomp ( & re , buf , REG_NOSUB ) ) != 0 ) { char s [ REGERR_BUF ] ; regerror ( rc , & re , s , sizeof s ) ; more_error ( ctl , s ) ; } while ( ! feof ( file ) ) { line3 = line2 ; line2 = line1 ; line1 = ctl -> file_position ; read_line ( ctl , file ) ; lncount ++ ; if ( regexec ( & re , ctl -> line_buf , 0 , NULL , 0 ) == 0 ) { if ( -- n == 0 ) { if ( lncount > 3 || ( lncount > 1 && ctl -> no_tty_in ) ) { putchar ( ' \n ' ) ; if ( ctl -> clear_line_ends ) putp ( ctl -> erase_line ) ; fputs ( _ ( " \n " ) , stdout ) ; } if ( ! ctl -> no_tty_in ) { ctl -> current_line -= ( lncount >= 3 ? 3 : lncount ) ; more_fseek ( ctl , file , line3 ) ; if ( ctl -> no_scroll ) { if ( ctl -> clear_line_ends ) { putp ( ctl -> go_home ) ; putp ( ctl -> erase_line ) ; } else more_clear_screen ( ctl ) ; } } else { kill_line ( ctl ) ; if ( ctl -> no_scroll ) { if ( ctl -> clear_line_ends ) { putp ( ctl -> go_home ) ; putp ( ctl -> erase_line ) ; } else more_clear_screen ( ctl ) ; } puts ( ctl -> line_buf ) ; } break ; } } } regfree ( & re ) ; if ( feof ( file ) ) { if ( ! ctl -> no_tty_in ) { ctl -> current_line = saveln ; more_fseek ( ctl , file , startline ) ; } else { fputs ( _ ( " \n \n " ) , stdout ) ; more_exit ( 0 ) ; } free ( ctl -> previous_search ) ; ctl -> previous_search = NULL ; notfound : more_error ( ctl , _ ( " " ) ) ; } }
Search for nth occurrence of regular expression contained in buf in
 the file
Search for nth occurrence of regular expression contained in buf in the file