home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume3 / modgen / getpath next >
Encoding:
Text File  |  1986-11-30  |  1.5 KB  |  45 lines

  1. #!/bin/csh -f
  2. #   1 Dec 85 Tim Radzykewycz: as released
  3. #   2 Jan 86 Robert Adams: removed debugging, parameterized things, commented
  4. #
  5. set BANG = '\!'
  6. set PathFile = "/usr/spool/uumap/paths"
  7. #
  8. #  Find host name and user name.  This should be able to parse
  9. #  addresses of the form uname@host and host!uname, and the
  10. #  first form should have priority, so that the combined
  11. #  form 'host1!uname@host0' can be used.
  12. #  Notice that this doesn't know about domaining!  In fact, it
  13. #  strips any internet type domaining out before doing the host
  14. #  search in the PathFile.
  15. #
  16. #  Invocation is:  getpath address
  17. #  where getpath will output to standard out the path to the
  18. #  user found in the PathFile.  If no path is found, the
  19. #  unmodified path is output.  If no "address" is given, getpath
  20. #  reads it from standard input.
  21. #
  22. echo $1 | sed 's/\..*//' > /tmp/$$
  23. if ("$1" == "") then
  24.     echo $< | sed 's/\..*//' > /tmp/$$
  25. endif
  26. grep -s '@' /tmp/$$
  27. # if there were matches, use form 'uname@host'
  28. if ($status == 0) then
  29.     set host = `sed -e "s/.*@//" /tmp/$$`
  30.     set uname = `sed -e "s/${host}//" -e "s/@//" /tmp/$$`
  31. else
  32.     set host = `sed -e "s/${BANG}.*//" /tmp/$$`
  33.     set uname = `sed -e "s/${host}//" -e "s/${BANG}//" /tmp/$$`
  34. endif
  35. #
  36. #  Now, find the path to that host, and tack on the uname
  37. #  to the end of it.
  38. set e_path = `grep "^${host}    " $PathFile`
  39. set uupath=`echo ${e_path} | sed -e 's/.*[     ]//' -e "s/%s/${uname}/" | sed -e "s/${BANG}${BANG}/${BANG}/g"`
  40. if ("$uupath" == "") then
  41.     set uupath=`cat /tmp/$$`
  42. endif
  43. echo $uupath
  44. rm -f /tmp/$$
  45.