PARM cmd='', entry=main # This script finds all occurrences of "cmd" as a UDC, script or program in # HPPATH. Wildcards are supported for UDC, program and command file names. # Note: a cmd like "foo.sh" is treated as a POSIX name, not a qualified # MPE name. if "!entry" = "main" then errclear if '!cmd' = "" then echo Usage: ':where cmd' ("cmd" can be wildcarded) echo Finds all occurrences of "cmd" as a UDC, script or program file echo Example: where @grep return endif setvar _wh_cmd "!cmd" if delimpos(_wh_cmd,"./") = 1 then echo WHERE requires the POSIX cmd to be unqualified. return endif # see if the command could be a UDC (wildcards are supported) setvar _wh_udc_ok (delimpos(_wh_cmd,'._') = 0) # see if the command could be an MPE filename (wildcards ok, and # MPE names cannot be qualified at all) setvar _wh_mpe_ok (delimpos(_wh_cmd,'._') = 0) ## All command values are assumed to be ok as a POSIX filename. ## The dash (-) char is excluded above since it could be in a [a-z] pattern # check for UDCs first if _wh_udc_ok then continue showcatalog >whereudc if cierror = 0 then xeq !hpfile !_wh_cmd entry=process_udcs 0 # loop through HPPATH setvar _wh_i 0 while setvar(_wh_tok,word(hppath,',; ',setvar(_wh_i,_wh_i+1)))<>'' do if delimpos(_wh_tok,'./') = 1 then # we have a POSIX path element # must explicitly reference _wh_tok since it could be "!hpcwd" setvar _wh_tok "!_wh_tok/!_wh_cmd" elseif _wh_mpe_ok then # we have an MPE syntax HPPATH element with an unqualified _tok # must explicitly reference _wh_tok since it could be "!hpgroup" setvar _wh_tok "!_wh_cmd.!_wh_tok" endif errclear if _wh_wild then continue listfile !_wh_tok,6 >prntlf elseif finfo(_wh_tok,'exists') then # write to same output file as listfile uses above echo ![fqualify(_wh_tok)] >prntlf else setvar hpcierr -1 endif if hpcierr = 0 then # at least one match xeq !hpfile !_wh_tok entry=process_listf = 0 do if lft(setvar(_wh_rec,rtrim(input())),1) = " " then # a UDC command name line if pmatch(ups(_wh_cmd),setvar(_wh_tok,word(_wh_rec))) then # display: UDC_command_name UDC_level UDC_filename echo !_wh_tok ![rpt(" ",26-len(_wh_tok))] & ![setvar(_wh_tok2,word(_wh_rec,,-1))+rpt(" ",7-len(_wh_tok2))] & UDC in !_wh_udcf endif else # a UDC filename line setvar _wh_udcf _wh_rec endif endwhile return elseif "!entry" = "process_listf" then # input redirected from the output of listfile,6 or a simple filename setvar _wh_eof finfo(hpstdin,'eof') while setvar(_wh_eof,_wh_eof-1) >= 0 do setvar _wh_fc "" if setvar(_wh_fc, & finfo(setvar(_wh_tok,ltrim(rtrim(input()))),'fmtfcode')) = "" setvar _wh_fc 'script' elseif _wh_fc <> 'NMPRG' and _wh_fc <> 'PROG' then setvar _wh_fc "" endif if _wh_fc <> "" and finfo(_wh_tok,'eof') > 0 then setvar _wh_lnk '' if finfo(_wh_tok,'filetype') = 'SYMLINK' then setvar _wh_fc 'symlink' # get target of the symlink file lf7tmp;msg continue listfile !_wh_tok,7 >*lf7tmp if hpcierr = 0 then # discard first 4 records input _wh_lnk <*lf7tmp input _wh_lnk <*lf7tmp input _wh_lnk <*lf7tmp input _wh_lnk <*lf7tmp input _wh_lnk <*lf7tmp setvar _wh_lnk "--!> " + word(_wh_lnk,,-1) endif endif # display: qualified_filename file_code or "script" and link if any echo !_wh_tok ![rpt(" ",max(0,26-len(_wh_tok)))] !_wh_fc & ![rpt(" ",7-len(_wh_fc))] !_wh_lnk endif endwhile return endif