#!/bin/bash #
# Script : crindex # Version : 2.0 # Author : Roland Rashleigh-Berry # Date : 07-Feb-2007 # Purpose : To create an index of macros or scripts with standard headers # (uses SAS). # SubScripts : justhdr, crindex_win # Notes : Output goes to standard output # Usage : crindex * > @index.txt # crindex *.sas > @index.txt #=============================================================================== # PARAMETERS: #-pos- -------------------------------description------------------------------- # 1 File name(s) or file pattern(s) or combination #=============================================================================== # AMENDMENT HISTORY: # init --date-- mod-id ----------------------description------------------------ # rrb 24Nov05 -stdio used for sas invocation # rrb 06Feb07 Call crindex_win for Windows configurations # rrb 07Feb07 Two more columns given to member name #=============================================================================== # This is public domain software. No guarantee as to suitability or accuracy is # given or implied. User uses this code entirely at their own risk. #=============================================================================== # Put out a usage message if not enough parameters supplied if [ $# -lt 1 ] ; then echo "Usage: crindex filename(s)" 1>&2 exit 1 fi # if a Windows config then call crindex_win and exit on return if [ -n "$CYGWIN" ] ; then crindex_win "$@" exit $? fi # extract just the headers justhdr $@ > ~/justhdr_$$.tmp # Feed SAS code into standard input sas -stdio -sasuser work 2>/dev/null << -----FINISH----- options validvarname=v7 nofmterr; data _crindex; length name $ 18 subgroup $ 16 text $ 80 line $ 200; retain fchar name subgroup " "; infile "~/justhdr_$$.tmp" pad eof=eof; getname: input @1 line \$char200.; if _n_=1 then fchar=substr(line,1,1); if substr(line,1,9) NE fchar||' Program' and substr(line,1,8) NE fchar||' Script' then goto getname; name: name=left(scan(line,2,':')); text=" "; subgroup=" "; text=" "; seq=0; prepurp: input @1 line \$char200.; if substr(line,1,9) NE fchar||' Purpose' then goto prepurp; subgroup="Purpose"; text=left(substr(line,index(line,':')+1)); seq=seq+1; output; input @1 line \$char200.; purpose: if substr(line,3,4) ne " " then goto preusage; text=left(substr(line,3)); seq=seq+1; output; input @1 line \$char200.; goto purpose; preusage: if substr(line,1,7) EQ fchar||' Usage' then goto usestart; input @1 line \$char200.; goto preusage; usestart: subgroup='Usage'; text=left(substr(line,index(line,':')+1)); seq=seq+1; output; input @1 line \$char200.; usage: if substr(line,1,8)=fchar||"=======" then goto endxxx; text=left(substr(line,2)); seq=seq+1; output; input @1 line \$char200.; goto usage; endxxx: return; drop line; eof: stop; run; proc sort data=_crindex; by name subgroup seq; run; data _null_; file stdout; set _crindex; by name subgroup; if _n_ EQ 1 then do; put @1 'Index of members in this directory with standard headers'; put @1 '========================================================'; put @1 '(this list was generated by the crindex script)'; end; if first.name then put / @1 name @20 '- ' text; else if first.subgroup then put / @22 subgroup +(-1) ": " text; else put @22 text; run; -----FINISH----- rm -f ~/justhdr_$$.tmp