<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>Self cannot run on Mac alone, but needs every platform including Sun. To coin a phrase.</div><div><br></div><div>Anyway did simplest fix I could think of and put in getoptfix branch:</div><div><br></div><div><a href="https://github.com/russellallen/self/commit/e9892acfdfc319648bf9e73d484b3bf33d9ed2c5">https://github.com/russellallen/self/commit/e9892acfdfc319648bf9e73d484b3bf33d9ed2c5</a></div><div><br></div><div>This works for me. If there are no suggested improvements, I'll merge into the mainline.</div><div><br></div><div>Russell</div><br><div><div>On 2 Feb 2014, at 1:49 pm, David Ungar <<a href="mailto:ungar@me.com">ungar@me.com</a>> wrote:</div><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); position: static; z-index: auto;"><div id="ygrp-mlmsg" style="font-size: 13px; font-family: Arial, helvetica, clean, sans-serif; position: relative;"><div id="ygrp-msg" style="line-height: 1.22em; z-index: 1;"><div id="ygrp-text" style="line-height: 1.22em; font-family: Georgia;"><div style="line-height: 1.22em; margin: 0px 0px 1em;"><span style="line-height: 1.22em;">Get a Mac? :)</span></div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;">- David<div style="line-height: 1.22em;">Sent from my iPhone, tap tap</div></div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;">On Feb 1, 2014, at 5:26 PM, Russell Allen <<a href="mailto:mail@russell-allen.com" style="line-height: 1.22em;">mail@russell-allen.com</a>> wrote:<br style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><blockquote type="cite" style="margin: 0px 0px 0px 4px; line-height: 1.22em;"><div style="line-height: 1.22em;"><span style="line-height: 1.22em;"> </span><div id="ygrp-text" style="line-height: 1.22em; font-family: Georgia;"><p style="line-height: 1.22em; margin: 0px 0px 1em;">OK, to partially answer my own question:</p><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;">GNU getopt, which is used on Linux, changes the order of argv as a side effect: </div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;"><a href="http://man7.org/linux/man-pages/man3/getopt.3.html" style="line-height: 1.22em;">http://man7.org/linux/man-pages/man3/getopt.3.html</a></div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;">"By default, getopt() permutes the contents of argv as it scans, so that eventually all the nonoptions are at the end."</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;">OS X uses a BSD getopt which is sane.</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;">As Wikipedia says (<span class="Apple-converted-space"> </span><a href="https://en.wikipedia.org/wiki/Getopt" style="line-height: 1.22em;">https://en.wikipedia.org/wiki/Getopt</a> ) :</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;">"getopt is a system dependent function. The implementation of getopt in GNU C Library does permute the contents of the argument vector as it scans, so that eventually all the non-option arguments are at the end. On the contrary, the implementation of getopt in BSD C Library does not permute the argument vector and returns -1 if it encounters a non-option argument."</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;">The Self VM uses getopt to parse the VM options, then passes the arguments onto the Self world via argv. So on OSX it is normal argv, on Linux it is argv as altered by getopt:</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;">In shell.cpp:</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;"><div style="line-height: 1.22em;">  OS::opterr= 0; // disable printed warning about unrecognized options</div><div style="line-height: 1.22em;">  while(opt_i= OS::optind,</div><div style="line-height: 1.22em;">        (c = OS::getopt(argc, (char* const*)argv, "Ff:hl:prtcs:woa")) != (char)-1) {</div><div style="line-height: 1.22em;">    if (strlen(argv[opt_i]) != 2) continue; // ignore multi-character options</div><div style="line-height: 1.22em;">    switch(c) {</div><div style="line-height: 1.22em;">    case 'F':</div></div><div style="line-height: 1.22em;"><span class="Apple-tab-span" style="line-height: 1.22em; white-space: pre;">      </span>etc ...</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;"><div style="line-height: 1.22em;">  // save remaining args for Self-level access</div><div style="line-height: 1.22em;">  prog_argc= argc;</div><div style="line-height: 1.22em;">  prog_argv= argv;</div></div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;">So my next question is, what is the best way to fix this so that _CommandLine returns the arguments in proper order on Linux?</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;">Russell</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"><div style="line-height: 1.22em;"><div style="line-height: 1.22em;">On 1 Feb 2014, at 9:55 pm, Russell Allen <<a href="mailto:mail@russell-allen.com" style="line-height: 1.22em;">mail@russell-allen.com</a>> wrote:</div><br class="Apple-interchange-newline" style="line-height: 1.22em;"><blockquote type="cite" style="margin: 0px 0px 0px 4px; line-height: 1.22em;"><div style="line-height: 1.22em; font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal;"><div id="ygrp-mlmsg" style="font-size: 13px; font-family: Arial, helvetica, clean, sans-serif; line-height: 1.22em;"><div id="ygrp-msg" style="line-height: 1.22em;"><div id="ygrp-text" style="line-height: 1.22em; font-family: Georgia;"><p style="line-height: 1.22em; margin: 0px 0px 1em;">Just in case anyone has any ideas, I get this in OS X as expected:</p><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;"><div style="line-height: 1.22em;">Macintosh-2:mio russellallen$<span class="Apple-converted-space" style="line-height: 1.22em;"> </span><font color="#008f00" style="line-height: 1.22em;">Self -port 4000 -headless</font></div><div style="line-height: 1.22em;">Self Virtual Machine Version 4.1.13, Thu 09 Jan 14 15:06:29 Mac OS X i386 (4.4-272-g885323f-dirty)</div><div style="line-height: 1.22em;">Copyright 1989-2003: The Self Group (type _Credits for credits)</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;">for I386:  LogVMMessages = true</div><div style="line-height: 1.22em;">for I386:  PrintScriptName  = true</div><div style="line-height: 1.22em;">for I386:  Inline = true</div><div style="line-height: 1.22em;">for I386:  SICDeferUncommonBranches = false (not implemented)</div><div style="line-height: 1.22em;">for I386:  SICReplaceOnStack = false (not implemented)</div><div style="line-height: 1.22em;">for I386:  SaveOutgoingArgumentsOfPatchedFrames = true</div><div style="line-height: 1.22em;">VM# _CommandLine</div><div style="line-height: 1.22em;"><font color="#008f00" style="line-height: 1.22em;"><0>: ( | parent* = <1>. | object array: {'/Applications/Self Control.app/Contents/Resources/Self.app/Contents/MacOS/Self', '-port', '4000', '-headless'} )</font></div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div></div><div style="line-height: 1.22em;">but I get this in Linux (Fedora 19):</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;"><div style="line-height: 1.22em;">[self@messaging ~]$<font color="#008f00" style="line-height: 1.22em;"><span class="Apple-converted-space" style="line-height: 1.22em;"> </span>./selfvm -port 4000 -headless</font></div><div style="line-height: 1.22em;">Self Virtual Machine Version 4.1.13, Sat 01 Feb 14 08:00:32 Linux i386 (4.5.0-7-gb833000)</div><div style="line-height: 1.22em;">Copyright 1989-2003: The Self Group (type _Credits for credits)</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;">for I386:  LogVMMessages = true</div><div style="line-height: 1.22em;">for I386:  PrintScriptName  = true</div><div style="line-height: 1.22em;">for I386:  Inline = true</div><div style="line-height: 1.22em;">for I386:  SICDeferUncommonBranches = false (not implemented)</div><div style="line-height: 1.22em;">for I386:  SICReplaceOnStack = false (not implemented)</div><div style="line-height: 1.22em;">for I386:  SaveOutgoingArgumentsOfPatchedFrames = true</div><div style="line-height: 1.22em;">VM# _CommandLine</div><div style="line-height: 1.22em;"><font color="#008f00" style="line-height: 1.22em;"><0>: ( | parent* = <1>. | object array: {'./selfvm', '-port', '-headless', '4000'} )</font></div></div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;">Why on earth would the order of the command line arguments vary between platforms? Or more precisely, why is Linux reordering my arguments?</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;">Russell</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;"><br class="webkit-block-placeholder" style="line-height: 1.22em;"></div></div><div style="line-height: 1.22em; color: rgb(255, 255, 255); height: 0px;"></div></div></div></div></blockquote></div><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em; margin: 0px 0px 1em;"><br class="webkit-block-placeholder"></div></div></div></blockquote><div style="line-height: 1.22em; margin: 0px 0px 1em;"><br class="webkit-block-placeholder"></div></div><div style="line-height: 1.22em; color: rgb(255, 255, 255); height: 0px;"></div></div></blockquote></div><br></body></html>