temporarily disable elisp exception tests
[bpt/guile.git] / libguile / unicode.c
1 /* Copyright (C) 2014 Free Software Foundation, Inc.
2 *
3 * This library is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU Lesser General Public License as
5 * published by the Free Software Foundation, either version 3 of the
6 * License, or (at your option) any later version.
7 *
8 * This library 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library. If not, see
15 * <http://www.gnu.org/licenses/>.
16 */
17
18 \f
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22
23 #include <ctype.h>
24 #include <limits.h>
25 #include <unicase.h>
26 #include <unictype.h>
27 #include <uniname.h>
28
29 #include "libguile/_scm.h"
30 #include "libguile/validate.h"
31
32 #include "libguile/unicode.h"
33
34 \f
35
36 SCM_DEFINE (scm_char_to_formal_name, "char->formal-name", 1, 0, 0,
37 (SCM ch),
38 "Return the formal all-upper-case unicode name of @var{ch},\n"
39 "as a string. If the character has no name, return @code{#f}.")
40 #define FUNC_NAME s_scm_char_to_formal_name
41 {
42 char buf[UNINAME_MAX + 1];
43
44 SCM_VALIDATE_CHAR (1, ch);
45
46 memset(buf, 0, UNINAME_MAX + 1);
47
48 if (unicode_character_name (SCM_CHAR (ch), buf))
49 return scm_from_latin1_string (buf);
50
51 return SCM_BOOL_F;
52 }
53 #undef FUNC_NAME
54
55 SCM_DEFINE (scm_formal_name_to_char, "formal-name->char", 1, 0, 0,
56 (SCM name),
57 "Return the character whose formal all-upper-case unicode name is\n"
58 "@var{name}, or @code{#f} if no such character is known.")
59 #define FUNC_NAME s_scm_formal_name_to_char
60 {
61 char *c_name;
62 scm_t_wchar ret;
63
64 SCM_VALIDATE_STRING (1, name);
65
66 c_name = scm_to_latin1_string (name);
67 ret = unicode_name_character (c_name);
68 free (c_name);
69
70 return ret == UNINAME_INVALID ? SCM_BOOL_F : SCM_MAKE_CHAR (ret);
71 }
72 #undef FUNC_NAME
73
74 static void
75 scm_load_unicode (void)
76 {
77 #ifndef SCM_MAGIC_SNARFER
78 #include "libguile/unicode.x"
79 #endif
80 }
81
82 void
83 scm_init_unicode (void)
84 {
85 scm_c_register_extension ("libguile-" SCM_EFFECTIVE_VERSION,
86 "scm_init_unicode",
87 (scm_t_extension_init_func)scm_load_unicode,
88 NULL);
89 }
90
91 /*
92 Local Variables:
93 c-file-style: "gnu"
94 End:
95 */