Back to index

im-sdk  12.3.91
im-preedit-start-reply.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <sys/types.h>
00004 #if defined(lint) && defined(HAVE_NOTE_H)
00005 #include <note.h>
00006 #endif /* lint && HAVE_NOTE_H */
00007 
00008 #include <iiimp-data.h>
00009 #include <iiimp-opcode.h>
00010 
00011 #include "iiimp-dataP.h"
00012 
00013 
00014 IIIMP_message *
00015 iiimp_preedit_start_reply_new(
00016     IIIMP_data_s *   data_s,
00017     IIIMP_card16     im_id,
00018     IIIMP_card16     ic_id,
00019     IIIMP_int32             maximum_length)
00020 {
00021     IIIMP_message *  m;
00022     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00023     if (NULL == m) {
00024        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00025        return NULL;
00026     }
00027     m->opcode = IM_PREEDIT_START_REPLY;
00028     m->im_id = im_id;
00029     m->ic_id = ic_id;
00030     m->v.preedit_start_reply.maximum_length = maximum_length;
00031     return m;
00032 }
00033 
00034 
00035 void
00036 iiimp_preedit_start_reply_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00037 {
00038 #if defined(lint) && defined(HAVE_NOTE_H)
00039     NOTE(ARGUNUSED(data_s))
00040 #endif /* lint && HAVE_NOTE_H */
00041     if (NULL == m) return;
00042     free(m);
00043     return;
00044 }
00045 
00046 
00047 uchar_t *
00048 iiimp_preedit_start_reply_pack(
00049     IIIMP_data_s *   data_s,
00050     IIIMP_card16     im_id,
00051     IIIMP_card16     ic_id,
00052     IIIMP_int32             maximum_length,
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;      /* max length of preedit string */
00065 
00066     length = (nbyte >> 2);
00067     *buf_size = (1 + 3 + nbyte);
00068 
00069     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00070     if (NULL == buf) {
00071        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00072        return NULL;
00073     }
00074 
00075     PUT_PACKET_HEADER(buf, IM_PREEDIT_START_REPLY, length);
00076 
00077     rest = nbyte;
00078     p = (buf + 4);
00079 
00080     PUTU16(im_id, rest, p, data_s->byte_swap);
00081     PUTU16(ic_id, rest, p, data_s->byte_swap);
00082     PUTU32(maximum_length, rest, p, data_s->byte_swap);
00083 
00084     return buf;
00085 }
00086 
00087 
00088 IIIMP_message *
00089 iiimp_preedit_start_reply_unpack(
00090     IIIMP_data_s *   data_s,
00091     IIIMP_card7             opcode,
00092     size_t *         nbyte,
00093     const uchar_t ** ptr)
00094 {
00095     IIIMP_message *                m;
00096     IIIMP_preedit_start_reply_v *  v;
00097     size_t                         rest;
00098     const uchar_t *                p;
00099 
00100     rest = *nbyte;
00101     p = *ptr;
00102 
00103     if (rest < (2 + 2 + 4)) {
00104        data_s->status = IIIMP_DATA_INVALID;
00105        return NULL;
00106     }
00107 
00108     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00109     if (NULL == m) {
00110        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00111        return NULL;
00112     }
00113     v = &(m->v.preedit_start_reply);
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     GET32(v->maximum_length, rest, p, data_s->byte_swap);
00120 
00121     *nbyte = rest;
00122     *ptr = p;
00123 
00124     return m;
00125 }
00126 
00127 
00128 void
00129 iiimp_preedit_start_reply_print(
00130     IIIMP_data_s *   data_s,
00131     IIIMP_message *  m)
00132 {
00133     iiimp_message_header_print(data_s, m->opcode, m->im_id, m->ic_id);
00134     (void)fprintf(data_s->print_fp, "\tmax length of preedit string=%d\n",
00135                 m->v.preedit_start_reply.maximum_length);
00136 }
00137 
00138 
00139 /* Local Variables: */
00140 /* c-file-style: "iiim-project" */
00141 /* End: */