<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://pickwiki.org/index.php?action=history&amp;feed=atom&amp;title=PARSE.CMDLINE</id>
	<title>PARSE.CMDLINE - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://pickwiki.org/index.php?action=history&amp;feed=atom&amp;title=PARSE.CMDLINE"/>
	<link rel="alternate" type="text/html" href="https://pickwiki.org/index.php?title=PARSE.CMDLINE&amp;action=history"/>
	<updated>2026-04-28T23:43:01Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://pickwiki.org/index.php?title=PARSE.CMDLINE&amp;diff=2124&amp;oldid=prev</id>
		<title>Conversion script: link fix</title>
		<link rel="alternate" type="text/html" href="https://pickwiki.org/index.php?title=PARSE.CMDLINE&amp;diff=2124&amp;oldid=prev"/>
		<updated>2015-02-26T23:48:55Z</updated>

		<summary type="html">&lt;p&gt;link fix&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;HomePage&amp;gt;&amp;gt;SourceCode&amp;gt;&amp;gt;BasicSource&amp;gt;&amp;gt;SVN&amp;gt;&amp;gt;PARSE.CMDLINE&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;PRE&amp;gt;&lt;br /&gt;
             subroutine PARSE.CMDLINE(SENTENCE, MAT CMDLINE, OPTIONS) &lt;br /&gt;
* =======================================================================================&lt;br /&gt;
* @LIB: Parse the [[UniVerse]] Command line using a standardized format&lt;br /&gt;
* =======================================================================================&lt;br /&gt;
* 24.Mar.2009 james: Add &amp;#039;\&amp;#039; as a valid Quote character for command line options.&lt;br /&gt;
* 30.Oct.2007 jim: NOPARAM option to allow no-parameter flags before Arguments.&lt;br /&gt;
*                  DEBUG.FLAG now uses new LOCATE method: DEBUG CMDLINE to debug.&lt;br /&gt;
* 04.Sep.2007 jim: Handle CMD.VERB = &amp;#039;RUN&amp;#039; so callers don&amp;#039;t have to.&lt;br /&gt;
* 02.Jul.2007 jim: SINGLEPARAM option to allow Flags before Arguments, &amp;#039;Unix-Style&amp;#039;; i.e.:&lt;br /&gt;
*                  -&amp;lt;flag&amp;gt; &amp;lt;param&amp;gt; ARG ARG ...&lt;br /&gt;
*                  (was for DISPLAY.DIFFS but now not used anymore ?)&lt;br /&gt;
* 30-Aug-2005 jra: Add OPTIONS.&lt;br /&gt;
* 14-Nov-2003 New syntax for &amp;#039;COPY.TO.REV&amp;#039;; to be used for all future commands.&lt;br /&gt;
* =======================================================================================&lt;br /&gt;
*&lt;br /&gt;
*   SENTENCE : Pass in @SENTENCE or really anything you want to parse.&lt;br /&gt;
*&lt;br /&gt;
*   CMDLINE  : Pass this array (so we don&amp;#039;t have to put it in Global Common)&lt;br /&gt;
*&lt;br /&gt;
*   OPTIONS  : &amp;#039;LONGFLAGS&amp;#039;   : -TEST will be treated as one flag instead of &amp;#039;-T EST&amp;#039;.&lt;br /&gt;
*              &amp;#039;SINGLEPARAM&amp;#039; : -x will use only ONE following parameter.&lt;br /&gt;
*              &amp;#039;NOPARAM&amp;#039;     : -x will be the flag with NO following parameter.&lt;br /&gt;
*&lt;br /&gt;
* =======================================================================================&lt;br /&gt;
*&lt;br /&gt;
*  Note that this does a COMPLETE CHARACTER BY CHARACTER PARSE:&lt;br /&gt;
*  this allows it to handle strings in quotes, strange file names, etc.&lt;br /&gt;
*&lt;br /&gt;
* Usage:&lt;br /&gt;
*&lt;br /&gt;
* %&amp;lt; -----------------------&lt;br /&gt;
*   $include RMS.BP EQU.CMDLINE &lt;br /&gt;
*   call PARSE.CMDLINE(@SENTENCE, MAT CMDLINE, Options) &lt;br /&gt;
*   if CMD.HELP then&lt;br /&gt;
*     print &amp;quot;&amp;lt;your help here&amp;gt;...&lt;br /&gt;
*     stop&lt;br /&gt;
*   end&lt;br /&gt;
*   &amp;lt;etc...&amp;gt;&lt;br /&gt;
* %&amp;lt; -----------------------&lt;br /&gt;
*&lt;br /&gt;
*    DSI &amp;#039;Standardized&amp;#039; Syntax:&lt;br /&gt;
*&lt;br /&gt;
*  &amp;lt;Verb&amp;gt; &amp;lt;Arg1&amp;gt; &amp;lt;Arg2&amp;gt; &amp;lt;-Flag1&amp;gt; &amp;lt;Param1&amp;gt; &amp;lt;-Flag2Param2&amp;gt; ( &amp;lt;Option1&amp;gt; &amp;lt;Option2&amp;gt;&lt;br /&gt;
*&lt;br /&gt;
* Examples:&lt;br /&gt;
*    COPY.TO.REV FILE ITEM -T &amp;quot;TCL COMMAND&amp;quot; -F A (O P&lt;br /&gt;
* &lt;br /&gt;
* Guidelines:&lt;br /&gt;
*     - Use ARGS for &amp;#039;fixed position&amp;#039; parameters which are always required&lt;br /&gt;
*       ALL ARGS are to be used BEFORE OPTIONS AND FLAGS ! (unlike Unix...)&lt;br /&gt;
*     - Options and Flags are single characters unless &amp;#039;LONGFLAGS&amp;#039; is used&lt;br /&gt;
*     - Use &amp;#039;(&amp;#039; OPTIONS for options with no parameters (but &amp;#039;-&amp;#039; is always recommended)&lt;br /&gt;
*     - Options do NOT need spaces or subsequent &amp;#039;(&amp;#039;s, but they won&amp;#039;t hurt.&lt;br /&gt;
*     - Use &amp;#039;-&amp;#039; FLAGS for things with another value; i.e. the &amp;#039;parameter&amp;#039;&lt;br /&gt;
*     - Flags do NOT need spaces from their params, but they won&amp;#039;t hurt.&lt;br /&gt;
*     - Programs should check the &amp;#039;CMD.HELP&amp;#039; flag after calling this and&lt;br /&gt;
*       immediately display a help msg and exit if it&amp;#039;s set.&lt;br /&gt;
*&lt;br /&gt;
* See &amp;#039;RMS.BP COPY.TO.REV&amp;#039; for an example.&lt;br /&gt;
*&lt;br /&gt;
* Use: &amp;#039;CMDLINE.TEST&amp;#039; to check your parameters and as an aid to writing your code.&lt;br /&gt;
*&lt;br /&gt;
* Note that since this program does a &amp;#039;pure parse&amp;#039; of the command line, it only&lt;br /&gt;
* acknowledges &amp;#039;-&amp;#039;, &amp;#039;(&amp;#039;, and quotes when they START a string; therefore they&lt;br /&gt;
* can be embedded in Item-ID&amp;#039;s without conflicting with the option parsing.&lt;br /&gt;
*&lt;br /&gt;
* =======================================================================================&lt;br /&gt;
&lt;br /&gt;
  $include RMS.BP RMS.COMMON  ;*  DEBUG.FLAG to check for &amp;#039;c&amp;#039; flag.&lt;br /&gt;
  &lt;br /&gt;
  * We need this to get at the EQU&amp;#039;ed names.&lt;br /&gt;
  * (and although we don&amp;#039;t need the &amp;#039;dim&amp;#039;; it won&amp;#039;t hurt):&lt;br /&gt;
  $include RMS.BP EQU.CMDLINE &lt;br /&gt;
&lt;br /&gt;
  mat CMDLINE = &amp;#039;&amp;#039;  ;*  Clear out old COMMON&amp;#039;s&lt;br /&gt;
&lt;br /&gt;
  PROCLINE = SENTENCE  ;*  Now passed in !&lt;br /&gt;
  &lt;br /&gt;
  convert @VM to @FM in OPTIONS  ;*  Just in case caller used &amp;lt;1,-1&amp;gt; instead of &amp;lt;-1&amp;gt;&lt;br /&gt;
  locate(&amp;#039;LONGFLAGS&amp;#039;,   OPTIONS; LOC) then LONG.FLAGS  = @TRUE else LONG.FLAGS  = @FALSE&lt;br /&gt;
  locate(&amp;#039;NOPARAM&amp;#039;,     OPTIONS; LOC) then NOPARAM     = @TRUE else NOPARAM     = @FALSE&lt;br /&gt;
  locate(&amp;#039;SINGLEPARAM&amp;#039;, OPTIONS; LOC) then SINGLEPARAM = @TRUE else SINGLEPARAM = @FALSE&lt;br /&gt;
  CMD.HELP = @FALSE   ;*  Flag for &amp;#039;-H&amp;#039;&lt;br /&gt;
  OPTIONS  = @FALSE   ;*  After a &amp;#039;(&amp;#039; ALL are options&lt;br /&gt;
  FLAGS    = @FALSE   ;*  After a &amp;#039;-&amp;#039; are parameters or another Flag&lt;br /&gt;
  POS      = 1        ;*  Position in PROCLINE&lt;br /&gt;
  FLAG.PTR = 0        ;*  Which FLAG we are on: keeps incrementing.&lt;br /&gt;
  loop&lt;br /&gt;
    gosub [[GetNextVal]]&lt;br /&gt;
   while P # &amp;#039;&amp;#039; DO&lt;br /&gt;
*    locate( &amp;quot;CMDLINE&amp;quot;, DEBUG.FLAG; dummy) then&lt;br /&gt;
*      print &amp;quot;P:&amp;quot;:P: ; input j ; if j = &amp;#039;D&amp;#039; then debug&lt;br /&gt;
*    end&lt;br /&gt;
    begin case&lt;br /&gt;
      case CMD.VERB = &amp;#039;&amp;#039; ; CMD.VERB = P&lt;br /&gt;
      case P[1,1] = &amp;#039;-&amp;#039;  ; gosub [[StartNewFlag]]&lt;br /&gt;
      case P[1,1] = &amp;#039;(&amp;#039;  ; gosub [[StartOptions]]&lt;br /&gt;
      case OPTIONS       ; gosub [[AddOptions]]&lt;br /&gt;
      case FLAGS&lt;br /&gt;
        if P[1,1] = &amp;#039;-&amp;#039; then&lt;br /&gt;
          gosub [[StartNewFlag]]&lt;br /&gt;
        end else&lt;br /&gt;
          FLAG.PARAM = P ; gosub [[AddFlagParameter]]&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
      case 1             ; CMD.ARG.S&amp;lt;1,-1&amp;gt; = P&lt;br /&gt;
    end case&lt;br /&gt;
  repeat&lt;br /&gt;
&lt;br /&gt;
  *  Handle &amp;#039;RUN &amp;lt;file.BP&amp;gt; &amp;lt;program&amp;gt;&amp;#039; here so callers don&amp;#039;t have to:&lt;br /&gt;
  &lt;br /&gt;
  if CMD.VERB = &amp;#039;RUN&amp;#039; and CMD.ARG.S&amp;lt;1, 1&amp;gt;&amp;#039;R#3&amp;#039; = &amp;#039;.BP&amp;#039; then&lt;br /&gt;
    CMD.VERB = CMD.ARG.S&amp;lt;1, 2&amp;gt;&lt;br /&gt;
    CMD.ARG.S = delete( CMD.ARG.S, 1, 1 )  ;*  Delete the &amp;#039;.BP&amp;#039;&lt;br /&gt;
    CMD.ARG.S = delete( CMD.ARG.S, 1, 1 )  ;*  Delete the VERB (now in CMD.VERB)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  *  Finally set these convenience variables:&lt;br /&gt;
  CMD.NUM.ARGS    = dcount(CMD.ARG.S, @VM)&lt;br /&gt;
  CMD.NUM.OPTIONS = dcount(CMD.OPTION.S, @VM)&lt;br /&gt;
  CMD.NUM.FLAGS   = dcount(CMD.FLAG.S, @VM)&lt;br /&gt;
return&lt;br /&gt;
&lt;br /&gt;
[[StartOptions]]:&lt;br /&gt;
  OPTIONS = 1&lt;br /&gt;
  P = P[2,9999]&lt;br /&gt;
  gosub [[AddOptions]]&lt;br /&gt;
return&lt;br /&gt;
&lt;br /&gt;
[[AddOptions]]:&lt;br /&gt;
  if P = &amp;#039;H&amp;#039; or P = &amp;#039;?&amp;#039; then&lt;br /&gt;
    CMD.HELP = 1&lt;br /&gt;
  end&lt;br /&gt;
  CMD.OPTION.S&amp;lt;1,-1&amp;gt; = P&lt;br /&gt;
return&lt;br /&gt;
&lt;br /&gt;
[[StartNewFlag]]:&lt;br /&gt;
  OPTIONS = @FALSE  ;*  Switch modes&lt;br /&gt;
  FLAGS   = @TRUE&lt;br /&gt;
  if LONG.FLAGS then&lt;br /&gt;
    FLAG = P&lt;br /&gt;
    EXTRA = &amp;#039;&amp;#039;&lt;br /&gt;
  end else&lt;br /&gt;
    FLAG  = P[2,1]&lt;br /&gt;
    EXTRA = P[3,9999]&lt;br /&gt;
  end&lt;br /&gt;
  if FLAG[1,1] = &amp;#039;H&amp;#039; or FLAG[1,1] = &amp;#039;?&amp;#039; then&lt;br /&gt;
    CMD.HELP = @TRUE&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  *  Now re-use the same position if the flag is the same:&lt;br /&gt;
  locate FLAG in CMD.FLAG.S&amp;lt;1&amp;gt; setting OLD.PTR then&lt;br /&gt;
    FLAG.PTR = OLD.PTR&lt;br /&gt;
  end else&lt;br /&gt;
    FLAG.PTR += 1&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  CMD.FLAG.S&amp;lt;1,FLAG.PTR&amp;gt; = FLAG&lt;br /&gt;
  if EXTRA # &amp;#039;&amp;#039; then&lt;br /&gt;
    FLAG.PARAM = EXTRA ; gosub [[AddFlagParameter]]&lt;br /&gt;
  end&lt;br /&gt;
  if NOPARAM then FLAGS = @FALSE&lt;br /&gt;
return&lt;br /&gt;
&lt;br /&gt;
[[AddFlagParameter]]:&lt;br /&gt;
  CMD.PARAM.S&amp;lt;1,FLAG.PTR,-1&amp;gt; = FLAG.PARAM&lt;br /&gt;
  if SINGLEPARAM then  ;*  We&amp;#039;ve got one: so NO MORE for this flag:&lt;br /&gt;
    FLAGS = @FALSE&lt;br /&gt;
  end&lt;br /&gt;
return&lt;br /&gt;
&lt;br /&gt;
*  Everything within Quotes (single or double ?) is a single value too:&lt;br /&gt;
*  old: VAL = field(PROCLINE,&amp;#039; &amp;#039;,I)&lt;br /&gt;
&lt;br /&gt;
[[GetNextVal]]:&lt;br /&gt;
  P = &amp;#039;&amp;#039;  ;*  This gets returned&lt;br /&gt;
  loop &lt;br /&gt;
    C = PROCLINE[POS, 1]&lt;br /&gt;
   while POS &amp;lt;= len(PROCLINE) and C # &amp;quot; &amp;quot; do&lt;br /&gt;
    if C = &amp;#039;&amp;quot;&amp;#039; or C = &amp;quot;&amp;#039;&amp;quot;  or C = &amp;quot;\&amp;quot; then&lt;br /&gt;
      gosub [[GetQuotedVal]]&lt;br /&gt;
    end else&lt;br /&gt;
      P := C&lt;br /&gt;
    end&lt;br /&gt;
    POS += 1&lt;br /&gt;
  repeat&lt;br /&gt;
  POS += 1  ;*  Past the space&lt;br /&gt;
  * Now get past MORE spaces for over-spaces lines (like a &amp;#039;trim&amp;#039;):&lt;br /&gt;
  loop&lt;br /&gt;
  while PROCLINE[POS, 1] = &amp;#039; &amp;#039; do&lt;br /&gt;
    POS += 1&lt;br /&gt;
  repeat&lt;br /&gt;
return&lt;br /&gt;
&lt;br /&gt;
[[GetQuotedVal]]:&lt;br /&gt;
  Q = C    ;*  Look for matching &amp;#039;Q&amp;#039;uote character&lt;br /&gt;
  POS += 1 ;*  Past the quote&lt;br /&gt;
  loop&lt;br /&gt;
    CHAR = PROCLINE[POS, 1]&lt;br /&gt;
   while POS &amp;lt;= len(PROCLINE) and CHAR # Q do&lt;br /&gt;
    P := CHAR&lt;br /&gt;
    POS += 1 ;*  Past the quote&lt;br /&gt;
  repeat&lt;br /&gt;
return&lt;br /&gt;
&amp;lt;/PRE&amp;gt;&lt;/div&gt;</summary>
		<author><name>Conversion script</name></author>
	</entry>
</feed>