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

  1. /* $TOG: imInt.c /main/4 1997/04/28 16:39:57 barstow $ */
  2. /******************************************************************
  3.  
  4.            Copyright 1992, 1993, 1994 by FUJITSU LIMITED
  5.  
  6. Permission to use, copy, modify, distribute, and sell this software
  7. and its documentation for any purpose is hereby granted without fee,
  8. provided that the above copyright notice appear in all copies and
  9. that both that copyright notice and this permission notice appear
  10. in supporting documentation, and that the name of FUJITSU LIMITED
  11. not be used in advertising or publicity pertaining to distribution
  12. of the software without specific, written prior permission.
  13. FUJITSU LIMITED makes no representations about the suitability of
  14. this software for any purpose. 
  15. It is provided "as is" without express or implied warranty.
  16.  
  17. FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  18. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  19. EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20. CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  21. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  22. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  23. PERFORMANCE OF THIS SOFTWARE.
  24.  
  25.   Author: Takashi Fujiwara     FUJITSU LIMITED 
  26.                                fujiwara@a80.tech.yk.fujitsu.co.jp
  27.  
  28. ******************************************************************/
  29. /* $XFree86: xc/lib/X11/imInt.c,v 3.0.4.3 1998/05/19 02:55:10 dawes Exp $ */
  30.  
  31. #include "Xlib_private.h"
  32. #undef CARD8
  33. #include <X11/Xproto.h>
  34. #include <X11/Xatom.h>
  35. #include <X11/Xlib.h>
  36. #include <X11/Xmd.h>
  37. #include "Xlcint.h"
  38. #include "Ximint.h"
  39. #include "XimImSw.h"
  40.  
  41. Private Xim         *_XimCurrentIMlist  = (Xim *)NULL;
  42. Private int         _XimCurrentIMcount = 0;
  43.  
  44. #ifndef BUFSIZE
  45. #define BUFSIZE 2048
  46. #endif
  47.  
  48. Private Bool
  49. #if NeedFunctionPrototypes
  50. _XimSetIMStructureList(
  51.     Xim          im)
  52. #else
  53. _XimSetIMStructureList(im)
  54.     Xim          im;
  55. #endif
  56. {
  57.     DBUG_ENTER("_XimSetIMStructureList")
  58.     register int  i;
  59.     Xim         *xim;
  60.  
  61.     if(!(_XimCurrentIMlist)) {
  62.     if(!(_XimCurrentIMlist = (Xim *)Xmalloc(sizeof(Xim))))
  63.         DBUG_RETURN(False);
  64.     _XimCurrentIMlist[0] = im;
  65.     _XimCurrentIMcount   = 1;
  66.     }
  67.     else {
  68.     for(i = 0; i < _XimCurrentIMcount; i++) {
  69.         if(!( _XimCurrentIMlist[i])) {
  70.         _XimCurrentIMlist[i] = im;
  71.         break;
  72.         }
  73.     }
  74.     if(i >= _XimCurrentIMcount) {
  75.         if(!(xim = (Xim *)Xrealloc(_XimCurrentIMlist, 
  76.                      ((i + 1) * sizeof(Xim)))))
  77.         DBUG_RETURN(False);
  78.         _XimCurrentIMlist              = xim;
  79.         _XimCurrentIMlist[_XimCurrentIMcount] = im;
  80.         _XimCurrentIMcount++;
  81.     }
  82.     }
  83.     DBUG_RETURN(True);
  84. }
  85.  
  86. Public void
  87. _XimDestroyIMStructureList(im)
  88.     Xim          im;
  89. {
  90.     DBUG_ENTER("_XimDestroyIMStructureList")
  91.     register int  i;
  92.  
  93.     for(i = 0; i < _XimCurrentIMcount; i++) {
  94.     if(_XimCurrentIMlist[i] == im) {
  95.         _XimCurrentIMlist[i] = NULL;
  96.         break;
  97.     }
  98.     }
  99.     DBUG_VOID_RETURN;
  100. }
  101.  
  102. Public void
  103. _XimServerDestroy(im_2_destroy)
  104.     Xim          im_2_destroy;
  105. {
  106.     DBUG_ENTER("_XimServerDestroy")
  107.     register int  i;
  108.     Xim          im;
  109.     XIC          ic;
  110.  
  111.     for(i = 0; i < _XimCurrentIMcount; i++) {
  112.     if(!(im = _XimCurrentIMlist[i]))
  113.         continue;
  114.     /*
  115.      * Only continue if this im is the one to be destroyed.
  116.      */
  117.     if (im != im_2_destroy)
  118.         continue;
  119.  
  120.     if (im->core.destroy_callback.callback)
  121.         (*im->core.destroy_callback.callback)((XIM)im,
  122.             im->core.destroy_callback.client_data, NULL);
  123.     for (ic = im->core.ic_chain; ic; ic = ic->core.next) {
  124.         if (ic->core.destroy_callback.callback) {
  125.         (*ic->core.destroy_callback.callback)(ic,
  126.             ic->core.destroy_callback.client_data, NULL);
  127.         }
  128.     }
  129.     _XimResetIMInstantiateCallback( im );
  130.     (void)im->methods->close((XIM)im);
  131.     Xfree(im);
  132.     _XimCurrentIMlist[i] = NULL;
  133.     DBUG_VOID_RETURN;
  134.     }
  135.     DBUG_VOID_RETURN;
  136. }
  137.  
  138. #ifdef XIM_CONNECTABLE
  139. Public void
  140. _XimServerReconectableDestroy()
  141. {
  142.     DBUG_ENTER("_XimServerReconectableDestroy")
  143.     register int  i;
  144.     Xim          im;
  145.     XIC          ic;
  146.  
  147.     for(i = 0; i < _XimCurrentIMcount; i++) {
  148.     if(!(im = _XimCurrentIMlist[i]))
  149.         continue;
  150.  
  151.     if (im->core.destroy_callback.callback)
  152.         (*im->core.destroy_callback.callback)(im,
  153.             im->core.destroy_callback.client_data, NULL);
  154.     for (ic = im->core.ic_chain; ic; ic = ic->core.next) {
  155.         if (ic->core.destroy_callback.callback) {
  156.         (*ic->core.destroy_callback.callback)(ic,
  157.             ic->core.destroy_callback.client_data, NULL);
  158.         }
  159.     }
  160.     _XimResetIMInstantiateCallback( im );
  161.     (void)im->methods->close((XIM)im);
  162.     }
  163.     DBUG_VOID_RETURN;
  164. }
  165. #endif /* XIM_CONNECTABLE */
  166.  
  167. Private char    *
  168. #if NeedFunctionPrototypes
  169. _XimStrstr(
  170.     register char    *src,
  171.     register char    *dest)
  172. #else
  173. _XimStrstr(src, dest)
  174.     register char    *src, *dest;
  175. #endif
  176. {
  177.     DBUG_ENTER("_XimStrstr")
  178.     int             len;
  179.     
  180.     len = strlen(dest);
  181.     while ((src = strchr(src, *dest)) != 0) {
  182.     if(!strncmp(src, dest, len))
  183.         DBUG_RETURN(src);
  184.     src++;
  185.     }
  186.     DBUG_RETURN(NULL);
  187. }
  188.  
  189. Private char *
  190. #if NeedFunctionPrototypes
  191. _XimMakeImName(
  192.     XLCd       lcd)
  193. #else
  194. _XimMakeImName(lcd)
  195.     XLCd       lcd;
  196. #endif
  197. {
  198.     DBUG_ENTER("_XimMakeImName")
  199.     char       buf[BUFSIZE];
  200.     register char *mod;
  201.     register int   i = 0;
  202.     char      *ret;
  203.  
  204.     buf[0] = '\0';
  205.     if (lcd->core->modifiers != (char *)NULL &&
  206.     strlen(lcd->core->modifiers) >= sizeof(buf))
  207.     DBUG_RETURN(NULL);
  208.     if(lcd->core->modifiers != (char *)NULL && *lcd->core->modifiers != '\0') {
  209.     mod = _XimStrstr(lcd->core->modifiers, XIMMODIFIER);
  210.     if(mod) {
  211.         mod += strlen(XIMMODIFIER);
  212.         while (*mod && *mod != '@')
  213.         buf[i++] = *mod++;
  214.         buf[i] = '\0';
  215.     }
  216.     }
  217.     if(!(ret = Xmalloc(i + 1)))
  218.     DBUG_RETURN(NULL);
  219.     (void)strcpy(ret, buf);
  220.     DBUG_RETURN(ret);
  221. }
  222.  
  223. Private XIM
  224. #if NeedFunctionPrototypes
  225. _XimOpenIM(
  226.     XLCd         lcd,
  227.     Display        *dpy,
  228.     XrmDatabase         rdb,
  229.     char        *res_name,
  230.     char        *res_class)
  231. #else
  232. _XimOpenIM(lcd, dpy, rdb, res_name, res_class)
  233.     XLCd         lcd;
  234.     Display        *dpy;
  235.     XrmDatabase         rdb;
  236.     char        *res_name, *res_class;
  237. #endif
  238. {
  239.     DBUG_ENTER("_XimOpenIM")
  240.     Xim             im;
  241.     register int     i;
  242.     
  243.     if (!(im = (Xim)Xmalloc(sizeof(XimRec))))
  244.     DBUG_RETURN((XIM)NULL);
  245.     bzero(im, sizeof(XimRec));
  246.  
  247.     im->core.lcd       = lcd;
  248.     im->core.ic_chain  = (XIC)NULL;
  249.     im->core.display   = dpy;
  250.     im->core.rdb       = rdb;
  251.     im->core.res_name  = NULL;
  252.     im->core.res_class = NULL;
  253.     if((res_name != NULL) && (*res_name != '\0')){
  254.     if(!(im->core.res_name  = (char *)Xmalloc(strlen(res_name)+1)))
  255.         goto Error1;
  256.     strcpy(im->core.res_name,res_name);
  257.     }
  258.     if((res_class != NULL) && (*res_class != '\0')){
  259.     if(!(im->core.res_class = (char *)Xmalloc(strlen(res_class)+1)))
  260.         goto Error2;
  261.     strcpy(im->core.res_class,res_class);
  262.     }
  263.     if(!(im->core.im_name = _XimMakeImName(lcd)))
  264.     goto Error3;
  265.  
  266.     for(i= 0; ; i++) {
  267.     if(_XimImSportRec[i].checkprocessing(im)) {
  268.         if(!(_XimImSportRec[i].im_open(im)))
  269.         goto Error4;
  270.         if(!_XimSetIMStructureList(im))
  271.         goto Error4;
  272.         DBUG_RETURN((XIM)im);
  273.     }
  274.     }
  275.  
  276. Error4 :
  277.     _XimImSportRec[i].im_free(im);
  278.     Xfree(im);
  279.     DBUG_RETURN(NULL);
  280. Error3 :
  281.     if(im->core.im_name)
  282.     Xfree(im->core.im_name);
  283. Error2:
  284.     if(im->core.res_class)
  285.     Xfree(im->core.res_class);
  286. Error1:
  287.     if(im->core.res_name)
  288.     Xfree(im->core.res_name);
  289.     Xfree(im);
  290.     DBUG_RETURN(NULL);
  291. }
  292.  
  293. Public Bool
  294. _XInitIM(lcd)
  295.     XLCd     lcd;
  296. {
  297.     DBUG_ENTER("_XInitIM")
  298.     if(lcd == (XLCd)NULL)
  299.     DBUG_RETURN(False);
  300.     lcd->methods->open_im = _XimOpenIM;
  301.     lcd->methods->register_callback = _XimRegisterIMInstantiateCallback;
  302.     lcd->methods->unregister_callback = _XimUnRegisterIMInstantiateCallback;
  303.     DBUG_RETURN(True);
  304. }
  305.