home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / programm / 4605 < prev    next >
Encoding:
Text File  |  1992-09-09  |  1.7 KB  |  48 lines

  1. Newsgroups: comp.unix.programmer
  2. Path: sparky!uunet!stanford.edu!leland.Stanford.EDU!schemers
  3. From: schemers@leland.Stanford.EDU (Roland Schemers)
  4. Subject: pathname "cleanup" routine
  5. Message-ID: <1992Sep10.043443.20693@leland.Stanford.EDU>
  6. Sender: news@leland.Stanford.EDU (Mr News)
  7. Organization: Distributed Computing Group, Stanford University
  8. Date: Thu, 10 Sep 92 04:34:43 GMT
  9. Lines: 37
  10.  
  11. Before I reinvent the wheel, does anyone have or know of a
  12. pathname "cleanup" function that will do the following:
  13.  
  14. Remove  "/../" and "/./" and "//" from a path.
  15. Expand ~ and environment variables.
  16. Add leading "/" if not present.
  17.  
  18. It shouldn't check for the existence of the file, just cleanup the 
  19. path.
  20.  
  21. Examples:
  22.  
  23.       input          output
  24.    -------------    ---------
  25.    ///../tmp          /tmp
  26.    ///../tmp/../bar   /bar
  27.    ~foo/stuff         /u/foo
  28.    bar                /u/foo/bar  (current dir is /foo/u)
  29.    /usr/./bin         /usr/bin
  30.    $HOME/$MACHINE     /u/foo/mips
  31.  
  32. Seems like a simple state machine might do it.
  33. Note I can't just pass it off to csh since I want to clean
  34. up stuff like "/../" also.
  35.  
  36. thanks, Roland
  37. --
  38. Roland J. Schemers III              |            Networking Systems
  39. Systems Programmer                  |            168 Pine Hall   (415)-723-6740
  40. Distributed Computing Group         |            Stanford, CA 94305-4122
  41. Stanford University                 |            schemers@Slapshot.Stanford.EDU
  42.  
  43. -- 
  44. Roland J. Schemers III              |            Networking Systems
  45. Systems Programmer                  |            168 Pine Hall   (415)-723-6740
  46. Distributed Computing Group         |            Stanford, CA 94305-4122
  47. Stanford University                 |            schemers@Slapshot.Stanford.EDU
  48.