1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162 |
- /**********************************************************************
- mktable.c
- **********************************************************************/
- /*-
- * Copyright (c) 2002-2007 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
- #include <stdlib.h>
- #include <stdio.h>
- #include <locale.h>
- #define __USE_ISOC99
- #include <ctype.h>
- #include "regenc.h"
- #define ASCII 0
- #define UNICODE_ISO_8859_1 1
- #define ISO_8859_1 2
- #define ISO_8859_2 3
- #define ISO_8859_3 4
- #define ISO_8859_4 5
- #define ISO_8859_5 6
- #define ISO_8859_6 7
- #define ISO_8859_7 8
- #define ISO_8859_8 9
- #define ISO_8859_9 10
- #define ISO_8859_10 11
- #define ISO_8859_11 12
- #define ISO_8859_13 13
- #define ISO_8859_14 14
- #define ISO_8859_15 15
- #define ISO_8859_16 16
- #define KOI8 17
- #define KOI8_R 18
- typedef struct {
- int num;
- char* name;
- } ENC_INFO;
- static ENC_INFO Info[] = {
- { ASCII, "ASCII" },
- { UNICODE_ISO_8859_1, "UNICODE_ISO_8859_1" },
- { ISO_8859_1, "ISO_8859_1" },
- { ISO_8859_2, "ISO_8859_2" },
- { ISO_8859_3, "ISO_8859_3" },
- { ISO_8859_4, "ISO_8859_4" },
- { ISO_8859_5, "ISO_8859_5" },
- { ISO_8859_6, "ISO_8859_6" },
- { ISO_8859_7, "ISO_8859_7" },
- { ISO_8859_8, "ISO_8859_8" },
- { ISO_8859_9, "ISO_8859_9" },
- { ISO_8859_10, "ISO_8859_10" },
- { ISO_8859_11, "ISO_8859_11" },
- { ISO_8859_13, "ISO_8859_13" },
- { ISO_8859_14, "ISO_8859_14" },
- { ISO_8859_15, "ISO_8859_15" },
- { ISO_8859_16, "ISO_8859_16" },
- { KOI8, "KOI8" },
- { KOI8_R, "KOI8_R" }
- };
- static int IsAlpha(int enc, int c)
- {
- if (enc == ASCII)
- return isalpha(c);
- if (c >= 0x41 && c <= 0x5a) return 1;
- if (c >= 0x61 && c <= 0x7a) return 1;
- switch (enc) {
- case UNICODE_ISO_8859_1:
- case ISO_8859_1:
- case ISO_8859_9:
- if (c == 0xaa) return 1;
- if (c == 0xb5) return 1;
- if (c == 0xba) return 1;
- if (c >= 0xc0 && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xff) return 1;
- break;
- case ISO_8859_2:
- if (c == 0xa1 || c == 0xa3) return 1;
- if (c == 0xa5 || c == 0xa6) return 1;
- if (c >= 0xa9 && c <= 0xac) return 1;
- if (c >= 0xae && c <= 0xaf) return 1;
- if (c == 0xb1 || c == 0xb3) return 1;
- if (c == 0xb5 || c == 0xb6) return 1;
- if (c >= 0xb9 && c <= 0xbc) return 1;
- if (c >= 0xbe && c <= 0xbf) return 1;
- if (c >= 0xc0 && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xfe) return 1;
- break;
- case ISO_8859_3:
- if (c == 0xa1) return 1;
- if (c == 0xa6) return 1;
- if (c >= 0xa9 && c <= 0xac) return 1;
- if (c == 0xaf) return 1;
- if (c == 0xb1) return 1;
- if (c == 0xb5 || c == 0xb6) return 1;
- if (c >= 0xb9 && c <= 0xbc) return 1;
- if (c == 0xbf) return 1;
- if (c >= 0xc0 && c <= 0xc2) return 1;
- if (c >= 0xc4 && c <= 0xcf) return 1;
- if (c >= 0xd1 && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xe2) return 1;
- if (c >= 0xe4 && c <= 0xef) return 1;
- if (c >= 0xf1 && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xfe) return 1;
- break;
- case ISO_8859_4:
- if (c >= 0xa1 && c <= 0xa3) return 1;
- if (c == 0xa5 || c == 0xa6) return 1;
- if (c >= 0xa9 && c <= 0xac) return 1;
- if (c == 0xae) return 1;
- if (c == 0xb1 || c == 0xb3) return 1;
- if (c == 0xb5 || c == 0xb6) return 1;
- if (c >= 0xb9 && c <= 0xbf) return 1;
- if (c >= 0xc0 && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xfe) return 1;
- break;
- case ISO_8859_5:
- if (c >= 0xa1 && c <= 0xcf && c != 0xad) return 1;
- if (c >= 0xd0 && c <= 0xff && c != 0xf0 && c != 0xfd) return 1;
- break;
- case ISO_8859_6:
- if (c >= 0xc1 && c <= 0xda) return 1;
- if (c >= 0xe0 && c <= 0xf2) return 1;
- break;
- case ISO_8859_7:
- if (c == 0xb6) return 1;
- if (c >= 0xb8 && c <= 0xba) return 1;
- if (c == 0xbc) return 1;
- if (c >= 0xbe && c <= 0xbf) return 1;
- if (c == 0xc0) return 1;
- if (c >= 0xc1 && c <= 0xdb && c != 0xd2) return 1;
- if (c >= 0xdc && c <= 0xfe) return 1;
- break;
- case ISO_8859_8:
- if (c == 0xb5) return 1;
- if (c >= 0xe0 && c <= 0xfa) return 1;
- break;
- case ISO_8859_10:
- if (c >= 0xa1 && c <= 0xa6) return 1;
- if (c >= 0xa8 && c <= 0xac) return 1;
- if (c == 0xae || c == 0xaf) return 1;
- if (c >= 0xb1 && c <= 0xb6) return 1;
- if (c >= 0xb8 && c <= 0xbc) return 1;
- if (c >= 0xbe && c <= 0xff) return 1;
- break;
- case ISO_8859_11:
- if (c >= 0xa1 && c <= 0xda) return 1;
- if (c >= 0xdf && c <= 0xfb) return 1;
- break;
- case ISO_8859_13:
- if (c == 0xa8) return 1;
- if (c == 0xaa) return 1;
- if (c == 0xaf) return 1;
- if (c == 0xb5) return 1;
- if (c == 0xb8) return 1;
- if (c == 0xba) return 1;
- if (c >= 0xbf && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xfe) return 1;
- break;
- case ISO_8859_14:
- if (c == 0xa1 || c == 0xa2) return 1;
- if (c == 0xa4 || c == 0xa5) return 1;
- if (c == 0xa6 || c == 0xa8) return 1;
- if (c >= 0xaa && c <= 0xac) return 1;
- if (c >= 0xaf && c <= 0xb5) return 1;
- if (c >= 0xb7 && c <= 0xff) return 1;
- break;
- case ISO_8859_15:
- if (c == 0xaa) return 1;
- if (c == 0xb5) return 1;
- if (c == 0xba) return 1;
- if (c >= 0xc0 && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xff) return 1;
- if (c == 0xa6) return 1;
- if (c == 0xa8) return 1;
- if (c == 0xb4) return 1;
- if (c == 0xb8) return 1;
- if (c == 0xbc) return 1;
- if (c == 0xbd) return 1;
- if (c == 0xbe) return 1;
- break;
- case ISO_8859_16:
- if (c == 0xa1) return 1;
- if (c == 0xa2) return 1;
- if (c == 0xa3) return 1;
- if (c == 0xa6) return 1;
- if (c == 0xa8) return 1;
- if (c == 0xaa) return 1;
- if (c == 0xac) return 1;
- if (c == 0xae) return 1;
- if (c == 0xaf) return 1;
- if (c == 0xb2) return 1;
- if (c == 0xb3) return 1;
- if (c == 0xb4) return 1;
- if (c >= 0xb8 && c <= 0xba) return 1;
- if (c == 0xbc) return 1;
- if (c == 0xbd) return 1;
- if (c == 0xbe) return 1;
- if (c == 0xbf) return 1;
- if (c >= 0xc0 && c <= 0xde) return 1;
- if (c >= 0xdf && c <= 0xff) return 1;
- break;
- case KOI8_R:
- if (c == 0xa3 || c == 0xb3) return 1;
- /* fall */
- case KOI8:
- if (c >= 0xc0 && c <= 0xff) return 1;
- break;
- default:
- exit(-1);
- }
- return 0;
- }
- static int IsBlank(int enc, int c)
- {
- if (enc == ASCII)
- return isblank(c);
- if (c == 0x09 || c == 0x20) return 1;
- switch (enc) {
- case UNICODE_ISO_8859_1:
- case ISO_8859_1:
- case ISO_8859_2:
- case ISO_8859_3:
- case ISO_8859_4:
- case ISO_8859_5:
- case ISO_8859_6:
- case ISO_8859_7:
- case ISO_8859_8:
- case ISO_8859_9:
- case ISO_8859_10:
- case ISO_8859_11:
- case ISO_8859_13:
- case ISO_8859_14:
- case ISO_8859_15:
- case ISO_8859_16:
- case KOI8:
- if (c == 0xa0) return 1;
- break;
- case KOI8_R:
- if (c == 0x9a) return 1;
- break;
- default:
- exit(-1);
- }
- return 0;
- }
- static int IsCntrl(int enc, int c)
- {
- if (enc == ASCII)
- return iscntrl(c);
- if (c >= 0x00 && c <= 0x1F) return 1;
- switch (enc) {
- case UNICODE_ISO_8859_1:
- if (c == 0xad) return 1;
- /* fall */
- case ISO_8859_1:
- case ISO_8859_2:
- case ISO_8859_3:
- case ISO_8859_4:
- case ISO_8859_5:
- case ISO_8859_6:
- case ISO_8859_7:
- case ISO_8859_8:
- case ISO_8859_9:
- case ISO_8859_10:
- case ISO_8859_11:
- case ISO_8859_13:
- case ISO_8859_14:
- case ISO_8859_15:
- case ISO_8859_16:
- case KOI8:
- if (c >= 0x7f && c <= 0x9F) return 1;
- break;
- case KOI8_R:
- if (c == 0x7f) return 1;
- break;
- default:
- exit(-1);
- }
- return 0;
- }
- static int IsDigit(int enc ARG_UNUSED, int c)
- {
- if (c >= 0x30 && c <= 0x39) return 1;
- return 0;
- }
- static int IsGraph(int enc, int c)
- {
- if (enc == ASCII)
- return isgraph(c);
- if (c >= 0x21 && c <= 0x7e) return 1;
- switch (enc) {
- case UNICODE_ISO_8859_1:
- case ISO_8859_1:
- case ISO_8859_2:
- case ISO_8859_4:
- case ISO_8859_5:
- case ISO_8859_9:
- case ISO_8859_10:
- case ISO_8859_13:
- case ISO_8859_14:
- case ISO_8859_15:
- case ISO_8859_16:
- if (c >= 0xa1 && c <= 0xff) return 1;
- break;
- case ISO_8859_3:
- if (c >= 0xa1) {
- if (c == 0xa5 || c == 0xae || c == 0xbe || c == 0xc3 || c == 0xd0 ||
- c == 0xe3 || c == 0xf0)
- return 0;
- else
- return 1;
- }
- break;
- case ISO_8859_6:
- if (c == 0xa4 || c == 0xac || c == 0xad || c == 0xbb || c == 0xbf)
- return 1;
- if (c >= 0xc1 && c <= 0xda) return 1;
- if (c >= 0xe0 && c <= 0xf2) return 1;
- break;
- case ISO_8859_7:
- if (c >= 0xa1 && c <= 0xfe &&
- c != 0xa4 && c != 0xa5 && c != 0xaa &&
- c != 0xae && c != 0xd2) return 1;
- break;
- case ISO_8859_8:
- if (c >= 0xa2 && c <= 0xfa) {
- if (c >= 0xbf && c <= 0xde) return 0;
- return 1;
- }
- break;
- case ISO_8859_11:
- if (c >= 0xa1 && c <= 0xda) return 1;
- if (c >= 0xdf && c <= 0xfb) return 1;
- break;
- case KOI8:
- if (c >= 0xc0 && c <= 0xff) return 1;
- break;
- case KOI8_R:
- if (c >= 0x80 && c <= 0xff && c != 0x9a) return 1;
- break;
- default:
- exit(-1);
- }
- return 0;
- }
- static int IsLower(int enc, int c)
- {
- if (enc == ASCII)
- return islower(c);
- if (c >= 0x61 && c <= 0x7a) return 1;
- switch (enc) {
- case UNICODE_ISO_8859_1:
- case ISO_8859_1:
- case ISO_8859_9:
- if (c == 0xaa) return 1;
- if (c == 0xb5) return 1;
- if (c == 0xba) return 1;
- if (c >= 0xdf && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xff) return 1;
- break;
- case ISO_8859_2:
- if (c == 0xb1 || c == 0xb3) return 1;
- if (c == 0xb5 || c == 0xb6) return 1;
- if (c >= 0xb9 && c <= 0xbc) return 1;
- if (c >= 0xbe && c <= 0xbf) return 1;
- if (c >= 0xdf && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xfe) return 1;
- break;
- case ISO_8859_3:
- if (c == 0xb1) return 1;
- if (c == 0xb5 || c == 0xb6) return 1;
- if (c >= 0xb9 && c <= 0xbc) return 1;
- if (c == 0xbf) return 1;
- if (c == 0xdf) return 1;
- if (c >= 0xe0 && c <= 0xe2) return 1;
- if (c >= 0xe4 && c <= 0xef) return 1;
- if (c >= 0xf1 && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xfe) return 1;
- break;
- case ISO_8859_4:
- if (c == 0xa2) return 1;
- if (c == 0xb1 || c == 0xb3) return 1;
- if (c == 0xb5 || c == 0xb6) return 1;
- if (c >= 0xb9 && c <= 0xbc) return 1;
- if (c >= 0xbe && c <= 0xbf) return 1;
- if (c == 0xdf) return 1;
- if (c >= 0xe0 && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xfe) return 1;
- break;
- case ISO_8859_5:
- if (c >= 0xd0 && c <= 0xff && c != 0xf0 && c != 0xfd) return 1;
- break;
- case ISO_8859_6:
- break;
- case ISO_8859_7:
- if (c == 0xc0) return 1;
- if (c >= 0xdc && c <= 0xfe) return 1;
- break;
- case ISO_8859_8:
- if (c == 0xb5) return 1;
- break;
- case ISO_8859_10:
- if (c >= 0xb1 && c <= 0xb6) return 1;
- if (c >= 0xb8 && c <= 0xbc) return 1;
- if (c == 0xbe || c == 0xbf) return 1;
- if (c >= 0xdf && c <= 0xff) return 1;
- break;
- case ISO_8859_11:
- break;
- case ISO_8859_13:
- if (c == 0xb5) return 1;
- if (c == 0xb8) return 1;
- if (c == 0xba) return 1;
- if (c == 0xbf) return 1;
- if (c >= 0xdf && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xfe) return 1;
- break;
- case ISO_8859_14:
- if (c == 0xa2) return 1;
- if (c == 0xa5) return 1;
- if (c == 0xab) return 1;
- if (c == 0xb1 || c == 0xb3 || c == 0xb5) return 1;
- if (c >= 0xb8 && c <= 0xba) return 1;
- if (c == 0xbc) return 1;
- if (c == 0xbe || c == 0xbf) return 1;
- if (c >= 0xdf && c <= 0xff) return 1;
- break;
- case ISO_8859_15:
- if (c == 0xaa) return 1;
- if (c == 0xb5) return 1;
- if (c == 0xba) return 1;
- if (c >= 0xdf && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xff) return 1;
- if (c == 0xa8) return 1;
- if (c == 0xb8) return 1;
- if (c == 0xbd) return 1;
- break;
- case ISO_8859_16:
- if (c == 0xa2) return 1;
- if (c == 0xa8) return 1;
- if (c == 0xae) return 1;
- if (c == 0xb3) return 1;
- if (c >= 0xb8 && c <= 0xba) return 1;
- if (c == 0xbd) return 1;
- if (c == 0xbf) return 1;
- if (c >= 0xdf && c <= 0xff) return 1;
- break;
- case KOI8_R:
- if (c == 0xa3) return 1;
- /* fall */
- case KOI8:
- if (c >= 0xc0 && c <= 0xdf) return 1;
- break;
- default:
- exit(-1);
- }
- return 0;
- }
- static int IsPrint(int enc, int c)
- {
- if (enc == ASCII)
- return isprint(c);
- if (c >= 0x20 && c <= 0x7e) return 1;
- switch (enc) {
- case UNICODE_ISO_8859_1:
- if (c >= 0x09 && c <= 0x0d) return 1;
- if (c == 0x85) return 1;
- /* fall */
- case ISO_8859_1:
- case ISO_8859_2:
- case ISO_8859_4:
- case ISO_8859_5:
- case ISO_8859_9:
- case ISO_8859_10:
- case ISO_8859_13:
- case ISO_8859_14:
- case ISO_8859_15:
- case ISO_8859_16:
- if (c >= 0xa0 && c <= 0xff) return 1;
- break;
- case ISO_8859_3:
- if (c >= 0xa0) {
- if (c == 0xa5 || c == 0xae || c == 0xbe || c == 0xc3 || c == 0xd0 ||
- c == 0xe3 || c == 0xf0)
- return 0;
- else
- return 1;
- }
- break;
- case ISO_8859_6:
- if (c == 0xa0) return 1;
- if (c == 0xa4 || c == 0xac || c == 0xad || c == 0xbb || c == 0xbf)
- return 1;
- if (c >= 0xc1 && c <= 0xda) return 1;
- if (c >= 0xe0 && c <= 0xf2) return 1;
- break;
- case ISO_8859_7:
- if (c >= 0xa0 && c <= 0xfe &&
- c != 0xa4 && c != 0xa5 && c != 0xaa &&
- c != 0xae && c != 0xd2) return 1;
- break;
- case ISO_8859_8:
- if (c >= 0xa0 && c <= 0xfa) {
- if (c >= 0xbf && c <= 0xde) return 0;
- if (c == 0xa1) return 0;
- return 1;
- }
- break;
- case ISO_8859_11:
- if (c >= 0xa0 && c <= 0xda) return 1;
- if (c >= 0xdf && c <= 0xfb) return 1;
- break;
- case KOI8:
- if (c == 0xa0) return 1;
- if (c >= 0xc0 && c <= 0xff) return 1;
- break;
- case KOI8_R:
- if (c >= 0x80 && c <= 0xff) return 1;
- break;
- default:
- exit(-1);
- }
- return 0;
- }
- static int IsPunct(int enc, int c)
- {
- if (enc == ASCII)
- return ispunct(c);
- if (enc == UNICODE_ISO_8859_1) {
- if (c == 0x24 || c == 0x2b || c == 0x5e || c == 0x60 ||
- c == 0x7c || c == 0x7e) return 1;
- if (c >= 0x3c && c <= 0x3e) return 1;
- }
- if (c >= 0x21 && c <= 0x2f) return 1;
- if (c >= 0x3a && c <= 0x40) return 1;
- if (c >= 0x5b && c <= 0x60) return 1;
- if (c >= 0x7b && c <= 0x7e) return 1;
- switch (enc) {
- case ISO_8859_1:
- case ISO_8859_9:
- case ISO_8859_15:
- if (c == 0xad) return 1;
- /* fall */
- case UNICODE_ISO_8859_1:
- if (c == 0xa1) return 1;
- if (c == 0xab) return 1;
- if (c == 0xb7) return 1;
- if (c == 0xbb) return 1;
- if (c == 0xbf) return 1;
- break;
- case ISO_8859_2:
- case ISO_8859_4:
- case ISO_8859_5:
- case ISO_8859_14:
- if (c == 0xad) return 1;
- break;
- case ISO_8859_3:
- case ISO_8859_10:
- if (c == 0xad) return 1;
- if (c == 0xb7) return 1;
- if (c == 0xbd) return 1;
- break;
- case ISO_8859_6:
- if (c == 0xac) return 1;
- if (c == 0xad) return 1;
- if (c == 0xbb) return 1;
- if (c == 0xbf) return 1;
- break;
- case ISO_8859_7:
- if (c == 0xa1 || c == 0xa2) return 1;
- if (c == 0xab) return 1;
- if (c == 0xaf) return 1;
- if (c == 0xad) return 1;
- if (c == 0xb7 || c == 0xbb) return 1;
- break;
- case ISO_8859_8:
- if (c == 0xab) return 1;
- if (c == 0xad) return 1;
- if (c == 0xb7) return 1;
- if (c == 0xbb) return 1;
- if (c == 0xdf) return 1;
- break;
- case ISO_8859_13:
- if (c == 0xa1 || c == 0xa5) return 1;
- if (c == 0xab || c == 0xad) return 1;
- if (c == 0xb4 || c == 0xb7) return 1;
- if (c == 0xbb) return 1;
- if (c == 0xff) return 1;
- break;
- case ISO_8859_16:
- if (c == 0xa5) return 1;
- if (c == 0xab) return 1;
- if (c == 0xad) return 1;
- if (c == 0xb5) return 1;
- if (c == 0xb7) return 1;
- if (c == 0xbb) return 1;
- break;
- case KOI8_R:
- if (c == 0x9e) return 1;
- break;
- case ISO_8859_11:
- case KOI8:
- break;
- default:
- exit(-1);
- }
- return 0;
- }
- static int IsSpace(int enc, int c)
- {
- if (enc == ASCII)
- return isspace(c);
- if (c >= 0x09 && c <= 0x0d) return 1;
- if (c == 0x20) return 1;
- switch (enc) {
- case UNICODE_ISO_8859_1:
- if (c == 0x85) return 1;
- /* fall */
- case ISO_8859_1:
- case ISO_8859_2:
- case ISO_8859_3:
- case ISO_8859_4:
- case ISO_8859_5:
- case ISO_8859_6:
- case ISO_8859_7:
- case ISO_8859_8:
- case ISO_8859_9:
- case ISO_8859_10:
- case ISO_8859_11:
- case ISO_8859_13:
- case ISO_8859_14:
- case ISO_8859_15:
- case ISO_8859_16:
- case KOI8:
- if (c == 0xa0) return 1;
- break;
- case KOI8_R:
- if (c == 0x9a) return 1;
- break;
- default:
- exit(-1);
- }
- return 0;
- }
- static int IsUpper(int enc, int c)
- {
- if (enc == ASCII)
- return isupper(c);
- if (c >= 0x41 && c <= 0x5a) return 1;
- switch (enc) {
- case UNICODE_ISO_8859_1:
- case ISO_8859_1:
- case ISO_8859_9:
- if (c >= 0xc0 && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xde) return 1;
- break;
- case ISO_8859_2:
- if (c == 0xa1 || c == 0xa3) return 1;
- if (c == 0xa5 || c == 0xa6) return 1;
- if (c >= 0xa9 && c <= 0xac) return 1;
- if (c >= 0xae && c <= 0xaf) return 1;
- if (c >= 0xc0 && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xde) return 1;
- break;
- case ISO_8859_3:
- if (c == 0xa1) return 1;
- if (c == 0xa6) return 1;
- if (c >= 0xa9 && c <= 0xac) return 1;
- if (c == 0xaf) return 1;
- if (c >= 0xc0 && c <= 0xc2) return 1;
- if (c >= 0xc4 && c <= 0xcf) return 1;
- if (c >= 0xd1 && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xde) return 1;
- break;
- case ISO_8859_4:
- if (c == 0xa1 || c == 0xa3) return 1;
- if (c == 0xa5 || c == 0xa6) return 1;
- if (c >= 0xa9 && c <= 0xac) return 1;
- if (c == 0xae) return 1;
- if (c == 0xbd) return 1;
- if (c >= 0xc0 && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xde) return 1;
- break;
- case ISO_8859_5:
- if (c >= 0xa1 && c <= 0xcf && c != 0xad) return 1;
- break;
- case ISO_8859_6:
- break;
- case ISO_8859_7:
- if (c == 0xb6) return 1;
- if (c >= 0xb8 && c <= 0xba) return 1;
- if (c == 0xbc) return 1;
- if (c >= 0xbe && c <= 0xbf) return 1;
- if (c >= 0xc1 && c <= 0xdb && c != 0xd2) return 1;
- break;
- case ISO_8859_8:
- case ISO_8859_11:
- break;
- case ISO_8859_10:
- if (c >= 0xa1 && c <= 0xa6) return 1;
- if (c >= 0xa8 && c <= 0xac) return 1;
- if (c == 0xae || c == 0xaf) return 1;
- if (c >= 0xc0 && c <= 0xde) return 1;
- break;
- case ISO_8859_13:
- if (c == 0xa8) return 1;
- if (c == 0xaa) return 1;
- if (c == 0xaf) return 1;
- if (c >= 0xc0 && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xde) return 1;
- break;
- case ISO_8859_14:
- if (c == 0xa1) return 1;
- if (c == 0xa4 || c == 0xa6) return 1;
- if (c == 0xa8) return 1;
- if (c == 0xaa || c == 0xac) return 1;
- if (c == 0xaf || c == 0xb0) return 1;
- if (c == 0xb2 || c == 0xb4 || c == 0xb7) return 1;
- if (c == 0xbb || c == 0xbd) return 1;
- if (c >= 0xc0 && c <= 0xde) return 1;
- break;
- case ISO_8859_15:
- if (c >= 0xc0 && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xde) return 1;
- if (c == 0xa6) return 1;
- if (c == 0xb4) return 1;
- if (c == 0xbc) return 1;
- if (c == 0xbe) return 1;
- break;
- case ISO_8859_16:
- if (c == 0xa1) return 1;
- if (c == 0xa3) return 1;
- if (c == 0xa6) return 1;
- if (c == 0xaa) return 1;
- if (c == 0xac) return 1;
- if (c == 0xaf) return 1;
- if (c == 0xb2) return 1;
- if (c == 0xb4) return 1;
- if (c == 0xbc) return 1;
- if (c == 0xbe) return 1;
- if (c >= 0xc0 && c <= 0xde) return 1;
- break;
- case KOI8_R:
- if (c == 0xb3) return 1;
- /* fall */
- case KOI8:
- if (c >= 0xe0 && c <= 0xff) return 1;
- break;
- default:
- exit(-1);
- }
- return 0;
- }
- static int IsXDigit(int enc, int c)
- {
- if (enc == ASCII)
- return isxdigit(c);
- if (c >= 0x30 && c <= 0x39) return 1;
- if (c >= 0x41 && c <= 0x46) return 1;
- if (c >= 0x61 && c <= 0x66) return 1;
- return 0;
- }
- static int IsWord(int enc, int c)
- {
- if (enc == ASCII) {
- return (isalpha(c) || isdigit(c) || c == 0x5f);
- }
- if (c >= 0x30 && c <= 0x39) return 1;
- if (c >= 0x41 && c <= 0x5a) return 1;
- if (c == 0x5f) return 1;
- if (c >= 0x61 && c <= 0x7a) return 1;
- switch (enc) {
- case UNICODE_ISO_8859_1:
- case ISO_8859_1:
- case ISO_8859_9:
- if (c == 0xaa) return 1;
- if (c >= 0xb2 && c <= 0xb3) return 1;
- if (c == 0xb5) return 1;
- if (c >= 0xb9 && c <= 0xba) return 1;
- if (c >= 0xbc && c <= 0xbe) return 1;
- if (c >= 0xc0 && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xff) return 1;
- break;
- case ISO_8859_2:
- if (c == 0xa1 || c == 0xa3) return 1;
- if (c == 0xa5 || c == 0xa6) return 1;
- if (c >= 0xa9 && c <= 0xac) return 1;
- if (c >= 0xae && c <= 0xaf) return 1;
- if (c == 0xb1 || c == 0xb3) return 1;
- if (c == 0xb5 || c == 0xb6) return 1;
- if (c >= 0xb9 && c <= 0xbc) return 1;
- if (c >= 0xbe && c <= 0xbf) return 1;
- if (c >= 0xc0 && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xfe) return 1;
- break;
- case ISO_8859_3:
- if (c == 0xa1) return 1;
- if (c == 0xa6) return 1;
- if (c >= 0xa9 && c <= 0xac) return 1;
- if (c == 0xaf) return 1;
- if (c >= 0xb1 && c <= 0xb3) return 1;
- if (c == 0xb5 || c == 0xb6) return 1;
- if (c >= 0xb9 && c <= 0xbd) return 1;
- if (c == 0xbf) return 1;
- if (c >= 0xc0 && c <= 0xc2) return 1;
- if (c >= 0xc4 && c <= 0xcf) return 1;
- if (c >= 0xd1 && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xe2) return 1;
- if (c >= 0xe4 && c <= 0xef) return 1;
- if (c >= 0xf1 && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xfe) return 1;
- break;
- case ISO_8859_4:
- if (c >= 0xa1 && c <= 0xa3) return 1;
- if (c == 0xa5 || c == 0xa6) return 1;
- if (c >= 0xa9 && c <= 0xac) return 1;
- if (c == 0xae) return 1;
- if (c == 0xb1 || c == 0xb3) return 1;
- if (c == 0xb5 || c == 0xb6) return 1;
- if (c >= 0xb9 && c <= 0xbf) return 1;
- if (c >= 0xc0 && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xfe) return 1;
- break;
- case ISO_8859_5:
- if (c >= 0xa1 && c <= 0xcf && c != 0xad) return 1;
- if (c >= 0xd0 && c <= 0xff && c != 0xf0 && c != 0xfd) return 1;
- break;
- case ISO_8859_6:
- if (c >= 0xc1 && c <= 0xda) return 1;
- if (c >= 0xe0 && c <= 0xea) return 1;
- if (c >= 0xeb && c <= 0xf2) return 1;
- break;
- case ISO_8859_7:
- if (c == 0xb2 || c == 0xb3) return 1;
- if (c == 0xb6) return 1;
- if (c >= 0xb8 && c <= 0xba) return 1;
- if (c >= 0xbc && c <= 0xbf) return 1;
- if (c == 0xc0) return 1;
- if (c >= 0xc1 && c <= 0xdb && c != 0xd2) return 1;
- if (c >= 0xdc && c <= 0xfe) return 1;
- break;
- case ISO_8859_8:
- if (c == 0xb2 || c == 0xb3 || c == 0xb5 || c == 0xb9) return 1;
- if (c >= 0xbc && c <= 0xbe) return 1;
- if (c >= 0xe0 && c <= 0xfa) return 1;
- break;
- case ISO_8859_10:
- if (c >= 0xa1 && c <= 0xff) {
- if (c != 0xa7 && c != 0xad && c != 0xb0 && c != 0xb7 && c != 0xbd)
- return 1;
- }
- break;
- case ISO_8859_11:
- if (c >= 0xa1 && c <= 0xda) return 1;
- if (c >= 0xdf && c <= 0xfb) return 1;
- break;
- case ISO_8859_13:
- if (c == 0xa8) return 1;
- if (c == 0xaa) return 1;
- if (c == 0xaf) return 1;
- if (c == 0xb2 || c == 0xb3 || c == 0xb5 || c == 0xb9) return 1;
- if (c >= 0xbc && c <= 0xbe) return 1;
- if (c == 0xb8) return 1;
- if (c == 0xba) return 1;
- if (c >= 0xbf && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xfe) return 1;
- break;
- case ISO_8859_14:
- if (c >= 0xa1 && c <= 0xff) {
- if (c == 0xa3 || c == 0xa7 || c == 0xa9 || c == 0xad || c == 0xae ||
- c == 0xb6) return 0;
- return 1;
- }
- break;
- case ISO_8859_15:
- if (c == 0xaa) return 1;
- if (c >= 0xb2 && c <= 0xb3) return 1;
- if (c == 0xb5) return 1;
- if (c >= 0xb9 && c <= 0xba) return 1;
- if (c >= 0xbc && c <= 0xbe) return 1;
- if (c >= 0xc0 && c <= 0xd6) return 1;
- if (c >= 0xd8 && c <= 0xf6) return 1;
- if (c >= 0xf8 && c <= 0xff) return 1;
- if (c == 0xa6) return 1;
- if (c == 0xa8) return 1;
- if (c == 0xb4) return 1;
- if (c == 0xb8) return 1;
- break;
- case ISO_8859_16:
- if (c == 0xa1) return 1;
- if (c == 0xa2) return 1;
- if (c == 0xa3) return 1;
- if (c == 0xa6) return 1;
- if (c == 0xa8) return 1;
- if (c == 0xaa) return 1;
- if (c == 0xac) return 1;
- if (c == 0xae) return 1;
- if (c == 0xaf) return 1;
- if (c == 0xb2) return 1;
- if (c == 0xb3) return 1;
- if (c == 0xb4) return 1;
- if (c >= 0xb8 && c <= 0xba) return 1;
- if (c == 0xbc) return 1;
- if (c == 0xbd) return 1;
- if (c == 0xbe) return 1;
- if (c == 0xbf) return 1;
- if (c >= 0xc0 && c <= 0xde) return 1;
- if (c >= 0xdf && c <= 0xff) return 1;
- break;
- case KOI8_R:
- if (c == 0x9d) return 1;
- if (c == 0xa3 || c == 0xb3) return 1;
- /* fall */
- case KOI8:
- if (c >= 0xc0 && c <= 0xff) return 1;
- break;
- default:
- exit(-1);
- }
- return 0;
- }
- static int IsAscii(int enc ARG_UNUSED, int c)
- {
- if (c >= 0x00 && c <= 0x7f) return 1;
- return 0;
- }
- static int IsNewline(int enc ARG_UNUSED, int c)
- {
- if (c == 0x0a) return 1;
- return 0;
- }
- static int exec(FILE* fp, ENC_INFO* einfo)
- {
- #define NCOL 8
- int c, val, enc;
- enc = einfo->num;
- fprintf(fp, "static const unsigned short Enc%s_CtypeTable[256] = {\n",
- einfo->name);
- for (c = 0; c < 256; c++) {
- val = 0;
- if (IsNewline(enc, c)) val |= BIT_CTYPE_NEWLINE;
- if (IsAlpha (enc, c)) val |= (BIT_CTYPE_ALPHA | BIT_CTYPE_ALNUM);
- if (IsBlank (enc, c)) val |= BIT_CTYPE_BLANK;
- if (IsCntrl (enc, c)) val |= BIT_CTYPE_CNTRL;
- if (IsDigit (enc, c)) val |= (BIT_CTYPE_DIGIT | BIT_CTYPE_ALNUM);
- if (IsGraph (enc, c)) val |= BIT_CTYPE_GRAPH;
- if (IsLower (enc, c)) val |= BIT_CTYPE_LOWER;
- if (IsPrint (enc, c)) val |= BIT_CTYPE_PRINT;
- if (IsPunct (enc, c)) val |= BIT_CTYPE_PUNCT;
- if (IsSpace (enc, c)) val |= BIT_CTYPE_SPACE;
- if (IsUpper (enc, c)) val |= BIT_CTYPE_UPPER;
- if (IsXDigit(enc, c)) val |= BIT_CTYPE_XDIGIT;
- if (IsWord (enc, c)) val |= BIT_CTYPE_WORD;
- if (IsAscii (enc, c)) val |= BIT_CTYPE_ASCII;
- if (c % NCOL == 0) fputs(" ", fp);
- fprintf(fp, "0x%04x", val);
- if (c != 255) fputs(",", fp);
- if (c != 0 && c % NCOL == (NCOL-1))
- fputs("\n", fp);
- else
- fputs(" ", fp);
- }
- fprintf(fp, "};\n");
- return 0;
- }
- extern int main(int argc ARG_UNUSED, char* argv[] ARG_UNUSED)
- {
- int i;
- FILE* fp = stdout;
- setlocale(LC_ALL, "C");
- /* setlocale(LC_ALL, "POSIX"); */
- /* setlocale(LC_ALL, "en_GB.iso88591"); */
- /* setlocale(LC_ALL, "de_BE.iso88591"); */
- /* setlocale(LC_ALL, "fr_FR.iso88591"); */
- for (i = 0; i < (int )(sizeof(Info)/sizeof(ENC_INFO)); i++) {
- exec(fp, &Info[i]);
- }
- return 0;
- }
|