Changed license terms to the plain LGPL thru-out.
[bpt/guile.git] / libguile / deprecated.c
1 /* This file contains definitions for deprecated features. When you
2 deprecate something, move it here when that is feasible.
3 */
4
5 /* Copyright (C) 2003 Free Software Foundation, Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 #include "libguile/_scm.h"
23 #include "libguile/deprecated.h"
24 #include "libguile/deprecation.h"
25 #include "libguile/snarf.h"
26 #include "libguile/validate.h"
27 #include "libguile/strings.h"
28 #include "libguile/strop.h"
29
30 #include <stdio.h>
31 #include <string.h>
32
33 #if (SCM_ENABLE_DEPRECATED == 1)
34
35 SCM_REGISTER_PROC(s_substring_move_left_x, "substring-move-left!", 5, 0, 0, scm_substring_move_x);
36
37 SCM_REGISTER_PROC(s_substring_move_right_x, "substring-move-right!", 5, 0, 0, scm_substring_move_x);
38
39 SCM
40 scm_wta (SCM arg, const char *pos, const char *s_subr)
41 {
42 if (!s_subr || !*s_subr)
43 s_subr = NULL;
44 if ((~0x1fL) & (long) pos)
45 {
46 /* error string supplied. */
47 scm_misc_error (s_subr, pos, scm_list_1 (arg));
48 }
49 else
50 {
51 /* numerical error code. */
52 scm_t_bits error = (scm_t_bits) pos;
53
54 switch (error)
55 {
56 case SCM_ARGn:
57 scm_wrong_type_arg (s_subr, 0, arg);
58 case SCM_ARG1:
59 scm_wrong_type_arg (s_subr, 1, arg);
60 case SCM_ARG2:
61 scm_wrong_type_arg (s_subr, 2, arg);
62 case SCM_ARG3:
63 scm_wrong_type_arg (s_subr, 3, arg);
64 case SCM_ARG4:
65 scm_wrong_type_arg (s_subr, 4, arg);
66 case SCM_ARG5:
67 scm_wrong_type_arg (s_subr, 5, arg);
68 case SCM_ARG6:
69 scm_wrong_type_arg (s_subr, 6, arg);
70 case SCM_ARG7:
71 scm_wrong_type_arg (s_subr, 7, arg);
72 case SCM_WNA:
73 scm_wrong_num_args (arg);
74 case SCM_OUTOFRANGE:
75 scm_out_of_range (s_subr, arg);
76 case SCM_NALLOC:
77 scm_memory_error (s_subr);
78 default:
79 /* this shouldn't happen. */
80 scm_misc_error (s_subr, "Unknown error", SCM_EOL);
81 }
82 }
83 return SCM_UNSPECIFIED;
84 }
85
86 /* Module registry
87 */
88
89 /* We can't use SCM objects here. One should be able to call
90 SCM_REGISTER_MODULE from a C++ constructor for a static
91 object. This happens before main and thus before libguile is
92 initialized. */
93
94 struct moddata {
95 struct moddata *link;
96 char *module_name;
97 void *init_func;
98 };
99
100 static struct moddata *registered_mods = NULL;
101
102 void
103 scm_register_module_xxx (char *module_name, void *init_func)
104 {
105 struct moddata *md;
106
107 scm_c_issue_deprecation_warning
108 ("`scm_register_module_xxx' is deprecated. Use extensions instead.");
109
110 /* XXX - should we (and can we) DEFER_INTS here? */
111
112 for (md = registered_mods; md; md = md->link)
113 if (!strcmp (md->module_name, module_name))
114 {
115 md->init_func = init_func;
116 return;
117 }
118
119 md = (struct moddata *) malloc (sizeof (struct moddata));
120 if (md == NULL)
121 {
122 fprintf (stderr,
123 "guile: can't register module (%s): not enough memory",
124 module_name);
125 return;
126 }
127
128 md->module_name = module_name;
129 md->init_func = init_func;
130 md->link = registered_mods;
131 registered_mods = md;
132 }
133
134 SCM_DEFINE (scm_registered_modules, "c-registered-modules", 0, 0, 0,
135 (),
136 "Return a list of the object code modules that have been imported into\n"
137 "the current Guile process. Each element of the list is a pair whose\n"
138 "car is the name of the module, and whose cdr is the function handle\n"
139 "for that module's initializer function. The name is the string that\n"
140 "has been passed to scm_register_module_xxx.")
141 #define FUNC_NAME s_scm_registered_modules
142 {
143 SCM res;
144 struct moddata *md;
145
146 res = SCM_EOL;
147 for (md = registered_mods; md; md = md->link)
148 res = scm_cons (scm_cons (scm_makfrom0str (md->module_name),
149 scm_ulong2num ((unsigned long) md->init_func)),
150 res);
151 return res;
152 }
153 #undef FUNC_NAME
154
155 SCM_DEFINE (scm_clear_registered_modules, "c-clear-registered-modules", 0, 0, 0,
156 (),
157 "Destroy the list of modules registered with the current Guile process.\n"
158 "The return value is unspecified. @strong{Warning:} this function does\n"
159 "not actually unlink or deallocate these modules, but only destroys the\n"
160 "records of which modules have been loaded. It should therefore be used\n"
161 "only by module bookkeeping operations.")
162 #define FUNC_NAME s_scm_clear_registered_modules
163 {
164 struct moddata *md1, *md2;
165
166 SCM_DEFER_INTS;
167
168 for (md1 = registered_mods; md1; md1 = md2)
169 {
170 md2 = md1->link;
171 free (md1);
172 }
173 registered_mods = NULL;
174
175 SCM_ALLOW_INTS;
176 return SCM_UNSPECIFIED;
177 }
178 #undef FUNC_NAME
179
180
181 void
182 scm_i_init_deprecated ()
183 {
184 #include "libguile/deprecated.x"
185 }
186
187 #endif