UnixFilename.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Sep 1997 04:57:04 +0200
changeset 2908 b3be3629fcb1
parent 2907 1666bf27f351
child 2911 9964e6839a8e
permissions -rw-r--r--
vms stuff

'From Smalltalk/X, Version:3.1.9 on 8-sep-1997 at 12:39:54 am'                  !

Filename subclass:#UnixFilename
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'OS-Unix'
!

!UnixFilename class methodsFor:'queries'!

isBadCharacter:aCharacter
    "return true, if aCharacter is unallowed in a filename."

    aCharacter == $/ ifTrue:[^ true].
    ^ super isBadCharacter:aCharacter

    "Created: 8.9.1997 / 00:13:14 / cg"
!

isCaseSensitive
    "return true, if filenames are case sensitive.return true, if filenames are case sensitive."

    ^ true
!

parentDirectoryName
    "return the name used for the parent directory.
     This is '..' for unix and dos-like systems.
     (there may be more in the future."

    ^ '..'
!

separator
    "return the file/directory separator."

     ^ $/

     "
      Filename concreteClass separator  
     "

    "Created: 8.9.1997 / 00:18:14 / cg"
! !

!UnixFilename methodsFor:'file queries'!

fileType
    "this returns a string describing the type of contents of
     the file. This is done using the unix 'file' command,
     (which usually is configurable by /etc/magic).
     On non-unix systems, this may return an empty string, not knowning
     about the contents.
     Since the returned string differs among systems (and language settings),
     it is only useful for user-information; NOT as a tag to be used by a program."

    |stream typeString|

    "/ since executing 'file' takes some time, do the most common
    "/ ones are checked first, using the general fileType implementation. 
    "/ (also, the file-command is only available on Unix systems.

    typeString := super fileType.
    typeString ~= 'file' ifTrue:[^ typeString].

    stream := PipeStream readingFrom:('file ' , self pathName).
    stream notNil ifTrue:[
        typeString := stream contents asString.
        stream close.
        typeString := typeString copyFrom:(typeString indexOf:$:) + 1.
        typeString := typeString withoutSeparators
    ].
    ^ typeString

    "
     'Makefile' asFilename fileType 
     '.' asFilename fileType     
     '/dev/null' asFilename fileType        
     'smalltalk.rc' asFilename fileType    
     'bitmaps/SBrowser.xbm' asFilename fileType    
    "

    "Modified: 7.9.1997 / 23:43:03 / cg"
! !

!UnixFilename 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)."

    |sepString|

    sepString := self class separator asString.
    nameString = sepString ifTrue:[
	"I am the root"
	^ sepString  , subname
    ].
    ^ nameString , sepString , subname asString

    "
     '/tmp' asFilename constructString:'foo'   
     '/' asFilename constructString:'foo'         
     '/usr/tmp' asFilename constructString:'foo'
     '/foo/bar' asFilename constructString:'baz' 
    "

    "Modified: 7.9.1995 / 10:15:22 / claus"
    "Modified: 29.2.1996 / 20:55:18 / cg"
    "Created: 7.9.1997 / 23:44:55 / cg"
! !