home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / mutt / load.mut < prev    next >
Text File  |  1988-10-24  |  2KB  |  52 lines

  1.   ;; load.mut : load with path search
  2.   ;; Load a file, searching along a set of paths (in this case the paths
  3.   ;;   are held in a env var).  The env var is list:  each path is
  4.   ;;   separated by a ":"  (UNIX) or ";" (MS-DOS) (see APATH below).  Each
  5.   ;;   path elment is assumed to end with a "/".  (If MS-DOS, the separater
  6.   ;;   can be a "\").  See the example below.
  7.   ;; Notes:
  8.   ;;   If you want to search the current directory and the directory in the
  9.   ;;     ME env var, put "::" in the path or end the path with ":".
  10.   ;;   Don't put multiple paths in the ME env var because it will confuse
  11.   ;;     (load) and your init file probably won't be loaded, etc.
  12.   ;;   The directories are searched in order.
  13.   ;;   It is somewhat sleazy to have to use 2 env vars for load.  If this
  14.   ;;     functionality is really needed, it should be built into ME but I
  15.   ;;     only see this being useful on multiuser or LANed systems and it
  16.   ;;     seems to work OK ...
  17.   ;; Example:  To search "/foo" and "/bar" use "MES=/foo/:/bar/".  The
  18.   ;;   current directory is not searched, nor is the directory in $ME.  To
  19.   ;;   include .  and $ME, use "MES=/foo/:/bar/:"  or "MES=:/foo/:/bar/" or
  20.   ;;   "MES=/foo/::/bar/".
  21.   ;; C Durland  10/88
  22.  
  23. (const
  24.     ;; RE to pick out a path: 
  25.   APATH '\([^:]*\):'    ;; '\([^:]*\):' for UNIX, '\([^;]*\);' for MS-DOS
  26.   PATH-ENV-VAR "MES"    ;; env var that holds the path
  27. )
  28.  
  29. (defun
  30.   load-with-path-search
  31.   {
  32.     (string path 200 fname 100)
  33.  
  34.     (fname (ask "Load (with path search): "))
  35.     (path (getenv PATH-ENV-VAR))
  36.     (while TRUE
  37.     {
  38.       (arg-prefix 1)    ; don't complain if not found (I'll do it myself)
  39.       (if (RE-string APATH path)
  40.         { (if (load (concat (get-matched '\1') fname)) (done)) }
  41.     {
  42.       (if (load (concat path fname))
  43.         ()    ; TRUE
  44.         { (msg 'Could not load "' fname '".') FALSE })
  45.       (done)
  46.     }
  47.       )
  48.       (path (substr path (+ 1 (strlen (get-matched '\1'))) 1000))
  49.     })
  50.   }
  51. )
  52.