<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Get a Mac? :)<br><br>- David<div>Sent from my iPhone, tap tap</div></div><div><br>On Feb 1, 2014, at 5:26 PM, Russell Allen <<a href="mailto:mail@russell-allen.com">mail@russell-allen.com</a>> wrote:<br><br></div><blockquote type="cite"><div>














<span style="display:none"> </span>



    <div id="ygrp-text">
      
      
      <p>OK, to partially answer my own question:</p><div><br></div><div>GNU getopt, which is used on Linux, changes the order of argv as a side effect: </div><div><br></div><div><a href="http://man7.org/linux/man-pages/man3/getopt.3.html">http://man7.org/linux/man-pages/man3/getopt.3.html</a></div><div><br></div><div>"By default, getopt() permutes the contents of argv as it scans, so that eventually all the nonoptions are at the end."</div><div><br></div><div>OS X uses a BSD getopt which is sane.</div><div><br></div><div>As Wikipedia says ( <a href="https://en.wikipedia.org/wiki/Getopt">https://en.wikipedia.org/wiki/Getopt</a> ) :</div><div><br></div><div>"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><br></div><div>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><br></div><div>In shell.cpp:</div><div><br></div><div><div>  OS::opterr= 0; // disable printed warning about unrecognized options</div><div>  while(opt_i= OS::optind,</div><div>        (c = OS::getopt(argc, (char* const*)argv, "Ff:hl:prtcs:woa")) != (char)-1) {</div><div>    if (strlen(argv[opt_i]) != 2) continue; // ignore multi-character options</div><div>    switch(c) {</div><div>    case 'F':</div></div><div><span class="Apple-tab-span" style="white-space:pre;">   </span>etc ...</div><div><br></div><div><div>  // save remaining args for Self-level access</div><div>  prog_argc= argc;</div><div>  prog_argv=
 argv;</div></div><div><br></div><div>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><br></div><div>Russell</div><div><br><div><div>On 1 Feb 2014, at 9:55 pm, Russell Allen <<a href="mailto:mail@russell-allen.com">mail@russell-allen.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="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;"><div id="ygrp-msg"><div id="ygrp-text" style="font-family: Georgia;"><p>Just in case anyone has any ideas, I get this in OS X as expected:</p><div><br></div><div><div>Macintosh-2:mio russellallen$<span class="Apple-converted-space"> </span><font color="#008f00">Self -port
 4000 -headless</font></div><div>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>Copyright 1989-2003: The Self Group (type _Credits for credits)</div><div><br></div><div>for I386:  LogVMMessages = true</div><div>for I386:  PrintScriptName  = true</div><div>for I386:  Inline = true</div><div>for I386:  SICDeferUncommonBranches = false (not implemented)</div><div>for I386:  SICReplaceOnStack = false (not implemented)</div><div>for I386:  SaveOutgoingArgumentsOfPatchedFrames = true</div><div>VM# _CommandLine</div><div><font color="#008f00"><0>: ( | parent* = <1>. | object array: {'/Applications/Self Control.app/Contents/Resources/Self.app/Contents/MacOS/Self', '-port', '4000', '-headless'} )</font></div><div><br></div></div><div>but I get this in Linux (Fedora 19):</div><div><br></div><div><div>[self@messaging ~]$<font color="#008f00"><span class="Apple-converted-space"> </span>./selfvm -port 4000 -headless</font></div><div>Self Virtual Machine Version 4.1.13, Sat 01 Feb 14 08:00:32 Linux i386 (4.5.0-7-gb833000)</div><div>Copyright 1989-2003: The Self Group (type _Credits for credits)</div><div><br></div><div>for I386:  LogVMMessages = true</div><div>for I386:  PrintScriptName  = true</div><div>for I386:  Inline = true</div><div>for I386:  SICDeferUncommonBranches = false (not implemented)</div><div>for I386:  SICReplaceOnStack = false (not implemented)</div><div>for I386:  SaveOutgoingArgumentsOfPatchedFrames = true</div><div>VM# _CommandLine</div><div><font color="#008f00"><0>: ( | parent* = <1>. | object array: {'./selfvm', '-port', '-headless', '4000'} )</font></div></div><div><br></div><div>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><br></div><div>Russell</div><div><br></div><div><br></div><div><br class="webkit-block-placeholder"></div></div><div style="color: rgb(255, 255, 255);height: 0px;"></div></div></div></div></blockquote></div><br></div><p></p>

    </div>
     

    





<!-- end group email -->

</div></blockquote></body></html>