1 /* This file contains definitions for discouraged features.  When you
2    discourage something, move it here when that is feasible.
3 */
4 
5 /* Copyright (C) 2003, 2004, 2006, 2008 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifdef HAVE_CONFIG_H
23 #  include <config.h>
24 #endif
25 
26 #include <libguile.h>
27 
28 
29 #if (SCM_ENABLE_DISCOURAGED == 1)
30 
31 SCM
scm_short2num(short x)32 scm_short2num (short x)
33 {
34   return scm_from_short (x);
35 }
36 
37 SCM
scm_ushort2num(unsigned short x)38 scm_ushort2num (unsigned short x)
39 {
40   return scm_from_ushort (x);
41 }
42 
43 SCM
scm_int2num(int x)44 scm_int2num (int x)
45 {
46   return scm_from_int (x);
47 }
48 
49 SCM
scm_uint2num(unsigned int x)50 scm_uint2num (unsigned int x)
51 {
52   return scm_from_uint (x);
53 }
54 
55 SCM
scm_long2num(long x)56 scm_long2num (long x)
57 {
58   return scm_from_long (x);
59 }
60 
61 SCM
scm_ulong2num(unsigned long x)62 scm_ulong2num (unsigned long x)
63 {
64   return scm_from_ulong (x);
65 }
66 
67 SCM
scm_size2num(size_t x)68 scm_size2num (size_t x)
69 {
70   return scm_from_size_t (x);
71 }
72 
73 SCM
scm_ptrdiff2num(ptrdiff_t x)74 scm_ptrdiff2num (ptrdiff_t x)
75 {
76   return scm_from_ssize_t (x);
77 }
78 
79 short
scm_num2short(SCM x,unsigned long pos,const char * s_caller)80 scm_num2short (SCM x, unsigned long pos, const char *s_caller)
81 {
82   return scm_to_short (x);
83 }
84 
85 unsigned short
scm_num2ushort(SCM x,unsigned long pos,const char * s_caller)86 scm_num2ushort (SCM x, unsigned long pos, const char *s_caller)
87 {
88   return scm_to_ushort (x);
89 }
90 
91 int
scm_num2int(SCM x,unsigned long pos,const char * s_caller)92 scm_num2int (SCM x, unsigned long pos, const char *s_caller)
93 {
94   return scm_to_int (x);
95 }
96 
97 unsigned int
scm_num2uint(SCM x,unsigned long pos,const char * s_caller)98 scm_num2uint (SCM x, unsigned long pos, const char *s_caller)
99 {
100   return scm_to_uint (x);
101 }
102 
103 long
scm_num2long(SCM x,unsigned long pos,const char * s_caller)104 scm_num2long (SCM x, unsigned long pos, const char *s_caller)
105 {
106   return scm_to_long (x);
107 }
108 
109 unsigned long
scm_num2ulong(SCM x,unsigned long pos,const char * s_caller)110 scm_num2ulong (SCM x, unsigned long pos, const char *s_caller)
111 {
112   return scm_to_ulong (x);
113 }
114 
115 size_t
scm_num2size(SCM x,unsigned long pos,const char * s_caller)116 scm_num2size (SCM x, unsigned long pos, const char *s_caller)
117 {
118   return scm_to_size_t (x);
119 }
120 
121 ptrdiff_t
scm_num2ptrdiff(SCM x,unsigned long pos,const char * s_caller)122 scm_num2ptrdiff (SCM x, unsigned long pos, const char *s_caller)
123 {
124   return scm_to_ssize_t (x);
125 }
126 
127 #if SCM_SIZEOF_LONG_LONG != 0
128 
129 SCM
scm_long_long2num(long long x)130 scm_long_long2num (long long x)
131 {
132   return scm_from_long_long (x);
133 }
134 
135 SCM
scm_ulong_long2num(unsigned long long x)136 scm_ulong_long2num (unsigned long long x)
137 {
138   return scm_from_ulong_long (x);
139 }
140 
141 long long
scm_num2long_long(SCM x,unsigned long pos,const char * s_caller)142 scm_num2long_long (SCM x, unsigned long pos, const char *s_caller)
143 {
144   return scm_to_long_long (x);
145 }
146 
147 unsigned long long
scm_num2ulong_long(SCM x,unsigned long pos,const char * s_caller)148 scm_num2ulong_long (SCM x, unsigned long pos, const char *s_caller)
149 {
150   return scm_to_ulong_long (x);
151 }
152 
153 #endif
154 
155 SCM
scm_make_real(double x)156 scm_make_real (double x)
157 {
158   return scm_from_double (x);
159 }
160 
161 double
scm_num2dbl(SCM a,const char * why)162 scm_num2dbl (SCM a, const char *why)
163 {
164   return scm_to_double (a);
165 }
166 
167 SCM
scm_float2num(float n)168 scm_float2num (float n)
169 {
170   return scm_from_double ((double) n);
171 }
172 
173 SCM
scm_double2num(double n)174 scm_double2num (double n)
175 {
176   return scm_from_double (n);
177 }
178 
179 SCM
scm_make_complex(double x,double y)180 scm_make_complex (double x, double y)
181 {
182   return scm_c_make_rectangular (x, y);
183 }
184 
185 SCM
scm_mem2symbol(const char * mem,size_t len)186 scm_mem2symbol (const char *mem, size_t len)
187 {
188   return scm_from_locale_symboln (mem, len);
189 }
190 
191 SCM
scm_mem2uninterned_symbol(const char * mem,size_t len)192 scm_mem2uninterned_symbol (const char *mem, size_t len)
193 {
194   return scm_make_symbol (scm_from_locale_stringn (mem, len));
195 }
196 
197 SCM
scm_str2symbol(const char * str)198 scm_str2symbol (const char *str)
199 {
200   return scm_from_locale_symbol (str);
201 }
202 
203 
204 /* This function must only be applied to memory obtained via malloc,
205    since the GC is going to apply `free' to it when the string is
206    dropped.
207 
208    Also, s[len] must be `\0', since we promise that strings are
209    null-terminated.  Perhaps we could handle non-null-terminated
210    strings by claiming they're shared substrings of a string we just
211    made up.  */
212 SCM
scm_take_str(char * s,size_t len)213 scm_take_str (char *s, size_t len)
214 {
215   SCM answer = scm_from_locale_stringn (s, len);
216   free (s);
217   return answer;
218 }
219 
220 /* `s' must be a malloc'd string.  See scm_take_str.  */
221 SCM
scm_take0str(char * s)222 scm_take0str (char *s)
223 {
224   return scm_take_locale_string (s);
225 }
226 
227 SCM
scm_mem2string(const char * src,size_t len)228 scm_mem2string (const char *src, size_t len)
229 {
230   return scm_from_locale_stringn (src, len);
231 }
232 
233 SCM
scm_str2string(const char * src)234 scm_str2string (const char *src)
235 {
236   return scm_from_locale_string (src);
237 }
238 
239 SCM
scm_makfrom0str(const char * src)240 scm_makfrom0str (const char *src)
241 {
242   if (!src) return SCM_BOOL_F;
243   return scm_from_locale_string (src);
244 }
245 
246 SCM
scm_makfrom0str_opt(const char * src)247 scm_makfrom0str_opt (const char *src)
248 {
249   return scm_makfrom0str (src);
250 }
251 
252 
253 SCM
scm_allocate_string(size_t len)254 scm_allocate_string (size_t len)
255 {
256   return scm_i_make_string (len, NULL);
257 }
258 
259 SCM_DEFINE (scm_make_keyword_from_dash_symbol, "make-keyword-from-dash-symbol", 1, 0, 0,
260             (SCM symbol),
261             "Make a keyword object from a @var{symbol} that starts with a dash.")
262 #define FUNC_NAME s_scm_make_keyword_from_dash_symbol
263 {
264   SCM dash_string, non_dash_symbol;
265 
266   SCM_ASSERT (scm_is_symbol (symbol)
267 	      && ('-' == scm_i_symbol_chars(symbol)[0]),
268 	      symbol, SCM_ARG1, FUNC_NAME);
269 
270   dash_string = scm_symbol_to_string (symbol);
271   non_dash_symbol =
272     scm_string_to_symbol (scm_c_substring (dash_string,
273 					   1,
274 					   scm_c_string_length (dash_string)));
275 
276   return scm_symbol_to_keyword (non_dash_symbol);
277 }
278 #undef FUNC_NAME
279 
280 SCM_DEFINE (scm_keyword_dash_symbol, "keyword-dash-symbol", 1, 0, 0,
281             (SCM keyword),
282 	    "Return the dash symbol for @var{keyword}.\n"
283 	    "This is the inverse of @code{make-keyword-from-dash-symbol}.")
284 #define FUNC_NAME s_scm_keyword_dash_symbol
285 {
286   SCM symbol = scm_keyword_to_symbol (keyword);
287   SCM parts = scm_list_2 (scm_from_locale_string ("-"),
288 			  scm_symbol_to_string (symbol));
289   return scm_string_to_symbol (scm_string_append (parts));
290 }
291 #undef FUNC_NAME
292 
293 SCM
scm_c_make_keyword(const char * s)294 scm_c_make_keyword (const char *s)
295 {
296   return scm_from_locale_keyword (s);
297 }
298 
299 
300 void
scm_i_init_discouraged(void)301 scm_i_init_discouraged (void)
302 {
303 #include "libguile/discouraged.x"
304 }
305 
306 #endif
307