Annotation of 43BSDTahoe/new/help/src/f77/xref, revision 1.1.1.1

1.1       root        1: #      /bin/csh -f
                      2: more << 'EOT'
                      3: ##nroff
                      4: .TI F77/XREF "Oct. 15, 1984"
                      5: Cross References for F77 Programs
                      6: .ds CF
                      7: 
                      8: .nf
                      9: The f77 compiler does not produce listings or cross references.
                     10: This help file generates a cross reference for an f77 program.
                     11: To get a corresponding listing of the program including line
                     12: numbers, use 'cat -n'.
                     13: 
                     14: The script is simple-minded and assumes:
                     15: 
                     16: 1.  Blanks are significant, i.e. there are no blanks in the middle
                     17:     of variable names, command keywords, and statement numbers.
                     18: 2.  Names, keywords, statement numbers and strings are not split
                     19:     across lines.
                     20: 
                     21: The script is easily confused by:
                     22: 
                     23: 1.  Counted Holleriths outside of format statements.
                     24: 2.  The presence of both " and ' in the same line outside of format
                     25:     statements.
                     26: 
                     27: All alphanumeric strings starting with a letter are tallied in the
                     28: cross reference.  The script can not tell the difference between
                     29: \&'do', 'if', ..  used as keywords or as variable names.  Since f77
                     30: allows 16 character names, even 'continue' and 'equivalence' could
                     31: be variable names.
                     32: 
                     33: Similarly, if a number is used both as a statement number and as an
                     34: integer, both uses are tallied.
                     35: 
                     36: The script is very slow, about 3 lines/second on a VAX 750.
                     37: 
                     38: ##
                     39: 'EOT'
                     40: echo -n "enter input file name, carriage return to exit: "
                     41: set in_file = $<
                     42: if( $in_file == '' ) then
                     43:        exit(0)
                     44: endif
                     45: echo -n "enter output file name, carriage return to exit: "
                     46: set out_file = $<
                     47: if( $out_file == '' ) then
                     48:        exit(0)
                     49: endif
                     50: if( $out_file !~ /* ) then
                     51:        set out_file = `pwd`/${out_file}
                     52: endif
                     53: echo -n "enter 'y' if input file has sequence information in columns 73-80: "
                     54: if( $< =~ y* ) then
                     55:        set sequencing = "yes"
                     56: else
                     57:        set sequencing = "no"
                     58: endif
                     59: #
                     60: unset time
                     61: set dir = /tmp/f77_xref$$
                     62: /bin/rm -f -r $dir
                     63: mkdir $dir
                     64: #
                     65: #      via 'sed': replace comment lines by null lines
                     66: #              replace 0 in col. 6 by " "
                     67: #              replace contin. char in col. 6 by '_' in col. 1
                     68: #              delete strings:  "..."  or  '...'
                     69: #              add spaces around "format" so it'll be separate awk field
                     70: #
                     71: cat << 'EOT'  >! $dir/sed1
                     72: /^[cC*]/s/^.*$//
                     73: /^     0/s// /
                     74: /^     [^ ]/s//_ /
                     75: /".*"/s/"[^"]*"/ /g
                     76: /'.*'/s/'[^']*'/ /g
                     77: /format/s// format /g
                     78: 'EOT'
                     79: if( $sequencing == "yes" ) then
                     80:        colrm 73 < $in_file | sed -f $dir/sed1  >! $dir/step1
                     81: else
                     82:        sed -f $dir/sed1 < $in_file  >! $dir/step1
                     83: endif
                     84: #      now blank out format statements including continuation cards
                     85: #      also save numbers in statement number field in file 'labels'
                     86: cd $dir
                     87: cat << 'EOT'  >! awk1
                     88: { if ( $2 == "format" ) {
                     89:        print $1;
                     90:        print "%" $1 >> "labels";
                     91:        prev = "format";
                     92:   } else if ( ( $1 == "&" || $1 == "_") && prev == "format" ) {
                     93:        print " ";
                     94:   } else if ( length == 0 ) {
                     95:        print ;
                     96:   } else {
                     97:        c1 = substr( $1, 1, 1 );
                     98:        if( c1 >= "0" && c1 <= "9" ) print "%" $1 >> "labels";
                     99:        print ;
                    100:        prev = " ";
                    101:   }
                    102: }
                    103: 'EOT'
                    104: cat /dev/null >! labels
                    105: awk -f awk1  < step1 >! step2
                    106: #      tr: get rid of special characters
                    107: #      awk: add line number to each word and split into one word/line
                    108: #      then sort and get count of dups
                    109: cat << 'EOT' >! awk2
                    110: { { for ( i = 1; i <= NF; i++ ) print $i , NR } }
                    111: 'EOT'
                    112: tr  -cs 'A-Za-z0-9\012' ' ' < step2  | awk -f awk2 | sort +0 -1 +1n labels - |     uniq -c >! step3
                    113: #      print it out, one word + references per line
                    114: cat << 'EOT' >! awk3
                    115: { c1 = substr($2,1,1);
                    116:   use = "y";
                    117:   if ( c1 == "%" ) {                   # label definition
                    118:        $2 = substr($2,2,length($2));
                    119:        labels[ $2 ] = "y";
                    120:        use = "";
                    121:   } else if ( c1 >= "0" && c1 <= "9" && labels[ $2 ] == "" )
                    122:        use = "";       # starts with digit, but not a label.
                    123:   if ( use != "" ) {
                    124:      if ( $2 == prev ) {
                    125:        if ( length(refs) > 66 ) {
                    126:                print refs;
                    127:                refs = prev " (cont.)   ";
                    128:        }
                    129:      } else {
                    130:                prev = $2;
                    131:                print refs;
                    132:                refs = $2 "     ";
                    133:      }
                    134:      refs = refs " " $3;
                    135:      if( $1 != 1 ) refs = refs "(" $1 ")";
                    136:   }
                    137: }
                    138: END { if( refs != "" ) print refs; }
                    139: 'EOT'
                    140: awk -f awk3 < step3 | sort -n >! $out_file
                    141: /bin/rm -f -r $dir

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.