OpenVMSFilename.st
changeset 2911 9964e6839a8e
parent 2907 1666bf27f351
child 2913 31d7aab40357
--- a/OpenVMSFilename.st	Tue Sep 09 19:31:56 1997 +0200
+++ b/OpenVMSFilename.st	Tue Sep 09 19:35:21 1997 +0200
@@ -1,4 +1,4 @@
-'From Smalltalk/X, Version:3.1.9 on 8-sep-1997 at 12:39:22 am'                  !
+'From Smalltalk/X, Version:3.1.9 on 9-sep-1997 at 11:55:40 pm'                  !
 
 Filename subclass:#OpenVMSFilename
 	instanceVariableNames:''
@@ -7,8 +7,93 @@
 	category:'OS-OpenVMS'
 !
 
+Object subclass:#NameComponents
+	instanceVariableNames:'volume directory filename'
+	classVariableNames:''
+	poolDictionaries:''
+	privateIn:OpenVMSFilename
+!
+
+!OpenVMSFilename class methodsFor:'documentation'!
+
+documentation
+"
+    Filenames in OpenVMS.
+"
+! !
+
+!OpenVMSFilename class methodsFor:'helpers'!
+
+nameFromComponents:aComponentObject
+    "concatenate the components, return a fileNameString"
+
+    |s volume directory filename|
+
+    volume := aComponentObject volume.
+    directory := aComponentObject directory.
+    filename := aComponentObject filename.
+
+    volume notNil ifTrue:[
+        s := volume , ':'
+    ] ifFalse:[
+        s := ''
+    ].
+    directory notNil ifTrue:[
+        s := s , '[' , directory , ']'
+    ].
+    filename notNil ifTrue:[
+        s := s , filename
+    ].
+    s isEmpty ifTrue:[
+        ^ '[]'
+    ].
+    ^ s
+
+    "Modified: 9.9.1997 / 09:38:41 / cg"
+!
+
+parseComponentsFrom:aString
+    "given a pathName, decompose into volume, directory & filename.
+     Return the components as a componentObject."
+
+    |v d f idx0 idx|
+
+    idx := aString indexOf:$:.
+    idx ~~ 0 ifTrue:[
+        v := aString copyTo:idx - 1.
+    ].
+    idx := idx + 1.
+    (aString at:idx) == $[ ifTrue:[
+        idx0 := idx + 1.
+        idx := aString indexOf:$] startingAt:idx0.
+        idx == 0 ifTrue:[
+            "/ mhmh - malformed. what should we do here ?
+            self error:'malformed filename'
+        ].
+        d := aString copyFrom:idx0 to:(idx-1).
+        idx := idx + 1.
+    ].
+    f := aString copyFrom:idx.
+    ^ NameComponents basicNew volume:v directory:d filename:f
+
+    "
+     OpenVMSFilename nameFromComponents:(OpenVMSFilename parseComponentsFrom:'dka100:[stx.libbasic]Object.st')
+     OpenVMSFilename nameFromComponents:(OpenVMSFilename parseComponentsFrom:'dka100:[stx.libbasic.-]Object.st')
+     OpenVMSFilename nameFromComponents:(OpenVMSFilename parseComponentsFrom:'dka100:[-]Object.st')
+     OpenVMSFilename nameFromComponents:(OpenVMSFilename parseComponentsFrom:'dka100:[]Object.st')
+     OpenVMSFilename nameFromComponents:(OpenVMSFilename parseComponentsFrom:'dka100:Object.st')
+     OpenVMSFilename nameFromComponents:(OpenVMSFilename parseComponentsFrom:'dka100:[stx.libbasic]')
+    "
+
+    "Modified: 9.9.1997 / 08:50:04 / cg"
+! !
+
 !OpenVMSFilename class methodsFor:'queries'!
 
+directorySuffix
+    ^ '.DIR'
+!
+
 isBadCharacter:aCharacter
     "return true, if aCharacter is unallowed in a filename."
 
@@ -18,10 +103,29 @@
     "Created: 8.9.1997 / 00:14:47 / cg"
 !
 
+isCaseSensitive
+    "return true, if filenames are case sensitive.return true, if filenames are case sensitive."
+
+    ^ false
+!
+
+maxComponentLength
+    "return the maximum number of characters a filename component
+     may have in VMS"
+
+    ^ 39
+!
+
+maxLength
+    "return the maximum number of characters a filename may have in VMS"
+
+    ^ 1024
+!
+
 separator
     "return the file/directory separator.
      For openVMS, the separator concept does not really fit,
-     since names are composed as volume:[dir.dir.dir]file."
+     since names are composed as 'volume:[dir.dir.dir]file.ext'."
 
      ^ $.
 
@@ -30,6 +134,7 @@
      "
 
     "Created: 8.9.1997 / 00:17:28 / cg"
+    "Modified: 9.9.1997 / 08:51:01 / cg"
 !
 
 tempFileNameTemplate
@@ -43,3 +148,256 @@
     "Modified: 8.9.1997 / 00:29:23 / cg"
 ! !
 
+!OpenVMSFilename methodsFor:'instance creation'!
+
+constructString:subname
+    "taking the receiver as a directory name, construct a new
+     filename-string for an entry within this directory
+     (i.e. for a file or a subdirectory in that directory)."
+
+    |v d f comps|
+
+    comps := self class parseComponentsFrom:nameString.
+    (f := comps filename) notNil ifTrue:[
+        "/ path was of the form vol:[d1...dN]foo
+        "/ assume foo is a directory and append it to directory path.
+
+        (f asUppercase endsWith:'.DIR') ifTrue:[
+            f := f copyWithoutLast:4
+        ].
+        d := comps directory , '.' , f.
+        comps directory:d.
+    ].
+    comps filename:subname.
+    ^ self class nameFromComponents:comps
+
+    "
+     (OpenVMSFilename named:'sys$root:[foo.bar]') construct:'baz'
+     (OpenVMSFilename named:'sys$root:[foo.bar]baz') construct:'foo'
+    "
+
+    "Modified: 9.9.1997 / 05:26:04 / cg"
+! !
+
+!OpenVMSFilename methodsFor:'queries'!
+
+isAbsolute
+    "return true, if the receiver represents an absolute pathname
+     (in contrast to one relative to the current directory)."
+
+    |comps dir|
+
+    comps := self class parseComponentsFrom:nameString.
+    (dir := comps directory) isNil ifTrue:[
+        "/ mhmh ...
+        ^ false
+    ].
+    dir size == 0 ifTrue:[
+        "/ [] - the current directory is relative
+        ^ false
+    ].
+    dir = '-' ifTrue:[
+        "/ [-] - the parent directory is relative
+        ^ false
+    ].
+    (dir startsWith:'-.') ifTrue:[
+        "/ [-.] - some parent directory is relative
+        ^ false
+    ].
+    ^ (dir startsWith:'.') not
+
+    "
+     (OpenVMSFilename named:'dka:[foo.bar]baz.st') isAbsolute   
+     (OpenVMSFilename named:'[foo.bar]baz.st') isAbsolute    
+     (OpenVMSFilename named:'[.foo.bar]baz.st') isAbsolute   
+     (OpenVMSFilename named:'[]baz.st') isAbsolute           
+     (OpenVMSFilename named:'[-]baz.st') isAbsolute    
+     (OpenVMSFilename named:'[-.-]baz.st') isAbsolute   
+    "
+
+    "Modified: 9.9.1997 / 09:03:42 / cg"
+! !
+
+!OpenVMSFilename methodsFor:'queries-path & name'!
+
+baseName
+    "return my baseName as a string.
+     - thats the file/directory name without leading parent-dirs.
+     See also: #pathName, #directoryName and #directoryPathName.
+     Compatibility note: use #tail for ST-80 compatibility."
+
+    |idx d f comps|
+
+    comps := self class parseComponentsFrom:nameString.
+    (f := comps filename) size > 0  ifTrue:[
+        ^ f
+    ].
+
+    "/ path was of the form vol:[d1...dN]
+    "/ cut off the last directory.
+    d := comps directory.
+    d notNil ifTrue:[
+        d = '' ifTrue:[
+            "/ [] 
+            "/ ought to get the current directory ...
+            ^ ''
+        ].
+        d = '-' ifTrue:[
+            "/ [-]
+            "/ ought to get the current directory ...
+            ^ ''
+        ].
+        (d endsWith:'.-') ifTrue:[
+            "/ [rest.-]
+            "/ ought to expand and get final directory ...
+            ^ ''
+        ].
+        idx := d lastIndexOf:$..
+        idx ~~ 0 ifTrue:[
+            ^ (d copyFrom:idx+1) , '.DIR'
+        ].
+        ^ d , '.DIR'
+    ].
+    ^ ''
+
+    "
+     (OpenVMSFilename named:'dka100:[stx.libbasic]Object.st') baseName
+     (OpenVMSFilename named:'stx$root:[stx.libbasic.-]Object.st') baseName 
+     (OpenVMSFilename named:'[-]Object.st') baseName                       
+     (OpenVMSFilename named:'[]Object.st') baseName                        
+     (OpenVMSFilename named:'Object.st') baseName                          
+     (OpenVMSFilename named:'[stx.libbasic]') baseName                     
+     (OpenVMSFilename named:'[stx]') baseName                     
+     (OpenVMSFilename named:'[]') baseName                     
+     (OpenVMSFilename named:'[-]') baseName                     
+    "
+
+    "Created: 9.9.1997 / 09:23:15 / cg"
+    "Modified: 9.9.1997 / 10:52:04 / cg"
+!
+
+directoryName
+    "return the directory name part of the file/directory as a string.
+     - thats the name of the directory where the file/dir represented by
+       the receiver is contained in.
+     (this is almost equivalent to #directory, but returns
+      a string instead of a Filename instance).
+     See also: #pathName, #directoryPathName and #baseName.
+     Compatibility note: use #head for ST-80 compatibility."
+
+    |idx d f comps|
+
+    comps := self class parseComponentsFrom:nameString.
+    d := comps directory.
+    (f := comps filename) size > 0  ifTrue:[
+        comps filename:nil.
+        ^ self class nameFromComponents:comps
+    ].
+
+    "/ path was of the form vol:[d1...dN]
+    "/ cut off the last directory.
+
+    d isNil ifFalse:[
+        d = '' ifTrue:[
+            "/ [] -> [-]
+        ] ifFalse:[
+            d = '-' ifTrue:[
+                "/ [-] -> [-.-]
+                d := '-.-'
+            ] ifFalse:[
+                (d endsWith:'.-') ifTrue:[
+                    "/ [rest.-] -> [rest.-.-]
+                    d := d , '.-'
+                ] ifFalse:[
+                    idx := d lastIndexOf:$..
+                    idx ~~ 0 ifTrue:[
+                        d := d copyTo:idx-1
+                    ]
+                ]
+            ]
+        ].
+        comps directory:d.
+    ].
+    ^ self class nameFromComponents:comps
+
+    "
+     (OpenVMSFilename named:'dka100:[stx.libbasic]Object.st') directoryName
+     (OpenVMSFilename named:'stx$root:[stx.libbasic.-]Object.st') directoryName 
+     (OpenVMSFilename named:'[-]Object.st') directoryName                       
+     (OpenVMSFilename named:'[]Object.st') directoryName                        
+     (OpenVMSFilename named:'Object.st') directoryName                          
+     (OpenVMSFilename named:'[stx.libbasic]') directoryName                     
+    "
+
+    "Created: 9.9.1997 / 09:23:15 / cg"
+    "Modified: 9.9.1997 / 10:36:42 / cg"
+!
+
+volume
+    "return the disc volume part of the name or an empty string."
+
+    ^ (self class parseComponentsFrom:nameString) volume ? ''
+
+    "
+     (OpenVMSFilename named:'dka100:[stx.libbasic]Object.st') volume  
+     (OpenVMSFilename named:'stx$root:[stx.libbasic.-]Object.st') volume 
+     (OpenVMSFilename named:'[-]Object.st') volume                       
+     (OpenVMSFilename named:'[]Object.st') volume                        
+     (OpenVMSFilename named:'Object.st') volume                          
+     (OpenVMSFilename named:'[stx.libbasic]') volume                     
+    "
+
+    "Modified: 9.9.1997 / 08:56:05 / cg"
+! !
+
+!OpenVMSFilename::NameComponents methodsFor:'accessing'!
+
+directory
+    ^ directory
+
+    "Created: 9.9.1997 / 05:21:04 / cg"
+!
+
+directory:aString
+    directory := aString
+
+    "Created: 9.9.1997 / 05:21:11 / cg"
+!
+
+filename
+    ^ filename
+
+    "Created: 9.9.1997 / 05:21:23 / cg"
+!
+
+filename:aString
+    filename := aString
+
+    "Created: 9.9.1997 / 05:21:28 / cg"
+!
+
+volume
+    ^ volume
+
+    "Created: 9.9.1997 / 05:20:58 / cg"
+!
+
+volume:aString
+    volume := aString
+
+    "Created: 9.9.1997 / 05:21:17 / cg"
+!
+
+volume:v directory:d filename:n
+    volume := v.
+    directory := d.
+    filename := n.
+
+    "Created: 9.9.1997 / 05:20:53 / cg"
+! !
+
+!OpenVMSFilename class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/libbasic/OpenVMSFilename.st,v 1.2 1997-09-09 17:35:20 cg Exp $'
+! !