From f2ddbae4acbaa186a1879be646d94455022ebac1 Mon Sep 17 00:00:00 2001 From: slava Date: Sun, 2 Jul 2006 22:51:57 +0000 Subject: [PATCH] Command line handling cleanup --- library/cli.factor | 13 ++++++++----- library/ui/cocoa/ui.factor | 6 ++++-- library/ui/tools/help.factor | 4 ++-- library/ui/tools/listener.factor | 6 +++++- vm/factor.c | 28 ++++++++++++++-------------- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/library/cli.factor b/library/cli.factor index 3597159655..9df372f4e9 100644 --- a/library/cli.factor +++ b/library/cli.factor @@ -28,10 +28,7 @@ parser sequences strings ; #! Handle a command-line argument. If the argument was #! consumed, returns f. Otherwise returns the argument. #! Parameters that start with + are runtime parameters. - dup empty? [ - "-" ?head [ cli-param f ] when - dup [ "+" ?head [ drop f ] when ] when - ] unless ; + "-" ?head [ cli-param f ] when ; : cli-args ( -- args ) 10 getenv ; @@ -48,5 +45,11 @@ parser sequences strings ; unix? macosx? not and "x11" set default-shell "shell" set ; +: ignore-cli-args? ( -- ? ) + #! On Mac OS X, files to run are given to us via a Cocoa API + #! so we ignore any command line switches which name files. + macosx? "shell" get "ui" = and ; + : parse-command-line ( -- ) - cli-args [ cli-arg ] subset [ try-run-file ] each ; + cli-args [ cli-arg ] subset + ignore-cli-args? [ drop ] [ [ try-run-file ] each ] if ; diff --git a/library/ui/cocoa/ui.factor b/library/ui/cocoa/ui.factor index 1a87155ffd..e2be523a50 100644 --- a/library/ui/cocoa/ui.factor +++ b/library/ui/cocoa/ui.factor @@ -4,11 +4,13 @@ IN: objc-classes DEFER: FactorApplicationDelegate IN: cocoa -USING: arrays gadgets gadgets-listener hashtables kernel +USING: arrays gadgets gadgets-listener hashtables kernel memory namespaces objc sequences errors freetype ; : finder-run-files ( alien -- ) - CF>string-array listener-run-files + #! We filter out the image name since that might be there on + #! first launch. + CF>string-array [ image = not ] subset listener-run-files NSApp NSApplicationDelegateReplySuccess -> replyToOpenOrPrint: ; diff --git a/library/ui/tools/help.factor b/library/ui/tools/help.factor index 8c06d7fd97..32cffe021c 100644 --- a/library/ui/tools/help.factor +++ b/library/ui/tools/help.factor @@ -7,8 +7,6 @@ namespaces sequences ; TUPLE: help-gadget history ; -: find-help-gadget [ help-gadget? ] find-parent ; - : show-help ( link help -- ) dup help-gadget-history add-history [ help-gadget-history set-model ] keep @@ -16,6 +14,8 @@ TUPLE: help-gadget history ; : go-home ( help -- ) "handbook" swap show-help ; +: find-help-gadget [ help-gadget? ] find-parent ; + : history-action find-help-gadget help-gadget-history ; : ( -- gadget ) diff --git a/library/ui/tools/listener.factor b/library/ui/tools/listener.factor index 3098321064..f5b1996c52 100644 --- a/library/ui/tools/listener.factor +++ b/library/ui/tools/listener.factor @@ -70,7 +70,11 @@ M: listener-gadget gadget-title drop "Listener" ; [ call-listener ] ; : listener-run-files ( seq -- ) - [ [ run-file ] each ] curry listener-tool call-tool ; + dup empty? [ + drop + ] [ + [ [ run-file ] each ] curry listener-tool call-tool + ] if ; M: input show ( input -- ) input-string listener-tool call-tool ; diff --git a/vm/factor.c b/vm/factor.c index 1bda95c283..d584804370 100644 --- a/vm/factor.c +++ b/vm/factor.c @@ -42,13 +42,13 @@ void usage(void) { printf("Usage: factor [ parameters ... ]\n"); printf("Runtime options -- n is a number:\n"); - printf(" +Dn Data stack size, kilobytes\n"); - printf(" +Rn Retain stack size, kilobytes\n"); - printf(" +Cn Call stack size, kilobytes\n"); - printf(" +Gn Number of generations, must be >= 2\n"); - printf(" +Yn Size of n-1 youngest generations, megabytes\n"); - printf(" +An Size of tenured and semi-spaces, megabytes\n"); - printf(" +Xn Code heap size, megabytes\n"); + printf(" -D=n Data stack size, kilobytes\n"); + printf(" -R=n Retain stack size, kilobytes\n"); + printf(" -C=n Call stack size, kilobytes\n"); + printf(" -G=n Number of generations, must be >= 2\n"); + printf(" -Y=n Size of n-1 youngest generations, megabytes\n"); + printf(" -A=n Size of tenured and semi-spaces, megabytes\n"); + printf(" -X=n Code heap size, megabytes\n"); printf("Other options are handled by the Factor library.\n"); printf("See the documentation for details.\n"); printf("Send bug reports to Slava Pestov .\n"); @@ -74,13 +74,13 @@ int main(int argc, char** argv) for(i = 1; i < argc; i++) { - if(factor_arg(argv[i],"+D%d",&ds_size)) continue; - if(factor_arg(argv[i],"+R%d",&rs_size)) continue; - if(factor_arg(argv[i],"+C%d",&cs_size)) continue; - if(factor_arg(argv[i],"+G%d",&generations)) continue; - if(factor_arg(argv[i],"+Y%d",&young_size)) continue; - if(factor_arg(argv[i],"+A%d",&aging_size)) continue; - if(factor_arg(argv[i],"+X%d",&code_size)) continue; + if(factor_arg(argv[i],"-D=%d",&ds_size)) continue; + if(factor_arg(argv[i],"-R=%d",&rs_size)) continue; + if(factor_arg(argv[i],"-C=%d",&cs_size)) continue; + if(factor_arg(argv[i],"-G=%d",&generations)) continue; + if(factor_arg(argv[i],"-Y=%d",&young_size)) continue; + if(factor_arg(argv[i],"-A=%d",&aging_size)) continue; + if(factor_arg(argv[i],"-X=%d",&code_size)) continue; if(strncmp(argv[i],"+",1) == 0) {