Back to index

im-sdk  12.3.91
comp-hotkeys.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 HOTKEY_LIST *
00014 iiimp_hotkey_list_new(
00015     IIIMP_data_s *   data_s,
00016     int                     count,
00017     HOTKEY *          hk)
00018 {
00019     HOTKEY_LIST *               data;
00020     size_t                      nbyte = 0;
00021     int                         i;
00022 
00023     data = (HOTKEY_LIST *) malloc(sizeof (HOTKEY_LIST));
00024     if (NULL == data) {
00025        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00026        return NULL;
00027     }
00028 
00029     for(i=0 ; i < count ; i++){
00030        nbyte += (4 +                  // size of HOTKEYCTL
00031                 4 +                  // size of N:length of HOTKEY keyevent
00032                 hk[i].hotkeylist->nbyte +
00033                 hk[i].label->nbyte ) ;
00034     }
00035 
00036     data->nbyte = nbyte ;
00037     data->count = count;
00038 
00039     if (0 == data) {
00040        data->hotkey = NULL;
00041     } else {
00042        data->hotkey = (HOTKEY *)malloc(nbyte);
00043        if (NULL == data->hotkey) {
00044            return NULL;
00045        }
00046     }
00047                                                                                 
00048     if (NULL != hk) {
00049        for (i=0 ; i < count ; i++) {
00050            data->hotkey[i].hotkeyctrl = hk[i].hotkeyctrl ;
00051            data->hotkey[i].nbyte = hk[i].hotkeylist->nbyte ;
00052            data->hotkey[i].hotkeylist = hk[i].hotkeylist;
00053            data->hotkey[i].label = hk[i].label;
00054        }
00055     }
00056 
00057     return data;
00058 }
00059 
00060 void
00061 iiimp_hotkey_list_pack(
00062     IIIMP_data_s *          data_s,
00063     HOTKEY_LIST  *           m,
00064     size_t *                nbyte,
00065     uchar_t **                     ptr)
00066 {
00067     size_t    rest;
00068     uchar_t * p;
00069     int         i;
00070 
00071     rest = *nbyte;
00072     p = *ptr;
00073 
00074     for (i = 0; i < m->count; i++) {
00075        PUTU16(m->hotkey[i].hotkeyctrl.hotkey_id, rest, p, data_s->byte_swap);
00076        PUTU8(m->hotkey[i].hotkeyctrl.state_flag, rest, p, data_s->byte_swap);
00077        PUTU8(m->hotkey[i].hotkeyctrl.action_flag, rest, p, data_s->byte_swap);
00078        PUTU32(m->hotkey[i].nbyte, rest, p, data_s->byte_swap);
00079        iiimp_keyevent_list_pack(data_s, m->hotkey[i].hotkeylist, &rest, &p);
00080        iiimp_string_pack(data_s, m->hotkey[i].label, &rest, &p);
00081     }
00082 
00083     *nbyte = rest;
00084     *ptr = p;
00085 
00086     return;
00087 }
00088 
00089 void
00090 iiimp_hotkey_list_delete(IIIMP_data_s * data_s, HOTKEY_LIST * m)
00091 {
00092     int i;
00093     if (NULL == m) return;
00094 
00095     for (i = 0; i < m->count; i++) {
00096        iiimp_keyevent_list_delete(data_s, m->hotkey[i].hotkeylist);
00097        iiimp_string_delete(data_s, m->hotkey[i].label);
00098     }
00099     if (m->hotkey) free (m->hotkey);
00100     free(m);
00101 }
00102 
00103 HOTKEY_LIST *
00104 iiimp_hotkey_list_unpack(
00105     IIIMP_data_s *   data_s,
00106     size_t *         nbyte,
00107     const uchar_t ** ptr,
00108     size_t           nbyte_max)
00109 {
00110     HOTKEY_LIST *       data;
00111     HOTKEY *            hk;
00112     int                 count = 0;
00113     int                 len;
00114     size_t           rest;
00115     const uchar_t *  p;
00116   
00117     hk = NULL;
00118 
00119     rest = nbyte_max;
00120     p = *ptr;
00121 
00122     if ((*nbyte < rest) || (rest < 4)) {
00123        data_s->status = IIIMP_DATA_INVALID;
00124        return NULL;
00125     }
00126 
00127     data = (HOTKEY_LIST *)malloc(nbyte_max);
00128     if (NULL == data) {
00129        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00130        return NULL;
00131     }
00132     data->nbyte = nbyte_max;
00133     data->hotkey = NULL;
00134 
00135     while (0 < rest) {
00136        if (!data->hotkey)
00137            data->hotkey = (HOTKEY *)malloc(sizeof(HOTKEY));
00138        else
00139            data->hotkey = (HOTKEY *)realloc((HOTKEY *)data->hotkey,(count+1) * sizeof(HOTKEY));
00140        if (NULL == data->hotkey) {
00141            data_s->status = IIIMP_DATA_MALLOC_ERROR;
00142            return NULL;
00143        }
00144        GETU16(data->hotkey[count].hotkeyctrl.hotkey_id, rest, p, data_s->byte_swap);
00145        GETU8(data->hotkey[count].hotkeyctrl.state_flag, rest, p, data_s->byte_swap);
00146        GETU8(data->hotkey[count].hotkeyctrl.action_flag, rest, p, data_s->byte_swap);
00147        GETU32(len, rest, p, data_s->byte_swap);
00148        data->hotkey[count].nbyte = len;
00149        data->hotkey[count].hotkeylist = iiimp_keyevent_list_unpack(data_s, &rest, &p, len);
00150        if (NULL == data->hotkey[count].hotkeylist) {
00151            free(data->hotkey);
00152            return NULL;
00153        }
00154        data->hotkey[count].label = iiimp_string_unpack(data_s, &rest, &p, rest);
00155        count++;
00156     }
00157     data->count = count;
00158 
00159     *nbyte -= (nbyte_max - rest);
00160     *ptr += nbyte_max; 
00161 
00162     return data;
00163 }
00164 
00165 void
00166 iiimp_hotkey_list_print(
00167     IIIMP_data_s *     data_s,
00168     HOTKEY_LIST *      m)
00169 {
00170     int i;
00171 
00172     if (NULL == m) return;
00173 
00174     for (i = 0; i < m->count; i++) {
00175        (void)fprintf(data_s->print_fp, "\tHOTKEY ID = ");
00176        (void)fprintf(data_s->print_fp, "(%d)\n", m->hotkey[i].hotkeyctrl.hotkey_id);
00177        (void)fprintf(data_s->print_fp, "\tSTATE FLAG = ");
00178        (void)fprintf(data_s->print_fp, "(%d)\n", m->hotkey[i].hotkeyctrl.state_flag);
00179        (void)fputc('\n', data_s->print_fp);
00180        (void)fprintf(data_s->print_fp, "\tACTION FLAG = ");
00181        (void)fprintf(data_s->print_fp, "(%d)\n", m->hotkey[i].hotkeyctrl.action_flag);
00182        (void)fputc('\n', data_s->print_fp);
00183        (void)fprintf(data_s->print_fp, "\tHOTKEY List = \n");
00184        iiimp_keyevent_list_print(data_s, m->hotkey[i].hotkeylist);
00185        (void)fprintf(data_s->print_fp, "\tText Label = ");
00186        iiimp_string_print(data_s, m->hotkey[i].label);
00187        (void)fputc('\n', data_s->print_fp);
00188     }
00189 }
00190 
00191 
00192 /* Local Variables: */
00193 /* c-file-style: "iiim-project" */
00194 /* End: */