$ verify = f$verify(0) $!***************************************************************************** $! $! GBLSEARCH - Procedure to SEARCH files for a string and edit $! any file containting the string. $! $! V1.000 07/06/86 Geoff Bryant Initial version $! $!***************************************************************************** $ $ say := "write sys$output" $ $ ! Check for help $ $ if f$edit(p1,"collapse,upcase") .nes. "HELP" then goto 10 $ type sys$input GBLSEARCH - Utility search and edit/read files This utility allows you to SEARCH files for a string and to edit files containing the string. GBLSEARCH is invoked as follows: $ @TOOLS:GBLSEARCH file(s) search_string edit/read You will be prompted for any unspecified parameters. Options are specified as switches for a file: /Confirm - will ask you to confirm each file /Exact - will do a case sensitive search /Names - will display the names of all files searched The default is to edit files read only. $ p1 := "" $ p2 := "" $ p3 := "" $ $ ! Get input file(s)... $ $ 10: prompt_p3 = ((p1 .eqs. "") .and. (p2 .eqs. "") .and. (p3 .eqs. "")) $ if p1 .eqs. "" then inquire p1 "Enter the filename(s) to be searched" $ p1 = f$edit(p1,"collapse,upcase") $ 20: if p2 .eqs. "" then read/prompt="Search for: " sys$command p2 $ if prompt_p3 then inquire p3 "Edit or Read_only [E/R D:E]" $ if f$extract(0,1,f$edit(p3,"upcase")) .eqs. "E" then p3 := "Edit" $ if p3 .eqs. "" then p3 := "Read" $ p3 = f$edit(p3,"collapse,upcase") $ $ ! Process the file(s)... $ $ element_number = 0 $ $ 100: $ element = f$element(element_number,",",p1) $ if element .eqs. "," then goto exit $ $ file = f$extract(0,f$locate("/",element),element) $ if f$parse(file,,,,"syntax_only") .nes. "" then goto 105 $ say "%GBLSEARCH-W-INVFILE, ''file' is not a valid filename." $ element_number = element_number + 1 $ goto 100 $ 105: $ switch = f$extract(f$locate("/",element),f$length(element),element) $ $ confirm = f$locate("/C",switch) .ne. f$length(switch) $ if .not. confirm then goto 110 $ beg = f$extract(0,f$locate("/C",switch),switch) $ end = f$extract(f$locate("/C",switch)+2,- f$length(switch),switch) $ end = f$extract(f$locate("/",end),f$length(end),end) $ switch = beg + end $ 110: $ names = f$locate("/N",switch) .ne. f$length(switch) $ if .not. names then goto 120 $ beg = f$extract(0,f$locate("/N",switch),switch) $ end = f$extract(f$locate("/N",switch)+2,- f$length(switch),switch) $ end = f$extract(f$locate("/",end),f$length(end),end) $ switch = beg + end $ 120: $ exact_flag = f$locate("/E",switch) .ne. f$length(switch) $ if .not. exact_flag then goto 130 $ beg = f$extract(0,f$locate("/E",switch),switch) $ end = f$extract(f$locate("/E",switch)+2,- f$length(switch),switch) $ end = f$extract(f$locate("/",end),f$length(end),end) $ switch = beg + end $ 130: $ if exact_flag then exact_text := "exact" $ if .not. exact_flag then exact_text := "no_exact" $ wild = (f$locate("*",file) .ne. f$length(file)) .or. - (f$locate("%",file) .ne. f$length(file)) .or. - (f$locate("...",file) .ne. f$length(file)) $ $ ! Find a file $ $ 200: this_file = f$search(file,97532) $ if this_file .eqs. "" then goto 400 $ this_file = this_file - f$parse(this_file,,,"version","syntax_only") $ $ ! Check for the search string $ if names then say "Searching in file: ",this_file $ assign/user nl: sys$output $ assign/user nl: sys$error $ search 'this_file "''p2'" $ if $status .ne. 1 then goto 300 $ $ if confirm then goto 220 $ if .not. names then say "File: ",this_file $ goto 230 $ 220: inquire/nopunc this_one - "File ''this_file' [Y/N/Q default=N]? " $ if (this_one .eqs. "Q") .or (this_one .eqs. "q") then goto exit $ if .not. this_one then goto 300 $ 230: $ open/write out sys$login:gblsubs_temp_file.tpu $ write out "" $ write out "procedure gbls$find_next" $ write out " on_error" $ write out " message('String not found');" $ write out " return;" $ write out " endon_error" $ write out " if (gbls$x_last_position <> 0) then " $ write out " move_horizontal(1) endif;" $ write out " search_range := search(""''p2'"",forward,''exact_text');" $ write out " position(beginning_of(search_range));" $ write out " gbls$x_last_position := mark(none);" $ write out "endprocedure" $ write out "" $ write out "procedure gbls$help" $ write out " if get_info(help_buffer,""type"") = UNSPECIFIED" $ write out " then" $ write out " help_buffer := create_buffer(""HELP"");" $ write out " set(eob_text,help_buffer,edt$x_empty);" $ write out " set(no_write,help_buffer);" $ write out " set(system,help_buffer);" $ write out " endif;" $ write out " set(status_line,info_window,bold," $ write out "' PF2 = APLTPU help = Resume editing'" $ write out " );" $ write out " set(width,info_window,get_info(screen,'width'));" $ write out " map(info_window,help_buffer);" $ write out " erase(help_buffer);" $ write out " position(beginning_of(current_buffer));" $ write out " split_line;copy_text(' ');" $ write out " split_line;copy_text(' The following keys have been defined in addition to the APLTPU keys:');" $ write out " split_line;copy_text(' ');" $ write out " split_line;copy_text(' CTRL/N - Find next occurance of *** ''p2' ***');" $ write out " split_line;copy_text(' ');" $ write out " split_line;copy_text(' PF2 - Help');" $ write out " split_line;copy_text(' ');" $ write out " position(beginning_of(current_buffer));" $ write out " update(info_window);" $ write out " loop" $ write out " wgb$x_learn_key := read_key;" $ write out " if wgb$x_learn_key = ctrl_f_key then" $ write out " unmap(info_window);" $ write out " return;" $ write out " endif;" $ write out " if wgb$x_learn_key = ret_key then" $ write out " unmap(info_window);" $ write out " return;" $ write out " endif;" $ write out " if wgb$x_learn_key = PF2 then" $ write out " wgb$help;" $ write out " return;" $ write out " endif;" $ write out " endloop;" $ write out "endprocedure" $ write out "" $ write out "" $ write out "define_key(""gbls$find_next"",ctrl_n_key);" $ write out "define_key(""gbls$help"",pf2);" $ write out "" $ write out "gbls$x_last_position := 0;" $ write out "gbls$find_next;" $ write out "" $ close out $ assign/user sys$command sys$input $ if p3 .eqs. "EDIT" then - edit/tpu/section=sys$library:apledtsecini- /command=sys$login:gblsubs_temp_file.tpu 'this_file''switch $ if p3 .nes. "EDIT" then - edit/tpu/section=sys$library:apledtsecini/read- /command=sys$login:gblsubs_temp_file.tpu 'this_file''switch $ delete/nolog sys$login:gblsubs_temp_file.tpu;0 $ $ 300: if wild then goto 200 $ $ 400: element_number = element_number + 1 $ goto 100 $ $ EXIT: $ clean_up = f$trnlnm("out") .nes. "" $ if clean_up then close out $ if clean_up then delete/nolog sys$login:gblsubs_temp_file.com;0 $ verify = f$verify(verify) $ exit