]> gitweb.factorcode.org Git - factor.git/blob - core/io/pathnames/pathnames-docs.factor
63a905d57805595813671f8eb426cb134e0c3eea
[factor.git] / core / io / pathnames / pathnames-docs.factor
1 USING: help.markup help.syntax io.backend io.files io.directories strings
2 sequences ;
3 IN: io.pathnames
4
5 HELP: path-separator?
6 { $values { "ch" "a code point" } { "?" "a boolean" } }
7 { $description "Tests if the code point is a platform-specific path separator." }
8 { $examples
9     "On Unix:"
10     { $example "USING: io.pathnames prettyprint ;" "CHAR: / path-separator? ." "t" }
11 } ;
12
13 HELP: parent-directory
14 { $values { "path" "a pathname string" } { "parent" "a pathname string" } }
15 { $description "Strips the last component off a pathname." }
16 { $examples { $example "USING: io io.pathnames ;" "\"/etc/passwd\" parent-directory print" "/etc/" } } ;
17
18 HELP: file-name
19 { $values { "path" "a pathname string" } { "string" string } }
20 { $description "Outputs the last component of a pathname string." }
21 { $examples
22     { $example "USING: io.pathnames prettyprint ;" "\"/usr/bin/gcc\" file-name ." "\"gcc\"" }
23     { $example "USING: io.pathnames prettyprint ;" "\"/usr/libexec/awk/\" file-name ." "\"awk\"" }
24 } ;
25
26 HELP: file-extension
27 { $values { "path" "a pathname string" } { "extension" string } }
28 { $description "Outputs the extension of " { $snippet "path" } ", or " { $link f } " if the filename has no extension." }
29 { $examples
30     { $example "USING: io.pathnames prettyprint ;" "\"/usr/bin/gcc\" file-extension ." "f" }
31     { $example "USING: io.pathnames prettyprint ;" "\"/home/csi/gui.vbs\" file-extension ." "\"vbs\"" }
32 } ;
33
34 HELP: file-stem
35 { $values { "path" "a pathname string" } { "stem" string } }
36 { $description "Outputs the " { $link file-name } " of " { $snippet "filename" } " with the file extension removed, if any." }
37 { $examples
38     { $example "USING: io.pathnames prettyprint ;" "\"/usr/bin/gcc\" file-stem ." "\"gcc\"" }
39     { $example "USING: io.pathnames prettyprint ;" "\"/home/csi/gui.vbs\" file-stem ." "\"gui\"" }
40 } ;
41
42 { file-name file-stem file-extension } related-words
43
44 HELP: path-components
45 { $values { "path" "a pathnames string" } { "seq" sequence } }
46 { $description "Splits a pathname on the " { $link path-separator } " into its its component strings." } ;
47
48 HELP: append-path
49 { $values { "str1" "a string" } { "str2" "a string" } { "str" "a string" } }
50 { $description "Appends " { $snippet "str1" } " and " { $snippet "str2" } " to form a pathname." } ;
51
52 HELP: prepend-path
53 { $values { "str1" "a string" } { "str2" "a string" } { "str" "a string" } }
54 { $description "Appends " { $snippet "str2" } " and " { $snippet "str1" } " to form a pathname." } ;
55
56 { append-path prepend-path } related-words
57
58 HELP: absolute-path?
59 { $values { "path" "a pathname string" } { "?" "a boolean" } }
60 { $description "Tests if a pathname is absolute. Examples of absolute pathnames are " { $snippet "/foo/bar" } " on Unix and " { $snippet "c:\\foo\\bar" } " on Windows." } ;
61
62 HELP: windows-absolute-path?
63 { $values { "path" "a pathname string" } { "?" "a boolean" } }
64 { $description "Tests if a pathname is absolute on Windows. Examples of absolute pathnames on Windows are " { $snippet "c:\\foo\\bar" } " and " { $snippet "\\\\?\\c:\\foo\\bar" } " for absolute Unicode pathnames." } ;
65
66 HELP: root-directory?
67 { $values { "path" "a pathname string" } { "?" "a boolean" } }
68 { $description "Tests if a pathname is a root directory. Examples of root directory pathnames are " { $snippet "/" } " on Unix and " { $snippet "c:\\" } " on Windows." } ;
69
70 { absolute-path? windows-absolute-path? root-directory? } related-words
71
72 HELP: resource-path
73 { $values { "path" "a pathname string" } { "newpath" "a pathname string" } }
74 { $description "Resolve a path relative to the Factor source code location." } ;
75
76 HELP: pathname
77 { $class-description "Class of path name objects. Path name objects can be created by calling " { $link <pathname> } "." } ;
78
79 HELP: normalize-path
80 { $values { "str" "a pathname string" } { "newstr" "a new pathname string" } }
81 { $description "Prepends the " { $link current-directory } " to the pathname, resolves a " { $snippet "resource:" } " prefix, if present, and performs any platform-specific pathname normalization." }
82 { $notes "High-level words, such as " { $link <file-reader> } " and " { $link delete-file } " call this word for you. It only needs to be called directly when passing pathnames to C functions or external processes. This is because Factor does not use the operating system's notion of a current directory, and instead maintains its own dynamically-scoped " { $link current-directory } " variable." }
83 { $examples
84   "For example, if you create a file named " { $snippet "data.txt" } " in the current directory, and wish to pass it to a process, you must normalize it:"
85   { $code
86     "\"1 2 3\" \"data.txt\" ascii set-file-contents"
87     "\"munge\" \"data.txt\" normalize-path 2array run-process"
88   }
89 } ;
90
91 HELP: canonicalize-path
92 { $values { "path" "a pathname string" } { "path'" "a new pathname string" } }
93 { $description "Returns an canonical name for a path. The canonical name is an absolute path containing no symlinks." } ;
94
95 HELP: <pathname>
96 { $values { "string" "a pathname string" } { "pathname" pathname } }
97 { $description "Creates a new " { $link pathname } "." } ;
98
99 HELP: home
100 { $values { "dir" string } }
101 { $description "Outputs the user's home directory." } ;
102
103 ARTICLE: "io.pathnames" "Pathname manipulation"
104 "Pathname manipulation:"
105 { $subsection parent-directory }
106 { $subsection file-name }
107 { $subsection file-stem }
108 { $subsection file-extension }
109 { $subsection last-path-separator }
110 { $subsection path-components }
111 { $subsection prepend-path }
112 { $subsection append-path }
113 { $subsection canonicalize-path }
114 "Pathname presentations:"
115 { $subsection pathname }
116 { $subsection <pathname> }
117 "Literal pathnames:"
118 { $subsection POSTPONE: P" }
119 "Low-level word:"
120 { $subsection normalize-path } ;
121
122 ABOUT: "io.pathnames"