1 /* Copyright (C) 1995,1996,1998,1999,2000,2001,2002, 2003, 2004, 2006, 2007, 2009, 2011 Free Software Foundation, Inc.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 #include "libguile/_scm.h"
30 #include "libguile/root.h"
31 #include "libguile/strings.h"
32 #include "libguile/validate.h"
33 #include "libguile/fluids.h"
35 #include "libguile/feature.h"
39 static SCM progargs_fluid
;
40 static SCM features_var
;
43 scm_add_feature (const char *str
)
45 SCM old
= SCM_VARIABLE_REF (features_var
);
46 SCM
new = scm_cons (scm_from_utf8_symbol (str
), old
);
47 SCM_VARIABLE_SET (features_var
, new);
52 SCM_DEFINE (scm_program_arguments
, "program-arguments", 0, 0, 0,
54 "@deffnx {Scheme Procedure} command-line\n"
55 "Return the list of command line arguments passed to Guile, as a list of\n"
56 "strings. The list includes the invoked program name, which is usually\n"
57 "@code{\"guile\"}, but excludes switches and parameters for command line\n"
58 "options like @code{-e} and @code{-l}.")
59 #define FUNC_NAME s_scm_program_arguments
61 return scm_fluid_ref (progargs_fluid
);
65 /* Set the value returned by program-arguments, given ARGC and ARGV.
67 If FIRST is non-zero, make it the first element; we do this in
68 situations where other code (like getopt) has parsed out a few
69 arguments, but we still want the script name to be the first
72 scm_set_program_arguments (int argc
, char **argv
, char *first
)
74 SCM args
= scm_makfromstrs (argc
, argv
);
76 args
= scm_cons (scm_from_locale_string (first
), args
);
77 scm_fluid_set_x (progargs_fluid
, args
);
80 SCM_DEFINE (scm_set_program_arguments_scm
, "set-program-arguments", 1, 0, 0,
82 "Set the command line arguments to be returned by\n"
83 "@code{program-arguments} (and @code{command-line}). @var{lst}\n"
84 "should be a list of strings, the first of which is the program\n"
85 "name (either a script name, or just @code{\"guile\"}).\n"
87 "Program arguments are held in a fluid and therefore have a\n"
88 "separate value in each Guile thread. Neither the list nor the\n"
89 "strings within it are copied, so should not be modified later.")
90 #define FUNC_NAME s_scm_set_program_arguments_scm
92 return scm_fluid_set_x (progargs_fluid
, lst
);
102 progargs_fluid
= scm_make_fluid ();
104 features_var
= scm_c_define ("*features*", SCM_EOL
);
106 scm_add_feature("system");
109 scm_add_feature(s_ed
);
112 scm_add_feature("char-ready?");
114 #if SCM_USE_PTHREAD_THREADS
115 scm_add_feature ("threads");
118 #include "libguile/feature.x"