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,1632 @@
|
|
|
1
|
+
/* liblouis Braille Translation and Back-Translation Library
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2016 Mike Gray, American Printing House for the Blind
|
|
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
|
+
#include "config.h"
|
|
22
|
+
|
|
23
|
+
#include <stdlib.h>
|
|
24
|
+
#include <stdio.h>
|
|
25
|
+
#include <string.h>
|
|
26
|
+
#include <ctype.h>
|
|
27
|
+
|
|
28
|
+
#include "internal.h"
|
|
29
|
+
|
|
30
|
+
// #define CHECK_OUTPUT_DEFINED
|
|
31
|
+
|
|
32
|
+
/////
|
|
33
|
+
|
|
34
|
+
// TODO: these functions are static and copied serveral times
|
|
35
|
+
|
|
36
|
+
int translation_direction = 1;
|
|
37
|
+
|
|
38
|
+
static TranslationTableCharacter *
|
|
39
|
+
findCharOrDots(widechar c, int m, const TranslationTableHeader *table) {
|
|
40
|
+
/* Look up character or dot pattern in the appropriate
|
|
41
|
+
* table. */
|
|
42
|
+
static TranslationTableCharacter noChar = { NULL, -1, 0, 0, 0, CTC_Space, 0, 0, 32, 0,
|
|
43
|
+
0 };
|
|
44
|
+
static TranslationTableCharacter noDots = { NULL, -1, 0, 0, 0, CTC_Space, 0, 0,
|
|
45
|
+
LOU_DOTS, 0, 0 };
|
|
46
|
+
TranslationTableCharacter *notFound;
|
|
47
|
+
TranslationTableCharacter *character;
|
|
48
|
+
TranslationTableOffset bucket;
|
|
49
|
+
unsigned long int makeHash = _lou_charHash(c);
|
|
50
|
+
if (m == 0) {
|
|
51
|
+
bucket = table->characters[makeHash];
|
|
52
|
+
notFound = &noChar;
|
|
53
|
+
} else {
|
|
54
|
+
bucket = table->dots[makeHash];
|
|
55
|
+
notFound = &noDots;
|
|
56
|
+
}
|
|
57
|
+
while (bucket) {
|
|
58
|
+
character = (TranslationTableCharacter *)&table->ruleArea[bucket];
|
|
59
|
+
if (character->value == c) return character;
|
|
60
|
+
bucket = character->next;
|
|
61
|
+
}
|
|
62
|
+
notFound->value = c;
|
|
63
|
+
return notFound;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static int
|
|
67
|
+
checkAttr(const widechar c, const TranslationTableCharacterAttributes a,
|
|
68
|
+
const TranslationTableHeader *table) {
|
|
69
|
+
return (((findCharOrDots(c, translation_direction ? 0 : 1, table))->attributes & a)
|
|
70
|
+
? 1
|
|
71
|
+
: 0);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/////
|
|
75
|
+
|
|
76
|
+
enum pattern_type {
|
|
77
|
+
PTN_ERROR,
|
|
78
|
+
|
|
79
|
+
PTN_START,
|
|
80
|
+
PTN_GROUP,
|
|
81
|
+
PTN_NOT,
|
|
82
|
+
|
|
83
|
+
PTN_ONE_MORE,
|
|
84
|
+
PTN_ZERO_MORE,
|
|
85
|
+
PTN_OPTIONAL,
|
|
86
|
+
|
|
87
|
+
PTN_ALTERNATE,
|
|
88
|
+
|
|
89
|
+
PTN_ANY,
|
|
90
|
+
PTN_ATTRIBUTES,
|
|
91
|
+
PTN_CHARS,
|
|
92
|
+
PTN_HOOK,
|
|
93
|
+
PTN_END_OF_INPUT,
|
|
94
|
+
|
|
95
|
+
PTN_END = 0xffff,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
#define EXPR_TYPE_IN(at, buffer) (buffer[(at) + 0])
|
|
99
|
+
#define EXPR_PRV_IN(at, buffer) (buffer[(at) + 1])
|
|
100
|
+
#define EXPR_NXT_IN(at, buffer) (buffer[(at) + 2])
|
|
101
|
+
#define EXPR_DATA_0_IN(at, buffer) (buffer[(at) + 3])
|
|
102
|
+
#define EXPR_DATA_1_IN(at, buffer) (buffer[(at) + 4])
|
|
103
|
+
#define EXPR_DATA_2_IN(at, buffer) (buffer[(at) + 5])
|
|
104
|
+
#define EXPR_DATA_IN(at, buffer) ((widechar *)&buffer[(at) + 3])
|
|
105
|
+
#define EXPR_CONST_DATA_IN(at, buffer) ((const widechar *)&buffer[(at) + 3])
|
|
106
|
+
|
|
107
|
+
#define EXPR_TYPE(at) EXPR_TYPE_IN((at), expr_data)
|
|
108
|
+
#define EXPR_PRV(at) EXPR_PRV_IN((at), expr_data)
|
|
109
|
+
#define EXPR_NXT(at) EXPR_NXT_IN((at), expr_data)
|
|
110
|
+
#define EXPR_DATA_0(at) EXPR_DATA_0_IN((at), expr_data)
|
|
111
|
+
#define EXPR_DATA_1(at) EXPR_DATA_1_IN((at), expr_data)
|
|
112
|
+
#define EXPR_DATA_2(at) EXPR_DATA_2_IN((at), expr_data)
|
|
113
|
+
#define EXPR_DATA(at) EXPR_DATA_IN((at), expr_data)
|
|
114
|
+
#define EXPR_CONST_DATA(at) EXPR_CONST_DATA_IN((at), expr_data)
|
|
115
|
+
|
|
116
|
+
#ifdef CHECK_OUTPUT_DEFINED
|
|
117
|
+
|
|
118
|
+
#ifndef DEBUG
|
|
119
|
+
#define DEBUG
|
|
120
|
+
|
|
121
|
+
#endif
|
|
122
|
+
|
|
123
|
+
#define START 0
|
|
124
|
+
#define CALL 1
|
|
125
|
+
#define RETURN 2
|
|
126
|
+
#define SHOW 3
|
|
127
|
+
|
|
128
|
+
#define CHECK_OUTPUT(type, ret, line, msg) \
|
|
129
|
+
{ \
|
|
130
|
+
do_output(type, ret, line, input[*input_crs], input_minmax, *input_crs, \
|
|
131
|
+
input_dir, expr_data, expr_crs, notOperator, loop_crs, loop_cnts, msg); \
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#else
|
|
135
|
+
|
|
136
|
+
#define CHECK_OUTPUT(type, ret, line, msg) \
|
|
137
|
+
{ ; }
|
|
138
|
+
|
|
139
|
+
#endif
|
|
140
|
+
|
|
141
|
+
struct expression {
|
|
142
|
+
widechar type;
|
|
143
|
+
widechar prv;
|
|
144
|
+
widechar nxt;
|
|
145
|
+
widechar data[1];
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/* gdb won't know what this is unless it is actually used */
|
|
149
|
+
#ifdef DEBUG
|
|
150
|
+
static struct expression *expr_debug;
|
|
151
|
+
#endif
|
|
152
|
+
|
|
153
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
154
|
+
|
|
155
|
+
static char spaces[] = "..............................";
|
|
156
|
+
static int space = 30;
|
|
157
|
+
|
|
158
|
+
static void
|
|
159
|
+
pattern_output_expression(
|
|
160
|
+
const widechar *expr_data, int expr_crs, const TranslationTableHeader *table) {
|
|
161
|
+
int i;
|
|
162
|
+
|
|
163
|
+
if (expr_crs == PTN_END) return;
|
|
164
|
+
|
|
165
|
+
while (EXPR_TYPE(expr_crs) != PTN_END) {
|
|
166
|
+
printf("%s%d", &spaces[space], expr_crs);
|
|
167
|
+
if (expr_crs < 100) printf(" ");
|
|
168
|
+
if (expr_crs < 10) printf(" ");
|
|
169
|
+
for (i = 0; i < 13 - (30 - space); i++) printf(" ");
|
|
170
|
+
|
|
171
|
+
switch (EXPR_TYPE(expr_crs)) {
|
|
172
|
+
case PTN_START:
|
|
173
|
+
|
|
174
|
+
printf("START\t%d\t%d\n", EXPR_PRV(expr_crs), EXPR_NXT(expr_crs));
|
|
175
|
+
break;
|
|
176
|
+
|
|
177
|
+
case PTN_GROUP:
|
|
178
|
+
|
|
179
|
+
printf("( \t%d\t%d\t-> %d\n", EXPR_PRV(expr_crs), EXPR_NXT(expr_crs),
|
|
180
|
+
EXPR_DATA_0(expr_crs));
|
|
181
|
+
space--;
|
|
182
|
+
if (space < 0) space = 0;
|
|
183
|
+
pattern_output_expression(expr_data, EXPR_DATA_0(expr_crs), table);
|
|
184
|
+
space++;
|
|
185
|
+
if (space > 30) space = 30;
|
|
186
|
+
break;
|
|
187
|
+
|
|
188
|
+
case PTN_NOT:
|
|
189
|
+
|
|
190
|
+
printf("! \t%d\t%d\t-> %d\n", EXPR_PRV(expr_crs), EXPR_NXT(expr_crs),
|
|
191
|
+
EXPR_DATA_0(expr_crs));
|
|
192
|
+
space--;
|
|
193
|
+
if (space < 0) space = 0;
|
|
194
|
+
pattern_output_expression(expr_data, EXPR_DATA_0(expr_crs), table);
|
|
195
|
+
space++;
|
|
196
|
+
if (space > 30) space = 30;
|
|
197
|
+
break;
|
|
198
|
+
|
|
199
|
+
case PTN_ONE_MORE:
|
|
200
|
+
|
|
201
|
+
printf("+ \t%d\t%d\t-> %d\t#%d\n", EXPR_PRV(expr_crs), EXPR_NXT(expr_crs),
|
|
202
|
+
EXPR_DATA_0(expr_crs), EXPR_DATA_1(expr_crs));
|
|
203
|
+
space--;
|
|
204
|
+
if (space < 0) space = 0;
|
|
205
|
+
pattern_output_expression(expr_data, EXPR_DATA_0(expr_crs), table);
|
|
206
|
+
space++;
|
|
207
|
+
if (space > 30) space = 30;
|
|
208
|
+
break;
|
|
209
|
+
|
|
210
|
+
case PTN_ZERO_MORE:
|
|
211
|
+
|
|
212
|
+
printf("* \t%d\t%d\t-> %d\t#%d\n", EXPR_PRV(expr_crs), EXPR_NXT(expr_crs),
|
|
213
|
+
EXPR_DATA_0(expr_crs), EXPR_DATA_1(expr_crs));
|
|
214
|
+
space--;
|
|
215
|
+
if (space < 0) space = 0;
|
|
216
|
+
pattern_output_expression(expr_data, EXPR_DATA_0(expr_crs), table);
|
|
217
|
+
space++;
|
|
218
|
+
if (space > 30) space = 30;
|
|
219
|
+
break;
|
|
220
|
+
|
|
221
|
+
case PTN_OPTIONAL:
|
|
222
|
+
|
|
223
|
+
printf("? \t%d\t%d\t-> %d\n", EXPR_PRV(expr_crs), EXPR_NXT(expr_crs),
|
|
224
|
+
EXPR_DATA_0(expr_crs));
|
|
225
|
+
space--;
|
|
226
|
+
if (space < 0) space = 0;
|
|
227
|
+
pattern_output_expression(expr_data, EXPR_DATA_0(expr_crs), table);
|
|
228
|
+
space++;
|
|
229
|
+
if (space > 30) space = 30;
|
|
230
|
+
break;
|
|
231
|
+
|
|
232
|
+
case PTN_ALTERNATE:
|
|
233
|
+
|
|
234
|
+
printf("| \t%d\t%d\t-> %d\t-> %d\n", EXPR_PRV(expr_crs),
|
|
235
|
+
EXPR_NXT(expr_crs), EXPR_DATA_0(expr_crs), EXPR_DATA_1(expr_crs));
|
|
236
|
+
space--;
|
|
237
|
+
if (space < 0) space = 0;
|
|
238
|
+
pattern_output_expression(expr_data, EXPR_DATA_0(expr_crs), table);
|
|
239
|
+
pattern_output_expression(expr_data, EXPR_DATA_1(expr_crs), table);
|
|
240
|
+
space++;
|
|
241
|
+
if (space > 30) space = 30;
|
|
242
|
+
break;
|
|
243
|
+
|
|
244
|
+
case PTN_ANY:
|
|
245
|
+
|
|
246
|
+
printf(". \t%d\t%d\n", EXPR_PRV(expr_crs), EXPR_NXT(expr_crs));
|
|
247
|
+
break;
|
|
248
|
+
|
|
249
|
+
case PTN_ATTRIBUTES:
|
|
250
|
+
|
|
251
|
+
printf("%% \t%d\t%d\t", EXPR_PRV(expr_crs), EXPR_NXT(expr_crs));
|
|
252
|
+
if (EXPR_DATA_0(expr_crs) & (table->numberedAttributes[0] >> 16)) printf("0");
|
|
253
|
+
if (EXPR_DATA_0(expr_crs) & (table->numberedAttributes[1] >> 16)) printf("1");
|
|
254
|
+
if (EXPR_DATA_0(expr_crs) & (table->numberedAttributes[2] >> 16)) printf("2");
|
|
255
|
+
if (EXPR_DATA_0(expr_crs) & (table->numberedAttributes[3] >> 16)) printf("3");
|
|
256
|
+
if (EXPR_DATA_0(expr_crs) & (table->numberedAttributes[4] >> 16)) printf("4");
|
|
257
|
+
if (EXPR_DATA_0(expr_crs) & (table->numberedAttributes[5] >> 16)) printf("5");
|
|
258
|
+
if (EXPR_DATA_0(expr_crs) & (table->numberedAttributes[6] >> 16)) printf("6");
|
|
259
|
+
if (EXPR_DATA_0(expr_crs) & (table->numberedAttributes[7] >> 16)) printf("7");
|
|
260
|
+
if (EXPR_DATA_0(expr_crs) & (CTC_EndOfInput >> 16)) printf("^");
|
|
261
|
+
if (EXPR_DATA_1(expr_crs) & CTC_Space) printf("_");
|
|
262
|
+
if (EXPR_DATA_1(expr_crs) & CTC_Digit) printf("#");
|
|
263
|
+
if (EXPR_DATA_1(expr_crs) & CTC_Letter) printf("a");
|
|
264
|
+
if (EXPR_DATA_1(expr_crs) & CTC_UpperCase) printf("u");
|
|
265
|
+
if (EXPR_DATA_1(expr_crs) & CTC_LowerCase) printf("l");
|
|
266
|
+
if (EXPR_DATA_1(expr_crs) & CTC_Punctuation) printf(".");
|
|
267
|
+
if (EXPR_DATA_1(expr_crs) & CTC_Sign) printf("$");
|
|
268
|
+
if (EXPR_DATA_1(expr_crs) & CTC_SeqDelimiter) printf("~");
|
|
269
|
+
if (EXPR_DATA_1(expr_crs) & CTC_SeqBefore) printf("<");
|
|
270
|
+
if (EXPR_DATA_1(expr_crs) & CTC_SeqAfter) printf(">");
|
|
271
|
+
puts("");
|
|
272
|
+
break;
|
|
273
|
+
|
|
274
|
+
case PTN_CHARS:
|
|
275
|
+
|
|
276
|
+
printf("[] \t%d\t%d\t", EXPR_PRV(expr_crs), EXPR_NXT(expr_crs));
|
|
277
|
+
for (i = 0; i < EXPR_DATA_0(expr_crs); i++)
|
|
278
|
+
printf("%c", EXPR_CONST_DATA(expr_crs)[i + 1]);
|
|
279
|
+
puts("");
|
|
280
|
+
break;
|
|
281
|
+
|
|
282
|
+
case PTN_HOOK:
|
|
283
|
+
|
|
284
|
+
printf("@ \t%d\t%d\t", EXPR_PRV(expr_crs), EXPR_NXT(expr_crs));
|
|
285
|
+
for (i = 0; i < EXPR_DATA_0(expr_crs); i++)
|
|
286
|
+
printf("%c", EXPR_CONST_DATA(expr_crs)[i + 1]);
|
|
287
|
+
puts("");
|
|
288
|
+
break;
|
|
289
|
+
|
|
290
|
+
case PTN_END_OF_INPUT:
|
|
291
|
+
|
|
292
|
+
printf("^ \t%d\t%d\n", EXPR_PRV(expr_crs), EXPR_NXT(expr_crs));
|
|
293
|
+
break;
|
|
294
|
+
|
|
295
|
+
default:
|
|
296
|
+
|
|
297
|
+
printf("%d? \t%d\t%d\n", EXPR_TYPE(expr_crs), EXPR_PRV(expr_crs),
|
|
298
|
+
EXPR_NXT(expr_crs));
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
expr_crs = EXPR_NXT(expr_crs);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
printf("%s%d", &spaces[space], expr_crs);
|
|
306
|
+
if (expr_crs < 100) printf(" ");
|
|
307
|
+
if (expr_crs < 10) printf(" ");
|
|
308
|
+
for (i = 0; i < 13 - (30 - space); i++) printf(" ");
|
|
309
|
+
printf("END\t%d\t%d\n", EXPR_PRV(expr_crs), EXPR_NXT(expr_crs));
|
|
310
|
+
fflush(stdout);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
static void
|
|
315
|
+
pattern_output(const widechar *expr_data, const TranslationTableHeader *table) {
|
|
316
|
+
printf("%d \tlength\n", expr_data[0]);
|
|
317
|
+
printf("%d \tloops\n", expr_data[1]);
|
|
318
|
+
if (expr_data[0] > 0 && expr_data[0] != PTN_END)
|
|
319
|
+
pattern_output_expression(expr_data, 2, table);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
static void
|
|
323
|
+
pattern_print_expression(
|
|
324
|
+
const widechar *expr_data, int expr_crs, const TranslationTableHeader *table) {
|
|
325
|
+
int i;
|
|
326
|
+
|
|
327
|
+
if (expr_crs == PTN_END) return;
|
|
328
|
+
|
|
329
|
+
while (EXPR_TYPE(expr_crs) != PTN_END) {
|
|
330
|
+
switch (EXPR_TYPE(expr_crs)) {
|
|
331
|
+
case PTN_START:
|
|
332
|
+
break;
|
|
333
|
+
|
|
334
|
+
case PTN_GROUP:
|
|
335
|
+
|
|
336
|
+
printf(" (");
|
|
337
|
+
pattern_print_expression(expr_data, EXPR_DATA_0(expr_crs), table);
|
|
338
|
+
printf(") ");
|
|
339
|
+
break;
|
|
340
|
+
|
|
341
|
+
case PTN_NOT:
|
|
342
|
+
|
|
343
|
+
printf("!");
|
|
344
|
+
pattern_print_expression(expr_data, EXPR_DATA_0(expr_crs), table);
|
|
345
|
+
break;
|
|
346
|
+
|
|
347
|
+
case PTN_ONE_MORE:
|
|
348
|
+
|
|
349
|
+
pattern_print_expression(expr_data, EXPR_DATA_0(expr_crs), table);
|
|
350
|
+
printf("+");
|
|
351
|
+
break;
|
|
352
|
+
|
|
353
|
+
case PTN_ZERO_MORE:
|
|
354
|
+
|
|
355
|
+
pattern_print_expression(expr_data, EXPR_DATA_0(expr_crs), table);
|
|
356
|
+
printf("*");
|
|
357
|
+
break;
|
|
358
|
+
|
|
359
|
+
case PTN_OPTIONAL:
|
|
360
|
+
|
|
361
|
+
pattern_print_expression(expr_data, EXPR_DATA_0(expr_crs), table);
|
|
362
|
+
printf("?");
|
|
363
|
+
break;
|
|
364
|
+
|
|
365
|
+
case PTN_ALTERNATE:
|
|
366
|
+
|
|
367
|
+
pattern_print_expression(expr_data, EXPR_DATA_0(expr_crs), table);
|
|
368
|
+
printf(" | ");
|
|
369
|
+
pattern_print_expression(expr_data, EXPR_DATA_1(expr_crs), table);
|
|
370
|
+
break;
|
|
371
|
+
|
|
372
|
+
case PTN_ANY:
|
|
373
|
+
|
|
374
|
+
printf(".");
|
|
375
|
+
break;
|
|
376
|
+
|
|
377
|
+
case PTN_ATTRIBUTES:
|
|
378
|
+
|
|
379
|
+
printf("%%[");
|
|
380
|
+
if (EXPR_DATA_0(expr_crs) & (table->numberedAttributes[0] >> 16)) printf("0");
|
|
381
|
+
if (EXPR_DATA_0(expr_crs) & (table->numberedAttributes[1] >> 16)) printf("1");
|
|
382
|
+
if (EXPR_DATA_0(expr_crs) & (table->numberedAttributes[2] >> 16)) printf("2");
|
|
383
|
+
if (EXPR_DATA_0(expr_crs) & (table->numberedAttributes[3] >> 16)) printf("3");
|
|
384
|
+
if (EXPR_DATA_0(expr_crs) & (table->numberedAttributes[4] >> 16)) printf("4");
|
|
385
|
+
if (EXPR_DATA_0(expr_crs) & (table->numberedAttributes[5] >> 16)) printf("5");
|
|
386
|
+
if (EXPR_DATA_0(expr_crs) & (table->numberedAttributes[6] >> 16)) printf("6");
|
|
387
|
+
if (EXPR_DATA_0(expr_crs) & (table->numberedAttributes[7] >> 16)) printf("7");
|
|
388
|
+
if (EXPR_DATA_0(expr_crs) & (CTC_EndOfInput >> 16)) printf("^");
|
|
389
|
+
if (EXPR_DATA_1(expr_crs) & CTC_Space) printf("_");
|
|
390
|
+
if (EXPR_DATA_1(expr_crs) & CTC_Digit) printf("#");
|
|
391
|
+
if (EXPR_DATA_1(expr_crs) & CTC_Letter) printf("a");
|
|
392
|
+
if (EXPR_DATA_1(expr_crs) & CTC_UpperCase) printf("u");
|
|
393
|
+
if (EXPR_DATA_1(expr_crs) & CTC_LowerCase) printf("l");
|
|
394
|
+
if (EXPR_DATA_1(expr_crs) & CTC_Punctuation) printf(".");
|
|
395
|
+
if (EXPR_DATA_1(expr_crs) & CTC_Sign) printf("$");
|
|
396
|
+
if (EXPR_DATA_1(expr_crs) & CTC_SeqDelimiter) printf("~");
|
|
397
|
+
if (EXPR_DATA_1(expr_crs) & CTC_SeqBefore) printf("<");
|
|
398
|
+
if (EXPR_DATA_1(expr_crs) & CTC_SeqAfter) printf(">");
|
|
399
|
+
printf("]");
|
|
400
|
+
break;
|
|
401
|
+
|
|
402
|
+
case PTN_CHARS:
|
|
403
|
+
|
|
404
|
+
if (EXPR_DATA_0(expr_crs) == 1)
|
|
405
|
+
printf("%c", EXPR_DATA_1(expr_crs));
|
|
406
|
+
else {
|
|
407
|
+
printf("[");
|
|
408
|
+
for (i = 0; i < EXPR_DATA_0(expr_crs); i++)
|
|
409
|
+
printf("%c", EXPR_CONST_DATA(expr_crs)[i + 1]);
|
|
410
|
+
printf("]");
|
|
411
|
+
}
|
|
412
|
+
break;
|
|
413
|
+
|
|
414
|
+
case PTN_HOOK:
|
|
415
|
+
|
|
416
|
+
printf("@[");
|
|
417
|
+
for (i = 0; i < EXPR_DATA_0(expr_crs); i++)
|
|
418
|
+
printf("%c", EXPR_CONST_DATA(expr_crs)[i + 1]);
|
|
419
|
+
printf("]");
|
|
420
|
+
break;
|
|
421
|
+
|
|
422
|
+
case PTN_END_OF_INPUT:
|
|
423
|
+
|
|
424
|
+
printf("^");
|
|
425
|
+
break;
|
|
426
|
+
|
|
427
|
+
// default: printf("%d?\n", EXPR_TYPE(expr_crs)); break;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
expr_crs = EXPR_NXT(expr_crs);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
static void
|
|
437
|
+
pattern_print(const widechar *expr_data, const TranslationTableHeader *table) {
|
|
438
|
+
if (expr_data[0] > 0 && expr_data[0] != PTN_END)
|
|
439
|
+
pattern_print_expression(expr_data, 2, table);
|
|
440
|
+
puts("");
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
#ifdef CHECK_OUTPUT_DEFINED
|
|
444
|
+
|
|
445
|
+
static void
|
|
446
|
+
do_padd(const int value) {
|
|
447
|
+
if (value < 100000) printf(" ");
|
|
448
|
+
if (value < 10000) printf(" ");
|
|
449
|
+
if (value < 1000) printf(" ");
|
|
450
|
+
if (value < 100) printf(" ");
|
|
451
|
+
if (value < 10) printf(" ");
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
static void
|
|
455
|
+
do_pad(const int value) {
|
|
456
|
+
if (value < 100) printf(" ");
|
|
457
|
+
if (value < 10) printf(" ");
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
static void
|
|
461
|
+
do_output(const int type, const int ret, const int line,
|
|
462
|
+
|
|
463
|
+
const int input, const int input_minmax, const int input_crs, const int input_dir,
|
|
464
|
+
const widechar *expr_data, const int expr_crs, const int notOperator,
|
|
465
|
+
const int loop_crs, const int *loop_cnts,
|
|
466
|
+
|
|
467
|
+
const char *msg) {
|
|
468
|
+
switch (type) {
|
|
469
|
+
case START:
|
|
470
|
+
|
|
471
|
+
space--;
|
|
472
|
+
if (space < 0) space = 0;
|
|
473
|
+
printf("|%s() ", &spaces[space]);
|
|
474
|
+
break;
|
|
475
|
+
|
|
476
|
+
case CALL:
|
|
477
|
+
|
|
478
|
+
printf("|%s> ", &spaces[space]);
|
|
479
|
+
break;
|
|
480
|
+
|
|
481
|
+
case RETURN:
|
|
482
|
+
|
|
483
|
+
printf("|%s<%d ", &spaces[space], ret);
|
|
484
|
+
space++;
|
|
485
|
+
if (space > 31) space = 31;
|
|
486
|
+
break;
|
|
487
|
+
|
|
488
|
+
case SHOW:
|
|
489
|
+
|
|
490
|
+
printf("|%s ", &spaces[space]);
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
printf("%d ", line);
|
|
495
|
+
do_padd(line);
|
|
496
|
+
|
|
497
|
+
switch (expr_data[expr_crs]) {
|
|
498
|
+
case PTN_ERROR:
|
|
499
|
+
printf("# ");
|
|
500
|
+
break;
|
|
501
|
+
case PTN_START:
|
|
502
|
+
printf("> ");
|
|
503
|
+
break;
|
|
504
|
+
case PTN_END_OF_INPUT:
|
|
505
|
+
printf("^ ");
|
|
506
|
+
break;
|
|
507
|
+
case PTN_ALTERNATE:
|
|
508
|
+
printf("| ");
|
|
509
|
+
break;
|
|
510
|
+
case PTN_OPTIONAL:
|
|
511
|
+
printf("? ");
|
|
512
|
+
break;
|
|
513
|
+
case PTN_ONE_MORE:
|
|
514
|
+
printf("+ ");
|
|
515
|
+
break;
|
|
516
|
+
case PTN_ZERO_MORE:
|
|
517
|
+
printf("* ");
|
|
518
|
+
break;
|
|
519
|
+
case PTN_NOT:
|
|
520
|
+
printf("! ");
|
|
521
|
+
break;
|
|
522
|
+
case PTN_GROUP:
|
|
523
|
+
printf("( ");
|
|
524
|
+
break;
|
|
525
|
+
case PTN_ANY:
|
|
526
|
+
printf(". ");
|
|
527
|
+
break;
|
|
528
|
+
case PTN_ATTRIBUTES:
|
|
529
|
+
printf("%% ");
|
|
530
|
+
break;
|
|
531
|
+
case PTN_CHARS:
|
|
532
|
+
printf("[ ");
|
|
533
|
+
break;
|
|
534
|
+
case PTN_HOOK:
|
|
535
|
+
printf("@ ");
|
|
536
|
+
break;
|
|
537
|
+
case PTN_END:
|
|
538
|
+
printf("< ");
|
|
539
|
+
break;
|
|
540
|
+
default:
|
|
541
|
+
printf(" ");
|
|
542
|
+
break;
|
|
543
|
+
}
|
|
544
|
+
printf("%d ", expr_crs);
|
|
545
|
+
do_padd(expr_crs);
|
|
546
|
+
|
|
547
|
+
if (input > 31 && input < 127)
|
|
548
|
+
printf("%c ", input);
|
|
549
|
+
else
|
|
550
|
+
printf("_ ");
|
|
551
|
+
|
|
552
|
+
if (input_crs * input_dir >= input_minmax * input_dir)
|
|
553
|
+
printf("# ");
|
|
554
|
+
else {
|
|
555
|
+
printf("%d ", input_crs);
|
|
556
|
+
do_pad(input_crs);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
if (input_dir > 0)
|
|
560
|
+
printf("<");
|
|
561
|
+
else
|
|
562
|
+
printf(">");
|
|
563
|
+
printf("%d ", input_minmax);
|
|
564
|
+
do_pad(input_minmax);
|
|
565
|
+
|
|
566
|
+
if (notOperator)
|
|
567
|
+
printf("! ");
|
|
568
|
+
else
|
|
569
|
+
printf(" ");
|
|
570
|
+
|
|
571
|
+
if (loop_crs) {
|
|
572
|
+
printf("%d ", loop_crs);
|
|
573
|
+
do_pad(loop_crs);
|
|
574
|
+
printf("%d ", loop_cnts[EXPR_DATA_1(loop_crs)]);
|
|
575
|
+
do_pad(loop_cnts[EXPR_DATA_1(loop_crs)]);
|
|
576
|
+
} else
|
|
577
|
+
printf("- - ");
|
|
578
|
+
if (EXPR_TYPE(expr_crs) == PTN_ONE_MORE || EXPR_TYPE(expr_crs) == PTN_ZERO_MORE) {
|
|
579
|
+
printf("%d ", loop_cnts[EXPR_DATA_1(expr_crs)]);
|
|
580
|
+
do_pad(loop_cnts[EXPR_DATA_1(expr_crs)]);
|
|
581
|
+
} else
|
|
582
|
+
printf("- ");
|
|
583
|
+
|
|
584
|
+
if (msg) printf("%s", msg);
|
|
585
|
+
puts("");
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
#endif
|
|
589
|
+
|
|
590
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
591
|
+
|
|
592
|
+
static int
|
|
593
|
+
pattern_compile_1(const widechar *input, const int input_max, int *input_crs,
|
|
594
|
+
widechar *expr_data, const int expr_max, widechar *expr_crs, widechar *loop_cnts,
|
|
595
|
+
TranslationTableHeader *table, const FileInfo *nested);
|
|
596
|
+
|
|
597
|
+
static int
|
|
598
|
+
pattern_compile_expression(const widechar *input, const int input_max, int *input_crs,
|
|
599
|
+
widechar *expr_data, const int expr_max, widechar *expr_crs, widechar *loop_cnts,
|
|
600
|
+
TranslationTableHeader *table, const FileInfo *nested) {
|
|
601
|
+
widechar *data;
|
|
602
|
+
int expr_start, expr_end, expr_sub, expr_crs_prv;
|
|
603
|
+
int input_end;
|
|
604
|
+
int attrs0, attrs1;
|
|
605
|
+
int set, esc, nest, i;
|
|
606
|
+
|
|
607
|
+
if (*input_crs >= input_max) return 0;
|
|
608
|
+
switch (input[*input_crs]) {
|
|
609
|
+
case '(':
|
|
610
|
+
|
|
611
|
+
if (*expr_crs + 10 >= expr_max) return 0;
|
|
612
|
+
|
|
613
|
+
(*input_crs)++;
|
|
614
|
+
if (*input_crs >= input_max) return 0;
|
|
615
|
+
|
|
616
|
+
/* find closing parenthesis */
|
|
617
|
+
nest = esc = 0;
|
|
618
|
+
for (input_end = *input_crs; input_end < input_max; input_end++) {
|
|
619
|
+
if (input[input_end] == '\\' && !esc) {
|
|
620
|
+
esc = 1;
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
if (input[input_end] == '(' && !esc)
|
|
625
|
+
nest++;
|
|
626
|
+
else if (input[input_end] == ')' && !esc) {
|
|
627
|
+
if (nest)
|
|
628
|
+
nest--;
|
|
629
|
+
else
|
|
630
|
+
break;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
esc = 0;
|
|
634
|
+
}
|
|
635
|
+
if (input_end >= input_max) return 0;
|
|
636
|
+
|
|
637
|
+
EXPR_TYPE(*expr_crs) = PTN_GROUP;
|
|
638
|
+
|
|
639
|
+
/* compile sub expressions */
|
|
640
|
+
expr_crs_prv = *expr_crs;
|
|
641
|
+
*expr_crs += 4;
|
|
642
|
+
EXPR_DATA_0(expr_crs_prv) = *expr_crs;
|
|
643
|
+
expr_sub = *expr_crs;
|
|
644
|
+
EXPR_TYPE(expr_sub) = PTN_ERROR;
|
|
645
|
+
EXPR_PRV(expr_sub) = PTN_END;
|
|
646
|
+
EXPR_NXT(expr_sub) = PTN_END;
|
|
647
|
+
if (!pattern_compile_1(input, input_end, input_crs, expr_data, expr_max, expr_crs,
|
|
648
|
+
loop_cnts, table, nested))
|
|
649
|
+
return 0;
|
|
650
|
+
(*input_crs)++;
|
|
651
|
+
|
|
652
|
+
/* reset end expression */
|
|
653
|
+
expr_end = *expr_crs;
|
|
654
|
+
EXPR_NXT(expr_end) = expr_crs_prv;
|
|
655
|
+
|
|
656
|
+
return *expr_crs += 3;
|
|
657
|
+
|
|
658
|
+
case '!':
|
|
659
|
+
|
|
660
|
+
if (*expr_crs + 10 >= expr_max) return 0;
|
|
661
|
+
|
|
662
|
+
(*input_crs)++;
|
|
663
|
+
EXPR_TYPE(*expr_crs) = PTN_NOT;
|
|
664
|
+
expr_crs_prv = *expr_crs;
|
|
665
|
+
*expr_crs += 4;
|
|
666
|
+
EXPR_DATA_0(expr_crs_prv) = *expr_crs;
|
|
667
|
+
|
|
668
|
+
/* create start expression */
|
|
669
|
+
expr_start = *expr_crs;
|
|
670
|
+
EXPR_TYPE(expr_start) = PTN_START;
|
|
671
|
+
EXPR_PRV(expr_start) = PTN_END;
|
|
672
|
+
*expr_crs += 3;
|
|
673
|
+
EXPR_NXT(expr_start) = *expr_crs;
|
|
674
|
+
|
|
675
|
+
/* compile sub expression */
|
|
676
|
+
expr_sub = *expr_crs;
|
|
677
|
+
EXPR_TYPE(expr_sub) = PTN_ERROR;
|
|
678
|
+
EXPR_PRV(expr_sub) = expr_start;
|
|
679
|
+
EXPR_NXT(expr_sub) = PTN_END;
|
|
680
|
+
|
|
681
|
+
if (!pattern_compile_expression(input, input_max, input_crs, expr_data, expr_max,
|
|
682
|
+
expr_crs, loop_cnts, table, nested))
|
|
683
|
+
return 0;
|
|
684
|
+
|
|
685
|
+
if (*expr_crs + 3 >= expr_max) return 0;
|
|
686
|
+
|
|
687
|
+
EXPR_NXT(expr_sub) = *expr_crs;
|
|
688
|
+
|
|
689
|
+
/* create end expression */
|
|
690
|
+
expr_end = *expr_crs;
|
|
691
|
+
EXPR_TYPE(expr_end) = PTN_END;
|
|
692
|
+
EXPR_PRV(expr_end) = expr_sub;
|
|
693
|
+
EXPR_NXT(expr_end) = expr_crs_prv;
|
|
694
|
+
|
|
695
|
+
return *expr_crs += 3;
|
|
696
|
+
|
|
697
|
+
case '+':
|
|
698
|
+
|
|
699
|
+
if (*expr_crs + 5 >= expr_max) return 0;
|
|
700
|
+
EXPR_TYPE(*expr_crs) = PTN_ONE_MORE;
|
|
701
|
+
EXPR_DATA_1(*expr_crs) = (*loop_cnts)++;
|
|
702
|
+
(*input_crs)++;
|
|
703
|
+
return *expr_crs += 5;
|
|
704
|
+
|
|
705
|
+
case '*':
|
|
706
|
+
|
|
707
|
+
if (*expr_crs + 5 >= expr_max) return 0;
|
|
708
|
+
EXPR_TYPE(*expr_crs) = PTN_ZERO_MORE;
|
|
709
|
+
EXPR_DATA_1(*expr_crs) = (*loop_cnts)++;
|
|
710
|
+
(*input_crs)++;
|
|
711
|
+
return *expr_crs += 5;
|
|
712
|
+
|
|
713
|
+
case '?':
|
|
714
|
+
|
|
715
|
+
if (*expr_crs + 4 >= expr_max) return 0;
|
|
716
|
+
EXPR_TYPE(*expr_crs) = PTN_OPTIONAL;
|
|
717
|
+
(*input_crs)++;
|
|
718
|
+
return *expr_crs += 4;
|
|
719
|
+
|
|
720
|
+
case '|':
|
|
721
|
+
|
|
722
|
+
if (*expr_crs + 5 >= expr_max) return 0;
|
|
723
|
+
EXPR_TYPE(*expr_crs) = PTN_ALTERNATE;
|
|
724
|
+
(*input_crs)++;
|
|
725
|
+
return *expr_crs += 5;
|
|
726
|
+
|
|
727
|
+
case '.':
|
|
728
|
+
|
|
729
|
+
if (*expr_crs + 3 >= expr_max) return 0;
|
|
730
|
+
EXPR_TYPE(*expr_crs) = PTN_ANY;
|
|
731
|
+
(*input_crs)++;
|
|
732
|
+
return *expr_crs += 3;
|
|
733
|
+
|
|
734
|
+
case '%':
|
|
735
|
+
|
|
736
|
+
if (*expr_crs + 5 >= expr_max) return 0;
|
|
737
|
+
|
|
738
|
+
(*input_crs)++;
|
|
739
|
+
if (*input_crs >= input_max) return 0;
|
|
740
|
+
|
|
741
|
+
/* find closing bracket */
|
|
742
|
+
if (input[*input_crs] == '[') {
|
|
743
|
+
set = 1;
|
|
744
|
+
(*input_crs)++;
|
|
745
|
+
for (input_end = *input_crs; input_end < input_max; input_end++)
|
|
746
|
+
if (input[input_end] == ']') break;
|
|
747
|
+
if (input_end >= input_max) return 0;
|
|
748
|
+
} else {
|
|
749
|
+
set = 0;
|
|
750
|
+
input_end = *input_crs + 1;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
EXPR_TYPE(*expr_crs) = PTN_ATTRIBUTES;
|
|
754
|
+
|
|
755
|
+
attrs0 = attrs1 = 0;
|
|
756
|
+
for (; (*input_crs) < input_end; (*input_crs)++) {
|
|
757
|
+
switch (input[*input_crs]) {
|
|
758
|
+
case '_':
|
|
759
|
+
attrs0 |= CTC_Space;
|
|
760
|
+
break;
|
|
761
|
+
case '#':
|
|
762
|
+
attrs0 |= CTC_Digit;
|
|
763
|
+
break;
|
|
764
|
+
case 'a':
|
|
765
|
+
attrs0 |= CTC_Letter;
|
|
766
|
+
break;
|
|
767
|
+
case 'u':
|
|
768
|
+
attrs0 |= CTC_UpperCase;
|
|
769
|
+
break;
|
|
770
|
+
case 'l':
|
|
771
|
+
attrs0 |= CTC_LowerCase;
|
|
772
|
+
break;
|
|
773
|
+
case '.':
|
|
774
|
+
attrs0 |= CTC_Punctuation;
|
|
775
|
+
break;
|
|
776
|
+
case '$':
|
|
777
|
+
attrs0 |= CTC_Sign;
|
|
778
|
+
break;
|
|
779
|
+
case 'm':
|
|
780
|
+
attrs0 |= CTC_Math;
|
|
781
|
+
break;
|
|
782
|
+
case '~':
|
|
783
|
+
attrs0 |= CTC_SeqDelimiter;
|
|
784
|
+
break;
|
|
785
|
+
case '<':
|
|
786
|
+
attrs0 |= CTC_SeqBefore;
|
|
787
|
+
break;
|
|
788
|
+
case '>':
|
|
789
|
+
attrs0 |= CTC_SeqAfter;
|
|
790
|
+
break;
|
|
791
|
+
|
|
792
|
+
case '0':
|
|
793
|
+
case '1':
|
|
794
|
+
case '2':
|
|
795
|
+
case '3':
|
|
796
|
+
case '4':
|
|
797
|
+
case '5':
|
|
798
|
+
case '6':
|
|
799
|
+
case '7': {
|
|
800
|
+
int k = input[*input_crs] - '0';
|
|
801
|
+
TranslationTableCharacterAttributes a = table->numberedAttributes[k];
|
|
802
|
+
if (!a) {
|
|
803
|
+
// attribute not used before yet: assign it a value
|
|
804
|
+
a = table->numberedAttributes[k] =
|
|
805
|
+
table->nextNumberedCharacterClassAttribute;
|
|
806
|
+
if (a > CTC_UserDefined8) {
|
|
807
|
+
_lou_logMessage(LOU_LOG_ERROR,
|
|
808
|
+
"%s:%d: error: Too many character attributes defined",
|
|
809
|
+
nested->fileName, nested->lineNumber);
|
|
810
|
+
return 0;
|
|
811
|
+
}
|
|
812
|
+
table->nextNumberedCharacterClassAttribute <<= 1;
|
|
813
|
+
}
|
|
814
|
+
attrs1 |= (a >> 16);
|
|
815
|
+
break;
|
|
816
|
+
}
|
|
817
|
+
case '^':
|
|
818
|
+
attrs1 |= (CTC_EndOfInput >> 16);
|
|
819
|
+
break;
|
|
820
|
+
|
|
821
|
+
default:
|
|
822
|
+
return 0;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
EXPR_DATA_0(*expr_crs) = attrs1;
|
|
826
|
+
EXPR_DATA_1(*expr_crs) = attrs0;
|
|
827
|
+
|
|
828
|
+
if (set) (*input_crs)++;
|
|
829
|
+
return *expr_crs += 5;
|
|
830
|
+
|
|
831
|
+
case '[':
|
|
832
|
+
|
|
833
|
+
(*input_crs)++;
|
|
834
|
+
if (*input_crs >= input_max) return 0;
|
|
835
|
+
|
|
836
|
+
/* find closing bracket */
|
|
837
|
+
esc = 0;
|
|
838
|
+
for (input_end = *input_crs; input_end < input_max; input_end++) {
|
|
839
|
+
if (input[input_end] == '\\' && !esc) {
|
|
840
|
+
esc = 1;
|
|
841
|
+
continue;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
if (input[input_end] == ']' && !esc) break;
|
|
845
|
+
esc = 0;
|
|
846
|
+
}
|
|
847
|
+
if (input_end >= input_max) return 0;
|
|
848
|
+
|
|
849
|
+
if (*expr_crs + 4 + (input_end - *input_crs) >= expr_max) return 0;
|
|
850
|
+
|
|
851
|
+
EXPR_TYPE(*expr_crs) = PTN_CHARS;
|
|
852
|
+
|
|
853
|
+
esc = 0;
|
|
854
|
+
data = EXPR_DATA(*expr_crs);
|
|
855
|
+
for (i = 1; *input_crs < input_end; (*input_crs)++) {
|
|
856
|
+
if (input[*input_crs] == '\\' && !esc) {
|
|
857
|
+
esc = 1;
|
|
858
|
+
continue;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
esc = 0;
|
|
862
|
+
data[i++] = (widechar)input[*input_crs];
|
|
863
|
+
}
|
|
864
|
+
data[0] = i - 1;
|
|
865
|
+
(*input_crs)++;
|
|
866
|
+
return *expr_crs += 4 + data[0];
|
|
867
|
+
|
|
868
|
+
case '@':
|
|
869
|
+
|
|
870
|
+
(*input_crs)++;
|
|
871
|
+
if (*input_crs >= input_max) return 0;
|
|
872
|
+
|
|
873
|
+
/* find closing bracket */
|
|
874
|
+
if (input[*input_crs] == '[') {
|
|
875
|
+
set = 1;
|
|
876
|
+
(*input_crs)++;
|
|
877
|
+
for (input_end = *input_crs; input_end < input_max; input_end++)
|
|
878
|
+
if (input[input_end] == ']') break;
|
|
879
|
+
if (input_end >= input_max) return 0;
|
|
880
|
+
} else {
|
|
881
|
+
set = 0;
|
|
882
|
+
input_end = *input_crs + 1;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
if (*expr_crs + 4 + (input_end - *input_crs) >= expr_max) return 0;
|
|
886
|
+
|
|
887
|
+
EXPR_TYPE(*expr_crs) = PTN_HOOK;
|
|
888
|
+
|
|
889
|
+
esc = 0;
|
|
890
|
+
data = EXPR_DATA(*expr_crs);
|
|
891
|
+
for (i = 1; *input_crs < input_end; (*input_crs)++) {
|
|
892
|
+
if (input[*input_crs] == '\\' && !esc) {
|
|
893
|
+
esc = 1;
|
|
894
|
+
continue;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
esc = 0;
|
|
898
|
+
data[i++] = (widechar)input[*input_crs];
|
|
899
|
+
}
|
|
900
|
+
data[0] = i - 1;
|
|
901
|
+
if (set) (*input_crs)++;
|
|
902
|
+
return *expr_crs += 4 + data[0];
|
|
903
|
+
|
|
904
|
+
case '^':
|
|
905
|
+
case '$':
|
|
906
|
+
|
|
907
|
+
if (*expr_crs + 3 >= expr_max) return 0;
|
|
908
|
+
EXPR_TYPE(*expr_crs) = PTN_END_OF_INPUT;
|
|
909
|
+
(*input_crs)++;
|
|
910
|
+
return *expr_crs += 3;
|
|
911
|
+
|
|
912
|
+
case '\\':
|
|
913
|
+
|
|
914
|
+
(*input_crs)++;
|
|
915
|
+
if (*input_crs >= input_max) return 0;
|
|
916
|
+
|
|
917
|
+
default:
|
|
918
|
+
|
|
919
|
+
if (*expr_crs + 5 >= expr_max) return 0;
|
|
920
|
+
EXPR_TYPE(*expr_crs) = PTN_CHARS;
|
|
921
|
+
EXPR_DATA_0(*expr_crs) = 1;
|
|
922
|
+
EXPR_DATA_1(*expr_crs) = (widechar)input[*input_crs];
|
|
923
|
+
(*input_crs)++;
|
|
924
|
+
return *expr_crs += 5;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
static int
|
|
929
|
+
pattern_insert_alternate(const widechar *input, const int input_max, int *input_crs,
|
|
930
|
+
widechar *expr_data, const int expr_max, widechar *expr_crs, widechar *loop_cnts,
|
|
931
|
+
int expr_insert, TranslationTableHeader *table, const FileInfo *nested) {
|
|
932
|
+
int expr_group, expr_alt, expr_end;
|
|
933
|
+
|
|
934
|
+
if (EXPR_TYPE(*expr_crs) == PTN_START) return 0;
|
|
935
|
+
|
|
936
|
+
if (*expr_crs + 12 >= expr_max) return 0;
|
|
937
|
+
|
|
938
|
+
/* setup alternate expression */
|
|
939
|
+
expr_alt = *expr_crs;
|
|
940
|
+
EXPR_TYPE(expr_alt) = PTN_ALTERNATE;
|
|
941
|
+
EXPR_PRV(expr_alt) = PTN_END;
|
|
942
|
+
EXPR_NXT(expr_alt) = PTN_END;
|
|
943
|
+
*expr_crs += 5;
|
|
944
|
+
|
|
945
|
+
/* setup group expression */
|
|
946
|
+
expr_group = *expr_crs;
|
|
947
|
+
EXPR_TYPE(expr_group) = PTN_GROUP;
|
|
948
|
+
EXPR_PRV(expr_group) = PTN_END;
|
|
949
|
+
EXPR_NXT(expr_group) = PTN_END;
|
|
950
|
+
*expr_crs += 4;
|
|
951
|
+
EXPR_DATA_0(expr_group) = *expr_crs;
|
|
952
|
+
|
|
953
|
+
EXPR_TYPE(*expr_crs) = PTN_ERROR;
|
|
954
|
+
EXPR_PRV(*expr_crs) = PTN_END;
|
|
955
|
+
EXPR_NXT(*expr_crs) = PTN_END;
|
|
956
|
+
if (!pattern_compile_1(input, input_max, input_crs, expr_data, expr_max, expr_crs,
|
|
957
|
+
loop_cnts, table, nested))
|
|
958
|
+
return 0;
|
|
959
|
+
expr_end = *expr_crs;
|
|
960
|
+
EXPR_NXT(expr_end) = expr_group;
|
|
961
|
+
|
|
962
|
+
/* setup last end expression */
|
|
963
|
+
if (*expr_crs + 3 >= expr_max) return 0;
|
|
964
|
+
*expr_crs += 3;
|
|
965
|
+
EXPR_TYPE(*expr_crs) = PTN_END;
|
|
966
|
+
EXPR_NXT(*expr_crs) = PTN_END;
|
|
967
|
+
|
|
968
|
+
/* replace insert expression with group expression using last end expression */
|
|
969
|
+
EXPR_NXT(EXPR_PRV(expr_insert)) = expr_group;
|
|
970
|
+
EXPR_PRV(expr_group) = EXPR_PRV(expr_insert);
|
|
971
|
+
|
|
972
|
+
EXPR_NXT(expr_group) = *expr_crs;
|
|
973
|
+
EXPR_PRV(*expr_crs) = expr_group;
|
|
974
|
+
|
|
975
|
+
/* link alternate and insert expressions before group end expression */
|
|
976
|
+
EXPR_NXT(EXPR_PRV(expr_end)) = expr_alt;
|
|
977
|
+
EXPR_PRV(expr_alt) = EXPR_PRV(expr_end);
|
|
978
|
+
|
|
979
|
+
EXPR_NXT(expr_alt) = expr_insert;
|
|
980
|
+
EXPR_PRV(expr_insert) = expr_alt;
|
|
981
|
+
|
|
982
|
+
EXPR_NXT(expr_insert) = expr_end;
|
|
983
|
+
EXPR_PRV(expr_end) = expr_insert;
|
|
984
|
+
|
|
985
|
+
return *expr_crs;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/* Compile all expression sequences, resolving character sets, attributes,
|
|
989
|
+
* groups, nots, and hooks. Note that unlike the other compile functions, on
|
|
990
|
+
* returning the expr_crs is set to the last end expression, not after it.
|
|
991
|
+
*/
|
|
992
|
+
static int
|
|
993
|
+
pattern_compile_1(const widechar *input, const int input_max, int *input_crs,
|
|
994
|
+
widechar *expr_data, const int expr_max, widechar *expr_crs, widechar *loop_cnts,
|
|
995
|
+
TranslationTableHeader *table, const FileInfo *nested) {
|
|
996
|
+
int expr_crs_prv;
|
|
997
|
+
|
|
998
|
+
if (*expr_crs + 6 >= expr_max) return 0;
|
|
999
|
+
|
|
1000
|
+
expr_crs_prv = *expr_crs;
|
|
1001
|
+
|
|
1002
|
+
/* setup start expression */
|
|
1003
|
+
EXPR_TYPE(*expr_crs) = PTN_START;
|
|
1004
|
+
EXPR_PRV(*expr_crs) = PTN_END;
|
|
1005
|
+
*expr_crs += 3;
|
|
1006
|
+
EXPR_NXT(expr_crs_prv) = *expr_crs;
|
|
1007
|
+
|
|
1008
|
+
/* setup end expression */
|
|
1009
|
+
EXPR_TYPE(*expr_crs) = PTN_END;
|
|
1010
|
+
EXPR_PRV(*expr_crs) = expr_crs_prv;
|
|
1011
|
+
EXPR_NXT(*expr_crs) = PTN_END;
|
|
1012
|
+
|
|
1013
|
+
while (*input_crs < input_max) {
|
|
1014
|
+
expr_crs_prv = *expr_crs;
|
|
1015
|
+
if (!pattern_compile_expression(input, input_max, input_crs, expr_data, expr_max,
|
|
1016
|
+
expr_crs, loop_cnts, table, nested))
|
|
1017
|
+
return 0;
|
|
1018
|
+
|
|
1019
|
+
/* setup end expression */
|
|
1020
|
+
if (*expr_crs + 3 >= expr_max) return 0;
|
|
1021
|
+
EXPR_NXT(expr_crs_prv) = *expr_crs;
|
|
1022
|
+
EXPR_TYPE(*expr_crs) = PTN_END;
|
|
1023
|
+
EXPR_PRV(*expr_crs) = expr_crs_prv;
|
|
1024
|
+
EXPR_NXT(*expr_crs) = PTN_END;
|
|
1025
|
+
|
|
1026
|
+
/* insert seqafterexpression before attributes of seqafterchars */
|
|
1027
|
+
// if(EXPR_TYPE(expr_crs_prv) == PTN_ATTRIBUTES)
|
|
1028
|
+
// if(EXPR_DATA_1(expr_crs_prv) & CTC_SeqAfter)
|
|
1029
|
+
// {
|
|
1030
|
+
// i = 0;
|
|
1031
|
+
// pattern_insert_alternate(table->seqAfterExpression,
|
|
1032
|
+
// table->seqAfterExpressionLength, &i, expr_data, expr_max,
|
|
1033
|
+
// expr_crs, loop_cnts, expr_crs_prv);
|
|
1034
|
+
// }
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
return *expr_crs;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
/* Resolve optional and loop expressions.
|
|
1041
|
+
*/
|
|
1042
|
+
static int
|
|
1043
|
+
pattern_compile_2(
|
|
1044
|
+
widechar *expr_data, int expr_at, const int expr_max, widechar *expr_crs) {
|
|
1045
|
+
int expr_start, expr_end, expr_prv, expr_sub;
|
|
1046
|
+
|
|
1047
|
+
while (EXPR_TYPE(expr_at) != PTN_END) {
|
|
1048
|
+
if (EXPR_TYPE(expr_at) == PTN_GROUP || EXPR_TYPE(expr_at) == PTN_NOT) {
|
|
1049
|
+
if (!pattern_compile_2(expr_data, EXPR_DATA_0(expr_at), expr_max, expr_crs))
|
|
1050
|
+
return 0;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
if (EXPR_TYPE(expr_at) == PTN_ZERO_MORE || EXPR_TYPE(expr_at) == PTN_ONE_MORE ||
|
|
1054
|
+
EXPR_TYPE(expr_at) == PTN_OPTIONAL) {
|
|
1055
|
+
if (*expr_crs + 6 >= expr_max) return 0;
|
|
1056
|
+
|
|
1057
|
+
/* get previous expressions, there must
|
|
1058
|
+
* be at least something and a PTN_START */
|
|
1059
|
+
expr_sub = EXPR_PRV(expr_at);
|
|
1060
|
+
if (EXPR_TYPE(expr_sub) == PTN_START) return 0;
|
|
1061
|
+
expr_prv = EXPR_PRV(expr_sub);
|
|
1062
|
+
|
|
1063
|
+
/* create start expression */
|
|
1064
|
+
expr_start = *expr_crs;
|
|
1065
|
+
EXPR_TYPE(expr_start) = PTN_START;
|
|
1066
|
+
EXPR_PRV(expr_start) = PTN_END;
|
|
1067
|
+
EXPR_NXT(expr_start) = expr_sub;
|
|
1068
|
+
*expr_crs += 3;
|
|
1069
|
+
|
|
1070
|
+
/* create end expression */
|
|
1071
|
+
expr_end = *expr_crs;
|
|
1072
|
+
EXPR_TYPE(expr_end) = PTN_END;
|
|
1073
|
+
EXPR_PRV(expr_end) = expr_sub;
|
|
1074
|
+
EXPR_NXT(expr_end) = expr_at;
|
|
1075
|
+
*expr_crs += 3;
|
|
1076
|
+
|
|
1077
|
+
/* relink previous expression before sub expression */
|
|
1078
|
+
EXPR_DATA_0(expr_at) = expr_start;
|
|
1079
|
+
EXPR_NXT(expr_prv) = expr_at;
|
|
1080
|
+
EXPR_PRV(expr_at) = expr_prv;
|
|
1081
|
+
|
|
1082
|
+
/* relink sub expression to start and end */
|
|
1083
|
+
EXPR_PRV(expr_sub) = expr_start;
|
|
1084
|
+
EXPR_NXT(expr_sub) = expr_end;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
expr_at = EXPR_NXT(expr_at);
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
return 1;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
/* Resolves alternative expressions.
|
|
1094
|
+
*/
|
|
1095
|
+
static int
|
|
1096
|
+
pattern_compile_3(
|
|
1097
|
+
widechar *expr_data, int expr_at, const int expr_max, widechar *expr_crs) {
|
|
1098
|
+
int expr_mrk, expr_start, expr_end, expr_sub_start, expr_sub_end;
|
|
1099
|
+
|
|
1100
|
+
while (EXPR_TYPE(expr_at) != PTN_END) {
|
|
1101
|
+
if (EXPR_TYPE(expr_at) == PTN_GROUP || EXPR_TYPE(expr_at) == PTN_NOT ||
|
|
1102
|
+
EXPR_TYPE(expr_at) == PTN_OPTIONAL ||
|
|
1103
|
+
EXPR_TYPE(expr_at) == PTN_ZERO_MORE ||
|
|
1104
|
+
EXPR_TYPE(expr_at) == PTN_ONE_MORE) {
|
|
1105
|
+
if (!pattern_compile_3(expr_data, EXPR_DATA_0(expr_at), expr_max, expr_crs))
|
|
1106
|
+
return 0;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
if (EXPR_TYPE(expr_at) == PTN_ALTERNATE) {
|
|
1110
|
+
if (*expr_crs + 12 >= expr_max) return 0;
|
|
1111
|
+
|
|
1112
|
+
/* get previous start expression,
|
|
1113
|
+
* can include alternate expressions */
|
|
1114
|
+
expr_mrk = EXPR_PRV(expr_at);
|
|
1115
|
+
if (EXPR_TYPE(expr_mrk) == PTN_START) return 0;
|
|
1116
|
+
expr_sub_end = expr_mrk;
|
|
1117
|
+
while (EXPR_TYPE(expr_mrk) != PTN_START) expr_mrk = EXPR_PRV(expr_mrk);
|
|
1118
|
+
expr_sub_start = EXPR_NXT(expr_mrk);
|
|
1119
|
+
|
|
1120
|
+
/* create first start expression */
|
|
1121
|
+
expr_start = *expr_crs;
|
|
1122
|
+
EXPR_TYPE(expr_start) = PTN_START;
|
|
1123
|
+
EXPR_PRV(expr_start) = PTN_END;
|
|
1124
|
+
EXPR_NXT(expr_start) = expr_sub_start;
|
|
1125
|
+
*expr_crs += 3;
|
|
1126
|
+
|
|
1127
|
+
/* create first end expression */
|
|
1128
|
+
expr_end = *expr_crs;
|
|
1129
|
+
EXPR_TYPE(expr_end) = PTN_END;
|
|
1130
|
+
EXPR_PRV(expr_end) = expr_sub_end;
|
|
1131
|
+
EXPR_NXT(expr_end) = expr_at;
|
|
1132
|
+
*expr_crs += 3;
|
|
1133
|
+
|
|
1134
|
+
/* relink previous expression before sub expression */
|
|
1135
|
+
EXPR_DATA_0(expr_at) = expr_start;
|
|
1136
|
+
EXPR_NXT(expr_mrk) = expr_at;
|
|
1137
|
+
EXPR_PRV(expr_at) = expr_mrk;
|
|
1138
|
+
|
|
1139
|
+
/* relink sub expression to start and end */
|
|
1140
|
+
EXPR_PRV(expr_sub_start) = expr_start;
|
|
1141
|
+
EXPR_NXT(expr_sub_end) = expr_end;
|
|
1142
|
+
|
|
1143
|
+
/* get following PTN_END or PTN_ALTERNATE expression */
|
|
1144
|
+
expr_mrk = EXPR_NXT(expr_at);
|
|
1145
|
+
if (EXPR_TYPE(expr_mrk) == PTN_END || EXPR_TYPE(expr_mrk) == PTN_ALTERNATE)
|
|
1146
|
+
return 0;
|
|
1147
|
+
expr_sub_start = expr_mrk;
|
|
1148
|
+
while (EXPR_TYPE(expr_mrk) != PTN_END && EXPR_TYPE(expr_mrk) != PTN_ALTERNATE)
|
|
1149
|
+
expr_mrk = EXPR_NXT(expr_mrk);
|
|
1150
|
+
expr_sub_end = EXPR_PRV(expr_mrk);
|
|
1151
|
+
|
|
1152
|
+
/* create first start expression */
|
|
1153
|
+
expr_start = *expr_crs;
|
|
1154
|
+
EXPR_TYPE(expr_start) = PTN_START;
|
|
1155
|
+
EXPR_PRV(expr_start) = PTN_END;
|
|
1156
|
+
EXPR_NXT(expr_start) = expr_sub_start;
|
|
1157
|
+
*expr_crs += 3;
|
|
1158
|
+
|
|
1159
|
+
/* create first end expression */
|
|
1160
|
+
expr_end = *expr_crs;
|
|
1161
|
+
EXPR_TYPE(expr_end) = PTN_END;
|
|
1162
|
+
EXPR_PRV(expr_end) = expr_sub_end;
|
|
1163
|
+
EXPR_NXT(expr_end) = expr_at;
|
|
1164
|
+
*expr_crs += 3;
|
|
1165
|
+
|
|
1166
|
+
/* relink following expression before sub expression */
|
|
1167
|
+
EXPR_DATA_1(expr_at) = expr_start;
|
|
1168
|
+
EXPR_PRV(expr_mrk) = expr_at;
|
|
1169
|
+
EXPR_NXT(expr_at) = expr_mrk;
|
|
1170
|
+
|
|
1171
|
+
/* relink sub expression to start and end */
|
|
1172
|
+
EXPR_PRV(expr_sub_start) = expr_start;
|
|
1173
|
+
EXPR_NXT(expr_sub_end) = expr_end;
|
|
1174
|
+
|
|
1175
|
+
/* check expressions were after alternate and got moved into
|
|
1176
|
+
* a sub expression, previous expressions already checked */
|
|
1177
|
+
if (!pattern_compile_3(expr_data, EXPR_DATA_1(expr_at), expr_max, expr_crs))
|
|
1178
|
+
return 0;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
expr_at = EXPR_NXT(expr_at);
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
return 1;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
int EXPORT_CALL
|
|
1188
|
+
_lou_pattern_compile(const widechar *input, const int input_max, widechar *expr_data,
|
|
1189
|
+
const int expr_max, TranslationTableHeader *table, const FileInfo *nested) {
|
|
1190
|
+
int input_crs;
|
|
1191
|
+
|
|
1192
|
+
input_crs = 0;
|
|
1193
|
+
expr_data[0] = 2;
|
|
1194
|
+
expr_data[1] = 0;
|
|
1195
|
+
|
|
1196
|
+
if (table == NULL || nested == NULL) return 0;
|
|
1197
|
+
|
|
1198
|
+
if (!pattern_compile_1(input, input_max, &input_crs, expr_data, expr_max,
|
|
1199
|
+
&expr_data[0], &expr_data[1], table, nested))
|
|
1200
|
+
return 0;
|
|
1201
|
+
|
|
1202
|
+
/* shift past the last end */
|
|
1203
|
+
expr_data[0] += 3;
|
|
1204
|
+
|
|
1205
|
+
if (!pattern_compile_2(expr_data, 2, expr_max, &expr_data[0])) return 0;
|
|
1206
|
+
|
|
1207
|
+
if (!pattern_compile_3(expr_data, 2, expr_max, &expr_data[0])) return 0;
|
|
1208
|
+
|
|
1209
|
+
return expr_data[0];
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
1213
|
+
|
|
1214
|
+
static void
|
|
1215
|
+
pattern_reverse_expression(widechar *expr_data, const int expr_start);
|
|
1216
|
+
|
|
1217
|
+
static void
|
|
1218
|
+
pattern_reverse_branch(widechar *expr_data, const int expr_at) {
|
|
1219
|
+
widechar expr_swap;
|
|
1220
|
+
|
|
1221
|
+
switch (EXPR_TYPE(expr_at)) {
|
|
1222
|
+
case PTN_ALTERNATE:
|
|
1223
|
+
|
|
1224
|
+
pattern_reverse_expression(expr_data, EXPR_DATA_0(expr_at));
|
|
1225
|
+
expr_swap = EXPR_DATA_0(expr_at);
|
|
1226
|
+
EXPR_DATA_0(expr_at) = EXPR_DATA_1(expr_at);
|
|
1227
|
+
EXPR_DATA_1(expr_at) = expr_swap;
|
|
1228
|
+
|
|
1229
|
+
case PTN_GROUP:
|
|
1230
|
+
case PTN_NOT:
|
|
1231
|
+
case PTN_ONE_MORE:
|
|
1232
|
+
case PTN_ZERO_MORE:
|
|
1233
|
+
case PTN_OPTIONAL:
|
|
1234
|
+
|
|
1235
|
+
pattern_reverse_expression(expr_data, EXPR_DATA_0(expr_at));
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
static void
|
|
1240
|
+
pattern_reverse_expression(widechar *expr_data, const int expr_start) {
|
|
1241
|
+
widechar expr_end, expr_crs, expr_prv;
|
|
1242
|
+
|
|
1243
|
+
expr_end = EXPR_NXT(expr_start);
|
|
1244
|
+
|
|
1245
|
+
/* empty expression */
|
|
1246
|
+
if (EXPR_TYPE(expr_end) == PTN_END) return;
|
|
1247
|
+
|
|
1248
|
+
/* find end expression */
|
|
1249
|
+
while (EXPR_TYPE(expr_end) != PTN_END) expr_end = EXPR_NXT(expr_end);
|
|
1250
|
+
|
|
1251
|
+
expr_crs = EXPR_PRV(expr_end);
|
|
1252
|
+
expr_prv = EXPR_PRV(expr_crs);
|
|
1253
|
+
|
|
1254
|
+
/* relink expression before end expression */
|
|
1255
|
+
EXPR_NXT(expr_start) = expr_crs;
|
|
1256
|
+
EXPR_PRV(expr_crs) = expr_start;
|
|
1257
|
+
EXPR_NXT(expr_crs) = expr_prv;
|
|
1258
|
+
|
|
1259
|
+
/* reverse any branching expressions */
|
|
1260
|
+
pattern_reverse_branch(expr_data, expr_crs);
|
|
1261
|
+
|
|
1262
|
+
while (expr_prv != expr_start) {
|
|
1263
|
+
/* shift current expression */
|
|
1264
|
+
expr_crs = expr_prv;
|
|
1265
|
+
expr_prv = EXPR_PRV(expr_prv);
|
|
1266
|
+
|
|
1267
|
+
/* reverse any branching expressions */
|
|
1268
|
+
pattern_reverse_branch(expr_data, expr_crs);
|
|
1269
|
+
|
|
1270
|
+
/* relink current expression */
|
|
1271
|
+
EXPR_PRV(expr_crs) = EXPR_NXT(expr_crs);
|
|
1272
|
+
EXPR_NXT(expr_crs) = expr_prv;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
/* relink expression after start expression */
|
|
1276
|
+
EXPR_PRV(expr_crs) = EXPR_NXT(expr_crs);
|
|
1277
|
+
EXPR_NXT(expr_crs) = expr_end;
|
|
1278
|
+
EXPR_PRV(expr_end) = expr_crs;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
void EXPORT_CALL
|
|
1282
|
+
_lou_pattern_reverse(widechar *expr_data) {
|
|
1283
|
+
pattern_reverse_expression(expr_data, 2);
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
1287
|
+
|
|
1288
|
+
static int
|
|
1289
|
+
pattern_check_chars(const widechar input_char, const widechar *expr_data) {
|
|
1290
|
+
int expr_cnt, i;
|
|
1291
|
+
|
|
1292
|
+
expr_cnt = expr_data[0] + 1;
|
|
1293
|
+
|
|
1294
|
+
for (i = 1; i < expr_cnt; i++)
|
|
1295
|
+
if (input_char == expr_data[i]) break;
|
|
1296
|
+
|
|
1297
|
+
if (i == expr_cnt) return 0;
|
|
1298
|
+
return 1;
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
static int
|
|
1302
|
+
pattern_check_attrs(const widechar input_char, const widechar *expr_data,
|
|
1303
|
+
const TranslationTableHeader *table) {
|
|
1304
|
+
int attrs;
|
|
1305
|
+
|
|
1306
|
+
attrs = ((expr_data[0] << 16) | expr_data[1]) & ~(CTC_EndOfInput | CTC_EmpMatch);
|
|
1307
|
+
if (!checkAttr(input_char, attrs, table)) return 0;
|
|
1308
|
+
return 1;
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
static int
|
|
1312
|
+
pattern_check_expression(const widechar *const input, int *input_crs,
|
|
1313
|
+
const int input_minmax, const int input_dir, const widechar *const expr_data,
|
|
1314
|
+
int (*hook)(const widechar input, const int data_len), widechar *hook_data,
|
|
1315
|
+
const int hook_max, int expr_crs, int notOperator, int loop_crs, int *loop_cnts,
|
|
1316
|
+
const TranslationTableHeader *table) {
|
|
1317
|
+
int input_crs_prv, input_start, attrs, ret, i;
|
|
1318
|
+
const widechar *data;
|
|
1319
|
+
|
|
1320
|
+
data = NULL;
|
|
1321
|
+
|
|
1322
|
+
/* save input_crs to know if loop consumed input */
|
|
1323
|
+
input_start = *input_crs;
|
|
1324
|
+
|
|
1325
|
+
CHECK_OUTPUT(START, 0, __LINE__, "check start")
|
|
1326
|
+
|
|
1327
|
+
while (!(EXPR_TYPE(expr_crs) == PTN_END && EXPR_TYPE(expr_crs) == PTN_END)) {
|
|
1328
|
+
/* end of input expression */
|
|
1329
|
+
if (EXPR_TYPE(expr_crs) == PTN_END_OF_INPUT) {
|
|
1330
|
+
if (*input_crs * input_dir >= input_minmax * input_dir) {
|
|
1331
|
+
if (notOperator)
|
|
1332
|
+
CHECK_OUTPUT(
|
|
1333
|
+
RETURN, 0, __LINE__, "end of input failed: no input and not")
|
|
1334
|
+
else
|
|
1335
|
+
CHECK_OUTPUT(RETURN, 1, __LINE__, "end of input passed: no input")
|
|
1336
|
+
return !notOperator;
|
|
1337
|
+
} else {
|
|
1338
|
+
if (notOperator)
|
|
1339
|
+
CHECK_OUTPUT(
|
|
1340
|
+
RETURN, 1, __LINE__, "end of input passed: input and not")
|
|
1341
|
+
else
|
|
1342
|
+
CHECK_OUTPUT(RETURN, 0, __LINE__, "end of input failed: input")
|
|
1343
|
+
return notOperator;
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
/* no more input */
|
|
1348
|
+
if (*input_crs * input_dir >= input_minmax * input_dir) {
|
|
1349
|
+
switch (EXPR_TYPE(expr_crs)) {
|
|
1350
|
+
case PTN_ATTRIBUTES:
|
|
1351
|
+
|
|
1352
|
+
attrs = (EXPR_DATA_0(expr_crs) << 16);
|
|
1353
|
+
if (attrs & CTC_EndOfInput) {
|
|
1354
|
+
if (notOperator) {
|
|
1355
|
+
CHECK_OUTPUT(RETURN, 0, __LINE__,
|
|
1356
|
+
"attributes failed: end of input attribute: not")
|
|
1357
|
+
return 0;
|
|
1358
|
+
}
|
|
1359
|
+
CHECK_OUTPUT(RETURN, 1, __LINE__,
|
|
1360
|
+
"attributes passed: end of input attribute")
|
|
1361
|
+
return 1;
|
|
1362
|
+
}
|
|
1363
|
+
CHECK_OUTPUT(RETURN, 0, __LINE__,
|
|
1364
|
+
"attributes failed: no end of input attribute")
|
|
1365
|
+
return 0;
|
|
1366
|
+
|
|
1367
|
+
case PTN_ANY:
|
|
1368
|
+
case PTN_CHARS:
|
|
1369
|
+
|
|
1370
|
+
CHECK_OUTPUT(RETURN, 0, __LINE__, "chars failed: no input")
|
|
1371
|
+
return 0;
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "no input")
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
switch (EXPR_TYPE(expr_crs)) {
|
|
1378
|
+
|
|
1379
|
+
case PTN_START:
|
|
1380
|
+
|
|
1381
|
+
expr_crs = EXPR_NXT(expr_crs);
|
|
1382
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "start next")
|
|
1383
|
+
break;
|
|
1384
|
+
|
|
1385
|
+
case PTN_GROUP:
|
|
1386
|
+
|
|
1387
|
+
expr_crs = EXPR_DATA_0(expr_crs);
|
|
1388
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "group next")
|
|
1389
|
+
break;
|
|
1390
|
+
|
|
1391
|
+
case PTN_NOT:
|
|
1392
|
+
|
|
1393
|
+
notOperator = !notOperator;
|
|
1394
|
+
expr_crs = EXPR_DATA_0(expr_crs);
|
|
1395
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "not next")
|
|
1396
|
+
break;
|
|
1397
|
+
|
|
1398
|
+
case PTN_ONE_MORE:
|
|
1399
|
+
|
|
1400
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "loop+ start")
|
|
1401
|
+
|
|
1402
|
+
case PTN_ZERO_MORE:
|
|
1403
|
+
|
|
1404
|
+
/* check if loop already started */
|
|
1405
|
+
if (expr_crs == loop_crs) {
|
|
1406
|
+
loop_cnts[EXPR_DATA_1(loop_crs)]++;
|
|
1407
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "loop again")
|
|
1408
|
+
} else {
|
|
1409
|
+
/* check if loop nested, wasn't running but has a count */
|
|
1410
|
+
if (loop_cnts[EXPR_DATA_1(expr_crs)]) {
|
|
1411
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "loop already running")
|
|
1412
|
+
goto loop_next;
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
/* start loop */
|
|
1416
|
+
loop_crs = expr_crs;
|
|
1417
|
+
loop_cnts[EXPR_DATA_1(loop_crs)] = 1;
|
|
1418
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "loop start")
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
/* start loop expression */
|
|
1422
|
+
input_crs_prv = *input_crs;
|
|
1423
|
+
ret = pattern_check_expression(input, input_crs, input_minmax, input_dir,
|
|
1424
|
+
expr_data, hook, hook_data, hook_max, EXPR_DATA_0(expr_crs),
|
|
1425
|
+
notOperator, loop_crs, loop_cnts, table);
|
|
1426
|
+
if (ret) {
|
|
1427
|
+
CHECK_OUTPUT(RETURN, 1, __LINE__, "loop passed")
|
|
1428
|
+
return 1;
|
|
1429
|
+
}
|
|
1430
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "loop failed")
|
|
1431
|
+
*input_crs = input_crs_prv;
|
|
1432
|
+
|
|
1433
|
+
/* check loop count */
|
|
1434
|
+
loop_cnts[EXPR_DATA_1(loop_crs)]--;
|
|
1435
|
+
if (EXPR_TYPE(expr_crs) == PTN_ONE_MORE) {
|
|
1436
|
+
if (loop_cnts[EXPR_DATA_1(loop_crs)] < 1) {
|
|
1437
|
+
CHECK_OUTPUT(RETURN, 0, __LINE__, "loop+ failed")
|
|
1438
|
+
return 0;
|
|
1439
|
+
} else
|
|
1440
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "loop+ passed")
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
/* continue after loop */
|
|
1444
|
+
loop_next:
|
|
1445
|
+
expr_crs = EXPR_NXT(expr_crs);
|
|
1446
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "loop next")
|
|
1447
|
+
break;
|
|
1448
|
+
|
|
1449
|
+
case PTN_OPTIONAL:
|
|
1450
|
+
|
|
1451
|
+
/* save current state */
|
|
1452
|
+
input_crs_prv = *input_crs;
|
|
1453
|
+
|
|
1454
|
+
/* start optional expression */
|
|
1455
|
+
CHECK_OUTPUT(CALL, 0, __LINE__, "option start")
|
|
1456
|
+
if (pattern_check_expression(input, input_crs, input_minmax, input_dir,
|
|
1457
|
+
expr_data, hook, hook_data, hook_max, EXPR_DATA_0(expr_crs),
|
|
1458
|
+
notOperator, loop_crs, loop_cnts, table)) {
|
|
1459
|
+
CHECK_OUTPUT(RETURN, 1, __LINE__, "option passed")
|
|
1460
|
+
return 1;
|
|
1461
|
+
}
|
|
1462
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "option failed")
|
|
1463
|
+
|
|
1464
|
+
/* continue after optional expression */
|
|
1465
|
+
*input_crs = input_crs_prv;
|
|
1466
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "no option start")
|
|
1467
|
+
expr_crs = EXPR_NXT(expr_crs);
|
|
1468
|
+
break;
|
|
1469
|
+
|
|
1470
|
+
case PTN_ALTERNATE:
|
|
1471
|
+
|
|
1472
|
+
/* save current state */
|
|
1473
|
+
input_crs_prv = *input_crs;
|
|
1474
|
+
|
|
1475
|
+
/* start first expression */
|
|
1476
|
+
CHECK_OUTPUT(CALL, 0, __LINE__, "or 1 start")
|
|
1477
|
+
if (pattern_check_expression(input, input_crs, input_minmax, input_dir,
|
|
1478
|
+
expr_data, hook, hook_data, hook_max, EXPR_DATA_0(expr_crs),
|
|
1479
|
+
notOperator, loop_crs, loop_cnts, table)) {
|
|
1480
|
+
CHECK_OUTPUT(RETURN, 1, __LINE__, "or 1 passed")
|
|
1481
|
+
return 1;
|
|
1482
|
+
}
|
|
1483
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "or 1 failed")
|
|
1484
|
+
|
|
1485
|
+
/* start second expression (no need to push) */
|
|
1486
|
+
*input_crs = input_crs_prv;
|
|
1487
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "or 2 start")
|
|
1488
|
+
expr_crs = EXPR_DATA_1(expr_crs);
|
|
1489
|
+
break;
|
|
1490
|
+
|
|
1491
|
+
case PTN_ANY:
|
|
1492
|
+
|
|
1493
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "any")
|
|
1494
|
+
*input_crs += input_dir;
|
|
1495
|
+
expr_crs = EXPR_NXT(expr_crs);
|
|
1496
|
+
break;
|
|
1497
|
+
|
|
1498
|
+
case PTN_ATTRIBUTES:
|
|
1499
|
+
|
|
1500
|
+
ret = pattern_check_attrs(
|
|
1501
|
+
input[*input_crs], EXPR_CONST_DATA(expr_crs), table);
|
|
1502
|
+
if (ret && notOperator) {
|
|
1503
|
+
CHECK_OUTPUT(RETURN, 0, __LINE__, "attributes failed: not");
|
|
1504
|
+
return 0;
|
|
1505
|
+
}
|
|
1506
|
+
if (!ret && !notOperator) {
|
|
1507
|
+
CHECK_OUTPUT(RETURN, 0, __LINE__, "attributes failed");
|
|
1508
|
+
return 0;
|
|
1509
|
+
}
|
|
1510
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "attributes passed")
|
|
1511
|
+
*input_crs += input_dir;
|
|
1512
|
+
expr_crs = EXPR_NXT(expr_crs);
|
|
1513
|
+
break;
|
|
1514
|
+
|
|
1515
|
+
case PTN_CHARS:
|
|
1516
|
+
|
|
1517
|
+
ret = pattern_check_chars(input[*input_crs], EXPR_CONST_DATA(expr_crs));
|
|
1518
|
+
if (ret && notOperator) {
|
|
1519
|
+
CHECK_OUTPUT(RETURN, 0, __LINE__, "chars failed: not");
|
|
1520
|
+
return 0;
|
|
1521
|
+
}
|
|
1522
|
+
if (!ret && !notOperator) {
|
|
1523
|
+
CHECK_OUTPUT(RETURN, 0, __LINE__, "chars failed");
|
|
1524
|
+
return 0;
|
|
1525
|
+
}
|
|
1526
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "chars passed")
|
|
1527
|
+
*input_crs += input_dir;
|
|
1528
|
+
expr_crs = EXPR_NXT(expr_crs);
|
|
1529
|
+
break;
|
|
1530
|
+
|
|
1531
|
+
case PTN_HOOK:
|
|
1532
|
+
|
|
1533
|
+
if (hook == NULL) {
|
|
1534
|
+
CHECK_OUTPUT(RETURN, 0, __LINE__, "hook failed: NULL");
|
|
1535
|
+
return 0;
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
/* copy expression data */
|
|
1539
|
+
data = EXPR_CONST_DATA(expr_crs);
|
|
1540
|
+
for (i = 0; i < data[0]; i++) hook_data[i] = data[i + 1];
|
|
1541
|
+
|
|
1542
|
+
/* call hook function */
|
|
1543
|
+
ret = hook(input[*input_crs], data[0]);
|
|
1544
|
+
if (ret && notOperator) {
|
|
1545
|
+
CHECK_OUTPUT(RETURN, 0, __LINE__, "hook failed: not");
|
|
1546
|
+
return 0;
|
|
1547
|
+
}
|
|
1548
|
+
if (!ret && !notOperator) {
|
|
1549
|
+
CHECK_OUTPUT(RETURN, 0, __LINE__, "hook failed");
|
|
1550
|
+
return 0;
|
|
1551
|
+
}
|
|
1552
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "hook passed")
|
|
1553
|
+
*input_crs += input_dir;
|
|
1554
|
+
expr_crs = EXPR_NXT(expr_crs);
|
|
1555
|
+
break;
|
|
1556
|
+
|
|
1557
|
+
case PTN_END:
|
|
1558
|
+
break;
|
|
1559
|
+
|
|
1560
|
+
default:
|
|
1561
|
+
|
|
1562
|
+
CHECK_OUTPUT(RETURN, 0, __LINE__, "unknown opcode")
|
|
1563
|
+
return 0;
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
/* check end expression */
|
|
1567
|
+
while (EXPR_TYPE(expr_crs) == PTN_END) {
|
|
1568
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "end")
|
|
1569
|
+
|
|
1570
|
+
/* check for end of expressions */
|
|
1571
|
+
if (EXPR_NXT(expr_crs) == PTN_END) break;
|
|
1572
|
+
|
|
1573
|
+
expr_crs = EXPR_NXT(expr_crs);
|
|
1574
|
+
|
|
1575
|
+
/* returning loop */
|
|
1576
|
+
if (EXPR_TYPE(expr_crs) == PTN_ZERO_MORE ||
|
|
1577
|
+
EXPR_TYPE(expr_crs) == PTN_ONE_MORE) {
|
|
1578
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "end loop")
|
|
1579
|
+
|
|
1580
|
+
/* check that loop consumed input */
|
|
1581
|
+
if (*input_crs == input_start) {
|
|
1582
|
+
CHECK_OUTPUT(RETURN, 0, __LINE__, "loop failed: did not consume")
|
|
1583
|
+
return 0;
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
/* loops do not continue to the next expression */
|
|
1587
|
+
break;
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
/* returning not */
|
|
1591
|
+
if (EXPR_TYPE(expr_crs) == PTN_NOT) notOperator = !notOperator;
|
|
1592
|
+
|
|
1593
|
+
expr_crs = EXPR_NXT(expr_crs);
|
|
1594
|
+
|
|
1595
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "end next")
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
CHECK_OUTPUT(SHOW, 0, __LINE__, "check next")
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
CHECK_OUTPUT(RETURN, 1, __LINE__, "check passed: end of expression");
|
|
1602
|
+
return 1;
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
static int
|
|
1606
|
+
pattern_check_hook(const widechar *input, const int input_start, const int input_minmax,
|
|
1607
|
+
const int input_dir, const widechar *expr_data,
|
|
1608
|
+
int (*hook)(const widechar input, const int data_len), widechar *hook_data,
|
|
1609
|
+
const int hook_max, const TranslationTableHeader *table) {
|
|
1610
|
+
int input_crs, ret, *loop_cnts;
|
|
1611
|
+
|
|
1612
|
+
input_crs = input_start;
|
|
1613
|
+
loop_cnts = malloc(expr_data[1] * sizeof(int));
|
|
1614
|
+
memset(loop_cnts, 0, expr_data[1] * sizeof(int));
|
|
1615
|
+
ret = pattern_check_expression(input, &input_crs, input_minmax, input_dir, expr_data,
|
|
1616
|
+
hook, hook_data, hook_max, 2, 0, 0, loop_cnts, table);
|
|
1617
|
+
free(loop_cnts);
|
|
1618
|
+
return ret;
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
int EXPORT_CALL
|
|
1622
|
+
_lou_pattern_check(const widechar *input, const int input_start, const int input_minmax,
|
|
1623
|
+
const int input_dir, const widechar *expr_data,
|
|
1624
|
+
const TranslationTableHeader *table) {
|
|
1625
|
+
#ifdef CHECK_OUTPUT_DEFINED
|
|
1626
|
+
pattern_output(expr_data, table);
|
|
1627
|
+
#endif
|
|
1628
|
+
return pattern_check_hook(
|
|
1629
|
+
input, input_start, input_minmax, input_dir, expr_data, NULL, NULL, 0, table);
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
////////////////////////////////////////////////////////////////////////////////
|