manpagez: man pages & more
info guile
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.2.6 Runtime Environment

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’ (see section 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 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. Eg.

{
  char *progname = argv[0];
  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 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.

Scheme Procedure: getenv name
C Function: scm_getenv (name)

Looks up the string name in the current environment. The return value is #f unless a string of the form NAME=VALUE is found, in which case the string VALUE is returned.

Scheme Procedure: setenv name value

Modifies the environment of the current process, which is also the default environment inherited by child processes.

If value is #f, then name is removed from the environment. Otherwise, the string name=value is added to the environment, replacing any existing string with name matching name.

The return value is unspecified.

Scheme Procedure: unsetenv name

Remove variable name from the environment. The name can not contain a ‘=’ character.

Scheme Procedure: environ [env]
C Function: scm_environ (env)

If env is omitted, return the current environment (in the Unix sense) as a list of strings. Otherwise set the current environment, which is also the default environment for child processes, to the supplied list of strings. Each member of env should be of the form name=value and values of name should not be duplicated. If env is supplied then the return value is unspecified.

Scheme Procedure: putenv str
C Function: scm_putenv (str)

Modifies the environment of the current process, which is also the default environment inherited by child processes.

If str is of the form NAME=VALUE then it will be written directly into the environment, replacing any existing environment string with name matching NAME. If str does not contain an equal sign, then any existing string with name matching str will be removed.

The return value is unspecified.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on April 20, 2013 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.