This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Patch for wrong no declaration seen for command-line-arguments
- From: Per Bothner <per at bothner dot com>
- To: Matthieu Vachon <matthieu dot o dot vachon at gmail dot com>
- Cc: "kawa at sourceware dot org" <kawa at sourceware dot org>
- Date: Sun, 15 Sep 2013 22:48:45 -0700
- Subject: Re: Patch for wrong no declaration seen for command-line-arguments
- Authentication-results: sourceware.org; auth=none
- References: <CAOTvmo=VWjMv2Etk9gagPTAa2OgnM-3XG9USdLWrARbJ22dTcg at mail dot gmail dot com>
On 09/11/2013 08:42 PM, Matthieu Vachon wrote:
Hi Per,
Here my try at fixing the incorrect warning that occurs when
generating a main method and using the `command-line-arguments`. It's
probably not the optimal way to fix the issue but I hope it is good
enough to be included in the trunk.
Thanks for prodding me into action. Your patch makes me think
that having a special case for command-line-arguments is the wrong approach.
Please try the attached patch instead. That is a simpler/cleaner
solution.
You might also consider using the (command-line) procedure.
It is specified by R6RS and R7RS so is more portable.
It also gives you the "command" used to invoke the application
(roughly argv[0]). The attached patch provides a more informative
result for (car (command-line)) - rather than plain "kawa".
I'd be interested in feedback in how portable it is: Windows,
MacOS, non-Sun/Oracle VMs (including ones that don't set the
sun.java.command property). (I also working on updating the
documentation.)
--
--Per Bothner
per@bothner.com http://per.bothner.com/
Index: gnu/expr/ApplicationMainSupport.java
===================================================================
--- gnu/expr/ApplicationMainSupport.java (revision 7583)
+++ gnu/expr/ApplicationMainSupport.java (working copy)
@@ -43,7 +43,6 @@
public static void setArgs (String[] args, int arg_start)
{
int nargs = args.length - arg_start;
- Object[] array = new Object[nargs];
if (arg_start == 0)
commandLineArgArray = args;
else
@@ -53,12 +52,10 @@
strings[i] = args[i+arg_start];
commandLineArgArray = strings;
}
- for (int i = nargs; --i >= 0; )
- array[i] = new FString (args[i + arg_start]);
- commandLineArguments = new FVector (array); // FIXME scsh has list
- // FIXME scsh also has command-line proc
- Environment.getCurrent().put("command-line-arguments",
- commandLineArguments);
+
+ Object[] array = new Object[nargs];
+ System.arraycopy(args, arg_start, array, 0, nargs);
+ commandLineArguments = new ConstVector(array); // FIXME scsh has list
}
public static boolean processSetProperty (String arg)
Index: kawa/lib/rnrs/programs.scm
===================================================================
--- kawa/lib/rnrs/programs.scm (revision 7583)
+++ kawa/lib/rnrs/programs.scm (working copy)
@@ -3,8 +3,32 @@
(require <kawa.lib.prim_syntax>)
(define (command-line) :: list
- (let ((arg0 "kawa")) ;; FIXME
- (cons arg0 (gnu.lists.LList:makeList gnu.expr.ApplicationMainSupport:commandLineArgArray 0))))
+ (let* ((rest
+ (gnu.lists.LList:makeList
+ gnu.expr.ApplicationMainSupport:commandLineArgArray 0))
+ (command ::java.lang.String
+ (try-catch
+ (let ((raw (java.lang.System:getProperty
+ "sun.java.command")))
+ (if (eq? raw #!null) #!null
+ ;; Strip off the tail of the property value that
+ ;; duplicates the rest value.
+ (let* ((frest (format #f "~{ ~a~}" rest))
+ (rlen (raw:length))
+ (flen (frest:length))
+ (alen (- rlen flen)))
+ (cond ((= flen 0)
+ raw)
+ ;; Sanity check
+ ((and (>= alen 0)
+ ((raw:substring alen):equals frest))
+ (raw:substring 0 alen))
+ (else
+ #!null)))))
+ (exp java.lang.Throwable #!null)))
+ (arg0 (if (eq? command #!null) "kawa"
+ ("java ":concat command))))
+ (cons arg0 rest)))
(define (exit #!optional (code 0)) :: #!void
(invoke-static <output-port> 'runCleanups)
Index: kawa/standard/Scheme.java
===================================================================
--- kawa/standard/Scheme.java (revision 7583)
+++ kawa/standard/Scheme.java (working copy)
@@ -565,6 +565,8 @@
defProcStFld("exit", "kawa.lib.rnrs.programs");
defProcStFld("command-line", "kawa.lib.rnrs.programs");
+ defAliasStFld("command-line-arguments",
+ "gnu.expr.ApplicationMainSupport", "commandLineArguments");
defProcStFld("bitwise-arithmetic-shift",
"gnu.kawa.functions.BitwiseOp", "ashift");