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