unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* doc scm_set_program_arguments
@ 2007-01-13 22:29 Kevin Ryde
  2007-01-13 23:12 ` Neil Jerram
  0 siblings, 1 reply; 4+ messages in thread
From: Kevin Ryde @ 2007-01-13 22:29 UTC (permalink / raw)


I wrote a few words for scm_set_program_arguments, which is mentioned
under scm_boot_guile but not otherwise described.


 -- C Function: void scm_set_program_arguments (int argc, char **argv,
          char *first)
     Set the  list of command line arguments to be returned by
     `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 the 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 or
     similar.

          {
            char *progname = argv[0];
            int i;
            for (i = 1; i < argc && argv[i][0] == '-'; i++)
              {
                /* munch option ... */
              }
            /* remaining args for scheme level use */
            scm_set_program_arguments (-1, argv+i, progname);
          }

     This sort of thing is often done at startup under `scm_boot_guile'
     and similar.  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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: doc scm_set_program_arguments
  2007-01-13 22:29 doc scm_set_program_arguments Kevin Ryde
@ 2007-01-13 23:12 ` Neil Jerram
  2007-01-15 22:20   ` Kevin Ryde
  0 siblings, 1 reply; 4+ messages in thread
From: Neil Jerram @ 2007-01-13 23:12 UTC (permalink / raw)


Kevin Ryde <user42@zip.com.au> writes:

> I wrote a few words for scm_set_program_arguments, which is mentioned
> under scm_boot_guile but not otherwise described.

Looks good, just one comment:

>             scm_set_program_arguments (-1, argv+i, progname);

Is argv normally NULL-terminated?  I would have thought that "argc-i"
would be more reliable than "-1" here.

Regards,
     Neil



_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: doc scm_set_program_arguments
  2007-01-13 23:12 ` Neil Jerram
@ 2007-01-15 22:20   ` Kevin Ryde
  2007-01-17 19:26     ` Neil Jerram
  0 siblings, 1 reply; 4+ messages in thread
From: Kevin Ryde @ 2007-01-15 22:20 UTC (permalink / raw)
  Cc: guile-devel

Neil Jerram <neil@ossau.uklinux.net> 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: doc scm_set_program_arguments
  2007-01-15 22:20   ` Kevin Ryde
@ 2007-01-17 19:26     ` Neil Jerram
  0 siblings, 0 replies; 4+ messages in thread
From: Neil Jerram @ 2007-01-17 19:26 UTC (permalink / raw)


Kevin Ryde <user42@zip.com.au> writes:

> Neil Jerram <neil@ossau.uklinux.net> writes:
>>
>> 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).

Thanks, that looks good.

Regards,
     Neil



_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-01-17 19:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-13 22:29 doc scm_set_program_arguments Kevin Ryde
2007-01-13 23:12 ` Neil Jerram
2007-01-15 22:20   ` Kevin Ryde
2007-01-17 19:26     ` Neil Jerram

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).