home *** CD-ROM | disk | FTP | other *** search
/ HTML - Publishing on the Internet / html_cdrom.iso / tools / html / windows / check / runachek.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1995-02-19  |  5KB  |  123 lines

  1. #!/bin/sh
  2. #
  3. # Shell script to run HTML cross-reference checking with htmlchek.awk
  4. #
  5. case `type gawk` in *gawk ) awkntrp='gawk';;
  6.                         * ) case `type nawk` in *nawk ) awkntrp='nawk';;
  7.                                                     * ) awkntrp='awk';;
  8.                             esac;;
  9. esac
  10. case ${HTMLCHEK:-"/"}
  11.     in */ );;
  12.        * ) HTMLCHEK="$HTMLCHEK/";;
  13. esac
  14. if test $# -lt 2
  15. then
  16.     echo "
  17.  Syntax is:  $0 directoryprefix outfileprefix [directory] [options]
  18. " >&2
  19. cat >&2 << '_EOHERE_'
  20.  The optional third parameter specifies the top directory of the tree in which
  21. all .html files are to be checked (for example, "$HOME/public_html"); if this
  22. is not present, then the current directory is used.  The first parameter
  23. ``directoryprefix'' is how this top directory is referenced in <...HREF="...">
  24. links in files in subordinate directories in the tree (for example, as
  25. "/~myself/" or "http://myhost.edu/~myself/").  If the files you are checking
  26. refer to each other only with simple relative URL's (i.e. with no access
  27. method or hostname specified, and not beginning with `/'), then you can get
  28. away with specifying ``directoryprefix'' as a null string ('').
  29.  
  30.  The second parameter ``outfileprefix'' is the name of the files (with the
  31. extensions ".NAME", ".HREF", ".SRC", and ".ERR") in which the ouput of the
  32. HTML-checking and cross-referencing process will be put.  And finally, the
  33. optional parameters are all of the form "option=value", as explained in the
  34. docs.  So the following are some typical command lines (putting
  35. _EOHERE_
  36.  echo "$0 first in a command, as in the first example, implies that
  37. you have set execute permission by running \"chmod +x $0\"):
  38.  
  39.   $0  http://uts.cc.utexas.edu/~churchh/  check
  40.  
  41.   sh  $0  ''  out  \$HOME/public_html  html3=1" >&2
  42.     exit 1
  43. else
  44.     if test -s ${HTMLCHEK}htmlchek.awk
  45.     then
  46.      case $1
  47.      in *?=* ) echo "Error: dirprefix parameter  $1  is in option=value form" >&2
  48.                exit 1;;
  49.      esac
  50.      case $2
  51.      in *?=* ) echo "Error: outfilesname parameter  $2  is in option=value form" >&2
  52.                exit 1;;
  53.      esac
  54.     dprefix=$1
  55.     oprefix=$2
  56.     shift 2
  57.     if test $# -ge 1
  58.     then
  59.         case $1
  60.              in *=* ) targdir='';;
  61.                   * ) targdir=$1
  62.                       shift;;
  63.         esac
  64.     else
  65.         targdir=''
  66.     fi
  67.     case ${dprefix:-"/"}
  68.         in */ ) ;;
  69.             * ) dprefix="$dprefix/";;
  70.     esac
  71.     case $dprefix
  72.          in ?* ) dprefix="dirprefix=$dprefix";;
  73.              * ) ;;
  74.     esac
  75.     case $targdir
  76.         in */ ) echo "Error: Target directory name  $targdir  should not have trailing slash" >&2
  77.                 exit 1;;
  78.            ?* ) subopt="subtract=${targdir}/";;
  79.             * ) subopt='';;
  80.     esac
  81.     for px
  82.     do
  83.     case $px
  84.     in -?* ) echo "You are passing flags to the $awkntrp interpreter in argument $px" >&2
  85.              echo "(This may not be what you intended)" >&2;;
  86.     append=* | arena=* | cf=* | configfile=* | deprecated=* |\
  87.     dlstrict=* | html3=* | htmlplus=* | loosepair=* |\
  88.     lowlevelnonpair=* | lowlevelpair=* | map=* | metachar=* |\
  89.     netscape=* | nogtwarn=* | nonblock=* | nonpair=* |\
  90.     nonrecurpair=* | novalopts=* | nowswarn=* | reqopts=* |\
  91.     strictpair=* | sugar=* | tagopts=* | usebase=* ) ;;
  92.        * ) echo "Error: The argument  $px  is not in option=value form, where," >&2
  93.            echo "the part before the equals sign \`=' is a recognized option." >&2
  94.            exit 1;;
  95.     esac
  96.     done
  97.     echo "Checking all .html files in and under ${targdir:-`pwd`} now... (using $awkntrp)" >&2
  98. $awkntrp -f ${HTMLCHEK}htmlchek.awk $dprefix xref=1 refsfile=$oprefix $subopt $@ `find ${targdir:-"."} -name \*.html -print` > $oprefix.ERR
  99.     if test $? -ne 0
  100.     then echo "Note: there was apparently an error in running $awkntrp" >&2
  101.          echo "There may be an appropriate errormessage at the end of $oprefix.ERR" >&2
  102.          exit 1
  103.     fi
  104.     if test ! \( -s $oprefix.NAME -a -s $oprefix.HREF -a -s $oprefix.SRC -a -s $oprefix.ERR \)
  105.     then echo "Was some error on output files; Exiting..." >&2
  106.          exit 1
  107.     fi
  108.     echo "Errorcheck data is in the file $oprefix.ERR; locations in the specified
  109.  files which are not referenced from the files are in $oprefix.NAME,
  110.  references from the specified files which are not found in the files are
  111.  in $oprefix.HREF, and references to inline images are in $oprefix.SRC;
  112.  if the map=1 option was specified, cross-dependency information is in
  113.  $oprefix.MAP" >&2
  114.     else echo "
  115. htmlchek.awk is not found.  Either copy it to the current directory, or
  116. set the environment variable HTMLCHEK to the pathname where it is located.
  117. Do \`setenv HTMLCHEK /somedir/' in csh and tcsh, \`HTMLCHEK=/somedir/;
  118. export HTMLCHEK' in sh and its offspring." >&2
  119.          exit 1
  120.     fi
  121. fi
  122. exit 0
  123.