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

Linux Cross Reference
Tina4/src/sys/gen/tsprint.c

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

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

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