~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-libs/tina/file/fileTs_serialise.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/file/fileTs_serialise.c,v $
 37  * Date    :  $Date: 2005/02/07 23:27:41 $
 38  * Version :  $Revision: 1.5 $
 39  * CVS Id  :  $Id: fileTs_serialise.c,v 1.5 2005/02/07 23:27:41 paul Exp $
 40  *
 41  * Notes :
 42  *
 43  *********
 44 */
 45 
 46 #include "fileTs_serialise.h"
 47 
 48 #if HAVE_CONFIG_H
 49   #include <config.h>
 50 #endif
 51 
 52 #include <stdio.h>
 53 #include <stdlib.h>
 54 #include <string.h>
 55 #include <tina/sys/sysDef.h>
 56 #include <tina/sys/sysPro.h>
 57 #include <tina/file/file_TsDef.h>
 58 #include <tina/file/fileTs_free.h>
 59 
 60 #define SUBSTRUCT_ALIGNMENT 4
 61 #define ALIGN_VARPTR(start,here,size) \
 62 { \
 63    int tab=(int)((here).char_v-(char*)(start))%(size);\
 64    (here).char_v+=tab?(size)-tab:0;\
 65    }
 66 
 67 
 68 static int count = 0;           /* static data! */
 69 
 70 
 71 static List *serialise_parse(List * lg, void *data, Varptr dp, char **ss)
 72 {
 73         char *s = *ss;
 74         int repeats = 0, exiting = 0;
 75         static Varptr d, nulld;                 /* static data! */
 76 
 77         nulld.char_v = NULL;
 78         if (dp.char_v)
 79                 d = dp;                                                                                 /* if dp is null use static version d */
 80         /* else use new value */
 81 
 82         while (*s && !exiting)
 83         {
 84                 switch (*s++)
 85                 {
 86                         case '':
 87                                 repeats *= 10;
 88                                 break;
 89                         case '1':
 90                         case '2':
 91                         case '3':
 92                         case '4':
 93                         case '5':
 94                         case '6':
 95                         case '7':
 96                         case '8':
 97                         case '9':
 98                                 repeats *= 10;
 99                                 repeats += *(s - 1) - 48;
100                                 break;
101                         case '[':
102                         case '(':                                                               /* start of a repetition */
103                         {
104                                 char *temp_s = s;
105 
106                                 while (repeats-- > 0)
107                                 {
108                                         temp_s = s;
109                                         lg = serialise_parse(lg, data, nulld, &temp_s);
110                                 }
111                                 s = temp_s;                                                     /* the rest of the swap string */
112                                 repeats = 0;
113                         }
114                                 break;
115                         case ')':
116                         case ']':
117                                 exiting = 1;
118                                 break;
119                         case '/':
120                         {
121                                 char *end = strchr(s, '/');
122 
123                                 s = end + 1;
124                         }
125                                 break;
126                         default:
127                         {
128                                 do
129                                 {
130                                         switch (*(s - 1))
131                                         {
132                                                 case 'b':
133                                                 case 'c':
134                                                         d.char_v++;
135                                                         break;
136                                                 case 'f':
137                                                 case 'l':
138                                                 case 'i':
139                                                 case 'o':
140                                                 case 'u':
141                                                 case ',':
142                                                 case '.':
143                                                 case 'w':
144                                                         ALIGN_VARPTR(data, d, 4);
145                                                         d.int_v++;
146                                                         break;
147                                                 case 'p':
148                                                 case 's':
149                                                         ALIGN_VARPTR(data, d, 4);
150                                                         break;
151                                                 case 'h':
152                                                 case 'k':
153                                                         ALIGN_VARPTR(data, d, 2);
154                                                         d.short_v++;
155                                                         break;
156                                                 case 'g':
157                                                 case 'e':
158                                                         ALIGN_VARPTR(data, d, 8);
159                                                         d.double_v++;
160                                                         break;
161                                                 case 't':
162                                                         ALIGN_VARPTR(data, d, SUBSTRUCT_ALIGNMENT);
163                                                         break;
164                                         }
165                                         switch (*(s - 1))
166                                         {
167                                                 case 'p':                                       /* pointer types - recurse (later) */
168                                                         if (*d.ptr_v)
169                                                         {
170                                                                 Varptr td = d;  /* keep d pointer */
171 
172                                                                 lg = ts_serialise_gen(lg, *d.ptr_v);
173                                                                 d = td;
174                                                         }
175                                                         d.ptr_v++;
176                                                         break;
177                                                 case 's':                                       /* string */
178                                                         if (*d.ptr_v)
179                                                                 serialise_item(&lg, *d.ptr_v, strlen(*d.ptr_v));
180                                                         d.ptr_v++;
181                                                         break;
182                                                 case 't':                                       /* tagged struct */
183                                                         serialise_tagged_sub_item(&lg, d.int_v);
184                                                         break;
185                                         }
186                                 }
187                                 while (--repeats > 0);
188                                 repeats = 0;
189                         }
190                                 break;
191                 }
192         }
193 
194 
195         *ss = s;
196         return lg;
197 }
198 
199 
200 
201 int ts_serialise_end(void)
202 {
203         int c = count;
204 
205         count = 0;
206         return c;
207 }
208 
209 
210 int serialise_item(List ** lgp, void *d, size_t s)
211 {
212         List *l = NULL, *lg = *lgp;
213         int c, rcode = 0;
214 
215         if (s == 0)
216         {
217                 return rcode;
218         } else
219         {
220                 if (repeatp_checking_get())
221                         for (c = -1, l = lg; l; c--, l = l->next)       /* have we already had
222                                                                                                                                                                                                  * * this pointer? */
223                                 if (l->to == d)
224                                         break;
225                 /* else l defaults to new pointer */
226                 if (l)                                                                                  /* if we have */
227                 {
228                         /* mprintf("Repeat Item 0x%x %s\n",l->to,
229                          * tina_data_info_array[*(int*)l->to - ts_base_id].name); */
230                         lg = ref_addtostart(lg, l->to, c);      /* store an offset to
231                                                                                                                                                                          * * the prev ref */
232                         rcode = 0;                                                              /* return code to say don't process
233                                                                                                                                  * * this item further */
234                 } else
235                 {
236                         /* mprintf("New Item 0x%x %s\n",d,
237                          * tina_data_info_array[*(int*)d - ts_base_id].name); */
238                         lg = ref_addtostart(lg, d, s);  /* store the new one and
239                                                                                                                                                          * * the size */
240                         rcode = 1;                                                              /* ok to process this items contents */
241                 }
242                 count++;
243         }
244         *lgp = lg;
245         return rcode;
246 }
247 
248 
249 int serialise_tagged_item(List ** lgp, void *data, size_t s)
250 {
251         int rcode;
252 
253         if ((rcode = serialise_item(lgp, data, s)) == 1)
254         {
255                 char *ss =
256                                 tina_data_info_array[*(int *) data - ts_base_id].swap_string;
257                 Varptr d;
258 
259                 d.char_v = data;
260 
261                 d.int_v++;                                                                      /* skip over tag */
262                 *lgp = serialise_parse(*lgp, data, d, &ss);     /* serialise contents */
263         }
264         return rcode;
265 }
266 
267 
268 int serialise_tagged_sub_item(List ** lgp, void *data)
269 {
270         char *ss = tina_data_info_array[*(int *) data - ts_base_id].swap_string;
271         Varptr d;
272 
273         d.char_v = data;
274 
275         d.int_v++;                                                                              /* skip over tag */
276         *lgp = serialise_parse(*lgp, data, d, &ss);     /* serialise contents */
277         return 1;
278 }
279 
280 
281 List *ts_serialise(List * lg, void *data)
282 {
283         size_t s = tina_data_info_array[*(int *) data - ts_base_id].size;
284 
285         /* mprintf("Serialising a %s StructP <0x%x> with %s\n",
286          * tina_data_info_array[*(int*)data - ts_base_id].name, data,
287          * tina_data_info_array[*(int*)data - ts_base_id].swap_string); */
288         serialise_tagged_item(&lg, data, s);
289         return lg;
290 }
291 
292 
293 List *ts_serialise_gen(List * lg, void *d)
294 {
295         Sfunc s_func;
296         /* mprintf("ts_serialise_gen(0x%x,0x%x) count %d \n",lg,d,count); */
297         if (d)
298         {
299                 s_func =
300                                 (Sfunc) (tina_data_info_array[*(int *) d - ts_base_id].serialise);
301                 lg = s_func(lg, d);
302 /*  code rewritten for MVP compatability
303         lg = tina_data_info_array[*(int *) d - ts_base_id].serialise(
304         (struct list *)lg,
305         (void *) d);
306 */
307         }
308         return lg;
309 }
310 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.