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

Linux Cross Reference
Tina5/tina-libs/tina/file/fileTs_print.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_print.c,v $
 37  * Date    :  $Date: 2005/01/23 19:10:21 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: fileTs_print.c,v 1.4 2005/01/23 19:10:21 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes :
 44  *
 45  *********
 46 */
 47 
 48 #include "fileTs_print.h"
 49 
 50 #if HAVE_CONFIG_H
 51   #include <config.h>
 52 #endif
 53 
 54 #include <stdio.h>
 55 #include <stdlib.h>
 56 #include <stdarg.h>
 57 #include <string.h>
 58 #include <tina/sys/sysDef.h>
 59 #include <tina/sys/sysPro.h>
 60 #include <tina/file/file_TsDef.h>
 61 #include <tina/file/fileTs_free.h>
 62 
 63 
 64 #define SUBSTRUCT_ALIGNMENT 4
 65 #define ALIGN_VARPTR(start,here,size) \
 66 { \
 67    int tab=(int)((here).char_v-(char*)(start))%(size);\
 68     (here).char_v+=tab?(size)-tab:0;\
 69    }
 70 
 71 static char *typefromcode(char c)
 72 {
 73         switch (c)
 74         {
 75                 case 'b':
 76                         return "byte";
 77                 case 'c':
 78                         return "char";
 79                 case 'f':
 80                         return "float";
 81                 case 'l':
 82                         return "long";
 83                 case 'w':
 84                 case 'i':
 85                         return "int";
 86                 case 'o':
 87                         return "unsigned long";
 88                 case 'p':
 89                         return "POINTER *";
 90                 case 'u':
 91                         return "unsigned int";
 92                 case 'h':
 93                         return "short";
 94                 case 'k':
 95                         return "unsigned short";
 96                 case 'g':
 97                         return "double";
 98                 case 'e':
 99                         return "long double";
100                 case 's':
101                         return "char *";
102                 case '.':
103                         return "WOOPS";
104                 default:
105                         return NULL;
106         }
107 }
108 
109 static void print_parse(void *data, Varptr dp, char **ss)
110 {
111         char *s = *ss;
112         int repeats = 0, exiting = 0;
113         static Varptr d, nulld;                 /* static data! */
114         static int arrayp = 0;                  /* static data! */
115         static char *last_name = NULL;  /* static data! */
116         void *memcpy();
117 
118         nulld.char_v = NULL;
119         if (dp.char_v)
120                 d = dp;                                                                                 /* if dp is null use static version d */
121         /* else use new value */
122         while (*s && !exiting)
123         {
124                 if (!arrayp)
125                 {
126                         char *t = typefromcode(*s);
127 
128                         if (t)
129                                 mprintf("%s ", t);
130                 }
131                 switch (*s++)
132                 {
133                         case '':
134                                 repeats *= 10;
135                                 break;
136                         case '1':
137                         case '2':
138                         case '3':
139                         case '4':
140                         case '5':
141                         case '6':
142                         case '7':
143                         case '8':
144                         case '9':
145                                 repeats *= 10;
146                                 repeats += *(s - 1) - 48;
147                                 break;
148                         case '[':
149                                 if (last_name)
150                                 {
151                                         mprintf("%s <%s>[ ", typefromcode(*s), last_name);
152                                         last_name = NULL;
153                                 } else
154                                         mprintf("%s[ ", typefromcode(*s));
155                                 arrayp = 1;
156                                 {
157                                         char *temp_s = s;
158 
159                                         while (repeats-- > 0)
160                                         {
161                                                 temp_s = s;
162                                                 print_parse(data, nulld, &temp_s);
163                                         }
164                                         arrayp = 0;
165                                         mprintf("];");
166                                         s = temp_s;                                             /* the rest of the swap string */
167                                         repeats = 0;
168                                 }
169                                 break;
170                         case '(':                                                               /* start of a repetition */
171                         {
172                                 char *temp_s = s;
173 
174                                 while (repeats-- > 0)
175                                 {
176                                         temp_s = s;
177                                         print_parse(data, nulld, &temp_s);
178                                 }
179                                 s = temp_s;                                                     /* the rest of the swap string */
180                                 repeats = 0;
181                         }
182                                 break;
183                         case ']':
184                         case ')':
185                                 exiting = 1;
186                                 break;
187                         case '/':
188                         {
189                                 static char name[256];                          /* static data! */
190                                 char *end = strchr(s, '/');
191 
192                                 memcpy(name, s, end - s);
193                                 name[end - s] = 0;
194                                 last_name = name;
195                                 s = end + 1;
196                         }
197                                 break;
198                         default:
199                         {
200                                 if (last_name && *(s - 1) != 't')
201                                 {
202                                         mprintf("<%s>", last_name);
203                                         last_name = NULL;
204                                 }
205                                 do
206                                 {
207                                         switch (*(s - 1))
208                                         {
209                                                 case 'f':
210                                                 case 'l':
211                                                 case 'i':
212                                                 case 'o':
213                                                 case 'u':
214                                                 case 'p':
215                                                 case 's':
216                                                 case ',':
217                                                 case '.':
218                                                 case 'w':
219                                                         ALIGN_VARPTR(data, d, 4);
220                                                         break;
221                                                 case 'h':
222                                                 case 'k':
223                                                         ALIGN_VARPTR(data, d, 2);
224                                                         break;
225                                                 case 'e':
226                                                 case 'g':
227                                                         ALIGN_VARPTR(data, d, 8);
228                                                         break;
229                                                 case 't':
230                                                         ALIGN_VARPTR(data, d, SUBSTRUCT_ALIGNMENT);
231                                                         break;
232                                         }
233                                         switch (*(s - 1))
234                                         {
235                                                 case 'b':
236                                                         mprintf("0x%x,", *d.char_v++);
237                                                         break;
238                                                 case 'c':
239                                                         mprintf("%c", *d.uchar_v++);
240                                                         break;
241                                                 case 'f':
242                                                         mprintf("%g,", *d.float_v++);
243                                                         break;
244                                                 case 'l':
245                                                         mprintf("%li,", *d.int_v++);
246                                                         break;
247                                                 case 'w':
248                                                         mprintf("0x%x,", *d.int_v++);
249                                                         break;
250                                                 case 'i':
251                                                         mprintf("%d,", *d.int_v++);
252                                                         break;
253                                                 case 'o':
254                                                         mprintf("%lu,", *d.uint_v++);
255                                                         break;
256                                                 case '.':
257                                                         mprintf("Invalid data code;");
258                                                 case ',':
259                                                         d.uint_v++;
260                                                         break;
261                                                 case 'u':
262                                                         mprintf("%u,", *d.uint_v++);
263                                                         break;
264                                                 case 'h':
265                                                         mprintf("%hi,", *d.short_v++);
266                                                         break;
267                                                 case 'k':
268                                                         mprintf("%hu,", *d.ushort_v++);
269                                                         break;
270                                                 case 'e':
271                                                 case 'g':
272                                                         mprintf("%g,", *d.double_v++);
273                                                         break;
274                                                         /* case 'e': mprintf("%le, ",*d.l_double_v++);
275                                                          * NO LONG */
276                                                         /* DOUBLES */
277                                                         break;
278                                                 case 'p':                                       /* pointer types */
279                                                         if (*d.ptr_v)                   /* if not a null pointer ,
280                                                                                                                                  * * print_by_tag */
281                                                         {
282                                                                 Varptr td = d;  /* keep d pointer */
283 
284                                                                 mprintf("0x%x", *d.ptr_v);
285                                                                 ts_print_gen(*d.ptr_v);
286                                                                 d = td;                                 /* recover d pointer */
287                                                         } else
288                                                                 mprintf("NULL,");
289                                                         d.ptr_v++;
290                                                         break;
291                                                 case 's':                                       /* string */
292                                                         if (*d.ptr_v)                   /* if not a null pointer print
293                                                                                                                                  * * string */
294                                                                 mprintf("\"%s\",", (char *) *d.ptr_v);
295                                                         else
296                                                                 mprintf("\"\",");
297                                                         d.ptr_v++;
298                                                         break;
299                                                 case 't':                                       /* tagged struct */
300                                                 {
301                                                         char *s =
302                                                                         tina_data_info_array[*d.int_v - ts_base_id].swap_string;
303                                                         char *name =
304                                                                         tina_data_info_array[*d.int_v - ts_base_id].name;
305 
306                                                         if (last_name)
307                                                                 mprintf("struct %s <%s>{", name, last_name);
308                                                         else
309                                                                 mprintf("struct %s {", name);
310                                                         last_name = NULL;
311                                                         d.int_v++;                              /* skip tag */
312                                                         print_parse((void *) (d.int_v - 1), nulld, &s); /* carry d pointer on */
313                                                         mprintf("}%s;", name);
314                                                 }
315                                                         break;
316 
317                                         }
318                                 }
319                                 while (--repeats > 0);
320                                 repeats = 0;
321                         }
322                                 break;
323                 }
324         }
325         *ss = s;
326 }
327 
328 /* Take a data pointer. Identify the structures type, get it's swap
329  * string from the global table. Parse the swap string, printing
330  * various data types. Types 'p'and 't'  recursively descend the data
331  * tree. We must also align to short and long word boundaries relative
332  * to the start of the structure */
333 void ts_print(void *data)
334 {
335         char *s = tina_data_info_array[*(int *) data - ts_base_id].swap_string;
336         char *name = tina_data_info_array[*(int *) data - ts_base_id].name;
337         Varptr d;
338 
339         d.int_v = data;
340         d.int_v++;                                                                              /* skip over tag */
341         mprintf("struct %s {", name);
342         print_parse(data, d, &s);
343         mprintf("} %s;", name);
344 }
345 
346 void ts_print_gen(void *data)
347 {
348         static int calls = 0;                                   /* count recursive levels */            /* static data! */
349 
350         if (data)
351         {
352                 calls++;
353                 if (repeatp_checker(data))      /* new pointer? */
354                         tina_data_info_array[*(int *) data - ts_base_id].print(data);
355                 else
356                         mprintf("RPT struct %s;",
357                                                         tina_data_info_array[*(int *) data - ts_base_id].name);
358                 calls--;
359                 if (!calls)
360                         repeatp_checker(NULL);          /* reset check list */
361         } else
362                 mprintf("NULL,");
363 }
364 

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