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

  1. /* $XConsortium: imLcIm.c /main/10 1996/01/21 15:11:54 kaleb $ */
  2. /******************************************************************
  3.  
  4.           Copyright 1992, 1993, 1994 by FUJITSU LIMITED
  5.           Copyright 1993 by Digital Equipment Corporation
  6.  
  7. Permission to use, copy, modify, distribute, and sell this software
  8. and its documentation for any purpose is hereby granted without fee,
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in
  11. supporting documentation, and that the name of FUJITSU LIMITED and
  12. Digital Equipment Corporation not be used in advertising or publicity
  13. pertaining to distribution of the software without specific, written
  14. prior permission.  FUJITSU LIMITED and Digital Equipment Corporation
  15. makes no representations about the suitability of this software for
  16. any purpose.  It is provided "as is" without express or implied
  17. warranty.
  18.  
  19. FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION DISCLAIM ALL 
  20. WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED 
  21. WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 
  22. FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR 
  23. ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
  24. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 
  25. IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 
  26. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 
  27. THIS SOFTWARE.
  28.  
  29.   Author:    Takashi Fujiwara     FUJITSU LIMITED 
  30.                                      fujiwara@a80.tech.yk.fujitsu.co.jp
  31.   Modifier:  Franky Ling          Digital Equipment Corporation
  32.                               frankyling@hgrd01.enet.dec.com
  33.  
  34. ******************************************************************/
  35.  
  36. #include <stdio.h>
  37. /*
  38. #include <X11/Xlib.h>
  39. */
  40. #include "Xlib_private.h"
  41. #include <X11/Xmd.h>
  42. #include <X11/Xatom.h>
  43. #include <X11/Xos.h>
  44. #include "Xlcint.h"
  45. #include "XlcPublic.h"
  46. #include "Ximint.h"
  47. #include <ctype.h>
  48.  
  49. Public Bool
  50. _XimCheckIfLocalProcessing(im)
  51.     Xim          im;
  52. {
  53.     FILE        *fp;
  54.     char        *name;
  55.  
  56.     if(strcmp(im->core.im_name, "") == 0) {
  57.     name = _XlcFileName(im->core.lcd, COMPOSE_FILE);
  58.     if (name != (char *)NULL) {
  59.         fp = fopen(name, "r");
  60.         Xfree(name);
  61.         if (fp != (FILE *)NULL) {
  62.         fclose(fp);
  63.         return(True);
  64.         }
  65.     }
  66.     return(False);
  67.     } else if(strcmp(im->core.im_name, "local") == 0 ||
  68.           strcmp(im->core.im_name, "none" ) == 0 ) {
  69.     return(True);
  70.     }
  71.     return(False);
  72. }
  73.  
  74. Private void
  75. XimFreeDefaultTree(top)
  76.     DefTree *top;
  77. {
  78.     if (!top) return;
  79.     if (top->succession) XimFreeDefaultTree(top->succession);
  80.     if (top->next) XimFreeDefaultTree(top->next);
  81.     if (top->mb) Xfree(top->mb);
  82.     if (top->wc) Xfree(top->wc);
  83.     Xfree(top);
  84. }
  85.  
  86. Public void
  87. _XimLocalIMFree(im)
  88.     Xim        im;
  89. {
  90.     XimFreeDefaultTree(im->private.local.top);
  91.     if(im->core.im_resources) {
  92.     Xfree(im->core.im_resources);
  93.     im->core.im_resources = NULL;
  94.     }
  95.     if(im->core.ic_resources) {
  96.     Xfree(im->core.ic_resources);
  97.     im->core.ic_resources = NULL;
  98.     }
  99.     if(im->core.im_values_list) {
  100.     Xfree(im->core.im_values_list);
  101.     im->core.im_values_list = NULL;
  102.     }
  103.     if(im->core.ic_values_list) {
  104.     Xfree(im->core.ic_values_list);
  105.     im->core.ic_values_list = NULL;
  106.     }
  107.     if(im->core.styles) {
  108.     Xfree(im->core.styles);
  109.     im->core.styles = NULL;
  110.     }
  111.     if(im->core.res_name) {
  112.     Xfree(im->core.res_name);
  113.     im->core.res_name = NULL;
  114.     }
  115.     if(im->core.res_class) {
  116.     Xfree(im->core.res_class);
  117.     im->core.res_class = NULL;
  118.     }
  119.     if(im->core.im_name) {
  120.     Xfree(im->core.im_name);
  121.     im->core.im_name = NULL;
  122.     }
  123.     return;
  124. }
  125.  
  126. Private Status
  127. _XimLocalCloseIM(xim)
  128.     XIM        xim;
  129. {
  130.     Xim        im = (Xim)xim;
  131.     XIC        ic;
  132.     XIC        next;
  133.  
  134.     ic = im->core.ic_chain;
  135.     while (ic) {
  136.     (*ic->methods->destroy) (ic);
  137.     next = ic->core.next;
  138.     Xfree ((char *) ic);
  139.     ic = next;
  140.     }
  141.     _XimLocalIMFree(im);
  142.     _XimDestroyIMStructureList(im);
  143.     return(True);
  144. }
  145.  
  146. Public char *
  147. _XimLocalGetIMValues(xim, values)
  148.     XIM             xim;
  149.     XIMArg        *values;
  150. {
  151.     Xim             im = (Xim)xim;
  152.     XimDefIMValues     im_values;
  153.  
  154.     _XimGetCurrentIMValues(im, &im_values);
  155.     return(_XimGetIMValueData(im, (XPointer)&im_values, values,
  156.             im->core.im_resources, im->core.im_num_resources));
  157. }
  158.  
  159. Public char *
  160. _XimLocalSetIMValues(xim, values)
  161.     XIM             xim;
  162.     XIMArg        *values;
  163. {
  164.     Xim             im = (Xim)xim;
  165.     XimDefIMValues     im_values;
  166.     char        *name = (char *)NULL;
  167.  
  168.     _XimGetCurrentIMValues(im, &im_values);
  169.     name = _XimSetIMValueData(im, (XPointer)&im_values, values,
  170.         im->core.im_resources, im->core.im_num_resources);
  171.     _XimSetCurrentIMValues(im, &im_values);
  172.     return(name);
  173. }
  174.  
  175. Private void
  176. _XimCreateDefaultTree(im)
  177.     Xim        im;
  178. {
  179.     FILE *fp;
  180.     char *name;
  181.  
  182.     name = _XlcFileName(im->core.lcd, COMPOSE_FILE);
  183.     if (name == (char *)NULL)
  184.          return;
  185.     fp = fopen(name, "r");
  186.     Xfree(name);
  187.     if (fp == (FILE *)NULL)
  188.      return;
  189.     (void)XimParseStringFile(fp, &im->private.local.top);
  190.     fclose(fp);
  191. }
  192.  
  193. Private XIMMethodsRec      Xim_im_local_methods = {
  194.     _XimLocalCloseIM,           /* close */
  195.     _XimLocalSetIMValues,       /* set_values */
  196.     _XimLocalGetIMValues,       /* get_values */
  197.     _XimLocalCreateIC,          /* create_ic */
  198.     _XimLcctstombs,        /* ctstombs */
  199.     _XimLcctstowcs        /* ctstowcs */
  200. };
  201.  
  202. Public Bool
  203. _XimLocalOpenIM(im)
  204.     Xim             im;
  205. {
  206.     XLCd         lcd = im->core.lcd;
  207.     XlcConv         ctom_conv;
  208.     XlcConv         ctow_conv;
  209.     XimDefIMValues     im_values;
  210.  
  211.     _XimInitialResourceInfo();
  212.     if(_XimSetIMResourceList(&im->core.im_resources,
  213.                  &im->core.im_num_resources) == False) {
  214.     goto Open_Error;
  215.     }
  216.     if(_XimSetICResourceList(&im->core.ic_resources,
  217.                 &im->core.ic_num_resources) == False) {
  218.     goto Open_Error;
  219.     }
  220.  
  221.     _XimSetIMMode(im->core.im_resources, im->core.im_num_resources);
  222.  
  223.     _XimGetCurrentIMValues(im, &im_values);
  224.     if(_XimSetLocalIMDefaults(im, (XPointer)&im_values,
  225.         im->core.im_resources, im->core.im_num_resources) == False) {
  226.     goto Open_Error;
  227.     }
  228.     _XimSetCurrentIMValues(im, &im_values);
  229.  
  230.     _XimCreateDefaultTree(im);
  231.  
  232.     if (!(ctom_conv = _XlcOpenConverter(lcd,
  233.                     XlcNCompoundText, lcd, XlcNMultiByte)))
  234.     goto Open_Error;
  235.     if (!(ctow_conv = _XlcOpenConverter(lcd,
  236.                     XlcNCompoundText, lcd, XlcNWideChar)))
  237.     goto Open_Error;
  238.  
  239.     im->methods = &Xim_im_local_methods;
  240.     im->private.local.current_ic = (XIC)NULL;
  241.     im->private.local.ctom_conv = ctom_conv;
  242.     im->private.local.ctow_conv = ctow_conv;
  243.  
  244.     return(True);
  245.  
  246. Open_Error :
  247.     if (im->core.im_resources) {
  248.     Xfree(im->core.im_resources);
  249.     im->core.im_resources = NULL;
  250.     }
  251.     if (im->core.ic_resources) {
  252.     Xfree(im->core.ic_resources);
  253.     im->core.ic_resources = NULL;
  254.     }
  255.     if (im->core.im_values_list) {
  256.     Xfree(im->core.im_values_list);
  257.     im->core.im_values_list = NULL;
  258.     }
  259.     if (im->core.ic_values_list) {
  260.     Xfree(im->core.ic_values_list);
  261.     im->core.ic_values_list = NULL;
  262.     }
  263.     if (im->core.styles) {
  264.     Xfree(im->core.styles);
  265.     im->core.styles = NULL;
  266.     }
  267.     if (im->private.local.ctom_conv) {
  268.     _XlcCloseConverter(im->private.local.ctom_conv);
  269.     }
  270.     if (im->private.local.ctow_conv) {
  271.     _XlcCloseConverter(im->private.local.ctow_conv);
  272.     }
  273.     return(False);
  274. }
  275.