Back to index

im-sdk  12.3.91
comp-keyevent.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <sys/types.h>
00005 #if defined(lint) && defined(HAVE_NOTE_H)
00006 #include <note.h>
00007 #endif /* lint && HAVE_NOTE_H */
00008 
00009 #include <iiimp-data.h>
00010 
00011 #include "iiimp-dataP.h"
00012 
00013 
00014 IIIMP_keyevent_list *
00015 iiimp_keyevent_list_new(
00016     IIIMP_data_s *   data_s,
00017     int                     count,
00018     IIIMP_keyevent * k)
00019 {
00020     IIIMP_keyevent_list *   data;
00021     size_t                  nbyte;
00022 
00023     data = (IIIMP_keyevent_list *)malloc(sizeof (IIIMP_keyevent_list));
00024     if (NULL == data) {
00025        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00026        return NULL;
00027     }
00028 
00029     nbyte = ((4 + 4 + 4 + 4) * count);
00030 
00031     data->nbyte = nbyte;
00032     data->count = count;
00033 
00034     nbyte = ((sizeof (IIIMP_keyevent)) * count);
00035 
00036     if (0 == count) {
00037        data->keyevent = NULL;
00038     } else {
00039        data->keyevent = (IIIMP_keyevent *)malloc(nbyte);
00040        if (NULL == data->keyevent) {
00041            free(data);
00042            data_s->status = IIIMP_DATA_MALLOC_ERROR;
00043            return NULL;
00044        }
00045 
00046        (void)memcpy(data->keyevent, k, nbyte);
00047     }
00048 
00049     return data;
00050 }
00051 
00052 
00053 void
00054 iiimp_keyevent_list_delete(IIIMP_data_s * data_s, IIIMP_keyevent_list * kel)
00055 {
00056 #if defined(lint) && defined(HAVE_NOTE_H)
00057     NOTE(ARGUNUSED(data_s))
00058 #endif /* lint && HAVE_NOTE_H */
00059        if (NULL == kel) return;
00060     free(kel->keyevent);
00061     free(kel);
00062 }
00063 
00064 
00065 void
00066 iiimp_keyevent_list_pack(
00067     IIIMP_data_s *          data_s,
00068     IIIMP_keyevent_list *   m,
00069     size_t *                nbyte,
00070     uchar_t **                     ptr)
00071 {
00072     size_t    rest;
00073     uchar_t * p;
00074     int              i;
00075 
00076     rest = *nbyte;
00077     p = *ptr;
00078 
00079     for (i = 0; i < m->count; i++) {
00080        PUT32((m->keyevent + i)->keycode, rest, p, data_s->byte_swap);
00081        PUT32((m->keyevent + i)->keychar, rest, p, data_s->byte_swap);
00082        PUT32((m->keyevent + i)->modifier, rest, p, data_s->byte_swap);
00083        PUT32((m->keyevent + i)->time_stamp, rest, p, data_s->byte_swap);
00084     }
00085 
00086     *nbyte = rest;
00087     *ptr = p;
00088 
00089     return;
00090 }
00091 
00092 
00093 IIIMP_keyevent_list *
00094 iiimp_keyevent_list_unpack(
00095     IIIMP_data_s *          data_s,
00096     size_t *                nbyte,
00097     const uchar_t **        ptr,
00098     size_t                  nbyte_max)
00099 {
00100     IIIMP_keyevent_list *   l;
00101     size_t                  rest;
00102     const uchar_t *         p;
00103     int                            count;
00104     int                            i;
00105 
00106     rest = nbyte_max;
00107     p = *ptr;
00108 
00109     if ((*nbyte < rest)) {
00110        data_s->status = IIIMP_DATA_INVALID;
00111        return NULL;
00112     }
00113 
00114     count = (nbyte_max / KEY_EVENT_OBJECT_SIZE);
00115     if (nbyte_max != (count * KEY_EVENT_OBJECT_SIZE)) {
00116        data_s->status = IIIMP_DATA_INVALID;
00117        return NULL;
00118     }
00119 
00120     l = (IIIMP_keyevent_list *)malloc(sizeof (IIIMP_keyevent_list));
00121     if (NULL == l) {
00122        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00123        return NULL;
00124     }
00125 
00126     l->count = count;
00127 
00128     if (0 == count) {
00129        l->keyevent = NULL;
00130        return l;
00131     }
00132 
00133     l->keyevent = (IIIMP_keyevent *)malloc((sizeof (IIIMP_keyevent)) * count);
00134     if (NULL == l->keyevent) {
00135        free(l);
00136        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00137        return NULL;
00138     }
00139 
00140     for (i = 0; i < count; i++) {
00141        GET32((l->keyevent + i)->keycode, rest, p, data_s->byte_swap);
00142        GET32((l->keyevent + i)->keychar, rest, p, data_s->byte_swap);
00143        GET32((l->keyevent + i)->modifier, rest, p, data_s->byte_swap);
00144        GET32((l->keyevent + i)->time_stamp, rest, p, data_s->byte_swap);
00145     }
00146 
00147     /* This failed for the scenario of having multiple HOTKEYS and each
00148        having multiple keyevents.
00149        *nbyte = rest;
00150        */
00151 
00152     *nbyte -= (nbyte_max - rest);
00153     *ptr = p;
00154 
00155     return l;
00156 }
00157 
00158 
00159 void
00160 iiimp_keyevent_print(
00161     IIIMP_data_s *   data_s,
00162     IIIMP_keyevent * m)
00163 {
00164     if (NULL == m) return;
00165 
00166     (void)fprintf(data_s->print_fp,
00167                 "\tcode=%02x char=%02x modifier=%02x time_stamp=%x\n",
00168                 m->keycode, m->keychar, m->modifier, m->time_stamp);
00169 }
00170 
00171 
00172 void
00173 iiimp_keyevent_list_print(
00174     IIIMP_data_s *          data_s,
00175     IIIMP_keyevent_list *   m)
00176 {
00177     int       i;
00178 
00179     if (NULL == m) return;
00180 
00181     for (i = 0; i < m->count; i++) {
00182        iiimp_keyevent_print(data_s, m->keyevent + i);
00183     }
00184 }
00185 
00186 
00187 /* Local Variables: */
00188 /* c-file-style: "iiim-project" */
00189 /* End: */