Use Gnulib's `localcharset', with local patches.
[bpt/guile.git] / libguile / feature.c
CommitLineData
f39448c5 1/* Copyright (C) 1995,1996,1998,1999,2000,2001,2002, 2003, 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
0f2d19dd 2 *
73be1d9e 3 * This library is free software; you can redistribute it and/or
53befeb7
NJ
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.
0f2d19dd 7 *
53befeb7
NJ
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
0f2d19dd 12 *
73be1d9e
MV
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
53befeb7
NJ
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301 USA
73be1d9e 17 */
1bbd0b84 18
1bbd0b84 19
0f2d19dd 20\f
dbb605f5 21#ifdef HAVE_CONFIG_H
b652768e
RB
22# include <config.h>
23#endif
0f2d19dd 24
1a450153
DH
25#ifdef HAVE_STRING_H
26#include <string.h>
27#endif
0f2d19dd 28
1a450153 29#include "libguile/_scm.h"
a0599745 30#include "libguile/root.h"
a0599745 31#include "libguile/strings.h"
a0599745 32#include "libguile/validate.h"
73129443 33#include "libguile/fluids.h"
1a450153 34
a0599745 35#include "libguile/feature.h"
20e6290e 36
0f2d19dd
JB
37\f
38
73129443 39static SCM progargs_fluid;
86d31dfe 40static SCM features_var;
1a450153 41
0f2d19dd 42void
6e8d25a6 43scm_add_feature (const char *str)
0f2d19dd 44{
86d31dfe 45 SCM old = SCM_VARIABLE_REF (features_var);
cc95e00a 46 SCM new = scm_cons (scm_from_locale_symbol (str), old);
86d31dfe 47 SCM_VARIABLE_SET (features_var, new);
0f2d19dd
JB
48}
49
0f2d19dd 50\f
0b886892 51
3b3b36dd 52SCM_DEFINE (scm_program_arguments, "program-arguments", 0, 0, 0,
d46e4713 53 (),
8f85c0c6 54 "@deffnx {Scheme Procedure} command-line\n"
d46e4713
NJ
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}.")
1bbd0b84 59#define FUNC_NAME s_scm_program_arguments
0f2d19dd 60{
73129443 61 return scm_fluid_ref (progargs_fluid);
0f2d19dd 62}
1bbd0b84 63#undef FUNC_NAME
0f2d19dd 64
f29de790
JB
65/* Set the value returned by program-arguments, given ARGC and ARGV.
66
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
70 element. */
0b886892 71void
1bbd0b84 72scm_set_program_arguments (int argc, char **argv, char *first)
0b886892 73{
73129443 74 SCM args = scm_makfromstrs (argc, argv);
f29de790 75 if (first)
73129443
MV
76 args = scm_cons (scm_from_locale_string (first), args);
77 scm_fluid_set_x (progargs_fluid, args);
0b886892
JB
78}
79
23d72566
KR
80SCM_DEFINE (scm_set_program_arguments_scm, "set-program-arguments", 1, 0, 0,
81 (SCM lst),
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"
86 "\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
91{
92 return scm_fluid_set_x (progargs_fluid, lst);
93}
94#undef FUNC_NAME
95
0f2d19dd 96
0f2d19dd
JB
97\f
98
0f2d19dd
JB
99void
100scm_init_feature()
0f2d19dd 101{
f39448c5 102 progargs_fluid = scm_make_fluid ();
73129443 103
86d31dfe 104 features_var = scm_c_define ("*features*", SCM_EOL);
0f2d19dd
JB
105#ifndef _Windows
106 scm_add_feature("system");
107#endif
108#ifdef vms
109 scm_add_feature(s_ed);
110#endif
111#ifdef SICP
112 scm_add_feature("sicp");
113#endif
114#ifndef GO32
115 scm_add_feature("char-ready?");
116#endif
117#ifndef CHEAP_CONTINUATIONS
118 scm_add_feature ("full-continuation");
119#endif
73129443 120#if SCM_USE_PTHREAD_THREADS
a6cba733 121 scm_add_feature ("threads");
73129443
MV
122#endif
123
e11e83f3 124 scm_c_define ("char-code-limit", scm_from_int (SCM_CHAR_CODE_LIMIT));
26425129 125
a0599745 126#include "libguile/feature.x"
0f2d19dd 127}
89e00824
ML
128
129/*
130 Local Variables:
131 c-file-style: "gnu"
132 End:
133*/