diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-06-05 01:19:53 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-06-05 01:19:53 +0300 |
commit | 7087cd30afbb6f15c55b8adbc270776f35d4fefb (patch) | |
tree | fd57228a67d784149034ffc064f02bb10f138b00 /src/ellinika | |
parent | 70e1a84f121d0199f7fb140525b0c62dc138e0e4 (diff) | |
download | ellinika-7087cd30afbb6f15c55b8adbc270776f35d4fefb.tar.gz ellinika-7087cd30afbb6f15c55b8adbc270776f35d4fefb.tar.bz2 |
Bugfixes.
* data/db.struct (verb): Minor fix.
* src/ellinika/elchr.c: Fix base of lower case epsilon.
* src/ellinika/elmorph.c (_elstr_alloc_empty): New function.
(_elstr_alloc): Take additional argument. All uses changed.
(_elstr_concat): New function.
(_elstr_print): Correctly print objects with NULL sylmap.
(elstr?): New function.
(elstr-append): New function.
Diffstat (limited to 'src/ellinika')
-rw-r--r-- | src/ellinika/elchr.c | 4 | ||||
-rw-r--r-- | src/ellinika/elmorph.c | 95 |
2 files changed, 91 insertions, 8 deletions
diff --git a/src/ellinika/elchr.c b/src/ellinika/elchr.c index 10ea72d..3142b6f 100644 --- a/src/ellinika/elchr.c +++ b/src/ellinika/elchr.c | |||
@@ -213,7 +213,7 @@ struct char_info_st el_basic_ctype[] = { | |||
213 | { 0x03AA, CHF_VOWEL|CHF_UPPER|CHF_TREMA|CHF_DIPH2, 0x0399, 0x03CA }, /* Ϊ */ | 213 | { 0x03AA, CHF_VOWEL|CHF_UPPER|CHF_TREMA|CHF_DIPH2, 0x0399, 0x03CA }, /* Ϊ */ |
214 | { 0x03AB, CHF_VOWEL|CHF_UPPER|CHF_TREMA, 0x03A5, 0x03CB }, /* Ϋ */ | 214 | { 0x03AB, CHF_VOWEL|CHF_UPPER|CHF_TREMA, 0x03A5, 0x03CB }, /* Ϋ */ |
215 | { 0x03AC, CHF_VOWEL|CHF_LOWER|CHF_OXEIA, 0x03B1, 0x0386 }, /* ά */ | 215 | { 0x03AC, CHF_VOWEL|CHF_LOWER|CHF_OXEIA, 0x03B1, 0x0386 }, /* ά */ |
216 | { 0x03AD, CHF_VOWEL|CHF_LOWER|CHF_OXEIA, 0x03B4, 0x0388 }, /* έ */ | 216 | { 0x03AD, CHF_VOWEL|CHF_LOWER|CHF_OXEIA, 0x03B5, 0x0388 }, /* έ */ |
217 | { 0x03AE, CHF_VOWEL|CHF_LOWER|CHF_OXEIA|CHF_DIPH2, 0x03B7, 0x0389 }, /* ή */ | 217 | { 0x03AE, CHF_VOWEL|CHF_LOWER|CHF_OXEIA|CHF_DIPH2, 0x03B7, 0x0389 }, /* ή */ |
218 | { 0x03AF, CHF_VOWEL|CHF_LOWER|CHF_OXEIA|CHF_DIPH2, 0x03B9, 0x038A }, /* ί */ | 218 | { 0x03AF, CHF_VOWEL|CHF_LOWER|CHF_OXEIA|CHF_DIPH2, 0x03B9, 0x038A }, /* ί */ |
219 | { 0x03B0, CHF_VOWEL|CHF_OXEIA|CHF_TREMA, 0x03C5, 0, 0, 0, 0, 0x03CB }, /* ΰ */ | 219 | { 0x03B0, CHF_VOWEL|CHF_OXEIA|CHF_TREMA, 0x03C5, 0, 0, 0, 0, 0x03CB }, /* ΰ */ |
@@ -232,7 +232,7 @@ struct char_info_st el_basic_ctype[] = { | |||
232 | { 0x03BD, CHF_CONSONANT|CHF_LOWER|CHF_NUMERIC, 0, 0x039D, 50 }, /* ν */ | 232 | { 0x03BD, CHF_CONSONANT|CHF_LOWER|CHF_NUMERIC, 0, 0x039D, 50 }, /* ν */ |
233 | { 0x03BE, CHF_CONSONANT|CHF_LOWER|CHF_NUMERIC, 0, 0x039E, 60 }, /* ξ */ | 233 | { 0x03BE, CHF_CONSONANT|CHF_LOWER|CHF_NUMERIC, 0, 0x039E, 60 }, /* ξ */ |
234 | 234 | ||
235 | { 0x03BF, CHF_VOWEL|CHF_LOWER|CHF_NUMERIC, 0, 0x039F, 70, 0x03CC }, /* ο */ | 235 | { 0x03BF, CHF_VOWEL|CHF_LOWER|CHF_NUMERIC|CHF_DIPH1, 0, 0x039F, 70, 0x03CC }, /* ο */ |
236 | { 0x03C0, CHF_CONSONANT|CHF_LOWER|CHF_NUMERIC, 0, 0x03A0, 80 }, /* π */ | 236 | { 0x03C0, CHF_CONSONANT|CHF_LOWER|CHF_NUMERIC, 0, 0x03A0, 80 }, /* π */ |
237 | { 0x03C1, CHF_CONSONANT|CHF_LOWER|CHF_NUMERIC, 0, 0x03A1, 100 }, /* ρ */ | 237 | { 0x03C1, CHF_CONSONANT|CHF_LOWER|CHF_NUMERIC, 0, 0x03A1, 100 }, /* ρ */ |
238 | { 0x03C2, CHF_CONSONANT|CHF_LOWER, 0, 0x03A3 }, /* ς */ | 238 | { 0x03C2, CHF_CONSONANT|CHF_LOWER, 0, 0x03A3 }, /* ς */ |
diff --git a/src/ellinika/elmorph.c b/src/ellinika/elmorph.c index 6ff5f01..75e42f9 100644 --- a/src/ellinika/elmorph.c +++ b/src/ellinika/elmorph.c | |||
@@ -75,7 +75,18 @@ _elstr_syllabize(struct elstr *elstr) | |||
75 | } | 75 | } |
76 | 76 | ||
77 | static SCM | 77 | static SCM |
78 | _elstr_alloc(const char *instr) | 78 | _elstr_alloc_empty(struct elstr **pelstr) |
79 | { | ||
80 | struct elstr *elstr; | ||
81 | |||
82 | elstr = scm_gc_malloc(sizeof(*elstr), "Elstr"); | ||
83 | memset(elstr, 0, sizeof(*elstr)); | ||
84 | *pelstr = elstr; | ||
85 | SCM_RETURN_NEWSMOB(_elstr_tag, elstr); | ||
86 | } | ||
87 | |||
88 | static SCM | ||
89 | _elstr_alloc(const char *instr, int syl) | ||
79 | { | 90 | { |
80 | struct elstr *elstr; | 91 | struct elstr *elstr; |
81 | unsigned *wptr; | 92 | unsigned *wptr; |
@@ -88,6 +99,7 @@ _elstr_alloc(const char *instr) | |||
88 | elstr->str = wptr; | 99 | elstr->str = wptr; |
89 | elstr->len = wlen; | 100 | elstr->len = wlen; |
90 | elstr->sylmap = NULL; | 101 | elstr->sylmap = NULL; |
102 | if (syl) | ||
91 | _elstr_syllabize(elstr); | 103 | _elstr_syllabize(elstr); |
92 | 104 | ||
93 | SCM_RETURN_NEWSMOB(_elstr_tag, elstr); | 105 | SCM_RETURN_NEWSMOB(_elstr_tag, elstr); |
@@ -117,6 +129,22 @@ _elstr_dup(struct elstr *elstr) | |||
117 | SCM_RETURN_NEWSMOB(_elstr_tag, elnew); | 129 | SCM_RETURN_NEWSMOB(_elstr_tag, elnew); |
118 | } | 130 | } |
119 | 131 | ||
132 | static void | ||
133 | _elstr_concat(struct elstr *dest, struct elstr *src, const char *func_name) | ||
134 | { | ||
135 | unsigned *wp; | ||
136 | |||
137 | wp = realloc(dest->str, | ||
138 | sizeof(dest->str[0]) * (dest->len + src->len)); | ||
139 | if (!wp) | ||
140 | scm_memory_error(func_name); | ||
141 | dest->str = wp; | ||
142 | memcpy(dest->str + dest->len, | ||
143 | src->str, | ||
144 | sizeof(src->str[0]) * src->len); | ||
145 | dest->len += src->len; | ||
146 | } | ||
147 | |||
120 | static scm_sizet | 148 | static scm_sizet |
121 | _elstr_free(SCM smob) | 149 | _elstr_free(SCM smob) |
122 | { | 150 | { |
@@ -134,7 +162,9 @@ _elstr_print(SCM smob, SCM port, scm_print_state *pstate) | |||
134 | int i, j, an; | 162 | int i, j, an; |
135 | char *s; | 163 | char *s; |
136 | 164 | ||
137 | scm_puts("#<elstr ``", port); | 165 | scm_puts("#<elstr ", port); |
166 | if (elstr->sylmap) { | ||
167 | scm_puts("``", port); | ||
138 | an = elstr->nsyl - elstr->acc_syl; | 168 | an = elstr->nsyl - elstr->acc_syl; |
139 | if (an == 0) | 169 | if (an == 0) |
140 | scm_puts("[", port); | 170 | scm_puts("[", port); |
@@ -157,6 +187,18 @@ _elstr_print(SCM smob, SCM port, scm_print_state *pstate) | |||
157 | } | 187 | } |
158 | if (j == an) | 188 | if (j == an) |
159 | scm_puts("]", port); | 189 | scm_puts("]", port); |
190 | } else { | ||
191 | scm_puts("[NS] ``", port); | ||
192 | for (i = j = 0; i < elstr->len; i++) { | ||
193 | char r[6]; | ||
194 | int n; | ||
195 | n = utf8_wctomb(r, elstr->str[i]); | ||
196 | if (n == -1) | ||
197 | continue; | ||
198 | r[n] = 0; | ||
199 | scm_puts(r, port); | ||
200 | } | ||
201 | } | ||
160 | scm_puts("''>", port); | 202 | scm_puts("''>", port); |
161 | return 1; | 203 | return 1; |
162 | } | 204 | } |
@@ -169,6 +211,17 @@ _elstr_init() | |||
169 | scm_set_smob_print(_elstr_tag, _elstr_print); | 211 | scm_set_smob_print(_elstr_tag, _elstr_print); |
170 | } | 212 | } |
171 | 213 | ||
214 | #define scm_is_elstr(s) (!SCM_IMP(s) && SCM_CELL_TYPE(s) == _elstr_tag) | ||
215 | |||
216 | SCM_DEFINE_PUBLIC(scm_elstr_p, "elstr?", 1, 0, 0, | ||
217 | (SCM string), | ||
218 | "Return true if STRING is an elstr\n") | ||
219 | #define FUNC_NAME s_scm_elstr_p | ||
220 | { | ||
221 | return scm_is_elstr(string) ? SCM_BOOL_T : SCM_BOOL_F; | ||
222 | } | ||
223 | #undef FUNC_NAME | ||
224 | |||
172 | SCM_DEFINE_PUBLIC(scm_string__elstr, "string->elstr", 1, 0, 0, | 225 | SCM_DEFINE_PUBLIC(scm_string__elstr, "string->elstr", 1, 0, 0, |
173 | (SCM string), | 226 | (SCM string), |
174 | "Create new ELSTR from STRING\n") | 227 | "Create new ELSTR from STRING\n") |
@@ -179,7 +232,7 @@ SCM_DEFINE_PUBLIC(scm_string__elstr, "string->elstr", 1, 0, 0, | |||
179 | 232 | ||
180 | SCM_ASSERT(scm_is_string(string), string, SCM_ARG1, FUNC_NAME); | 233 | SCM_ASSERT(scm_is_string(string), string, SCM_ARG1, FUNC_NAME); |
181 | str = scm_to_locale_string(string); | 234 | str = scm_to_locale_string(string); |
182 | scm = _elstr_alloc(str); | 235 | scm = _elstr_alloc(str, 1); |
183 | free(str); | 236 | free(str); |
184 | if (scm == SCM_EOL) | 237 | if (scm == SCM_EOL) |
185 | scm_misc_error(FUNC_NAME, | 238 | scm_misc_error(FUNC_NAME, |
@@ -189,8 +242,6 @@ SCM_DEFINE_PUBLIC(scm_string__elstr, "string->elstr", 1, 0, 0, | |||
189 | } | 242 | } |
190 | #undef FUNC_NAME | 243 | #undef FUNC_NAME |
191 | 244 | ||
192 | #define scm_is_elstr(s) (!SCM_IMP(s) && SCM_CELL_TYPE(s) == _elstr_tag) | ||
193 | |||
194 | SCM_DEFINE_PUBLIC(scm_elstr__string, "elstr->string", 1, 0, 0, | 245 | SCM_DEFINE_PUBLIC(scm_elstr__string, "elstr->string", 1, 0, 0, |
195 | (SCM el), | 246 | (SCM el), |
196 | "Convert EL to a STRING\n") | 247 | "Convert EL to a STRING\n") |
@@ -475,7 +526,7 @@ _elstr_set_accent(SCM el, SCM n, int destructive, const char *func_name) | |||
475 | num = scm_to_uint(n); | 526 | num = scm_to_uint(n); |
476 | if (num > elstr->nsyl) | 527 | if (num > elstr->nsyl) |
477 | scm_misc_error(func_name, | 528 | scm_misc_error(func_name, |
478 | "cannot get syllable #~S: not enough syllables: ~S", | 529 | "cannot set accent on syllable #~S: not enough syllables: ~S", |
479 | scm_list_2(el, n)); | 530 | scm_list_2(el, n)); |
480 | acc_num = elstr->nsyl - num; | 531 | acc_num = elstr->nsyl - num; |
481 | if (acc_num == 0) | 532 | if (acc_num == 0) |
@@ -755,6 +806,38 @@ SCM_DEFINE_PUBLIC(scm_elstr_index, "elstr-index", | |||
755 | } | 806 | } |
756 | #undef FUNC_NAME | 807 | #undef FUNC_NAME |
757 | 808 | ||
809 | SCM_DEFINE_PUBLIC(scm_elstr_append, "elstr-append", | ||
810 | 0, 0, 1, | ||
811 | (SCM rest), | ||
812 | "") | ||
813 | #define FUNC_NAME s_scm_elstr_append | ||
814 | { | ||
815 | SCM ret = _elstr_alloc("", 0); | ||
816 | struct elstr *elstr = (struct elstr*) SCM_CDR(ret); | ||
817 | |||
818 | for (; !scm_is_null(rest); rest = SCM_CDR(rest)) { | ||
819 | SCM val = SCM_CAR(rest); | ||
820 | if (scm_is_elstr(val)) { | ||
821 | struct elstr *elt = (struct elstr*) SCM_CDR(val); | ||
822 | _elstr_concat(elstr, elt, FUNC_NAME); | ||
823 | } else if (scm_is_string(val)) { | ||
824 | char *s = scm_to_locale_string(val); | ||
825 | if (s[0]) { | ||
826 | SCM tmp = _elstr_alloc(s, 0); | ||
827 | free(s); | ||
828 | _elstr_concat(elstr, | ||
829 | (struct elstr*) SCM_CDR(tmp), | ||
830 | FUNC_NAME); | ||
831 | } else | ||
832 | free(s); | ||
833 | } else | ||
834 | scm_wrong_type_arg(FUNC_NAME, SCM_ARGn, rest); | ||
835 | } | ||
836 | _elstr_syllabize(elstr); | ||
837 | return ret; | ||
838 | } | ||
839 | #undef FUNC_NAME | ||
840 | |||
758 | 841 | ||
759 | void | 842 | void |
760 | scm_init_ellinika_elmorph_module() | 843 | scm_init_ellinika_elmorph_module() |