UnixFilename.st
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--
EncodedStream inherts from PeekableStream
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    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
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
Filename subclass:#UnixFilename
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	instanceVariableNames:''
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	classVariableNames:''
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	poolDictionaries:''
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	category:'OS-Unix'
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
!
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    22
!UnixFilename class methodsFor:'documentation'!
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    23
2931
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    24
copyright
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    25
"
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    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
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    28
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    29
 This software is furnished under a license and may be used
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    30
 only in accordance with the terms of that license and with the
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    32
 be provided or otherwise made available to, or used by, any
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    33
 other person.  No title to or ownership of the software is
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    34
 hereby transferred.
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    35
"
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    36
!
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    37
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    38
documentation
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    39
"
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    40
    Filenames in Unix.
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    41
"
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    42
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    43
! !
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    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
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
!UnixFilename class methodsFor:'queries'!
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
isBadCharacter:aCharacter
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    "return true, if aCharacter is unallowed in a filename."
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    aCharacter == $/ ifTrue:[^ true].
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    ^ super isBadCharacter:aCharacter
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
    "Created: 8.9.1997 / 00:13:14 / cg"
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
!
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
    78
isCaseSensitive
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
    79
    "return true, if filenames are case sensitive.return true, if filenames are case sensitive."
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
    80
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
    81
    ^ true
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
    82
!
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
    83
3171
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
    84
nullFilename
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
    85
    "Return /dev/null"
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
    86
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
    87
    ^ '/dev/null'
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
    88
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
    89
    "
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
    90
     Filename concreteClass nullFilename  
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
    91
    "
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
    92
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
    93
    "Modified: / 14.1.1998 / 14:20:55 / stefan"
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
    94
!
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
    95
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
    96
parentDirectoryName
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
    97
    "return the name used for the parent directory.
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
    98
     This is '..' for unix and dos-like systems.
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
    99
     (there may be more in the future."
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
   100
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
   101
    ^ '..'
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
   102
!
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
   103
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
separator
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
    "return the file/directory separator."
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
     ^ $/
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
     "
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
      Filename concreteClass separator  
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
     "
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    "Created: 8.9.1997 / 00:18:14 / cg"
8245
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   114
!
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   115
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   116
separatorString
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   117
    "return the file/directory separator as a string."
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   118
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   119
    ^ '/'
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   120
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   121
    "
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   122
     Filename concreteClass separatorString  
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   123
    "
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
! !
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
!UnixFilename methodsFor:'file queries'!
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
fileType
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    "this returns a string describing the type of contents of
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
     the file. This is done using the unix 'file' command,
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
     (which usually is configurable by /etc/magic).
3664
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   132
     Warning:
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   133
         Since the returned string differs among systems (and language settings),
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   134
         it is only useful for user-information; 
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   135
         NOT as a tag to be used by a program."
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
    |stream typeString|
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
    "/ since executing 'file' takes some time, do the most common
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
    "/ ones are checked first, using the general fileType implementation. 
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
    "/ (also, the file-command is only available on Unix systems.
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
    typeString := super fileType.
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
    typeString ~= 'file' ifTrue:[^ typeString].
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   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
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
    stream notNil ifTrue:[
3664
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   148
        typeString := stream contents asString.
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   149
        stream close.
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   150
        typeString := typeString copyFrom:(typeString indexOf:$:) + 1.
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   151
        typeString := typeString withoutSeparators
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
    ].
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
    ^ typeString
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
    "
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
     'Makefile' asFilename fileType 
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
     '.' asFilename fileType     
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
     '/dev/null' asFilename fileType        
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
     'smalltalk.rc' asFilename fileType    
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
     'bitmaps/SBrowser.xbm' asFilename fileType    
3664
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   161
     '../../libtool/bitmaps/SBrowser.xbm' asFilename fileType    
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
    "
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
3664
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   164
    "Modified: / 21.7.1998 / 11:26:32 / cg"
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
! !
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
2931
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   167
!UnixFilename methodsFor:'queries'!
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   168
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   169
isExplicitRelative
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   170
    "return true, if this name is an explicit relative name
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   171
     (i.e. starts with './' or '../', to avoid path-prepending)"
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   172
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   173
    (nameString startsWith:'./') ifTrue:[
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   174
	^ true
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   175
    ].
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   176
    (nameString startsWith:'../') ifTrue:[
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   177
	^ true
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   178
    ].
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   179
    ^ false
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   180
!
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   181
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   182
isHidden
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   183
    "return true, if the receiver represents a hidden file.
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   184
     On UNIX, a name starting with a period is considered hidden."
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   185
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   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
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   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
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   198
    "Modified: / 18.9.1997 / 18:03:28 / stefan"
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   199
    "Modified: / 21.7.1998 / 11:10:42 / cg"
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   200
!
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   201
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   202
nameWithSpecialExpansions:aString
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   203
    "return the nameString, expanding any OS specific macros. 
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   204
     Here, a ~ prefix is expanded to the users home dir (as in csh)"
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   205
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   206
    |dir user cutIdx idx userInfo|
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   207
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   208
    (aString startsWith:'~') ifTrue:[
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   209
        dir := OperatingSystem getHomeDirectory.
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   210
        cutIdx := 2.
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   211
        "/ look for ~username
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   212
        (aString size > 1) ifTrue:[
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   213
            idx := aString indexOf:$/.
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   214
            idx == 0 ifTrue:[
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   215
                user := aString copyFrom:2.
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   216
                cutIdx := aString size + 1.
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   217
            ] ifFalse:[
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   218
                user := aString copyFrom:2 to:(idx - 1).
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   219
                cutIdx := idx.
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   220
            ].
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   221
            user size > 0 ifTrue:[
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   222
                userInfo := OperatingSystem userInfoOf:user.
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   223
                (userInfo notNil and:[userInfo includesKey:#dir]) ifTrue:[
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   224
                    dir := userInfo at:#dir
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   225
                ] ifFalse:[
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   226
                    dir := nil
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   227
                ]
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   228
            ].
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   229
            dir isNil ifTrue:[
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   230
"/                ('Filename [info]: unknown user: ' , user) infoPrintCR.
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   231
                ^ aString
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   232
            ].
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   233
        ].
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   234
        ^ dir , (aString copyFrom:cutIdx)
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   235
    ].
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   236
    ^ aString
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   237
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   238
    "
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   239
     UnixFilename new nameWithSpecialExpansions:'~'      
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   240
     UnixFilename new nameWithSpecialExpansions:'~/work'  
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   241
     UnixFilename new nameWithSpecialExpansions:'~sv'     
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   242
     UnixFilename new nameWithSpecialExpansions:'~sv/work' 
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   243
     UnixFilename new nameWithSpecialExpansions:'~foo'    
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   244
     UnixFilename new nameWithSpecialExpansions:'~foo/bar' 
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   245
    "
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   246
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   247
    "Modified: / 21.7.1998 / 11:09:59 / cg"
2931
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   248
! !
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   249
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   250
!UnixFilename class methodsFor:'documentation'!
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   252
version
8245
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   253
    ^ '$Header: /cvs/stx/stx/libbasic/UnixFilename.st,v 1.10 2004-03-20 15:03:09 cg Exp $'
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
! !