12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184 | /********************************************************************** mktable.c **********************************************************************/ /*- * Copyright (c) 2002-2016 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> #ifndef __USE_ISOC99 #define __USE_ISOC99 #endif #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; const 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; int r; enc = einfo->num; r = fprintf(fp, "static const unsigned short Enc%s_CtypeTable[256] = {\n", einfo->name); if (r < 0) return -1; 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) { r = fputs(" ", fp); if (r < 0) return -1; } r = fprintf(fp, "0x%04x", val); if (r < 0) return -1; if (c != 255) { r = fputs(",", fp); if (r < 0) return -1; } if (c != 0 && c % NCOL == (NCOL-1)) r = fputs("\n", fp); else r = fputs(" ", fp); if (r < 0) return -1; } r = fprintf(fp, "};\n"); if (r < 0) return -1; return 0; } extern int main(int argc ARG_UNUSED, char* argv[] ARG_UNUSED) { int r; 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++) { r = exec(fp, &Info[i]); if (r < 0) { fprintf(stderr, "FAIL exec(): %d\n", r); return -1; } } return 0; }
|