* numbers.c (scm_logand, scm_logior, scm_logxor, scm_logtest,
[bpt/guile.git] / libguile / feature.c
CommitLineData
7dc6e754 1/* Copyright (C) 1995,1996,1998 Free Software Foundation, Inc.
0f2d19dd
JB
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
6 * any later version.
7 *
8 * This program 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
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
82892bed
JB
15 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
0f2d19dd
JB
17 *
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
20 *
21 * The exception is that, if you link the GUILE library with other files
22 * to produce an executable, this does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * Your use of that executable is in no way restricted on account of
25 * linking the GUILE library code into it.
26 *
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
29 *
30 * This exception applies only to the code released by the
31 * Free Software Foundation under the name GUILE. If you copy
32 * code from other Free Software Foundation releases into a copy of
33 * GUILE, as the General Public License permits, the exception does
34 * not apply to the code that you add in this way. To avoid misleading
35 * anyone as to the status of such modified files, you must delete
36 * this exception notice from them.
37 *
38 * If you write modifications of your own for GUILE, it is your choice
39 * whether to permit this exception to apply to your modifications.
82892bed 40 * If you do not wish that, delete this exception notice. */
0f2d19dd
JB
41\f
42
43#include <stdio.h>
44#include "_scm.h"
45
1330700c
MD
46#include "eval.h"
47
20e6290e
JB
48#include "feature.h"
49
95b88819
GH
50#ifdef HAVE_STRING_H
51#include <string.h>
52#endif
0f2d19dd
JB
53\f
54
f072db0c 55static SCM *scm_loc_features;
0f2d19dd 56
0f2d19dd
JB
57void
58scm_add_feature(str)
59 char* str;
0f2d19dd 60{
f072db0c
JB
61 *scm_loc_features = scm_cons(SCM_CAR(scm_intern(str, strlen(str))),
62 *scm_loc_features);
0f2d19dd
JB
63}
64
65
66\f
0f2d19dd 67SCM_PROC(s_program_arguments, "program-arguments", 0, 0, 0, scm_program_arguments);
0b886892 68
0f2d19dd
JB
69SCM
70scm_program_arguments ()
0f2d19dd
JB
71{
72 return scm_progargs;
73}
74
f29de790
JB
75/* Set the value returned by program-arguments, given ARGC and ARGV.
76
77 If FIRST is non-zero, make it the first element; we do this in
78 situations where other code (like getopt) has parsed out a few
79 arguments, but we still want the script name to be the first
80 element. */
0b886892 81void
f29de790 82scm_set_program_arguments (argc, argv, first)
0b886892
JB
83 int argc;
84 char **argv;
f29de790 85 char *first;
0b886892
JB
86{
87 scm_progargs = scm_makfromstrs (argc, argv);
f29de790
JB
88 if (first)
89 scm_progargs = scm_cons (scm_makfrom0str (first), scm_progargs);
0b886892
JB
90}
91
0f2d19dd 92
0f2d19dd 93\f
1330700c
MD
94/* Hooks */
95
96SCM_SYMBOL (scm_sym_hook, "hook");
97
98SCM_PROC (s_make_hook, "make-hook", 0, 0, 0, scm_make_hook);
99
100SCM
101scm_make_hook ()
102{
103 return scm_cons (scm_sym_hook, SCM_EOL);
104}
105
106SCM
107scm_make_named_hook (char* name)
108{
109 SCM hook = scm_make_hook ();
110 scm_permanent_object (scm_sysintern (name, hook));
111 return hook;
112}
113
114SCM_PROC (s_add_hook_x, "add-hook!", 2, 1, 0, scm_add_hook_x);
115
116SCM
117scm_add_hook_x (SCM hook, SCM thunk, SCM append_p)
118{
119 SCM rest;
120 SCM_ASSERT (SCM_NIMP (hook)
121 && SCM_CONSP (hook)
122 && SCM_CAR (hook) == scm_sym_hook
123 && scm_ilength (SCM_CDR (hook)) >= 0,
124 hook, SCM_ARG1, s_add_hook_x);
125 SCM_ASSERT (SCM_NFALSEP (scm_thunk_p (thunk)),
126 thunk, SCM_ARG2, s_add_hook_x);
127 rest = scm_delq_x (thunk, SCM_CDR (hook));
128 SCM_SETCDR (hook, (!SCM_UNBNDP (append_p) && SCM_NFALSEP (append_p)
129 ? scm_append_x (SCM_LIST2 (rest, SCM_LIST1 (thunk)))
130 : scm_cons (thunk, rest)));
131 return SCM_UNSPECIFIED;
132}
133
134SCM_PROC (s_remove_hook_x, "remove-hook!", 2, 0, 0, scm_remove_hook_x);
135
136SCM
137scm_remove_hook_x (SCM hook, SCM thunk)
138{
139 SCM_ASSERT (SCM_NIMP (hook)
140 && SCM_CONSP (hook)
141 && SCM_CAR (hook) == scm_sym_hook
142 && scm_ilength (SCM_CDR (hook)) >= 0,
143 hook, SCM_ARG1, s_add_hook_x);
144 SCM_ASSERT (SCM_NFALSEP (scm_thunk_p (thunk)),
145 thunk, SCM_ARG2, s_add_hook_x);
146 SCM_SETCDR (hook, scm_delq_x (thunk, SCM_CDR (hook)));
147 return SCM_UNSPECIFIED;
148}
149
150SCM_PROC (s_run_hooks, "run-hooks", 1, 0, 0, scm_run_hooks);
151
152SCM
153scm_run_hooks (SCM hook)
154{
155 SCM_ASSERT (SCM_NIMP (hook)
156 && SCM_CONSP (hook)
157 && SCM_CAR (hook) == scm_sym_hook
158 && scm_ilength (SCM_CDR (hook)) >= 0,
159 hook, SCM_ARG1, s_add_hook_x);
160 while (SCM_NIMP (hook = SCM_CDR (hook)))
161 scm_apply (SCM_CAR (hook), SCM_EOL, SCM_EOL);
162 return SCM_UNSPECIFIED;
163}
164
165\f
0f2d19dd 166
0f2d19dd
JB
167void
168scm_init_feature()
0f2d19dd 169{
25d8012c 170 scm_loc_features = SCM_CDRLOC (scm_sysintern ("*features*", SCM_EOL));
cf7c17e9 171#ifdef SCM_RECKLESS
0f2d19dd
JB
172 scm_add_feature("reckless");
173#endif
174#ifndef _Windows
175 scm_add_feature("system");
176#endif
177#ifdef vms
178 scm_add_feature(s_ed);
179#endif
180#ifdef SICP
181 scm_add_feature("sicp");
182#endif
183#ifndef GO32
184 scm_add_feature("char-ready?");
185#endif
186#ifndef CHEAP_CONTINUATIONS
187 scm_add_feature ("full-continuation");
188#endif
a6cba733
MD
189#ifdef USE_THREADS
190 scm_add_feature ("threads");
191#endif
192
e2806c10 193 scm_sysintern ("char-code-limit", SCM_MAKINUM (SCM_CHAR_CODE_LIMIT));
0f2d19dd
JB
194#include "feature.x"
195}