util/dttypes: remove register keyword
[oweals/cde.git] / cde / programs / dtudcfonted / libfal / _fallcGeneric.c
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 /* lcGeneric.c 1.4 - Fujitsu source for CDEnext    96/02/29 18:02:54    */ 
24 /* $XConsortium: _fallcGeneric.c /main/2 1996/09/27 19:03:31 drk $ */
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  * Copyright 1995 by 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 proprietry source code of FUJITSU LIMITED
54  *
55  * Modifier: Takanori Tateno   FUJITSU LIMITED
56  *
57  */
58
59 #include <stdio.h>
60 #include "_fallibint.h"
61 #include "_fallcGeneric.h"
62
63 static XLCd create();
64 static Bool initialize();
65 static void destroy();
66
67 static XLCdPublicMethodsRec genericMethods = {
68     { NULL },                   /* use default methods */
69     {
70         NULL,
71         create,
72         initialize,
73         destroy,
74         NULL
75     }
76 };
77
78 XLCdMethods _fallcGenericMethods = (XLCdMethods) &genericMethods;
79
80 static XLCd
81 create(name, methods)
82     char *name;
83     XLCdMethods methods;
84 {
85     XLCd lcd;
86     XLCdPublicMethods new;
87
88     lcd = (XLCd) Xmalloc(sizeof(XLCdRec));
89     if (lcd == NULL)
90         return (XLCd) NULL;
91     bzero((char *) lcd, sizeof(XLCdRec));
92
93     lcd->core = (XLCdCore) Xmalloc(sizeof(XLCdGenericRec));
94     if (lcd->core == NULL)
95         goto err;
96     bzero((char *) lcd->core, sizeof(XLCdGenericRec));
97
98     new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec));
99     if (new == NULL)
100         goto err;
101     *new = *((XLCdPublicMethods) methods);
102     lcd->methods = (XLCdMethods) new;
103
104     return lcd;
105
106 err:
107     Xfree(lcd);
108     return (XLCd) NULL;
109 }
110
111 static Bool
112 string_to_encoding(str, encoding)
113     char *str;
114     char *encoding;
115 {
116     char *next;
117     long value;
118     int base;
119
120     while (*str) {
121         if (*str == '\\') {
122             switch (*(str + 1)) {
123                 case 'x':
124                 case 'X':
125                     base = 16;
126                     break;
127                 default:
128                     base = 8;
129                     break;
130             }
131             value = strtol(str + 2, &next, base);
132             if (str + 2 != next) {
133                 *((unsigned char *) encoding++) = (unsigned char) value;
134                 str = next;
135                 continue;
136             }
137         }
138         *encoding++ = *str++;
139     }
140
141     *encoding = '\0';
142
143     return True;
144 }
145
146 static Bool
147 string_to_ulong(str, value)
148 char    *str;
149 unsigned long   *value;
150 {
151      char       *tmp1 = str;
152      int         base;
153
154      if(*tmp1++ != '\\'){
155           tmp1--;
156           base = 10;
157      }else{
158           switch(*tmp1++){
159           case 'x':
160                base = 16;
161                break;
162           case 'o':
163                base = 8;
164                break;
165           case 'd':
166                base = 10;
167                break;
168           default:
169                return(False);
170           }
171      }
172     *value = (unsigned) strtol(tmp1, NULL, base);
173      return(True);
174 }
175
176
177 static Bool
178 add_charset(codeset, charset)
179     CodeSet codeset;
180     XlcCharSet charset;
181 {
182     XlcCharSet *new_list;
183     int num;
184
185     if (num = codeset->num_charsets)
186         new_list = (XlcCharSet *) Xrealloc(codeset->charset_list,
187                                         (num + 1) * sizeof(XlcCharSet));
188     else
189         new_list = (XlcCharSet *) Xmalloc(sizeof(XlcCharSet));
190
191     if (new_list == NULL)
192         return False;
193
194     new_list[num] = charset;
195     codeset->charset_list = new_list;
196     codeset->num_charsets = num + 1;
197
198     return True;
199 }
200
201 static CodeSet
202 add_codeset(gen)
203     XLCdGenericPart *gen;
204 {
205     CodeSet new, *new_list;
206     int num;
207
208     new = (CodeSet) Xmalloc(sizeof(CodeSetRec));
209     if (new == NULL)
210         return NULL;
211     bzero((char *) new, sizeof(CodeSetRec));
212
213     if (num = gen->codeset_num)
214         new_list = (CodeSet *) Xrealloc(gen->codeset_list,
215                                         (num + 1) * sizeof(CodeSet));
216     else
217         new_list = (CodeSet *) Xmalloc(sizeof(CodeSet));
218
219     if (new_list == NULL)
220         goto err;
221
222     new_list[num] = new;
223     gen->codeset_list = new_list;
224     gen->codeset_num = num + 1;
225
226     return new;
227
228 err:
229     Xfree(new);
230
231     return NULL;
232 }
233
234 static Bool
235 add_parse_list(gen, type, encoding, codeset)
236     XLCdGenericPart *gen;
237     EncodingType type;
238     char *encoding;
239     CodeSet codeset;
240 {
241     ParseInfo new, *new_list;
242     char *str;
243     unsigned char ch;
244     int num;
245
246     str = (char *) Xmalloc(strlen(encoding) + 1);
247     if (str == NULL)
248         return False;
249     strcpy(str, encoding);
250
251     new = (ParseInfo) Xmalloc(sizeof(ParseInfoRec));
252     if (new == NULL)
253         goto err;
254     bzero((char *) new, sizeof(ParseInfoRec));
255
256     if (gen->mb_parse_table == NULL) {
257         gen->mb_parse_table = (unsigned char *) Xmalloc(256); /* 2^8 */
258         if (gen->mb_parse_table == NULL)
259             goto err;
260         bzero((char *) gen->mb_parse_table, 256);
261     }
262
263     if (num = gen->mb_parse_list_num)
264         new_list = (ParseInfo *) Xrealloc(gen->mb_parse_list,
265                                           (num + 2) * sizeof(ParseInfo));
266     else {
267         new_list = (ParseInfo *) Xmalloc(2 * sizeof(ParseInfo));
268     }
269
270     if (new_list == NULL)
271         goto err;
272
273     new_list[num] = new;
274     new_list[num + 1] = NULL;
275     gen->mb_parse_list = new_list;
276     gen->mb_parse_list_num = num + 1;
277
278     ch = (unsigned char) *str;
279     if (gen->mb_parse_table[ch] == 0)
280         gen->mb_parse_table[ch] = num + 1;
281
282     new->type = type;
283     new->encoding = str;
284     new->codeset = codeset;
285
286     if (codeset->parse_info == NULL)
287         codeset->parse_info = new;
288
289     return True;
290
291 err:
292     Xfree(str);
293     if (new)
294         Xfree(new);
295
296     return False;
297 }
298
299 static void
300 free_charset(lcd)
301     XLCd lcd;
302 {
303     XLCdGenericPart *gen = XLC_GENERIC_PART(lcd);
304     CodeSet *codeset;
305     ParseInfo *parse_info;
306     int num;
307
308     if (gen->mb_parse_table)
309         Xfree(gen->mb_parse_table);
310     if (num = gen->mb_parse_list_num) {
311         for (parse_info = gen->mb_parse_list; num-- > 0; parse_info++) {
312             if ((*parse_info)->encoding)
313                 Xfree((*parse_info)->encoding);
314             Xfree(*parse_info);
315         }
316         Xfree(gen->mb_parse_list);
317     }
318
319     if (num = gen->codeset_num)
320         Xfree(gen->codeset_list);
321 }
322 /* For VW/UDC */
323
324 #define FORWARD  (unsigned long)'+'
325 #define BACKWARD (unsigned long)'-'
326
327 static char *getscope(str,scp)
328 char *str;
329 FontScope scp;
330 {
331     char buff[256],*next;
332     unsigned long start=0,end=0,dest=0,shift=0,direction=0;
333     sscanf(str,"[\\x%lx,\\x%lx]->\\x%lx", &start, &end, &dest);
334     if( dest ){
335         if(dest >= start ){
336             shift = dest - start;
337             direction = FORWARD ;
338         } else {
339             shift = start - dest;
340             direction = BACKWARD;
341         }
342     }
343     scp->start = start      ;
344     scp->end   = end        ;
345     scp->shift = shift      ;
346     scp->shift_direction
347                = direction  ;
348     /* .......... */
349     while(*str){
350         if(*str == ',' && *(str+1) == '['){
351             break;
352         }
353         str++;
354     }
355     next = str+1 ;
356     return(next);
357 }
358 static int count_scopemap(str)
359 char *str;
360 {
361     char *ptr;
362     int num=0;
363     for(ptr=str;*ptr;ptr++){
364         if(*ptr == ']'){
365             num ++;
366         }
367     }
368     return(num);
369 }
370 FontScope falparse_scopemaps(str,size)
371 char *str;
372 int *size;
373 {
374         int num=0,i;
375         FontScope scope,sc_ptr;
376         char *str_sc;
377         num = count_scopemap(str);
378         scope = (FontScope )Xmalloc(num * sizeof(FontScopeRec));
379         if(scope == NULL) {
380                 return (NULL);
381         }
382         for (i=0,str_sc=str,sc_ptr=scope;
383                         i < num; i++,sc_ptr++){
384                 str_sc = getscope(str_sc,sc_ptr);
385         }
386         *size = num;
387         return (scope);
388 }
389
390 void
391 dbg_printValue(str,value,num)
392 char *str;
393 char **value;
394 int num;
395 {
396 /*
397     int i;
398     for(i=0;i<num;i++){
399         fprintf(stderr,"%s value[%d] = %s\n",str,i,value[i]);
400     }
401 */
402 }
403
404 void
405 dmpscope(name,sc,num)
406 FontScope sc;
407 int num;
408 {
409 /*
410     int i;
411     fprintf(stderr,"dmpscope %s\n",name);
412     for(i=0;i<num;i++){
413         fprintf(stderr,"%x %x %x %x \n",
414                 sc[i].start,
415                 sc[i].end,
416                 sc[i].shift,
417                 sc[i].shift_direction);
418     }
419     fprintf(stderr,"dmpscope end\n");
420 */
421 }
422
423 static XlcCharSet srch_charset_define(name,new)
424 char *name;
425 int *new;
426 {
427     XlcCharSet charset = NULL;
428     *new = 0;
429     charset = _fallcGetCharSet(name);
430     if (charset == NULL &&
431         (charset = _fallcCreateDefaultCharSet(name, ""))) {
432         _fallcAddCharSet(charset);
433         *new = 1;
434     }
435     return(charset);
436 }
437
438 static int
439 read_charset_define(lcd,gen)
440 XLCd lcd;
441 XLCdGenericPart *gen;
442 {
443     int i=0;
444     char csd[16],cset_name[256];
445     char name[BUFSIZ];
446     XlcCharSet charsetd;
447     char **value;
448     int num,new,side=0;
449     char *tmp;
450
451     for(i=0;;i++){ /* loop start */
452         charsetd = 0;
453         sprintf(csd, "csd%d", i);
454
455         /* charset_name   */
456         sprintf(name, "%s.%s", csd , "charset_name");
457         _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
458         dbg_printValue(name,value,num);
459         if (num > 0) {
460             snprintf(cset_name, sizeof(cset_name), "%s", value[0]);
461             snprintf(name, sizeof(name), "%s.%s", csd , "side");
462             _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
463             if (num > 0) {
464                 dbg_printValue(name,value,num);
465                 if( !_fallcNCompareISOLatin1(value[0], "none", 4) ){
466                     side =  XlcNONE ;
467                     strcat(cset_name,":none");
468                 } else
469                 if( !_fallcNCompareISOLatin1(value[0], "GL", 2) ){
470                     side =  XlcGL ;
471                     strcat(cset_name,":GL");
472                 } else {
473                     side =  XlcGR ;
474                     strcat(cset_name,":GR");
475                 }
476                 if (charsetd == NULL &&
477                     (charsetd = srch_charset_define(cset_name,&new)) == NULL)
478                     return 0;
479             }
480         } else {
481             if(i == 0){
482                 continue ;
483             } else {
484                 break ;
485             }
486         }
487         if(new){
488             tmp = (char *)Xmalloc(strlen(cset_name)+1);
489             if(tmp == NULL){
490                 return 0;
491             }
492             strcpy(tmp,cset_name);
493             charsetd->name = tmp;
494         }
495         /* side   */
496         charsetd->side =  side ;
497         /* length */
498         snprintf(name, sizeof(name), "%s.%s", csd , "length");
499         _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
500         if (num > 0) {
501             dbg_printValue(name,value,num);
502             charsetd->char_size = atoi(value[0]);
503         }
504         /* gc_number */
505         snprintf(name, sizeof(name), "%s.%s", csd , "gc_number");
506         _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
507         if (num > 0) {
508             dbg_printValue(name,value,num);
509             charsetd->set_size = atoi(value[0]);
510         }
511         /* string_encoding */
512         snprintf(name, sizeof(name), "%s.%s", csd , "string_encoding");
513         _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
514         if (num > 0) {
515             dbg_printValue(name,value,num);
516             if(!strcmp("False",value[0])){
517                 charsetd->string_encoding = False;
518             } else {
519                 charsetd->string_encoding = True;
520             }
521         }
522         /* sequence */
523         snprintf(name, sizeof(name), "%s.%s", csd , "sequence");
524         _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
525         if (num > 0) {
526             dbg_printValue(name,value,num);
527 /*
528             if(charsetd->ct_sequence){
529                 Xfree(charsetd->ct_sequence);
530             }
531 */
532             tmp = (char *)Xmalloc(strlen(value[0])+1);
533             if(tmp == NULL){
534                 return 0;
535             }
536             charsetd->ct_sequence = tmp;
537             string_to_encoding(value[0],tmp);
538         }
539         /* encoding_name */
540         snprintf(name, sizeof(name), "%s.%s", csd , "encoding_name");
541         _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
542         if (num > 0) {
543             dbg_printValue(name,value,num);
544 /*
545             if(charsetd->encoding_name){
546                 Xfree(charsetd->encoding_name);
547             }
548 */
549             tmp = (char *)Xmalloc(strlen(value[0]) + 1);
550             strcpy(tmp,value[0]);
551             charsetd->encoding_name = tmp;
552             charsetd->xrm_encoding_name =
553                 falrmStringToQuark(tmp);
554         }
555     }
556     return 1;
557 }
558
559 SegConv
560 faladd_conversion(gen)
561 XLCdGenericPart *gen;
562 {
563     SegConv new_list;
564     int num;
565
566     if (num = gen->segment_conv_num){
567         new_list = (SegConv) Xrealloc(gen->segment_conv,
568                                         (num + 1) * sizeof(SegConvRec));
569     } else {
570         new_list = (SegConv) Xmalloc(sizeof(SegConvRec));
571     }
572
573     if (new_list == NULL)
574         return False;
575
576     gen->segment_conv = new_list;
577     gen->segment_conv_num = num + 1;
578
579     return (&new_list[num]);
580
581 }
582 static int
583 read_segmentconversion(lcd,gen)
584 XLCd lcd;
585 XLCdGenericPart *gen;
586 {
587     int i=0;
588     char conv[16];
589     char name[BUFSIZ];
590     char **value;
591     int num,new;
592     SegConv conversion;
593     for(i=0 ; ; i++){ /* loop start */
594         conversion = 0;
595         sprintf(conv, "conv%d", i);
596
597         /* length                */
598         sprintf(name, "%s.%s", conv , "length");
599         _fallcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
600         if (num > 0) {
601             char *tmp;
602             if (conversion == NULL &&
603                 (conversion = faladd_conversion(gen)) == NULL) {
604                 return 0;
605             }
606             dbg_printValue(name,value,num);
607         } else {
608             if(i == 0){
609                 continue;
610             } else {
611                 break ;
612             }
613         }
614         conversion->length = atoi(value[0]);
615
616         /* source_encoding       */
617         sprintf(name, "%s.%s", conv , "source_encoding");
618         _fallcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
619         if (num > 0) {
620             char *tmp;
621             dbg_printValue(name,value,num);
622             tmp = (char *)Xmalloc(strlen(value[0])+1);
623             if(tmp == NULL){
624                 return 0;
625             }
626             strcpy(tmp,value[0]);
627             conversion->source_encoding = tmp;
628             conversion->source = srch_charset_define(tmp,&new);
629             if(new){
630                 tmp = (char *)Xmalloc(strlen(conversion->source_encoding)+1);
631                 if(tmp == NULL){
632                     return 0;
633                 }
634                 strcpy(tmp,conversion->source_encoding);
635                 conversion->source->name = tmp;
636             }
637         }
638         /* destination_encoding  */
639         sprintf(name, "%s.%s", conv , "destination_encoding");
640         _fallcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
641         if (num > 0) {
642             char *tmp;
643             dbg_printValue(name,value,num);
644             tmp = (char *)Xmalloc(strlen(value[0])+1);
645             if(tmp == NULL){
646                 return 0;
647             }
648             strcpy(tmp,value[0]);
649             conversion->destination_encoding = tmp;
650             conversion->dest = srch_charset_define(tmp,&new);
651             if(new){
652                 tmp = (char *)Xmalloc(
653                     strlen(conversion->destination_encoding)+1);
654                 if(tmp == NULL){
655                     return 0;
656                 }
657                 strcpy(tmp,conversion->destination_encoding);
658                 conversion->dest->name = tmp;
659             }
660         }
661         /* range                 */
662         sprintf(name, "%s.%s", conv , "range");
663         _fallcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
664         if (num > 0) {
665             char *tmp;
666             dbg_printValue(name,value,num);
667             sscanf(value[0],"\\x%lx,\\x%lx",
668                 &(conversion->range.start),
669                 &(conversion->range.end));
670         }
671         /* conversion            */
672         sprintf(name, "%s.%s", conv , "conversion");
673         _fallcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
674         if (num > 0) {
675             char *tmp;
676             dbg_printValue(name,value,num);
677             conversion->conv =
678                 falparse_scopemaps(value[0],&conversion->conv_num);
679         }
680     }  /* loop end */
681
682     return 1;
683 }
684
685 static ExtdSegment create_ctextseg(value,num)
686 char **value;
687 int num;
688 {
689     ExtdSegment ret;
690     char side_str[128],*ptr;
691     char cset_name[128],*tmp;
692     int i,new;
693     FontScope scope;
694     ret = (ExtdSegment)Xmalloc(sizeof(ExtdSegmentRec));
695     if(ret == NULL){
696         return (0);
697     }
698     if(strchr(value[0],':')){
699         ret->name = (char *)Xmalloc(strlen(value[0])+1);
700         if(ret->name == NULL){
701             XFree(ret);
702             return(NULL);
703         }
704         strcpy(ret->name,value[0]);
705         ptr = strchr(ret->name,':');
706         *ptr = 0;
707         ptr++;
708         if( !_fallcNCompareISOLatin1(ptr, "none", 4) ){
709             ret->side =  XlcNONE ;
710             snprintf(cset_name,sizeof(cset_name),"%s:%s",ret->name,"none");
711         } else
712         if( !_fallcNCompareISOLatin1(ptr, "GL", 2) ){
713             ret->side =  XlcGL ;
714             snprintf(cset_name,sizeof(cset_name),"%s:%s",ret->name,"GL");
715         } else {
716             ret->side =  XlcGR ;
717             snprintf(cset_name,sizeof(cset_name),"%s:%s",ret->name,"GR");
718         }
719     } else {
720         ret->name = (char *)Xmalloc(strlen(value[0])+1);
721         if(ret->name == NULL){
722             XFree(ret);
723             return(NULL);
724         }
725         strcpy(ret->name,value[0]);
726     }
727     ret->area = (FontScope)Xmalloc((num - 1)*sizeof(FontScopeRec));
728     if(ret->area == NULL){
729         XFree(ret->name);
730         XFree(ret);
731         return(NULL);
732     }
733     ret->area_num  = num - 1;
734     scope = ret->area ;
735     for(i=1;i<num;i++){
736         sscanf(value[i],"\\x%lx,\\x%lx", &scope[i-1].start, &scope[i-1].end);
737     }
738     ret->charset = srch_charset_define(cset_name,&new);
739     if(new){
740         tmp = (char *)Xmalloc(strlen(cset_name)+1);
741         if(tmp == NULL){
742             XFree(ret->area);
743             XFree(ret->name);
744             XFree(ret);
745             return NULL;
746         }
747         strcpy(tmp,cset_name);
748         ret->charset->name = tmp;
749     }
750     return(ret);
751 }
752 /* For VW/UDC end */
753
754 static Bool
755 load_generic(lcd)
756     XLCd lcd;
757 {
758     XLCdGenericPart *gen = XLC_GENERIC_PART(lcd);
759     char **value;
760     int num;
761     unsigned long l;
762     int i;
763     int M,ii;
764
765     gen->codeset_num = 0;
766
767     /***** wc_encoding_mask *****/
768     _fallcGetResource(lcd, "XLC_XLOCALE", "wc_encoding_mask", &value, &num);
769     if (num > 0) {
770         if (string_to_ulong(value[0], &l) == False) 
771             goto err;
772         gen->wc_encode_mask = l;
773     }
774     /***** wc_shift_bits *****/
775     _fallcGetResource(lcd, "XLC_XLOCALE", "wc_shift_bits", &value, &num);
776     if (num > 0)
777         gen->wc_shift_bits = atoi(value[0]);
778     if (gen->wc_shift_bits < 1)
779         gen->wc_shift_bits = 8;
780 #ifndef X_NOT_STDC_ENV
781     /***** use_stdc_env *****/
782     _fallcGetResource(lcd, "XLC_XLOCALE", "use_stdc_env", &value, &num);
783     if (num > 0 && !_fallcCompareISOLatin1(value[0], "True"))
784         gen->use_stdc_env = True;
785     else
786         gen->use_stdc_env = False;
787     /***** force_convert_to_mb *****/
788     _fallcGetResource(lcd, "XLC_XLOCALE", "force_convert_to_mb", &value, &num);
789     if (num > 0 && !_fallcCompareISOLatin1(value[0], "True"))
790         gen->force_convert_to_mb = True;
791     else
792         gen->force_convert_to_mb = False;
793 #endif
794     
795     for (i = 0; ; i++) {
796         CodeSetRec *codeset = NULL;
797         char cs[16];
798         char name[BUFSIZ];
799
800         sprintf(cs, "cs%d", i);
801
802         /***** codeset.side *****/
803         sprintf(name, "%s.%s", cs , "side");
804         _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
805         if (num > 0) {
806             char *tmp;
807
808             if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
809                 goto err;
810
811             /* 3.4.1 side */
812             if( !_fallcNCompareISOLatin1(value[0], "none", 4) ){
813                 codeset->side =  XlcNONE ;
814             } else
815             if( !_fallcNCompareISOLatin1(value[0], "GL", 2) ){
816                 codeset->side =  XlcGL ;
817             } else {
818                 codeset->side =  XlcGR ;
819             }
820
821             tmp = strrchr(value[0], ':');
822             if (tmp != NULL && !_fallcCompareISOLatin1(tmp + 1, "Default")) {
823                 if (codeset->side == XlcGR)
824                     gen->initial_state_GR = codeset;
825                 else
826                     gen->initial_state_GL = codeset;
827             }
828         }
829
830         /***** codeset.length *****/
831         sprintf(name, "%s.%s", cs , "length");
832         _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
833         if (num > 0) {
834             if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
835                 goto err;
836             codeset->length = atoi(value[0]);
837             if (codeset->length < 1)
838                 codeset->length = 1;
839         }
840
841         /***** codeset.mb_encoding *****/
842         sprintf(name, "%s.%s", cs, "mb_encoding");
843         _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
844         if (num > 0) {
845             static struct { 
846                 char *str;
847                 int type;
848             } shifts[] = {
849                 {"<SS>", E_SS},
850                 {"<LSL>", E_LSL},
851                 {"<LSR>", E_LSR},
852                 0
853             };
854             int j;
855
856             if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
857                 goto err;
858             for ( ; num-- > 0; value++) {
859                 char encoding[256];
860                 char *tmp = *value;
861                 int type = E_SS;    /* for BC */
862                 for (j = 0; shifts[j].str; j++) {
863                     if (!_fallcNCompareISOLatin1(tmp, shifts[j].str,
864                                                strlen(shifts[j].str))) {
865                         type = shifts[j].type;
866                         tmp += strlen(shifts[j].str);
867                         break;
868                     }
869                 }
870                 if (string_to_encoding(tmp, encoding) == False)
871                         goto err;
872                 add_parse_list(gen, type, encoding, codeset);
873             }
874         }
875
876         /***** codeset.wc_encoding *****/
877         sprintf(name, "%s.%s", cs, "wc_encoding");
878         _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
879         if (num > 0) {
880             if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
881                 goto err;
882             if (string_to_ulong(value[0], &l) == False) 
883                 goto err;
884             codeset->wc_encoding = l;
885         }
886   
887         /***** codeset.ct_encoding *****/
888         sprintf(name, "%s.%s", cs, "ct_encoding");
889         _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
890         if (num > 0) {
891             XlcCharSet charset;
892             char *encoding;
893
894             if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
895                 goto err;
896             for ( ; num-- > 0; value++) {
897                 string_to_encoding(*value, name);
898                 charset = NULL;
899                 if ((encoding = strchr(name, ':')) &&
900                     (encoding = strchr(encoding + 1, ':'))) {
901                     *encoding++ = '\0';
902                     charset = _fallcAddCT(name, encoding);
903                 }
904                 if (charset == NULL) {
905                     charset = _fallcGetCharSet(name);
906                     if (charset == NULL &&
907                         (charset = _fallcCreateDefaultCharSet(name, ""))) {
908                         charset->side = codeset->side;
909                         charset->char_size = codeset->length;
910                         _fallcAddCharSet(charset);
911                     }
912                 }
913                 if (charset) {
914                     if (add_charset(codeset, charset) == False)
915                         goto err;
916                 }
917             }
918         }
919
920         if (codeset == NULL)
921             break;
922         codeset->cs_num = i;
923         /* For VW/UDC */
924         /***** 3.4.2 byteM (1 <= M <= length)*****/
925         for(M=1; M-1  < codeset->length; M++){
926             long start,end;
927             ByteInfo tmpb;
928
929             sprintf(name,"%s.%s%d",cs,"byte",M);
930             _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
931
932             if( M == 1){
933                 if(num < 1) {
934                     codeset->byteM = NULL ;
935                     break ;
936                 }
937                 codeset->byteM =
938                     (ByteInfoListRec *)Xmalloc(
939                          (codeset->length)*sizeof(ByteInfoListRec));
940                 if(codeset->byteM == NULL){
941                     goto err;
942                 }
943             }
944
945             if(num > 0){
946                 dbg_printValue(name,value,num);
947                 (codeset->byteM)[M-1].M = M;
948                 (codeset->byteM)[M-1].byteinfo_num = num;
949                 (codeset->byteM)[M-1].byteinfo =
950                     (ByteInfo)Xmalloc( num * sizeof(ByteInfoRec));
951                 for(ii = 0 ; ii < num ; ii++){
952                     char tmp[128];
953                     tmpb = (codeset->byteM)[M-1].byteinfo ;
954                     /* default 0x00 - 0xff */
955                     sscanf(value[ii], "\\x%lx,\\x%lx", (long unsigned *) &start, (long unsigned *) &end);
956                     tmpb[ii].start = (unsigned char)start;
957                     tmpb[ii].end  = (unsigned char)end;
958                 }
959             }
960             /* .... */
961         }
962
963
964         /***** codeset.mb_conversion *****/
965         sprintf(name, "%s.%s", cs, "mb_conversion");
966         _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
967         if (num > 0) {
968                 dbg_printValue(name,value,num);
969                 codeset->mbconv = Xmalloc(sizeof(ConversionRec));
970                 codeset->mbconv->convlist =
971                 falparse_scopemaps(value[0],&(codeset->mbconv->conv_num));
972                 dmpscope("mb_conv",codeset->mbconv->convlist,
973                         codeset->mbconv->conv_num);
974                 /* [\x%x,\x%x]->\x%x,... */
975         }
976         /***** codeset.ct_conversion *****/
977         sprintf(name, "%s.%s", cs, "ct_conversion");
978         _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
979         if (num > 0) {
980                 dbg_printValue(name,value,num);
981                 codeset->ctconv = Xmalloc(sizeof(ConversionRec));
982                 codeset->ctconv->convlist =
983                 falparse_scopemaps(value[0],&(codeset->ctconv->conv_num));
984                 dmpscope("ctconv",codeset->ctconv->convlist,
985                         codeset->ctconv->conv_num);
986                 /* [\x%x,\x%x]->\x%x,... */
987         }
988         /***** codeset.ct_conversion_file *****/
989         sprintf(name, "%s.%s", cs, "ct_conversion_file");
990         _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
991         if (num > 0) {
992                 dbg_printValue(name,value,num);
993                 /* [\x%x,\x%x]->\x%x,... */
994         }
995         /***** codeset.ct_extended_segment *****/
996         sprintf(name, "%s.%s", cs, "ct_extended_segment");
997         _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
998         if (num > 0) {
999                 dbg_printValue(name,value,num);
1000                 codeset->ctextseg = create_ctextseg(value,num);
1001                 /* [\x%x,\x%x]->\x%x,... */
1002         }
1003         /* For VW/UDC end */
1004
1005     }
1006          
1007     read_charset_define(lcd,gen);       /* For VW/UDC */
1008     read_segmentconversion(lcd,gen);    /* For VW/UDC */
1009
1010     return True;
1011
1012 err:
1013     free_charset(lcd);
1014
1015     return False;
1016 }
1017
1018 static Bool
1019 initialize(lcd)
1020     XLCd lcd;
1021 {
1022     XLCdPublicMethods superclass = (XLCdPublicMethods) _fallcPublicMethods;
1023
1024     XLC_PUBLIC_METHODS(lcd)->superclass = superclass;
1025
1026     if (superclass->pub.initialize) {
1027         if ((*superclass->pub.initialize)(lcd) == False)
1028             return False;
1029     }
1030
1031     if(load_generic(lcd) == False)
1032         return False;
1033
1034     return True;
1035 }
1036 /* VW/UDC start 95.01.08 */
1037 static void 
1038 freeByteM(codeset)
1039     CodeSet codeset;
1040 {
1041     int i;
1042     ByteInfoList blst;
1043     if(codeset->byteM == NULL) {
1044         return ;
1045     }
1046     blst = codeset->byteM;
1047     for(i=0;i<codeset->length;i++){
1048         if(blst[i].byteinfo){
1049             Xfree(blst[i].byteinfo);
1050             blst[i].byteinfo = NULL;
1051         }
1052     }
1053     Xfree(codeset->byteM); 
1054     codeset->byteM = NULL;
1055 }
1056 static void 
1057 freeConversion(codeset)
1058     CodeSet codeset;
1059 {
1060     int i;
1061     Conversion mbconv,ctconv;
1062     if( codeset->mbconv ) {
1063         mbconv = codeset->mbconv;
1064         /*  ...  */
1065         if(mbconv->convlist){
1066             Xfree(mbconv->convlist);
1067             mbconv->convlist = NULL;
1068         }
1069         Xfree(mbconv);
1070         codeset->mbconv = NULL;
1071     }
1072     if( codeset->ctconv ) {
1073         ctconv = codeset->ctconv;
1074         /*  ...  */
1075         if(ctconv->convlist){
1076             Xfree(ctconv->convlist);
1077             ctconv->convlist = NULL;
1078         }
1079         Xfree(ctconv);
1080         codeset->ctconv = NULL;
1081     }
1082 }
1083 static void 
1084 freeExtdSegment(codeset)
1085     CodeSet codeset;
1086 {
1087     int i;
1088     ExtdSegment ctextseg;
1089     if(codeset->ctextseg == NULL) {
1090         return ;
1091     }
1092     ctextseg = codeset->ctextseg;
1093     if(ctextseg->name){
1094         Xfree(ctextseg->name);
1095         ctextseg->name = NULL;
1096     }
1097     if(ctextseg->area){
1098         Xfree(ctextseg->area);
1099         ctextseg->area = NULL;
1100     }
1101     Xfree(codeset->ctextseg); 
1102     codeset->ctextseg = NULL;
1103 }
1104 static void 
1105 freeParseInfo(codeset)
1106     CodeSet codeset;
1107 {
1108     int i;
1109     ParseInfo parse_info;
1110     if(codeset->parse_info == NULL) {
1111         return ;
1112     }
1113     parse_info = codeset->parse_info;
1114     if(parse_info->encoding){
1115         Xfree(parse_info->encoding);
1116         parse_info->encoding = NULL;
1117     }
1118     Xfree(codeset->parse_info); 
1119     codeset->parse_info = NULL;
1120 }
1121 static void
1122 destroy_CodeSetList(gen)
1123     XLCdGenericPart *gen ;
1124 {
1125     CodeSet *codeset = gen->codeset_list;
1126     int i;
1127     if(gen->codeset_num == 0) {
1128         return;
1129     }
1130     for(i=0;i<gen->codeset_num;i++){
1131         freeByteM(codeset[i]);
1132         freeConversion(codeset[i]);
1133         freeExtdSegment(codeset[i]);
1134         freeParseInfo(codeset[i]);
1135         if(codeset[i]->charset_list){
1136             Xfree(codeset[i]->charset_list);
1137             codeset[i]->charset_list = NULL;
1138         }
1139         Xfree(codeset[i]); codeset[i]=NULL;
1140     }
1141     Xfree(codeset); gen->codeset_list = NULL;
1142 }
1143 /*  */
1144 static void
1145 destroy_SegConv(gen)
1146     XLCdGenericPart *gen ;
1147 {
1148     SegConv seg = gen->segment_conv;
1149     int i;
1150     if(gen->segment_conv_num == 0) {
1151         return;
1152     }
1153     for(i=0;i<gen->segment_conv_num;i++){
1154         if(seg[i].source_encoding){
1155             Xfree(seg[i].source_encoding);
1156             seg[i].source_encoding = NULL;
1157         }
1158         if(seg[i].destination_encoding){
1159             Xfree(seg[i].destination_encoding); 
1160             seg[i].destination_encoding = NULL;
1161         }
1162         if(seg[i].conv){
1163             Xfree(seg[i].conv); seg[i].conv = NULL;
1164         }
1165     }
1166     Xfree(seg); gen->segment_conv = NULL;
1167 }
1168
1169 static void
1170 destroy_gen(lcd)
1171     XLCd lcd;
1172 {
1173     XLCdGenericPart *gen = XLC_GENERIC_PART(lcd);
1174     destroy_SegConv(gen);
1175     destroy_CodeSetList(gen);
1176     if(gen->mb_parse_table){
1177         Xfree(gen->mb_parse_table);
1178         gen->mb_parse_table = NULL;
1179     }
1180     if(gen->mb_parse_list){
1181         Xfree(gen->mb_parse_list);
1182         gen->mb_parse_list = NULL;
1183     }
1184 }
1185 /* VW/UDC end 95.01.08 */
1186 static void
1187 destroy(lcd)
1188     XLCd lcd;
1189 {
1190     XLCdPublicMethods superclass = XLC_PUBLIC_METHODS(lcd)->superclass;
1191
1192     destroy_gen(lcd); /* ADD 1996.01.08 */
1193     if (superclass && superclass->pub.destroy)
1194         (*superclass->pub.destroy)(lcd);
1195 }