Guidance
指路人
g.yi.org
Upload / Forum Attachment / Reginald Rexx Programming Language Compiler User Forum Attachments and Pictures / 13274-search_in_project.rex

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
/*
GUIBEGIN


WINDOW , 435, 7, 287, 37, POPUP|CAPTION|SYSMENU|THICK, , Search for string in current project
	FONT 8, 400, MS Shell Dlg
	TEXT 15, 12, 50, 8, GROUP, , , , Search string
	ENTRY 72, 10, 193, 12, UPPER|H_AUTO|BORDER|TABSTOP, CLIENTEDGE, search_string_entry
	PUSH 247, 23, 33, 12, DEFAULT|HIDE|TABSTOP, , ok_button, , OK
DEND
GUIEND
*/

/* Load Rexx Gui functions. */
LIBRARY rexxgui
guierr = "SYNTAX"
guiheading = 1
registry_key = "Software\Rexxcenter\search_in_project\last_search_string"
/* Get the last string they searched for (if they have) */
search_string_entry = VALUE(registry_key, , "WIN32")

/* Get the path to my script */
PARSE SOURCE . . filename
/* Construct the full path of the data file */
full_path = FILESPEC('D', filename) || FILESPEC('P', filename)
DO
	/* Now try and register Peter's array programs - accept failure */
	rc = registerarray.rex(full_path)
	IF rc = 0 THEN
		sw_array = 1			/* Use array functions */
		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
		/* Save the search string for the next time */
		rc = VALUE(registry_key, search_string_entry, "WIN32")
		guidestroywindow()
END
RETURN
wm_click_ok_button:
guigetctlvalue()
/* Check that they've opened a project */
err = editproject('project_name', 'QUERY')
IF err <> '' THEN
	DO
		guisay('0D0A'x||err||'0D0A'x)  /* No - leave */
		RETURN
	END	

/* Get the names of the scripts in the project */
rc = get_project_contents(program_list., project_name)
sw_found = 0			/* In case NOTHING found */
/* Loop through the contents's list looking for the string */
DO i = 1 TO program_list.0
	sourcecode.0 = get_file(program_list.i, sourcecode.)
	IF sourcecode.0 <> 0 THEN
		/* Look for the string in the sourcecode */
		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 using Peter's array handling, then we need to 
	   erase the variable, otherwise the array handling would 
	   always append the next file to the previous one */
	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 our arrays here. 20000 lines should be enough for
 any sourcecode. Can't imagine any sourcecode has more than
 500 sections (if it did, it would be unmaintainable)
************************************************************/ 
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 the items in the project

 1	List of items in project
 2	Name of the resulting project

 NB NB NB 
 NO attempt is made to analyze the differing contents in
 the project. Since my projects ONLY ever contains scripts
 I haven't tried skipping other items that could be
 included in the project file 
 NB NB NB  
**********************************************************/
get_project_contents:

USE ARG program_list., project_name

/* Open the project file for reading */
STREAM(project_name, 'C', 'OPEN READ')

/* 10000 should always (?) be enough for the contents of a project */
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 <> ""
	/* Get the length of the next item .... */
	name_length = LEFT(project_contents,1)
	/* ... and translate it to a "readable" numeric */
	temp = C2D(name_length)
	project_contents = SUBSTR(project_contents,2)
	/* Get the actual script name .... */
  next_script = LEFT(project_contents,temp)
	project_contents = SUBSTR(project_contents,temp+1)
	/* ... and add it to the stem */
	program_list.0 = program_list.0 + 1
	program_list.[program_list.0] = next_script

END		

RETURN 0 
/****************************************************************
 Look for the string
****************************************************************/
find_string:

USE ARG sourcecode., search_string

IF sw_array = 1 THEN
	/* Use Peter's stuff */
	found_line = search_array()		
ELSE
	DO
		/* LOADTEXT variation - loop a line at a time */
		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
/*************************************************************
 Read the file into storage, either using LOADTEXT or Peter's
 array handling
*************************************************************/ 
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
	/* Use Peter's array handling */
	records = fetch(stem., filein)

RETURN records
/***********************************************************************
 We're using Peter's array handling
***********************************************************************/
search_array:

found_line = search(sourcecode., search_string, 1, , "A", "N")
 /* -10 means outside the scope of the array (though this should
 		never happen) - pretend not found */	
IF found_line = -10 THEN
	found_line = 0    
RETURN found_line	
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sun 2024-2-25  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2010-03-22 21:36:57