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

  1. /* $XConsortium: lcRM.c,v 1.3 94/01/20 18:07:18 rws Exp $ */
  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 "Xlib_private.h"
  28. #include "XlcPubI.h"
  29. #include <stdio.h>
  30.  
  31. typedef struct _StateRec {
  32.     XLCd lcd;
  33.     XlcConv conv;
  34. } StateRec, *State;
  35.  
  36. static void
  37. mbinit(state)
  38.     XPointer state;
  39. {
  40.     DBUG_ENTER("mbinit")
  41.     _XlcResetConverter(((State) state)->conv);
  42.     DBUG_VOID_RETURN;
  43. }
  44.  
  45. static char
  46. mbchar(state, str, lenp)
  47.     XPointer state;
  48.     char *str;
  49.     int *lenp;
  50. {
  51.     DBUG_ENTER("mbchar")
  52.     XlcConv conv = ((State) state)->conv;
  53.     XlcCharSet charset;
  54.     char *from, *to, buf[BUFSIZ];
  55.     int from_left, to_left;
  56.     XPointer args[1];
  57.  
  58.     from = str;
  59.     *lenp = from_left = XLC_PUBLIC(((State) state)->lcd, mb_cur_max);
  60.     to = buf;
  61.     to_left = BUFSIZ;
  62.     args[0] = (XPointer) &charset;
  63.  
  64.     _XlcConvert(conv, (XPointer *) &from, &from_left, (XPointer *) &to,
  65.         &to_left, args, 1);
  66.     
  67.     *lenp -= from_left;
  68.  
  69.     /* XXX */
  70.     DBUG_RETURN(buf[0]);
  71. }
  72.  
  73. static void
  74. mbfinish(state)
  75.     XPointer state;
  76. {
  77. }
  78.  
  79. static char *
  80. lcname(state)
  81.     XPointer state;
  82. {
  83.     DBUG_ENTER("lcname")
  84.     char *result = ((State) state)->lcd->core->name;
  85.     DBUG_RETURN(result);
  86. }
  87.  
  88. static void
  89. destroy(state)
  90.     XPointer state;
  91. {
  92.     DBUG_ENTER("destroy")
  93.     _XlcCloseConverter(((State) state)->conv);
  94.     _XCloseLC(((State) state)->lcd);
  95.     Xfree((char *) state);
  96.     DBUG_VOID_RETURN;
  97. }
  98.  
  99. static XrmMethodsRec rm_methods = {
  100.     mbinit,
  101.     mbchar,
  102.     mbfinish,
  103.     lcname,
  104.     destroy
  105. } ;
  106.  
  107. XrmMethods
  108. _XrmDefaultInitParseInfo(lcd, rm_state)
  109.     XLCd lcd;
  110.     XPointer *rm_state;
  111. {
  112.     DBUG_ENTER("_XrmDefaultInitParseInfo")
  113.     State state;
  114.  
  115.     state = (State) Xmalloc(sizeof(StateRec));
  116.     if (state == NULL)
  117.     DBUG_RETURN((XrmMethods) NULL);
  118.  
  119.     state->lcd = lcd;
  120.     state->conv = _XlcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNChar);
  121.     if (state->conv == NULL) {
  122.     Xfree((char *) state);
  123.  
  124.     DBUG_RETURN((XrmMethods) NULL);
  125.     }
  126.     
  127.     *rm_state = (XPointer) state;
  128.     
  129.     DBUG_RETURN(&rm_methods);
  130. }
  131.