aboutsummaryrefslogtreecommitdiff
path: root/src/ellinika
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-06-13 14:05:13 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-06-14 02:27:27 +0300
commitce29f168ed52f08228b99a789785271a4a3c9b0e (patch)
treeacdcf09cc887bc508d8d803ad971f96e9da442be /src/ellinika
parentbee3becef44e298f59d72cee3c8e552bccb10d65 (diff)
downloadellinika-ce29f168ed52f08228b99a789785271a4a3c9b0e.tar.gz
ellinika-ce29f168ed52f08228b99a789785271a4a3c9b0e.tar.bz2
Implement escape function.
Diffstat (limited to 'src/ellinika')
-rw-r--r--src/ellinika/.gitignore1
-rw-r--r--src/ellinika/Makefile.am6
-rw-r--r--src/ellinika/elmorph.c41
-rw-r--r--src/ellinika/elmorph.h2
-rw-r--r--src/ellinika/sql.scm33
-rw-r--r--src/ellinika/tests/escape.scm6
-rw-r--r--src/ellinika/utf8scm.c149
7 files changed, 196 insertions, 42 deletions
diff --git a/src/ellinika/.gitignore b/src/ellinika/.gitignore
index 11bf478..2c9a340 100644
--- a/src/ellinika/.gitignore
+++ b/src/ellinika/.gitignore
@@ -5,3 +5,4 @@ elmorph.scm
5elmorph.x 5elmorph.x
6phoneme.c 6phoneme.c
7phoneme.h 7phoneme.h
8utf8scm.x
diff --git a/src/ellinika/Makefile.am b/src/ellinika/Makefile.am
index b8988d4..581a537 100644
--- a/src/ellinika/Makefile.am
+++ b/src/ellinika/Makefile.am
@@ -22,7 +22,8 @@ guile_DATA=\
22 config.scm\ 22 config.scm\
23 dico.scm\ 23 dico.scm\
24 elmorph.scm\ 24 elmorph.scm\
25 tenses.scm 25 tenses.scm\
26 sql.scm
26 27
27cgi.m4: Makefile 28cgi.m4: Makefile
28 echo 'divert(-1)' > $@ 29 echo 'divert(-1)' > $@
@@ -57,13 +58,14 @@ pkglib_LTLIBRARIES=libelmorph.la
57libelmorph_la_SOURCES = \ 58libelmorph_la_SOURCES = \
58 aorist.c\ 59 aorist.c\
59 utf8.c\ 60 utf8.c\
61 utf8scm.c\
60 elchr.c\ 62 elchr.c\
61 elmorph.c\ 63 elmorph.c\
62 elmorph.h\ 64 elmorph.h\
63 phoneme.y\ 65 phoneme.y\
64 syllabificator.c 66 syllabificator.c
65 67
66DOT_X_FILES = elmorph.x 68DOT_X_FILES = elmorph.x utf8scm.x
67 69
68BUILT_SOURCES = $(DOT_X_FILES) 70BUILT_SOURCES = $(DOT_X_FILES)
69 71
diff --git a/src/ellinika/elmorph.c b/src/ellinika/elmorph.c
index 6d6a69a..56bead3 100644
--- a/src/ellinika/elmorph.c
+++ b/src/ellinika/elmorph.c
@@ -769,46 +769,6 @@ SCM_DEFINE_PUBLIC(scm_elstr_char_phoneme, "elstr-char-phoneme",
769} 769}
770#undef FUNC_NAME 770#undef FUNC_NAME
771 771
772SCM_DEFINE_PUBLIC(scm_utf8_toupper, "utf8-toupper", 1, 0, 0,
773 (SCM string),
774"Convert STRING to uppercase\n")
775#define FUNC_NAME s_scm_utf8_toupper
776{
777 char *str;
778 SCM scm;
779
780 SCM_ASSERT(scm_is_string(string), string, SCM_ARG1, FUNC_NAME);
781 str = scm_to_locale_string(string);
782 if (utf8_toupper(str, strlen(str)))
783 scm_misc_error(FUNC_NAME,
784 "cannot convert to upper case: ~S",
785 scm_list_1(string));
786 scm = scm_from_locale_string(str);
787 free(str);
788 return scm;
789}
790#undef FUNC_NAME
791
792SCM_DEFINE_PUBLIC(scm_utf8_tolower, "utf8-tolower", 1, 0, 0,
793 (SCM string),
794"Convert STRING to lowercase\n")
795#define FUNC_NAME s_scm_utf8_tolower
796{
797 char *str;
798 SCM scm;
799
800 SCM_ASSERT(scm_is_string(string), string, SCM_ARG1, FUNC_NAME);
801 str = scm_to_locale_string(string);
802 if (utf8_tolower(str, strlen(str)))
803 scm_misc_error(FUNC_NAME,
804 "cannot convert to lower case: ~S",
805 scm_list_1(string));
806 scm = scm_from_locale_string(str);
807 free(str);
808 return scm;
809}
810#undef FUNC_NAME
811
812static SCM 772static SCM
813_elstr_thema_aoristoy(SCM el, int destructive, const char *func_name) 773_elstr_thema_aoristoy(SCM el, int destructive, const char *func_name)
814{ 774{
@@ -1036,4 +996,5 @@ scm_init_ellinika_elmorph_module()
1036 scm_c_export(deftab[i].sym, NULL); 996 scm_c_export(deftab[i].sym, NULL);
1037 } 997 }
1038#include "elmorph.x" 998#include "elmorph.x"
999 elmorph_utf8scm_init();
1039} 1000}
diff --git a/src/ellinika/elmorph.h b/src/ellinika/elmorph.h
index c0df60f..83e1c83 100644
--- a/src/ellinika/elmorph.h
+++ b/src/ellinika/elmorph.h
@@ -137,3 +137,5 @@ int phoneme_map(struct phoneme **pph, size_t *plen,
137 unsigned *word, size_t len); 137 unsigned *word, size_t len);
138int syllable_map(struct syllable **psyl, size_t *plen, 138int syllable_map(struct syllable **psyl, size_t *plen,
139 struct phoneme *phon, size_t nphon); 139 struct phoneme *phon, size_t nphon);
140
141void elmorph_utf8scm_init(void);
diff --git a/src/ellinika/sql.scm b/src/ellinika/sql.scm
new file mode 100644
index 0000000..c0301ad
--- /dev/null
+++ b/src/ellinika/sql.scm
@@ -0,0 +1,33 @@
1(define-module (ellinika sql))
2
3(use-modules (srfi srfi-1)
4 (ellinika elmorph)
5 (gamma sql))
6
7(define ellinika:sql-verbose #f)
8(define ellinika:sql-conn #f)
9
10(define (ellinika:sql-connect arg)
11 (set! ellinika:sql-conn (sql-open-connection args))
12 (if ellinika:sql-conn
13 (sql-query ellinika:sql-conn "SET NAMES utf8"))
14 ellinika:sql-conn)
15
16(define (ellinika:sql-disconnect)
17 (if ellinika:sql-conn (sql-close-connection ellinika:sql-conn)))
18
19(define (ellinika:sql-query format . rest)
20 (let ((query (apply format #f
21 (map (lambda (arg)
22 (if arg
23 "NULL"
24 (utf8-escape arg)))
25 rest))))
26 (cond
27 (ellinika:sql-verbose
28 (format #f "QUERY: ~A~%" query)
29 (let ((res (sql-query ellinika:sql-conn query)))
30 (format #f "RES: ~A~%" res)
31 res))
32 (else
33 (sql-query ellinika:sql-conn query)))))
diff --git a/src/ellinika/tests/escape.scm b/src/ellinika/tests/escape.scm
new file mode 100644
index 0000000..841e496
--- /dev/null
+++ b/src/ellinika/tests/escape.scm
@@ -0,0 +1,6 @@
1(load-extension "./libelmorph" "scm_init_ellinika_elmorph_module")
2
3(display (utf8-escape "ο \"παρα\\κείμενος\""))
4(newline)
5(display (utf8-escape "ο \"παρα\\κείμενος\"" "ία" ))
6(newline)
diff --git a/src/ellinika/utf8scm.c b/src/ellinika/utf8scm.c
new file mode 100644
index 0000000..89f5fba
--- /dev/null
+++ b/src/ellinika/utf8scm.c
@@ -0,0 +1,149 @@
1/* This file is part of Ellinika project.
2 Copyright (C) 2011 Sergey Poznyakoff
3
4 Ellinika is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 Ellinika is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#ifdef HAVE_CONFIG_H
18# include <config.h>
19#endif
20#include <errno.h>
21#include <stdlib.h>
22#include <libguile.h>
23#include "utf8.h"
24
25
26SCM_DEFINE_PUBLIC(scm_utf8_toupper, "utf8-toupper", 1, 0, 0,
27 (SCM string),
28"Convert STRING to uppercase\n")
29#define FUNC_NAME s_scm_utf8_toupper
30{
31 char *str;
32 SCM scm;
33
34 SCM_ASSERT(scm_is_string(string), string, SCM_ARG1, FUNC_NAME);
35 str = scm_to_locale_string(string);
36 if (utf8_toupper(str, strlen(str)))
37 scm_misc_error(FUNC_NAME,
38 "cannot convert to upper case: ~S",
39 scm_list_1(string));
40 scm = scm_from_locale_string(str);
41 free(str);
42 return scm;
43}
44#undef FUNC_NAME
45
46SCM_DEFINE_PUBLIC(scm_utf8_tolower, "utf8-tolower", 1, 0, 0,
47 (SCM string),
48"Convert STRING to lowercase\n")
49#define FUNC_NAME s_scm_utf8_tolower
50{
51 char *str;
52 SCM scm;
53
54 SCM_ASSERT(scm_is_string(string), string, SCM_ARG1, FUNC_NAME);
55 str = scm_to_locale_string(string);
56 if (utf8_tolower(str, strlen(str)))
57 scm_misc_error(FUNC_NAME,
58 "cannot convert to lower case: ~S",
59 scm_list_1(string));
60 scm = scm_from_locale_string(str);
61 free(str);
62 return scm;
63}
64#undef FUNC_NAME
65
66static int
67memberof(unsigned *w, size_t len, unsigned c)
68{