[squeak-dev] The Inbox: System-dtl.1164.mcz
David T. Lewis
lewis at mail.msen.com
Fri Jun 12 19:41:34 UTC 2020
Hi Tim,
On Tue, Jun 09, 2020 at 12:06:00PM -0700, tim Rowledge wrote:
>
>
> > On 2020-06-09, at 11:52 AM, David T. Lewis <lewis at mail.msen.com> wrote:
> >
> > Funny you should mention it, that's how I went down this rabbit hole
> > in the first place. I was thinking that it would be an obviously good
> > thing to do if we could evaluate a doIt or named script file immediately
> > on image startup, as opposed to waiting until all of the Etoys script
> > processing comes to life somewhere later in the startUp process.
>
> Exactly. Note that VW has several commandline switches we might want to learn from
>
> -filein {some file names}
> -doit {some strings}
> -evaluate {a single string & write result to stdout & quit
> -cli {start a commandline loop}
>
Attached is a quick and dirty implementation than handles -filein, -doit, and -evaluate.
Dave
-------------- next part --------------
'From Squeak6.0alpha of 8 June 2020 [latest update: #19714] on 12 June 2020 at 3:38:05 pm'!
"Change Set: DoItFirst-dtl
Date: 12 June 2020
Author: David T Lewis
Be the first thing in the system startup list, and do things that should be done prior to any additional image initialization. If the first image argument is a recognized option, evalutate it. Image arguments are typically preceeded by a '--' token on the command line.
Possible command options:
-filein {some file names}
-doit {some strings}
-evaluate {a single string & write result to stdout & quit"!
!DoItFirst commentStamp: 'dtl 6/12/2020 15:34' prior: 0!
Be the first thing in the system startup list, and do things that should be done prior to any additional image initialization. If the first image argument is a recognized option, evalutate it. Image arguments are typically preceeded by a '--' token on the command line.
Possible command options:
-filein {some file names}
-doit {some strings}
-evaluate {a single string & write result to stdout & quit
!
!DoItFirst class methodsFor: 'class initialization' stamp: 'dtl 6/11/2020 18:42'!
initialize
"DoItFirst initialize"
Smalltalk addToStartUpList: self before: SmallInteger.! !
!DoItFirst class methodsFor: 'actions' stamp: 'dtl 6/12/2020 14:41'!
doIt: arguments
"Evaluate arguments and print the result on stdout, or error message on stderr.
Exit the image after any error."
FileStream startUp: true.
arguments do: [ :arg |
[FileStream stdout nextPutAll: (Compiler evaluate: arg) asString; lf; flush]
on: Error
do: [ :ex | FileStream stderr nextPutAll: ex asString; lf; flush.
Smalltalk quitPrimitive ]]! !
!DoItFirst class methodsFor: 'actions' stamp: 'dtl 6/12/2020 14:35'!
evaluate: arg
"Evaluate arg and print the result on stdout, or error message on stderr.
Exit immediately without saving the image."
FileStream startUp: true.
[FileStream stdout nextPutAll: (Compiler evaluate: arg) asString; lf; flush]
on: Error
do: [ :ex | FileStream stderr nextPutAll: ex asString; lf; flush ].
Smalltalk quitPrimitive! !
!DoItFirst class methodsFor: 'actions' stamp: 'dtl 6/12/2020 15:28'!
fileIn: fileNames
"File in each named file. On error, print a message to stderr and exit the image."
FileStream startUp: true.
fileNames do: [ :arg |
[ | fs |
fs := FileStream oldFileNamed: arg.
FileStream stdout nextPutAll: 'fiie in ', fs asString; lf; flush.
fs fileIn ]
on: Error
do: [ :ex | FileStream stderr nextPutAll: ex asString; lf; flush.
Smalltalk quitPrimitive ]]! !
!DoItFirst class methodsFor: 'system startup' stamp: 'dtl 6/12/2020 14:47'!
startUp: resuming
resuming ifTrue: [ | args |
args := Smalltalk arguments.
args size > 1
ifTrue: [ args first
caseOf: {
[ '-doit' ] -> [ self doIt: args allButFirst ] .
[ '--doit' ] -> [ self doIt: args allButFirst ] .
[ '-evaluate' ] -> [ self evaluate: args second ] .
[ '--evaluate' ] -> [ self evaluate: args second ] .
[ '-filein' ] -> [ self fileIn: args allButFirst ] .
[ '--filein' ] -> [ self fileIn: args allButFirst ]
}
otherwise: []]]
! !
DoItFirst initialize!
More information about the Squeak-dev
mailing list
|