author | Stefan Vogel <sv@exept.de> |
Tue, 13 Jul 2004 15:10:20 +0200 | |
changeset 8447 | 9bdea3431846 |
parent 8245 | 343908a8a4e1 |
child 8752 | 3e7429854c55 |
permissions | -rw-r--r-- |
2943
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
1 |
" |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
2 |
COPYRIGHT (c) 1997 by eXept Software AG |
3125
543358373041
care for filenames with blanks when invoking 'file' command
Claus Gittinger <cg@exept.de>
parents:
2943
diff
changeset
|
3 |
All Rights Reserved |
2943
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
4 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
5 |
This software is furnished under a license and may be used |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
6 |
only in accordance with the terms of that license and with the |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
7 |
inclusion of the above copyright notice. This software may not |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
8 |
be provided or otherwise made available to, or used by, any |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
9 |
other person. No title to or ownership of the software is |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
10 |
hereby transferred. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
11 |
" |
2907 | 12 |
|
7939
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
13 |
"{ Package: 'stx:libbasic' }" |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
14 |
|
2907 | 15 |
Filename subclass:#UnixFilename |
16 |
instanceVariableNames:'' |
|
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'OS-Unix' |
|
20 |
! |
|
21 |
||
2911 | 22 |
!UnixFilename class methodsFor:'documentation'! |
23 |
||
2931 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
3125
543358373041
care for filenames with blanks when invoking 'file' command
Claus Gittinger <cg@exept.de>
parents:
2943
diff
changeset
|
27 |
All Rights Reserved |
2931 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
2911 | 38 |
documentation |
39 |
" |
|
40 |
Filenames in Unix. |
|
41 |
" |
|
42 |
||
43 |
! ! |
|
44 |
||
7939
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
45 |
!UnixFilename class methodsFor:'instance creation'! |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
46 |
|
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
47 |
named:aString |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
48 |
"return a filename for a directory named aString. |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
49 |
This is the same as 'aString asFilename'." |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
50 |
|
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
51 |
|singleByteString| |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
52 |
|
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
53 |
aString bitsPerCharacter > 8 ifTrue:[ |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
54 |
singleByteString := CharacterEncoder::ISO10646_to_UTF8 encodeString:aString |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
55 |
] ifFalse:[ |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
56 |
singleByteString := aString. |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
57 |
]. |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
58 |
^ (self basicNew) setName:singleByteString |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
59 |
|
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
60 |
" |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
61 |
Filename named:'/tmp/fooBar' |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
62 |
" |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
63 |
|
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
64 |
"Modified: 7.9.1997 / 23:30:06 / cg" |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
65 |
! ! |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
66 |
|
2907 | 67 |
!UnixFilename class methodsFor:'queries'! |
68 |
||
69 |
isBadCharacter:aCharacter |
|
70 |
"return true, if aCharacter is unallowed in a filename." |
|
71 |
||
72 |
aCharacter == $/ ifTrue:[^ true]. |
|
73 |
^ super isBadCharacter:aCharacter |
|
74 |
||
75 |
"Created: 8.9.1997 / 00:13:14 / cg" |
|
76 |
! |
|
77 |
||
2908 | 78 |
isCaseSensitive |
79 |
"return true, if filenames are case sensitive.return true, if filenames are case sensitive." |
|
80 |
||
81 |
^ true |
|
82 |
! |
|
83 |
||
3171 | 84 |
nullFilename |
85 |
"Return /dev/null" |
|
86 |
||
87 |
^ '/dev/null' |
|
88 |
||
89 |
" |
|
90 |
Filename concreteClass nullFilename |
|
91 |
" |
|
92 |
||
93 |
"Modified: / 14.1.1998 / 14:20:55 / stefan" |
|
94 |
! |
|
95 |
||
2908 | 96 |
parentDirectoryName |
97 |
"return the name used for the parent directory. |
|
98 |
This is '..' for unix and dos-like systems. |
|
99 |
(there may be more in the future." |
|
100 |
||
101 |
^ '..' |
|
102 |
! |
|
103 |
||
2907 | 104 |
separator |
105 |
"return the file/directory separator." |
|
106 |
||
107 |
^ $/ |
|
108 |
||
109 |
" |
|
110 |
Filename concreteClass separator |
|
111 |
" |
|
112 |
||
113 |
"Created: 8.9.1997 / 00:18:14 / cg" |
|
8245 | 114 |
! |
115 |
||
116 |
separatorString |
|
117 |
"return the file/directory separator as a string." |
|
118 |
||
119 |
^ '/' |
|
120 |
||
121 |
" |
|
122 |
Filename concreteClass separatorString |
|
123 |
" |
|
2907 | 124 |
! ! |
125 |
||
126 |
!UnixFilename methodsFor:'file queries'! |
|
127 |
||
128 |
fileType |
|
129 |
"this returns a string describing the type of contents of |
|
130 |
the file. This is done using the unix 'file' command, |
|
131 |
(which usually is configurable by /etc/magic). |
|
3664 | 132 |
Warning: |
133 |
Since the returned string differs among systems (and language settings), |
|
134 |
it is only useful for user-information; |
|
135 |
NOT as a tag to be used by a program." |
|
2907 | 136 |
|
137 |
|stream typeString| |
|
138 |
||
139 |
"/ since executing 'file' takes some time, do the most common |
|
140 |
"/ ones are checked first, using the general fileType implementation. |
|
141 |
"/ (also, the file-command is only available on Unix systems. |
|
142 |
||
143 |
typeString := super fileType. |
|
144 |
typeString ~= 'file' ifTrue:[^ typeString]. |
|
145 |
||
3125
543358373041
care for filenames with blanks when invoking 'file' command
Claus Gittinger <cg@exept.de>
parents:
2943
diff
changeset
|
146 |
stream := PipeStream readingFrom:('file "' , self pathName , '"'). |
2907 | 147 |
stream notNil ifTrue:[ |
3664 | 148 |
typeString := stream contents asString. |
149 |
stream close. |
|
150 |
typeString := typeString copyFrom:(typeString indexOf:$:) + 1. |
|
151 |
typeString := typeString withoutSeparators |
|
2907 | 152 |
]. |
153 |
^ typeString |
|
154 |
||
155 |
" |
|
156 |
'Makefile' asFilename fileType |
|
157 |
'.' asFilename fileType |
|
158 |
'/dev/null' asFilename fileType |
|
159 |
'smalltalk.rc' asFilename fileType |
|
160 |
'bitmaps/SBrowser.xbm' asFilename fileType |
|
3664 | 161 |
'../../libtool/bitmaps/SBrowser.xbm' asFilename fileType |
2907 | 162 |
" |
163 |
||
3664 | 164 |
"Modified: / 21.7.1998 / 11:26:32 / cg" |
2907 | 165 |
! ! |
166 |
||
2931 | 167 |
!UnixFilename methodsFor:'queries'! |
168 |
||
169 |
isExplicitRelative |
|
170 |
"return true, if this name is an explicit relative name |
|
171 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
172 |
||
173 |
(nameString startsWith:'./') ifTrue:[ |
|
174 |
^ true |
|
175 |
]. |
|
176 |
(nameString startsWith:'../') ifTrue:[ |
|
177 |
^ true |
|
178 |
]. |
|
179 |
^ false |
|
180 |
! |
|
181 |
||
182 |
isHidden |
|
183 |
"return true, if the receiver represents a hidden file. |
|
184 |
On UNIX, a name starting with a period is considered hidden." |
|
185 |
||
186 |
^ self baseName startsWith:'.' |
|
2943
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
187 |
! |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
188 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
189 |
isImplicit |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
190 |
"return true, if the receiver represents builtin names such as '.' or '..'. |
3664 | 191 |
On UNIX, the current and parent dir names are considered implicit." |
2943
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
192 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
193 |
|name| |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
194 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
195 |
name := self baseName. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
196 |
^ name = '.' or:[name = '..']. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
197 |
|
3664 | 198 |
"Modified: / 18.9.1997 / 18:03:28 / stefan" |
199 |
"Modified: / 21.7.1998 / 11:10:42 / cg" |
|
200 |
! |
|
201 |
||
202 |
nameWithSpecialExpansions:aString |
|
203 |
"return the nameString, expanding any OS specific macros. |
|
204 |
Here, a ~ prefix is expanded to the users home dir (as in csh)" |
|
205 |
||
206 |
|dir user cutIdx idx userInfo| |
|
207 |
||
208 |
(aString startsWith:'~') ifTrue:[ |
|
209 |
dir := OperatingSystem getHomeDirectory. |
|
210 |
cutIdx := 2. |
|
211 |
"/ look for ~username |
|
212 |
(aString size > 1) ifTrue:[ |
|
213 |
idx := aString indexOf:$/. |
|
214 |
idx == 0 ifTrue:[ |
|
215 |
user := aString copyFrom:2. |
|
216 |
cutIdx := aString size + 1. |
|
217 |
] ifFalse:[ |
|
218 |
user := aString copyFrom:2 to:(idx - 1). |
|
219 |
cutIdx := idx. |
|
220 |
]. |
|
221 |
user size > 0 ifTrue:[ |
|
222 |
userInfo := OperatingSystem userInfoOf:user. |
|
223 |
(userInfo notNil and:[userInfo includesKey:#dir]) ifTrue:[ |
|
224 |
dir := userInfo at:#dir |
|
225 |
] ifFalse:[ |
|
226 |
dir := nil |
|
227 |
] |
|
228 |
]. |
|
229 |
dir isNil ifTrue:[ |
|
230 |
"/ ('Filename [info]: unknown user: ' , user) infoPrintCR. |
|
231 |
^ aString |
|
232 |
]. |
|
233 |
]. |
|
234 |
^ dir , (aString copyFrom:cutIdx) |
|
235 |
]. |
|
236 |
^ aString |
|
237 |
||
238 |
" |
|
239 |
UnixFilename new nameWithSpecialExpansions:'~' |
|
240 |
UnixFilename new nameWithSpecialExpansions:'~/work' |
|
241 |
UnixFilename new nameWithSpecialExpansions:'~sv' |
|
242 |
UnixFilename new nameWithSpecialExpansions:'~sv/work' |
|
243 |
UnixFilename new nameWithSpecialExpansions:'~foo' |
|
244 |
UnixFilename new nameWithSpecialExpansions:'~foo/bar' |
|
245 |
" |
|
246 |
||
247 |
"Modified: / 21.7.1998 / 11:09:59 / cg" |
|
2931 | 248 |
! ! |
249 |
||
2911 | 250 |
!UnixFilename class methodsFor:'documentation'! |
2907 | 251 |
|
2911 | 252 |
version |
8245 | 253 |
^ '$Header: /cvs/stx/stx/libbasic/UnixFilename.st,v 1.10 2004-03-20 15:03:09 cg Exp $' |
2907 | 254 |
! ! |