From VisualWorks®, 7.6 of March 3, 2008 on March 3, 2008 at 9:47:08 pm (Dialog confirm: 'You are filing-in a Parcel source file!\\While this is possible it will not have\the same effect as loading the parcel.\None of the Parcel''s prerequisites will\be loaded and none of its load actions\will be performed.\\Are you sure you want to file-in?' withCRs) ifFalse: [self error: 'Parcel file-in abandoned. Choose terminate or close.'] <class> <name>NullStream</name> <environment>OS</environment> <super>Core.PeekableStream</super> <private>false</private> none <imports> private OS.IOConstants.* </imports> <category>Standard IO Streams</category> <attributes> <package>Standard IO Streams</package> </attributes> </class> <comment> OS.NullStream
For those platforms that do not have stdin, stdout or stderr (or those platforms which are not using the correct VM), the system needs a stand-in for StandardIOStream. This class provides that behavior. It ignores what is written to it, and answers a space when sent #next.
</comment> <class> <name>StandardIOSubsystem</name> <environment>OS</environment> <super>Core.Subsystem</super> <private>false</private> none error ioAccessorClass <imports></imports> <category>Standard I/O Streams</category> <attributes> <package>Standard IO Streams</package> </attributes> </class> <comment> OS.StandardIOSubsystem
This class arranges for the Stdin, Stdout and Stderr globals to be installed with appropriate streams. The subsystem is activated on image start-up when the #earlySystemInstallation event is sent. This activation is wrapped in an error handler, and if an error occurs it is stored in the error instance variable and NullStream instances are installed in the globals. Instance Variables: error <Error> The error if any that occured when the system was activated ioAccessorClass <IOAccessor | nil> The platforms specific IOAccessorClass that responds to #stdin, #stdout and #stderr with the appropriate handles
</comment> <class> <name>StandardIOStream</name> <environment>OS</environment> <super>Core.Stream</super> <private>false</private> none stream mutex <imports></imports> <category>Standard I/O Streams</category> <attributes> <package>Standard IO Streams</package> </attributes> </class> <comment> OS.StandardIOStream
StandardIOStream provides a minimal stream API around a stream, which is protected by a RecursionLock. It is intended to be used for the Stdin, Stdout and Stderr shared variable globals in the OS namespace. These globals are initialized with the proper stream when the system is returning from snapshot by the StandardStreamsSubstem. When using #nextPut: #nextPutAll:, and the argument contains a Character cr, then the stream will be implicitly flushed. Because of the RecursionLock, a client can also use #lockWhile: and not be concerned with deadlocking the mutex. For example: Stdout lockWhile: [Stdout nextPutAll: 'abc'; nextPut: 'def'; flush] Instance Variables: mutex <RecursionLock> The guard for thread safety stream <Stream> The stream that we are protecting
</comment> <name>Stderr</name> <environment>OS</environment> <private>false</private> <constant>false</constant> <category>standard i/o streams</category> <initializer>StandardIOStream new</initializer> <attributes> <package>Standard IO Streams</package> </attributes> <name>Stdout</name> <environment>OS</environment> <private>false</private> <constant>false</constant> <category>standard i/o streams</category> <initializer>StandardIOStream new</initializer> <attributes> <package>Standard IO Streams</package> </attributes> <name>Stdin</name> <environment>OS</environment> <private>false</private> <constant>false</constant> <category>standard i/o streams</category> <initializer>StandardIOStream new</initializer> <attributes> <package>Standard IO Streams</package> </attributes> <methods> OS.NullStream <category>accessing</category>
atEnd ^true
contents ^''
flush
next ^self class endOfStreamSignal raiseRequestFrom: self
nextPut: anObject
nextPutAll: anObject
upToAll: aCollection ^String new
</methods> <methods> OS.NullStream <category>stream modes</category>
binary
isBinary ^false
isText ^true
lineEndConvention ^LineEndTransparent
lineEndConvention: aNumber
text
</methods> <methods> OS.NullStream <category>positioning</category>
padTo: bsize
padTo: bsize put: aCharacter
position ^0
position: anInteger
skipToAll: aSequence
</methods> <methods> OS.NullStream <category>testing</category>
closed ^true
isReadable "The receiver does not actually read or write, but because it serves both roles for those platforms that do not have stdin/stdout/stderr answer true." ^true
isWritable "The receiver does not actually read or write, but because it serves both roles for those platforms that do not have stdin/stdout/stderr answer true." ^true
</methods> <methods> OS.NullStream class <category>instance creation</category>
new ^self basicNew
</methods> <methods> OS.StandardIOSubsystem <category>private</category>
handleError: anException error := anException. self installNullHandles
installHandles ioAccessorClass isNil ifTrue: [^self installNullHandles]. (Array with: Stdout with: Stdin with: Stderr) with: self standardHandles do: [:global :handle | "First, ensure that we are not in the set of OpenStreams." handle removeDependency. global stream: handle]
installNullHandles Stdout stream: NullStream new. Stdin stream: NullStream new. Stderr stream: NullStream new.
privateSetUp "Dispatch for the appropriate platform to set-up the globals in the OS namespace." | platformSymbol platformArray | platformArray := OSSystemSupport currentPlatform. platformSymbol := platformArray at: 1. ioAccessorClass := nil. #win32 == platformSymbol ifTrue: [ioAccessorClass := PCIOAccessor]. #unix == platformSymbol ifTrue: [ioAccessorClass := UnixIOAccessor]. self installHandles
standardHandles "Return the IOAccessor handles for stdout, stdin and stderr in that order." ^Array with: ioAccessorClass stdout with: ioAccessorClass stdin with: ioAccessorClass stderr
</methods> <methods> OS.StandardIOSubsystem <category>prerequisites</category>
prerequisiteSystems "The only prerequisite system we need is the one that flushes the open handles on start-up." ^Array with: EarlyInterestNotificationSystem.
</methods> <methods> OS.StandardIOSubsystem <category>accessing</category>
canActivate "We need to figure out a way to test if it is OK to activate. For example, on MacOS it doesn't make sense since there is no command line. On Windows it might be nice to know if the VM is actually the console engine. So this method simply calls its superclass' implemenation with this horrible comment as a reminder to come back and finish this." ^super canActivate
</methods> <methods> OS.StandardIOSubsystem <category>actions</category>
setUp "Because system start-up can occur before the windowing system is installed, capture the error that occured and do nothing." error := nil. [self privateSetUp] on: Error do: [:ex | self handleError: ex].
</methods> <methods> OS.StandardIOSubsystem class <category>options</category>
activationEvent ^#earlySystemInstallation.
</methods> <methods> OS.StandardIOStream <category>accessing</category>
commit "We can't actually call commit on stdout, so just flush." ^self flush.
contents "Answer with a copy of the receiver's readable information." ^mutex critical: [stream contents]
flush "If we have a bad stream handle, flush is the operation that reveals it. If so, just reset to be a null stream." ^mutex critical: [self flushStream].
lockWhile: aBlockClosure ^mutex critical: aBlockClosure
next ^mutex critical: [stream next]
nextPut: aByte ^mutex critical: [stream nextPut: aByte. aByte = Character cr ifTrue: [stream flush]]
nextPutAll: aCollection ^mutex critical: [|shouldFlush| shouldFlush := aCollection anySatisfy: [:each | each = Character cr]. stream nextPutAll: aCollection. shouldFlush ifTrue: [self flushStream]]
peek ^mutex critical: [stream peek]
peekFor: anObject "Answer false and do not move the position if self next ~= anObject or if the receiver is at the end. Answer true and increment position if self next = anObject." ^mutex critical: [stream peekFor: anObject]
skipToAll: aCollection "Skip forward to the next occurrence (if any) of aCollection. If found, leave the stream positioned before the occurrence, and answer the receiver; if not found, answer nil, and leave the stream positioned at the end." ^mutex critical: [stream skipToAll: aCollection]
skipUpTo: anObject "Skip forward to the occurrence (if any, not inclusive) of anObject. If not there, answer nil. Leaves stream positioned before anObject." ^mutex critical: [stream skipUpTo: anObject]
through: anObject ^mutex critical: [stream through: anObject]
upToAll: aCollection "Answer a subcollection from the current position up to the occurrence (if any, not inclusive) of aCollection, and leave the stream positioned before the occurrence. If no occurrence is found, answer the entire remaining stream contents, and leave the stream positioned at the end." ^mutex critical: [stream upToAll: aCollection]
upToSeparator "Answer a subcollection from position to the occurrence (if any, exclusive) of a separator. The stream is left positioned after the separator. If no separator is found answer everything." ^mutex critical: [stream upToSeparator].
</methods> <methods> OS.StandardIOStream <category>testing</category>
atEnd ^mutex critical: [[stream atEnd] on: OsInvalidArgumentsError , OsTransferFaultError do: [:ex | true]]
closed "Answer if the receiver is closed." ^mutex critical: [stream closed]
isReadable "Answer whether the stream implements #next." ^stream isReadable
isWritable "Answer whether the stream implements #next." ^stream isWritable
</methods> <methods> OS.StandardIOStream <category>initialize-release</category>
initialize mutex := RecursionLock new
stream: aStream mutex critical: [ stream := aStream]
</methods> <methods> OS.StandardIOStream <category>private</category>
contentsSpecies ^stream contentsSpecies
flushStream "Flush our internal stream. If we have a bad stream handle, flush is the operation that reveals it. If so, just reset to be a null stream" [stream flush] on: OSErrorHolder badAccessorSignal do: [:ex | StandardIOSubsystem current handleError: ex. ex return: nil].
</methods> <methods> OS.StandardIOStream <category>stream modes</category>
binary stream binary
isBinary ^stream isBinary
isText ^stream isText
lineEndConvention "Answer the numeric constant that corresponds to the current line-end convention (see the line-end constants in the pool of IOConstants for the range of possible values)." ^stream lineEndConvention
lineEndConvention: aNumber "Set the line-end convention to that corresponding to aNumber (aNumber should be one of the line-end constants from the pool of IOConstants)." stream lineEndConvention: aNumber
text stream text
</methods> <methods> OS.StandardIOStream <category>positioning</category>
padTo: bsize "Pad (skip) to next boundary of bsize characters, and answer how many characters were skipped." ^mutex critical: [stream padTo: bsize]
padTo: bsize put: aCharacter "Pad using the argument, aCharacter, to next boundary of bsize characters, and answer how many characters were written." ^mutex critical: [stream padTo: bsize put: aCharacter]
position "Answer the receiver's position." ^mutex critical: [stream position]
position: anIndex "StandardIOStreams cannot be positioned directly." ^self shouldNotImplement
skip: n "Reposition to the relative number n." mutex critical: [stream skip: n]
</methods> <methods> OS.StandardIOStream <category>fileIn</category>
nextChunk "Answer the contents of the receiver, up to the next terminator character, with double terminators ignored." ^mutex critical: [stream nextChunk]
</methods> <methods> OS.StandardIOStream <category>character reading</category>
skipSeparators "Move the receiver's position past any separators." ^mutex critical: [stream skipSeparators]
</methods> <methods> OS.StandardIOStream <category>status</category>
close "Close the stream. Note that if this is actually stdin/out/err, this is probably not a good idea." ^mutex critical: [stream close].
</methods> <methods> OS.StandardIOStream class <category>instance creation</category>
new ^self basicNew initialize
on: stream ^(self new) stream: stream; yourself
</methods> <methods> OS.UnixIOAccessor class <category>standard streams</category>
stdin "Return an initialized stream for the handle associated with stdin." ^ExternalReadStream on: (self connectionForStandardHandleNumber: 0)
</methods> <methods> OS.PCIOAccessor class <category>standard streams</category>
stderr "Return an initialized stream for the handle associated with stderr." ^ExternalWriteStream on: (self connectionForStandardHandleNumber: 2)
</methods> <methods> OS.PCIOAccessor class <category>primtive-standard streams</category>
primHandleForStandardIOStream: id "Return the the handle for either Stdin, Stdout or Stderr (0, 1, 2). Repeated calls with the same id will cause the primitive to fail. This is why the StandardStreamsSubsystem is used to set up the globals for Stdin, Stdout and Stderr." <primitive: 740 errorCode: error> ^self errorReporter reportProceedingOn: self new.
</methods> <methods> OS.UnixIOAccessor class <category>private-standard streams</category>
primHandleForStandardIOStream: id "Return the handle for the standard handle associated with id. On UNIX, we do not need to call a primitive but, we do need to duplicate the handle." (#(0 1 2) includes: id) ifFalse: [self error: #invalidrequest << #dialogs >> 'invalid request']. ^OSSystemSupport concreteClass new dup: id
</methods> <methods> OS.PCIOAccessor class <category>standard streams</category>
connectionForStandardHandleNumber: anInteger "Return an ExternalConnection on Stdout, Stdin, or Stderr, depending on the number passed in. Note that we explicitly do not call the normal handleValue: routine, which registers the handle in the OpenFDs handle registry. This is because handles in that registry are automatically closed on finalization, and standard i/o handles cannot be closed." ^ExternalConnection ioAccessor: (self defaultForFiles new initialize handle: (self primHandleForStandardIOStream: anInteger))
stdout "Return an initialized stream for the handle associated with stdout." ^ExternalWriteStream on: (self connectionForStandardHandleNumber: 1)
stdin "Return an initialized stream for the handle associated with stdin." ^ExternalReadStream on: (self connectionForStandardHandleNumber: 0)
</methods> <methods> OS.UnixIOAccessor class <category>standard streams</category>
connectionForStandardHandleNumber: anInteger "Return an ExternalConnection on Stdout, Stdin, or Stderr, depending on the number passed in. Note that we explicitly do not call the normal handleValue: routine, which registers the handle in the OpenFDs handle registry. This is because handles in that registry are automatically closed on finalization, and standard i/o handles cannot be closed." ^ExternalConnection ioAccessor: (UnixPipeAccessor new initialize handle: (self primHandleForStandardIOStream: anInteger))
stderr "Return an initialized stream for the handle associated with stderr." ^ExternalWriteStream on: (self connectionForStandardHandleNumber: 2)
stdout "Return an initialized stream for the handle associated with stdout." ^ExternalWriteStream on: (self connectionForStandardHandleNumber: 1)
</methods> <methods> Core.ImageConfigurationSystem <category>private</category>
stdout ^OS.Stdout.
</methods> <methods> Core.ImageConfigurationSystem <category>command line handling</category>
runCodeAndThenQuit: argumentStream "This allows you to run arbitrary code from the command line, specified a Smalltalk string to be evaluated. After evaluation, the string will be printed to standard out and the image will quit. Make very sure that we always quit, even if closing the stream doesn't work." <option: '-evaluate'> | expressions result | self class allowExpressions ifFalse: [^self]. [expressions := CommandLineInterest argumentsFrom: argumentStream. expressions do: [:each | result := Compiler evaluate: each. self stdout nextPutAll: result displayString. self stdout flush]] ensure: [ObjectMemory quit].
</methods> <methods> Core.LocaleSystem <category>prerequisites</category>
standardIOPrerequisite <prerequisites> ^StandardIOSubsystem.
</methods> <methods> OS.UnixSystemSupport <category>procedures</category>
dup: filedes <C: int dup(int filedes)> ^self externalAccessFailedWith: _errorCode
</methods> "Imported Classes:" self error: 'Attempting to file-in parcel imports. Choose terminate or close' <class> <name>Subsystem</name> <environment>Core</environment> <super>Core.Object</super> <private>false</private> none state canActivate prerequisites current <imports></imports> <category>System-Subsystems</category> <attributes> <package>System-Subsystems</package> </attributes> </class> <class> <name>LocaleSystem</name> <environment>Core</environment> <super>Core.Subsystem</super> <private>false</private> none <imports></imports> <category>System-Subsystems</category> <attributes> <package>System-Subsystems</package> </attributes> </class> <class> <name>Stream</name> <environment>Core</environment> <super>Core.Object</super> <private>false</private> none <imports> private IOConstants.* </imports> <category>Collections-Streams</category> <attributes> <package>Collections-Streams</package> </attributes> </class> <class> <name>PeekableStream</name> <environment>Core</environment> <super>Core.Stream</super> <private>false</private> none <imports></imports> <category>Collections-Streams</category> <attributes> <package>Collections-Streams</package> </attributes> </class> <class> <name>ImageConfigurationSystem</name> <environment>Core</environment> <super>Core.Subsystem</super> <private>false</private> none allowParcelLoading allowFilein allowSettings allowExpressions useDefaultConfigFile allowDevelopment <imports></imports> <category>System-Subsystems</category> <attributes> <package>System-Subsystems</package> </attributes> </class> <class> <name>UnixSystemSupport</name> <environment>OS</environment> <super>OS.OSSystemSupport</super> <private>false</private> none <imports> OS.UnixSystemSupportDictionary.* </imports> <category>OS-Unix</category> <attributes> <includeFiles></includeFiles> <includeDirectories></includeDirectories> <libraryFiles>linkedIn</libraryFiles> <libraryDirectories></libraryDirectories> false full <package>OS-Unix</package> </attributes> </class>