home *** CD-ROM | disk | FTP | other *** search
- #! /bin/sh
-
- ignoreset=""
- SEPERATEFILES=1;
- DEBUG=0;
-
- while getopts sdI: c
- do
- case $c in
- I) ignorefile=$OPTARG;
- ignoreset='"'`cat $ignorefile`'"';
- echo ignorefile=$ignorefile $ignoreset;;
- s) SEPERATEFILES=1;
- echo seperatefiles=$SEPERATEFILES;;
- d) DEBUG=1;
- echo debug=$DEBUG;;
- esac
- done
- shift `expr $OPTIND - 1`
-
- infile=$1
-
- if test -f $infile
- then
- echo infile=$infile
- else
- echo "can't find infile="$infile
- exit
- fi
-
- sed 's/OUT/\&__tmpi__/g' $infile |
- nawk '
-
- function initfile(fname) {
- printf "\n\n" > fname;
- }
-
- function initframe(framenum)
- {
- if ( framenum == 0 ) {
- if ( changefile == 1 ) {
- currentfile = tname"_init";
- }
- initfile(currentfile);
- filelist = filelist" "currentfile;
- printf "/* %s_init */\n\n", tname >> currentfile;
- } else {
- prevframe = framenum - 1;
- printf "\n/* end frame %d */\n\n", prevframe >> currentfile;
- if ( changefile == 1 ) {
- currentfile = tname"_frame"framenum;
- initfile(currentfile);
- filelist = filelist" "currentfile;
- }
- printf "/* %s_frame%d\n */\n\n",tname,framecount >> currentfile;
- }
- }
-
- BEGIN {
-
- FS = "("; # seperates commands=$1 from args=$2
- framecount = 0;
- init = 0;
- currentfile = tname;
- filelist = "";
- }
- {
- cmd = $1;
-
-
- # dump out comments
- if ( substr($1,1,2) == "/*" ) {
- # printf "\t%s\n", $0 >> currentfile;
- next;
- }
-
- if ( init == 0 ) {
- init = 1;
- initframe(framecount);
- }
-
- # check against ignore file
- if ((cmd != "") &&
- ((ignorefile == "") ||
- ((system("fgrep -s" cmd " " ignorefile)) == 1 )))
- {
- print $0 >> currentfile;
- }
-
- # set flags for new frame
- if (cmd == "swapbuffers") {
- framecount += 1;
- init = 0;
- }
- }
-
- END {
- # close last block
- framecount = framecount - (1.0 - init);
- printf "\n/* end frame %d */\n\n", framecount >> currentfile;
- }
- ' tname=$1 changefile=$SEPERATEFILES debug=$DEBUG ignorefile=$ignorefile
-