discouraged.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /* This file contains definitions for discouraged features. When you
  2. discourage something, move it here when that is feasible.
  3. */
  4. /* Copyright (C) 2003, 2004, 2006, 2008 Free Software Foundation, Inc.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public License
  8. * as published by the Free Software Foundation; either version 3 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19. * 02110-1301 USA
  20. */
  21. #ifdef HAVE_CONFIG_H
  22. # include <config.h>
  23. #endif
  24. #include <libguile.h>
  25. #if (SCM_ENABLE_DISCOURAGED == 1)
  26. SCM
  27. scm_short2num (short x)
  28. {
  29. return scm_from_short (x);
  30. }
  31. SCM
  32. scm_ushort2num (unsigned short x)
  33. {
  34. return scm_from_ushort (x);
  35. }
  36. SCM
  37. scm_int2num (int x)
  38. {
  39. return scm_from_int (x);
  40. }
  41. SCM
  42. scm_uint2num (unsigned int x)
  43. {
  44. return scm_from_uint (x);
  45. }
  46. SCM
  47. scm_long2num (long x)
  48. {
  49. return scm_from_long (x);
  50. }
  51. SCM
  52. scm_ulong2num (unsigned long x)
  53. {
  54. return scm_from_ulong (x);
  55. }
  56. SCM
  57. scm_size2num (size_t x)
  58. {
  59. return scm_from_size_t (x);
  60. }
  61. SCM
  62. scm_ptrdiff2num (ptrdiff_t x)
  63. {
  64. return scm_from_ssize_t (x);
  65. }
  66. short
  67. scm_num2short (SCM x, unsigned long pos, const char *s_caller)
  68. {
  69. return scm_to_short (x);
  70. }
  71. unsigned short
  72. scm_num2ushort (SCM x, unsigned long pos, const char *s_caller)
  73. {
  74. return scm_to_ushort (x);
  75. }
  76. int
  77. scm_num2int (SCM x, unsigned long pos, const char *s_caller)
  78. {
  79. return scm_to_int (x);
  80. }
  81. unsigned int
  82. scm_num2uint (SCM x, unsigned long pos, const char *s_caller)
  83. {
  84. return scm_to_uint (x);
  85. }
  86. long
  87. scm_num2long (SCM x, unsigned long pos, const char *s_caller)
  88. {
  89. return scm_to_long (x);
  90. }
  91. unsigned long
  92. scm_num2ulong (SCM x, unsigned long pos, const char *s_caller)
  93. {
  94. return scm_to_ulong (x);
  95. }
  96. size_t
  97. scm_num2size (SCM x, unsigned long pos, const char *s_caller)
  98. {
  99. return scm_to_size_t (x);
  100. }
  101. ptrdiff_t
  102. scm_num2ptrdiff (SCM x, unsigned long pos, const char *s_caller)
  103. {
  104. return scm_to_ssize_t (x);
  105. }
  106. #if SCM_SIZEOF_LONG_LONG != 0
  107. SCM
  108. scm_long_long2num (long long x)
  109. {
  110. return scm_from_long_long (x);
  111. }
  112. SCM
  113. scm_ulong_long2num (unsigned long long x)
  114. {
  115. return scm_from_ulong_long (x);
  116. }
  117. long long
  118. scm_num2long_long (SCM x, unsigned long pos, const char *s_caller)
  119. {
  120. return scm_to_long_long (x);
  121. }
  122. unsigned long long
  123. scm_num2ulong_long (SCM x, unsigned long pos, const char *s_caller)
  124. {
  125. return scm_to_ulong_long (x);
  126. }
  127. #endif
  128. SCM
  129. scm_make_real (double x)
  130. {
  131. return scm_from_double (x);
  132. }
  133. double
  134. scm_num2dbl (SCM a, const char *why)
  135. {
  136. return scm_to_double (a);
  137. }
  138. SCM
  139. scm_float2num (float n)
  140. {
  141. return scm_from_double ((double) n);
  142. }
  143. SCM
  144. scm_double2num (double n)
  145. {
  146. return scm_from_double (n);
  147. }
  148. SCM
  149. scm_make_complex (double x, double y)
  150. {
  151. return scm_c_make_rectangular (x, y);
  152. }
  153. SCM
  154. scm_mem2symbol (const char *mem, size_t len)
  155. {
  156. return scm_from_locale_symboln (mem, len);
  157. }
  158. SCM
  159. scm_mem2uninterned_symbol (const char *mem, size_t len)
  160. {
  161. return scm_make_symbol (scm_from_locale_stringn (mem, len));
  162. }
  163. SCM
  164. scm_str2symbol (const char *str)
  165. {
  166. return scm_from_locale_symbol (str);
  167. }
  168. /* This function must only be applied to memory obtained via malloc,
  169. since the GC is going to apply `free' to it when the string is
  170. dropped.
  171. Also, s[len] must be `\0', since we promise that strings are
  172. null-terminated. Perhaps we could handle non-null-terminated
  173. strings by claiming they're shared substrings of a string we just
  174. made up. */
  175. SCM
  176. scm_take_str (char *s, size_t len)
  177. {
  178. SCM answer = scm_from_locale_stringn (s, len);
  179. free (s);
  180. return answer;
  181. }
  182. /* `s' must be a malloc'd string. See scm_take_str. */
  183. SCM
  184. scm_take0str (char *s)
  185. {
  186. return scm_take_locale_string (s);
  187. }
  188. SCM
  189. scm_mem2string (const char *src, size_t len)
  190. {
  191. return scm_from_locale_stringn (src, len);
  192. }
  193. SCM
  194. scm_str2string (const char *src)
  195. {
  196. return scm_from_locale_string (src);
  197. }
  198. SCM
  199. scm_makfrom0str (const char *src)
  200. {
  201. if (!src) return SCM_BOOL_F;
  202. return scm_from_locale_string (src);
  203. }
  204. SCM
  205. scm_makfrom0str_opt (const char *src)
  206. {
  207. return scm_makfrom0str (src);
  208. }
  209. SCM
  210. scm_allocate_string (size_t len)
  211. {
  212. return scm_i_make_string (len, NULL);
  213. }
  214. SCM_DEFINE (scm_make_keyword_from_dash_symbol, "make-keyword-from-dash-symbol", 1, 0, 0,
  215. (SCM symbol),
  216. "Make a keyword object from a @var{symbol} that starts with a dash.")
  217. #define FUNC_NAME s_scm_make_keyword_from_dash_symbol
  218. {
  219. SCM dash_string, non_dash_symbol;
  220. SCM_ASSERT (scm_is_symbol (symbol)
  221. && ('-' == scm_i_symbol_chars(symbol)[0]),
  222. symbol, SCM_ARG1, FUNC_NAME);
  223. dash_string = scm_symbol_to_string (symbol);
  224. non_dash_symbol =
  225. scm_string_to_symbol (scm_c_substring (dash_string,
  226. 1,
  227. scm_c_string_length (dash_string)));
  228. return scm_symbol_to_keyword (non_dash_symbol);
  229. }
  230. #undef FUNC_NAME
  231. SCM_DEFINE (scm_keyword_dash_symbol, "keyword-dash-symbol", 1, 0, 0,
  232. (SCM keyword),
  233. "Return the dash symbol for @var{keyword}.\n"
  234. "This is the inverse of @code{make-keyword-from-dash-symbol}.")
  235. #define FUNC_NAME s_scm_keyword_dash_symbol
  236. {
  237. SCM symbol = scm_keyword_to_symbol (keyword);
  238. SCM parts = scm_list_2 (scm_from_locale_string ("-"),
  239. scm_symbol_to_string (symbol));
  240. return scm_string_to_symbol (scm_string_append (parts));
  241. }
  242. #undef FUNC_NAME
  243. SCM
  244. scm_c_make_keyword (const char *s)
  245. {
  246. return scm_from_locale_keyword (s);
  247. }
  248. void
  249. scm_i_init_discouraged (void)
  250. {
  251. #include "libguile/discouraged.x"
  252. }
  253. #endif