home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.programmer
- Path: sparky!uunet!stanford.edu!leland.Stanford.EDU!schemers
- From: schemers@leland.Stanford.EDU (Roland Schemers)
- Subject: pathname "cleanup" routine
- Message-ID: <1992Sep10.043443.20693@leland.Stanford.EDU>
- Sender: news@leland.Stanford.EDU (Mr News)
- Organization: Distributed Computing Group, Stanford University
- Date: Thu, 10 Sep 92 04:34:43 GMT
- Lines: 37
-
- Before I reinvent the wheel, does anyone have or know of a
- pathname "cleanup" function that will do the following:
-
- Remove "/../" and "/./" and "//" from a path.
- Expand ~ and environment variables.
- Add leading "/" if not present.
-
- It shouldn't check for the existence of the file, just cleanup the
- path.
-
- Examples:
-
- input output
- ------------- ---------
- ///../tmp /tmp
- ///../tmp/../bar /bar
- ~foo/stuff /u/foo
- bar /u/foo/bar (current dir is /foo/u)
- /usr/./bin /usr/bin
- $HOME/$MACHINE /u/foo/mips
-
- Seems like a simple state machine might do it.
- Note I can't just pass it off to csh since I want to clean
- up stuff like "/../" also.
-
- thanks, Roland
- --
- Roland J. Schemers III | Networking Systems
- Systems Programmer | 168 Pine Hall (415)-723-6740
- Distributed Computing Group | Stanford, CA 94305-4122
- Stanford University | schemers@Slapshot.Stanford.EDU
-
- --
- Roland J. Schemers III | Networking Systems
- Systems Programmer | 168 Pine Hall (415)-723-6740
- Distributed Computing Group | Stanford, CA 94305-4122
- Stanford University | schemers@Slapshot.Stanford.EDU
-