defconst, defvar: proclaim special at compile-time
[bpt/guile.git] / libguile / feature.c
CommitLineData
ed4c3739 1/* Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
921cd222 2 * 2006, 2007, 2009, 2011, 2013 Free Software Foundation, Inc.
ed4c3739 3 *
73be1d9e 4 * This library is free software; you can redistribute it and/or
53befeb7
NJ
5 * modify it under the terms of the GNU Lesser General Public License
6 * as published by the Free Software Foundation; either version 3 of
7 * the License, or (at your option) any later version.
0f2d19dd 8 *
53befeb7
NJ
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
0f2d19dd 13 *
73be1d9e
MV
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
53befeb7
NJ
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA
73be1d9e 18 */
1bbd0b84 19
1bbd0b84 20
0f2d19dd 21\f
dbb605f5 22#ifdef HAVE_CONFIG_H
b652768e
RB
23# include <config.h>
24#endif
0f2d19dd 25
1a450153
DH
26#ifdef HAVE_STRING_H
27#include <string.h>
28#endif
0f2d19dd 29
1a450153 30#include "libguile/_scm.h"
a0599745 31#include "libguile/root.h"
a0599745 32#include "libguile/strings.h"
a0599745 33#include "libguile/validate.h"
73129443 34#include "libguile/fluids.h"
1a450153 35
a0599745 36#include "libguile/feature.h"
20e6290e 37
0f2d19dd
JB
38\f
39
ed4c3739
LC
40SCM scm_program_arguments_fluid;
41
86d31dfe 42static SCM features_var;
1a450153 43
0f2d19dd 44void
6e8d25a6 45scm_add_feature (const char *str)
0f2d19dd 46{
86d31dfe 47 SCM old = SCM_VARIABLE_REF (features_var);
25d50a05 48 SCM new = scm_cons (scm_from_utf8_symbol (str), old);
86d31dfe 49 SCM_VARIABLE_SET (features_var, new);
0f2d19dd
JB
50}
51
0f2d19dd 52\f
0b886892 53
3b3b36dd 54SCM_DEFINE (scm_program_arguments, "program-arguments", 0, 0, 0,
d46e4713 55 (),
8f85c0c6 56 "@deffnx {Scheme Procedure} command-line\n"
d46e4713
NJ
57 "Return the list of command line arguments passed to Guile, as a list of\n"
58 "strings. The list includes the invoked program name, which is usually\n"
59 "@code{\"guile\"}, but excludes switches and parameters for command line\n"
60 "options like @code{-e} and @code{-l}.")
1bbd0b84 61#define FUNC_NAME s_scm_program_arguments
0f2d19dd 62{
ed4c3739 63 return scm_fluid_ref (scm_program_arguments_fluid);
0f2d19dd 64}
1bbd0b84 65#undef FUNC_NAME
0f2d19dd 66
f29de790
JB
67/* Set the value returned by program-arguments, given ARGC and ARGV.
68
69 If FIRST is non-zero, make it the first element; we do this in
70 situations where other code (like getopt) has parsed out a few
71 arguments, but we still want the script name to be the first
72 element. */
0b886892 73void
1bbd0b84 74scm_set_program_arguments (int argc, char **argv, char *first)
0b886892 75{
73129443 76 SCM args = scm_makfromstrs (argc, argv);
f29de790 77 if (first)
73129443 78 args = scm_cons (scm_from_locale_string (first), args);
ed4c3739 79 scm_fluid_set_x (scm_program_arguments_fluid, args);
0b886892
JB
80}
81
23d72566
KR
82SCM_DEFINE (scm_set_program_arguments_scm, "set-program-arguments", 1, 0, 0,
83 (SCM lst),
84 "Set the command line arguments to be returned by\n"
85 "@code{program-arguments} (and @code{command-line}). @var{lst}\n"
86 "should be a list of strings, the first of which is the program\n"
87 "name (either a script name, or just @code{\"guile\"}).\n"
88 "\n"
89 "Program arguments are held in a fluid and therefore have a\n"
90 "separate value in each Guile thread. Neither the list nor the\n"
91 "strings within it are copied, so should not be modified later.")
92#define FUNC_NAME s_scm_set_program_arguments_scm
93{
ed4c3739 94 return scm_fluid_set_x (scm_program_arguments_fluid, lst);
23d72566
KR
95}
96#undef FUNC_NAME
97
0f2d19dd 98
0f2d19dd
JB
99\f
100
0f2d19dd
JB
101void
102scm_init_feature()
0f2d19dd 103{
ed4c3739 104 scm_program_arguments_fluid = scm_make_fluid ();
73129443 105
86d31dfe 106 features_var = scm_c_define ("*features*", SCM_EOL);
0f2d19dd
JB
107#ifndef _Windows
108 scm_add_feature("system");
109#endif
110#ifdef vms
111 scm_add_feature(s_ed);
112#endif
0f2d19dd
JB
113#ifndef GO32
114 scm_add_feature("char-ready?");
115#endif
73129443 116#if SCM_USE_PTHREAD_THREADS
a6cba733 117 scm_add_feature ("threads");
73129443
MV
118#endif
119
a0599745 120#include "libguile/feature.x"
0f2d19dd 121}
89e00824
ML
122
123/*
124 Local Variables:
125 c-file-style: "gnu"
126 End:
127*/