Annotation of gforth/kernel/args.fs, revision 1.16
1.1 anton 1: \ argument expansion
2:
1.16 ! anton 3: \ Copyright (C) 1995,1996,1997,1998,2000,2003 Free Software Foundation, Inc.
1.1 anton 4:
5: \ This file is part of Gforth.
6:
7: \ Gforth is free software; you can redistribute it and/or
8: \ modify it under the terms of the GNU General Public License
9: \ as published by the Free Software Foundation; either version 2
10: \ of the License, or (at your option) any later version.
11:
12: \ This program is distributed in the hope that it will be useful,
13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: \ GNU General Public License for more details.
16:
17: \ You should have received a copy of the GNU General Public License
18: \ along with this program; if not, write to the Free Software
1.9 anton 19: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
1.1 anton 20:
21: : cstring>sstring ( cstring -- addr n ) \ gforth cstring-to-sstring
22: -1 0 scan 0 swap 1+ /string ;
23: : arg ( n -- addr count ) \ gforth
1.6 crook 24: \g Return the string for the @i{n}th command-line argument.
1.1 anton 25: cells argv @ + @ cstring>sstring ;
26: : #! ( -- ) \ gforth hash-bang
1.5 crook 27: \g An alias for @code{\}
1.1 anton 28: postpone \ ; immediate
29:
30: Create pathstring 2 cells allot \ string
31: Create pathdirs 2 cells allot \ dir string array, pointer and count
1.6 crook 32:
1.1 anton 33: Variable argv ( -- addr ) \ gforth
1.6 crook 34: \g @code{Variable} -- a pointer to a vector of pointers to the command-line
1.1 anton 35: \g arguments (including the command-name). Each argument is
36: \g represented as a C-style string.
1.6 crook 37:
1.1 anton 38: Variable argc ( -- addr ) \ gforth
1.6 crook 39: \g @code{Variable} -- the number of command-line arguments (including the command name).
1.1 anton 40:
41: 0 Value script? ( -- flag )
42:
43: : do-option ( addr1 len1 addr2 len2 -- n )
44: 2swap
1.12 anton 45: 2dup s" -e" str= >r
46: 2dup s" --evaluate" str= r> or
1.10 pazsan 47: IF 2drop ( dup >r ) evaluate
48: ( r> >tib +! ) 2 EXIT THEN
1.12 anton 49: 2dup s" -h" str= >r
50: 2dup s" --help" str= r> or
1.3 pazsan 51: IF ." Image Options:" cr
52: ." FILE load FILE (with `require')" cr
53: ." -e STRING, --evaluate STRING interpret STRING (with `EVALUATE')" cr
1.13 anton 54: ." Report bugs on <https://savannah.gnu.org/bugs/?func=addbug&group=gforth>" cr
1.3 pazsan 55: bye
56: THEN
1.1 anton 57: ." Unknown option: " type cr 2drop 1 ;
58:
1.2 jwilke 59: : (process-args) ( -- )
1.1 anton 60: true to script?
1.10 pazsan 61: \ >tib @ >r #tib @ >r >in @ >r
1.1 anton 62: argc @ 1
63: ?DO
64: I arg over c@ [char] - <>
65: IF
1.10 pazsan 66: \ 2dup dup #tib ! >in ! >tib !
1.1 anton 67: required 1
68: ELSE
69: I 1+ argc @ = IF s" " ELSE I 1+ arg THEN
70: do-option
71: THEN
72: +LOOP
1.10 pazsan 73: \ r> >in ! r> #tib ! r> >tib !
1.1 anton 74: false to script?
75: ;
76:
1.11 pazsan 77: : os-boot ( path n **argv argc -- )
78: stdout TO outfile-id
79: stdin TO infile-id
80: argc ! argv ! pathstring 2! ;
81:
1.2 jwilke 82: ' (process-args) IS process-args
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>