]> git.donarmstrong.com Git - lilypond.git/blob - guile18/libguile/feature.c
New upstream version 2.19.65
[lilypond.git] / guile18 / libguile / feature.c
1 /* Copyright (C) 1995,1996,1998,1999,2000,2001,2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
2  * 
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but 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.
12  *
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 02110-1301 USA
16  */
17
18
19 \f
20 #ifdef HAVE_CONFIG_H
21 #  include <config.h>
22 #endif
23
24 #ifdef HAVE_STRING_H
25 #include <string.h>
26 #endif
27
28 #include "libguile/_scm.h"
29 #include "libguile/root.h"
30 #include "libguile/strings.h"
31 #include "libguile/validate.h"
32 #include "libguile/fluids.h"
33
34 #include "libguile/feature.h"
35
36 \f
37
38 static SCM progargs_fluid;
39 static SCM features_var;
40
41 void
42 scm_add_feature (const char *str)
43 {
44   SCM old = SCM_VARIABLE_REF (features_var);
45   SCM new = scm_cons (scm_from_locale_symbol (str), old);
46   SCM_VARIABLE_SET (features_var, new);
47 }
48
49 \f
50
51 SCM_DEFINE (scm_program_arguments, "program-arguments", 0, 0, 0, 
52             (),
53             "@deffnx {Scheme Procedure} command-line\n"
54             "Return the list of command line arguments passed to Guile, as a list of\n"
55             "strings.  The list includes the invoked program name, which is usually\n"
56             "@code{\"guile\"}, but excludes switches and parameters for command line\n"
57             "options like @code{-e} and @code{-l}.")
58 #define FUNC_NAME s_scm_program_arguments
59 {
60   return scm_fluid_ref (progargs_fluid);
61 }
62 #undef FUNC_NAME
63
64 /* Set the value returned by program-arguments, given ARGC and ARGV.
65
66    If FIRST is non-zero, make it the first element; we do this in
67    situations where other code (like getopt) has parsed out a few
68    arguments, but we still want the script name to be the first
69    element.  */
70 void
71 scm_set_program_arguments (int argc, char **argv, char *first)
72 {
73   SCM args = scm_makfromstrs (argc, argv);
74   if (first)
75     args = scm_cons (scm_from_locale_string (first), args);
76   scm_fluid_set_x (progargs_fluid, args);
77 }
78
79 SCM_DEFINE (scm_set_program_arguments_scm, "set-program-arguments", 1, 0, 0, 
80             (SCM lst),
81             "Set the command line arguments to be returned by\n"
82             "@code{program-arguments} (and @code{command-line}).  @var{lst}\n"
83             "should be a list of strings, the first of which is the program\n"
84             "name (either a script name, or just @code{\"guile\"}).\n"
85             "\n"
86             "Program arguments are held in a fluid and therefore have a\n"
87             "separate value in each Guile thread.  Neither the list nor the\n"
88             "strings within it are copied, so should not be modified later.")
89 #define FUNC_NAME s_scm_set_program_arguments_scm
90 {
91   return scm_fluid_set_x (progargs_fluid, lst);
92 }
93 #undef FUNC_NAME
94
95
96 \f
97
98 void
99 scm_init_feature()
100 {
101   progargs_fluid = scm_permanent_object (scm_make_fluid ());
102
103   features_var = scm_c_define ("*features*", SCM_EOL);
104 #ifndef _Windows
105   scm_add_feature("system");
106 #endif
107 #ifdef vms
108   scm_add_feature(s_ed);
109 #endif
110 #ifdef SICP
111   scm_add_feature("sicp");
112 #endif
113 #ifndef GO32
114   scm_add_feature("char-ready?");
115 #endif
116 #ifndef CHEAP_CONTINUATIONS
117   scm_add_feature ("full-continuation");
118 #endif
119 #if SCM_USE_PTHREAD_THREADS
120   scm_add_feature ("threads");
121 #endif
122
123   scm_c_define ("char-code-limit", scm_from_int (SCM_CHAR_CODE_LIMIT));
124
125 #include "libguile/feature.x"
126 }
127
128 /*
129   Local Variables:
130   c-file-style: "gnu"
131   End:
132 */