home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hot Shareware 35
/
hot35.iso
/
ficheros
/
9TXT
/
ZE32V270.ZIP
/
ISEARCH.ZM_
/
ISEARCH.ZM
Wrap
Text File
|
1997-10-04
|
5KB
|
166 lines
/*************************************************************************
Name: IncrementalSearch
Description: This macro provides an incremental search feature. To
use this macro either run it directly or install it to
the Macros menu using the Options Macros menu item. The
following keys are also supported:
ASCII Char - add the char to the search string
BackSpace - remove last char from the search string
ESC - cancel the search
Enter - complete the search
ArrowUp - search for previous occurrence
ArrowDown - search for next occurrence
ArrowLeft - same as backspace
ArrowRight - add the next char to the search string
Author: Brander, Bertel K.
Contact: bertel@post4.tele.dk
**************************************************************************/
int IncrementalSearch()
{
int ox;
int oy;
int length;
int end = 0;
char ch;
string sstring = "";
// make sure it is a document window
if (is_document() == 0)
{
message("This macro only works for document files!");
beep();
return;
}
// save the current cursor porition
cursor_save();
// save the current search engine setting
search_save();
set_find_text(sstring);
// extended codes found by printing 'getch' values to debug_output
key_left = 37;
key_up = 38;
key_right = 39;
key_down = 40;
key_escape = 27;
key_backspace = 8;
key_enter = 13;
ch = 0;
message("Enter the search text. Backspace, ESC/Enter and Arrow keys control searching.");
// do the searching till an escape/enter key is hit
while (end == 0)
{
// gets ascii keys and extended keys
ch = getch(sExtended);
if ((ch != -1) && (ch != key_escape) && (ch != key_enter))
{
if ((ch == 0) && (sExtended == key_down))
{
// line down key pressed
found = SearchNext();
}
else if ((ch == 0) && (sExtended == key_up))
{
// line up key pressed
found = SearchPrevious();
}
else if ((ch == 0) && (sExtended == key_right))
{
// get the current column position
get_column_pos(column);
// get the length of the current highlighted word and a bit more
sstring = "$W";
wordlength = strlen(sstring) + 1;
// get a part of the line starting at column of wordlength
get_line(sstring, column, wordlength);
// search for the new word
set_find_text(sstring);
found = SearchNext();
}
else if (((ch == 0) && (sExtended == key_left)) || (ch == key_backspace))
{
// remove last char from sstring
length = strlen(sstring);
if (length > 1)
{
strleft(sstring, sstring, length -1);
set_find_text(sstring);
found = SearchPrevious();
}
else
{
// nothing left to search for
sstring = "";
MarkHide();
found = 1;
}
}
else if (ch != 0)
{
// an ascii key was pressed
get_column_pos(ox);
get_line_pos(oy);
strcat(sstring, ch);
set_find_text(sstring);
MoveLineLeftEx();
found = 1; // assume success
if (SearchNext() == 0)
{
// no match were found so try search backwards with no sound
beep_enable(0);
if (SearchPrevious() == 0)
{
// No match were found, remove last char from sstring
length = strlen(sstring);
strleft(sstring, sstring, length - 1);
set_find_text(sstring);
set_column_pos(ox);
set_line_pos(oy);
found = 0; // no success
}
beep_enable(1);
}
}
if (found == 1) message("Search for: %s", sstring);
}
else if (ch == key_escape)
{
// restore the cursor porition
cursor_restore();
message("Incremental search canceled.");
end = -1;
}
else if (ch == key_enter)
{
end = 1;
}
}
if (end == 1) message("Incremental search complete.");
MarkHide();
// restore the search settings
search_restore();
}