3336
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1997 by eXept Software AG
|
3570
|
3 |
All Rights Reserved
|
3336
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
3570
|
13 |
'From Smalltalk/X, Version:3.4.7 on 1-aug-1998 at 09:51:13' !
|
|
14 |
|
3336
|
15 |
Filename subclass:#PCFilename
|
|
16 |
instanceVariableNames:''
|
|
17 |
classVariableNames:'StandardSuffixTable'
|
|
18 |
poolDictionaries:''
|
3570
|
19 |
category:'OS-Windows'
|
|
20 |
!
|
|
21 |
|
|
22 |
!PCFilename class methodsFor:'documentation'!
|
|
23 |
|
3336
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 1997 by eXept Software AG
|
3570
|
27 |
All Rights Reserved
|
3336
|
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 |
"
|
3570
|
36 |
!
|
|
37 |
|
3336
|
38 |
documentation
|
|
39 |
"
|
|
40 |
Filenames in Windows-NT / Win95.
|
|
41 |
"
|
3570
|
42 |
! !
|
|
43 |
|
|
44 |
!PCFilename class methodsFor:'initialization'!
|
|
45 |
|
3336
|
46 |
initStandardSuffixTable
|
|
47 |
"since there is no 'file' command to extract the type,
|
|
48 |
return a guess based upon the files suffix. The following
|
|
49 |
table defines what is returned."
|
|
50 |
|
|
51 |
StandardSuffixTable := Dictionary new.
|
|
52 |
#(
|
3570
|
53 |
'COM' 'executable'
|
|
54 |
'DIR' 'directory'
|
|
55 |
'EXE' 'executable'
|
|
56 |
'LST' 'listing'
|
|
57 |
'OBJ' 'object file'
|
|
58 |
'TMP' 'temporary'
|
|
59 |
'BAS' 'basic source'
|
|
60 |
'C' 'c source'
|
|
61 |
'COB' 'cobol source'
|
|
62 |
'FOR' 'fortran source'
|
|
63 |
'PAS' 'pascal source'
|
|
64 |
'PL1' 'PL/1 source'
|
|
65 |
'ST' 'smalltalk source'
|
|
66 |
'STH' 'stc generated header'
|
|
67 |
'DLL' 'dynamic link library'
|
3336
|
68 |
) pairWiseDo:[:k :v |
|
3570
|
69 |
StandardSuffixTable at:k put:v
|
3336
|
70 |
]
|
|
71 |
|
|
72 |
"
|
|
73 |
StandardSuffixTable := nil.
|
|
74 |
self initStandardSuffixTable
|
|
75 |
"
|
|
76 |
|
|
77 |
"Modified: 16.10.1997 / 13:12:39 / cg"
|
3570
|
78 |
! !
|
|
79 |
|
|
80 |
!PCFilename class methodsFor:'instance creation'!
|
|
81 |
|
3336
|
82 |
newTemporaryIn:aDirectoryPrefix
|
|
83 |
"return a new unique filename - use this for temporary files.
|
|
84 |
redefined to always return an MSDOS 8+3 fileName,
|
|
85 |
in case the tempFile is passed to an OLD dos utility.."
|
|
86 |
|
|
87 |
|pid nr nameString|
|
|
88 |
|
|
89 |
(self ~~ ConcreteClass) ifTrue:[
|
3570
|
90 |
^ ConcreteClass newTemporaryIn:aDirectoryPrefix
|
3336
|
91 |
].
|
|
92 |
|
|
93 |
"/ although the above allows things to be redefined in concrete classes,
|
|
94 |
"/ the following should work on all systems ...
|
|
95 |
|
|
96 |
NextTempFilenameIndex isNil ifTrue:[
|
3570
|
97 |
NextTempFilenameIndex := 1.
|
3336
|
98 |
].
|
|
99 |
|
|
100 |
pid := OperatingSystem getProcessId printString.
|
|
101 |
pid := pid copyLast:(3 min:pid size).
|
|
102 |
nr := NextTempFilenameIndex printString.
|
|
103 |
nr := nr copyLast:(3 min:nr size).
|
|
104 |
nameString := (self tempFileNameTemplate)
|
3570
|
105 |
bindWith:pid
|
|
106 |
with:nr.
|
3336
|
107 |
NextTempFilenameIndex := NextTempFilenameIndex + 1.
|
|
108 |
|
|
109 |
(aDirectoryPrefix isNil or:[aDirectoryPrefix asString isEmpty]) ifFalse:[
|
3570
|
110 |
^ aDirectoryPrefix asFilename construct:nameString
|
3336
|
111 |
].
|
|
112 |
^ self named:nameString
|
|
113 |
|
|
114 |
"temp files in '/tmp':
|
|
115 |
|
|
116 |
Filename newTemporary
|
|
117 |
"
|
|
118 |
|
|
119 |
"temp files somewhere
|
|
120 |
(not recommended - use above since it can be controlled via shell variables):
|
|
121 |
|
|
122 |
Filename newTemporaryIn:'/tmp'
|
|
123 |
Filename newTemporaryIn:'/tmp'
|
|
124 |
Filename newTemporaryIn:'/usr/tmp'
|
|
125 |
Filename newTemporaryIn:'/'
|
|
126 |
"
|
|
127 |
|
|
128 |
"a local temp file:
|
|
129 |
|
|
130 |
Filename newTemporaryIn:''
|
|
131 |
Filename newTemporaryIn:nil
|
|
132 |
Filename newTemporaryIn:'.'
|
|
133 |
Filename newTemporaryIn:('source' asFilename)
|
|
134 |
"
|
|
135 |
|
|
136 |
"Modified: 7.9.1995 / 10:48:31 / claus"
|
|
137 |
"Modified: 8.9.1997 / 00:28:33 / cg"
|
|
138 |
"Created: 30.1.1998 / 11:49:33 / md"
|
|
139 |
"Modified: 30.1.1998 / 11:52:06 / md"
|
|
140 |
"Modified: 30.1.1998 / 12:09:18 / dq"
|
3570
|
141 |
! !
|
|
142 |
|
|
143 |
!PCFilename class methodsFor:'queries'!
|
|
144 |
|
3336
|
145 |
isBadCharacter:aCharacter
|
|
146 |
"return true, if aCharacter is unallowed in a filename."
|
|
147 |
|
|
148 |
('<>:"/\|' includes:aCharacter) ifTrue:[^ true].
|
|
149 |
^ super isBadCharacter:aCharacter
|
|
150 |
|
|
151 |
"Created: 8.9.1997 / 00:14:06 / cg"
|
3570
|
152 |
!
|
|
153 |
|
3336
|
154 |
isCaseSensitive
|
|
155 |
"return true, if filenames are case sensitive."
|
|
156 |
|
|
157 |
^ false
|
3570
|
158 |
!
|
|
159 |
|
3336
|
160 |
separator
|
|
161 |
"return the file/directory separator."
|
|
162 |
|
|
163 |
^ $\
|
|
164 |
|
|
165 |
"
|
|
166 |
Filename concreteClass separator
|
|
167 |
"
|
|
168 |
|
|
169 |
"Modified: 8.9.1997 / 00:18:03 / cg"
|
3570
|
170 |
!
|
|
171 |
|
3336
|
172 |
tempFileNameTemplate
|
|
173 |
"return a template for temporary files.
|
|
174 |
This is expanded with the current processID and a sequenceNumber
|
|
175 |
to generate a unique filename.
|
|
176 |
Redefined for MSDOS 8+3 filenames"
|
|
177 |
|
|
178 |
^ 'st%1%2.tmp'
|
|
179 |
|
|
180 |
"Created: 30.1.1998 / 12:09:18 / dq"
|
3570
|
181 |
! !
|
|
182 |
|
|
183 |
!PCFilename methodsFor:'file operations'!
|
|
184 |
|
|
185 |
renameTo:newName
|
|
186 |
"rename the file - the argument must be convertable to a String.
|
|
187 |
Raise an error if not successful.
|
|
188 |
Redefined to delete any existing target-file first."
|
3336
|
189 |
|
3570
|
190 |
newName asFilename exists ifTrue:[
|
|
191 |
newName asFilename delete
|
|
192 |
].
|
|
193 |
|
|
194 |
^ super renameTo:newName
|
3336
|
195 |
|
3570
|
196 |
"
|
|
197 |
'\tmp\foo' asFilename renameTo:'\tmp\bar'
|
|
198 |
"
|
|
199 |
|
|
200 |
"Modified: 20.1.1998 / 15:33:00 / md"
|
|
201 |
! !
|
|
202 |
|
|
203 |
!PCFilename methodsFor:'queries'!
|
|
204 |
|
3336
|
205 |
fileType
|
|
206 |
"this returns a string describing the type of contents of
|
|
207 |
the file. Here, the suffix is examined for a standard
|
|
208 |
suffix and an appropriate string is returned.
|
|
209 |
Poor MSDOS - no file command."
|
|
210 |
|
|
211 |
|suff type info fmt|
|
|
212 |
|
|
213 |
StandardSuffixTable isNil ifTrue:[
|
3570
|
214 |
self class initStandardSuffixTable
|
3336
|
215 |
].
|
|
216 |
|
|
217 |
suff := self suffix asUppercase.
|
|
218 |
type := StandardSuffixTable at:suff ifAbsent:nil.
|
|
219 |
type isNil ifTrue:[
|
3570
|
220 |
type := super fileType.
|
3336
|
221 |
].
|
|
222 |
^ type
|
|
223 |
|
|
224 |
"Created: 16.10.1997 / 13:07:24 / cg"
|
|
225 |
"Modified: 16.10.1997 / 13:10:00 / cg"
|
3570
|
226 |
!
|
|
227 |
|
3336
|
228 |
isExecutableProgram
|
|
229 |
"return true, if such a file exists and is an executable program.
|
|
230 |
(i.e. for directories, false is returned.)"
|
|
231 |
|
|
232 |
((self hasSuffix:'exe')
|
|
233 |
or:[self hasSuffix:'com']) ifTrue:[
|
3570
|
234 |
^ super isExecutableProgram
|
3336
|
235 |
].
|
|
236 |
^ false
|
|
237 |
|
|
238 |
"Created: 16.10.1997 / 13:19:10 / cg"
|
3570
|
239 |
!
|
|
240 |
|
3336
|
241 |
isExplicitRelative
|
|
242 |
"return true, if this name is an explicit relative name
|
|
243 |
(i.e. starts with './' or '../', to avoid path-prepending)"
|
|
244 |
|
|
245 |
(nameString startsWith:'.\') ifTrue:[
|
|
246 |
^ true
|
|
247 |
].
|
|
248 |
(nameString startsWith:'..\') ifTrue:[
|
|
249 |
^ true
|
|
250 |
].
|
|
251 |
^ false
|
3570
|
252 |
!
|
|
253 |
|
3336
|
254 |
isVolumeAbsolute
|
|
255 |
"return true, if the receiver represents an absolute pathname
|
|
256 |
on some disk volume."
|
|
257 |
|
3570
|
258 |
^ (((nameString size >= 3) and:[(nameString at:2) == $:]) and:[(nameString at:3) == $\])
|
3336
|
259 |
|
|
260 |
"Created: 7.9.1997 / 23:54:20 / cg"
|
3570
|
261 |
!
|
|
262 |
|
3336
|
263 |
localNameStringFrom:aString
|
|
264 |
"ST-80 compatibility.
|
|
265 |
what does this do ? (used in FileNavigator-goody).
|
|
266 |
GUESS: does it strip off the voulume-character and initial '\' ?"
|
|
267 |
|
|
268 |
(aString at:2) == $: ifTrue:[
|
|
269 |
(aString at:3) == $\ ifTrue:[
|
|
270 |
^ aString copyFrom:4
|
|
271 |
].
|
|
272 |
^ aString copyFrom:3
|
|
273 |
].
|
|
274 |
(aString at:1) == $\ ifTrue:[
|
|
275 |
^ aString copyFrom:1
|
|
276 |
].
|
|
277 |
^ aString
|
3570
|
278 |
!
|
|
279 |
|
3336
|
280 |
volume
|
|
281 |
"return the disc volume part of the name or an empty string.
|
|
282 |
This is only used with DOS filenames - on unix, an empty string is returned"
|
|
283 |
|
|
284 |
(nameString at:2) == $: ifTrue:[
|
3570
|
285 |
^ nameString copyTo:1
|
3336
|
286 |
].
|
|
287 |
^ ''
|
|
288 |
|
|
289 |
"Created: 7.9.1997 / 23:58:06 / cg"
|
3570
|
290 |
! !
|
|
291 |
|
|
292 |
!PCFilename methodsFor:'special accessing'!
|
|
293 |
|
|
294 |
osNameForDirectory
|
|
295 |
"special - return the OS's name for the receiver to
|
|
296 |
access it as a directory.
|
|
297 |
Care remove trailing backSlashes here"
|
3336
|
298 |
|
3570
|
299 |
(nameString endsWith:'\') ifTrue:[
|
|
300 |
((nameString size == 3) and:[(nameString at:2) == $:]) ifFalse:[
|
|
301 |
^nameString copyWithoutLast:1
|
|
302 |
]
|
|
303 |
].
|
|
304 |
^ nameString
|
3336
|
305 |
|
3570
|
306 |
"Modified: 20.1.1998 / 15:39:06 / md"
|
|
307 |
!
|
|
308 |
|
|
309 |
setName:aString
|
|
310 |
"set the filename"
|
|
311 |
|
|
312 |
nameString := aString copy replaceAll:$/ with:$\
|
|
313 |
|
|
314 |
"Created: 22.1.1998 / 17:32:45 / md"
|
|
315 |
! !
|
|
316 |
|
|
317 |
!PCFilename class methodsFor:'documentation'!
|
|
318 |
|
3336
|
319 |
version
|
3570
|
320 |
^ '$Header: /cvs/stx/stx/libbasic/PCFilename.st,v 1.9 1998-06-15 13:39:10 cg Exp $'
|
|
321 |
! !
|