author | Claus Gittinger <cg@exept.de> |
Wed, 22 Oct 2008 00:20:59 +0200 | |
changeset 11261 | e8dcdce0b2ae |
parent 9940 | 2c73d0c164b9 |
child 11318 | fc07976462e8 |
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:[ |
9931
d43f06e92188
fixed #named: for wide-string-names
Claus Gittinger <cg@exept.de>
parents:
8946
diff
changeset
|
54 |
singleByteString := aString utf8Encoded. |
7939
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 |
|
9931
d43f06e92188
fixed #named: for wide-string-names
Claus Gittinger <cg@exept.de>
parents:
8946
diff
changeset
|
64 |
"Modified: / 04-08-2005 / 09:21:35 / janfrog" |
9940 | 65 |
"Modified: / 18-09-2006 / 22:20:51 / cg" |
7939
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
66 |
! ! |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
67 |
|
2907 | 68 |
!UnixFilename class methodsFor:'queries'! |
69 |
||
70 |
isBadCharacter:aCharacter |
|
71 |
"return true, if aCharacter is unallowed in a filename." |
|
72 |
||
73 |
aCharacter == $/ ifTrue:[^ true]. |
|
74 |
^ super isBadCharacter:aCharacter |
|
75 |
||
76 |
"Created: 8.9.1997 / 00:13:14 / cg" |
|
77 |
! |
|
78 |
||
2908 | 79 |
isCaseSensitive |
80 |
"return true, if filenames are case sensitive.return true, if filenames are case sensitive." |
|
81 |
||
82 |
^ true |
|
83 |
! |
|
84 |
||
3171 | 85 |
nullFilename |
86 |
"Return /dev/null" |
|
87 |
||
88 |
^ '/dev/null' |
|
89 |
||
90 |
" |
|
8752 | 91 |
Filename nullFilename |
3171 | 92 |
" |
93 |
||
94 |
"Modified: / 14.1.1998 / 14:20:55 / stefan" |
|
95 |
! |
|
96 |
||
2908 | 97 |
parentDirectoryName |
98 |
"return the name used for the parent directory. |
|
99 |
This is '..' for unix and dos-like systems. |
|
100 |
(there may be more in the future." |
|
101 |
||
102 |
^ '..' |
|
103 |
! |
|
104 |
||
2907 | 105 |
separator |
106 |
"return the file/directory separator." |
|
107 |
||
108 |
^ $/ |
|
109 |
||
110 |
" |
|
111 |
Filename concreteClass separator |
|
112 |
" |
|
113 |
||
114 |
"Created: 8.9.1997 / 00:18:14 / cg" |
|
8245 | 115 |
! |
116 |
||
117 |
separatorString |
|
118 |
"return the file/directory separator as a string." |
|
119 |
||
120 |
^ '/' |
|
121 |
||
122 |
" |
|
8752 | 123 |
Filename separatorString |
8245 | 124 |
" |
2907 | 125 |
! ! |
126 |
||
127 |
!UnixFilename methodsFor:'file queries'! |
|
128 |
||
129 |
fileType |
|
130 |
"this returns a string describing the type of contents of |
|
131 |
the file. This is done using the unix 'file' command, |
|
132 |
(which usually is configurable by /etc/magic). |
|
3664 | 133 |
Warning: |
134 |
Since the returned string differs among systems (and language settings), |
|
135 |
it is only useful for user-information; |
|
136 |
NOT as a tag to be used by a program." |
|
2907 | 137 |
|
138 |
|stream typeString| |
|
139 |
||
140 |
"/ since executing 'file' takes some time, do the most common |
|
141 |
"/ ones are checked first, using the general fileType implementation. |
|
142 |
"/ (also, the file-command is only available on Unix systems. |
|
143 |
||
144 |
typeString := super fileType. |
|
145 |
typeString ~= 'file' ifTrue:[^ typeString]. |
|
146 |
||
3125
543358373041
care for filenames with blanks when invoking 'file' command
Claus Gittinger <cg@exept.de>
parents:
2943
diff
changeset
|
147 |
stream := PipeStream readingFrom:('file "' , self pathName , '"'). |
2907 | 148 |
stream notNil ifTrue:[ |
3664 | 149 |
typeString := stream contents asString. |
150 |
stream close. |
|
151 |
typeString := typeString copyFrom:(typeString indexOf:$:) + 1. |
|
152 |
typeString := typeString withoutSeparators |
|
2907 | 153 |
]. |
154 |
^ typeString |
|
155 |
||
156 |
" |
|
157 |
'Makefile' asFilename fileType |
|
158 |
'.' asFilename fileType |
|
159 |
'/dev/null' asFilename fileType |
|
160 |
'smalltalk.rc' asFilename fileType |
|
161 |
'bitmaps/SBrowser.xbm' asFilename fileType |
|
3664 | 162 |
'../../libtool/bitmaps/SBrowser.xbm' asFilename fileType |
2907 | 163 |
" |
164 |
||
3664 | 165 |
"Modified: / 21.7.1998 / 11:26:32 / cg" |
2907 | 166 |
! ! |
167 |
||
2931 | 168 |
!UnixFilename methodsFor:'queries'! |
169 |
||
170 |
isExplicitRelative |
|
171 |
"return true, if this name is an explicit relative name |
|
172 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
173 |
||
174 |
(nameString startsWith:'./') ifTrue:[ |
|
175 |
^ true |
|
176 |
]. |
|
177 |
(nameString startsWith:'../') ifTrue:[ |
|
178 |
^ true |
|
179 |
]. |
|
180 |
^ false |
|
181 |
! |
|
182 |
||
183 |
isHidden |
|
184 |
"return true, if the receiver represents a hidden file. |
|
185 |
On UNIX, a name starting with a period is considered hidden." |
|
186 |
||
187 |
^ 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
|
188 |
! |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
189 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
190 |
isImplicit |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
191 |
"return true, if the receiver represents builtin names such as '.' or '..'. |
3664 | 192 |
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
|
193 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
194 |
|name| |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
195 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
196 |
name := self baseName. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
197 |
^ name = '.' or:[name = '..']. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
198 |
|
3664 | 199 |
"Modified: / 18.9.1997 / 18:03:28 / stefan" |
200 |
"Modified: / 21.7.1998 / 11:10:42 / cg" |
|
2931 | 201 |
! ! |
202 |
||
2911 | 203 |
!UnixFilename class methodsFor:'documentation'! |
2907 | 204 |
|
2911 | 205 |
version |
9940 | 206 |
^ '$Header: /cvs/stx/stx/libbasic/UnixFilename.st,v 1.14 2006-09-18 20:19:54 cg Exp $' |
2907 | 207 |
! ! |