# HG changeset patch # User Claus Gittinger # Date 827603720 -3600 # Node ID 94c803be0210d77c13cbe6bf4d131aa33d01369b # Parent 956d62a5656c43c002f67758310eab1e69ac8f76 compile errorMethods with +optSpace diff -r 956d62a5656c -r 94c803be0210 Filename.st --- a/Filename.st Sat Mar 23 18:22:50 1996 +0100 +++ b/Filename.st Sat Mar 23 18:55:20 1996 +0100 @@ -226,14 +226,14 @@ sep := self separator asString. s := ''. aCollectionOfDirectoryNames keysAndValuesDo:[:index :component | - index == 1 ifTrue:[ - (component ~= sep - or:[aCollectionOfDirectoryNames size == 1]) ifTrue:[ - s := s , component - ] - ] ifFalse:[ - s := s , '/' , component - ]. + index == 1 ifTrue:[ + (component ~= sep + or:[aCollectionOfDirectoryNames size == 1]) ifTrue:[ + s := s , component + ] + ] ifFalse:[ + s := s , '/' , component + ]. ]. ^ self named:s @@ -243,10 +243,10 @@ Filename fromComponents:#('/') Filename fromComponents: - (Filename components:('.' asFilename pathName)) + (Filename components:('.' asFilename pathName)) Filename fromComponents: - (Filename components:('.' asFilename name)) + (Filename components:('.' asFilename name)) " "Modified: 29.2.1996 / 20:18:34 / cg" @@ -276,7 +276,7 @@ s := OperatingSystem getHomeDirectory. s isNil ifTrue:[ - ^ self defaultDirectory + ^ self defaultDirectory ]. ^ s asFilename @@ -330,7 +330,7 @@ |pid nm| NextTempFilenameIndex isNil ifTrue:[ - NextTempFilenameIndex := 1. + NextTempFilenameIndex := 1. ]. " @@ -341,9 +341,9 @@ NextTempFilenameIndex := NextTempFilenameIndex + 1. (aDirectoryPrefix isNil or:[aDirectoryPrefix asString isEmpty]) ifFalse:[ - nm := aDirectoryPrefix asFilename construct:nm + nm := aDirectoryPrefix asFilename construct:nm ] ifTrue:[ - nm := nm asFilename + nm := nm asFilename ]. ^ nm @@ -380,18 +380,18 @@ (at least on unix ...). Notice: do not hardcode '/tmp' into your programs - things may be - different on other OS's. Also, the user may want to set the - TMPDIR environment variable to have her temp files somewhere else. - (especially on SUNOS, the root partition is ALWAYS too small ..." + different on other OS's. Also, the user may want to set the + TMPDIR environment variable to have her temp files somewhere else. + (especially on SUNOS, the root partition is ALWAYS too small ..." |tempDir| tempDir := OperatingSystem getEnvironment:'ST_TMPDIR'. tempDir isNil ifTrue:[ - tempDir := OperatingSystem getEnvironment:'TMPDIR'. - tempDir isNil ifTrue:[ - tempDir := '/tmp' - ]. + tempDir := OperatingSystem getEnvironment:'TMPDIR'. + tempDir isNil ifTrue:[ + tempDir := '/tmp' + ]. ]. ^ self named:tempDir @@ -418,7 +418,7 @@ components := aString asCollectionOfSubstringsSeparatedBy:(self separator). components first isEmpty ifTrue:[ - components at:1 put:(self separator asString) + components at:1 put:(self separator asString) ]. ^ components @@ -676,30 +676,50 @@ !Filename methodsFor:'error handling'! accessDeniedError:filename + "{ Pragma: +optSpace }" + + "report an error that access to some file was denied" + ^ OperatingSystem accessDeniedErrorSignal raiseRequestWith:filename errorString:('access denied: ' , filename asString) ! fileCreationError:filename + "{ Pragma: +optSpace }" + + "report an error that some file could not be created" + ^ OperatingSystem accessDeniedErrorSignal raiseRequestWith:filename errorString:('cannot create/write file: ' , filename asString) ! fileNotFoundError:filename + "{ Pragma: +optSpace }" + + "report an error that some file was not found" + ^ OperatingSystem fileNotFoundErrorSignal raiseRequestWith:filename errorString:('file not found: ' , filename asString) ! removeError:filename + "{ Pragma: +optSpace }" + + "report an error that some file could not be removed" + ^ OperatingSystem accessDeniedErrorSignal raiseRequestWith:filename errorString:('cannot remove: ' , filename asString) ! reportError:string with:filename + "{ Pragma: +optSpace }" + + "report an error" + ^ OperatingSystem errorSignal raiseRequestWith:filename errorString:string @@ -1002,7 +1022,7 @@ This may not be supported on all operating systems" (OperatingSystem truncateFile:nameString to:newSize) ifFalse:[ - ^ self reportError:'unsupported operation' with:self + ^ self reportError:'unsupported operation' with:self ] " @@ -1205,8 +1225,8 @@ sepString := self class separator asString. nameString = sepString ifTrue:[ - "I am the root" - ^ sepString , subname + "I am the root" + ^ sepString , subname ]. ^ nameString , sepString , subname asString @@ -1577,89 +1597,89 @@ sepString := self class separator asString. (nameString endsWith:sepString) ifTrue:[ - ^ #() + ^ #() ]. parentString := self class parentDirectoryName. baseName := self baseName. baseName ~= nameString ifTrue:[ - prefix := self directoryName. + prefix := self directoryName. ]. self isAbsolute ifTrue:[ - dir := self directory + dir := self directory ] ifFalse:[ - aDirectory isNil ifTrue:[ - dir := self directory - ] ifFalse:[ - dir := (aDirectory construct:nameString) directory - ] + aDirectory isNil ifTrue:[ + dir := self directory + ] ifFalse:[ + dir := (aDirectory construct:nameString) directory + ] ]. matching := OrderedCollection new. dir directoryContents do:[:fileName | - ((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ - (fileName startsWith:baseName) ifTrue:[ - matching add:fileName - ] - ] + ((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ + (fileName startsWith:baseName) ifTrue:[ + matching add:fileName + ] + ] ]. (nMatch := matching size) > 1 ifTrue:[ - " - find the longest common prefix - " - matchLen := baseName size. - matchLen > matching first size ifTrue:[ - try := baseName. - allMatching := false - ] ifFalse:[ - try := matching first copyTo:matchLen. - allMatching := true. - ]. + " + find the longest common prefix + " + matchLen := baseName size. + matchLen > matching first size ifTrue:[ + try := baseName. + allMatching := false + ] ifFalse:[ + try := matching first copyTo:matchLen. + allMatching := true. + ]. - [allMatching] whileTrue:[ - matching do:[:aName | - (aName startsWith:try) ifFalse:[ - allMatching := false - ] - ]. - allMatching ifTrue:[ - matchLen < matching first size ifTrue:[ - matchLen := matchLen + 1. - try := matching first copyTo:matchLen. - ] ifFalse:[ - allMatching := false - ] - ] ifFalse:[ - try := matching first copyTo:matchLen - 1. - ] - ]. - " - and set my name to the last full match - " - nameString := try + [allMatching] whileTrue:[ + matching do:[:aName | + (aName startsWith:try) ifFalse:[ + allMatching := false + ] + ]. + allMatching ifTrue:[ + matchLen < matching first size ifTrue:[ + matchLen := matchLen + 1. + try := matching first copyTo:matchLen. + ] ifFalse:[ + allMatching := false + ] + ] ifFalse:[ + try := matching first copyTo:matchLen - 1. + ] + ]. + " + and set my name to the last full match + " + nameString := try ]. " if I had a directory-prefix, change names in collection ... " prefix notNil ifTrue:[ - prefix = '/' ifTrue:[ - "/ avoid introducing double slashes - prefix := '' - ]. - matching := matching collect:[:n | prefix , '/' , n]. - nMatch == 1 ifTrue:[ - nameString := matching first - ] ifFalse:[ - nMatch > 1 ifTrue:[ - nameString := prefix , '/' , nameString - ] - ] + prefix = '/' ifTrue:[ + "/ avoid introducing double slashes + prefix := '' + ]. + matching := matching collect:[:n | prefix , '/' , n]. + nMatch == 1 ifTrue:[ + nameString := matching first + ] ifFalse:[ + nMatch > 1 ifTrue:[ + nameString := prefix , '/' , nameString + ] + ] ] ifFalse:[ - nMatch == 1 ifTrue:[ - nameString := matching first - ] + nMatch == 1 ifTrue:[ + nameString := matching first + ] ]. " @@ -1803,11 +1823,11 @@ nm := self baseName. idx := nm lastIndexOf:(self class suffixSeparator). idx == 0 ifTrue:[ - ^ Array with:nm with:'' + ^ Array with:nm with:'' ]. ^ Array - with:(nm copyTo:idx-1) - with:(nm copyFrom:idx+1) + with:(nm copyTo:idx-1) + with:(nm copyFrom:idx+1) " 'abc.st' asFilename prefixAndSuffix @@ -1828,9 +1848,9 @@ otherwise, the new suffix simply appended to the name." ^ self class named: - (self withoutSuffix name - , self class suffixSeparator asString - , aSuffix asString) + (self withoutSuffix name + , self class suffixSeparator asString + , aSuffix asString) " 'abc.st' asFilename withSuffix:'o' @@ -1869,5 +1889,5 @@ !Filename class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.53 1996-03-07 13:53:37 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.54 1996-03-23 17:55:20 cg Exp $' ! !