Diff for /gforth/kernel/args.fs between versions 1.18 and 1.19

version 1.18, 2004/01/18 22:00:21 version 1.19, 2004/01/19 07:41:04
Line 23 Line 23
   
 : arg ( u -- addr count ) \ gforth  : arg ( u -- addr count ) \ gforth
 \g Return the string for the @i{u}th command-line argument; returns  \g Return the string for the @i{u}th command-line argument; returns
 \g @code{0 0} if the access is beyond the last argument.  \g @code{0 0} if the access is beyond the last argument.  @code{0 arg}
   \g is the program name with which you started Gforth.  The next
   \g unprocessed argument is always @code{1 arg}, the one after that is
   \g @code{2 arg} etc.  All arguments already processed by the system
   \g are deleted.  After you have processed an argument, you can delete
   \g it with @code{shift-args}.
     dup argc @ u< if      dup argc @ u< if
         cells argv @ + @ cstring>sstring          cells argv @ + @ cstring>sstring
     else      else
Line 38  Create pathstring 2 cells allot \ string Line 43  Create pathstring 2 cells allot \ string
 Create pathdirs   2 cells allot \ dir string array, pointer and count  Create pathdirs   2 cells allot \ dir string array, pointer and count
   
 Variable argv ( -- addr ) \ gforth  Variable argv ( -- addr ) \ gforth
 \g @code{Variable} -- a pointer to a vector of pointers to the command-line  \g @code{Variable} -- a pointer to a vector of pointers to the
 \g arguments (including the command-name). Each argument is  \g command-line arguments (including the command-name). Each argument
 \g represented as a C-style string.  \g is represented as a C-style zero-terminated string.  Changed by
   \g @code{next-arg} and @code{shift-args}.
           
 Variable argc ( -- addr ) \ gforth  Variable argc ( -- addr ) \ gforth
 \g @code{Variable} -- the number of command-line arguments (including the command name).  \g @code{Variable} -- the number of command-line arguments (including
   \g the command name).  Changed by @code{next-arg} and @code{shift-args}.
   
           
 0 Value script? ( -- flag )  0 Value script? ( -- flag )
           
Line 58  Variable argc ( -- addr ) \ gforth Line 66  Variable argc ( -- addr ) \ gforth
         argv @ !          argv @ !
     endif ;      endif ;
   
   : next-arg ( -- addr u ) \ gforth
   \g get the next argument from the OS command line, consuming it; if
   \g there is no argument left, return @code{0 0}.
       1 arg shift-args ;
   
 : process-option ( addr u -- )  : process-option ( addr u -- )
     \ process option, possibly consuming further arguments      \ process option, possibly consuming further arguments
     2dup s" -e"         str= >r      2dup s" -e"         str= >r
     2dup s" --evaluate" str= r> or if      2dup s" --evaluate" str= r> or if
         2drop 1 arg shift-args evaluate exit endif          2drop next-arg evaluate exit endif
     2dup s" -h"         str= >r      2dup s" -h"         str= >r
     2dup s" --help"     str= r> or if      2dup s" --help"     str= r> or if
         ." Image Options:" cr          ." Image Options:" cr
Line 77  Variable argc ( -- addr ) \ gforth Line 90  Variable argc ( -- addr ) \ gforth
     true to script?      true to script?
     BEGIN      BEGIN
         argc @ 1 > WHILE          argc @ 1 > WHILE
             1 arg shift-args over c@ [char] - <> IF              next-arg over c@ [char] - <> IF
                 required                  required
             else              else
                 process-option                  process-option

Removed from v.1.18  
changed lines
  Added in v.1.19


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>