# NCClib.def: Defines Common Macros for Network Charging and Control # $Id: NCClib.def,v 1.3 2012/04/17 10:26:38 mschenke Exp $ # ARCS: $Header: /home/cvs/cvs/RDA_4/src/scripting/lib/modules/NCClib.def,v 1.3 2012/04/17 10:26:38 mschenke Exp $ # # Change History # 20120405 KRA Improve get_chksum macro. =head1 NAME NCClib - Defines Common Macros for Network Charging and Control =head1 DESCRIPTION This persistent submodule regroups macros that are common to Network Charging and Control module. The following macros are available: =cut # Make the module persistent and share macros keep $KEEP_BLOCK,@SHARE_MACROS var @SHARE_MACROS = ('get_chksum','get_files','get_scripts','get_sum',\ 'sort_all_files','stat_tree') =head2 S This macro gathers the check sum information for the specified directory. =cut macro get_chksum {var ($dir,$lvl,$pre) = @arg import $TOP keep $TOP report chksum prefix {write "---+ '",$pre,"' Check Sum Information" write '| *Checksum*| *Size*|*Filename*|' } loop $fil (grepDir($dir,'^\.+$','npv')) {if testFile('fr',$fil) {var ($val) = command(concat('cksum ',quote($fil,'x'))) if ?$val {var ($chk,$siz,$pth) = split('\s+',$val,3) write '| ',$chk,'| ',$siz,'|',$pth,' |' } } } if isCreated(true) {write $TOP toc $lvl,':[[',getFile(),'][rda_report][Check Sum Information]]' } } =head2 S This macro gathers the plain files in the specified directories recursively (depth 10) and of size less than 2 MB. =cut macro get_files {var @fil = () loop $dir (@arg) {loop $fil (grepDir($dir,'^\.+$','drv',10)) {if and(testFile('fr',$fil),expr('<=',getSize($fil),2097152)) call push(@fil,$fil) } } return @fil } =head2 S This macro gathers the related script files for the specified directory. =cut macro get_scripts {var ($dir,$flg) = @arg var @fil = () loop $fil (grepDir($dir,'^\.+$','npv')) {next !testFile('fr',$fil) var ($lin) = command(concat('file ',quote($fil,'x'))) var (undef,$typ) = split('\:\s+',$lin,2) if $flg {if match($typ,'executable\s.*?\sscript|commands text') call push(@fil,$fil) } elsif or(match($fil,'\.(sh|awk|pl|sql)$'),\ match($typ,'executable\s.*?\sscript|commands text')) call push(@fil,$fil) } return @fil } =head2 S This macro gathers the sum information for the specified directory. =cut macro get_sum {var ($dir,$lvl,$pre) = @arg import $TOP keep $TOP report sum prefix {write "---+!! '",$pre,"' Sum Information" write '%TOC3-2%' } loop $fil (grepDir($dir,'^\.+$','npv')) {if testFile('fr',$fil) {write '---++ ',encode(basename($fil)) call statFile('b',$fil) write '---++++!! sum: (sum size filename)' call writeCommand(concat('sum ',quote($fil,'x'))) write $TOP } } if isCreated(true) toc $lvl,':[[',getFile(),'][rda_report][Sum Information]]' } =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. =cut macro sort_all_files {var ($lvl,$lgt,@fil) = @arg import $TOP,%DUP keep $TOP,%DUP # Filter the file list loop $fil (@fil) {var ($dir,$bas) = parseFile($fil) if testFile('frT',$fil) {var $fil{$dir,$bas} = $fil var $tbl{$dir,$bas} = $fil } elsif testFile('frB',$fil) {var $dat{$dir,$bas} = $fil var $tbl{$dir,$bas} = $fil } } # Generate the reports and related index links var $det = $lvl incr $det loop $grp (keys(%tbl)) {# Start a new section toc $lvl,':',encode(addSymbol($grp)),' ' # Treat each file loop $nam (keys($tbl{$grp})) {var $fil = $tbl{$grp,$nam} debug ' Inside sort_all_files, getting ',$fil if missing($DUP{$fil}) {report concat('log_',$nam) if exists($fil{$grp,$nam}) {if $lgt write '---+ Last ',$cnt,' Lines of ',encode($nam),' File' else write '---+ Display of ',encode($nam),' File' write '---## Information Taken from ',encode($fil) call statFile('b',$fil) if $lgt call writeTail($fil,$lgt) else call writeFile($fil) write $TOP } elsif exists($dat{$grp,$nam}) {write '---+ Display of ',encode($nam),' File' write ' * Links point to files that have been collected in their \ original format. Opening them directly in your browser can \ present risks. To prevent them, access the file outside the \ browser or use the link to save them and use an adequate \ viewer.' write '|*File Name*| *Size*|*Last Modified Date*|' var $lnk = encode($fil) if $siz = getSize($fil) {output b,concat('dat_',$nam) if ${CUR.LAST}->write_data($fil) var $lnk = concat('[[',${CUR.LAST}->get_raw(true),'][_blank][',$lnk,']]') end ${CUR.LAST} } write '|',$lnk,' | ',$siz,'|',\ getLastModify($fil,'%d-%b-%Y %H:%M:%S'),' |' } var $DUP{$fil} = getFile() } if $DUP{$fil} toc $det,':[[',last,'][rda_report][',encode($nam),']]' } } } =head2 S This macro lists the content of the specified directory recursively. =cut macro stat_tree {var ($dir) = @arg import $TOP keep $TOP if expr('>',statDir('n',$dir),0) write $TOP loop $pth (findDir($dir,'^\.+$','npv')) {next testFile('l',$pth) call stat_tree($pth) } } =head1 SEE ALSO L, L =head1 COPYRIGHT NOTICE Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. =head1 TRADEMARK NOTICE Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. =cut