From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: Re: doc scm_set_program_arguments Date: Tue, 16 Jan 2007 09:20:04 +1100 Message-ID: <873b6cue3v.fsf@zip.com.au> References: <87d55iimr4.fsf@zip.com.au> <87bql2msh3.fsf@ossau.uklinux.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1168899638 3482 80.91.229.12 (15 Jan 2007 22:20:38 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 15 Jan 2007 22:20:38 +0000 (UTC) Cc: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Jan 15 23:20:34 2007 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1H6aBk-00055G-JY for guile-devel@m.gmane.org; Mon, 15 Jan 2007 23:20:24 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1H6aBk-0002xr-ES for guile-devel@m.gmane.org; Mon, 15 Jan 2007 17:20:24 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1H6aBh-0002xm-A6 for guile-devel@gnu.org; Mon, 15 Jan 2007 17:20:21 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1H6aBf-0002xF-Ht for guile-devel@gnu.org; Mon, 15 Jan 2007 17:20:21 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1H6aBf-0002xB-FF for guile-devel@gnu.org; Mon, 15 Jan 2007 17:20:19 -0500 Original-Received: from [61.8.2.215] (helo=mailout1.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.52) id 1H6aBe-0007eT-NV for guile-devel@gnu.org; Mon, 15 Jan 2007 17:20:19 -0500 Original-Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.2.163]) by mailout1.pacific.net.au (Postfix) with ESMTP id EF3E65A7DD8; Tue, 16 Jan 2007 09:20:16 +1100 (EST) Original-Received: from localhost (ppp275F.dyn.pacific.net.au [61.8.39.95]) by mailproxy2.pacific.net.au (Postfix) with ESMTP id 23CA02742D; Tue, 16 Jan 2007 09:20:16 +1100 (EST) Original-Received: from gg by localhost with local (Exim 4.63) (envelope-from ) id 1H6aBQ-0004Uk-Ot; Tue, 16 Jan 2007 09:20:04 +1100 Original-To: Neil Jerram Mail-Copies-To: never In-Reply-To: <87bql2msh3.fsf@ossau.uklinux.net> (Neil Jerram's message of "Sat, 13 Jan 2007 23:12:24 +0000") User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:6428 Archived-At: Neil Jerram writes: > > Is argv normally NULL-terminated? Yes, if it's from main(). > I would have thought that "argc-i" would be more reliable than "-1" > here. I guess it's clearer to use one method or the other (not a mixture). I changed it to below (with set-program-arguments added too). Is there a particular reason for the extra `command-line' name? -- Scheme Procedure: program-arguments -- Scheme Procedure: command-line -- Scheme Procedure: set-program-arguments -- C Function: scm_program_arguments () -- C Function: scm_set_program_arguments_scm (lst) Get the command line arguments passed to Guile, or set new arguments. The arguments are a list of strings, the first of which is the invoked program name. This is just "guile" (or the executable path) when run interactively, or it's the script name when running a script with `-s' (*note Invoking Guile::). guile -L /my/extra/dir -s foo.scm abc def (program-arguments) => ("foo.scm" "abc" "def") `set-program-arguments' allows a library module or similar to modify the arguments, for example to strip options it recognises, leaving the rest for the mainline. The argument list is held in a fluid, which means it's separate for each thread. Neither the list nor the strings within it are copied at any point and normally should not be mutated. The two names `program-arguments' and `command-line' are an historical accident, they both do exactly the same thing. The name `scm_set_program_arguments_scm' has an extra `_scm' on the end to avoid clashing with the C function below. -- C Function: void scm_set_program_arguments (int argc, char **argv, char *first) Set the list of command line arguments for `program-arguments' and `command-line' above. ARGV is an array of null-terminated strings, as in a C `main' function. ARGC is the number of strings in ARGV, or if it's negative then a `NULL' entry in ARGV marks its end. FIRST is an extra string put at the start of the arguments, or `NULL' for no such extra. This is a convenient way to pass the program name after advancing ARGV to strip option arguments. { char *progname = argv[0]; int i; for (argv++; argv[0] != NULL && argv[0][0] == '-'; argv++) { /* munch option ... */ } /* remaining args for scheme level use */ scm_set_program_arguments (-1, argv, progname); } This sort of thing is often done at startup under `scm_boot_guile' with any options handled at the C level removed. The given strings are all copied, so the C data is not accessed again once `scm_set_program_arguments' returns. _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel