LIBRARY rexxgui
guierr = "SYNTAX"
guiheading = 1
registry_key = "Software\Rexxcenter\search_in_project\last_search_string"
search_string_entry = VALUE(registry_key, , "WIN32")
PARSE SOURCE . . filename
full_path = FILESPEC('D', filename) || FILESPEC('P', filename)
DO
rc = registerarray.rex(full_path)
IF rc = 0 THEN
sw_array = 1
rc = define_array()
CATCH SYNTAX
sw_array = 0
END
guicreatewindow('NORMAL')
again:
DO FOREVER
guigetmsg()
IF EXISTS('GuiSignal') == 0 THEN
DROP (guiobject)
CATCH SYNTAX
CONDITION()
SIGNAL again
CATCH HALT
FINALLY
rc = VALUE(registry_key, search_string_entry, "WIN32")
guidestroywindow()
END
RETURN
wm_click_ok_button:
guigetctlvalue()
err = editproject('project_name', 'QUERY')
IF err <> '' THEN
DO
guisay('0D0A'x||err||'0D0A'x)
RETURN
END
rc = get_project_contents(program_list., project_name)
sw_found = 0
DO i = 1 TO program_list.0
sourcecode.0 = get_file(program_list.i, sourcecode.)
IF sourcecode.0 <> 0 THEN
found_line = find_string(sourcecode., search_string_entry)
temp = FILESPEC('N', program_list.i)
PARSE VAR temp filename '.' .
SELECT
WHEN sourcecode.0 = 0 THEN
SAY filename "seems to be empty"
WHEN found_line <> 0 THEN
DO
SAY "Found string on line "found_line" in "filename
sw_found = 1
END
OTHERWISE
NOP
END
IF sw_array = 1 THEN
rc = eraseglobal(sourcecode., 1, )
END
IF sw_found = 0 THEN
SAY 'No occurrences of 'search_string_entry' were found in the project'
RETURN 0
define_array:
sourcecode. = globals("sourcecode",20000)
IF sourcecode. < 1 THEN
DO
SAY '*** Error calling GLOBALS - switching to non-array handling'
sw_array = 0
END
RETURN 0
get_project_contents:
USE ARG program_list., project_name
STREAM(project_name, 'C', 'OPEN READ')
project_entries = CHARIN(project_name, 1, 10000)
PARSE VAR project_entries . '0000'x project_contents '0000'x
program_list.0 = 0
DO WHILE project_contents <> ""
name_length = LEFT(project_contents,1)
temp = C2D(name_length)
project_contents = SUBSTR(project_contents,2)
next_script = LEFT(project_contents,temp)
project_contents = SUBSTR(project_contents,temp+1)
program_list.0 = program_list.0 + 1
program_list.[program_list.0] = next_script
END
RETURN 0
find_string:
USE ARG sourcecode., search_string
IF sw_array = 1 THEN
found_line = search_array()
ELSE
DO
found_line = 0
DO i2 = 1 TO sourcecode.0
temp = sourcecode.i2
IF POS(search_string,temp) <> 0 THEN
DO
found_line = i2
LEAVE
END
END
END
RETURN found_line
get_file:
PROCEDURE EXPOSE sw_array
USE ARG filein, stem.
IF sw_array = 0 THEN
DO
STREAM(filein, 'C', 'OPEN READ')
LOADTEXT('stem.', filein)
STREAM(filein, 'C', 'CLOSE')
records = stem.0
END
ELSE
records = fetch(stem., filein)
RETURN records
search_array:
found_line = search(sourcecode., search_string, 1, , "A", "N")
IF found_line = -10 THEN
found_line = 0
RETURN found_line |