File:
[gforth] /
gforth /
kernel /
args.fs
Revision
1.5:
download - view:
text,
annotated -
select for diffs
Tue Mar 23 20:24:23 1999 UTC (25 years, 1 month ago) by
crook
Branches:
MAIN
CVS tags:
HEAD
Makefile.in
-- changes to make documentation build with moofglos.fs
rather than with mini-oof.fs (since the former contains glossary
entries and the latter does not)
assert.fs blocks.fs debug.fs environ.fs errors.fs extend.fs float.fs
glocals.fs moofglos.fs prim search.fs struct.fs stuff.fs vt100.fs
kernel/args.fs kernel/basics.fs kernel/comp.fs kernel/cond.fs
kernel/files.fs kernel/getdoers.fs kernel/int.fs kernel/io.fs
kernel/nio.fs kernel/paths.fs kernel/require.fs kernel/special.fs
kernel/tools.fs kernel/toolsext.fs kernel/vars.fs
-- many small changes to glossary entries.. I think most are done
now, so I hope to change far fewer files next time!
doc/gforth.ds
-- many, many small changes and a few large ones. Moved some sections
around, fixed typos and formatting errors, added new section on
exception handling, rearranged 'files' section.
1: \ argument expansion
2:
3: \ Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
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
19: \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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
24: \g Return the string for the @var{n}th command-line argument.
25: cells argv @ + @ cstring>sstring ;
26: : #! ( -- ) \ gforth hash-bang
27: \g An alias for @code{\}
28: postpone \ ; immediate
29:
30: Create pathstring 2 cells allot \ string
31: Create pathdirs 2 cells allot \ dir string array, pointer and count
32: Variable argv ( -- addr ) \ gforth
33: \g VARIABLE: A pointer to a vector of pointers to the command-line
34: \g arguments (including the command-name). Each argument is
35: \g represented as a C-style string.
36: Variable argc ( -- addr ) \ gforth
37: \g VARIABLE: The number of command-line arguments (including the command name).
38:
39: 0 Value script? ( -- flag )
40:
41: : do-option ( addr1 len1 addr2 len2 -- n )
42: 2swap
43: 2dup s" -e" compare 0= >r
44: 2dup s" --evaluate" compare 0= r> or
45: IF 2drop dup >r evaluate
46: r> >tib +! 2 EXIT THEN
47: 2dup s" -h" compare 0= >r
48: 2dup s" --help" compare 0= r> or
49: IF ." Image Options:" cr
50: ." FILE load FILE (with `require')" cr
51: ." -e STRING, --evaluate STRING interpret STRING (with `EVALUATE')" cr
52: ." Report bugs to <bug-gforth@gnu.ai.mit.edu>" cr
53: bye
54: THEN
55: ." Unknown option: " type cr 2drop 1 ;
56:
57: : (process-args) ( -- )
58: true to script?
59: >tib @ >r #tib @ >r >in @ >r
60: argc @ 1
61: ?DO
62: I arg over c@ [char] - <>
63: IF
64: 2dup dup #tib ! >in ! >tib !
65: required 1
66: ELSE
67: I 1+ argc @ = IF s" " ELSE I 1+ arg THEN
68: do-option
69: THEN
70: +LOOP
71: r> >in ! r> #tib ! r> >tib !
72: false to script?
73: ;
74:
75: ' (process-args) IS process-args
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>