#! /bin/csh -f set usage = "$0 -maxlen MAX -title TITLE < INFILE.idx > OUTFILE.html" while ( ( $#argv > 0 ) && ( "x$1" =~ x-* ) ) if ( ( $#argv >= 2 ) && ("x$1" == "x-maxlen" ) ) then set maxlen = "$2"; shift; shift; else if ( ( $#argv >= 2 ) && ("x$1" == "x-title" ) ) then set title = "$2"; shift; shift; else echo "usage: ${usage}"; exit 1 endif end if ( $#argv != 0 ) then echo "usage: ${usage}"; exit 1 endif cat html-header.html \ | sed -e 's"@TITLE@"'"${title}"'"g' \ | sed -e 's/@DATE@/'"`date +'%Y-%m-%d %H:%M:%S'`"'/g' echo "" echo "
"

cat \
  | gawk \
      -v maxlen=${maxlen} \
      ' function pr(sec, loc, tr, str, defn) \
          { printf "%-8s %-12s %s %s  %s\n", \
              sec, loc, tr, str, defn; \
          } \
        \
        function rp(ch, n, str) \
          { n-=length(str); \
            while (n > 0) { n--; str = (str ch); } \
            return str; \
          } \
        \
        BEGIN { \
          FS="|"; oloc=""; \
          pr("sec", "location", "T:", \
             ("" rp(" ", maxlen, "text") ""), \
             "object (class) comments"); \
          pr(rp("-", 8), rp("-", 12), "--", rp("-", maxlen), rp("-", 30)); \
        } \
        /./ { \
          loc = ($3 "." $4 "." $5); \
          if ((loc!=oloc)&&(oloc!="")) { printf "\n"; } \
          pr( (loc != oloc ? $2 : ""), \
              (loc != oloc ? loc : ""), \
              ($6 ":"), ("" rp(" ", maxlen, $7) ""), \
              ($10 " (" $9 ") " $11 "")); \
          oloc = loc; \
        } \
      '

echo "
" echo "
" cat html-trailer.html