/usr/share/jed/lib/search.sl is in jed-common 1:0.99.19-7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | %
% forward and backward search functions. These functions can search across
% lines.
%
require ("srchmisc");
define search_across_lines (str, dir)
{
variable n, s, s1, fun, len;
len = strlen (str);
fun = &fsearch;
if (dir < 0) fun = &bsearch;
n = is_substr (str, "\n");
!if (n)
{
if (@fun (str)) return len;
return -1;
}
s = substr (str, 1, n);
s1 = substr (str, n + 1, strlen(str));
n = strlen(s);
push_mark ();
while (@fun(s))
{
% we are matched at end of the line.
go_right (n);
if (looking_at(s1))
{
go_left(n);
pop_mark_0 ();
return len;
}
if (dir < 0) go_left (n);
}
pop_mark_1 ();
-1;
}
private define setup_case_search (pat)
{
variable cs = CASE_SEARCH;
if (strlow (pat) != pat)
{
CASE_SEARCH = 1;
}
return cs;
}
define search_generic_search (prompt, dir, line_ok_fun)
{
variable str, not_found = 1;
str = read_mini(prompt, LAST_SEARCH, Null_String);
!if (strlen(str)) return;
push_mark ();
variable cs = setup_case_search (str);
ERROR_BLOCK
{
pop_mark (not_found);
CASE_SEARCH = cs;
}
if ((dir > 0) and looking_at(str)) go_right_1 ();
save_search_string (str);
not_found = not (search_maybe_again (&search_across_lines, str, dir,
line_ok_fun));
if (not_found) verror ("%s: not found.", str);
EXECUTE_ERROR_BLOCK;
}
define search_forward ()
{
search_generic_search ("Search forward:", 1, &_function_return_1);
}
define search_backward ()
{
search_generic_search ("Search backward:", -1, &_function_return_1);
}
define replace_do_replace (str, len)
{
replace_chars (len, str); % returns strlen (str)
#iffalse
push_mark ();
go_right(len);
del_region ();
insert (str);
strlen (str);
#endif
}
define search_search_function (pat)
{
variable cs = setup_case_search (pat);
EXIT_BLOCK
{
CASE_SEARCH = cs;
}
variable len = strlen (pat);
if (search_across_lines (pat, 1) > 0) return len;
return -1;
}
define replace_cmd ()
{
variable pat, prompt, rep;
variable has_prefix;
pat = read_mini("Replace:", Null_String, Null_String);
!if (strlen (pat)) return;
prompt = strcat (strcat ("Replace '", pat), "' with:");
rep = read_mini(prompt, "", "");
variable cs = setup_case_search (pat);
ERROR_BLOCK
{
CASE_SEARCH = cs;
}
replace_with_query (&search_search_function, pat, rep, 1, &replace_do_replace);
EXECUTE_ERROR_BLOCK;
message ("done.");
}
provide ("search");
|