2004-07-16 02:26:21 -04:00
|
|
|
! Copyright (C) 2003, 2004 Slava Pestov.
|
2005-01-29 14:18:28 -05:00
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2004-12-17 21:46:19 -05:00
|
|
|
IN: command-line
|
2005-04-19 20:28:01 -04:00
|
|
|
USING: files kernel kernel-internals lists namespaces parser
|
|
|
|
sequences strings ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-07-22 19:48:50 -04:00
|
|
|
! This file is run as the last stage of boot.factor; it relies
|
|
|
|
! on all other words already being defined.
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-07-30 16:22:20 -04:00
|
|
|
: ?run-file ( file -- )
|
|
|
|
dup exists? [ (run-file) ] [ drop ] ifte ;
|
|
|
|
|
|
|
|
: run-user-init ( -- )
|
|
|
|
#! Run user init file if it exists
|
|
|
|
"user-init" get [
|
2004-12-15 16:57:29 -05:00
|
|
|
[ "~" get , "/" , ".factor-" , "rc" , ] make-string
|
2004-07-30 16:22:20 -04:00
|
|
|
?run-file
|
|
|
|
] when ;
|
|
|
|
|
2004-12-24 02:52:02 -05:00
|
|
|
: set-path ( value list -- )
|
|
|
|
unswons over [ nest [ set-path ] bind ] [ nip set ] ifte ;
|
|
|
|
|
|
|
|
: cli-var-param ( name value -- ) swap ":" split set-path ;
|
|
|
|
|
2005-04-16 00:23:27 -04:00
|
|
|
: cli-bool-param ( name -- ) "no-" ?string-head not swap set ;
|
2004-10-09 21:43:14 -04:00
|
|
|
|
2004-07-30 16:22:20 -04:00
|
|
|
: cli-param ( param -- )
|
|
|
|
#! Handle a command-line argument starting with '-' by
|
|
|
|
#! setting that variable to t, or if the argument is
|
|
|
|
#! prefixed with 'no-', setting the variable to f.
|
2004-10-09 21:43:14 -04:00
|
|
|
#!
|
|
|
|
#! Arguments containing = are handled differently; they
|
|
|
|
#! set the object path.
|
2004-12-24 02:52:02 -05:00
|
|
|
"=" split1 [ cli-var-param ] [ cli-bool-param ] ifte* ;
|
2004-07-30 16:22:20 -04:00
|
|
|
|
|
|
|
: cli-arg ( argument -- argument )
|
|
|
|
#! Handle a command-line argument. If the argument was
|
|
|
|
#! consumed, returns f. Otherwise returns the argument.
|
2005-03-27 01:52:13 -05:00
|
|
|
#! Parameters that start with + are runtime parameters.
|
2005-04-19 20:28:01 -04:00
|
|
|
dup empty? [
|
2005-03-27 01:52:13 -05:00
|
|
|
"-" ?string-head [ cli-param f ] when
|
|
|
|
dup [ "+" ?string-head [ drop f ] when ] when
|
|
|
|
] unless ;
|
2004-07-30 16:22:20 -04:00
|
|
|
|
|
|
|
: parse-switches ( args -- args )
|
2004-08-22 19:06:51 -04:00
|
|
|
[ cli-arg ] map ;
|
2004-07-30 16:22:20 -04:00
|
|
|
|
|
|
|
: run-files ( args -- )
|
|
|
|
[ [ run-file ] when* ] each ;
|
|
|
|
|
2004-12-25 02:55:03 -05:00
|
|
|
: cli-args ( -- args ) 10 getenv ;
|
|
|
|
|
2005-03-07 22:11:36 -05:00
|
|
|
: default-cli-args
|
|
|
|
#! Some flags are *on* by default, unless user specifies
|
|
|
|
#! -no-<flag> CLI switch
|
|
|
|
"user-init" on
|
|
|
|
"compile" on
|
|
|
|
os "win32" = "ui" "ansi" ? "shell" set ;
|
|
|
|
|
2004-12-25 02:55:03 -05:00
|
|
|
: parse-command-line ( -- )
|
2004-07-30 16:22:20 -04:00
|
|
|
#! Parse command line arguments.
|
2004-12-25 02:55:03 -05:00
|
|
|
#! The first CLI arg is the image name.
|
|
|
|
cli-args unswons "image" set parse-switches run-files ;
|