liblouis-rb 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +520 -0
- data/README.md +100 -0
- data/Rakefile +80 -0
- data/ext/liblouis/braille_character.c +200 -0
- data/ext/liblouis/braille_table.c +198 -0
- data/ext/liblouis/braille_text.c +223 -0
- data/ext/liblouis/extconf.rb +73 -0
- data/ext/liblouis/liblouis.c +168 -0
- data/ext/liblouis/liblouis_ext.h +49 -0
- data/ext/liblouis/table_source.c +161 -0
- data/ext/liblouis/translation.c +443 -0
- data/liblouis-rb.gemspec +49 -0
- data/spec/liblouis_spec.rb +62 -0
- data/test/integration/packaging_test.rb +82 -0
- data/test/table_source_cases.rb +9 -0
- data/test/test_braille_character.rb +62 -0
- data/test/test_braille_table.rb +379 -0
- data/test/test_braille_text.rb +30 -0
- data/test/test_helper.rb +7 -0
- data/test/translation_cases.rb +33 -0
- data/vendor/liblouis/COPYING +674 -0
- data/vendor/liblouis/COPYING.LESSER +502 -0
- data/vendor/liblouis/configure.ac +290 -0
- data/vendor/liblouis/liblouis/commonTranslationFunctions.c +95 -0
- data/vendor/liblouis/liblouis/compileTranslationTable.c +5515 -0
- data/vendor/liblouis/liblouis/internal.h +781 -0
- data/vendor/liblouis/liblouis/liblouis.h.in +514 -0
- data/vendor/liblouis/liblouis/logging.c +233 -0
- data/vendor/liblouis/liblouis/lou_backTranslateString.c +1855 -0
- data/vendor/liblouis/liblouis/lou_translateString.c +4177 -0
- data/vendor/liblouis/liblouis/maketable.c +463 -0
- data/vendor/liblouis/liblouis/metadata.c +1258 -0
- data/vendor/liblouis/liblouis/pattern.c +1632 -0
- data/vendor/liblouis/liblouis/utils.c +448 -0
- data/vendor/liblouis/tables/Es-Es-G0.utb +248 -0
- data/vendor/liblouis/tables/IPA-unicode-range.uti +200 -0
- data/vendor/liblouis/tables/IPA.utb +164 -0
- data/vendor/liblouis/tables/Lv-Lv-g1.utb +509 -0
- data/vendor/liblouis/tables/Makefile.am +503 -0
- data/vendor/liblouis/tables/Pl-Pl-g1.utb +312 -0
- data/vendor/liblouis/tables/README +6 -0
- data/vendor/liblouis/tables/afr-za-g1.ctb +63 -0
- data/vendor/liblouis/tables/afr-za-g2.ctb +1050 -0
- data/vendor/liblouis/tables/akk-borger.utb +997 -0
- data/vendor/liblouis/tables/akk.utb +1002 -0
- data/vendor/liblouis/tables/ancient-languages-borger.utb +114 -0
- data/vendor/liblouis/tables/ancient-languages-us.utb +114 -0
- data/vendor/liblouis/tables/ar-ar-comp8.utb +293 -0
- data/vendor/liblouis/tables/ar-ar-g1-core.uti +291 -0
- data/vendor/liblouis/tables/ar-ar-g1.utb +26 -0
- data/vendor/liblouis/tables/ar-ar-g2.ctb +447 -0
- data/vendor/liblouis/tables/ar-ar-math.uti +501 -0
- data/vendor/liblouis/tables/ar.tbl +17 -0
- data/vendor/liblouis/tables/as-in-g1.utb +27 -0
- data/vendor/liblouis/tables/as.tbl +18 -0
- data/vendor/liblouis/tables/aw-in-g1.utb +27 -0
- data/vendor/liblouis/tables/awa.tbl +18 -0
- data/vendor/liblouis/tables/ba.utb +64 -0
- data/vendor/liblouis/tables/be-in-g1.utb +27 -0
- data/vendor/liblouis/tables/bel-comp.utb +42 -0
- data/vendor/liblouis/tables/bel-detailed.utb +32 -0
- data/vendor/liblouis/tables/bel.utb +61 -0
- data/vendor/liblouis/tables/bengali.cti +238 -0
- data/vendor/liblouis/tables/bg.ctb +215 -0
- data/vendor/liblouis/tables/bg.dis +84 -0
- data/vendor/liblouis/tables/bg.tbl +21 -0
- data/vendor/liblouis/tables/bg.utb +454 -0
- data/vendor/liblouis/tables/bh.ctb +24 -0
- data/vendor/liblouis/tables/bh.tbl +17 -0
- data/vendor/liblouis/tables/bn.tbl +18 -0
- data/vendor/liblouis/tables/bo.ctb +184 -0
- data/vendor/liblouis/tables/bo.tbl +21 -0
- data/vendor/liblouis/tables/boxes.ctb +162 -0
- data/vendor/liblouis/tables/br-in-g1.utb +27 -0
- data/vendor/liblouis/tables/bra.tbl +18 -0
- data/vendor/liblouis/tables/braille-patterns.cti +287 -0
- data/vendor/liblouis/tables/ca-chardefs.cti +225 -0
- data/vendor/liblouis/tables/ca-g1.ctb +46 -0
- data/vendor/liblouis/tables/ca.tbl +18 -0
- data/vendor/liblouis/tables/chr-us-g1.ctb +180 -0
- data/vendor/liblouis/tables/ckb-chardefs.cti +219 -0
- data/vendor/liblouis/tables/ckb-g1.ctb +31 -0
- data/vendor/liblouis/tables/ckb-translation.cti +131 -0
- data/vendor/liblouis/tables/ckb.tbl +18 -0
- data/vendor/liblouis/tables/compress.cti +44 -0
- data/vendor/liblouis/tables/controlchars.cti +27 -0
- data/vendor/liblouis/tables/cop-eg-comp8.utb +255 -0
- data/vendor/liblouis/tables/cop.utb +231 -0
- data/vendor/liblouis/tables/corrections.cti +47 -0
- data/vendor/liblouis/tables/countries.cti +263 -0
- data/vendor/liblouis/tables/critical-apparatus.uti +54 -0
- data/vendor/liblouis/tables/cs-chardefs.cti +385 -0
- data/vendor/liblouis/tables/cs-comp8.utb +405 -0
- data/vendor/liblouis/tables/cs-g1.ctb +37 -0
- data/vendor/liblouis/tables/cs-translation.cti +63 -0
- data/vendor/liblouis/tables/cs.tbl +20 -0
- data/vendor/liblouis/tables/cuneiform-transliterated-compact.utb +432 -0
- data/vendor/liblouis/tables/cuneiform-transliterated.utb +160 -0
- data/vendor/liblouis/tables/cy-cy-g1.utb +487 -0
- data/vendor/liblouis/tables/cy-cy-g2.ctb +199 -0
- data/vendor/liblouis/tables/cy.tbl +19 -0
- data/vendor/liblouis/tables/da-dk-6miscChars.cti +385 -0
- data/vendor/liblouis/tables/da-dk-6miscChars_1993.cti +412 -0
- data/vendor/liblouis/tables/da-dk-8miscChars.cti +90 -0
- data/vendor/liblouis/tables/da-dk-8miscChars_1993.cti +102 -0
- data/vendor/liblouis/tables/da-dk-g08.ctb +290 -0
- data/vendor/liblouis/tables/da-dk-g08_1993.ctb +331 -0
- data/vendor/liblouis/tables/da-dk-g16-lit_1993.ctb +294 -0
- data/vendor/liblouis/tables/da-dk-g16.ctb +289 -0
- data/vendor/liblouis/tables/da-dk-g16_1993.ctb +305 -0
- data/vendor/liblouis/tables/da-dk-g18.ctb +545 -0
- data/vendor/liblouis/tables/da-dk-g18_1993.ctb +563 -0
- data/vendor/liblouis/tables/da-dk-g2.dic +7439 -0
- data/vendor/liblouis/tables/da-dk-g26-lit_1993.ctb +898 -0
- data/vendor/liblouis/tables/da-dk-g26.ctb +1345 -0
- data/vendor/liblouis/tables/da-dk-g26_1993.ctb +1127 -0
- data/vendor/liblouis/tables/da-dk-g26l-lit_1993.ctb +588 -0
- data/vendor/liblouis/tables/da-dk-g26l_1993.ctb +604 -0
- data/vendor/liblouis/tables/da-dk-g28.ctb +2426 -0
- data/vendor/liblouis/tables/da-dk-g28_1993.ctb +2063 -0
- data/vendor/liblouis/tables/da-dk-g28l_1993.ctb +1594 -0
- data/vendor/liblouis/tables/da-dk-octobraille.dis +316 -0
- data/vendor/liblouis/tables/da-dk-octobraille_1993.dis +313 -0
- data/vendor/liblouis/tables/de-accents-detailed.cti +214 -0
- data/vendor/liblouis/tables/de-accents.cti +214 -0
- data/vendor/liblouis/tables/de-chardefs6.cti +289 -0
- data/vendor/liblouis/tables/de-chardefs8.cti +278 -0
- data/vendor/liblouis/tables/de-chess.ctb +37 -0
- data/vendor/liblouis/tables/de-comp6.utb +226 -0
- data/vendor/liblouis/tables/de-de-comp8.ctb +492 -0
- data/vendor/liblouis/tables/de-de.dis +331 -0
- data/vendor/liblouis/tables/de-eurobrl6.dis +101 -0
- data/vendor/liblouis/tables/de-eurobrl6u.dis +96 -0
- data/vendor/liblouis/tables/de-g0-core.uti +732 -0
- data/vendor/liblouis/tables/de-g0-detailed.utb +84 -0
- data/vendor/liblouis/tables/de-g0.utb +57 -0
- data/vendor/liblouis/tables/de-g1-core-patterns.dic +4863 -0
- data/vendor/liblouis/tables/de-g1-core.cti +67 -0
- data/vendor/liblouis/tables/de-g1-detailed.ctb +79 -0
- data/vendor/liblouis/tables/de-g1.ctb +54 -0
- data/vendor/liblouis/tables/de-g2-core-patterns.dic +26711 -0
- data/vendor/liblouis/tables/de-g2-core.cti +607 -0
- data/vendor/liblouis/tables/de-g2-detailed.ctb +60 -0
- data/vendor/liblouis/tables/de-g2.ctb +57 -0
- data/vendor/liblouis/tables/devanagari.cti +325 -0
- data/vendor/liblouis/tables/digits6Dots.uti +30 -0
- data/vendor/liblouis/tables/digits6DotsPlusDot6.uti +30 -0
- data/vendor/liblouis/tables/digits8Dots.uti +30 -0
- data/vendor/liblouis/tables/dra.ctb +23 -0
- data/vendor/liblouis/tables/dra.tbl +21 -0
- data/vendor/liblouis/tables/el.ctb +775 -0
- data/vendor/liblouis/tables/en-GB-g2.ctb +829 -0
- data/vendor/liblouis/tables/en-chardefs.cti +193 -0
- data/vendor/liblouis/tables/en-chess.ctb +37 -0
- data/vendor/liblouis/tables/en-g3-patterns.dic +11194 -0
- data/vendor/liblouis/tables/en-g3.ctb +2261 -0
- data/vendor/liblouis/tables/en-gb-comp8.ctb +282 -0
- data/vendor/liblouis/tables/en-gb-g1.utb +527 -0
- data/vendor/liblouis/tables/en-in-g1.ctb +162 -0
- data/vendor/liblouis/tables/en-nabcc.utb +166 -0
- data/vendor/liblouis/tables/en-nz-g1.utb +65 -0
- data/vendor/liblouis/tables/en-nz-g2.ctb +46 -0
- data/vendor/liblouis/tables/en-ueb-chardefs.uti +938 -0
- data/vendor/liblouis/tables/en-ueb-g1.ctb +167 -0
- data/vendor/liblouis/tables/en-ueb-g2.ctb +3925 -0
- data/vendor/liblouis/tables/en-ueb-math.ctb +71 -0
- data/vendor/liblouis/tables/en-us-brf.dis +102 -0
- data/vendor/liblouis/tables/en-us-comp6.ctb +149 -0
- data/vendor/liblouis/tables/en-us-comp8-ext.utb +626 -0
- data/vendor/liblouis/tables/en-us-comp8.ctb +62 -0
- data/vendor/liblouis/tables/en-us-compbrl.uti +69 -0
- data/vendor/liblouis/tables/en-us-emphasis.uti +45 -0
- data/vendor/liblouis/tables/en-us-g1.ctb +199 -0
- data/vendor/liblouis/tables/en-us-g2.ctb +1081 -0
- data/vendor/liblouis/tables/en-us-interline.ctb +1126 -0
- data/vendor/liblouis/tables/en-us-mathtext.ctb +880 -0
- data/vendor/liblouis/tables/en_CA.ctb +195 -0
- data/vendor/liblouis/tables/en_CA.tbl +21 -0
- data/vendor/liblouis/tables/en_GB.tbl +26 -0
- data/vendor/liblouis/tables/en_US-comp8-ext.tbl +15 -0
- data/vendor/liblouis/tables/en_US.tbl +26 -0
- data/vendor/liblouis/tables/eo-g1-x-system.ctb +85 -0
- data/vendor/liblouis/tables/eo-g1.ctb +165 -0
- data/vendor/liblouis/tables/eo.tbl +14 -0
- data/vendor/liblouis/tables/es-chardefs.cti +206 -0
- data/vendor/liblouis/tables/es-g1.ctb +36 -0
- data/vendor/liblouis/tables/es-g2.ctb +955 -0
- data/vendor/liblouis/tables/es-new.dis +284 -0
- data/vendor/liblouis/tables/es-no.utb +79 -0
- data/vendor/liblouis/tables/es-old.dis +284 -0
- data/vendor/liblouis/tables/es.tbl +19 -0
- data/vendor/liblouis/tables/et-6dot.utb +269 -0
- data/vendor/liblouis/tables/et-g0.utb +139 -0
- data/vendor/liblouis/tables/ethio-g1.ctb +335 -0
- data/vendor/liblouis/tables/eurodefs.cti +107 -0
- data/vendor/liblouis/tables/fa-ir-comp8.ctb +250 -0
- data/vendor/liblouis/tables/fa-ir-g1.utb +311 -0
- data/vendor/liblouis/tables/fi-fi-8dot.ctb +278 -0
- data/vendor/liblouis/tables/fi.utb +354 -0
- data/vendor/liblouis/tables/fil-g2.ctb +491 -0
- data/vendor/liblouis/tables/fr-bfu-comp6-puncs-math.uti +351 -0
- data/vendor/liblouis/tables/fr-bfu-comp6.utb +238 -0
- data/vendor/liblouis/tables/fr-bfu-comp68.cti +251 -0
- data/vendor/liblouis/tables/fr-bfu-comp8.utb +323 -0
- data/vendor/liblouis/tables/fr-bfu-g2.ctb +4644 -0
- data/vendor/liblouis/tables/ga-g1.utb +95 -0
- data/vendor/liblouis/tables/ga-g2.ctb +231 -0
- data/vendor/liblouis/tables/gd.ctb +123 -0
- data/vendor/liblouis/tables/gd.tbl +21 -0
- data/vendor/liblouis/tables/gez.tbl +21 -0
- data/vendor/liblouis/tables/gon.ctb +25 -0
- data/vendor/liblouis/tables/gon.tbl +17 -0
- data/vendor/liblouis/tables/gr-pl-comp8.uti +256 -0
- data/vendor/liblouis/tables/grc-international-common.uti +104 -0
- data/vendor/liblouis/tables/grc-international-composed.uti +268 -0
- data/vendor/liblouis/tables/grc-international-decomposed.uti +268 -0
- data/vendor/liblouis/tables/grc-international-en-composed.utb +54 -0
- data/vendor/liblouis/tables/grc-international-en.utb +206 -0
- data/vendor/liblouis/tables/grc-international-es.utb +228 -0
- data/vendor/liblouis/tables/gu-in-g1.utb +27 -0
- data/vendor/liblouis/tables/gu.tbl +18 -0
- data/vendor/liblouis/tables/gujarati.cti +221 -0
- data/vendor/liblouis/tables/gurumuki.cti +393 -0
- data/vendor/liblouis/tables/haw-us-g1.ctb +54 -0
- data/vendor/liblouis/tables/hbo-cantillated-rules.uti +71 -0
- data/vendor/liblouis/tables/hbo-cantillated.utb +109 -0
- data/vendor/liblouis/tables/hbo-common-rules.uti +152 -0
- data/vendor/liblouis/tables/hbo-ihbc-rules.uti +58 -0
- data/vendor/liblouis/tables/hbo-slim-rules.uti +68 -0
- data/vendor/liblouis/tables/hbo-slim.utb +100 -0
- data/vendor/liblouis/tables/hbo.utb +107 -0
- data/vendor/liblouis/tables/he-IL-comp8.utb +464 -0
- data/vendor/liblouis/tables/he-IL.utb +406 -0
- data/vendor/liblouis/tables/he-common-consonants.uti +102 -0
- data/vendor/liblouis/tables/he-common-vowels-ihbc.uti +161 -0
- data/vendor/liblouis/tables/hi-in-g1.utb +27 -0
- data/vendor/liblouis/tables/hi.tbl +18 -0
- data/vendor/liblouis/tables/hr-chardefs.cti +278 -0
- data/vendor/liblouis/tables/hr-comp8.tbl +21 -0
- data/vendor/liblouis/tables/hr-comp8.utb +239 -0
- data/vendor/liblouis/tables/hr-digits.uti +40 -0
- data/vendor/liblouis/tables/hr-g1.ctb +36 -0
- data/vendor/liblouis/tables/hr-g1.tbl +9 -0
- data/vendor/liblouis/tables/hr-translation.cti +364 -0
- data/vendor/liblouis/tables/ht-frenchcompatibility.uti +61 -0
- data/vendor/liblouis/tables/ht-g1.utb +114 -0
- data/vendor/liblouis/tables/hu-backtranslate-correction.dis +38 -0
- data/vendor/liblouis/tables/hu-backtranslate-word-corrections.cti +4293 -0
- data/vendor/liblouis/tables/hu-chardefs.cti +298 -0
- data/vendor/liblouis/tables/hu-exceptionwords.cti +3204 -0
- data/vendor/liblouis/tables/hu-hu-comp8.ctb +183 -0
- data/vendor/liblouis/tables/hu-hu-g1.ctb +129 -0
- data/vendor/liblouis/tables/hu-hu-g1_braille_input.cti +486 -0
- data/vendor/liblouis/tables/hu-hu-g2.ctb +270 -0
- data/vendor/liblouis/tables/hu-hu-g2_exceptions.cti +1164 -0
- data/vendor/liblouis/tables/hy.ctb +121 -0
- data/vendor/liblouis/tables/hy.tbl +21 -0
- data/vendor/liblouis/tables/hyph_cs_CZ.dic +3637 -0
- data/vendor/liblouis/tables/hyph_da_DK.dic +8896 -0
- data/vendor/liblouis/tables/hyph_de_DE.dic +5799 -0
- data/vendor/liblouis/tables/hyph_en_US.dic +5537 -0
- data/vendor/liblouis/tables/hyph_eo.dic +1024 -0
- data/vendor/liblouis/tables/hyph_es_ES.dic +877 -0
- data/vendor/liblouis/tables/hyph_fr_FR.dic +1067 -0
- data/vendor/liblouis/tables/hyph_hu_HU.dic +98519 -0
- data/vendor/liblouis/tables/hyph_it_IT.dic +410 -0
- data/vendor/liblouis/tables/hyph_nb_NO.dic +27142 -0
- data/vendor/liblouis/tables/hyph_nl_NL.dic +12725 -0
- data/vendor/liblouis/tables/hyph_nn_NO.dic +27142 -0
- data/vendor/liblouis/tables/hyph_pl_PL.dic +4074 -0
- data/vendor/liblouis/tables/hyph_pt_PT.dic +308 -0
- data/vendor/liblouis/tables/hyph_ru.dic +6480 -0
- data/vendor/liblouis/tables/hyph_sv_SE.dic +4697 -0
- data/vendor/liblouis/tables/is-chardefs6.cti +170 -0
- data/vendor/liblouis/tables/is-chardefs8.cti +293 -0
- data/vendor/liblouis/tables/is.ctb +157 -0
- data/vendor/liblouis/tables/is.tbl +18 -0
- data/vendor/liblouis/tables/it-it-comp6.utb +404 -0
- data/vendor/liblouis/tables/it-it-comp8.utb +663 -0
- data/vendor/liblouis/tables/iu-ca-g1.ctb +236 -0
- data/vendor/liblouis/tables/ja-kantenji-ucs2.utb +11448 -0
- data/vendor/liblouis/tables/ja-kantenji.utb +53 -0
- data/vendor/liblouis/tables/ja-rokutenkanji.utb +8710 -0
- data/vendor/liblouis/tables/ka-in-g1.utb +27 -0
- data/vendor/liblouis/tables/ka.utb +128 -0
- data/vendor/liblouis/tables/kannada.cti +282 -0
- data/vendor/liblouis/tables/kh-in-g1.utb +26 -0
- data/vendor/liblouis/tables/kha.tbl +18 -0
- data/vendor/liblouis/tables/kk.utb +77 -0
- data/vendor/liblouis/tables/km-g1.utb +412 -0
- data/vendor/liblouis/tables/kmr.tbl +108 -0
- data/vendor/liblouis/tables/kn.tbl +18 -0
- data/vendor/liblouis/tables/ko-2006-g1.ctb +49 -0
- data/vendor/liblouis/tables/ko-2006-g2.ctb +53 -0
- data/vendor/liblouis/tables/ko-2006.cti +190 -0
- data/vendor/liblouis/tables/ko-chars.cti +15140 -0
- data/vendor/liblouis/tables/ko-g1-rules.cti +634 -0
- data/vendor/liblouis/tables/ko-g1.ctb +48 -0
- data/vendor/liblouis/tables/ko-g2-rules.cti +9263 -0
- data/vendor/liblouis/tables/ko-g2.ctb +52 -0
- data/vendor/liblouis/tables/ko.cti +223 -0
- data/vendor/liblouis/tables/kok.ctb +24 -0
- data/vendor/liblouis/tables/kok.tbl +17 -0
- data/vendor/liblouis/tables/kru.ctb +24 -0
- data/vendor/liblouis/tables/kru.tbl +17 -0
- data/vendor/liblouis/tables/ks-in-g1.utb +27 -0
- data/vendor/liblouis/tables/latinLetterDef6Dots.uti +78 -0
- data/vendor/liblouis/tables/latinLetterDef8Dots.uti +75 -0
- data/vendor/liblouis/tables/latinLowercase.uti +389 -0
- data/vendor/liblouis/tables/latinUppercaseComp6.uti +78 -0
- data/vendor/liblouis/tables/lg-ug-g1.utb +60 -0
- data/vendor/liblouis/tables/litdigits6Dots.uti +30 -0
- data/vendor/liblouis/tables/litdigits6DotsPlusDot6.uti +30 -0
- data/vendor/liblouis/tables/lo-g1.utb +3127 -0
- data/vendor/liblouis/tables/loweredDigits6Dots.uti +30 -0
- data/vendor/liblouis/tables/loweredDigits8Dots.uti +30 -0
- data/vendor/liblouis/tables/lt-6dot.utb +308 -0
- data/vendor/liblouis/tables/lt-8dot.utb +281 -0
- data/vendor/liblouis/tables/lt.ctb +313 -0
- data/vendor/liblouis/tables/lv.tbl +22 -0
- data/vendor/liblouis/tables/maketablelist.sh +52 -0
- data/vendor/liblouis/tables/malayalam.cti +674 -0
- data/vendor/liblouis/tables/mao-nz-g1.ctb +65 -0
- data/vendor/liblouis/tables/marburg_single_cell_defs.cti +66 -0
- data/vendor/liblouis/tables/marburg_unicode_defs.cti +297 -0
- data/vendor/liblouis/tables/mk-g1.utb +240 -0
- data/vendor/liblouis/tables/ml-in-g1.utb +27 -0
- data/vendor/liblouis/tables/ml.tbl +21 -0
- data/vendor/liblouis/tables/mn-MN-common.cti +110 -0
- data/vendor/liblouis/tables/mn-MN-g1.utb +52 -0
- data/vendor/liblouis/tables/mn-MN-g2.ctb +50 -0
- data/vendor/liblouis/tables/mn-in-g1.utb +27 -0
- data/vendor/liblouis/tables/mni.tbl +18 -0
- data/vendor/liblouis/tables/mr-in-g1.utb +27 -0
- data/vendor/liblouis/tables/mr.tbl +18 -0
- data/vendor/liblouis/tables/ms-my-g2.ctb +4897 -0
- data/vendor/liblouis/tables/mt.ctb +114 -0
- data/vendor/liblouis/tables/mt.tbl +21 -0
- data/vendor/liblouis/tables/mun.ctb +24 -0
- data/vendor/liblouis/tables/mun.tbl +17 -0
- data/vendor/liblouis/tables/mwr.ctb +24 -0
- data/vendor/liblouis/tables/mwr.tbl +17 -0
- data/vendor/liblouis/tables/my-g1.utb +771 -0
- data/vendor/liblouis/tables/my-g2.ctb +3805 -0
- data/vendor/liblouis/tables/ne.ctb +22 -0
- data/vendor/liblouis/tables/ne.tbl +18 -0
- data/vendor/liblouis/tables/nemethdefs.cti +382 -0
- data/vendor/liblouis/tables/nl-BE.dis +532 -0
- data/vendor/liblouis/tables/nl-NL-g0.utb.in +646 -0
- data/vendor/liblouis/tables/nl-chardefs.uti.in +455 -0
- data/vendor/liblouis/tables/nl-comp8.utb +411 -0
- data/vendor/liblouis/tables/nl-print.dis +551 -0
- data/vendor/liblouis/tables/nl-unicode.dis +540 -0
- data/vendor/liblouis/tables/no-no-8dot-fallback-6dot-g0.utb +59 -0
- data/vendor/liblouis/tables/no-no-8dot.utb +629 -0
- data/vendor/liblouis/tables/no-no-braillo-047-01.dis +247 -0
- data/vendor/liblouis/tables/no-no-chardefs6.uti +305 -0
- data/vendor/liblouis/tables/no-no-comp8.ctb +323 -0
- data/vendor/liblouis/tables/no-no-cyrillic6dot.uti +95 -0
- data/vendor/liblouis/tables/no-no-g0.utb +320 -0
- data/vendor/liblouis/tables/no-no-g1.ctb +272 -0
- data/vendor/liblouis/tables/no-no-g2.ctb +737 -0
- data/vendor/liblouis/tables/no-no-g3.ctb +3597 -0
- data/vendor/liblouis/tables/no-no-generic.ctb +295 -0
- data/vendor/liblouis/tables/no-no-generic.dis +295 -0
- data/vendor/liblouis/tables/no-no-latinLetterDef6Dots_diacritics.uti +852 -0
- data/vendor/liblouis/tables/no-no.dis +291 -0
- data/vendor/liblouis/tables/np-in-g1.utb +27 -0
- data/vendor/liblouis/tables/nso-za-g1.utb +38 -0
- data/vendor/liblouis/tables/nso-za-g2.ctb +38 -0
- data/vendor/liblouis/tables/ny-mw.utb +70 -0
- data/vendor/liblouis/tables/or-in-g1.utb +27 -0
- data/vendor/liblouis/tables/or.tbl +18 -0
- data/vendor/liblouis/tables/oriya.cti +238 -0
- data/vendor/liblouis/tables/ovd-6g0.utb +64 -0
- data/vendor/liblouis/tables/ovd-8g0.utb +81 -0
- data/vendor/liblouis/tables/pa.tbl +18 -0
- data/vendor/liblouis/tables/pi.ctb +24 -0
- data/vendor/liblouis/tables/pi.tbl +17 -0
- data/vendor/liblouis/tables/pl-pl-comp8.ctb +658 -0
- data/vendor/liblouis/tables/pl.tbl +12 -0
- data/vendor/liblouis/tables/printables.cti +70 -0
- data/vendor/liblouis/tables/pt-comp6.utb +299 -0
- data/vendor/liblouis/tables/pt-pt-comp8.ctb +395 -0
- data/vendor/liblouis/tables/pt-pt-g1.utb +1312 -0
- data/vendor/liblouis/tables/pt-pt-g2.ctb +874 -0
- data/vendor/liblouis/tables/pt.tbl +20 -0
- data/vendor/liblouis/tables/pu-in-g1.utb +42 -0
- data/vendor/liblouis/tables/quotation-marks.uti +30 -0
- data/vendor/liblouis/tables/ro-g0.utb +85 -0
- data/vendor/liblouis/tables/ro.ctb +126 -0
- data/vendor/liblouis/tables/ro.tbl +21 -0
- data/vendor/liblouis/tables/ru-brf.dis +116 -0
- data/vendor/liblouis/tables/ru-comp6.utb +258 -0
- data/vendor/liblouis/tables/ru-comp8.utb +740 -0
- data/vendor/liblouis/tables/ru-letters.dis +145 -0
- data/vendor/liblouis/tables/ru-litbrl-detailed.utb +77 -0
- data/vendor/liblouis/tables/ru-litbrl.ctb +857 -0
- data/vendor/liblouis/tables/ru-math.uti +395 -0
- data/vendor/liblouis/tables/ru-ru-g1.ctb +804 -0
- data/vendor/liblouis/tables/ru-unicode.dis +121 -0
- data/vendor/liblouis/tables/rw-rw-g1.utb +133 -0
- data/vendor/liblouis/tables/sa-in-g1.utb +27 -0
- data/vendor/liblouis/tables/sa.tbl +18 -0
- data/vendor/liblouis/tables/sah.utb +72 -0
- data/vendor/liblouis/tables/sd.tbl +18 -0
- data/vendor/liblouis/tables/se-se.ctb +246 -0
- data/vendor/liblouis/tables/se-se.dis +334 -0
- data/vendor/liblouis/tables/si-in-g1.utb +27 -0
- data/vendor/liblouis/tables/sin.cti +213 -0
- data/vendor/liblouis/tables/sin.utb +35 -0
- data/vendor/liblouis/tables/sk-g1.ctb +1019 -0
- data/vendor/liblouis/tables/sk-sk-g1.utb +206 -0
- data/vendor/liblouis/tables/sk-sk.utb +112 -0
- data/vendor/liblouis/tables/sl-si-comp8.ctb +204 -0
- data/vendor/liblouis/tables/sl-si-g1.utb +471 -0
- data/vendor/liblouis/tables/sl.tbl +20 -0
- data/vendor/liblouis/tables/smi-6g0.utb +64 -0
- data/vendor/liblouis/tables/smi-8g0.utb +61 -0
- data/vendor/liblouis/tables/sot-za-g1.ctb +72 -0
- data/vendor/liblouis/tables/sot-za-g2.ctb +244 -0
- data/vendor/liblouis/tables/spaces.uti +62 -0
- data/vendor/liblouis/tables/sr-Cyrl.ctb +59 -0
- data/vendor/liblouis/tables/sr-common.cti +161 -0
- data/vendor/liblouis/tables/sr-cyrletters.cti +92 -0
- data/vendor/liblouis/tables/sr-g1.ctb +57 -0
- data/vendor/liblouis/tables/sr-latletters.cti +45 -0
- data/vendor/liblouis/tables/sv-1989.ctb +241 -0
- data/vendor/liblouis/tables/sv-1996.ctb +180 -0
- data/vendor/liblouis/tables/sv-6common.uti +1199 -0
- data/vendor/liblouis/tables/sv-6g0d.utb +508 -0
- data/vendor/liblouis/tables/sv-6g0p.utb +61 -0
- data/vendor/liblouis/tables/sv-6g1.uti +106 -0
- data/vendor/liblouis/tables/sv-6g1d.ctb +57 -0
- data/vendor/liblouis/tables/sv-6g2.uti +254 -0
- data/vendor/liblouis/tables/sv-6g2d.ctb +57 -0
- data/vendor/liblouis/tables/sv-8g0d.utb +495 -0
- data/vendor/liblouis/tables/sv-8g0n.utb +1236 -0
- data/vendor/liblouis/tables/sv-8g1.uti +199 -0
- data/vendor/liblouis/tables/sv-8g1d.ctb +73 -0
- data/vendor/liblouis/tables/sv-8g1n.ctb +73 -0
- data/vendor/liblouis/tables/sv-8g2.uti +486 -0
- data/vendor/liblouis/tables/sv-8g2d.ctb +73 -0
- data/vendor/liblouis/tables/sv-8g2n.ctb +73 -0
- data/vendor/liblouis/tables/sv-g0.utb +65 -0
- data/vendor/liblouis/tables/sv-g1.ctb +57 -0
- data/vendor/liblouis/tables/sv-g2.ctb +57 -0
- data/vendor/liblouis/tables/sv-phon.uti +241 -0
- data/vendor/liblouis/tables/sw-ke-g1-2.ctb +90 -0
- data/vendor/liblouis/tables/sw-ke-g1-3.ctb +109 -0
- data/vendor/liblouis/tables/sw-ke-g1-4.ctb +107 -0
- data/vendor/liblouis/tables/sw-ke-g1-5.ctb +73 -0
- data/vendor/liblouis/tables/sw-ke-g1.utb +278 -0
- data/vendor/liblouis/tables/sw-ke-g2.ctb +276 -0
- data/vendor/liblouis/tables/syc.utb +195 -0
- data/vendor/liblouis/tables/ta-ta-g1.ctb +167 -0
- data/vendor/liblouis/tables/ta.ctb +24 -0
- data/vendor/liblouis/tables/ta.tbl +21 -0
- data/vendor/liblouis/tables/tamil.cti +86 -0
- data/vendor/liblouis/tables/te-in-g1.utb +27 -0
- data/vendor/liblouis/tables/te.tbl +18 -0
- data/vendor/liblouis/tables/telugu.cti +239 -0
- data/vendor/liblouis/tables/text_nabcc.dis +426 -0
- data/vendor/liblouis/tables/th-comp8-backward.utb +226 -0
- data/vendor/liblouis/tables/th-g0.utb +177 -0
- data/vendor/liblouis/tables/th-g1.utb +89 -0
- data/vendor/liblouis/tables/th-g1.uti +315 -0
- data/vendor/liblouis/tables/th-g2.ctb +616 -0
- data/vendor/liblouis/tables/tr-g1.ctb +254 -0
- data/vendor/liblouis/tables/tr-g2.ctb +863 -0
- data/vendor/liblouis/tables/tr-g2.tbl +20 -0
- data/vendor/liblouis/tables/tr.ctb +324 -0
- data/vendor/liblouis/tables/tr.tbl +21 -0
- data/vendor/liblouis/tables/tsn-za-g1.ctb +33 -0
- data/vendor/liblouis/tables/tsn-za-g2.ctb +33 -0
- data/vendor/liblouis/tables/tt.utb +74 -0
- data/vendor/liblouis/tables/uga.utb +86 -0
- data/vendor/liblouis/tables/uk-comp.utb +53 -0
- data/vendor/liblouis/tables/uk-detailed.utb +32 -0
- data/vendor/liblouis/tables/uk.utb +101 -0
- data/vendor/liblouis/tables/ukchardefs.cti +106 -0
- data/vendor/liblouis/tables/ukmaths_single_cell_defs.cti +65 -0
- data/vendor/liblouis/tables/ukmaths_unicode_defs.cti +298 -0
- data/vendor/liblouis/tables/uni-text.dis +330 -0
- data/vendor/liblouis/tables/unicode-braille.utb +291 -0
- data/vendor/liblouis/tables/unicode-without-blank.dis +24 -0
- data/vendor/liblouis/tables/unicode.dis +278 -0
- data/vendor/liblouis/tables/ur-pk-g1.utb +248 -0
- data/vendor/liblouis/tables/ur-pk-g2.ctb +641 -0
- data/vendor/liblouis/tables/us-table.dis +67 -0
- data/vendor/liblouis/tables/uz-g1.utb +117 -0
- data/vendor/liblouis/tables/ve-za-g1.utb +69 -0
- data/vendor/liblouis/tables/ve-za-g2.ctb +208 -0
- data/vendor/liblouis/tables/vi-cb8.utb +49 -0
- data/vendor/liblouis/tables/vi-charsdef.uti +36 -0
- data/vendor/liblouis/tables/vi-lettersdef.uti +401 -0
- data/vendor/liblouis/tables/vi-puncsdef.uti +446 -0
- data/vendor/liblouis/tables/vi-saigon-g1.ctb +530 -0
- data/vendor/liblouis/tables/vi-vn-g0.utb +135 -0
- data/vendor/liblouis/tables/vi-vn-g1.ctb +574 -0
- data/vendor/liblouis/tables/vi-vn-g2.ctb +743 -0
- data/vendor/liblouis/tables/wiskunde-chardefs.cti +261 -0
- data/vendor/liblouis/tables/wordcx.dis +91 -0
- data/vendor/liblouis/tables/xh-za-g1.utb +61 -0
- data/vendor/liblouis/tables/xh-za-g2.ctb +386 -0
- data/vendor/liblouis/tables/yi.utb +236 -0
- data/vendor/liblouis/tables/zh-chn.ctb +45011 -0
- data/vendor/liblouis/tables/zh-hk.ctb +10461 -0
- data/vendor/liblouis/tables/zh-tw.ctb +53810 -0
- data/vendor/liblouis/tables/zh_CHN.tbl +23 -0
- data/vendor/liblouis/tables/zhcn-cbs.ctb +31523 -0
- data/vendor/liblouis/tables/zhcn-g1.ctb +26523 -0
- data/vendor/liblouis/tables/zhcn-g2.ctb +26519 -0
- data/vendor/liblouis/tables/zu-za-g1.utb +33 -0
- data/vendor/liblouis/tables/zu-za-g2.ctb +33 -0
- metadata +558 -0
|
@@ -0,0 +1,1258 @@
|
|
|
1
|
+
/* liblouis Braille Translation and Back-Translation Library
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2015 Bert Frees <bertfrees@gmail.com>
|
|
4
|
+
|
|
5
|
+
This file is part of liblouis.
|
|
6
|
+
|
|
7
|
+
liblouis is free software: you can redistribute it and/or modify it
|
|
8
|
+
under the terms of the GNU Lesser General Public License as published
|
|
9
|
+
by the Free Software Foundation, either version 2.1 of the License, or
|
|
10
|
+
(at your option) any later version.
|
|
11
|
+
|
|
12
|
+
liblouis is distributed in the hope that it will be useful, but
|
|
13
|
+
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 liblouis. If not, see <http://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @file
|
|
23
|
+
* @brief Find translation tables
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include "config.h"
|
|
27
|
+
|
|
28
|
+
#include <stdlib.h>
|
|
29
|
+
#include <string.h>
|
|
30
|
+
#ifndef _MSC_VER
|
|
31
|
+
#include <strings.h> /* for strcasecmp/strncasecmp; on MSVC these are shimmed in internal.h */
|
|
32
|
+
#endif
|
|
33
|
+
#if defined(_MSC_VER) || defined(_WIN32)
|
|
34
|
+
#include <windows.h>
|
|
35
|
+
#else
|
|
36
|
+
#include <dirent.h>
|
|
37
|
+
#endif
|
|
38
|
+
#include <sys/stat.h>
|
|
39
|
+
#include "internal.h"
|
|
40
|
+
|
|
41
|
+
/* =============================== LIST =================================== */
|
|
42
|
+
|
|
43
|
+
typedef struct List {
|
|
44
|
+
void *head;
|
|
45
|
+
void (*free)(void *); // free head
|
|
46
|
+
void *(*dup)(void *); // dup head
|
|
47
|
+
struct List *tail;
|
|
48
|
+
} List;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Returns a list with the element `x' added to `list'. Returns a sorted list
|
|
52
|
+
* if `cmp' is not NULL and if `list' is also sorted. New elements replace
|
|
53
|
+
* existing ones if they are equal according to `cmp'. If `cmp' is NULL,
|
|
54
|
+
* elements are simply prepended to the list. The function `dup' is used to
|
|
55
|
+
* duplicate elements when the list is copied. The `free' function is used to
|
|
56
|
+
* free elements when they are removed from the list. The returned list must
|
|
57
|
+
* be freed by the caller, using list_free.
|
|
58
|
+
*/
|
|
59
|
+
static List *
|
|
60
|
+
list_conj(List *list, void *x, int (*cmp)(void *, void *), void *(*dup)(void *),
|
|
61
|
+
void (*free)(void *)) {
|
|
62
|
+
if (!list) {
|
|
63
|
+
list = malloc(sizeof(List));
|
|
64
|
+
list->head = x;
|
|
65
|
+
list->free = free;
|
|
66
|
+
list->dup = dup;
|
|
67
|
+
list->tail = NULL;
|
|
68
|
+
return list;
|
|
69
|
+
} else if (!cmp) {
|
|
70
|
+
List *l = malloc(sizeof(List));
|
|
71
|
+
l->head = x;
|
|
72
|
+
l->free = free;
|
|
73
|
+
l->dup = dup;
|
|
74
|
+
l->tail = list;
|
|
75
|
+
return l;
|
|
76
|
+
} else {
|
|
77
|
+
List *l1 = list;
|
|
78
|
+
List *l2 = NULL;
|
|
79
|
+
while (l1) {
|
|
80
|
+
int c = cmp(l1->head, x);
|
|
81
|
+
if (c > 0)
|
|
82
|
+
break;
|
|
83
|
+
else if (c < 0) {
|
|
84
|
+
l2 = l1;
|
|
85
|
+
l1 = l2->tail;
|
|
86
|
+
} else {
|
|
87
|
+
if (x != l1->head && !dup && free) free(x);
|
|
88
|
+
return list;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
List *l3 = malloc(sizeof(List));
|
|
92
|
+
l3->head = x;
|
|
93
|
+
l3->free = free;
|
|
94
|
+
l3->dup = dup;
|
|
95
|
+
l3->tail = l1;
|
|
96
|
+
if (!l2)
|
|
97
|
+
list = l3;
|
|
98
|
+
else
|
|
99
|
+
l2->tail = l3;
|
|
100
|
+
return list;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Free an instance of type List.
|
|
106
|
+
*/
|
|
107
|
+
static void
|
|
108
|
+
list_free(List *list) {
|
|
109
|
+
if (list) {
|
|
110
|
+
if (list->free) list->free(list->head);
|
|
111
|
+
list_free(list->tail);
|
|
112
|
+
free(list);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Adapters so that list_free/list_dup can be used as generic List/Feature
|
|
118
|
+
* callbacks (which are typed `void (*)(void *)' / `void *(*)(void *)') without
|
|
119
|
+
* calling through an incompatibly-typed function pointer, which is undefined
|
|
120
|
+
* behaviour.
|
|
121
|
+
*/
|
|
122
|
+
static void
|
|
123
|
+
list_free_(void *v) {
|
|
124
|
+
list_free(v);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Duplicate an instance of type List.
|
|
129
|
+
*/
|
|
130
|
+
static List *
|
|
131
|
+
list_dup(List *list) {
|
|
132
|
+
if (!list) return list;
|
|
133
|
+
List *d = malloc(sizeof(List));
|
|
134
|
+
d->head = list->dup ? list->dup(list->head) : list->head;
|
|
135
|
+
d->free = list->free;
|
|
136
|
+
d->dup = list->dup;
|
|
137
|
+
d->tail = list_dup(list->tail);
|
|
138
|
+
return d;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Adapter, see list_free_/list_dup_ above.
|
|
143
|
+
*/
|
|
144
|
+
static void *
|
|
145
|
+
list_dup_(void *v) {
|
|
146
|
+
return list_dup(v);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Adapter so that strdup can be used as a generic List/Feature dup callback
|
|
151
|
+
* (typed `void *(*)(void *)') without calling through an incompatibly-typed
|
|
152
|
+
* function pointer, which is undefined behaviour.
|
|
153
|
+
*/
|
|
154
|
+
static void *
|
|
155
|
+
strdup_(void *s) {
|
|
156
|
+
return strdup(s);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Sort a list based on a comparison function.
|
|
161
|
+
*
|
|
162
|
+
* This function returns a new list, however the input list should not be used after the
|
|
163
|
+
* returned list is freed as the elements are not copied.
|
|
164
|
+
*/
|
|
165
|
+
static List *
|
|
166
|
+
list_sort(List *list, int (*cmp)(void *, void *)) {
|
|
167
|
+
List *newList = NULL;
|
|
168
|
+
List *l;
|
|
169
|
+
for (l = list; l; l = l->tail) {
|
|
170
|
+
newList = list_conj(newList, l->head, cmp, NULL, l->free);
|
|
171
|
+
l->free = NULL;
|
|
172
|
+
}
|
|
173
|
+
list_free(list);
|
|
174
|
+
return newList;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Get the size of a list.
|
|
179
|
+
*/
|
|
180
|
+
static int
|
|
181
|
+
list_size(List *list) {
|
|
182
|
+
int len = 0;
|
|
183
|
+
List *l;
|
|
184
|
+
for (l = list; l; l = l->tail) len++;
|
|
185
|
+
return len;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Convert a list into a NULL terminated array.
|
|
190
|
+
*/
|
|
191
|
+
static void **
|
|
192
|
+
list_toArray(List *list, int deepCopy) {
|
|
193
|
+
void **array;
|
|
194
|
+
List *l;
|
|
195
|
+
int i;
|
|
196
|
+
array = malloc((1 + list_size(list)) * sizeof(void *));
|
|
197
|
+
i = 0;
|
|
198
|
+
for (l = list; l; l = l->tail)
|
|
199
|
+
array[i++] = deepCopy && l->dup ? l->dup(l->head) : l->head;
|
|
200
|
+
array[i] = NULL;
|
|
201
|
+
return array;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/* ============================== FEATURE ================================= */
|
|
205
|
+
|
|
206
|
+
typedef struct {
|
|
207
|
+
char *key;
|
|
208
|
+
void *val;
|
|
209
|
+
void (*free)(void *); // free val
|
|
210
|
+
void *(*dup)(void *); // dup val
|
|
211
|
+
} Feature;
|
|
212
|
+
|
|
213
|
+
typedef struct {
|
|
214
|
+
Feature feature;
|
|
215
|
+
int importance;
|
|
216
|
+
} FeatureWithImportance;
|
|
217
|
+
|
|
218
|
+
typedef struct {
|
|
219
|
+
Feature feature;
|
|
220
|
+
int lineNumber; // no line number (-1) means it is a default value
|
|
221
|
+
} FeatureWithLineNumber;
|
|
222
|
+
|
|
223
|
+
typedef struct {
|
|
224
|
+
char *name;
|
|
225
|
+
List *features;
|
|
226
|
+
} TableMeta;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Create an instance of type Feature.
|
|
230
|
+
*
|
|
231
|
+
* The returned instance must be freed by the caller, using feat_free. The `key' string is
|
|
232
|
+
* freed in feat_free and copied in feat_dup. What happens with `val' is determined by the
|
|
233
|
+
* `dup' and `free' arguments.
|
|
234
|
+
*/
|
|
235
|
+
static Feature
|
|
236
|
+
feat_new(char *key, void *val, void *(*dup)(void *), void (*free)(void *)) {
|
|
237
|
+
Feature f;
|
|
238
|
+
f.key = key;
|
|
239
|
+
f.val = val;
|
|
240
|
+
f.dup = dup;
|
|
241
|
+
f.free = free;
|
|
242
|
+
return f;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Free an instance of type Feature.
|
|
247
|
+
*/
|
|
248
|
+
static void
|
|
249
|
+
feat_free(Feature *f) {
|
|
250
|
+
if (f) {
|
|
251
|
+
free(f->key);
|
|
252
|
+
if (f->free) f->free(f->val);
|
|
253
|
+
free(f);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Adapters, see list_free_/list_dup_ above.
|
|
259
|
+
*/
|
|
260
|
+
static void
|
|
261
|
+
feat_free_(void *v) {
|
|
262
|
+
feat_free(v);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Duplicate an instance of type Feature.
|
|
267
|
+
*/
|
|
268
|
+
static Feature *
|
|
269
|
+
feat_dup(Feature *f) {
|
|
270
|
+
if (!f) return NULL;
|
|
271
|
+
Feature *d = malloc(sizeof(Feature));
|
|
272
|
+
d->key = strdup(f->key);
|
|
273
|
+
d->val = f->dup ? f->dup(f->val) : f->val;
|
|
274
|
+
d->free = f->free;
|
|
275
|
+
d->dup = f->dup;
|
|
276
|
+
return d;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Adapter, see list_free_/list_dup_ above.
|
|
281
|
+
*/
|
|
282
|
+
static void *
|
|
283
|
+
feat_dup_(void *v) {
|
|
284
|
+
return feat_dup(v);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Free an instance of type TableMeta.
|
|
289
|
+
*
|
|
290
|
+
* Both `name' string and `features' list are freed.
|
|
291
|
+
*/
|
|
292
|
+
static void
|
|
293
|
+
meta_free(TableMeta *m) {
|
|
294
|
+
if (m) {
|
|
295
|
+
free(m->name);
|
|
296
|
+
list_free(m->features);
|
|
297
|
+
free(m);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Adapter, see list_free_/list_dup_ above.
|
|
303
|
+
*/
|
|
304
|
+
static void
|
|
305
|
+
meta_free_(void *v) {
|
|
306
|
+
meta_free(v);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/* =========================== LANGUAGE TAGS ============================== */
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Return true if the tag we're parsing is a language tag (language, region or
|
|
313
|
+
* locale).
|
|
314
|
+
*/
|
|
315
|
+
static int
|
|
316
|
+
isLanguageTag(const char *key, int len) {
|
|
317
|
+
return strncasecmp("language", key, len) == 0 ||
|
|
318
|
+
strncasecmp("region", key, len) == 0 || strncasecmp("locale", key, len) == 0;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
static int
|
|
322
|
+
isAlpha(char c) {
|
|
323
|
+
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
static int
|
|
327
|
+
isAlphaNum(char c) {
|
|
328
|
+
return (c >= '0' && c <= '9') || isAlpha(c);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Parse language tag into a list of subtags.
|
|
333
|
+
*
|
|
334
|
+
* The returned list must be freed by the caller, using list_free.
|
|
335
|
+
*/
|
|
336
|
+
static List *
|
|
337
|
+
parseLanguageTag(const char *val) {
|
|
338
|
+
List *list = NULL;
|
|
339
|
+
List **tail = &list;
|
|
340
|
+
static char subtag[9];
|
|
341
|
+
if (!*val) return NULL;
|
|
342
|
+
if (val[0] == '*') {
|
|
343
|
+
if (val[1] && val[1] != '-') return NULL;
|
|
344
|
+
*subtag = '\0';
|
|
345
|
+
strncat(subtag, val, 1);
|
|
346
|
+
*tail = list_conj(NULL, strdup(subtag), NULL, strdup_, free);
|
|
347
|
+
tail = &(*tail)->tail;
|
|
348
|
+
if (!val[1]) return list;
|
|
349
|
+
val = &val[2];
|
|
350
|
+
}
|
|
351
|
+
while (1) {
|
|
352
|
+
int len = 0;
|
|
353
|
+
for (; len <= 8; len++)
|
|
354
|
+
if (!val[len] || !isAlphaNum(val[len]) || (!list && !isAlpha(val[len])))
|
|
355
|
+
break;
|
|
356
|
+
if (len < 1 || len > 8 || (val[len] && val[len] != '-')) {
|
|
357
|
+
list_free(list);
|
|
358
|
+
return NULL;
|
|
359
|
+
}
|
|
360
|
+
*subtag = '\0';
|
|
361
|
+
strncat(subtag, val, len);
|
|
362
|
+
*tail = list_conj(NULL, strdup(subtag), NULL, strdup_, free);
|
|
363
|
+
tail = &(*tail)->tail;
|
|
364
|
+
if (!val[len]) return list;
|
|
365
|
+
val = &val[len + 1];
|
|
366
|
+
}
|
|
367
|
+
return NULL;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Serialize language tag.
|
|
372
|
+
*
|
|
373
|
+
* The returned string must be freed by the caller.
|
|
374
|
+
*/
|
|
375
|
+
static char *
|
|
376
|
+
serializeLanguageTag(const List *tag) {
|
|
377
|
+
int len = 0;
|
|
378
|
+
const List *l;
|
|
379
|
+
for (l = tag; l; l = l->tail) len = len + 1 + strlen(l->head);
|
|
380
|
+
char *s = malloc(len * sizeof(char));
|
|
381
|
+
s[0] = '\0';
|
|
382
|
+
for (l = tag; l; l = l->tail) {
|
|
383
|
+
if (l != tag) s = strcat(s, "-");
|
|
384
|
+
s = strcat(s, l->head);
|
|
385
|
+
}
|
|
386
|
+
return s;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/* ======================================================================== */
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Sort features by their key (alphabetical order).
|
|
393
|
+
*/
|
|
394
|
+
static int
|
|
395
|
+
cmpKeys(Feature *f1, Feature *f2) {
|
|
396
|
+
return strcasecmp(f1->key, f2->key);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Adapter, see list_free_/list_dup_ above.
|
|
401
|
+
*/
|
|
402
|
+
static int
|
|
403
|
+
cmpKeys_(void *v1, void *v2) {
|
|
404
|
+
return cmpKeys(v1, v2);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Sort features by their key and value (alphabetical order).
|
|
409
|
+
*/
|
|
410
|
+
static int
|
|
411
|
+
cmpFeatures(Feature *f1, Feature *f2) {
|
|
412
|
+
int r = strcasecmp(f1->key, f2->key);
|
|
413
|
+
if (r != 0) return r;
|
|
414
|
+
if (isLanguageTag(f1->key, MAXSTRING)) {
|
|
415
|
+
List *l1 = f1->val;
|
|
416
|
+
List *l2 = f2->val;
|
|
417
|
+
while (l1 && l2) {
|
|
418
|
+
r = strcasecmp(l1->head, l2->head);
|
|
419
|
+
if (r != 0) return r;
|
|
420
|
+
l1 = l1->tail;
|
|
421
|
+
l2 = l2->tail;
|
|
422
|
+
}
|
|
423
|
+
return l1 ? 1 : l2 ? -1 : 0;
|
|
424
|
+
} else
|
|
425
|
+
return strcasecmp(f1->val, f2->val);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Adapter, see list_free_/list_dup_ above.
|
|
430
|
+
*/
|
|
431
|
+
static int
|
|
432
|
+
cmpFeatures_(void *v1, void *v2) {
|
|
433
|
+
return cmpFeatures(v1, v2);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Return a positive number if the given language tag matches the language range,
|
|
438
|
+
* 0 otherwise.
|
|
439
|
+
*
|
|
440
|
+
* In case of a perfect match, return 10. Otherwise, for each extra subtag that
|
|
441
|
+
* has no exact match in the range, subtract two.
|
|
442
|
+
*
|
|
443
|
+
* See also <https://datatracker.ietf.org/doc/html/rfc4647#section-3.3.2>
|
|
444
|
+
*/
|
|
445
|
+
static int
|
|
446
|
+
matchLanguageTags(const List *tag, const List *range) {
|
|
447
|
+
static const int POS_MATCH = 10;
|
|
448
|
+
static const int EXTRA = -2;
|
|
449
|
+
int q = POS_MATCH;
|
|
450
|
+
if (*((char *)range->head) == '*')
|
|
451
|
+
q += EXTRA;
|
|
452
|
+
else if (strcasecmp(tag->head, range->head) != 0)
|
|
453
|
+
return 0;
|
|
454
|
+
range = range->tail;
|
|
455
|
+
tag = tag->tail;
|
|
456
|
+
while (range) {
|
|
457
|
+
if (!tag) return 0;
|
|
458
|
+
if (strcasecmp(tag->head, range->head) == 0) {
|
|
459
|
+
range = range->tail;
|
|
460
|
+
tag = tag->tail;
|
|
461
|
+
continue;
|
|
462
|
+
} else if (strlen(tag->head) == 1)
|
|
463
|
+
return 0;
|
|
464
|
+
else
|
|
465
|
+
q += EXTRA;
|
|
466
|
+
tag = tag->tail;
|
|
467
|
+
}
|
|
468
|
+
while (tag) {
|
|
469
|
+
q += EXTRA;
|
|
470
|
+
tag = tag->tail;
|
|
471
|
+
}
|
|
472
|
+
return q;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Compute the match quotient of the features in a query against the features in a table's
|
|
477
|
+
* metadata.
|
|
478
|
+
*
|
|
479
|
+
* The features are assumed to be sorted. The query's features must be
|
|
480
|
+
* of type FeatureWithImportance and are assumed to have no duplicate
|
|
481
|
+
* keys. How a feature contributes to the match quotient depends on
|
|
482
|
+
* its importance, on whether the feature is undefined, defined with
|
|
483
|
+
* the same value (positive match), or defined with a different value
|
|
484
|
+
* (negative match), and on the `fuzzy' argument. If the `fuzzy'
|
|
485
|
+
* argument evaluates to true, negative matches and undefined features
|
|
486
|
+
* get a lower penalty.
|
|
487
|
+
*/
|
|
488
|
+
static int
|
|
489
|
+
matchFeatureLists(const List *query, const List *tableFeatures, int fuzzy) {
|
|
490
|
+
static const int POS_MATCH = 10;
|
|
491
|
+
static const int NEG_MATCH = -100;
|
|
492
|
+
static const int UNDEFINED = -20;
|
|
493
|
+
static const int EXTRA = -1;
|
|
494
|
+
static const int POS_MATCH_FUZZY = 10;
|
|
495
|
+
static const int NEG_MATCH_FUZZY = -25;
|
|
496
|
+
static const int UNDEFINED_FUZZY = -5;
|
|
497
|
+
static const int EXTRA_FUZZY = -1;
|
|
498
|
+
int posMatch, negMatch, undefined, extra;
|
|
499
|
+
if (!fuzzy) {
|
|
500
|
+
posMatch = POS_MATCH;
|
|
501
|
+
negMatch = NEG_MATCH;
|
|
502
|
+
undefined = UNDEFINED;
|
|
503
|
+
extra = EXTRA;
|
|
504
|
+
} else {
|
|
505
|
+
posMatch = POS_MATCH_FUZZY;
|
|
506
|
+
negMatch = NEG_MATCH_FUZZY;
|
|
507
|
+
undefined = UNDEFINED_FUZZY;
|
|
508
|
+
extra = EXTRA_FUZZY;
|
|
509
|
+
}
|
|
510
|
+
int quotient = 0;
|
|
511
|
+
const List *l1 = query;
|
|
512
|
+
const List *l2 = tableFeatures;
|
|
513
|
+
while (1) {
|
|
514
|
+
if (!l1) {
|
|
515
|
+
if (!l2) break;
|
|
516
|
+
quotient += extra;
|
|
517
|
+
const List *l = l2;
|
|
518
|
+
l = l->tail;
|
|
519
|
+
while (l && cmpKeys(l->head, l2->head) == 0) l = l->tail;
|
|
520
|
+
l2 = l;
|
|
521
|
+
} else if (!l2) {
|
|
522
|
+
quotient += undefined;
|
|
523
|
+
l1 = l1->tail;
|
|
524
|
+
} else {
|
|
525
|
+
int cmp = cmpKeys(l1->head, l2->head);
|
|
526
|
+
if (cmp < 0) {
|
|
527
|
+
quotient += undefined;
|
|
528
|
+
l1 = l1->tail;
|
|
529
|
+
} else if (cmp > 0) {
|
|
530
|
+
quotient += extra;
|
|
531
|
+
const List *l = l2;
|
|
532
|
+
l = l->tail;
|
|
533
|
+
while (l && cmpKeys(l->head, l2->head) == 0) l = l->tail;
|
|
534
|
+
l2 = l;
|
|
535
|
+
} else {
|
|
536
|
+
const List *l = l2;
|
|
537
|
+
char *k = ((Feature *)l->head)->key;
|
|
538
|
+
int best = negMatch;
|
|
539
|
+
if (isLanguageTag(k, MAXSTRING)) {
|
|
540
|
+
int extraLanguages = 0;
|
|
541
|
+
while (1) {
|
|
542
|
+
// special handling of language tags: tags in the
|
|
543
|
+
// table are intepreted as language ranges
|
|
544
|
+
List *v = ((Feature *)l->head)->val;
|
|
545
|
+
List *v1 = ((Feature *)l1->head)->val;
|
|
546
|
+
int q = matchLanguageTags(v1, v);
|
|
547
|
+
if (q > 0 && q > best)
|
|
548
|
+
best = q;
|
|
549
|
+
else if (!q)
|
|
550
|
+
extraLanguages += extra;
|
|
551
|
+
l = l->tail;
|
|
552
|
+
if (!l || cmpKeys(l->head, l2->head) != 0) break;
|
|
553
|
+
}
|
|
554
|
+
if (best > 0)
|
|
555
|
+
best += ((extraLanguages + 4) /
|
|
556
|
+
5); // penalty for extra languages is lower than penalty
|
|
557
|
+
// for fields that are not in query at all
|
|
558
|
+
} else {
|
|
559
|
+
while (1) {
|
|
560
|
+
if (best < 0) {
|
|
561
|
+
char *v = ((Feature *)l->head)->val;
|
|
562
|
+
char *v1 = ((Feature *)l1->head)->val;
|
|
563
|
+
if (strcasecmp(v1, v) == 0)
|
|
564
|
+
best = posMatch;
|
|
565
|
+
else if (strcasecmp(k, "unicode-range") == 0) {
|
|
566
|
+
// special handling of unicode-range: ucs2 in
|
|
567
|
+
// table also matches ucs4 in query
|
|
568
|
+
if (strcasecmp(v1, "ucs4") == 0 &&
|
|
569
|
+
strcasecmp(v, "ucs2") == 0) {
|
|
570
|
+
best = posMatch;
|
|
571
|
+
best--; // add small penalty to favour ucs4 table
|
|
572
|
+
// if it exists
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
l = l->tail;
|
|
577
|
+
if (!l || cmpKeys(l->head, l2->head) != 0) break;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
quotient += best;
|
|
581
|
+
l1 = l1->tail;
|
|
582
|
+
l2 = l;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
return quotient;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Return true if a character matches [0-9A-Za-z_-\.]
|
|
591
|
+
*/
|
|
592
|
+
static int
|
|
593
|
+
isValidChar(char c) {
|
|
594
|
+
return isAlphaNum(c) || c == '-' || c == '.' || c == '_';
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Return true if a character matches [\s\t]
|
|
599
|
+
*/
|
|
600
|
+
static int
|
|
601
|
+
isSpace(char c) {
|
|
602
|
+
return c == ' ' || c == '\t';
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Parse a table query into a list of features. Features defined first get a
|
|
607
|
+
* higher importance.
|
|
608
|
+
*
|
|
609
|
+
* The returned list must be freed by the caller, using list_free.
|
|
610
|
+
*/
|
|
611
|
+
static List *
|
|
612
|
+
parseQuery(const char *query) {
|
|
613
|
+
List *features = NULL;
|
|
614
|
+
const char *key = NULL;
|
|
615
|
+
const char *val = NULL;
|
|
616
|
+
size_t keySize = 0;
|
|
617
|
+
size_t valSize = 0;
|
|
618
|
+
const char *c;
|
|
619
|
+
int pos = 0;
|
|
620
|
+
int unicodeRange = 0;
|
|
621
|
+
while (1) {
|
|
622
|
+
c = &query[pos++];
|
|
623
|
+
if (isSpace(*c) || (*c == '\n') || (*c == '\0')) {
|
|
624
|
+
if (key) {
|
|
625
|
+
char *v = NULL;
|
|
626
|
+
if (val) {
|
|
627
|
+
v = malloc(valSize + 1);
|
|
628
|
+
v[valSize] = '\0';
|
|
629
|
+
memcpy(v, val, valSize);
|
|
630
|
+
}
|
|
631
|
+
if (!v) goto compile_error;
|
|
632
|
+
char *k = malloc(keySize + 1);
|
|
633
|
+
k[keySize] = '\0';
|
|
634
|
+
memcpy(k, key, keySize);
|
|
635
|
+
if (isLanguageTag(k, keySize)) {
|
|
636
|
+
List *tag = parseLanguageTag(v);
|
|
637
|
+
if (!tag) {
|
|
638
|
+
_lou_logMessage(LOU_LOG_ERROR, "Not a valid language tag: %s", v);
|
|
639
|
+
free(k);
|
|
640
|
+
free(v);
|
|
641
|
+
list_free(features);
|
|
642
|
+
return NULL;
|
|
643
|
+
}
|
|
644
|
+
if (strcasecmp(k, "locale") == 0) {
|
|
645
|
+
// locale is shorthand for language + region
|
|
646
|
+
FeatureWithImportance f1 = {
|
|
647
|
+
feat_new(strdup("language"), tag, list_dup_, list_free_), 0
|
|
648
|
+
};
|
|
649
|
+
FeatureWithImportance f2 = { feat_new(strdup("region"),
|
|
650
|
+
list_dup(tag), list_dup_,
|
|
651
|
+
list_free_),
|
|
652
|
+
0 };
|
|
653
|
+
_lou_logMessage(LOU_LOG_DEBUG, "Query has feature '%s:%s'",
|
|
654
|
+
f1.feature.key, v);
|
|
655
|
+
_lou_logMessage(LOU_LOG_DEBUG, "Query has feature '%s:%s'",
|
|
656
|
+
f2.feature.key, v);
|
|
657
|
+
features = list_conj(features,
|
|
658
|
+
memcpy(malloc(sizeof(f1)), &f1, sizeof(f1)), NULL,
|
|
659
|
+
feat_dup_, feat_free_);
|
|
660
|
+
features = list_conj(features,
|
|
661
|
+
memcpy(malloc(sizeof(f2)), &f2, sizeof(f2)), NULL,
|
|
662
|
+
feat_dup_, feat_free_);
|
|
663
|
+
} else {
|
|
664
|
+
FeatureWithImportance f = {
|
|
665
|
+
feat_new(strdup(k), tag, list_dup_, list_free_), 0
|
|
666
|
+
};
|
|
667
|
+
_lou_logMessage(LOU_LOG_DEBUG, "Query has feature '%s:%s'", k, v);
|
|
668
|
+
features = list_conj(features,
|
|
669
|
+
memcpy(malloc(sizeof(f)), &f, sizeof(f)), NULL, feat_dup_,
|
|
670
|
+
feat_free_);
|
|
671
|
+
}
|
|
672
|
+
} else {
|
|
673
|
+
FeatureWithImportance f = {
|
|
674
|
+
feat_new(strdup(k), strdup(v), strdup_, free), 0
|
|
675
|
+
};
|
|
676
|
+
_lou_logMessage(LOU_LOG_DEBUG, "Query has feature '%s:%s'", k, v);
|
|
677
|
+
features =
|
|
678
|
+
list_conj(features, memcpy(malloc(sizeof(f)), &f, sizeof(f)),
|
|
679
|
+
NULL, feat_dup_, feat_free_);
|
|
680
|
+
if (strcasecmp(k, "unicode-range") == 0) unicodeRange = 1;
|
|
681
|
+
}
|
|
682
|
+
free(k);
|
|
683
|
+
free(v);
|
|
684
|
+
key = val = NULL;
|
|
685
|
+
keySize = valSize = 0;
|
|
686
|
+
}
|
|
687
|
+
if (*c == '\0') break;
|
|
688
|
+
} else if (*c == ':') {
|
|
689
|
+
if (!key || val)
|
|
690
|
+
goto compile_error;
|
|
691
|
+
else {
|
|
692
|
+
c = &query[pos++];
|
|
693
|
+
if (isValidChar(*c)) {
|
|
694
|
+
val = c;
|
|
695
|
+
valSize = 1;
|
|
696
|
+
} else
|
|
697
|
+
goto compile_error;
|
|
698
|
+
}
|
|
699
|
+
} else if (isValidChar(*c)) {
|
|
700
|
+
if (val)
|
|
701
|
+
valSize++;
|
|
702
|
+
else if (key)
|
|
703
|
+
keySize++;
|
|
704
|
+
else {
|
|
705
|
+
key = c;
|
|
706
|
+
keySize = 1;
|
|
707
|
+
}
|
|
708
|
+
} else
|
|
709
|
+
goto compile_error;
|
|
710
|
+
}
|
|
711
|
+
// add defaults
|
|
712
|
+
if (!unicodeRange) {
|
|
713
|
+
// default value of unicode-range is determined by CHARSIZE
|
|
714
|
+
static char value[5] = "";
|
|
715
|
+
if (!*value) sprintf(value, "ucs%ld", CHARSIZE);
|
|
716
|
+
FeatureWithImportance *f = memcpy(malloc(sizeof(FeatureWithImportance)),
|
|
717
|
+
(&(FeatureWithImportance){
|
|
718
|
+
feat_new(strdup("unicode-range"), strdup(value), strdup_, free),
|
|
719
|
+
-1 }),
|
|
720
|
+
sizeof(FeatureWithImportance));
|
|
721
|
+
_lou_logMessage(LOU_LOG_DEBUG, "Query has feature '%s:%s'", f->feature.key,
|
|
722
|
+
f->feature.val);
|
|
723
|
+
features = list_conj(features, f, NULL, feat_dup_, feat_free_);
|
|
724
|
+
}
|
|
725
|
+
// attach importance to features
|
|
726
|
+
{
|
|
727
|
+
int k = 1;
|
|
728
|
+
List *l;
|
|
729
|
+
for (l = features; l; l = l->tail) {
|
|
730
|
+
FeatureWithImportance *f = l->head;
|
|
731
|
+
f->importance = k++;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
// sort features by key (alphabetical order)
|
|
735
|
+
return list_sort(features, cmpKeys_);
|
|
736
|
+
compile_error:
|
|
737
|
+
_lou_logMessage(LOU_LOG_ERROR, "Unexpected character '%c' at position %d", *c, pos);
|
|
738
|
+
list_free(features);
|
|
739
|
+
return NULL;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Convert a widechar string to a normal string.
|
|
744
|
+
*/
|
|
745
|
+
static char *
|
|
746
|
+
widestrToStr(const widechar *str, size_t n) {
|
|
747
|
+
char *result = malloc((1 + n) * sizeof(char));
|
|
748
|
+
size_t k;
|
|
749
|
+
for (k = 0; k < n; k++) result[k] = (char)str[k];
|
|
750
|
+
result[k] = '\0';
|
|
751
|
+
return result;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* Extract a list of features from a table. The features are of type
|
|
756
|
+
* FeatureWithLineNumber.
|
|
757
|
+
*/
|
|
758
|
+
static List *
|
|
759
|
+
analyzeTable(const char *table, int activeOnly) {
|
|
760
|
+
static char fileName[MAXSTRING];
|
|
761
|
+
List *features = NULL;
|
|
762
|
+
FileInfo info;
|
|
763
|
+
|
|
764
|
+
{
|
|
765
|
+
char **resolved = _lou_resolveTable(table, NULL);
|
|
766
|
+
|
|
767
|
+
if (resolved == NULL) {
|
|
768
|
+
_lou_logMessage(LOU_LOG_ERROR, "Cannot resolve table '%s'", table);
|
|
769
|
+
return NULL;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
sprintf(fileName, "%s", *resolved);
|
|
773
|
+
int k = 0;
|
|
774
|
+
|
|
775
|
+
for (k = 0; resolved[k]; k += 1) free(resolved[k]);
|
|
776
|
+
free(resolved);
|
|
777
|
+
|
|
778
|
+
if (k > 1) {
|
|
779
|
+
_lou_logMessage(
|
|
780
|
+
LOU_LOG_ERROR, "Table '%s' resolves to more than one file", table);
|
|
781
|
+
return NULL;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
info.fileName = fileName;
|
|
786
|
+
info.encoding = noEncoding;
|
|
787
|
+
info.status = 0;
|
|
788
|
+
info.lineNumber = 0;
|
|
789
|
+
if ((info.in = fopen(info.fileName, "rb"))) {
|
|
790
|
+
FeatureWithLineNumber *region = NULL;
|
|
791
|
+
FeatureWithLineNumber *language = NULL;
|
|
792
|
+
int unicodeRange = 0;
|
|
793
|
+
while (_lou_getALine(&info)) {
|
|
794
|
+
if (info.linelen == 0)
|
|
795
|
+
;
|
|
796
|
+
else if (info.line[0] == '#') {
|
|
797
|
+
if (info.linelen >= 2 &&
|
|
798
|
+
(info.line[1] == '+' ||
|
|
799
|
+
(!activeOnly && info.line[1] == '-' &&
|
|
800
|
+
!(info.linelen > 2 && info.line[2] == '-')))) {
|
|
801
|
+
int active = (info.line[1] == '+');
|
|
802
|
+
widechar *key = NULL;
|
|
803
|
+
widechar *val = NULL;
|
|
804
|
+
size_t keySize = 0;
|
|
805
|
+
size_t valSize = 0;
|
|
806
|
+
info.linepos = 2;
|
|
807
|
+
if (info.linepos < info.linelen &&
|
|
808
|
+
isValidChar((char)info.line[info.linepos])) {
|
|
809
|
+
key = &info.line[info.linepos];
|
|
810
|
+
keySize = 1;
|
|
811
|
+
info.linepos++;
|
|
812
|
+
while (info.linepos < info.linelen &&
|
|
813
|
+
isValidChar((char)info.line[info.linepos])) {
|
|
814
|
+
keySize++;
|
|
815
|
+
info.linepos++;
|
|
816
|
+
}
|
|
817
|
+
char *k = widestrToStr(key, keySize);
|
|
818
|
+
int isLangTag = isLanguageTag(k, keySize);
|
|
819
|
+
if (info.linepos < info.linelen &&
|
|
820
|
+
info.line[info.linepos] == ':') {
|
|
821
|
+
info.linepos++;
|
|
822
|
+
while (info.linepos < info.linelen &&
|
|
823
|
+
isSpace((char)info.line[info.linepos]))
|
|
824
|
+
info.linepos++;
|
|
825
|
+
if (info.linepos < info.linelen &&
|
|
826
|
+
(!active ||
|
|
827
|
+
isValidChar((char)info.line[info.linepos]) ||
|
|
828
|
+
(isLangTag &&
|
|
829
|
+
'*' == info.line[info.linepos]))) {
|
|
830
|
+
val = &info.line[info.linepos];
|
|
831
|
+
valSize = 1;
|
|
832
|
+
info.linepos++;
|
|
833
|
+
while (info.linepos < info.linelen &&
|
|
834
|
+
(!active ||
|
|
835
|
+
isValidChar(
|
|
836
|
+
(char)info.line[info.linepos]))) {
|
|
837
|
+
valSize++;
|
|
838
|
+
info.linepos++;
|
|
839
|
+
}
|
|
840
|
+
} else {
|
|
841
|
+
free(k);
|
|
842
|
+
goto compile_error;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
if (info.linepos == info.linelen) {
|
|
846
|
+
char *v = val ? widestrToStr(val, valSize) : NULL;
|
|
847
|
+
if (!v) {
|
|
848
|
+
free(k);
|
|
849
|
+
goto compile_error;
|
|
850
|
+
}
|
|
851
|
+
if (!active) {
|
|
852
|
+
// normalize space
|
|
853
|
+
int i = 0;
|
|
854
|
+
int j = 0;
|
|
855
|
+
int space = 1;
|
|
856
|
+
while (v[i]) {
|
|
857
|
+
if (isSpace(v[i])) {
|
|
858
|
+
if (!space) {
|
|
859
|
+
v[j++] = ' ';
|
|
860
|
+
space = 1;
|
|
861
|
+
}
|
|
862
|
+
} else {
|
|
863
|
+
v[j++] = v[i];
|
|
864
|
+
space = 0;
|
|
865
|
+
}
|
|
866
|
+
i++;
|
|
867
|
+
}
|
|
868
|
+
if (j > 0 && v[j - 1] == ' ') j--;
|
|
869
|
+
v[j] = '\0';
|
|
870
|
+
}
|
|
871
|
+
if (isLangTag) {
|
|
872
|
+
List *tag = parseLanguageTag(v);
|
|
873
|
+
if (!tag) {
|
|
874
|
+
_lou_logMessage(LOU_LOG_ERROR,
|
|
875
|
+
"Not a valid language tag: %s (line %d)", v,
|
|
876
|
+
info.lineNumber);
|
|
877
|
+
list_free(features);
|
|
878
|
+
return NULL;
|
|
879
|
+
}
|
|
880
|
+
if (strcasecmp(k, "locale") == 0) {
|
|
881
|
+
FeatureWithLineNumber *f1 = memcpy(
|
|
882
|
+
malloc(sizeof(FeatureWithLineNumber)),
|
|
883
|
+
(&(FeatureWithLineNumber){
|
|
884
|
+
feat_new(strdup("language"), tag,
|
|
885
|
+
list_dup_, list_free_),
|
|
886
|
+
info.lineNumber }),
|
|
887
|
+
sizeof(FeatureWithLineNumber));
|
|
888
|
+
FeatureWithLineNumber *f2 = memcpy(
|
|
889
|
+
malloc(sizeof(FeatureWithLineNumber)),
|
|
890
|
+
(&(FeatureWithLineNumber){
|
|
891
|
+
feat_new(strdup("region"),
|
|
892
|
+
list_dup(tag), list_dup_,
|
|
893
|
+
list_free_),
|
|
894
|
+
info.lineNumber }),
|
|
895
|
+
sizeof(FeatureWithLineNumber));
|
|
896
|
+
_lou_logMessage(LOU_LOG_DEBUG,
|
|
897
|
+
"Table has feature '%s:%s'", f1->feature.key,
|
|
898
|
+
v);
|
|
899
|
+
_lou_logMessage(LOU_LOG_DEBUG,
|
|
900
|
+
"Table has feature '%s:%s'", f2->feature.key,
|
|
901
|
+
v);
|
|
902
|
+
features = list_conj(
|
|
903
|
+
features, f1, NULL, feat_dup_, feat_free_);
|
|
904
|
+
features = list_conj(
|
|
905
|
+
features, f2, NULL, feat_dup_, feat_free_);
|
|
906
|
+
if (!language) language = f1;
|
|
907
|
+
if (!region) region = f2;
|
|
908
|
+
} else {
|
|
909
|
+
FeatureWithLineNumber *f = memcpy(
|
|
910
|
+
malloc(sizeof(FeatureWithLineNumber)),
|
|
911
|
+
(&(FeatureWithLineNumber){
|
|
912
|
+
feat_new(strdup(k), tag, list_dup_,
|
|
913
|
+
list_free_),
|
|
914
|
+
info.lineNumber }),
|
|
915
|
+
sizeof(FeatureWithLineNumber));
|
|
916
|
+
_lou_logMessage(LOU_LOG_DEBUG,
|
|
917
|
+
"Table has feature '%s:%s'", k, v);
|
|
918
|
+
features = list_conj(
|
|
919
|
+
features, f, NULL, feat_dup_, feat_free_);
|
|
920
|
+
if (strcasecmp(k, "language") == 0) {
|
|
921
|
+
if (!language) language = f;
|
|
922
|
+
} else if (strcasecmp(k, "region") == 0) {
|
|
923
|
+
if (!region) region = f;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
} else {
|
|
927
|
+
FeatureWithLineNumber *f =
|
|
928
|
+
memcpy(malloc(sizeof(FeatureWithLineNumber)),
|
|
929
|
+
(&(FeatureWithLineNumber){
|
|
930
|
+
feat_new(strdup(k), strdup(v),
|
|
931
|
+
strdup_, free),
|
|
932
|
+
info.lineNumber }),
|
|
933
|
+
sizeof(FeatureWithLineNumber));
|
|
934
|
+
_lou_logMessage(
|
|
935
|
+
LOU_LOG_DEBUG, "Table has feature '%s:%s'", k, v);
|
|
936
|
+
features = list_conj(
|
|
937
|
+
features, f, NULL, feat_dup_, feat_free_);
|
|
938
|
+
if (strcasecmp(k, "unicode-range") == 0) unicodeRange = 1;
|
|
939
|
+
}
|
|
940
|
+
free(k);
|
|
941
|
+
free(v);
|
|
942
|
+
} else {
|
|
943
|
+
free(k);
|
|
944
|
+
goto compile_error;
|
|
945
|
+
}
|
|
946
|
+
} else
|
|
947
|
+
goto compile_error;
|
|
948
|
+
}
|
|
949
|
+
} else
|
|
950
|
+
break;
|
|
951
|
+
}
|
|
952
|
+
fclose(info.in);
|
|
953
|
+
// add defaults
|
|
954
|
+
if (!region && language) {
|
|
955
|
+
region = memcpy(malloc(sizeof(FeatureWithLineNumber)),
|
|
956
|
+
(&(FeatureWithLineNumber){
|
|
957
|
+
feat_new(strdup("region"), list_dup(language->feature.val),
|
|
958
|
+
list_dup_, list_free_),
|
|
959
|
+
-1 }),
|
|
960
|
+
sizeof(FeatureWithLineNumber));
|
|
961
|
+
char *v = serializeLanguageTag(region->feature.val);
|
|
962
|
+
_lou_logMessage(
|
|
963
|
+
LOU_LOG_DEBUG, "Table has feature '%s:%s'", region->feature.key, v);
|
|
964
|
+
free(v);
|
|
965
|
+
features = list_conj(features, region, NULL, feat_dup_, feat_free_);
|
|
966
|
+
}
|
|
967
|
+
if (features && !unicodeRange) {
|
|
968
|
+
// by default we assume unicode-range: ucs2
|
|
969
|
+
FeatureWithLineNumber *f = memcpy(malloc(sizeof(FeatureWithLineNumber)),
|
|
970
|
+
(&(FeatureWithLineNumber){ feat_new(strdup("unicode-range"),
|
|
971
|
+
strdup("ucs2"), strdup_, free),
|
|
972
|
+
-1 }),
|
|
973
|
+
sizeof(FeatureWithLineNumber));
|
|
974
|
+
_lou_logMessage(LOU_LOG_DEBUG, "Table has feature '%s:%s'", f->feature.key,
|
|
975
|
+
f->feature.val);
|
|
976
|
+
features = list_conj(features, f, NULL, feat_dup_, feat_free_);
|
|
977
|
+
}
|
|
978
|
+
} else
|
|
979
|
+
_lou_logMessage(LOU_LOG_ERROR, "Cannot open table '%s'", info.fileName);
|
|
980
|
+
return list_sort(features, cmpFeatures_);
|
|
981
|
+
compile_error:
|
|
982
|
+
if (info.linepos < info.linelen)
|
|
983
|
+
_lou_logMessage(LOU_LOG_ERROR, "Unexpected character '%c' on line %d, column %d",
|
|
984
|
+
info.line[info.linepos], info.lineNumber, info.linepos);
|
|
985
|
+
else
|
|
986
|
+
_lou_logMessage(LOU_LOG_ERROR, "Unexpected newline on line %d", info.lineNumber);
|
|
987
|
+
list_free(features);
|
|
988
|
+
return NULL;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* List of discoverable tables and corresponding metadata.
|
|
993
|
+
*
|
|
994
|
+
* The list is freed by _lou_freeTableIndex, which is invoked by lou_free. It should not
|
|
995
|
+
* be copied.
|
|
996
|
+
*/
|
|
997
|
+
static List *tableIndex = NULL;
|
|
998
|
+
|
|
999
|
+
void EXPORT_CALL
|
|
1000
|
+
lou_indexTables(const char **tables) {
|
|
1001
|
+
const char **table;
|
|
1002
|
+
list_free(tableIndex);
|
|
1003
|
+
tableIndex = NULL;
|
|
1004
|
+
for (table = tables; *table; table++) {
|
|
1005
|
+
_lou_logMessage(LOU_LOG_DEBUG, "Analyzing table %s", *table);
|
|
1006
|
+
List *features = analyzeTable(*table, 1);
|
|
1007
|
+
if (features) {
|
|
1008
|
+
TableMeta m = { strdup(*table), features };
|
|
1009
|
+
tableIndex = list_conj(tableIndex, memcpy(malloc(sizeof(m)), &m, sizeof(m)),
|
|
1010
|
+
NULL, NULL, meta_free_);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
if (!tableIndex) _lou_logMessage(LOU_LOG_WARN, "No tables were indexed");
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
// called by lou_free
|
|
1017
|
+
void EXPORT_CALL
|
|
1018
|
+
_lou_freeTableIndex(void) {
|
|
1019
|
+
list_free(tableIndex);
|
|
1020
|
+
tableIndex = NULL;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
/**
|
|
1024
|
+
* Returns the list of files found in a single directory.
|
|
1025
|
+
*
|
|
1026
|
+
* Must be freed by the caller, using list_free.
|
|
1027
|
+
*/
|
|
1028
|
+
#if defined(_MSC_VER) || defined(_WIN32)
|
|
1029
|
+
static List *
|
|
1030
|
+
listDir(List *list, char *dirName) {
|
|
1031
|
+
static char glob[MAXSTRING];
|
|
1032
|
+
static char fileName[MAXSTRING];
|
|
1033
|
+
WIN32_FIND_DATAA ffd;
|
|
1034
|
+
HANDLE hFind;
|
|
1035
|
+
sprintf(glob, "%s%c%c", dirName, DIR_SEP, '*');
|
|
1036
|
+
hFind = FindFirstFileA(glob, &ffd);
|
|
1037
|
+
if (hFind == INVALID_HANDLE_VALUE) {
|
|
1038
|
+
_lou_logMessage(LOU_LOG_WARN, "%s is not a directory", dirName);
|
|
1039
|
+
} else {
|
|
1040
|
+
do {
|
|
1041
|
+
if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
|
|
1042
|
+
sprintf(fileName, "%s%c%s", dirName, DIR_SEP, ffd.cFileName);
|
|
1043
|
+
list = list_conj(list, strdup(fileName), NULL, strdup_, free);
|
|
1044
|
+
}
|
|
1045
|
+
} while (FindNextFileA(hFind, &ffd));
|
|
1046
|
+
FindClose(hFind);
|
|
1047
|
+
}
|
|
1048
|
+
return list;
|
|
1049
|
+
}
|
|
1050
|
+
#else /* !_MSC_VER */
|
|
1051
|
+
static List *
|
|
1052
|
+
listDir(List *list, char *dirName) {
|
|
1053
|
+
static char fileName[MAXSTRING];
|
|
1054
|
+
struct stat info;
|
|
1055
|
+
DIR *dir;
|
|
1056
|
+
struct dirent *file;
|
|
1057
|
+
if ((dir = opendir(dirName))) {
|
|
1058
|
+
while ((file = readdir(dir))) {
|
|
1059
|
+
sprintf(fileName, "%s%c%s", dirName, DIR_SEP, file->d_name);
|
|
1060
|
+
if (stat(fileName, &info) == 0 && !(info.st_mode & S_IFDIR)) {
|
|
1061
|
+
list = list_conj(list, strdup(fileName), NULL, strdup_, free);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
closedir(dir);
|
|
1065
|
+
} else {
|
|
1066
|
+
_lou_logMessage(LOU_LOG_WARN, "%s is not a directory", dirName);
|
|
1067
|
+
}
|
|
1068
|
+
return list;
|
|
1069
|
+
}
|
|
1070
|
+
#endif /* !_MSC_VER */
|
|
1071
|
+
|
|
1072
|
+
/**
|
|
1073
|
+
* Returns the list of files found on searchPath, where searchPath is a
|
|
1074
|
+
* comma-separated list of directories.
|
|
1075
|
+
*/
|
|
1076
|
+
static List *
|
|
1077
|
+
listFiles(char *searchPath) {
|
|
1078
|
+
List *list = NULL;
|
|
1079
|
+
char *dirName;
|
|
1080
|
+
int pos = 0;
|
|
1081
|
+
int n;
|
|
1082
|
+
while (1) {
|
|
1083
|
+
for (n = 0; searchPath[pos + n] != '\0' && searchPath[pos + n] != ','; n++);
|
|
1084
|
+
dirName = malloc(n + 1);
|
|
1085
|
+
dirName[n] = '\0';
|
|
1086
|
+
memcpy(dirName, &searchPath[pos], n);
|
|
1087
|
+
list = listDir(list, dirName);
|
|
1088
|
+
free(dirName);
|
|
1089
|
+
pos += n;
|
|
1090
|
+
if (searchPath[pos] == '\0')
|
|
1091
|
+
break;
|
|
1092
|
+
else
|
|
1093
|
+
pos++;
|
|
1094
|
+
}
|
|
1095
|
+
return list;
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
static void
|
|
1099
|
+
indexTablePath(void) {
|
|
1100
|
+
char *searchPath;
|
|
1101
|
+
List *tables;
|
|
1102
|
+
void *tablesArray;
|
|
1103
|
+
_lou_logMessage(
|
|
1104
|
+
LOU_LOG_WARN, "Tables have not been indexed yet. Indexing LOUIS_TABLEPATH.");
|
|
1105
|
+
searchPath = _lou_getTablePath();
|
|
1106
|
+
if (searchPath == NULL) {
|
|
1107
|
+
_lou_logMessage(LOU_LOG_ERROR, "Failed to get table path");
|
|
1108
|
+
return;
|
|
1109
|
+
}
|
|
1110
|
+
tables = listFiles(searchPath);
|
|
1111
|
+
tablesArray = list_toArray(tables, 0);
|
|
1112
|
+
lou_indexTables(tablesArray);
|
|
1113
|
+
free(searchPath);
|
|
1114
|
+
list_free(tables);
|
|
1115
|
+
free(tablesArray);
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
char *EXPORT_CALL
|
|
1119
|
+
lou_findTable(const char *query) {
|
|
1120
|
+
if (!tableIndex) indexTablePath();
|
|
1121
|
+
List *queryFeatures = parseQuery(query);
|
|
1122
|
+
int bestQuotient = 0;
|
|
1123
|
+
char *bestMatch = NULL;
|
|
1124
|
+
List *l;
|
|
1125
|
+
for (l = tableIndex; l; l = l->tail) {
|
|
1126
|
+
TableMeta *table = l->head;
|
|
1127
|
+
int q = matchFeatureLists(queryFeatures, table->features, 0);
|
|
1128
|
+
if (q > bestQuotient) {
|
|
1129
|
+
bestQuotient = q;
|
|
1130
|
+
if (bestMatch) free(bestMatch);
|
|
1131
|
+
bestMatch = strdup(table->name);
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
list_free(queryFeatures);
|
|
1135
|
+
if (bestMatch) {
|
|
1136
|
+
_lou_logMessage(LOU_LOG_INFO, "Best match: %s (%d)", bestMatch, bestQuotient);
|
|
1137
|
+
return bestMatch;
|
|
1138
|
+
} else {
|
|
1139
|
+
_lou_logMessage(LOU_LOG_INFO, "No table could be found for query '%s'", query);
|
|
1140
|
+
return NULL;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
void EXPORT_CALL
|
|
1145
|
+
lou_freeTableFile(char *table) {
|
|
1146
|
+
free(table);
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
typedef struct {
|
|
1150
|
+
char *name;
|
|
1151
|
+
int matchQuotient;
|
|
1152
|
+
} TableMatch;
|
|
1153
|
+
|
|
1154
|
+
static int
|
|
1155
|
+
cmpMatches(TableMatch *m1, TableMatch *m2) {
|
|
1156
|
+
if (m1->matchQuotient > m2->matchQuotient)
|
|
1157
|
+
return -1;
|
|
1158
|
+
else
|
|
1159
|
+
return 1;
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
/**
|
|
1163
|
+
* Adapter, see list_free_/list_dup_ above.
|
|
1164
|
+
*/
|
|
1165
|
+
static int
|
|
1166
|
+
cmpMatches_(void *v1, void *v2) {
|
|
1167
|
+
return cmpMatches(v1, v2);
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
/**
|
|
1171
|
+
* Adapter so that strcmp can be used as a generic List comparator (typed
|
|
1172
|
+
* `int (*)(void *, void *)') without calling through an incompatibly-typed
|
|
1173
|
+
* function pointer, which is undefined behaviour.
|
|
1174
|
+
*/
|
|
1175
|
+
static int
|
|
1176
|
+
strcmp_(void *v1, void *v2) {
|
|
1177
|
+
return strcmp(v1, v2);
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
/**
|
|
1181
|
+
* The returned array and strings must be freed by the caller.
|
|
1182
|
+
*/
|
|
1183
|
+
char **EXPORT_CALL
|
|
1184
|
+
lou_findTables(const char *query) {
|
|
1185
|
+
char **tablesArray;
|
|
1186
|
+
List *matches = NULL;
|
|
1187
|
+
if (!tableIndex) indexTablePath();
|
|
1188
|
+
List *queryFeatures = parseQuery(query);
|
|
1189
|
+
List *l;
|
|
1190
|
+
for (l = tableIndex; l; l = l->tail) {
|
|
1191
|
+
TableMeta *table = l->head;
|
|
1192
|
+
int quotient = matchFeatureLists(queryFeatures, table->features, 0);
|
|
1193
|
+
if (quotient > 0) {
|
|
1194
|
+
TableMatch m = { strdup(table->name), quotient };
|
|
1195
|
+
matches = list_conj(matches, memcpy(malloc(sizeof(m)), &m, sizeof(m)),
|
|
1196
|
+
cmpMatches_, NULL, free);
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
list_free(queryFeatures);
|
|
1200
|
+
if (matches) {
|
|
1201
|
+
_lou_logMessage(LOU_LOG_INFO, "%d matches found", list_size(matches));
|
|
1202
|
+
int i = 0;
|
|
1203
|
+
tablesArray = malloc((1 + list_size(matches)) * sizeof(void *));
|
|
1204
|
+
for (List *m = matches; m; m = m->tail)
|
|
1205
|
+
tablesArray[i++] = ((TableMatch *)m->head)->name;
|
|
1206
|
+
tablesArray[i] = NULL;
|
|
1207
|
+
list_free(matches);
|
|
1208
|
+
return tablesArray;
|
|
1209
|
+
} else {
|
|
1210
|
+
_lou_logMessage(LOU_LOG_INFO, "No table could be found for query '%s'", query);
|
|
1211
|
+
return NULL;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
char *EXPORT_CALL
|
|
1216
|
+
lou_getTableInfo(const char *table, const char *key) {
|
|
1217
|
+
char *value = NULL;
|
|
1218
|
+
List *features = analyzeTable(table, 0);
|
|
1219
|
+
List *l;
|
|
1220
|
+
int lineNumber = -1; // line number of first matching feature
|
|
1221
|
+
for (l = features; l; l = l->tail) {
|
|
1222
|
+
FeatureWithLineNumber *f = l->head;
|
|
1223
|
+
int cmp = strcasecmp(f->feature.key, key);
|
|
1224
|
+
if (cmp == 0) {
|
|
1225
|
+
if (lineNumber < 0 || lineNumber > f->lineNumber) {
|
|
1226
|
+
if (isLanguageTag(key, MAXSTRING))
|
|
1227
|
+
value = serializeLanguageTag(f->feature.val);
|
|
1228
|
+
else
|
|
1229
|
+
value = strdup(f->feature.val);
|
|
1230
|
+
lineNumber = f->lineNumber;
|
|
1231
|
+
}
|
|
1232
|
+
} else if (cmp > 0) {
|
|
1233
|
+
break;
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
list_free(features);
|
|
1237
|
+
return value;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
void EXPORT_CALL
|
|
1241
|
+
lou_freeTableInfo(char *info) {
|
|
1242
|
+
free(info);
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
char **EXPORT_CALL
|
|
1246
|
+
lou_listTables(void) {
|
|
1247
|
+
void *tablesArray;
|
|
1248
|
+
List *tables = NULL;
|
|
1249
|
+
List *l;
|
|
1250
|
+
if (!tableIndex) indexTablePath();
|
|
1251
|
+
for (l = tableIndex; l; l = l->tail) {
|
|
1252
|
+
TableMeta *table = l->head;
|
|
1253
|
+
tables = list_conj(tables, strdup(table->name), strcmp_, NULL, NULL);
|
|
1254
|
+
}
|
|
1255
|
+
tablesArray = list_toArray(tables, 0);
|
|
1256
|
+
list_free(tables);
|
|
1257
|
+
return tablesArray;
|
|
1258
|
+
}
|