home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 18.ddi / reloc.2 / $INTFBIN / ckfile < prev    next >
Encoding:
Text File  |  1990-12-08  |  1.4 KB  |  80 lines

  1. #    Copyright (c) 1990 UNIX System Laboratories, Inc.
  2. #    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T
  3. #      All Rights Reserved
  4.  
  5. #    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF
  6. #    UNIX System Laboratories, Inc.
  7. #    The copyright notice above does not evidence any
  8. #    actual or intended publication of such source code.
  9.  
  10. #ident    "@(#)/usr/sadm/sysadm/bin/ckfile.sl 1.1 4.0 12/08/90 5497 AT&T-USL"
  11.  
  12. # ckfile - validate a file name according to the type
  13. #       Input: $1 - type of file (e.g. command, device, regular and pipe)
  14. #          $2 - file name
  15.  
  16. UNKNOWN=-1    # unknown type
  17. OK=0        # everything is ok
  18. NOTHING=1    # nothing entered
  19. NOTFULLPATH=2    # not full path name
  20. NOTEXIST=3    # not exist
  21. NOTEXEC=4     # not executable
  22. NOTCHARDEV=5     # not chacracter device
  23. NOTREG=6     # not a regular file
  24. NOTPIPE=7     # not a pipe
  25.  
  26. # nothing entered
  27. test -z "$1" && exit $NOTHING
  28. if [ "$1" = regular ]
  29. then
  30.     test -z "$2" && exit $OK
  31. else
  32.     test -z "$2" && exit $NOTHING
  33. fi
  34. type=$1
  35. eval set $2
  36. case $1 in
  37.     /*)    ;;
  38.     *)    exit $NOTFULLPATH;;
  39.         
  40. esac
  41.  
  42. lsfile=`ls $1 2>/dev/null`
  43.  
  44. if test -z "$lsfile"
  45. then
  46.     exit $NOTEXIST
  47. fi
  48.  
  49. case $type in
  50.     command)
  51.         if [ -f "$1" -a -x "$1" ]
  52.         then
  53.             exit $OK
  54.         else
  55.             exit $NOTEXEC
  56.         fi;;
  57.     device)
  58.         if [ -c "$1" ]
  59.         then
  60.             exit $OK
  61.         else
  62.             exit $NOTCHARDEV
  63.         fi;;
  64.     regular)
  65.         if [ ! -f "$1" ]
  66.         then
  67.             exit $NOTREG
  68.         else
  69.             exit $OK
  70.         fi;;
  71.     pipe)
  72.         if [ -p "$1" ]
  73.         then
  74.             exit $OK
  75.         else
  76.             exit $NOTPIPE
  77.         fi;;
  78.     *)    exit $UNKNOWN;;
  79. esac
  80.