home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / Xlc_Public.c < prev    next >
C/C++ Source or Header  |  1999-11-02  |  8KB  |  306 lines

  1. /* $TOG: lcPublic.c /main/8 1997/06/03 15:52:52 kaleb $ */
  2. /*
  3.  * Copyright 1992, 1993 by TOSHIBA Corp.
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation for any purpose and without fee is hereby granted, provided
  7.  * that the above copyright notice appear in all copies and that both that
  8.  * copyright notice and this permission notice appear in supporting
  9.  * documentation, and that the name of TOSHIBA not be used in advertising
  10.  * or publicity pertaining to distribution of the software without specific,
  11.  * written prior permission. TOSHIBA make no representations about the
  12.  * suitability of this software for any purpose.  It is provided "as is"
  13.  * without express or implied warranty.
  14.  *
  15.  * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17.  * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  *
  23.  * Author: Katsuhisa Yano    TOSHIBA Corp.
  24.  *                   mopi@osa.ilab.toshiba.co.jp
  25.  */
  26.  
  27. #include <stdio.h>
  28. #include "Xlib_private.h"
  29. #include "XlcPubI.h"
  30.  
  31. static char *default_string();
  32.  
  33. static XLCd create();
  34. static Bool initialize();
  35. static void destroy();
  36. static char *get_values();
  37.  
  38. static XLCdPublicMethodsRec publicMethods = {
  39.     {
  40.     destroy,
  41.     _XlcDefaultMapModifiers,
  42.     NULL,
  43.     NULL,
  44.     _XrmDefaultInitParseInfo,
  45.     _XmbTextPropertyToTextList,
  46.     _XwcTextPropertyToTextList,
  47.     _XmbTextListToTextProperty,
  48.     _XwcTextListToTextProperty,
  49.     _XwcFreeStringList,
  50.     default_string,
  51.     NULL,
  52.     NULL
  53.     }, 
  54.     {
  55.     NULL,
  56.     create,
  57.     initialize,
  58.     destroy,
  59.     get_values,
  60.     _XlcGetLocaleDataBase
  61.     }
  62. };
  63.  
  64. XLCdMethods _XlcPublicMethods = (XLCdMethods) &publicMethods;
  65.  
  66. static char *
  67. default_string(lcd)
  68.     XLCd lcd;
  69. {
  70.     return XLC_PUBLIC(lcd, default_string);
  71. }
  72.  
  73. static XLCd
  74. create(name, methods)
  75.     char *name;
  76.     XLCdMethods methods;
  77. {
  78.     DBUG_ENTER("create")
  79.     XLCd lcd;
  80.     XLCdPublicMethods new;
  81.  
  82.     lcd = (XLCd) Xmalloc(sizeof(XLCdRec));
  83.     if (lcd == NULL)
  84.         DBUG_RETURN((XLCd) NULL);
  85.     bzero((char *) lcd, sizeof(XLCdRec));
  86.  
  87.     lcd->core = (XLCdCore) Xmalloc(sizeof(XLCdPublicRec));
  88.     if (lcd->core == NULL)
  89.     goto err;
  90.     bzero((char *) lcd->core, sizeof(XLCdPublicRec));
  91.  
  92.     new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec));
  93.     if (new == NULL)
  94.     goto err;
  95.     *new = *((XLCdPublicMethods) methods);
  96.     lcd->methods = (XLCdMethods) new;
  97.  
  98.     DBUG_RETURN(lcd);
  99.  
  100. err:
  101.     Xfree(lcd);
  102.     DBUG_RETURN((XLCd) NULL);
  103. }
  104.  
  105. static Bool
  106. load_public(lcd)
  107.     XLCd lcd;
  108. {
  109.     DBUG_ENTER("load_public")
  110.     XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
  111.     char **values, *str;
  112.     int num;
  113.  
  114.     if(_XlcCreateLocaleDataBase(lcd) == NULL) {
  115. #if defined(DEBUG) && defined(VERBOSE)
  116.     fprintf(stderr,"load_public: _XlcCreateLocaleDataBase() failed!\n");
  117. #endif
  118.     DBUG_RETURN(False);
  119. }
  120.  
  121.     _XlcGetResource(lcd, "XLC_XLOCALE", "mb_cur_max", &values, &num);
  122.     if (num > 0) {
  123.     pub->mb_cur_max = atoi(values[0]);
  124.     if (pub->mb_cur_max < 1)
  125.         pub->mb_cur_max = 1;
  126.     } else
  127.     pub->mb_cur_max = 1;
  128.  
  129.     _XlcGetResource(lcd, "XLC_XLOCALE", "state_dependent", &values, &num);
  130.     if (num > 0 && !_XlcCompareISOLatin1(values[0], "True"))
  131.     pub->is_state_depend = True;
  132.     else
  133.     pub->is_state_depend = False;
  134.  
  135.     _XlcGetResource(lcd, "XLC_XLOCALE", "encoding_name", &values, &num);
  136.     str = (num > 0) ? values[0] : "STRING";
  137.     pub->encoding_name = (char*) Xmalloc(strlen(str) + 1);
  138.     if (pub->encoding_name == NULL) {
  139. #if defined(DEBUG) && defined(VERBOSE)
  140.     fprintf(stderr, "load_public: malloc failed!\n");
  141. #endif
  142.     DBUG_RETURN(False);
  143.     }
  144.     strcpy(pub->encoding_name, str);
  145.  
  146.     DBUG_RETURN(True);
  147. }
  148.  
  149. static Bool
  150. initialize_core(lcd)
  151.     XLCd lcd;
  152. {
  153.     DBUG_ENTER("initialize_core")
  154.     XLCdMethods methods = lcd->methods;
  155.     XLCdMethods core = &publicMethods.core;
  156.  
  157.     if (methods->close == NULL)
  158.     methods->close = core->close;
  159.  
  160.     if (methods->map_modifiers == NULL)
  161.     methods->map_modifiers = core->map_modifiers;
  162.  
  163.     if (methods->open_om == NULL)
  164.     _XInitOM(lcd);
  165.  
  166.     if (methods->open_im == NULL)
  167.     _XInitIM(lcd);
  168.  
  169.     if (methods->init_parse_info == NULL)
  170.     methods->init_parse_info = core->init_parse_info;
  171.  
  172.     if (methods->mb_text_prop_to_list == NULL)
  173.     methods->mb_text_prop_to_list = core->mb_text_prop_to_list;
  174.  
  175.     if (methods->wc_text_prop_to_list == NULL)
  176.     methods->wc_text_prop_to_list = core->wc_text_prop_to_list;
  177.  
  178.     if (methods->mb_text_list_to_prop == NULL)
  179.     methods->mb_text_list_to_prop = core->mb_text_list_to_prop;
  180.  
  181.     if (methods->wc_text_list_to_prop == NULL)
  182.     methods->wc_text_list_to_prop = core->wc_text_list_to_prop;
  183.  
  184.     if (methods->wc_free_string_list == NULL)
  185.     methods->wc_free_string_list = core->wc_free_string_list;
  186.  
  187.     if (methods->default_string == NULL)
  188.     methods->default_string = core->default_string;
  189.  
  190.     DBUG_RETURN(True);
  191. }
  192.  
  193. extern Bool _XlcInitCTInfo();
  194.  
  195. static Bool
  196. initialize(lcd)
  197.     XLCd lcd;
  198. {
  199.     DBUG_ENTER("initialize")
  200.     XLCdPublicMethodsPart *methods = XLC_PUBLIC_METHODS(lcd);
  201.     XLCdPublicMethodsPart *pub_methods = &publicMethods.pub;
  202.     XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
  203.     char *name;
  204. #if !defined(X_NOT_STDC_ENV) && !defined(X_LOCALE)
  205.     char siname[256];
  206.     char *_XlcMapOSLocaleName();
  207. #endif
  208.  
  209.     _XlcInitCTInfo();
  210.  
  211.     if (initialize_core(lcd) == False)
  212.     DBUG_RETURN(False);
  213.  
  214.     name = lcd->core->name;
  215. #if !defined(X_NOT_STDC_ENV) && !defined(X_LOCALE)
  216.     name = _XlcMapOSLocaleName(name, siname);
  217. #endif
  218.     
  219.     if (_XlcResolveLocaleName(name, pub) == 0)
  220.     DBUG_RETURN(False);
  221.  
  222.     if (pub->default_string == NULL)
  223.     pub->default_string = "";
  224.  
  225.     if (methods->get_values == NULL)
  226.     methods->get_values = pub_methods->get_values;
  227.  
  228.     if (methods->get_resource == NULL)
  229.     methods->get_resource = pub_methods->get_resource;
  230.     {
  231.     Bool result = load_public(lcd);
  232.     DBUG_RETURN(result);
  233.     }
  234. }
  235.  
  236. static void
  237. destroy_core(lcd)
  238.     XLCd    lcd;
  239. {
  240.     DBUG_ENTER("destroy_core")
  241.     if (lcd->core) {
  242.     if (lcd->core->name)
  243.             Xfree(lcd->core->name);
  244.     Xfree(lcd->core);
  245.     }
  246.  
  247.     if (lcd->methods)
  248.     Xfree(lcd->methods);
  249.  
  250.     Xfree(lcd);
  251.     DBUG_VOID_RETURN;
  252. }
  253.  
  254. static void
  255. destroy(lcd)
  256.     XLCd lcd;
  257. {
  258.     DBUG_ENTER("destroy")
  259.     XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
  260.  
  261.     _XlcDestroyLocaleDataBase(lcd);
  262.  
  263.     if (pub->siname)
  264.     Xfree(pub->siname);
  265.     if (pub->encoding_name)
  266.     Xfree(pub->encoding_name);
  267.  
  268.     destroy_core(lcd);
  269.     DBUG_VOID_RETURN;
  270. }
  271.  
  272. static XlcResource resources[] = {
  273.     { XlcNCodeset, NULLQUARK, sizeof(char *),
  274.       XOffsetOf(XLCdPublicRec, pub.codeset), XlcGetMask },
  275.     { XlcNDefaultString, NULLQUARK, sizeof(char *),
  276.       XOffsetOf(XLCdPublicRec, pub.default_string), XlcGetMask },
  277.     { XlcNEncodingName, NULLQUARK, sizeof(char *),
  278.       XOffsetOf(XLCdPublicRec, pub.encoding_name), XlcGetMask },
  279.     { XlcNLanguage, NULLQUARK, sizeof(char *),
  280.       XOffsetOf(XLCdPublicRec, pub.language), XlcGetMask },
  281.     { XlcNMbCurMax, NULLQUARK, sizeof(int),
  282.       XOffsetOf(XLCdPublicRec, pub.mb_cur_max), XlcGetMask },
  283.     { XlcNStateDependentEncoding, NULLQUARK, sizeof(Bool),
  284.       XOffsetOf(XLCdPublicRec, pub.is_state_depend), XlcGetMask },
  285.     { XlcNTerritory, NULLQUARK, sizeof(char *),
  286.       XOffsetOf(XLCdPublicRec, pub.territory), XlcGetMask }
  287. };
  288.  
  289. static char *
  290. get_values(lcd, args, num_args)
  291.     register XLCd lcd;
  292.     register XlcArgList args;
  293.     register int num_args;
  294. {
  295.     DBUG_ENTER("get_values")
  296.     XLCdPublic pub = (XLCdPublic) lcd->core;
  297.     char *result;
  298.  
  299.     if (resources[0].xrm_name == NULLQUARK)
  300.     _XlcCompileResourceList(resources, XlcNumber(resources));
  301.  
  302.     result = _XlcGetValues((XPointer) pub, resources, XlcNumber(resources), args,
  303.              num_args, XlcGetMask);
  304.     DBUG_RETURN(result);
  305. }
  306.