"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/search.c" between
most-5.1.0.tar.gz and most-5.2.0.tar.gz

About: most is a textfile paging program (supports multiple windows and can scroll left and right).

search.c  (most-5.1.0):search.c  (most-5.2.0)
/* -*- mode: C; mode: fold -*- */ /* -*- mode: C; mode: fold -*- */
/* /*
This file is part of MOST. This file is part of MOST.
Copyright (c) 1991, 1999, 2002, 2005-2018, 2019 John E. Davis Copyright (c) 1991, 1999, 2002, 2005-2021, 2022 John E. Davis
This program is free software; you can redistribute it and/or modify it This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option) Software Foundation; either version 2 of the License, or (at your option)
any later version. any later version.
This program is distributed in the hope that it will be useful, but WITHOUT This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details. more details.
skipping to change at line 34 skipping to change at line 34
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <slang.h> #include <slang.h>
#include "most.h" #include "most.h"
#include "window.h" #include "window.h"
#include "line.h" #include "line.h"
#include "file.h" #include "file.h"
#include "display.h" #include "display.h"
#include "search.h" #include "search.h"
#include "color.h"
/* Note!!! The regular expression searches may not work. I have not /* Note!!! The regular expression searches may not work. I have not
* tested them. * tested them.
* FIXME!!! This whole thing needs to be rewritten. It is a mess. * FIXME!!! This whole thing needs to be rewritten. It is a mess.
*/ */
int Most_Case_Sensitive = 0; int Most_Case_Sensitive = 0;
char Most_Search_Str[256]; char Most_Search_Str[256];
int Most_Search_Dir = 1; int Most_Search_Dir = 1;
skipping to change at line 165 skipping to change at line 166
/* This routine returns the 1 + position of first match of key in str. /* This routine returns the 1 + position of first match of key in str.
* searches from beg up to but not including end. Handles backspace, etc * searches from beg up to but not including end. Handles backspace, etc
*/ */
static unsigned char * static unsigned char *
bs_fsearch (Search_Type *st, bs_fsearch (Search_Type *st,
unsigned char *beg, unsigned char *end, unsigned char *beg, unsigned char *end,
unsigned char *key) unsigned char *key)
{ {
unsigned char ch, ch1, ch1up; unsigned char ch, ch1, ch1up;
unsigned char *pos; unsigned char *pos;
int cis, key_len, j, str_len; MOST_INT j, key_len, str_len;
int cis;
(void) st; (void) st;
key_len = strlen ((char *)key); key_len = strlen ((char *)key);
if (key_len == 0) if (key_len == 0)
return Most_Eob; return Most_Eob;
str_len = (int) (end - beg); str_len = (MOST_INT)(end - beg);
if (str_len < key_len) return (Most_Eob); if (str_len < key_len) return (Most_Eob);
cis = (Most_Case_Sensitive == 0); cis = (Most_Case_Sensitive == 0);
ch1 = key[0]; ch1 = key[0];
ch1up = UPCASE(ch1); ch1up = UPCASE(ch1);
while (1) while (1)
{ {
/* Find first character that matches */ /* Find first character that matches */
while (1) while (1)
{ {
if (beg == end) return Most_Eob; if (beg == end) return Most_Eob;
ch = *beg++; ch = *beg++;
if ((ch == 033) && is_ansi_escape (&beg, end))
continue;
if ((ch == ch1) if ((ch == ch1)
|| (cis && (ch1up == UPCASE(ch)))) || (cis && (ch1up == UPCASE(ch))))
break; break;
} }
/* so we have a position of possible match */ /* so we have a position of possible match */
j = 1; j = 1;
pos = beg; /* save this position so we start from here again */ pos = beg; /* save this position so we start from here again */
skipping to change at line 253 skipping to change at line 258
* Search backwards in the buffer "beg" up to, but not including "end" for * Search backwards in the buffer "beg" up to, but not including "end" for
* pattern "key". It handles backspaces, etc * pattern "key". It handles backspaces, etc
*/ */
static unsigned char * static unsigned char *
bs_bsearch (Search_Type *st, bs_bsearch (Search_Type *st,
unsigned char *beg, unsigned char *end, unsigned char *beg, unsigned char *end,
unsigned char *key) unsigned char *key)
{ {
unsigned char ch, ch1, ch1up; unsigned char ch, ch1, ch1up;
unsigned char *pos; unsigned char *pos;
int key_len,j, str_len; MOST_INT key_len, str_len, j;
int cis; int cis;
(void) st; (void) st;
key_len = strlen ((char *)key); key_len = strlen ((char *)key);
if (key_len == 0) return Most_Eob; if (key_len == 0) return Most_Eob;
str_len = (int) (end - beg); str_len = (MOST_INT) (end - beg);
if (str_len < key_len) return Most_Eob; if (str_len < key_len) return Most_Eob;
ch1 = key[key_len-1]; ch1 = key[key_len-1];
ch1up = UPCASE(ch1); ch1up = UPCASE(ch1);
cis = (Most_Case_Sensitive == 0); cis = (Most_Case_Sensitive == 0);
while (1) while (1)
{ {
while (1) while (1)
{ {
if (end < beg) if (end < beg)
return Most_Eob; return Most_Eob;
ch = *end--; ch = *end--;
if ((ch == 'm') && is_rev_ansi_escape (beg, &end))
continue;
if ((ch == ch1) if ((ch == ch1)
|| (cis && (ch1up == UPCASE(ch)))) || (cis && (ch1up == UPCASE(ch))))
break; break;
} }
pos = end; /* save this position so we start from here again */ pos = end; /* save this position so we start from here again */
j = key_len - 2; j = key_len - 2;
while (1) while (1)
skipping to change at line 389 skipping to change at line 398
return 0; return 0;
} }
static int static int
do_search_internal (Search_Type *st, do_search_internal (Search_Type *st,
unsigned char *from, int repeat, MOST_INT *col) unsigned char *from, int repeat, MOST_INT *col)
{ {
/* return the line match was found as well as line number, /* return the line match was found as well as line number,
* search from i on; assume that line_array match the i so we need * search from i on; assume that line_array match the i so we need
* no initial lookup */ * no initial lookup */
int test;
MOST_INT save_line, the_col, row, s_len;
char string[300]; char string[300];
unsigned char *pos, *eob; unsigned char *pos, *eob;
unsigned int save_ofs; MOST_UINT save_ofs, found_ofs;
unsigned int found_ofs; MOST_INT save_line, the_col, row, s_len;
int test;
if (*Most_Search_Str == 0) if (*Most_Search_Str == 0)
{ {
most_message("Search string not specified.",1); most_message("Search string not specified.",1);
return -1; return -1;
} }
if ((from < Most_Beg) || (from > Most_Eob)) return -1; if ((from < Most_Beg) || (from > Most_Eob)) return -1;
save_ofs = Most_C_Offset; save_ofs = Most_C_Offset;
skipping to change at line 421 skipping to change at line 428
eob = Most_Eob; eob = Most_Eob;
test = repeat && (pos < Most_Eob) && (pos >= Most_Beg); test = repeat && (pos < Most_Eob) && (pos >= Most_Beg);
while(test) while(test)
{ {
if (Most_Search_Dir == 1) if (Most_Search_Dir == 1)
{ {
while (1) while (1)
{ {
unsigned int pos_ofs; size_t pos_ofs;
pos = (*st->fsearch_method)(st, pos, Most_Eob, (unsigned char*) Most_Search_Str); pos = (*st->fsearch_method)(st, pos, Most_Eob, (unsigned char*) Most_Search_Str);
pos_ofs = (unsigned int) (Most_Eob - Most_Beg); pos_ofs = (Most_Eob - Most_Beg);
if (pos < Most_Eob) if (pos < Most_Eob)
break; break;
if (0 == most_read_file_dsc (10, 0)) if (0 == most_read_file_dsc (10, 0))
{ {
/* Pointer may be invalid after this call */ /* Pointer may be invalid after this call */
pos = Most_Beg + pos_ofs; pos = Most_Beg + pos_ofs;
break; break;
} }
 End of changes. 12 change blocks. 
12 lines changed or deleted 19 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)