# library.def: Defines Common Macros # $Id: library.def,v 1.34 2008/02/25 13:16:13 mschenke Exp $ # ARCS: $Header: /home/cvs/repository/RDA_4/src/scripting/lib/modules/library.def,v 1.34 2008/02/25 13:16:13 mschenke Exp $ # # Change History # 20080225 MSC Improve the documentation. =head1 NAME library - Defines Common Macros =head1 DESCRIPTION This persistent sub module regroups macros that are common to several modules. The following macros are available: =cut # Make the module persistent and share macros keep $KEEP_BLOCK,@SHARE_MACROS var @SHARE_MACROS = ('cat_file','cat_report','cat_search',\ 'head_file','head_report',\ 'search_files','sort_files','sort_shares',\ 'tail_file','tail_report') # Define the internal counter and duplicate file hash var ($CNT,%DUP) = (0) keep $CNT,%DUP =head2 S This macro inserts a file into the current report. =cut macro cat_file {var ($dir,$nam,$cmd,$alt) = @arg debug ' Inside cat_file, looking for ',$nam,' in ',$dir var $fil = catFile($dir,$nam) if testFile('f',$fil) {write '---+ Display of ',$nam,' File' write '---## Information Taken from ',$fil if $cmd var $flg = writeFilter($fil,$cmd,$alt) else var $flg = writeFile($fil) if !$flg {write '**',$nam,' not readable.**%BR%\ May be file permission problems.%BR%\ Permissions are:%BR%' call statFile('b',$fil) write 'User: ',id(),'%BR%' } } } =head2 S This macro generates a report from a file. =cut macro cat_report {var ($dir,$nam,$pre,$cmd,$alt) = @arg debug ' Inside cat_report, looking for ',$nam,' in ',$dir var $fil = catFile($dir,$nam) if testFile('f',$fil) {report concat(nvl($pre,''),$nam) write '---+ Display of ',$nam,' File' # Add the file in the report write '---## Information Taken from ',$fil if $cmd var $flg = writeFilter($fil,$cmd,$alt) else var $flg = writeFile($fil) if !$flg {write '**',$nam,' not readable.**%BR%\ May be file permission problems.%BR%\ Permissions are:%BR%' call statFile('b',$fil) write 'User: ',id(),'%BR%' } # Add it in the index toc '3:[[',getFile(),'][rda_report][',$nam,']]' } } =head2 S This macro generates a report from a file that is searched for in a directory list. =cut macro cat_search {var ($nam,$opt,$pre,$cmd,$alt) = @arg # On first call, initialize the directory list if !@dir {keep @dir var $ORACLE_HOME = getSetting('ORACLE_HOME','') var @dir = (\ catDir($ORACLE_HOME,'bin'),\ '/etc',\ '/var/opt/oracle',\ catDir($ORACLE_HOME,'network','admin'),\ catDir($ORACLE_HOME,'network','agent')\ ) if getEnv('TNS_ADMIN') {var $tns = last if isVms() {if compare('ne',lc($tns),lc($dir[3])) var $dir[5] = $tns } else {if compare('ne',$tns,$dir[3]) var $dir[5] = $tns } } } # Search the file in the directory list report concat(nvl($pre,''),$nam) var $flg = $opt var $top = true var $ttl = concat('---+ Display of ',$nam,\ ' File from all Well-Known Locations') loop $dir (@dir) {debug ' Inside cat_search, looking for ',$nam,' in ',$dir var $fil = catFile($dir,$nam) prefix {if $ttl {write $ttl var $ttl = undef } write '---## Information Taken from ',$fil if $top write '**Files from this location will override the contents for ',$nam,\ ' at every other location**' } if $cmd {if writeFilter($fil,$cmd,$alt) var $flg = true } else {if writeFile($fil) var $flg = true } var $top = false } unprefix # Display the permissions for mandatory files if !$flg {write $ttl write '**No readable ',$nam,' file found in any usual place.**%BR%\ May be file permission problems or file does not exist.%BR%' loop $dir (@dir) {var $fil = catFile($dir,$nam) write 'Permissions for ',$fil,' are:%BR%' if !statFile('b',$fil) write " ''File not found''%BR%" } write 'User: ',id(),'%BR%' } # Add it in the index if isCreated(true) toc '3:[[',getFile(),'][rda_report][',$nam,']]' } =head2 S This macro inserts the first lines of a file into the current report. =cut macro head_file {var ($dir,$nam,$lin) = @arg debug ' Inside head_file, looking for ',$lin,' first lines of ',$nam,\ ' in ',$dir var $fil = catFile($dir,$nam) if testFile('f',$fil) {write '---+ ',$lin,' First Lines of ',$nam,' File' write '---## Information Taken from ',$fil if !writeLines($fil,1,$lin) {write '**',$nam,' not readable.**%BR%\ May be file permission problems.%BR%\ Permissions are:%BR%' call statFile('b',$fil) write 'User: ',id(),'%BR%' } } } =head2 S This macro inserts the first lines of a file into a report. =cut macro head_report {var ($dir,$nam,$lin,$pre) = @arg debug ' Inside head_report, looking for ',$lin,' first lines of ',$nam,\ ' in ',$dir var $fil = catFile($dir,$nam) if testFile('f',$fil) {report concat(nvl($pre,''),$nam) write '---+ ',$lin,' First Lines of ',$nam,' File' write '---## Information Taken from ',$fil if !writeLines($fil,1,$lin) {write '**',$nam,' not readable.**%BR%\ May be file permission problems.%BR%\ Permissions are:%BR%' call statFile('b',$fil) write 'User: ',id(),'%BR%' } # Add it in the index toc '3:[[',getFile(),'][rda_report][',$nam,']]' } } =head2 S This macro looks in the specified directory and sub directories for all files that match the regular expression. When a number of lines is specified, only the final lines are collected. =cut macro search_files {var ($dir,$re,$lgt) = @arg import $CNT,$TOP keep $pre,$CNT,$TOP debug ' Inside search_files, looking for "',$re,'" in ',$dir if !$pre {import $ORACLE_HOME var $pre = concat('^',quote($ORACLE_HOME),'\b') } var $lst = '' loop $fil (grepDir($dir,$re,'dir')) {next !testFile('frT',$fil) # Check for a new section var $grp = dirname($fil) if compare('ne',$grp,$lst) {var $lst = $grp toc '3:',replace($grp,$pre,'$OH'),' ' } # Create the report associated with the file incr $CNT var $nam = basename($fil) report concat('log',$CNT,'_',$nam) if match($nam,'^USData.xml$',true) {write '---+ Display of ',$nam,' File' write '---## Information Taken from ',$fil call statFile('b',$fil) write '**File was not collected, because of the file size.**%BR%' } elsif $lgt {write '---+ Last ',$lgt,' Lines of ',$nam,' File' write '---## Information Taken from ',$fil call statFile('b',$fil) call writeTail($fil,$lgt) write $TOP } else {write '---+ Display of ',$nam,' File' write '---## Information Taken from ',$fil call statFile('b',$fil) call writeFile($fil) write $TOP } toc '4:[[',getFile(),'][rda_report][',$nam,']]' } } =head2 S This macro is equivalent to C. =cut macro sort_files return sort_shares(undef,@arg) =head2 S This macro uses the unsorted file list to generate links in the RDA menu structure for each directory and the files located in that directory. If the file name has the C<*.log> structure, it limits the lines collected to the last lines. When a non-empty string is specified as a share group, all produced reports are shared automatically using that group, specifying their file name as link text. A file is collected only once per module. The following occurrences are replaced by a link to the first one. =cut macro sort_shares {var ($shr,$lvl,$lgt,@fil) = @arg import $CNT,$TOP,%DUP,%LOG keep $pre,$CNT,$TOP,%DUP if !$pre {import $ORACLE_HOME var $pre = concat('^',quote($ORACLE_HOME),'\b') } # Filter the file list loop $fil (@fil) {if testFile('frT',$fil) {next match($fil,'\.(bmp|exe|gif|gz|ico|jar|jpe?g|wav|wbmp|zip)$',true) var $fil{join("\001",dirname($fil),basename($fil))} = $fil } } # Generate the reports and related index links var $lst = '' var $det = $lvl incr $det loop $fil (keys(%fil)) {var $fil = $fil{$fil} # Check for a new section var $grp = dirname($fil) if compare('ne',$grp,$lst) {var $lst = $grp toc $lvl,':',replace($grp,$pre,'$OH'),' ' } # Create the report associated with the file debug ' Inside sort_files, getting ',$fil var $nam = basename($fil) if missing($DUP{$fil}) {incr $CNT report concat('log',$CNT,'_',$nam) if $shr share $shr,$fil if match($nam,'^USData.xml$',true) {write '---+ Display of ',$nam,' File' write '---## Information Taken from ',$fil call statFile('b',$fil) write '**File was not collected, because of the file size.**%BR%' } elsif match($fil,'(logs?[\/\\]|log$)',true) {if exists($LOG{$fil}) var $cnt = $LOG{$fil} else var $cnt = $lgt if $cnt write '---+ Last ',$cnt,' Lines of ',$nam,' File' else write '---+ Display of ',$nam,' File' write '---## Information Taken from ',$fil call statFile('b',$fil) if $cnt call writeTail($fil,$cnt) else call writeFile($fil) write $TOP } else {write '---+ Display of ',$nam,' File' write '---## Information Taken from ',$fil call statFile('b',$fil) call writeFile($fil) write $TOP } var $DUP{$fil} = getFile() } toc $det,':[[',$DUP{$fil},'][rda_report][',$nam,']]' } } =head2 S This macro inserts the last lines of a file into the current report. =cut macro tail_file {var ($dir,$nam,$lin) = @arg debug ' Inside tail_file, looking for ',$lin,' last lines of ',$nam,\ ' in ',$dir var $fil = catFile($dir,$nam) if testFile('f',$fil) {write '---+ Last ',$lin,' Lines of ',$nam,' File' write '---## Information Taken from ',$fil if !writeTail($fil,$lin) {write '**',$nam,' not readable.**%BR%\ May be file permission problems.%BR%\ Permissions are:%BR%' call statFile('b',$fil) write 'User: ',id(),'%BR%' } } } =head2 S This macro inserts the last lines of a file into a report. =cut macro tail_report {var ($dir,$nam,$lin,$pre) = @arg debug ' Inside tail_report, looking for ',$lin,' last lines of ',$nam,\ ' in ',$dir var $fil = catFile($dir,$nam) if testFile('f',$fil) {report concat(nvl($pre,''),$nam) write '---+ Last ',$lin,' Lines of ',$nam,' File' write '---## Information Taken from ',$fil if !writeTail($fil,$lin) {write '**',$nam,' not readable.**%BR%\ May be file permission problems.%BR%\ Permissions are:%BR%' call statFile('b',$fil) write 'User: ',id(),'%BR%' } # Add it in the index toc '3:[[',getFile(),'][rda_report][',$nam,']]' } } =head1 COPYRIGHT NOTICE Copyright (c) 2002-2008, Oracle. All rights reserved. =head1 TRADEMARK NOTICE Oracle, JD Edwards, PeopleSoft, and Siebel are registered trademarks of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. =cut