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

Linux Cross Reference
Tina6/tina-libs/tina/file/fileTs_deserialise.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_deserialise.c,v $
 37  * Date    :  $Date: 2005/01/09 17:49:25 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: fileTs_deserialise.c,v 1.4 2005/01/09 17:49:25 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes :
 44  *
 45  *********
 46 */
 47 
 48 #include "fileTs_deserialise.h"
 49 
 50 #if HAVE_CONFIG_H
 51   #include <config.h>
 52 #endif
 53 
 54 #include <stdio.h>
 55 #include <stdlib.h>
 56 #include <string.h>
 57 #include <tina/sys/sysDef.h>
 58 #include <tina/sys/sysPro.h>
 59 #include <tina/file/file_TsDef.h>
 60 
 61 
 62 #define SUBSTRUCT_ALIGNMENT 4
 63 #define ALIGN_VARPTR(start,here,size) \
 64 { \
 65    int tab=(int)((here).char_v-(char*)(start))%(size);\
 66    (here).char_v+=tab?(size)-tab:0;\
 67    }
 68 
 69 List *ts_deserialise_gen(List * lg, void **data);
 70 int deserialise_item(List ** lgp, void **data);
 71 
 72 List *deserialise_parse(List * lg, void *data, Varptr dp, char **ss)
 73 {
 74         char *s = *ss;
 75         static Varptr d, nulld;         /* static data! */
 76         int repeats = 0, exiting = 0;
 77 
 78         nulld.char_v = NULL;
 79         if (dp.char_v)
 80                 d = dp;                                                                                 /* if dp is null use static version d */
 81         /* else use new value */
 82 
 83         while (*s && !exiting)
 84         {
 85                 switch (*s++)
 86                 {
 87                         case '':
 88                                 repeats *= 10;
 89                                 break;
 90                         case '1':
 91                         case '2':
 92                         case '3':
 93                         case '4':
 94                         case '5':
 95                         case '6':
 96                         case '7':
 97                         case '8':
 98                         case '9':
 99                                 repeats *= 10;
100                                 repeats += *(s - 1) - 48;
101                                 break;
102                         case '[':
103                         case '(':                                                               /* start of a repetition */
104                         {
105                                 char *temp_s = s;
106 
107                                 while (repeats-- > 0)
108                                 {
109                                         s = temp_s;
110                                         lg = deserialise_parse(lg, data, nulld, &s);
111                                 }
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                                                         word_swap(d.char_v);
146                                                         d.int_v++;
147                                                         break;
148                                                 case 'p':
149                                                 case 's':
150                                                         ALIGN_VARPTR(data, d, 4);
151                                                         word_swap(d.char_v);
152                                                         break;
153                                                 case 'h':
154                                                 case 'k':
155                                                         ALIGN_VARPTR(data, d, 2);
156                                                         short_swap(d.char_v);
157                                                         d.short_v++;
158                                                         break;
159                                                 case 'e':
160                                                 case 'g':
161                                                         ALIGN_VARPTR(data, d, 8);
162                                                         long_swap(d.char_v);
163                                                         d.double_v++;
164                                                         break;
165                                                 case 't':
166                                                         ALIGN_VARPTR(data, d, SUBSTRUCT_ALIGNMENT);
167                                                         break;
168                                         }
169                                         switch (*(s - 1))
170                                         {
171                                                 case 'p':
172                                                         if (*d.ptr_v)                   /* was there data here */
173                                                         {
174                                                                 Varptr td = d;  /* keep d pointer */
175 
176                                                                 lg = ts_deserialise_gen(lg, d.ptr_v);   /* recurse */
177                                                                 d = td;
178                                                         }
179                                                         d.ptr_v++;
180                                                         break;
181                                                 case 's':
182                                                         if (*d.ptr_v)                   /* was there data here */
183                                                                 deserialise_item(&lg, d.ptr_v);
184                                                         d.ptr_v++;
185                                                         break;
186                                                 case 't':
187                                                         deserialise_tagged_sub_item(&lg, d.int_v);
188                                                         break;
189                                         }
190                                 }
191                                 while (--repeats > 0);
192                                 repeats = 0;
193                         }
194                                 break;
195                 }
196         }
197         *ss = s;
198         return lg;
199 }
200 
201 
202 
203 int deserialise_item(List ** lgp, void **data)
204 {
205         int rcode = 0;
206         List *lg = *lgp;
207 
208         if (!lg)                                                                                        /* end of lg list (shouldn't happen) */
209         {
210                 *data = NULL;
211                 rcode = -1;
212         } else if (lg->type < 0)                        /* duplicate pointer */
213         {
214                 /* mprintf("Getting Repeat Item 0x%x %s\n",lg->to,
215                  * tina_data_info_array[*(int*)lg->to - ts_base_id].name); */
216                 *data = lg->to;
217                 lg = lg->next;
218                 rcode = 0;
219         } else if (lg->to)                                              /* normal case */
220         {
221                 /* mprintf("Getting New Item 0x%x %s\n",lg->to,
222                  * tina_data_info_array[*(int*)lg->to - ts_base_id].name); */
223                 *data = lg->to;
224                 lg = lg->next;
225                 rcode = 1;
226         } else
227         {
228                 /* null pointer */
229 /* data = NULL; *//* otherwise give nothing and skip */
230                 lg = lg->next;
231         }
232 
233         *lgp = lg;
234         return rcode;
235 }
236 
237 
238 
239 int deserialise_tagged_item(List ** lgp, void **data)
240 {
241         int rcode = 0;
242         List *lg;
243         char *ss;
244 
245         if ((rcode = deserialise_item(lgp, data)) == 1)
246         {
247                 Varptr d;
248 
249                 d.char_v = *data;
250 
251                 lg = *lgp;
252                 word_swap((char *) d.int_v);    /* swap tag field of struct */
253                 /* mprintf("Deserialising a %s struct\n",
254                  * tina_data_info_array[*(int*)*data - ts_base_id].name); */
255                 ss = tina_data_info_array[*d.int_v - ts_base_id].swap_string;
256                 d.int_v++;                                                                      /* skip over tag */
257                 lg = deserialise_parse(lg, *data, d, &ss);
258                 *lgp = lg;
259         }
260         return rcode;
261 }
262 
263 
264 int deserialise_tagged_sub_item(List ** lgp, void *data)
265 {
266         char *ss;
267         Varptr d;
268 
269         d.char_v = data;
270 
271         word_swap((char *) d.int_v);    /* swap tag field of struct */
272         /* mprintf("Deserialising a %s sub-struct\n",
273          * tina_data_info_array[*(int*)data - ts_base_id].name); */
274         ss = tina_data_info_array[*(int *) data - ts_base_id].swap_string;
275         d.int_v++;                                                                              /* skip over tag */
276         *lgp = deserialise_parse(*lgp, data, d, &ss);
277 
278         return 1;
279 }
280 
281 
282 List *ts_deserialise(List * lg, void **data)
283 {
284         if (lg)
285                 deserialise_tagged_item(&lg, data);
286         return lg;
287 }
288 
289 
290 List *ts_deserialise_gen(List * lg, void **data)
291 {
292         Dfunc d_func;
293         /* mprintf("ts_serialise_gen(0x%x,0x%x) \n",lg,data); */
294         if (lg)
295         {
296                 Ts_id tag = *(int *) (lg->to);  /* use copy because real
297                                                                                                                                                  * * one */
298 
299                 if (lg->type > 0)                                               /* if not duplicate pointer */
300                         word_swap((char *) &tag);       /* will be swapped later     */
301 /* rewritten for MVP compatability
302         lg = tina_data_info_array[tag - ts_base_id].deserialise(lg, data);
303 */
304                 d_func = (Dfunc) (tina_data_info_array[tag - ts_base_id].deserialise);
305                 lg = d_func(lg, data);
306         }
307         return lg;
308 }
309 

~ [ 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.