_fallcGenConv.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* lcGenConv.c 1.5 - Fujitsu source for CDEnext 96/03/14 15:45:41 */
  24. /* $XConsortium: _fallcGenConv.c /main/1 1996/04/08 15:17:00 cde-fuj $ */
  25. /*
  26. * Copyright 1992, 1993 by TOSHIBA Corp.
  27. *
  28. * Permission to use, copy, modify, and distribute this software and its
  29. * documentation for any purpose and without fee is hereby granted, provided
  30. * that the above copyright notice appear in all copies and that both that
  31. * copyright notice and this permission notice appear in supporting
  32. * documentation, and that the name of TOSHIBA not be used in advertising
  33. * or publicity pertaining to distribution of the software without specific,
  34. * written prior permission. TOSHIBA make no representations about the
  35. * suitability of this software for any purpose. It is provided "as is"
  36. * without express or implied warranty.
  37. *
  38. * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  39. * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  40. * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  41. * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  42. * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  43. * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  44. * SOFTWARE.
  45. *
  46. * Author: Katsuhisa Yano TOSHIBA Corp.
  47. * mopi@osa.ilab.toshiba.co.jp
  48. */
  49. /*
  50. * (c) Copyright 1995 FUJITSU LIMITED
  51. * This is source code modified by FUJITSU LIMITED under the Joint
  52. * Development Agreement for the CDEnext PST.
  53. * This is unpublished proprietary source code of FUJITSU LIMITED
  54. *
  55. * Modifier: Masayoshi Shimamura FUJITSU LIMITED
  56. *
  57. */
  58. #include "_fallibint.h"
  59. #include "_fallcGeneric.h"
  60. #include <stdio.h>
  61. typedef struct _CTDataRec {
  62. char *name;
  63. char *encoding; /* Compound Text encoding */
  64. } CTDataRec, *CTData;
  65. static CTDataRec default_ct_data[] =
  66. {
  67. { "ISO8859-1:GL", "\033(B" },
  68. { "ISO8859-1:GR", "\033-A" },
  69. { "ISO8859-2:GR", "\033-B" },
  70. { "ISO8859-3:GR", "\033-C" },
  71. { "ISO8859-4:GR", "\033-D" },
  72. { "ISO8859-7:GR", "\033-F" },
  73. { "ISO8859-6:GR", "\033-G" },
  74. { "ISO8859-8:GR", "\033-H" },
  75. { "ISO8859-5:GR", "\033-L" },
  76. { "ISO8859-9:GR", "\033-M" },
  77. { "JISX0201.1976-0:GL", "\033(J" },
  78. { "JISX0201.1976-0:GR", "\033)I" },
  79. { "GB2312.1980-0:GL", "\033$(A" },
  80. { "GB2312.1980-0:GR", "\033$)A" },
  81. { "JISX0208.1983-0:GL", "\033$(B" },
  82. { "JISX0208.1983-0:GR", "\033$)B" },
  83. { "KSC5601.1987-0:GL", "\033$(C" },
  84. { "KSC5601.1987-0:GR", "\033$)C" },
  85. } ;
  86. static CTDataRec directionality_data[] =
  87. {
  88. { "BEGIN_LEFT-TO-RIGHT_TEXT", "\2331]" },
  89. { "BEGIN_RIGHT-TO-LEFT_TEXT", "\2332]" },
  90. { "END_OF_STRING", "\233]" },
  91. };
  92. typedef struct _StateRec {
  93. XLCd lcd;
  94. XlcCharSet charset; /* charset of current state */
  95. XlcCharSet GL_charset; /* charset of initial state in GL */
  96. XlcCharSet GR_charset; /* charset of initial state in GR */
  97. } StateRec, *State;
  98. #define GR 0x80 /* begins right-side (non-ascii) region */
  99. #define GL 0x7f /* ends left-side (ascii) region */
  100. #define ESC 0x1b
  101. #define CSI 0x9b
  102. #define STX 0x02
  103. #define isleftside(c) (((c) & GR) ? 0 : 1)
  104. #define isrightside(c) (!isleftside(c))
  105. /* -------------------------------------------------------------------------- */
  106. /* Misc */
  107. /* -------------------------------------------------------------------------- */
  108. static int
  109. compare(char *src, char *encoding, int length)
  110. {
  111. char *start = src;
  112. while (length-- > 0) {
  113. if (*src++ != *encoding++)
  114. return 0;
  115. if (*encoding == '\0')
  116. return src - start;
  117. }
  118. return 0;
  119. }
  120. static unsigned long
  121. conv_to_dest(Conversion conv, unsigned long code)
  122. {
  123. int i;
  124. int conv_num = conv->conv_num;
  125. FontScope convlist = conv->convlist;
  126. for (i = 0; i < conv_num; i++) {
  127. if (convlist[i].start <= code && code <= convlist[i].end) {
  128. switch (convlist[i].shift_direction) {
  129. case '+':
  130. return(code + convlist[i].shift);
  131. case '-':
  132. return(code - convlist[i].shift);
  133. default:
  134. return(code);
  135. }
  136. }
  137. }
  138. return(code);
  139. }
  140. static unsigned long
  141. conv_to_source(Conversion conv, unsigned long code)
  142. {
  143. int i;
  144. int conv_num;
  145. FontScope convlist;
  146. unsigned long start_p;
  147. unsigned long start_m;
  148. unsigned long end_p;
  149. unsigned long end_m;
  150. if (!conv)
  151. return(code);
  152. conv_num = conv->conv_num;
  153. convlist = conv->convlist;
  154. for (i = 0; i < conv_num; i++) {
  155. start_p = convlist[i].start + convlist[i].shift;
  156. start_m = convlist[i].start - convlist[i].shift;
  157. end_p = convlist[i].end + convlist[i].shift;
  158. end_m = convlist[i].end - convlist[i].shift;
  159. switch (convlist[i].shift_direction) {
  160. case '+':
  161. if (start_p <= code && code <= end_p)
  162. return(code - convlist[i].shift);
  163. break;
  164. case '-':
  165. if (start_m <= code && code <= end_m)
  166. return(code + convlist[i].shift);
  167. break;
  168. default:
  169. continue;
  170. }
  171. }
  172. return(code);
  173. }
  174. static unsigned long
  175. mb_to_gi(unsigned long mb, CodeSet codeset)
  176. {
  177. int i;
  178. unsigned long mb_tmp, mask = 0;
  179. if (codeset->mbconv) {
  180. mb_tmp = conv_to_dest(codeset->mbconv, mb);
  181. if (mb_tmp != mb)
  182. return(mb_tmp);
  183. }
  184. if (codeset->side == XlcC0 || codeset->side == XlcGL ||
  185. codeset->side == XlcC1 || codeset->side == XlcGR) {
  186. for (i = 0; i < codeset->length; i++)
  187. mask = (mask << 8) | GL;
  188. mb = mb & mask;
  189. }
  190. return(mb);
  191. }
  192. static unsigned long
  193. gi_to_mb(unsigned long glyph_index, CodeSet codeset)
  194. {
  195. int i;
  196. unsigned long mask = 0;
  197. if (codeset->side == XlcC1 || codeset->side == XlcGR) {
  198. for (i = 0; i < codeset->length; i++)
  199. mask = (mask << 8) | GR;
  200. glyph_index = glyph_index | mask;
  201. }
  202. if (codeset->mbconv)
  203. return( conv_to_source(codeset->mbconv, glyph_index) );
  204. return(glyph_index);
  205. }
  206. static Bool
  207. gi_to_wc(XLCd lcd, unsigned long glyph_index, CodeSet codeset, wchar_t *wc)
  208. {
  209. unsigned char mask = 0;
  210. unsigned long wc_encoding = codeset->wc_encoding;
  211. int i, length = codeset->length;
  212. unsigned long wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits);
  213. for (i = wc_shift_bits; i > 0; i--)
  214. mask = (mask << 1) | 0x01;
  215. for (*wc = 0, length--; length >= 0; length--)
  216. *wc = (*wc << wc_shift_bits) | ((glyph_index >> (length * 8 )) & mask);
  217. *wc = *wc | wc_encoding;
  218. return(True);
  219. }
  220. static Bool
  221. wc_to_gi(XLCd lcd, wchar_t wc, unsigned long *glyph_index, CodeSet *codeset)
  222. {
  223. int i;
  224. unsigned char mask = 0;
  225. unsigned long wc_encoding;
  226. unsigned long wc_encode_mask = XLC_GENERIC(lcd, wc_encode_mask);
  227. unsigned long wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits);
  228. int codeset_num = XLC_GENERIC(lcd, codeset_num);
  229. CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
  230. wc_encoding = wc & wc_encode_mask;
  231. for (*codeset = NULL, i = 0; i < codeset_num; i++) {
  232. if (wc_encoding == codeset_list[i]->wc_encoding) {
  233. *codeset = codeset_list[i];
  234. break;
  235. }
  236. }
  237. if (*codeset == NULL)
  238. return(False);
  239. for (i = wc_shift_bits; i > 0; i--)
  240. mask = (mask << 1) | 0x01;
  241. wc = wc & ~wc_encode_mask;
  242. for (*glyph_index = 0, i = (*codeset)->length - 1; i >= 0; i--)
  243. *glyph_index = (*glyph_index << 8) |
  244. ( ((unsigned long)wc >> (i * wc_shift_bits)) & mask );
  245. return(True);
  246. }
  247. static CodeSet
  248. byteM_parse_codeset(XLCd lcd, XPointer inbufptr)
  249. {
  250. unsigned char ch;
  251. CodeSet codeset;
  252. ByteInfoList byteM;
  253. ByteInfoListRec byteM_rec;
  254. ByteInfo byteinfo;
  255. ByteInfoRec byteinfo_rec;
  256. Bool hit;
  257. int i, j, k;
  258. int codeset_num = XLC_GENERIC(lcd, codeset_num);
  259. CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
  260. for (i = 0; i < codeset_num; i++) {
  261. codeset = codeset_list[i];
  262. byteM = codeset->byteM;
  263. if (codeset->side != XlcNONE || byteM == NULL)
  264. continue;
  265. for (j = 0; j < codeset->length; j++) {
  266. ch = *((unsigned char *)(inbufptr + j));
  267. byteM_rec = byteM[j];
  268. byteinfo = byteM_rec.byteinfo;
  269. for (hit=False,k=0; k < byteM_rec.byteinfo_num; k++) {
  270. byteinfo_rec = byteinfo[k];
  271. if (byteinfo_rec.start <= ch && ch <= byteinfo_rec.end) {
  272. hit = True;
  273. break;
  274. }
  275. }
  276. if (!hit)
  277. break;
  278. }
  279. if (hit)
  280. return(codeset);
  281. }
  282. return(NULL);
  283. }
  284. static CodeSet
  285. GLGR_parse_codeset(XLCd lcd, unsigned char ch)
  286. {
  287. int i;
  288. CodeSet initial_state_GL = XLC_GENERIC(lcd, initial_state_GL);
  289. CodeSet initial_state_GR = XLC_GENERIC(lcd, initial_state_GR);
  290. CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
  291. int codeset_num = XLC_GENERIC(lcd, codeset_num);
  292. XlcSide side = XlcGL;
  293. CodeSet codeset = initial_state_GL;
  294. if (isrightside(ch)) {
  295. side = XlcGR;
  296. codeset = initial_state_GR;
  297. }
  298. if (codeset)
  299. return(codeset);
  300. for (i = 0; i < codeset_num; i++) {
  301. codeset = codeset_list[i];
  302. if (codeset->side == side)
  303. return(codeset);
  304. }
  305. return(NULL);
  306. }
  307. static XlcCharSet
  308. gi_parse_charset(unsigned long glyph_index, CodeSet codeset)
  309. {
  310. int i;
  311. size_t table_size = sizeof(default_ct_data) / sizeof(default_ct_data[0]);
  312. XlcCharSet *charset_list = codeset->charset_list;
  313. int num_charsets = codeset->num_charsets;
  314. ExtdSegment ctextseg = codeset->ctextseg;
  315. XlcCharSet charset;
  316. int area_num;
  317. FontScope area;
  318. /* lockup ct sequence */
  319. for (i = 0; i < num_charsets; i++) {
  320. charset = charset_list[i];
  321. if (*charset->ct_sequence != '\0')
  322. break;
  323. }
  324. if (i >= num_charsets)
  325. return(NULL);
  326. /* Standard Character Set Encoding ? */
  327. for (i = 0; i < table_size; i++){
  328. if (compare(charset->ct_sequence,
  329. default_ct_data[i].encoding, strlen(charset->ct_sequence))){
  330. if (!ctextseg)
  331. return(charset);
  332. area = ctextseg->area;
  333. area_num = ctextseg->area_num;
  334. for (i = 0; i < area_num; i++) {
  335. if (area[i].start <= glyph_index && glyph_index <= area[i].end) {
  336. charset = ctextseg->charset;
  337. if (*charset->ct_sequence == '\0')
  338. return(NULL);
  339. break;
  340. }
  341. }
  342. }
  343. }
  344. return(charset);
  345. }
  346. static Bool
  347. ct_parse_csi(XPointer inbufptr, int *ctr_seq_len)
  348. {
  349. int i;
  350. int num = sizeof(directionality_data) / sizeof(directionality_data[0]);
  351. for (i = 0; i < num; i++) {
  352. if ( !(*ctr_seq_len = strlen(directionality_data[i].encoding)) )
  353. continue;
  354. if ( strncmp(inbufptr, directionality_data[i].encoding,
  355. *ctr_seq_len) == 0)
  356. return(True);
  357. }
  358. return(False);
  359. }
  360. static int
  361. cmp_esc_sequence(XPointer inbufptr, char *ct_sequence, char *encoding_name)
  362. {
  363. size_t table_size = sizeof(default_ct_data) / sizeof(default_ct_data[0]);
  364. int i, seq_len, name_len, total_len;
  365. unsigned char byte_m, byte_l;
  366. /* check esc sequence */
  367. if ( !(seq_len = strlen(ct_sequence) ) )
  368. return(0);
  369. if ( strncmp(inbufptr, ct_sequence, seq_len) != 0)
  370. return(0);
  371. /* Standard Character Set Encoding ? */
  372. for (i = 0; i < table_size; i++) {
  373. if (compare(ct_sequence,
  374. default_ct_data[i].encoding, strlen(ct_sequence)))
  375. return(seq_len);
  376. }
  377. /*
  378. * Non-Standard Character Set Encoding
  379. *
  380. * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+
  381. * | esc sequence | M | L | encoding name | STX |
  382. * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+
  383. * 4bytes 1byte 1byte variable length 1byte
  384. * | |
  385. * +-----------------------------------------+
  386. * name length = ((M - 128) * 128) + (L - 128)
  387. */
  388. /* get length of encoding name */
  389. inbufptr += seq_len;
  390. byte_m = *inbufptr++;
  391. byte_l = *inbufptr++;
  392. name_len = ((byte_m - 128) * 128) + (byte_l - 128);
  393. total_len = seq_len + name_len;
  394. /* compare encoding names */
  395. if ( strncmp(inbufptr, encoding_name, name_len - 3) != 0 )
  396. return(0);
  397. /* check STX (Start of Text) */
  398. inbufptr = inbufptr + name_len - 3;
  399. if ( *inbufptr != STX )
  400. return(0);
  401. return(total_len);
  402. }
  403. static Bool
  404. ct_parse_charset(
  405. XLCd lcd,
  406. XPointer inbufptr,
  407. XlcCharSet *charset,
  408. int *ctr_seq_len)
  409. {
  410. int i, j;
  411. ExtdSegment ctextseg;
  412. int num_charsets;
  413. XlcCharSet *charset_list;
  414. CodeSet codeset;
  415. int codeset_num = XLC_GENERIC(lcd, codeset_num);
  416. CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
  417. int segment_conv_num = XLC_GENERIC(lcd, segment_conv_num);
  418. SegConv segment_conv = XLC_GENERIC(lcd, segment_conv);
  419. /* get charset from XLC_XLOCALE by escape sequence */
  420. for (i = 0; i < codeset_num; i++) {
  421. codeset = codeset_list[i];
  422. num_charsets = codeset->num_charsets;
  423. charset_list = codeset->charset_list;
  424. ctextseg = codeset->ctextseg;
  425. for (j = 0; j < num_charsets; j++) {
  426. *charset = charset_list[j];
  427. if ( *ctr_seq_len = cmp_esc_sequence(inbufptr,
  428. (*charset)->ct_sequence, (*charset)->encoding_name) )
  429. return(True);
  430. }
  431. if (ctextseg) {
  432. *charset = ctextseg->charset;
  433. if ( *ctr_seq_len = cmp_esc_sequence(inbufptr,
  434. (*charset)->ct_sequence, (*charset)->encoding_name) )
  435. return(True);
  436. }
  437. }
  438. /* get charset from XLC_SEGMENTCONVERSION by escape sequence */
  439. if (!segment_conv)
  440. return(False);
  441. for (i = 0; i < segment_conv_num; i++) {
  442. *charset = segment_conv[i].source;
  443. if ( *ctr_seq_len = cmp_esc_sequence(inbufptr,
  444. (*charset)->ct_sequence, (*charset)->encoding_name) )
  445. return(True);
  446. *charset = segment_conv[i].dest;
  447. if ( *ctr_seq_len = cmp_esc_sequence(inbufptr,
  448. (*charset)->ct_sequence, (*charset)->encoding_name) )
  449. return(True);
  450. }
  451. return(False);
  452. }
  453. static Bool
  454. segment_conversion(XLCd lcd, XlcCharSet *charset, unsigned long *glyph_index)
  455. {
  456. int i;
  457. int segment_conv_num = XLC_GENERIC(lcd, segment_conv_num);
  458. SegConv segment_conv = XLC_GENERIC(lcd, segment_conv);
  459. FontScopeRec range;
  460. ConversionRec conv_rec;
  461. if (!segment_conv)
  462. return(True);
  463. for (i = 0; i < segment_conv_num; i++) {
  464. if (segment_conv[i].source == *charset)
  465. break;
  466. }
  467. if (i >= segment_conv_num)
  468. return(True);
  469. range = segment_conv[i].range;
  470. if (*glyph_index < range.start || range.end < *glyph_index)
  471. return(True);
  472. *charset = segment_conv[i].dest;
  473. conv_rec.conv_num = segment_conv[i].conv_num;
  474. conv_rec.convlist = segment_conv[i].conv;
  475. *glyph_index = conv_to_dest(&conv_rec, *glyph_index);
  476. return(True);
  477. }
  478. CodeSet
  479. _fallcGetCodeSetFromName(XLCd lcd, char *name)
  480. {
  481. int i, j;
  482. XlcCharSet charset;
  483. int num_charsets;
  484. XlcCharSet *charset_list;
  485. CodeSet codeset;
  486. int codeset_num = XLC_GENERIC(lcd, codeset_num);
  487. CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
  488. for (i = 0; i < codeset_num; i++) {
  489. codeset = codeset_list[i];
  490. num_charsets = codeset->num_charsets;
  491. charset_list = codeset->charset_list;
  492. for (j = 0; j < num_charsets; j++) {
  493. charset = charset_list[j];
  494. if (!strlen(charset->name))
  495. continue;
  496. if ( strcmp(charset->name, name) == 0)
  497. return(codeset);
  498. }
  499. }
  500. return(NULL);
  501. }
  502. static Bool
  503. _XlcGetCodeSetFromCharSet(
  504. XLCd lcd,
  505. XlcCharSet charset,
  506. CodeSet *codeset,
  507. unsigned long *glyph_index)
  508. {
  509. int i, j, num;
  510. CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
  511. XlcCharSet *charset_list;
  512. int codeset_num, num_charsets;
  513. Conversion ctconv;
  514. unsigned long glyph_index_tmp;
  515. ExtdSegment ctextseg;
  516. size_t table_size = sizeof(default_ct_data) / sizeof(default_ct_data[0]);
  517. codeset_num = XLC_GENERIC(lcd, codeset_num);
  518. for (num = 0 ; num < codeset_num; num++) {
  519. *codeset = codeset_list[num];
  520. ctconv = (*codeset)->ctconv;
  521. ctextseg = (*codeset)->ctextseg;
  522. num_charsets = (*codeset)->num_charsets;
  523. charset_list = (*codeset)->charset_list;
  524. glyph_index_tmp = conv_to_source(ctconv, *glyph_index);
  525. /* Standard Character Set Encoding ? */
  526. for (i = 0; i < table_size; i++) {
  527. if (compare(charset->ct_sequence,
  528. default_ct_data[i].encoding, strlen(charset->ct_sequence)))
  529. break;
  530. }
  531. if (i < table_size) {
  532. /* Standard Character Set Encoding */
  533. if (glyph_index_tmp == *glyph_index) {
  534. for (j = 0; j < num_charsets; j++) {
  535. if (charset_list[j] == charset) {
  536. goto end_loop;
  537. }
  538. }
  539. }
  540. } else {
  541. /* Non-Standard Character Set Encoding */
  542. for (j = 0; j < num_charsets; j++) {
  543. if (charset_list[j] == charset) {
  544. goto end_loop;
  545. }
  546. }
  547. if (glyph_index_tmp != *glyph_index) {
  548. if (ctextseg->charset == charset) {
  549. goto end_loop;
  550. }
  551. }
  552. }
  553. }
  554. end_loop:
  555. if (num < codeset_num) {
  556. *glyph_index = glyph_index_tmp;
  557. return(True);
  558. }
  559. return(False);
  560. }
  561. static Bool
  562. check_string_encoding(CodeSet codeset)
  563. {
  564. int i;
  565. XlcCharSet charset;
  566. XlcCharSet *charset_list = codeset->charset_list;
  567. int num_charsets = codeset->num_charsets;
  568. for (i = 0; i < num_charsets; i++) {
  569. charset = charset_list[i];
  570. if ( strcmp(charset->encoding_name, "ISO8859-1") == 0 ||
  571. charset->string_encoding)
  572. return(True);
  573. }
  574. return(False);
  575. }
  576. /* -------------------------------------------------------------------------- */
  577. /* Init */
  578. /* -------------------------------------------------------------------------- */
  579. static void
  580. init_state(XlcConv conv)
  581. {
  582. State state = (State) conv->state;
  583. /* for CT */
  584. state->charset = NULL;
  585. state->GL_charset = _fallcGetCharSet("ISO8859-1:GL");
  586. state->GR_charset = _fallcGetCharSet("ISO8859-1:GR");
  587. }
  588. /* -------------------------------------------------------------------------- */
  589. /* Convert */
  590. /* -------------------------------------------------------------------------- */
  591. static int
  592. mbstowcs_org(
  593. XlcConv conv,
  594. XPointer *from,
  595. int *from_left,
  596. XPointer *to,
  597. int *to_left,
  598. XPointer *args,
  599. int num_args)
  600. {
  601. State state = (State) conv->state;
  602. XLCd lcd = state->lcd;
  603. unsigned char ch;
  604. unsigned long mb = 0;
  605. wchar_t wc;
  606. int length = 0, len_left = 0;
  607. int unconv_num = 0;
  608. int num;
  609. Bool ss_flag = 0;
  610. CodeSet codeset = NULL;
  611. ParseInfo parse_info;
  612. XPointer inbufptr = *from;
  613. wchar_t *outbufptr = (wchar_t *) *to;
  614. int from_size = *from_left;
  615. unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
  616. ParseInfo *mb_parse_list = XLC_GENERIC(lcd, mb_parse_list);
  617. if (*from_left > *to_left)
  618. *from_left = *to_left;
  619. while (*from_left && *to_left) {
  620. ch = *inbufptr++;
  621. (*from_left)--;
  622. /* null ? */
  623. if (!ch) {
  624. if (outbufptr) {*outbufptr++ = L'\0';}
  625. (*to_left)--;
  626. /* error check */
  627. if (len_left) {
  628. unconv_num += (length - len_left);
  629. len_left = 0;
  630. }
  631. continue;
  632. }
  633. /* same mb char data */
  634. if (len_left){
  635. mb = (mb << 8) | ch; /* 1 byte left shift */
  636. len_left--;
  637. /* last of one mb char data */
  638. if (!len_left) {
  639. gi_to_wc(lcd, mb_to_gi(mb, codeset), codeset, &wc);
  640. if (outbufptr) {*outbufptr++ = wc;}
  641. (*to_left)--;
  642. }
  643. }
  644. /* next mb char data for single shift ? */
  645. if (mb_parse_table) {
  646. if ((num = mb_parse_table[ch]) > 0) {
  647. parse_info = mb_parse_list[num - 1];
  648. codeset = parse_info->codeset;
  649. length = len_left = codeset->length;
  650. mb = 0;
  651. ss_flag = 1;
  652. continue;
  653. }
  654. }
  655. /* next mb char data for byteM ? */
  656. if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1))) ||
  657. /* next mb char data for GL or GR side ? */
  658. (codeset = GLGR_parse_codeset(lcd, ch))){
  659. length = len_left = codeset->length;
  660. mb = 0;
  661. ss_flag = 0;
  662. }
  663. /* can't find codeset for the ch */
  664. unconv_num++;
  665. continue;
  666. } /* end of while */
  667. /* error check on last char */
  668. if (len_left) {
  669. inbufptr -= (length - len_left + ss_flag);
  670. (*from_left) += (length - len_left + ss_flag);
  671. unconv_num += (length - len_left + ss_flag);
  672. }
  673. *from = *from + from_size;
  674. *from_left = 0;
  675. *to = (XPointer)outbufptr;
  676. return unconv_num;
  677. }
  678. static int
  679. wcstombs_org(
  680. XlcConv conv,
  681. XPointer *from,
  682. int *from_left,
  683. XPointer *to,
  684. int *to_left,
  685. XPointer *args,
  686. int num_args)
  687. {
  688. State state = (State) conv->state;
  689. XLCd lcd = state->lcd;
  690. char *encoding;
  691. unsigned long mb, glyph_index;
  692. wchar_t wc;
  693. int length;
  694. int unconv_num = 0;
  695. CodeSet codeset;
  696. wchar_t *inbufptr = (wchar_t *) *from;
  697. XPointer outbufptr = *to;
  698. int from_size = *from_left;
  699. char *default_string = XLC_PUBLIC(lcd, default_string);
  700. int defstr_len = strlen(default_string);
  701. if (*from_left > *to_left)
  702. *from_left = *to_left;
  703. while (*from_left && *to_left) {
  704. wc = *inbufptr++;
  705. (*from_left)--;
  706. /* null ? */
  707. if (!wc) {
  708. if (outbufptr) {*outbufptr++ = '\0';}
  709. (*to_left)--;
  710. continue;
  711. }
  712. /* convert */
  713. if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
  714. /* output default_string of falDefaultString() */
  715. if (*to_left < defstr_len)
  716. break;
  717. if (outbufptr) {strncpy((char *)outbufptr, default_string, defstr_len);}
  718. if (outbufptr) {outbufptr += defstr_len;}
  719. (*to_left) -= defstr_len;
  720. unconv_num++;
  721. } else {
  722. mb = gi_to_mb(glyph_index, codeset);
  723. if (codeset->parse_info) {
  724. /* output shift sequence */
  725. encoding = codeset->parse_info->encoding;
  726. length = strlen(encoding);
  727. if (*to_left < length)
  728. break;
  729. if (outbufptr) {strncpy((char *)outbufptr, encoding, length);}
  730. if (outbufptr) {outbufptr += length;}
  731. (*to_left) -= length;
  732. }
  733. /* output characters */
  734. length = codeset->length;
  735. if (*to_left < length)
  736. break;
  737. if (outbufptr) {strncpy((char *)outbufptr, ((char *)&mb)+sizeof(mb)-length, length);}
  738. if (outbufptr) {outbufptr += length;}
  739. (*to_left) -= length;
  740. }
  741. } /* end of while */
  742. *from = *from + from_size;
  743. *from_left = 0;
  744. *to = outbufptr;
  745. return unconv_num;
  746. }
  747. static int
  748. wcstocts(
  749. XlcConv conv,
  750. XPointer *from,
  751. int *from_left,
  752. XPointer *to,
  753. int *to_left,
  754. XPointer *args,
  755. int num_args)
  756. {
  757. size_t table_size = sizeof(default_ct_data) / sizeof(default_ct_data[0]);
  758. State state = (State) conv->state;
  759. XLCd lcd = state->lcd;
  760. unsigned long glyph_index;
  761. wchar_t wc;
  762. int i, total_len, seq_len, name_len;
  763. int unconv_num = 0;
  764. Bool first_flag = True, standard_flag;
  765. XlcSide side;
  766. CodeSet codeset;
  767. XlcCharSet charset, old_charset = NULL;
  768. char *ct_sequence;
  769. XPointer p;
  770. wchar_t *inbufptr = (wchar_t *) *from;
  771. XPointer outbufptr = *to;
  772. int from_size = *from_left;
  773. if (*from_left > *to_left)
  774. *from_left = *to_left;
  775. while (*from_left && *to_left) {
  776. wc = *inbufptr++;
  777. (*from_left)--;
  778. /* null ? */
  779. if (!wc) {
  780. if (outbufptr) {*outbufptr++ = '\0';}
  781. (*to_left)--;
  782. continue;
  783. }
  784. /* convert */
  785. if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
  786. unconv_num++;
  787. continue;
  788. }
  789. /* parse charset */
  790. if ( !(charset = gi_parse_charset(glyph_index, codeset)) ) {
  791. unconv_num++;
  792. continue;
  793. }
  794. /* Standard Character Set Encoding ? */
  795. standard_flag = False;
  796. for (i = 0; i < table_size; i++)
  797. if (compare(charset->ct_sequence,
  798. default_ct_data[i].encoding, strlen(charset->ct_sequence)))
  799. standard_flag = True;
  800. /*
  801. * Non-Standard Character Set Encoding
  802. *
  803. * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+
  804. * | esc sequence | M | L | encoding name | STX |
  805. * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+
  806. * 4bytes 1byte 1byte variable length 1byte
  807. * | |
  808. * +-----------------------------------------+
  809. * name length = ((M - 128) * 128) + (L - 128)
  810. */
  811. /* make encoding data */
  812. ct_sequence = charset->ct_sequence;
  813. side = charset->side;
  814. seq_len = strlen(charset->ct_sequence);
  815. if (standard_flag) {
  816. name_len = 0;
  817. total_len = seq_len;
  818. } else {
  819. name_len = 2 + strlen(charset->encoding_name) + 1;
  820. total_len = seq_len + name_len;
  821. }
  822. /* output escape sequence of CT */
  823. if ( (charset != old_charset) &&
  824. !(first_flag && (strcmp(charset->encoding_name,"ISO8859-1")==0))) {
  825. if (*to_left < total_len + 1) {
  826. unconv_num++;
  827. break;
  828. }
  829. if (outbufptr) {
  830. strcpy((char *)outbufptr, charset->ct_sequence);
  831. outbufptr += seq_len;
  832. if (!standard_flag) {
  833. *outbufptr++ = name_len / 128 + 128;
  834. *outbufptr++ = name_len % 128 + 128;
  835. strcpy((char *)outbufptr, charset->encoding_name);
  836. outbufptr = outbufptr + name_len - 2 - 1;
  837. *outbufptr++ = STX;
  838. }
  839. }
  840. (*to_left) -= total_len;
  841. first_flag = False;
  842. old_charset = charset;
  843. }
  844. /* output glyph index */
  845. if (codeset->ctconv)
  846. glyph_index = conv_to_dest(codeset->ctconv, glyph_index);
  847. if (*to_left < charset->char_size) {
  848. unconv_num++;
  849. break;
  850. }
  851. p = ((XPointer)&glyph_index) + sizeof(glyph_index) - charset->char_size;
  852. for (i = 0; i < charset->char_size; i++) {
  853. if (side == XlcC0 || side == XlcGL) {
  854. if (outbufptr) {*outbufptr++ = *p++ & GL;}
  855. } else if (side == XlcC1 || side == XlcGR) {
  856. if (outbufptr) {*outbufptr++ = *p++ | GR;}
  857. } else {
  858. if (outbufptr) {*outbufptr++ = *p++;}
  859. }
  860. }
  861. (*to_left) -= charset->char_size;
  862. } /* end of while */
  863. *from = *from + from_size;
  864. *from_left = 0;
  865. *to = outbufptr;
  866. return unconv_num;
  867. }
  868. static int
  869. ctstowcs(
  870. XlcConv conv,
  871. XPointer *from,
  872. int *from_left,
  873. XPointer *to,
  874. int *to_left,
  875. XPointer *args,
  876. int num_args)
  877. {
  878. State state = (State) conv->state;
  879. XLCd lcd = state->lcd;
  880. unsigned char ch;
  881. unsigned long glyph_index = 0;
  882. wchar_t wc;
  883. int ctr_seq_len = 0, gi_len_left = 0, gi_len = 0;
  884. int unconv_num = 0;
  885. CodeSet codeset = NULL;
  886. XlcCharSet charset_tmp;
  887. XPointer inbufptr = *from;
  888. wchar_t *outbufptr = (wchar_t *) *to;
  889. int from_size = *from_left;
  890. init_state(conv);
  891. if (from == NULL || *from == NULL) {
  892. init_state(conv);
  893. return( 0 );
  894. }
  895. if (*from_left > *to_left)
  896. *from_left = *to_left;
  897. while (*from_left && *to_left) {
  898. ch = *inbufptr++;
  899. (*from_left)--;
  900. /* null ? */
  901. if (!ch) {
  902. if (outbufptr) {*outbufptr++ = L'\0';}
  903. (*to_left)--;
  904. /* error check */
  905. if (gi_len_left) {
  906. unconv_num += (gi_len - gi_len_left);
  907. gi_len_left = 0;
  908. }
  909. continue;
  910. }
  911. /* same glyph_index data */
  912. if (gi_len_left){
  913. if (state->charset->side == XlcC1 || state->charset->side == XlcGR)
  914. glyph_index = (glyph_index << 8) | (ch & GL);
  915. else
  916. glyph_index = (glyph_index << 8) | ch;
  917. gi_len_left--;
  918. /* last of one glyph_index data */
  919. if (!gi_len_left) {
  920. /* segment conversion */
  921. charset_tmp = state->charset;
  922. if ( !segment_conversion(lcd, &charset_tmp, &glyph_index) ) {
  923. unconv_num += gi_len;
  924. continue;
  925. }
  926. /* get codeset */
  927. if ( !_XlcGetCodeSetFromCharSet(lcd, charset_tmp,
  928. &codeset, &glyph_index) ) {
  929. unconv_num += gi_len;
  930. continue;
  931. }
  932. /* convert glyph index to wicd char */
  933. gi_to_wc(lcd, glyph_index, codeset, &wc);
  934. if (outbufptr) {*outbufptr++ = wc;}
  935. (*to_left)--;
  936. }
  937. continue;
  938. }
  939. /* control sequence ? */
  940. if (ch == CSI) {
  941. if ( !ct_parse_csi(inbufptr - 1, &ctr_seq_len) )
  942. goto skip_the_seg;
  943. if (*from_left < ctr_seq_len) {
  944. inbufptr--;
  945. (*from_left)++;
  946. unconv_num += *from_left;
  947. break;
  948. }
  949. /* skip the control sequence */
  950. inbufptr += (ctr_seq_len - 1);
  951. *from_left -= (ctr_seq_len - 1);
  952. continue;
  953. }
  954. /* escape sequence ? */
  955. if (ch == ESC) {
  956. if ( !ct_parse_charset(lcd,
  957. inbufptr - 1, &state->charset, &ctr_seq_len) )
  958. goto skip_the_seg;
  959. if (*from_left < ctr_seq_len) {
  960. inbufptr--;
  961. (*from_left)++;
  962. unconv_num += *from_left;
  963. break;
  964. }
  965. /* skip the escape sequence */
  966. inbufptr += (ctr_seq_len - 1);
  967. *from_left -= (ctr_seq_len - 1);
  968. continue;
  969. }
  970. /* check current state */
  971. if (state->charset) {
  972. if (state->charset->side == XlcC0 ||
  973. state->charset->side == XlcGL) {
  974. state->GL_charset = state->charset;
  975. } else if (state->charset->side == XlcC1 ||
  976. state->charset->side == XlcGR) {
  977. state->GR_charset = state->charset;
  978. }
  979. } else {
  980. if (isleftside(ch))
  981. state->charset = state->GL_charset;
  982. else
  983. state->charset = state->GR_charset;
  984. }
  985. gi_len = gi_len_left = state->charset->char_size;
  986. glyph_index = 0;
  987. skip_the_seg:
  988. /* skip until next escape or control sequence */
  989. while ( *from_left ) {
  990. ch = *inbufptr++;
  991. (*from_left)--;
  992. unconv_num++;
  993. if (ch == ESC || ch == CSI) {
  994. inbufptr--;
  995. (*from_left)++;
  996. unconv_num--;
  997. break;
  998. }
  999. }
  1000. if ( !(*from_left) )
  1001. break;
  1002. } /* end of while */
  1003. /* error check on last char */
  1004. if (gi_len_left) {
  1005. inbufptr -= (gi_len - gi_len_left);
  1006. (*from_left) += (gi_len - gi_len_left);
  1007. unconv_num += (gi_len - gi_len_left);
  1008. }
  1009. *from = *from + from_size;
  1010. *from_left = 0;
  1011. *to = (XPointer)outbufptr;
  1012. return unconv_num;
  1013. }
  1014. static int
  1015. mbstocts(
  1016. XlcConv conv,
  1017. XPointer *from,
  1018. int *from_left,
  1019. XPointer *to,
  1020. int *to_left,
  1021. XPointer *args,
  1022. int num_args)
  1023. {
  1024. XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t));
  1025. XPointer buf_ptr1 = buf;
  1026. int buf_left1 = (*from_left);
  1027. XPointer buf_ptr2 = buf_ptr1;
  1028. int buf_left2;
  1029. int unconv_num;
  1030. unconv_num = mbstowcs_org(conv,
  1031. from, from_left, &buf_ptr1, &buf_left1, args, num_args);
  1032. if (unconv_num < 0){
  1033. if (buf)
  1034. Xfree((char *)buf);
  1035. return unconv_num;
  1036. }
  1037. buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t);
  1038. unconv_num += wcstocts(conv,
  1039. &buf_ptr2, &buf_left2, to, to_left, args, num_args);
  1040. if (unconv_num < 0){
  1041. if (buf)
  1042. Xfree((char *)buf);
  1043. return unconv_num;
  1044. }
  1045. }
  1046. static int
  1047. mbstostr(
  1048. XlcConv conv,
  1049. XPointer *from,
  1050. int *from_left,
  1051. XPointer *to,
  1052. int *to_left,
  1053. XPointer *args,
  1054. int num_args)
  1055. {
  1056. State state = (State) conv->state;
  1057. XLCd lcd = state->lcd;
  1058. unsigned char ch;
  1059. unsigned long mb = 0;
  1060. int length = 0, len_left = 0;
  1061. int unconv_num = 0;
  1062. int num;
  1063. Bool ss_flag = 0;
  1064. CodeSet codeset = NULL;
  1065. ParseInfo parse_info;
  1066. XPointer inbufptr = *from;
  1067. XPointer outbufptr = *to;
  1068. int from_size = *from_left;
  1069. unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
  1070. ParseInfo *mb_parse_list = XLC_GENERIC(lcd, mb_parse_list);
  1071. if (*from_left > *to_left)
  1072. *from_left = *to_left;
  1073. while (*from_left && *to_left) {
  1074. ch = *inbufptr++;
  1075. (*from_left)--;
  1076. /* null ? */
  1077. if (!ch) {
  1078. if (outbufptr) {*outbufptr++ = '\0';}
  1079. (*to_left)--;
  1080. /* error check */
  1081. if (len_left) {
  1082. unconv_num += (length - len_left);
  1083. len_left = 0;
  1084. }
  1085. continue;
  1086. }
  1087. /* same mb char data */
  1088. if (len_left){
  1089. mb = (mb << 8) | ch; /* 1 byte left shift */
  1090. len_left--;
  1091. /* last of one mb char data */
  1092. if (!len_left) {
  1093. if (check_string_encoding(codeset)) {
  1094. if (outbufptr) {*outbufptr++ = mb & 0xff;}
  1095. (*to_left)--;
  1096. } else {
  1097. unconv_num++;
  1098. }
  1099. }
  1100. }
  1101. /* next mb char data for single shift ? */
  1102. if (mb_parse_table) {
  1103. if ((num = mb_parse_table[ch]) > 0) {
  1104. parse_info = mb_parse_list[num - 1];
  1105. codeset = parse_info->codeset;
  1106. length = len_left = codeset->length;
  1107. mb = 0;
  1108. ss_flag = 1;
  1109. continue;
  1110. }
  1111. }
  1112. /* next char data : byteM ? */
  1113. if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1))) ||
  1114. /* next char data : GL or GR side ? */
  1115. (codeset = GLGR_parse_codeset(lcd, ch))){
  1116. length = len_left = codeset->length;
  1117. mb = 0;
  1118. ss_flag = 0;
  1119. }
  1120. /* can't find codeset for the ch */
  1121. unconv_num++;
  1122. continue;
  1123. } /* end of while */
  1124. /* error check on last char */
  1125. if (len_left) {
  1126. inbufptr -= (length - len_left + ss_flag);
  1127. (*from_left) += (length - len_left + ss_flag);
  1128. unconv_num += (length - len_left + ss_flag);
  1129. }
  1130. *from = *from + from_size;
  1131. *from_left = 0;
  1132. *to = (XPointer)outbufptr;
  1133. return unconv_num;
  1134. }
  1135. static int
  1136. mbtocs(
  1137. XlcConv conv,
  1138. XPointer *from,
  1139. int *from_left,
  1140. XPointer *to,
  1141. int *to_left,
  1142. XPointer *args,
  1143. int num_args)
  1144. {
  1145. State state = (State) conv->state;
  1146. XLCd lcd = state->lcd;
  1147. unsigned char ch;
  1148. unsigned long mb = 0;
  1149. unsigned long glyph_index;
  1150. int length = 0, len_left = 0, char_len;
  1151. int unconv_num = 0;
  1152. int i, num;
  1153. XlcSide side;
  1154. CodeSet codeset = NULL;
  1155. XlcCharSet charset = NULL;
  1156. ParseInfo parse_info;
  1157. XPointer p;
  1158. XPointer inbufptr = *from;
  1159. XPointer outbufptr = *to;
  1160. int from_size = *from_left;
  1161. unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
  1162. ParseInfo *mb_parse_list = XLC_GENERIC(lcd, mb_parse_list);
  1163. if (*from_left > *to_left)
  1164. *from_left = *to_left;
  1165. while (*from_left && *to_left) {
  1166. ch = *inbufptr++;
  1167. (*from_left)--;
  1168. /* null ? */
  1169. if (!ch) {
  1170. unconv_num = 1;
  1171. if (len_left)
  1172. unconv_num += (length - len_left);
  1173. break;
  1174. }
  1175. /* same mb char data */
  1176. if (len_left)
  1177. goto output;
  1178. /* next mb char data for single shift ? */
  1179. if (mb_parse_table) {
  1180. if ((num = mb_parse_table[ch]) > 0) {
  1181. parse_info = mb_parse_list[num - 1];
  1182. codeset = parse_info->codeset;
  1183. length = len_left = codeset->length;
  1184. mb = 0;
  1185. continue;
  1186. }
  1187. }
  1188. /* next mb char data for byteM ? */
  1189. if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1))) ||
  1190. /* next mb char data for GL or GR side ? */
  1191. (codeset = GLGR_parse_codeset(lcd, ch))){
  1192. length = len_left = codeset->length;
  1193. mb = 0;
  1194. }
  1195. /* can't find codeset for the ch */
  1196. unconv_num = 1;
  1197. break;
  1198. output:
  1199. mb = (mb << 8) | ch; /* 1 byte left shift */
  1200. len_left--;
  1201. /* last of one mb char data */
  1202. if (!len_left) {
  1203. glyph_index = mb_to_gi(mb, codeset);
  1204. if (!(charset = gi_parse_charset(glyph_index, codeset))) {
  1205. unconv_num = length;
  1206. break;
  1207. }
  1208. char_len = charset->char_size;
  1209. side = charset->side;
  1210. /* output glyph index */
  1211. if (codeset->ctconv)
  1212. glyph_index = conv_to_dest(codeset->ctconv, glyph_index);
  1213. if (*to_left < char_len) {
  1214. unconv_num = length;
  1215. break;
  1216. }
  1217. p = ((XPointer)&glyph_index) + sizeof(glyph_index) - char_len;
  1218. for (i = 0; i < char_len; i++) {
  1219. if (side == XlcC0 || side == XlcGL) {
  1220. if (outbufptr) {*outbufptr++ = *p++ & GL;}
  1221. } else if (side == XlcC1 || side == XlcGR) {
  1222. if (outbufptr) {*outbufptr++ = *p++ | GR;}
  1223. } else {
  1224. if (outbufptr) {*outbufptr++ = *p++;}
  1225. }
  1226. }
  1227. (*to_left) -= char_len;
  1228. break;
  1229. }
  1230. } /* end of while */
  1231. /* error end */
  1232. if (unconv_num) {
  1233. *from = *from + from_size;
  1234. *from_left = 0;
  1235. *to = outbufptr;
  1236. return -1;
  1237. }
  1238. /* nomal end */
  1239. *from = inbufptr;
  1240. *to = outbufptr;
  1241. if (num_args > 0)
  1242. *((XlcCharSet *) args[0]) = charset;
  1243. return 0;
  1244. }
  1245. static int
  1246. mbstocs(
  1247. XlcConv conv,
  1248. XPointer *from,
  1249. int *from_left,
  1250. XPointer *to,
  1251. int *to_left,
  1252. XPointer *args,
  1253. int num_args)
  1254. {
  1255. int ret;
  1256. XlcCharSet charset_old, charset = NULL;
  1257. XPointer tmp_args[1];
  1258. XPointer inbufptr;
  1259. int in_left;
  1260. XPointer outbufptr;
  1261. int out_left;
  1262. tmp_args[0] = (XPointer) &charset;
  1263. ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, 1);
  1264. charset_old = charset;
  1265. inbufptr = *from;
  1266. in_left = *from_left;
  1267. outbufptr = *to;
  1268. out_left = *to_left;
  1269. while ( ret == 0 && *from_left && *to_left && charset_old == charset ) {
  1270. charset_old = charset;
  1271. inbufptr = *from;
  1272. in_left = *from_left;
  1273. outbufptr = *to;
  1274. out_left = *to_left;
  1275. ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, 1);
  1276. }
  1277. *from = inbufptr;
  1278. *from_left = in_left;
  1279. *to = outbufptr;
  1280. *to_left = out_left;
  1281. if (num_args > 0)
  1282. *((XlcCharSet *) args[0]) = charset_old;
  1283. /* error end */
  1284. if (ret != 0)
  1285. return( -1 );
  1286. return(0);
  1287. }
  1288. static int
  1289. wcstostr(
  1290. XlcConv conv,
  1291. XPointer *from,
  1292. int *from_left,
  1293. XPointer *to,
  1294. int *to_left,
  1295. XPointer *args,
  1296. int num_args)
  1297. {
  1298. State state = (State) conv->state;
  1299. XLCd lcd = state->lcd;
  1300. char *encoding;
  1301. unsigned long mb, glyph_index;
  1302. wchar_t wc;
  1303. int length;
  1304. int unconv_num = 0;
  1305. CodeSet codeset;
  1306. wchar_t *inbufptr = (wchar_t *) *from;
  1307. XPointer outbufptr = *to;
  1308. int from_size = *from_left;
  1309. char *default_string = XLC_PUBLIC(lcd, default_string);
  1310. int defstr_len = strlen(default_string);
  1311. if (*from_left > *to_left)
  1312. *from_left = *to_left;
  1313. while (*from_left && *to_left) {
  1314. wc = *inbufptr++;
  1315. (*from_left)--;
  1316. /* null ? */
  1317. if (!wc) {
  1318. if (outbufptr) {*outbufptr++ = '\0';}
  1319. (*to_left)--;
  1320. continue;
  1321. }
  1322. /* convert */
  1323. if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
  1324. /* output default_string of falDefaultString() */
  1325. if (*to_left < defstr_len)
  1326. break;
  1327. if (outbufptr) {strncpy((char *)outbufptr, default_string, defstr_len);}
  1328. if (outbufptr) {outbufptr += defstr_len;}
  1329. (*to_left) -= defstr_len;
  1330. unconv_num++;
  1331. } else {
  1332. mb = gi_to_mb(glyph_index, codeset);
  1333. if (codeset->parse_info) {
  1334. /* output shift sequence */
  1335. encoding = codeset->parse_info->encoding;
  1336. length = strlen(encoding);
  1337. if (*to_left < length)
  1338. break;
  1339. if (check_string_encoding(codeset)) {
  1340. if (outbufptr) {strncpy((char *)outbufptr, encoding, length);}
  1341. if (outbufptr) {outbufptr += length;}
  1342. (*to_left) -= length;
  1343. }
  1344. }
  1345. /* output characters */
  1346. length = codeset->length;
  1347. if (*to_left < length)
  1348. break;
  1349. if (check_string_encoding(codeset)) {
  1350. if (outbufptr) {strncpy((char *)outbufptr,
  1351. ((char *)&mb) + sizeof(mb) - length, length);}
  1352. if (outbufptr) {outbufptr += length;}
  1353. (*to_left) -= length;
  1354. } else {
  1355. unconv_num++;
  1356. }
  1357. }
  1358. } /* end of while */
  1359. *from = *from + from_size;
  1360. *from_left = 0;
  1361. *to = outbufptr;
  1362. return unconv_num;
  1363. }
  1364. static int
  1365. wctocs(
  1366. XlcConv conv,
  1367. XPointer *from,
  1368. int *from_left,
  1369. XPointer *to,
  1370. int *to_left,
  1371. XPointer *args,
  1372. int num_args)
  1373. {
  1374. State state = (State) conv->state;
  1375. XLCd lcd = state->lcd;
  1376. wchar_t wc;
  1377. unsigned long glyph_index;
  1378. int i, char_len;
  1379. int unconv_num = 0;
  1380. XlcSide side;
  1381. CodeSet codeset;
  1382. XlcCharSet charset;
  1383. XPointer p;
  1384. wchar_t *inbufptr = (wchar_t *) *from;
  1385. XPointer outbufptr = *to;
  1386. int from_size = *from_left;
  1387. if (*from_left > *to_left)
  1388. *from_left = *to_left;
  1389. if (*from_left && *to_left) {
  1390. wc = *inbufptr++;
  1391. (*from_left)--;
  1392. /* null ? */
  1393. if (!wc) {
  1394. unconv_num = 1;
  1395. goto end;
  1396. }
  1397. /* convert */
  1398. if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
  1399. unconv_num = 1;
  1400. goto end;
  1401. }
  1402. if ( !(charset = gi_parse_charset(glyph_index, codeset)) ) {
  1403. unconv_num = 1;
  1404. goto end;
  1405. }
  1406. char_len = charset->char_size;
  1407. side = charset->side;
  1408. /* output glyph index */
  1409. if (codeset->ctconv)
  1410. glyph_index = conv_to_dest(codeset->ctconv, glyph_index);
  1411. if (*to_left < char_len) {
  1412. unconv_num++;
  1413. goto end;
  1414. }
  1415. p = ((XPointer)&glyph_index) + sizeof(glyph_index) - char_len;
  1416. for (i = 0; i < char_len; i++) {
  1417. if (side == XlcC0 || side == XlcGL) {
  1418. if (outbufptr) {*outbufptr++ = *p++ & GL;}
  1419. } else if (side == XlcC1 || side == XlcGR) {
  1420. if (outbufptr) {*outbufptr++ = *p++ | GR;}
  1421. } else {
  1422. if (outbufptr) {*outbufptr++ = *p++;}
  1423. }
  1424. }
  1425. (*to_left) -= char_len;
  1426. }
  1427. end:
  1428. /* error end */
  1429. if (unconv_num) {
  1430. *from = *from + from_size;
  1431. *from_left = 0;
  1432. *to = outbufptr;
  1433. return -1;
  1434. }
  1435. /* nomal end */
  1436. *from = (XPointer)inbufptr;
  1437. *to = outbufptr;
  1438. if (num_args > 0)
  1439. *((XlcCharSet *) args[0]) = charset;
  1440. return 0;
  1441. }
  1442. static int
  1443. wcstocs(
  1444. XlcConv conv,
  1445. XPointer *from,
  1446. int *from_left,
  1447. XPointer *to,
  1448. int *to_left,
  1449. XPointer *args,
  1450. int num_args)
  1451. {
  1452. int ret;
  1453. XlcCharSet charset_old, charset = NULL;
  1454. XPointer tmp_args[1];
  1455. wchar_t *inbufptr;
  1456. int in_left;
  1457. XPointer outbufptr;
  1458. int out_left;
  1459. tmp_args[0] = (XPointer) &charset;
  1460. ret = wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
  1461. charset_old = charset;
  1462. inbufptr = (wchar_t *)(*from);
  1463. in_left = *from_left;
  1464. outbufptr = *to;
  1465. out_left = *to_left;
  1466. while ( ret == 0 && *from_left && *to_left && charset_old == charset ) {
  1467. charset_old = charset;
  1468. inbufptr = (wchar_t *)(*from);
  1469. in_left = *from_left;
  1470. outbufptr = *to;
  1471. out_left = *to_left;
  1472. ret = wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
  1473. }
  1474. *from = (XPointer)inbufptr;
  1475. *from_left = in_left;
  1476. *to = outbufptr;
  1477. *to_left = out_left;
  1478. if (num_args > 0)
  1479. *((XlcCharSet *) args[0]) = charset_old;
  1480. /* error end */
  1481. if (ret != 0)
  1482. return( -1 );
  1483. return(0);
  1484. }
  1485. static int
  1486. ctstombs(
  1487. XlcConv conv,
  1488. XPointer *from,
  1489. int *from_left,
  1490. XPointer *to,
  1491. int *to_left,
  1492. XPointer *args,
  1493. int num_args)
  1494. {
  1495. XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t));
  1496. XPointer buf_ptr1 = buf;
  1497. int buf_left1 = (*from_left);
  1498. XPointer buf_ptr2 = buf_ptr1;
  1499. int buf_left2;
  1500. int unconv_num;
  1501. unconv_num = ctstowcs(conv,
  1502. from, from_left, &buf_ptr1, &buf_left1, args, num_args);
  1503. if (unconv_num < 0){
  1504. if (buf)
  1505. Xfree((char *)buf);
  1506. return unconv_num;
  1507. }
  1508. buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t);
  1509. unconv_num += wcstombs_org(conv,
  1510. &buf_ptr2, &buf_left2, to, to_left, args, num_args);
  1511. if (unconv_num < 0){
  1512. if (buf)
  1513. Xfree((char *)buf);
  1514. return unconv_num;
  1515. }
  1516. }
  1517. static int
  1518. strtombs(
  1519. XlcConv conv,
  1520. XPointer *from,
  1521. int *from_left,
  1522. XPointer *to,
  1523. int *to_left,
  1524. XPointer *args,
  1525. int num_args)
  1526. {
  1527. State state = (State) conv->state;
  1528. XLCd lcd = state->lcd;
  1529. char *encoding;
  1530. unsigned long mb, glyph_index;
  1531. unsigned char ch;
  1532. int length;
  1533. int unconv_num = 0;
  1534. CodeSet codeset;
  1535. XPointer inbufptr = *from;
  1536. XPointer outbufptr = *to;
  1537. int from_size = *from_left;
  1538. if (*from_left > *to_left)
  1539. *from_left = *to_left;
  1540. while (*from_left && *to_left) {
  1541. ch = *inbufptr++;
  1542. (*from_left)--;
  1543. /* null ? */
  1544. if (!ch) {
  1545. if (outbufptr) {*outbufptr++ = '\0';}
  1546. (*to_left)--;
  1547. continue;
  1548. }
  1549. /* convert */
  1550. if (isleftside(ch)) {
  1551. glyph_index = ch;
  1552. codeset = _fallcGetCodeSetFromName(lcd, "ISO8859-1:GL");
  1553. } else {
  1554. glyph_index = ch & GL;
  1555. codeset = _fallcGetCodeSetFromName(lcd, "ISO8859-1:GR");
  1556. }
  1557. if (!codeset) {
  1558. unconv_num++;
  1559. continue;
  1560. }
  1561. mb = gi_to_mb(glyph_index, codeset);
  1562. if (codeset->parse_info) {
  1563. /* output shift sequence */
  1564. encoding = codeset->parse_info->encoding;
  1565. length = strlen(encoding);
  1566. if (*to_left < length)
  1567. break;
  1568. if (outbufptr) {strncpy((char *)outbufptr, encoding, length);}
  1569. if (outbufptr) {outbufptr += length;}
  1570. (*to_left) -= length;
  1571. }
  1572. /* output characters */
  1573. length = codeset->length;
  1574. if (*to_left < length)
  1575. break;
  1576. if (outbufptr) {strncpy((char *)outbufptr, ((char *)&mb)+sizeof(mb)-length, length);}
  1577. if (outbufptr) {outbufptr += length;}
  1578. (*to_left) -= length;
  1579. } /* end of while */
  1580. *from = *from + from_size;
  1581. *from_left = 0;
  1582. *to = outbufptr;
  1583. return unconv_num;
  1584. }
  1585. static int
  1586. strtowcs(
  1587. XlcConv conv,
  1588. XPointer *from,
  1589. int *from_left,
  1590. XPointer *to,
  1591. int *to_left,
  1592. XPointer *args,
  1593. int num_args)
  1594. {
  1595. State state = (State) conv->state;
  1596. XLCd lcd = state->lcd;
  1597. unsigned char ch;
  1598. unsigned long glyph_index;
  1599. wchar_t wc;
  1600. int unconv_num = 0;
  1601. CodeSet codeset;
  1602. XPointer inbufptr = *from;
  1603. wchar_t *outbufptr = (wchar_t *)*to;
  1604. int from_size = *from_left;
  1605. if (*from_left > *to_left)
  1606. *from_left = *to_left;
  1607. while (*from_left && *to_left) {
  1608. ch = *inbufptr++;
  1609. (*from_left)--;
  1610. /* null ? */
  1611. if (!ch) {
  1612. if (outbufptr) {*outbufptr++ = L'\0';}
  1613. (*to_left)--;
  1614. continue;
  1615. }
  1616. /* convert */
  1617. if (isleftside(ch)) {
  1618. glyph_index = ch;
  1619. codeset = _fallcGetCodeSetFromName(lcd, "ISO8859-1:GL");
  1620. } else {
  1621. glyph_index = ch & GL;
  1622. codeset = _fallcGetCodeSetFromName(lcd, "ISO8859-1:GR");
  1623. }
  1624. if (!codeset) {
  1625. unconv_num++;
  1626. continue;
  1627. }
  1628. gi_to_wc(lcd, glyph_index, codeset, &wc);
  1629. if (outbufptr) {*outbufptr++ = wc;}
  1630. (*to_left)--;
  1631. } /* end of while */
  1632. *from = *from + from_size;
  1633. *from_left = 0;
  1634. *to = (XPointer)outbufptr;
  1635. return unconv_num;
  1636. }
  1637. /* -------------------------------------------------------------------------- */
  1638. /* Close */
  1639. /* -------------------------------------------------------------------------- */
  1640. static void
  1641. close_converter(XlcConv conv)
  1642. {
  1643. if (conv->state) {
  1644. Xfree((char *) conv->state);
  1645. }
  1646. if (conv->methods) {
  1647. Xfree((char *) conv->methods);
  1648. }
  1649. Xfree((char *) conv);
  1650. }
  1651. /* -------------------------------------------------------------------------- */
  1652. /* Open */
  1653. /* -------------------------------------------------------------------------- */
  1654. static XlcConv
  1655. create_conv(XLCd lcd, XlcConvMethods methods)
  1656. {
  1657. XlcConv conv;
  1658. State state;
  1659. conv = (XlcConv) Xmalloc(sizeof(XlcConvRec));
  1660. if (conv == NULL)
  1661. return (XlcConv) NULL;
  1662. conv->methods = (XlcConvMethods) Xmalloc(sizeof(XlcConvMethodsRec));
  1663. if (conv->methods == NULL){
  1664. close_converter(conv);
  1665. return (XlcConv) NULL;
  1666. }
  1667. *conv->methods = *methods;
  1668. if (XLC_PUBLIC(lcd, is_state_depend))
  1669. conv->methods->reset = init_state;
  1670. conv->state = (XPointer) Xmalloc(sizeof(StateRec));
  1671. if (conv->state == NULL){
  1672. close_converter(conv);
  1673. return (XlcConv) NULL;
  1674. }
  1675. bzero((char *) conv->state, sizeof(StateRec));
  1676. state = (State) conv->state;
  1677. state->lcd = lcd;
  1678. init_state(conv);
  1679. return conv;
  1680. }
  1681. static XlcConvMethodsRec mbstowcs_methods = {
  1682. close_converter,
  1683. mbstowcs_org,
  1684. NULL
  1685. } ;
  1686. static XlcConv
  1687. open_mbstowcs(XLCd from_lcd, char *from_type, XLCd to_lcd, char *to_type)
  1688. {
  1689. return create_conv(from_lcd, &mbstowcs_methods);
  1690. }
  1691. static XlcConvMethodsRec mbstocts_methods = {
  1692. close_converter,
  1693. mbstocts,
  1694. NULL
  1695. } ;
  1696. static XlcConv
  1697. open_mbstocts(XLCd from_lcd, char *from_type, XLCd to_lcd, char *to_type)
  1698. {
  1699. return create_conv(from_lcd, &mbstocts_methods);
  1700. }
  1701. static XlcConvMethodsRec mbstostr_methods = {
  1702. close_converter,
  1703. mbstostr,
  1704. NULL
  1705. } ;
  1706. static XlcConv
  1707. open_mbstostr(XLCd from_lcd, char *from_type, XLCd to_lcd, char *to_type)
  1708. {
  1709. return create_conv(from_lcd, &mbstostr_methods);
  1710. }
  1711. static XlcConvMethodsRec mbstocs_methods = {
  1712. close_converter,
  1713. mbstocs,
  1714. NULL
  1715. } ;
  1716. static XlcConv
  1717. open_mbstocs(XLCd from_lcd, char *from_type, XLCd to_lcd, char *to_type)
  1718. {
  1719. return create_conv(from_lcd, &mbstocs_methods);
  1720. }
  1721. static XlcConvMethodsRec mbtocs_methods = {
  1722. close_converter,
  1723. mbtocs,
  1724. NULL
  1725. } ;
  1726. static XlcConv
  1727. open_mbtocs(XLCd from_lcd, char *from_type, XLCd to_lcd, char *to_type)
  1728. {
  1729. return create_conv(from_lcd, &mbtocs_methods);
  1730. }
  1731. static XlcConvMethodsRec wcstombs_methods = {
  1732. close_converter,
  1733. wcstombs_org,
  1734. NULL
  1735. } ;
  1736. static XlcConv
  1737. open_wcstombs(XLCd from_lcd, char *from_type, XLCd to_lcd, char *to_type)
  1738. {
  1739. return create_conv(from_lcd, &wcstombs_methods);
  1740. }
  1741. static XlcConvMethodsRec wcstocts_methods = {
  1742. close_converter,
  1743. wcstocts,
  1744. NULL
  1745. } ;
  1746. static XlcConv
  1747. open_wcstocts(XLCd from_lcd, char *from_type, XLCd to_lcd, char *to_type)
  1748. {
  1749. return create_conv(from_lcd, &wcstocts_methods);
  1750. }
  1751. static XlcConvMethodsRec wcstostr_methods = {
  1752. close_converter,
  1753. wcstostr,
  1754. NULL
  1755. } ;
  1756. static XlcConv
  1757. open_wcstostr(XLCd from_lcd, char *from_type, XLCd to_lcd, char *to_type)
  1758. {
  1759. return create_conv(from_lcd, &wcstostr_methods);
  1760. }
  1761. static XlcConvMethodsRec wcstocs_methods = {
  1762. close_converter,
  1763. wcstocs,
  1764. NULL
  1765. } ;
  1766. static XlcConv
  1767. open_wcstocs(XLCd from_lcd, char *from_type, XLCd to_lcd, char *to_type)
  1768. {
  1769. return create_conv(from_lcd, &wcstocs_methods);
  1770. }
  1771. static XlcConvMethodsRec wctocs_methods = {
  1772. close_converter,
  1773. wctocs,
  1774. NULL
  1775. } ;
  1776. static XlcConv
  1777. open_wctocs(XLCd from_lcd, char *from_type, XLCd to_lcd, char *to_type)
  1778. {
  1779. return create_conv(from_lcd, &wctocs_methods);
  1780. }
  1781. static XlcConvMethodsRec ctstombs_methods = {
  1782. close_converter,
  1783. ctstombs,
  1784. NULL
  1785. } ;
  1786. static XlcConv
  1787. open_ctstombs(XLCd from_lcd, char *from_type, XLCd to_lcd, char *to_type)
  1788. {
  1789. return create_conv(from_lcd, &ctstombs_methods);
  1790. }
  1791. static XlcConvMethodsRec ctstowcs_methods = {
  1792. close_converter,
  1793. ctstowcs,
  1794. NULL
  1795. } ;
  1796. static XlcConv
  1797. open_ctstowcs(XLCd from_lcd, char *from_type, XLCd to_lcd, char *to_type)
  1798. {
  1799. return create_conv(from_lcd, &ctstowcs_methods);
  1800. }
  1801. static XlcConvMethodsRec strtombs_methods = {
  1802. close_converter,
  1803. strtombs,
  1804. NULL
  1805. } ;
  1806. static XlcConv
  1807. open_strtombs(XLCd from_lcd, char *from_type, XLCd to_lcd, char *to_type)
  1808. {
  1809. return create_conv(from_lcd, &strtombs_methods);
  1810. }
  1811. static XlcConvMethodsRec strtowcs_methods = {
  1812. close_converter,
  1813. strtowcs,
  1814. NULL
  1815. } ;
  1816. static XlcConv
  1817. open_strtowcs(XLCd from_lcd, char *from_type, XLCd to_lcd, char *to_type)
  1818. {
  1819. return create_conv(from_lcd, &strtowcs_methods);
  1820. }
  1821. /* -------------------------------------------------------------------------- */
  1822. /* Loader */
  1823. /* -------------------------------------------------------------------------- */
  1824. XLCd
  1825. _fallcGenericLoader(char *name)
  1826. {
  1827. XLCd lcd;
  1828. lcd = _fallcCreateLC(name, _fallcGenericMethods);
  1829. if (lcd == NULL)
  1830. return lcd;
  1831. _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar, open_mbstowcs);
  1832. _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCompoundText, open_mbstocts);
  1833. _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNString, open_mbstostr);
  1834. _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs);
  1835. _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbtocs);
  1836. _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_wcstombs);
  1837. _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNCompoundText, open_wcstocts);
  1838. _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNString, open_wcstostr);
  1839. _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs);
  1840. _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNChar, open_wctocs);
  1841. _fallcSetConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte, open_ctstombs);
  1842. _fallcSetConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar, open_ctstowcs);
  1843. _fallcSetConverter(lcd, XlcNString, lcd, XlcNMultiByte, open_strtombs);
  1844. _fallcSetConverter(lcd, XlcNString, lcd, XlcNWideChar, open_strtowcs);
  1845. return lcd;
  1846. }