Back to index

im-sdk  12.3.91
im-aux-simple.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <sys/types.h>
00004 
00005 #include <iiimp-data.h>
00006 #include <iiimp-opcode.h>
00007 
00008 #include "iiimp-dataP.h"
00009 
00010 
00011 IIIMP_message *
00012 iiimp_aux_simple_new(
00013     IIIMP_data_s *   data_s,
00014     IIIMP_card7             opcode,
00015     IIIMP_card16     im_id,
00016     IIIMP_card16     ic_id,
00017     IIIMP_card32     class_index,
00018     IIIMP_string *   input_method_name)
00019 {
00020     IIIMP_message *  m;
00021     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00022     if (NULL == m) {
00023        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00024        return NULL;
00025     }
00026     m->opcode = opcode;
00027     m->im_id = im_id;
00028     m->ic_id = ic_id;
00029     m->v.aux_simple.class_index = class_index;
00030     m->v.aux_simple.input_method_name = input_method_name;
00031     return m;
00032 }
00033 
00034 
00035 void
00036 iiimp_aux_simple_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00037 {
00038     if (NULL == m) return;
00039     iiimp_string_delete(data_s, m->v.aux_simple.input_method_name);
00040     free(m);
00041     return;
00042 }
00043 
00044 
00045 uchar_t *
00046 iiimp_aux_simple_pack(
00047     IIIMP_data_s *   data_s,
00048     IIIMP_card7             opcode,
00049     IIIMP_card16     im_id,
00050     IIIMP_card16     ic_id,
00051     IIIMP_card32     class_index,
00052     IIIMP_string *   input_method_name,
00053     size_t *         buf_size)
00054 {
00055     size_t    nbyte;
00056     int              length;
00057     uchar_t * buf;
00058     size_t    rest;
00059     uchar_t * p;
00060 
00061     nbyte = 0;
00062     nbyte += 2;      /* input method id */
00063     nbyte += 2;      /* input context id */
00064     nbyte += 4;      /* auxiliary window class index */
00065     nbyte += input_method_name->nbyte;    /* input method name */
00066 
00067     length = (nbyte >> 2);
00068     *buf_size = (1 + 3 + nbyte);
00069 
00070     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00071     if (NULL == buf) {
00072        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00073        return NULL;
00074     }
00075 
00076     PUT_PACKET_HEADER(buf, opcode, length);
00077 
00078     rest = nbyte;
00079     p = (buf + 4);
00080 
00081     PUTU16(im_id, rest, p, data_s->byte_swap);
00082     PUTU16(ic_id, rest, p, data_s->byte_swap);
00083     PUTU32(class_index, rest, p, data_s->byte_swap);
00084     iiimp_string_pack(data_s, input_method_name, &rest, &p);
00085 
00086     return buf;
00087 }
00088 
00089 
00090 IIIMP_message *
00091 iiimp_aux_simple_unpack(
00092     IIIMP_data_s *   data_s,
00093     IIIMP_card7             opcode,
00094     size_t *         nbyte,
00095     const uchar_t ** ptr)
00096 {
00097     IIIMP_message *  m;
00098     size_t           rest;
00099     const uchar_t *  p;
00100 
00101     rest = *nbyte;
00102     p = *ptr;
00103 
00104     if (rest < (2 + 2 + 4 + 4)) {
00105        data_s->status = IIIMP_DATA_INVALID;
00106        return NULL;
00107     }
00108 
00109     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00110     if (NULL == m) {
00111        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00112        return NULL;
00113     }
00114 
00115     m->opcode = opcode;
00116 
00117     GETU16(m->im_id, rest, p, data_s->byte_swap);
00118     GETU16(m->ic_id, rest, p, data_s->byte_swap);
00119 
00120     GETU32(m->v.aux_simple.class_index, rest, p, data_s->byte_swap);
00121 
00122     m->v.aux_simple.input_method_name =
00123        iiimp_string_unpack(data_s, &rest, &p, rest);
00124     if (NULL == m->v.aux_simple.input_method_name) {
00125        free(m);
00126        return NULL;
00127     }
00128 
00129     return m;
00130 }
00131 
00132 
00133 void
00134 iiimp_aux_simple_print(
00135     IIIMP_data_s *   data_s,
00136     IIIMP_message *  m)
00137 {
00138     iiimp_message_header_print(data_s, m->opcode, m->im_id, m->ic_id);
00139     (void)fprintf(data_s->print_fp, "\tindex=%d name=",
00140                 m->v.aux_simple.class_index);
00141     iiimp_string_print(data_s, m->v.aux_simple.input_method_name);
00142     (void)fputc('\n', data_s->print_fp);
00143 }
00144 
00145 
00146 /* Local Variables: */
00147 /* c-file-style: "iiim-project" */
00148 /* End: */