Back to index

im-sdk  12.3.91
im-lookup-choice-process.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 #include "print-misc.h"
00013 
00014 
00015 IIIMP_message *
00016 iiimp_lookup_choice_process_new(
00017     IIIMP_data_s *   data_s,
00018     IIIMP_card16     im_id,
00019     IIIMP_card16     ic_id,
00020     IIIMP_card16     type,
00021     IIIMP_card16     value)
00022 {
00023     IIIMP_message *  m;
00024     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00025     if (NULL == m) {
00026        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00027        return NULL;
00028     }
00029     m->opcode = IM_LOOKUP_CHOICE_PROCESS;
00030     m->im_id = im_id;
00031     m->ic_id = ic_id;
00032     m->v.lookup_choice_process.type = type;
00033     m->v.lookup_choice_process.value = value;
00034     return m;
00035 }
00036 
00037 
00038 void
00039 iiimp_lookup_choice_process_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00040 {
00041 #if defined(lint) && defined(HAVE_NOTE_H)
00042     NOTE(ARGUNUSED(data_s))
00043 #endif /* lint && HAVE_NOTE_H */
00044     if (NULL == m) return;
00045     free(m);
00046     return;
00047 }
00048 
00049 
00050 uchar_t *
00051 iiimp_lookup_choice_process_pack(
00052     IIIMP_data_s *   data_s,
00053     IIIMP_card16     im_id,
00054     IIIMP_card16     ic_id,
00055     IIIMP_card16     type,
00056     IIIMP_card16     value,
00057     size_t *         buf_size)
00058 {
00059     size_t           nbyte;
00060     int                     length;
00061     uchar_t *        buf;
00062     size_t           rest;
00063     uchar_t *        p;
00064 
00065     nbyte = 0;
00066     nbyte += 2;      /* input method id */
00067     nbyte += 2;      /* input context id */
00068     nbyte += 2;      /* type */
00069     nbyte += 2;      /* INDEX or PAGE */
00070 
00071     length = (nbyte >> 2);
00072     *buf_size = (1 + 3 + nbyte);
00073 
00074     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00075     if (NULL == buf) {
00076        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00077        return NULL;
00078     }
00079 
00080     PUT_PACKET_HEADER(buf, IM_LOOKUP_CHOICE_PROCESS, length);
00081 
00082     rest = nbyte;
00083     p = (buf + 4);
00084 
00085     PUTU16(im_id, rest, p, data_s->byte_swap);
00086     PUTU16(ic_id, rest, p, data_s->byte_swap);
00087     PUTU16(type, rest, p, data_s->byte_swap);
00088     PUTU16(value, rest, p, data_s->byte_swap);
00089 
00090     return buf;
00091 }
00092 
00093 
00094 IIIMP_message *
00095 iiimp_lookup_choice_process_unpack(
00096     IIIMP_data_s *   data_s,
00097     IIIMP_card7             opcode,
00098     size_t *         nbyte,
00099     const uchar_t ** ptr)
00100 {
00101     IIIMP_message *                m;
00102     IIIMP_lookup_choice_process_v *       v;
00103     size_t                         rest;
00104     const uchar_t *                p;
00105 
00106     rest = *nbyte;
00107     p = *ptr;
00108 
00109     if (rest < (2 + 2 + 2 + 2)) {
00110        data_s->status = IIIMP_DATA_INVALID;
00111        return NULL;
00112     }
00113 
00114     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00115     if (NULL == m) {
00116        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00117        return NULL;
00118     }
00119     v = &(m->v.lookup_choice_process);
00120 
00121     m->opcode = opcode;
00122 
00123     GETU16(m->im_id, rest, p, data_s->byte_swap);
00124     GETU16(m->ic_id, rest, p, data_s->byte_swap);
00125     GETU16(v->type, rest, p, data_s->byte_swap);
00126     switch (v->type) {
00127     case IM_LOOKUP_CHOICE_PROCESS_INDEX: /* INDEX */
00128        GET16(v->value, rest, p, data_s->byte_swap);
00129        break;
00130     case IM_LOOKUP_CHOICE_PROCESS_PAGE: /* PAGE */
00131     default:
00132        GETU16(v->value, rest, p, data_s->byte_swap);
00133        break;
00134     }
00135 
00136     *nbyte = rest;
00137     *ptr = p;
00138 
00139     return m;
00140 }
00141 
00142 
00143 void
00144 iiimp_lookup_choice_process_print(
00145     IIIMP_data_s *   data_s,
00146     IIIMP_message *  m)
00147 {
00148     IIIMP_lookup_choice_process_v *       v;
00149 
00150     v = &(m->v.lookup_choice_process);
00151     iiimp_message_header_print(data_s, m->opcode, m->im_id, m->ic_id);
00152     switch (v->type) {
00153     case IM_LOOKUP_CHOICE_PROCESS_INDEX: /* index of selected choice */
00154        (void)fprintf(data_s->print_fp, "index=%d", v->value);
00155        break;
00156     case IM_LOOKUP_CHOICE_PROCESS_PAGE: /* page change */
00157        (void)fprintf(data_s->print_fp, "%s (%d)",
00158                     lookup_choice_process_page_string_get(v->value),
00159                     v->value);
00160        break;
00161     default:
00162        (void)fprintf(data_s->print_fp, "unknown operation type");
00163     }
00164     (void)fputc('\n', data_s->print_fp);
00165 }
00166 
00167 
00168 /* Local Variables: */
00169 /* c-file-style: "iiim-project" */
00170 /* End: */