#!/bin/sh # Make a tags file for Fortran routines. info() { cat <<-END Use: `basename $0` [-m] [-_] file... Purpose: create a tags file for Fortran files. Restrictions: the Fortran word "function" or "subroutine" must be space- or tab-delimited on the left, and appear on the same line as the routine name. Options: -m merge into existing tags file (default is to replace it). -_ For all routines "xxx_", make a duplicate entry "xxx". END } case $# in 0 ) info ; exit ;; esac merge=no strip=no for opt in "$@" do case "$opt" in -m ) merge=yes ; shift ;; -h ) info ; exit 0 ;; -_ ) strip=yes ; shift ;; -* ) echo "`basename $0`: Invalid option $opt" ; exit 1 ;; * ) break ;; esac done if [ $merge = no -a -f tags ] ; then rm tags ; fi for file in "$@" do sed -n -e \ '/^[ ][ ]*[Ss][Uu][Bb][Rr][Oo][Uu][Tt][Ii][Nn][Ee][ ]*\([a-zA-Z_0-9]\)/ {s?.*?/^&$/?;h;s/.*[Ss][Uu][Bb][Rr][Oo][Uu][Tt][Ii][Nn][Ee][ ]*\([a-zA-Z_0-9][a-zA-Z_0-9]*\).*/\1/;G;s/\n/ @@@@@ /;p }' \ -e '/^[ ][ ]*[a-zA-Z_0-9*]*[ ]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ ]*\([a-zA-Z_0-9]\)/ {s?.*?/^&$/?;h;s/.*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ ]*\([a-zA-Z_0-9][a-zA-Z_0-9]*\).*/\1/;G;s/\n/ @@@@@ /;p }' \ -e '/^[ ][ ]*[a-zA-Z_0-9*]*[ ]*[a-zA-Z_0-9]*[ ]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ ]*\([a-zA-Z_0-9]\)/ {s?.*?/^&$/?;h;s/.*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ ]*\([a-zA-Z_0-9][a-zA-Z_0-9]*\).*/\1/;G;s/\n/ @@@@@ /;p }' \ $file | sed "s@@@@@$file" >> tags done f=/usr/tmp/tags.$$ sort tags > $f case $strip in yes ) sed -n -e \ 'h;/^[a-zA-Z_0-9][a-zA-Z_0-9]*_[ ]/s/\([a-zA-Z_0-9][a-zA-Z_0-9]*\)_[ ]/\1 /p;g;p' $f >\ tags ;; * ) cp $f tags ;; esac rm $f