<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Hi Juan,<br>
<br>
I had a closer look at your implementation.<br>
It is less code and looks simpler, but it uses offsets and
indexes,<br>
therefore I find it harder to understand.<br>
<br>
It has the following drawbacks/missing features:<br>
<br>
<ol>
<li>It is not possible to pass options to scripts, they are are
all consumed<br>
by the parsing code and then ether honored or ignored.</li>
<li>In order to implement <tt>#lastCommandLineArguments</tt>
properly, you have to look <b>ahead</b> for a <tt>--</tt>.<br>
Of course before parsing, the arguments after <tt>--</tt>
can be stored in an instance variable<br>
</li>
</ol>
I am against implementing feature 1, because<br>
it implies once we add new options understood by Cuis' image,<br>
the options passed to the script would change in a rather
surprising way.<br>
<br>
The attached changes set implements feature 2.<br>
It only adds an instance variable and about 7 lines of code.<br>
With it you can do something like:<br>
<br>
--- snip ---<br>
<tt>squeak -vm-display-null -headless Cuis6.0-5632cli2.image -d
"Smalltalk scriptingArguments do: [ :arg | StdIOWriteStream
stdout nextPutAll: arg; space]. StdIOWriteStream stdout newLine"
a b c dee -d "Smalltalk scriptingArguments do: [ :arg |
StdIOWriteStream stdout nextPutAll: arg; space].
StdIOWriteStream stdout newLine" z y x why -q -- 1 2 3 -o</tt><br>
--- snap ---<br>
<br>
and get the following output:<br>
<br>
--- snip ---<br>
<tt>a b c dee 1 2 3 -o </tt><tt><br>
</tt><tt>z y x why 1 2 3 -o </tt><br>
--- snap ---<br>
<br>
I suppose that should support all sensible uses cases.<br>
I also presume, that all requirements of Dr. Geo are fulfilled.<br>
<br>
<br>
HTH and Best Regards,<br>
<br>
Gerald<br>
<br>
<br>
<br>
On 1/13/23 8:21 PM, Juan Vuletich wrote:<br>
</div>
<blockquote type="cite" cite="mid:63C1AF4F.3000004@cuis.st">Hi
Gerald,
<br>
<br>
Please check the attach. Besides being simpler and hopefully
easier to understand, it allows each script to have its own set of
arguments.
<br>
<br>
Perhaps we could add another getter to SystemDictionary, something
like #lastCommandLineArguments or such, to fetch what's after
'--'.
<br>
<br>
Thanks,
<br>
<br>
On 1/13/2023 1:18 PM, Gerald Klix via Cuis-dev wrote:
<br>
<blockquote type="cite">I never received this message, therefore I
am reseinding it:
<br>
<br>
<br>
Hi Juan,
<br>
<br>
let me answer questions one at time (even those that were not
asked:)
<br>
<br>
-q) If want to write small Cuis scripts, like the prototypical
“Hello World” program, you would write something like this:
<br>
<br>
squeak -vm-display-null -headless Cuis6.0-5626 -d
"StdIOWriteStream stdout nextPutAll: 'Hello World!'; newLine.
Smalltalk quit"
<br>
<br>
If you want to dump all unknown contributors to a file; it would
look like this:
<br>
<br>
squeak -vm-display-null -headless Cuis6.0-5626 -d "Smalltalk
unknownContributors printOn: StdIOWriteStream stdout. Smalltalk
quit" > unknownContributors.txt
<br>
<br>
Of course all these one-liners will end with `Smalltalk quit`,
therefore I came up with a shorter way to achieve the same
effect:
<br>
<br>
squeak -vm-display-null -headless Cuis6.0-5626 -d "Smalltalk
unknownContributors printOn: StdIOWriteStream stdout" -q >
unknownContributors.txt
<br>
<br>
-c) is completely useless, because the old implementation only
accepts one `-s` option.
<br>
`-s` consumes and copies all the remaining arguments to
`startUpScriptArguments`,
<br>
terminating the loop,I did not catch that detail.
<br>
I will fix this in the next version of the change.
<br>
<br>
--) Posix requires a program to stop option parsing once it
encounters a double dash.
<br>
To give an example that proves the necessity of this behavior,
just try this in your Mac's terminal:
<br>
<br>
echo Hehehe > -f
<br>
<br>
Than try to delete the file named “-f” using `rm -f`. This does
not work, you have to use `rm -- -f`.
<br>
You can also check git, grep, ls or any other little Unix
utility . Just check:
<br>
<br>
echo Hehehe > -r
<br>
ls -r
<br>
<br>
vs.
<br>
<br>
ls -- -r
<br>
<br>
(I leave it as an exercise to the gentle reader to get rid of
that '-r' file.)
<br>
<br>
Therefore handling `--` should be done correctly, because it
avoids unnecessary surprises.
<br>
But it also makes it easy to pass arguments to code package
(classes) that are
<br>
installed with "-r". This part of Haver's installation package
could be written in a less hacky way:
<br>
<br>
<a class="moz-txt-link-freetext" href="https://hg.sr.ht/~cy-de-fect/HaverOnCuis/browse/haver/Haverize.pck.st?rev=tip#L131">https://hg.sr.ht/~cy-de-fect/HaverOnCuis/browse/haver/Haverize.pck.st?rev=tip#L131</a>
<br>
<br>
The same is true for the `-d` option, you can implement `echo`
with Cuis like this:
<br>
<br>
squeak -vm-display-null -headless Cuis6.0-5626 -d "Smalltalk
startUpScriptArguments do: [ :arg | StdIOWriteStream stdout
nextPutAll: arg; space]. StdIOWriteStream stdout newLine" -q --
-n 1 2 3 a b dee
<br>
<br>
compare to
<br>
<br>
echo -- -n 1 2 3 a b dee
<br>
<br>
Of course you want '--' handled correctly in your Cuis scripts,
there is no use
<br>
in every author implementing it again, when she needs it.
<br>
<br>
<br>
#copyStartupScriptArgumentsFrom:)
<br>
<br>
Simply creates a fresh copy of the arguments after `--` for
<br>
each script, code file, package or piece of code passed on the
command line.
<br>
<br>
There is a reason for recreating the array for each script, code
file etc.:
<br>
I never like the Unix's getopt(3) behavior.
<br>
«By default, getopt() permutes the contents of argv as it scans,
<br>
so that eventually all the nonoptions are at the end.»
<br>
(<a class="moz-txt-link-freetext" href="https://www.man7.org/linux/man-pages/man3/getopt.3.html">https://www.man7.org/linux/man-pages/man3/getopt.3.html</a>)
<br>
Option parsing and program should no mess with the command line
arguments,
<br>
this creates all sorts of nasty side effects.
<br>
<br>
I hope I made my point about "end of options" and "--" clear.
<br>
Please give some time to come up with a simpler version of the
change.
<br>
<br>
<br>
HTH,
<br>
<br>
Gerald
<br>
<br>
<br>
On 1/12/23 3:59 PM, Juan Vuletich wrote:
<br>
<blockquote type="cite">Hi Gerald,
<br>
<br>
I agree that "do not ignore exceptions" doesn't need an
argument. Then, maybe -e should never take an argument. I also
like -h and -v. Not sure about the value of -q, but I
wouldn't mind including it.
<br>
<br>
But can you explain -- and #copyStartupScriptArgumentsFrom: ?
Can you give an example of use? I don't get it.
<br>
<br>
Thanks,
<br>
<br>
On 1/11/2023 6:53 PM, Gerald Klix via Cuis-dev wrote:
<br>
<blockquote type="cite">Hi guys,
<br>
<br>
thanks a lot for the encouraging feedback.
<br>
<br>
It motivated me to to improve the exception
<br>
ignoring stuff a bit; I just wanted '-e' to work without an
argument.
<br>
Then I noticed, that we can't handle options without
arguments.
<br>
Therefore I added, em well, some other options to the
command line
<br>
parsing code. I hope I haven't overdone it.
<br>
<br>
You can now say `squeak Cuis.image -h` and get this output:
<br>
<br>
--- snip --
<br>
Command line options:
<br>
-h Display this help message and quit
<br>
-v Display the system information, containg the version and
quit
<br>
-q Just quit
<br>
-e <exception> Evaluate exception and ignore it
<br>
-e Set the exception to ignore to nil, i.e. do not ignore
exceptions
<br>
-r <feature> Require <feature>
<br>
-d <code> Evaluate <code>
<br>
-l <codeFile> Load e.g. file in <codeFile>
<br>
-s <scriptFile> Evaluate code ein <scriptFile>
<br>
-c Clear the array of start up script arguments
<br>
-- end of options; stop processing options
<br>
<br>
Arguments for scripts, code files, packages (and
<code>):
<br>
-s and -- store the remaining arguments in 'Smalltalk
startUpScriptArguments'
<br>
-c clears the aforementioned array
<br>
Packages (-f), code files (-l) and code (-d) gets a fresh
copy of the array if -- is present
<br>
<br>
Multiple options:
<br>
Options -e, -r, -d, -l, -s and -c can be passed multiple
times
<br>
--- snap ---
<br>
<br>
Please review the change set and give me feedback.
<br>
There might be some incompatibilities.
<br>
<br>
<br>
HTH and Best Regards,
<br>
<br>
Gerald
<br>
<br>
<br>
<br>
On 1/11/23 2:33 PM, Dr. Nicola Mingotti wrote:
<br>
<blockquote type="cite">nice !
<br>
<br>
Nicola
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
On 1/8/23 17:21, Gerald Klix via Cuis-dev wrote:
<br>
<blockquote type="cite">Hi all, Hi Juan,
<br>
<br>
I was bit annoyed by the impossibility to debug scripts
and packages
<br>
run or installed from the command line.
<br>
Therefore I added an option, ``-e <argument>``,
that lets you
<br>
set the exception class to handle before executing a
script.
<br>
<br>
With the attached change set, you can now write:
<br>
<br>
squeak Cuis.image -e nil -s myScript.st
<br>
<br>
If ``myScript.st`` contains an error, a Debugger
<br>
will pop up.
<br>
<br>
<br>
HTH and Best Regards,
<br>
<br>
Gerald
<br>
<br>
</blockquote>
<br>
</blockquote>
<br>
</blockquote>
<br>
<br>
</blockquote>
<br>
<br>
</blockquote>
<br>
<br>
</blockquote>
<br>
</body>
</html>