]> andersk Git - moira.git/blob - gdb/gdb_stype.c
Be paranoid.
[moira.git] / gdb / gdb_stype.c
1 /*
2  *      $Source$
3  *      $Header$
4  */
5
6 #ifndef lint
7 static char *rcsid_gdb_stype_c = "$Header$";
8 #endif  lint
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 /************************************************************************/
31 /*      
32 /*                         gdb_stype.c
33 /*      
34 /*            GDB - System Data Type Definitions
35 /*      
36 /*      Author: Noah Mendelsohn
37 /*      Copyright: 1986 MIT Project Athena 
38 /*      
39 /*      This file initializes the definitions for all system defined
40 /*      data types, and it includes the type specific semantic routines
41 /*      for each of the system defined types.
42 /*      
43 /*      The initialization routine which adds these type definitions 
44 /*      to the type definition table is at the end of this source file.
45 /*      
46 /************************************************************************/
47 /*      
48 /*      This file is organized into one section for each system
49 /*      defined type followed at the end by a final section which
50 /*      initializes the type tables.  Each of the type specific
51 /*      sections does #defines for each type specific parameter.  The
52 /*      gdb_i_stype initialization routine at the end of this source
53 /*      file uses these defines to initialize the appropriate entry in
54 /*      the type definition tables.
55 /*      
56 /*      NOTE: some of the type definitions in this file may be machine
57 /*      dependent.
58 /*      
59 /************************************************************************/
60
61 #include <stdio.h>
62 #include <strings.h>
63 #include "gdb.h"
64 #ifdef vax                      /* XXX */
65         extern u_long ntohl(), htonl();
66 #endif vax
67 #include <netinet/in.h>                         /* for htonl routine */
68 \f
69 /************************************************************************/
70 /*      
71 /*                           INTEGER_T
72 /*      
73 /************************************************************************/
74
75 #define IN_LEN          (sizeof(int))
76 #define IN_ALI          IN_LEN
77 #define IN_NULL         g_in_null
78 #define IN_CDLEN        g_in_cdlen
79 #define IN_ENC          g_in_enc
80 #define IN_DEC          g_in_dec
81 #define IN_FORM         g_in_form
82 #define IN_NAME         "INTEGER_T"
83
84 #define IN_EXTERNSIZE 4                         /* length of an encoded */
85                                                 /* integer */
86         /*----------------------------------------------------------*/
87         /*      
88         /*                      g_in_null
89         /*      
90         /*      Fill in a null value for an integer.
91         /*      
92         /*----------------------------------------------------------*/
93
94 int
95 g_in_null(dp)
96 char *dp;                                       /* pointer to the data */
97 {
98         *((int *)dp) = 0;                       /* fill in a null value */
99 }
100
101         /*----------------------------------------------------------*/
102         /*      
103         /*                      g_in_cdlen
104         /*      
105         /*      Return coded length for an integer.  We're currently
106         /*      using the Berkeley 'htonl' routine which converts 
107         /*      an integer (actually a long, ahem!) to a canonical
108         /*      4 byte form.>
109         /*      
110         /*----------------------------------------------------------*/
111
112
113 int
114 g_in_cdlen(dp,hcon)
115 char *dp;                                       /* pointer to the data */
116 HALF_CONNECTION hcon;
117 {
118         return IN_EXTERNSIZE;
119 }
120
121         /*----------------------------------------------------------*/
122         /*      
123         /*                      g_in_enc
124         /*      
125         /*      Encode an integer for transmission
126         /*      
127         /*----------------------------------------------------------*/
128
129 int
130 g_in_enc(dp, hcon, outp)
131 char *dp;                                       /* pointer to data */
132 HALF_CONNECTION hcon;                           /* connection descriptor */
133 char *outp;                                     /* place to put the output */
134 {
135         register char *cp;                      /* next char in output */
136         register char *op = outp;
137         register char *endp = outp+IN_EXTERNSIZE;
138
139         unsigned long converted;                /* the integer goes here */
140                                                 /* in network byte order*/
141
142        /*
143         * Put it in network format, then copy one byte at a time to
144         * account for the fact that the RT has trouble with unaligned longs
145         */
146
147         converted = htonl(*(u_long *)dp);
148
149         cp = (char *)&converted;
150         *op++ = *cp++;
151         *op++ = *cp++;
152         *op++ = *cp++;
153         *op++ = *cp++;
154
155         return (int)(endp);                     /* return pointer to next */
156                                                 /* unused output byte*/
157 }
158
159         /*----------------------------------------------------------*/
160         /*      
161         /*                      g_in_dec
162         /*      
163         /*      Decode an integer from external form to local
164         /*      representation.
165         /*      
166         /*      
167         /*----------------------------------------------------------*/
168
169 int
170 g_in_dec(outp, hcon, inp)
171 char *inp;                                      /* pointer to data */
172 HALF_CONNECTION hcon;                           /* connection descriptor */
173 char *outp;                                     /* place to put the output */
174 {
175         register char *ip = inp;                /* next byte of input */
176         int buffer;
177         register char *bp;                      /* next byte in buffer */
178
179        /*
180         * Copy a byte at a time to buffer to account for RT difficulties
181         * with unaligned ints.
182         */
183         bp = (char *)&buffer;
184         *bp++ = *ip++;
185         *bp++ = *ip++;
186         *bp++ = *ip++;
187         *bp++ = *ip++;
188
189        /*
190         * Convert it and return pointer to next byte of input.
191         */
192
193         *(int *)outp = ntohl((u_long)buffer);
194         return (int)(ip);
195 }
196
197         /*----------------------------------------------------------*/
198         /*      
199         /*                      g_in_form
200         /*      
201         /*      Format an integer on output logging file for
202         /*      debugging.
203         /*      
204         /*----------------------------------------------------------*/
205
206 int
207 g_in_form(name, dp)
208 char *name;                                     /* string name of the field */
209 char *dp;                                       /* pointer to the data */
210 {
211         fprintf(gdb_log, "INTEGER_T\t%s=%d\n",name,(*(int *)dp));
212 }
213 \f
214 /************************************************************************/
215 /*      
216 /*                           STRING_T
217 /*      
218 /************************************************************************/
219
220 #define ST_LEN          (sizeof(STRING))
221 #define ST_ALI          (sizeof(int))
222 #define ST_NULL         g_st_null
223 #define ST_CDLEN        g_st_cdlen
224 #define ST_ENC          g_st_enc
225 #define ST_DEC          g_st_dec
226 #define ST_FORM         g_st_form
227 #define ST_NAME         "STRING_T"
228
229         /*----------------------------------------------------------*/
230         /*      
231         /*                      g_st_null
232         /*      
233         /*      Fill in a null value for a string.
234         /*      
235         /*----------------------------------------------------------*/
236 int
237 g_st_null(dp)
238 char *dp;                                       /* pointer to the data */
239 {
240         register STRING *stp = (STRING *)dp;    /* re-type as string */
241         STRING_DATA(*stp) = NULL;               /* no data */
242         MAX_STRING_SIZE(*stp) = 0;              /* for cleanliness */
243 }
244
245         /*----------------------------------------------------------*/
246         /*      
247         /*                      g_st_cdlen
248         /*      
249         /*      Return coded length for a string.  We have to send the
250         /*      actual length of the data along with the data itself.
251         /*      For this reason, we leave space for a coded integer
252         /*      in addition to the data bytes.  We actually call the
253         /*      integer coding routines to code the length.
254         /*      
255         /*      Note that a separate type understanding null termination
256         /*      might be an interesting optimization someday.
257         /*      
258         /*----------------------------------------------------------*/
259
260 int
261 g_st_cdlen(dp,hcon)
262 char *dp;                                       /* pointer to the data */
263 HALF_CONNECTION hcon;
264 {
265         register STRING *stp = (STRING *)dp;    /* re-type as string */
266
267         return (MAX_STRING_SIZE(*stp) + 
268                 g_in_cdlen((char *)&MAX_STRING_SIZE(*stp),hcon));
269 }
270
271         /*----------------------------------------------------------*/
272         /*      
273         /*                      g_st_enc
274         /*      
275         /*      Encode a string for transmission
276         /*      
277         /*----------------------------------------------------------*/
278
279 int
280 g_st_enc(dp, hcon, outp)
281 char *dp;                                       /* pointer to data */
282 HALF_CONNECTION hcon;                           /* connection descriptor */
283 char *outp;                                     /* place to put the output */
284 {
285         register STRING *stp = (STRING *)dp;    /* re-type as string */
286         int len;
287         register char *nextp;                   /* place to put next output */
288                                                 /* byte */
289        /*
290         * Use the integer coding routine to get the length encoded first
291         */
292
293         len = MAX_STRING_SIZE(*stp);            /* length of both source */
294                                                 /* and coded form*/
295         nextp = (char *)g_in_enc((char *)&len, hcon, outp);
296         
297        /*
298         * Now, copy the data itself after the encoded integer length
299         */
300         if (len > 0)
301                 bcopy(STRING_DATA(*stp), nextp, len);
302                                                 /* copy the data without */
303                                                 /* changing representation*/
304         return (int)(nextp+len);
305 }
306
307         /*----------------------------------------------------------*/
308         /*      
309         /*                      g_st_dec
310         /*      
311         /*      Decode a string from external form.  We always
312         /*      allocate new space for the string, intentionally
313         /*      ignoring any which may have been in use before.  If we
314         /*      freed it, we would not be robust against calls on
315         /*      uninitialized fields.  This may have nasty side
316         /*      effects if the intention was to leave 'gas' at the end
317         /*      of the string, but we want to accurately copy the
318         /*      data.  Note that string_free is robust against null
319         /*      pointers.
320         /*      
321         /*----------------------------------------------------------*/
322
323 int
324 g_st_dec(outp, hcon, inp)
325 char *inp;                                      /* pointer to input data */
326 HALF_CONNECTION hcon;                           /* connection descriptor */
327 char *outp;                                     /* place to put the output */
328 {
329         register STRING *stp = (STRING *)outp;  /* re-type as string */
330         int len;
331         register char *nextp;                   /* next byte to scan */
332        /*
333         * Use the integer coding routine to get the length encoded first
334         */
335
336         nextp = (char *)g_in_dec((char *)&len, hcon, inp);
337
338
339        /*
340         * Allocate memory for the string.  If length is 0, then null it
341         * out.  Note that we had considered freeing any existing strings
342         * which might be there, but this turns out to cause lots of
343         * trouble for the many callers who don't want to initialize before
344         * a decode.
345         */
346         if (len == 0) {
347                 STRING_DATA(*stp) = NULL;
348                 MAX_STRING_SIZE(*stp) = 0;
349                 return (int)(nextp);
350         }
351         (void) string_alloc(stp, len);          /* this sets string length */
352                                                 /* in addition to doing the */
353                                                 /* allocation */
354         
355        /*
356         * Now, copy the data itself 
357         */
358         bcopy(nextp, STRING_DATA(*stp), len);   /* copy the data without */
359                                                 /* changing representation*/
360         return (int)(nextp+len);
361 }
362
363         /*----------------------------------------------------------*/
364         /*      
365         /*                      g_st_form
366         /*      
367         /*      Format a string on output logging file for
368         /*      debugging.
369         /*      
370         /*----------------------------------------------------------*/
371
372 int
373 g_st_form(name, dp)
374 char *name;                                     /* string name of the field */
375 char *dp;                                       /* pointer to the data */
376 {
377         register STRING *stp = (STRING *)dp;    /* re-type as string */
378         int len;
379         register char *cp;                      /* next char to print */
380         register char *past_end;                /* 1st one not to print */
381
382         len = MAX_STRING_SIZE(*stp);
383         fprintf(gdb_log, "STRING_T\t%s[%d]=\"", name,len);
384         
385         if (len == 0 ) {
386                 fprintf(gdb_log, "\"\n");
387                 return;
388         }
389            
390
391         cp = STRING_DATA(*stp);
392         past_end = cp + len;
393
394         while (cp < past_end)
395                 (void) putc(*cp++, gdb_log);
396
397         fprintf(gdb_log,"\"\n");
398 }
399 \f
400 /************************************************************************/
401 /*      
402 /*                           REAL_T
403 /*      
404 /************************************************************************/
405
406 #define RL_LEN          (sizeof(double))
407 #define RL_ALI          RL_LEN
408 #define RL_NULL         g_rl_null
409 #define RL_CDLEN        g_rl_cdlen
410 #define RL_ENC          g_rl_enc
411 #define RL_DEC          g_rl_dec
412 #define RL_FORM         g_rl_form
413 #define RL_NAME         "REAL_T"
414
415 #define RL_EXTERNSIZE 32                        /* length of ascii coding */
416                                                 /* must change lengths in */
417                                                 /* encode and decode */
418                                                 /* routines to match*/
419         /*----------------------------------------------------------*/
420         /*      
421         /*                      g_rl_null
422         /*      
423         /*      Fill in a null value for an real.
424         /*      
425         /*----------------------------------------------------------*/
426 int
427 g_rl_null(dp)
428 char *dp;                                       /* pointer to the data */
429 {
430         *((double *)dp) = 0.0;                  /* fill in a null value */
431 }
432
433         /*----------------------------------------------------------*/
434         /*      
435         /*                      g_rl_cdlen
436         /*      
437         /*      Return coded length for an real.  For now, we just
438         /*      code as a 12 digit ASCII converted string.  Obviously,
439         /*      we can do much better in the future.
440         /*      
441         /*----------------------------------------------------------*/
442
443
444 int
445 g_rl_cdlen(dp,hcon)
446 char *dp;                                       /* pointer to the data */
447 HALF_CONNECTION hcon;
448 {
449         return RL_EXTERNSIZE;
450 }
451
452         /*----------------------------------------------------------*/
453         /*      
454         /*                      g_rl_enc
455         /*      
456         /*      Encode an real for transmission
457         /*      
458         /*----------------------------------------------------------*/
459
460 int
461 g_rl_enc(dp, hcon, outp)
462 char *dp;                                       /* pointer to data */
463 HALF_CONNECTION hcon;                           /* connection descriptor */
464 char *outp;                                     /* place to put the output */
465 {
466         register char *cp;                      /* next char in output */
467         register char *endp = outp+RL_EXTERNSIZE;
468
469        /*
470         * Convert the data into printable ASCII in the output stream
471         * Note that the width in the format below must be less than
472         * RL_EXTERNSIZE, because sprintf needs space for its terminating
473         * null.
474         */
475
476         (void) sprintf(outp,"%30le",*((double *)dp));
477
478        /*
479         * Sprintf produces output of unpredictable length, and with 
480         * a null termination.  Pad it out to the desired length.
481         */
482
483         cp = outp + strlen(outp);               /* find out where convertd */
484                                                 /* string stops*/
485         while (cp < endp)
486                 *cp++ = ' ';                    /* pad to desired length */
487
488         return (int)(outp+RL_EXTERNSIZE);       /* return pointer to next */
489                                                 /* unused output byte*/
490 }
491
492         /*----------------------------------------------------------*/
493         /*      
494         /*                      g_rl_dec
495         /*      
496         /*      Decode an real from external form
497         /*      
498         /*----------------------------------------------------------*/
499
500 int
501 g_rl_dec(outp, hcon, inp)
502 char *inp;                                      /* pointer to data */
503 HALF_CONNECTION hcon;                           /* connection descriptor */
504 char *outp;                                     /* place to put the output */
505 {
506         (void) sscanf(inp,"%30le", (double *)outp);
507         return (int)(inp+RL_EXTERNSIZE);
508 }
509
510         /*----------------------------------------------------------*/
511         /*      
512         /*                      g_rl_form
513         /*      
514         /*      Format an real on output logging file for
515         /*      debugging.
516         /*      
517         /*----------------------------------------------------------*/
518
519 int
520 g_rl_form(name, dp)
521 char *name;                                     /* string name of the field */
522 char *dp;                                       /* pointer to the data */
523 {
524         fprintf(gdb_log, "REAL_T\t\t%s=%le\n",name,*((double *)dp) );
525 }
526 \f
527 /************************************************************************/
528 /*      
529 /*                           DATE_T
530 /*      
531 /************************************************************************/
532
533 #define DT_LEN          25                      /* see ingres definition */
534 #define DT_ALI          1                       /* char data, need not align */
535 #define DT_NULL         g_dt_null
536 #define DT_CDLEN        g_dt_cdlen
537 #define DT_ENC          g_dt_enc
538 #define DT_DEC          g_dt_dec
539 #define DT_FORM         g_dt_form
540 #define DT_NAME         "DATE_T"
541
542 #define DT_EXTERNSIZE   DT_LEN                  /* length of ascii coding */
543                                                 /* must change lengths in */
544                                                 /* encode and decode */
545                                                 /* routines to match*/
546         /*----------------------------------------------------------*/
547         /*      
548         /*                      g_dt_null
549         /*      
550         /*      Fill in a null value for a date.
551         /*      
552         /*----------------------------------------------------------*/
553 int
554 g_dt_null(dp)
555 char *dp;                                       /* pointer to the data */
556 {
557         register char *cp = dp;                 /* next character to fill in */
558         register char *endp = dp + DT_LEN;
559
560        /*
561         * Fill the field with character blanks
562         */
563         while (cp < endp)
564                 *cp++ = ' ';
565 }
566
567         /*----------------------------------------------------------*/
568         /*      
569         /*                      g_dt_cdlen
570         /*      
571         /*      Return coded length for an date.  For now, we just
572         /*      code as a 25 digit ASCII converted string.
573         /*      
574         /*----------------------------------------------------------*/
575
576
577 int
578 g_dt_cdlen(dp,hcon)
579 char *dp;                                       /* pointer to the data */
580 HALF_CONNECTION hcon;
581 {
582         return DT_EXTERNSIZE;
583 }
584
585         /*----------------------------------------------------------*/
586         /*      
587         /*                      g_dt_enc
588         /*      
589         /*      Encode a date for transmission
590         /*      
591         /*----------------------------------------------------------*/
592
593 int
594 g_dt_enc(dp, hcon, outp)
595 char *dp;                                       /* pointer to data */
596 HALF_CONNECTION hcon;                           /* connection descriptor */
597 char *outp;                                     /* place to put the output */
598 {
599         register char *ip = dp;                 /* next char in input */
600         register char *op = outp;               /* next char in output */
601         register char *endp = op+DT_EXTERNSIZE;
602
603        /*
604         * Copy the input untransformed to the output 
605         */
606
607         while (op < endp)
608                 *op++ = *ip++;                  /* pad to desired length */
609
610         return (int)(endp);                     /* return pointer to next */
611                                                 /* unused output byte*/
612 }
613
614         /*----------------------------------------------------------*/
615         /*      
616         /*                      g_dt_dec
617         /*      
618         /*      Decode an date from external form
619         /*      
620         /*----------------------------------------------------------*/
621
622 int
623 g_dt_dec(outp, hcon, inp)
624 char *inp;                                      /* pointer to data */
625 HALF_CONNECTION hcon;                           /* connection descriptor */
626 char *outp;                                     /* place to put the output */
627 {
628         register char *ip = inp;                /* next char in input */
629         register char *op = outp;               /* next char in output */
630         register char *endp = op+DT_EXTERNSIZE;
631
632        /*
633         * Copy the input untransformed to the output 
634         */
635
636         while (op < endp)
637                 *op++ = *ip++;                  /* pad to desired length */
638
639         return (int)(endp);                     /* return pointer to next */
640                                                 /* unused output byte*/
641 }
642
643         /*----------------------------------------------------------*/
644         /*      
645         /*                      g_dt_form
646         /*      
647         /*      Format a date on output logging file for
648         /*      debugging.
649         /*      
650         /*----------------------------------------------------------*/
651
652 int
653 g_dt_form(name, dp)
654 char *name;                                     /* string name of the field */
655 char *dp;                                       /* pointer to the data */
656 {
657         char buf[DT_EXTERNSIZE+1];
658
659         bcopy(dp, buf, DT_EXTERNSIZE);          /* copy date to buffer */
660         buf[DT_EXTERNSIZE] = '\0';              /* null terminate it */
661         fprintf(gdb_log, "DATE_T\t\t%s=%s\n",name,buf);
662 }
663 \f
664 /************************************************************************/
665 /*      
666 /*                           TUPLE_DESCRIPTOR_T
667 /*      
668 /*      The external representation of a tuple descriptor will be to
669 /*      send the count of the number of fields, and then a one byte
670 /*      signed integer describing each type followed by all the
671 /*      corresponding null terminated strings.  The tuple descriptor
672 /*      will really get re-created wth proper offsets and lengths upon
673 /*      receipt by the create_tuple_descriptor operation.
674 /*      
675 /************************************************************************/
676
677 #define TPD_LEN         (sizeof(TUPLE_DESCRIPTOR))
678 #define TPD_ALI         (sizeof(TUPLE_DESCRIPTOR))
679 #define TPD_NULL        g_tpd_null
680 #define TPD_CDLEN       g_tpd_cdlen
681 #define TPD_ENC         g_tpd_enc
682 #define TPD_DEC         g_tpd_dec
683 #define TPD_FORM        g_tpd_form
684 #define TPD_NAME        "TUPLE_DESCRIPTOR_T"
685
686         /*----------------------------------------------------------*/
687         /*      
688         /*                      g_tpd_null
689         /*      
690         /*      Fill in a null value for a tuple_descriptor.
691         /*      
692         /*----------------------------------------------------------*/
693 int
694 g_tpd_null(dp)
695 char *dp;                                       /* pointer to the data */
696 {
697         register TUPLE_DESCRIPTOR *tdp = (TUPLE_DESCRIPTOR *)dp; 
698                                                 /* re-type as */
699                                                 /* tuple_descriptor */
700         (*tdp) = NULL;                          /* no data */
701 }
702
703         /*----------------------------------------------------------*/
704         /*      
705         /*                      g_tpd_cdlen
706         /*      
707         /*      Return coded length for a tuple_descriptor.  
708         /*      
709         /*----------------------------------------------------------*/
710
711 int
712 g_tpd_cdlen(dp,hcon)
713 char *dp;                                       /* pointer to the data */
714 HALF_CONNECTION hcon;
715 {
716         register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);      
717                                                 /* re-type as */
718                                                 /* tuple_descriptor */
719         register int coded_len;                 /* the value we're trying */
720                                                 /* to compute */
721
722        /*
723         * Validate the descriptor
724         */
725         if (tdp == NULL)
726                 GDB_GIVEUP("g_tpd_cdlen (coded length) was given a null tuple descriptor\nthis may be due to an attempt to transmit invalid data")
727         GDB_CHECK_TPD(tdp,"g_tpd_cdlen: compute coded length of tuple descriptor")
728
729         coded_len = g_in_cdlen((char *)&(tdp->field_count),hcon);
730                                                 /* we're going to send */
731                                                 /* the field count as a */
732                                                 /* true integer*/
733
734         coded_len += tdp->str_len + tdp->field_count;
735                                                 /* space for all the */
736                                                 /* strings, with nulls, */
737                                                 /* and for the one byte */
738                                                 /* types*/
739
740         return coded_len;
741                 
742 }
743
744         /*----------------------------------------------------------*/
745         /*      
746         /*                      g_tpd_enc
747         /*      
748         /*      Encode a tuple_descriptor for transmission
749         /*      
750         /*----------------------------------------------------------*/
751
752 int
753 g_tpd_enc(dp, hcon, outp)
754 char *dp;                                       /* pointer to data */
755 HALF_CONNECTION hcon;                           /* connection descriptor */
756 char *outp;                                     /* place to put the output */
757 {
758         register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);
759                                                 /* re-type as */
760                                                 /* tuple_descriptor */
761         register char *nextp;                   /* place to put next output */
762                                                 /* byte */
763         register int i;                         /* a loop counter  */
764
765        /*
766         * Validate the descriptor
767         */
768         if (tdp == NULL)
769                 GDB_GIVEUP("g_tpd_enc (encode) was given a null tuple descriptor\nthis may be due to an attempt to transmit invalid data")
770         GDB_CHECK_TPD(tdp,"g_tpd_enc: encode tuple descriptor")
771
772        /*
773         * Use the integer coding routine to send the number of fields first
774         */
775                                                 /* and coded form*/
776         nextp = (char *)g_in_enc((char *)&(tdp->field_count), hcon, outp);
777
778        /*
779         * Next, put in the one byte codes for each of the field types
780         */
781
782         for (i=0; i<tdp->field_count; i++) {
783                 *nextp++ = tdp->var[i].type & 0xff; /* put out the one byte */
784                                                    /* type codes */
785         }
786
787        /*
788         * Finally, copy all the null terminated strings.
789         */
790         bcopy(((char *)(tdp))+gdb_descriptor_length(tdp->field_count), 
791               nextp, tdp->str_len);             /* copy the string data all */
792                                                 /* at once */
793         return (int)(nextp+tdp->str_len);
794 }
795
796         /*----------------------------------------------------------*/
797         /*      
798         /*                      g_tpd_dec
799         /*      
800         /*      Decode a tuple_descriptor from external form.  For
801         /*      safety in memory management, we always re-allocate the
802         /*      space for the tuple_descriptor. If the pointer passed
803         /*      to us is not null, then we assume that it points to a
804         /*      legal tuple descriptor, which we first free.  Because
805         /*      data representation may change, we must re-do the
806         /*      create-tuple-descriptor, so it can determine the local
807         /*      machine dependent representation and alignment rules
808         /*      for the data.
809         /*      
810         /*----------------------------------------------------------*/
811
812 #define GDB_MAX_DECODED_FIELDS 100
813
814 int
815 g_tpd_dec(outp, hcon, inp)
816 char *inp;                                      /* pointer to input data */
817 HALF_CONNECTION hcon;                           /* connection descriptor */
818 char *outp;                                     /* place to put the output */
819 {
820         register TUPLE_DESCRIPTOR *tdp = (TUPLE_DESCRIPTOR *)outp;      
821                                                 /* re-type as */
822                                                 /* tuple_descriptor */
823         int field_count;                        /* number of fields in the */
824                                                 /* newly received descriptor*/
825         register int i;                         /* a loop counter */
826
827         register int tmp;                       /* working variable to hold */
828                                                 /* type while they're being */
829                                                 /* sign extended */
830         char *nextt;                            /* next byte to scan for */
831                                                 /* a type code byte*/
832         char *nextn;                            /* next byte to scan for */
833                                                 /* a string name */
834         char *field_names[GDB_MAX_DECODED_FIELDS];
835                                                 /* put pointers to the */
836                                                 /* field names here */
837         FIELD_TYPE field_types[GDB_MAX_DECODED_FIELDS];
838                                                 /* put the field types in */
839                                                 /* the array here*/
840        /*
841         * Use the integer coding routine to get the number of fields
842         */
843
844         nextt = (char *)g_in_dec((char *)&field_count, hcon, inp);
845         if (field_count > GDB_MAX_DECODED_FIELDS)
846                 GDB_GIVEUP("g_tpd_dec: Trying to decode tuple descriptor with too many fields.\n")
847
848
849        /*
850         * For each field, pick up its type code, being sure to sign extend,
851         * and a pointer to its string name.
852         */
853         nextn = nextt + field_count;            /* there is one byte of */
854                                                 /* type info for each field, */
855                                                 /* after that comes the */
856                                                 /* first string.  nextn */
857                                                 /* now points to the first */
858                                                 /* string */
859         for (i=0; i<field_count; i++) {
860                 tmp = *nextt++;                 /* type code, may need */
861                                                 /* sign extension */
862                 if (tmp & 0x80)
863                         tmp |= ((~0) ^ 0xff);   /* sign extend if needed */
864                                                 /* this is the most machine */
865                                                 /* independent sign extension */
866                                                 /* I could come up with. */
867                                                 /* Presumes char is one byte, */
868                                                 /* but makes no assumption */
869                                                 /* about sizeof(int) */
870                 field_types[i] = tmp;
871                 field_names[i] = nextn;         /* pointer to name of the */
872                                                 /* field */
873                 nextn += strlen(nextn) +1;      /* set up for possible name */
874                                                 /* to follow */
875         }
876
877        /*
878         * In case there was already a tuple descriptor here, free it.
879         */
880
881         delete_tuple_descriptor(*tdp);
882
883        /*
884         * Create a new descriptor based on the information we have received.
885         */
886         *tdp = create_tuple_descriptor(field_count, field_names, field_types);
887
888         return (int)nextn;
889 }
890
891         /*----------------------------------------------------------*/
892         /*      
893         /*                      g_tpd_form
894         /*      
895         /*      Format a tuple_descriptor on output logging file for
896         /*      debugging.
897         /*      
898         /*----------------------------------------------------------*/
899
900 int
901 g_tpd_form(name, dp)
902 char *name;                                     /* tuple_descriptor name of the field */
903 char *dp;                                       /* pointer to the data */
904 {
905         register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);      
906                                                 /* re-type as */
907                                                 /* tuple_descriptor */
908         register int i;                         /* loop variable through */
909                                                 /* field definitions */
910
911
912        /*
913         *  Handle the special case where the descriptor is null
914         */
915         if (tdp == NULL) {
916                 fprintf(gdb_log, "TUPLE_DESCRIPTOR %s (loc=NULL)\n", name);
917                 return;
918         }
919
920        /*
921         * Validate the descriptor
922         */
923         GDB_CHECK_TPD(tdp,"g_tpd_form: format tuple descriptor")
924
925        /*
926         * Descriptor is not null
927         */
928         fprintf(gdb_log, "TUPLE_DESCRIPTOR %s (loc=0x%x)\n", name, tdp);
929
930         for (i=0; i<tdp->field_count; i++) {
931                 fprintf(gdb_log,"\tField Type Code = %3d %20s\tField Name=%s\n" ,
932                         tdp->var[i].type, 
933                         STR_PROPERTY(tdp->var[i].type,NAME_PROPERTY),
934                         tdp->var[i].name);
935         }
936         fprintf(gdb_log,"\n");
937 }
938 \f
939 /************************************************************************/
940 /*      
941 /*                           TUPLE_T
942 /*      
943 /*      There is a distinction between the type tuple_t and the
944 /*      type tuple_data_t.  Tuple_t is a complete self-contained
945 /*      tuple, with its descriptor.  It actually refers to the
946 /*      tuple variable itself, which is a pointer.  Tuple_data 
947 /*      is only the data portion of the tuple, not the descriptor.
948 /*      It is used when the receiving tuple is already allocated,
949 /*      with a correct descriptor, for sending just the data.
950 /*      
951 /*      Note that some of the routines for tuple_t could have been
952 /*      implemented in terms of tuple_data_t routines.  For the
953 /*      moment, they have not been, but that may later be changed.
954 /*      Doesn't seem to make much difference as long as they are
955 /*      short and simple, and this way does save a bit of overhead.
956 /*      
957 /************************************************************************/
958
959 #define TP_LEN          (sizeof(TUPLE))
960 #define TP_ALI          TP_LEN
961 #define TP_NULL         g_tp_null
962 #define TP_CDLEN        g_tp_cdlen
963 #define TP_ENC          g_tp_enc
964 #define TP_DEC          g_tp_dec
965 #define TP_FORM         g_tp_form
966 #define TP_NAME         "TUPLE_T"
967
968         /*----------------------------------------------------------*/
969         /*      
970         /*                      g_tp_null
971         /*      
972         /*      Fill in a null value for a tuple.
973         /*      
974         /*----------------------------------------------------------*/
975 int
976 g_tp_null(dp)
977 char *dp;                                       /* pointer to the data */
978 {
979         *((TUPLE *)dp) = NULL;
980 }
981
982         /*----------------------------------------------------------*/
983         /*      
984         /*                      g_tp_cdlen
985         /*      
986         /*      Return coded length for a tuple.  We have to send the
987         /*      descriptor along with the data itself.  We do this
988         /*      with calls to the appropriate encodeing routines.
989         /*      
990         /*----------------------------------------------------------*/
991
992 int
993 g_tp_cdlen(dp,hcon)
994 char *dp;                                       /* pointer to the data */
995 HALF_CONNECTION hcon;
996 {
997         register TUPLE tup = *((TUPLE *)dp);    /* deref as tuple */
998         register int len;                       /* accumulated length */
999         register int i;                         /* index to fields */
1000         TUPLE_DESCRIPTOR tpd;                   /* descriptor for this tuple */
1001
1002        /*
1003         * Validate the tuple
1004         */
1005         if (tup == NULL)
1006                 GDB_GIVEUP("g_tp_cdlen (coded length) was given a null tuple\nthis may be due to an attempt to transmit invalid data")
1007         GDB_CHECK_TUP(tup,"g_tp_cdlen: compute coded length of tuple")
1008
1009        /*
1010         * First, get length of the descriptor when coded.
1011         */
1012
1013         tpd = DESCRIPTOR_FROM_TUPLE(tup);
1014         len = g_tpd_cdlen((char *)&tpd,hcon);
1015
1016        /*
1017         * Now, for each field, add in its coded length
1018         */
1019         
1020         for (i=0; i<tpd->field_count; i++) {
1021                 len += (int)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1022                                     CODED_LENGTH_PROPERTY)
1023                            (FIELD_FROM_TUPLE(tup, i),hcon);
1024         }
1025         
1026         return len;
1027 }
1028
1029         /*----------------------------------------------------------*/
1030         /*      
1031         /*                      g_tp_enc
1032         /*      
1033         /*      Encode a tuple for transmission
1034         /*      
1035         /*----------------------------------------------------------*/
1036
1037 int
1038 g_tp_enc(dp, hcon, outp)
1039 char *dp;                                       /* pointer to data */
1040 HALF_CONNECTION hcon;                           /* connection descriptor */
1041 char *outp;                                     /* place to put the output */
1042 {
1043         register TUPLE tup = *((TUPLE *)dp);    /* deref as tuple */
1044         register int i;                         /* index to fields */
1045         TUPLE_DESCRIPTOR tpd;                   /* descriptor for this tuple */
1046         char *op;                               /* next byte of output */
1047
1048        /*
1049         * Validate the tuple
1050         */
1051         if (tup == NULL)
1052                 GDB_GIVEUP("g_tp_enc (encode) was given a null tuple\nthis may be due to an attempt to transmit invalid data")
1053         GDB_CHECK_TUP(tup,"g_tp_enc: encode tuple")
1054
1055        /*
1056         * First, get the tuple descriptor and encode it
1057         */
1058
1059         tpd = DESCRIPTOR_FROM_TUPLE(tup);
1060         op = (char *)g_tpd_enc((char *)&tpd, hcon, outp);
1061
1062        /*
1063         * Now, for each field, code it
1064         */
1065         
1066         for (i=0; i<tpd->field_count; i++) {
1067                 op = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1068                                     ENCODE_PROPERTY)
1069                            (FIELD_FROM_TUPLE(tup, i),hcon, op);
1070         }
1071         
1072         return (int)op;
1073 }
1074
1075         /*----------------------------------------------------------*/
1076         /*      
1077         /*                      g_tp_dec
1078         /*      
1079         /*      Decode a tuple from external form.  For safety
1080         /*      in memory management, we always re-allocate the
1081         /*      space for the tuple, so the lengths come out right.
1082         /*      This may have nasty side effects if the intention
1083         /*      was to leave 'gas' at the end of the tuple, but
1084         /*      we want to accurately copy the data.  Note that
1085         /*      tuple_free is robust against null pointers.
1086         /*      
1087         /*----------------------------------------------------------*/
1088
1089 int
1090 g_tp_dec(outp, hcon, inp)
1091 char *inp;                                      /* pointer to input data */
1092 HALF_CONNECTION hcon;                           /* connection descriptor */
1093 char *outp;                                     /* place to put the output */
1094 {
1095         register TUPLE tup;                     /* the new tuple */
1096         register int i;                         /* index to fields */
1097         TUPLE_DESCRIPTOR tpd;                   /* descriptor for this tuple */
1098         char *ip;                               /* next byte of input */
1099
1100        /*
1101         * First, get the tuple descriptor and decode it
1102         */
1103
1104         tpd = NULL;                             /* so decode will know */
1105                                                 /* there's no existing one */
1106                                                 /* to free */
1107         ip = (char *)g_tpd_dec((char *)&tpd, hcon, inp);
1108
1109        /*
1110         * Now make an empty tuple based on the descriptor
1111         */
1112
1113         tup = create_tuple(tpd);
1114
1115        /*
1116         * The tuple descriptor has a reference count of 2 here, one 
1117         * from the tpd_dec routine, and one from the create_tuple.
1118         * Since we don't expect to explicitly undo the two separately,
1119         * we decrement the count here.
1120         */
1121
1122         UNREFERENCE_TUPLE_DESCRIPTOR(tpd);      /* decr. the reference count */
1123
1124        /*
1125         * Now, for each field, decode it.
1126         */
1127         
1128         for (i=0; i<tpd->field_count; i++) {
1129                 ip = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1130                                     DECODE_PROPERTY)
1131                            (FIELD_FROM_TUPLE(tup, i),hcon, ip);
1132         }
1133         
1134         *((TUPLE *)outp) = tup;                 /* put the new tuple */
1135                                                 /* pointer where the */
1136                                                 /* caller wants it */
1137         return (int)ip;
1138 }
1139
1140         /*----------------------------------------------------------*/
1141         /*      
1142         /*                      g_tp_form
1143         /*      
1144         /*      Format a tuple on output logging file for
1145         /*      debugging.
1146         /*      
1147         /*----------------------------------------------------------*/
1148
1149 int
1150 g_tp_form(name, dp)
1151 char *name;                                     /* tuple name of the field */
1152 char *dp;                                       /* pointer to the data */
1153 {
1154         register TUPLE tup = *((TUPLE *)dp);    /* deref as tuple */
1155         register int i;                         /* index to fields */
1156         TUPLE_DESCRIPTOR tpd;                   /* descriptor for this tuple */
1157
1158
1159        /*
1160         * Handle special case where tuple is null
1161         */
1162
1163         if (tup==NULL) {
1164                 fprintf(gdb_log,"\nTUPLE Name=%s is NULL\n---------------------------\n",name);
1165                 return;
1166         }
1167
1168         GDB_CHECK_TUP(tup,"g_tp_form: format tuple")
1169        /*
1170         * Get the descriptor--for now, we won't print it 
1171         */
1172         tpd = DESCRIPTOR_FROM_TUPLE(tup);
1173
1174        /*
1175         * Print a header
1176         */
1177
1178         fprintf(gdb_log,"\nTUPLE at address: 0x%x Name=%s\n---------------------------\n",tup,name);
1179
1180        /*
1181         * Now, for each field, print it
1182         */
1183         
1184         for (i=0; i<tpd->field_count; i++) {
1185                 FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1186                                     FORMAT_PROPERTY)
1187                            (tpd->var[i].name,FIELD_FROM_TUPLE(tup, i));
1188         }
1189         
1190         fprintf(gdb_log,"END_OF_TUPLE\n");
1191 }
1192 \f
1193 /************************************************************************/
1194 /*      
1195 /*                           TUPLE_DATA_T
1196 /*      
1197 /*      The distinction between tuple_data_t and tuple_t is a
1198 /*      subtle one.  Tuple_t is used when a single tuple is to
1199 /*      be decoded, outside of any larger context.  It (re)allocates
1200 /*      memory for both the tuple itself and its descriptor.
1201 /*      
1202 /*      Tuple_data is used in the case where the tuple and its
1203 /*      descriptor are already allocated, but only the data is 
1204 /*      to be received.  This is useful in cases like receiving an
1205 /*      entire relation, in which the descriptor is common to 
1206 /*      all the tuples, and should not be resent or reallocated
1207 /*      with each one.  Receive relation can send the tuple descriptor
1208 /*      once, then do a create_tuple followed by a decode tuple_data
1209 /*      to receive the tuple field data into the existing tuple.
1210 /*      
1211 /*      Note that the definition of null is different in the two cases.
1212 /*      The null value for a tuple is just a null pointer.  The null
1213 /*      for tuple data is to null each of the fields in the tuple
1214 /*      recursively.  The routines in this section may dereference
1215 /*      null pointers if the tuples they are passed are null.  Note
1216 /*      also that there is one less level of indirection in passing
1217 /*      data to these routines than to those of tuple_t.  
1218 /*      
1219 /*      Note  also that the null and decode routines supplied here
1220 /*      presume that any fields with dependent memory (e.g. string_t
1221 /*      fields have already been cleaned up.)
1222 /*      
1223 /*      Note that this is not quite a kosher type, in the sense that
1224 /*      it's length is not fixed.  The entry for length below 
1225 /*      is meaningless, because the real length is computed from the
1226 /*      desc.  Among other things, this means that TUPLEs cannot
1227 /*      contain fields of this type.
1228 /*      
1229 /************************************************************************/
1230
1231 #define TDT_LEN         (sizeof(TUPLE))
1232 #define TDT_ALI         TDT_LEN
1233 #define TDT_NULL        g_tdt_null
1234 #define TDT_CDLEN       g_tdt_cdlen
1235 #define TDT_ENC         g_tdt_enc
1236 #define TDT_DEC         g_tdt_dec
1237 #define TDT_FORM        g_tdt_form
1238 #define TDT_NAME        "TUPLE_DATA_T"
1239
1240         /*----------------------------------------------------------*/
1241         /*      
1242         /*                      g_tdt_null
1243         /*      
1244         /*      Fill in a null value for a tuple.
1245         /*      
1246         /*----------------------------------------------------------*/
1247 int
1248 g_tdt_null(dp)
1249 char *dp;                                       /* pointer to the data */
1250 {
1251         TUPLE tup = (TUPLE)dp;                  /* dp is of type TUPLE, */
1252                                                 /* which is actually */
1253                                                 /* a pointer to the */
1254                                                 /* tuple data */
1255         TUPLE_DESCRIPTOR tpd;                   /* the descriptor for this */
1256                                                 /* tuple*/
1257         register int i;                         /* a loop counter */
1258
1259        /*
1260         * For each field in the tuple, call its null routine
1261         */
1262         tup->id = GDB_TUP_ID;
1263
1264         tpd = DESCRIPTOR_FROM_TUPLE(tup);
1265
1266         for (i=0; i<tpd->field_count; i++) {
1267                 FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),NULL_PROPERTY)
1268                     (FIELD_FROM_TUPLE(tup,i));
1269         }
1270 }
1271
1272         /*----------------------------------------------------------*/
1273         /*      
1274         /*                      g_tdt_cdlen
1275         /*      
1276         /*      Return coded length for tuple data.  Since the descriptor
1277         /*      for the tuple is known at both sides, we send only
1278         /*      the coded fields, not even the field counts.
1279         /*      
1280         /*----------------------------------------------------------*/
1281
1282 int
1283 g_tdt_cdlen(dp,hcon)
1284 char *dp;                                       /* pointer to the data */
1285 HALF_CONNECTION hcon;
1286 {
1287         register TUPLE tup = (TUPLE)dp;         /* arg typed as tuple */
1288         register int len;                       /* accumulated length */
1289         register int i;                         /* index to fields */
1290         TUPLE_DESCRIPTOR tpd;                   /* descriptor for this tuple */
1291
1292        /*
1293         * Validate the tuple data
1294         */
1295         if (tup == NULL)
1296                 GDB_GIVEUP("g_tdt_cdlen (coded length) was given null tuple data\nthis may be due to an attempt to transmit invalid data")
1297         GDB_CHECK_TUP(tup,"g_tdt_cdlen: compute coded length of tuple data")
1298        /*
1299         * First, find the tuple descriptor and set initial coded len to 0
1300         */
1301
1302         tpd = DESCRIPTOR_FROM_TUPLE(tup);
1303         len = 0;
1304
1305        /*
1306         * Now, for each field, add in its coded length
1307         */
1308         
1309         for (i=0; i<tpd->field_count; i++) {
1310                 len += (int)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1311                                     CODED_LENGTH_PROPERTY)
1312                            (FIELD_FROM_TUPLE(tup, i),hcon);
1313         }
1314         
1315         return len;
1316 }
1317
1318         /*----------------------------------------------------------*/
1319         /*      
1320         /*                      g_tdt_enc
1321         /*      
1322         /*      Encode tuple data for transmission.
1323         /*      
1324         /*----------------------------------------------------------*/
1325
1326 int
1327 g_tdt_enc(dp, hcon, outp)
1328 char *dp;                                       /* pointer to data */
1329 HALF_CONNECTION hcon;                           /* connection descriptor */
1330 char *outp;                                     /* place to put the output */
1331 {
1332         register TUPLE tup = (TUPLE)dp;         /* type as tuple */
1333         register int i;                         /* index to fields */
1334         TUPLE_DESCRIPTOR tpd;                   /* descriptor for this tuple */
1335         char *op = outp;                        /* next byte of output */
1336
1337        /*
1338         * Validate the tuple data
1339         */
1340         if (tup == NULL)
1341                 GDB_GIVEUP("g_tdt_enc (encode) was given null tuple data\nthis may be due to an attempt to transmit invalid data")
1342         GDB_CHECK_TUP(tup,"g_tdt_enc: encode of tuple data")
1343        /*
1344         * First, get the tuple descriptor 
1345         */
1346
1347         tpd = DESCRIPTOR_FROM_TUPLE(tup);
1348
1349        /*
1350         * Now, for each field, code it
1351         */
1352         
1353         for (i=0; i<tpd->field_count; i++) {
1354                 op = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1355                                     ENCODE_PROPERTY)
1356                            (FIELD_FROM_TUPLE(tup, i),hcon, op);
1357         }
1358         
1359         return (int)op;
1360 }
1361
1362         /*----------------------------------------------------------*/
1363         /*      
1364         /*                      g_tdt_dec
1365         /*      
1366         /*      Decode tuple data from external form.  We presume
1367         /*      that the tuple itself is allocated, and the descriptor
1368         /*      properly set up for the local machine representation.
1369         /*      Here we just decode the fields.
1370         /*      
1371         /*----------------------------------------------------------*/
1372
1373 int
1374 g_tdt_dec(outp, hcon, inp)
1375 char *inp;                                      /* pointer to input data */
1376 HALF_CONNECTION hcon;                           /* connection descriptor */
1377 char *outp;                                     /* place to put the output */
1378 {
1379         register TUPLE tup = (TUPLE)outp;       /* the filled in tuple */
1380         register int i;                         /* index to fields */
1381         TUPLE_DESCRIPTOR tpd;                   /* descriptor for this tuple */
1382         char *ip = inp;                         /* next byte of input */
1383
1384        /*
1385         * Validate the tuple data
1386         */
1387         if (tup == NULL)
1388                 GDB_GIVEUP("g_tdt_dec (decode) was given null tuple data\nthis may be due to an attempt to transmit invalid data")
1389         GDB_CHECK_TUP(tup,"g_tdt_dec: decode of tuple data")
1390        /*
1391         * First, get the tuple descriptor 
1392         */
1393
1394         tpd = DESCRIPTOR_FROM_TUPLE(tup);
1395
1396        /*
1397         * Now, for each field, decode it.
1398         */
1399         
1400         for (i=0; i<tpd->field_count; i++) {
1401                 ip = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1402                                     DECODE_PROPERTY)
1403                            (FIELD_FROM_TUPLE(tup, i),hcon, ip);
1404         }
1405         
1406         return (int)ip;
1407 }
1408
1409         /*----------------------------------------------------------*/
1410         /*      
1411         /*                      g_tdt_form
1412         /*      
1413         /*      Format tuple data on output logging file for
1414         /*      debugging.
1415         /*      
1416         /*----------------------------------------------------------*/
1417
1418 int
1419 g_tdt_form(name, dp)
1420 char *name;                                     /* tuple name of the field */
1421 char *dp;                                       /* pointer to the data */
1422 {
1423         register TUPLE tup = (TUPLE)dp;         /* as tuple */
1424         register int i;                         /* index to fields */
1425         TUPLE_DESCRIPTOR tpd;                   /* descriptor for this tuple */
1426
1427
1428        /*
1429         * Handle special case where we're given a null address for the 
1430         * tuple
1431         */
1432         if (tup==NULL) {
1433                 fprintf(gdb_log,"\nTUPLE Name=%s is NULL\n---------------------------\n",name);
1434                 return;
1435         }
1436
1437
1438        /*
1439         * Validate the tuple data
1440         */
1441         GDB_CHECK_TUP(tup,"g_tdt_form: format tuple data")
1442        /*
1443         * Get the descriptor--for now, we won't print it 
1444         */
1445         tpd = DESCRIPTOR_FROM_TUPLE(tup);
1446
1447        /*
1448         * Print a header
1449         */
1450
1451         fprintf(gdb_log,"\nTUPLE at address: 0x%x  Name=%s\n---------------------------\n",tup,name);
1452
1453        /*
1454         * Now, for each field, print it
1455         */
1456         
1457         for (i=0; i<tpd->field_count; i++) {
1458                 FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1459                                     FORMAT_PROPERTY)
1460                            (tpd->var[i].name,FIELD_FROM_TUPLE(tup, i));
1461         }
1462         
1463         fprintf(gdb_log,"END_OF_TUPLE\n");
1464 }
1465 \f
1466 /************************************************************************/
1467 /*      
1468 /*                           RELATION_T
1469 /*      
1470 /*      Relations consist of link lists of tuples, all of which are
1471 /*      presumed to share a tuple descriptor.  For transmission, 
1472 /*      these are encoded as follows:
1473 /*      
1474 /*      1) A count of the number of tuples, sent as a properly coded
1475 /*         integer.
1476 /*      
1477 /*      2) The tuple descriptor itself, encoded by its encoding routine.
1478 /*      
1479 /*      3) For each tuple, its tuple data, encoded using the routines
1480 /*         of the tuple_data_t type.
1481 /*      
1482 /************************************************************************/
1483
1484 #define REL_LEN         (sizeof(RELATION))
1485 #define REL_ALI         REL_LEN
1486 #define REL_NULL        g_rel_null
1487 #define REL_CDLEN       g_rel_cdlen
1488 #define REL_ENC         g_rel_enc
1489 #define REL_DEC         g_rel_dec
1490 #define REL_FORM        g_rel_form
1491 #define REL_NAME        "RELATION_T"
1492
1493
1494         /*----------------------------------------------------------*/
1495         /*      
1496         /*                      g_rel_null
1497         /*      
1498         /*      Fill in a null value for a relation.  Maybe we should
1499         /*      check for an existing relation and properly free it,
1500         /*      but for now, we don't.
1501         /*      
1502         /*----------------------------------------------------------*/
1503 int
1504 g_rel_null(dp)
1505 char *dp;                                       /* pointer to the data */
1506 {
1507         *((RELATION *)dp) = NULL;
1508 }
1509
1510         /*----------------------------------------------------------*/
1511         /*      
1512         /*                      g_rel_cdlen
1513         /*      
1514         /*      Return coded length for a relation.  
1515         /*      
1516         /*----------------------------------------------------------*/
1517
1518 int
1519 g_rel_cdlen(dp,hcon)
1520 char *dp;                                       /* pointer to the data */
1521 HALF_CONNECTION hcon;
1522 {
1523         register RELATION rel = *((RELATION *)dp); /* deref as relation */
1524         int  len;                               /* accumulated length */
1525         register TUPLE t;                       /* index to a tuple */
1526         int tuple_count = 0;                    /* number of tuples in this */
1527                                                 /* relation*/
1528         TUPLE_DESCRIPTOR tpd;                   /* descriptor for this */
1529                                                 /* relation */
1530
1531        /*
1532         * Validate the relation
1533         */
1534         if (rel == NULL)
1535                 GDB_GIVEUP("g_rel_cdlen (coded  length) was given null relation\nthis may be due to an attempt to transmit invalid data")
1536         GDB_CHECK_REL(rel,"g_rel_cdlen: compute coded length of relation")
1537        /*
1538         * First, get the tuple descriptor for this relation
1539         */
1540
1541         tpd = DESCRIPTOR_FROM_RELATION(rel);
1542
1543        /*
1544         * Count the number of tuples in the relation
1545         */
1546         for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL; 
1547              t = NEXT_TUPLE_IN_RELATION(rel,t))
1548                 tuple_count++;
1549        /*
1550         * Start with the coded length for the tuple count and the
1551         * descriptor, which are sent first.
1552         */
1553
1554         len = g_in_cdlen((char *)&tuple_count, hcon);   /* length of tuple_count */
1555                                                 /* in coded form */
1556         len += g_tpd_cdlen((char *)&tpd, hcon);
1557
1558        /*
1559         * Now, for each tuple, add in its coded length
1560         */
1561         
1562         for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL; 
1563              t = NEXT_TUPLE_IN_RELATION(rel,t))
1564                 len += g_tdt_cdlen((char *)t, hcon);
1565         
1566         return len;
1567 }
1568
1569         /*----------------------------------------------------------*/
1570         /*      
1571         /*                      g_rel_enc
1572         /*      
1573         /*      Encode a relation for transmission
1574         /*      
1575         /*----------------------------------------------------------*/
1576
1577 int
1578 g_rel_enc(dp, hcon, outp)
1579 char *dp;                                       /* pointer to data */
1580 HALF_CONNECTION hcon;                           /* connection descriptor */
1581 char *outp;                                     /* place to put the output */
1582 {
1583         register RELATION rel = *((RELATION *)dp); /* deref as relation */
1584         char *op;                               /* pointer to next unused */
1585                                                 /* output byte*/
1586         register TUPLE t;                       /* index to a tuple */
1587         int tuple_count = 0;                    /* number of tuples in this */
1588                                                 /* relation*/
1589         TUPLE_DESCRIPTOR tpd;                   /* descriptor for this */
1590                                                 /* relation */
1591
1592        /*
1593         * Validate the relation
1594         */
1595         if (rel == NULL)
1596                 GDB_GIVEUP("g_rel_enc (encode) was given null relation\nthis may be due to an attempt to transmit invalid data")
1597         GDB_CHECK_REL(rel,"g_rel_enc: encode relation")
1598
1599        /*
1600         * First, get the tuple descriptor for this relation
1601         */
1602
1603         tpd = DESCRIPTOR_FROM_RELATION(rel);
1604
1605        /*
1606         * Count the number of tuples in the relation
1607         */
1608         for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL; 
1609              t = NEXT_TUPLE_IN_RELATION(rel,t))
1610                 tuple_count++;
1611        /*
1612         * Encode the count and the tuple descriptor for this relation
1613         */
1614
1615         op = (char *)g_in_enc((char *)&tuple_count, hcon,outp); 
1616                                                 /* length of tuple_count */
1617                                                 /* in coded form */
1618         op = (char *)g_tpd_enc((char *)&tpd, hcon,op);
1619
1620        /*
1621         * Now, encode each tuple
1622         */
1623         
1624         for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL; 
1625              t = NEXT_TUPLE_IN_RELATION(rel,t))
1626                 op = (char *)g_tdt_enc((char *)t, hcon, op);
1627         
1628         return (int)op;
1629 }
1630
1631         /*----------------------------------------------------------*/
1632         /*      
1633         /*                      g_rel_dec
1634         /*      
1635         /*      Decode a relation from external form.  We should 
1636         /*      really check to make sure the relation we are given
1637         /*      is null, and if not, call delete_relation on it 
1638         /*      first.  For the moment, we just presume it's null.
1639         /*      
1640         /*      We proceed by decoding the integer count and the
1641         /*      tuple descriptor, from which we create the null
1642         /*      relation.  We then loop for each tuple, doing a
1643         /*      create, a decode, and an add to relation.
1644         /*      
1645         /*----------------------------------------------------------*/
1646
1647 int
1648 g_rel_dec(outp, hcon, inp)
1649 char *inp;                                      /* pointer to input data */
1650 HALF_CONNECTION hcon;                           /* connection descriptor */
1651 char *outp;                                     /* place to put the output */
1652 {
1653         register RELATION rel;                  /* build the relation here */
1654         char *ip;                               /* pointer to next unused */
1655                                                 /* input byte*/
1656         register TUPLE t;                       /* index to a tuple */
1657         register int i;                         /* loop counter on tuples */
1658         int tuple_count = 0;                    /* number of tuples in this */
1659                                                 /* relation*/
1660         TUPLE_DESCRIPTOR tpd;                   /* descriptor for this */
1661                                                 /* relation */
1662
1663        /*
1664         * First, get the field count and tuple descriptor for this relation
1665         */
1666
1667         ip = (char *)g_in_dec((char *)&tuple_count, hcon, inp);
1668
1669         tpd = NULL;                             /* so decode will know */
1670                                                 /* there's no existing one */
1671                                                 /* to free */
1672         ip = (char *)g_tpd_dec((char *)&tpd, hcon, ip);
1673
1674        /*
1675         * Now, create a null relation using the descriptor
1676         */
1677         
1678         rel = create_relation(tpd);
1679
1680        /*
1681         * The reference count for the tuple descriptor is currently 2, 
1682         * one from the tpd_dec and one from the create relation.  Since
1683         * these will not be undone separately, we decrement the reference
1684         * count to 1
1685         */
1686
1687         UNREFERENCE_TUPLE_DESCRIPTOR(tpd);
1688
1689        /*
1690         * For each tuple, create it, receive it, add it to the relation
1691         */
1692         
1693         for (i=0; i<tuple_count; i++) {
1694                 t = create_tuple(tpd);
1695                 ip = (char *)g_tdt_dec((char *)t, hcon, ip);
1696                 ADD_TUPLE_TO_RELATION(rel, t);          
1697         }
1698
1699        /*
1700         * Now store the address of the created relation where requested
1701         * and return pointer to next available input byte.
1702         */
1703
1704         *((RELATION *)outp) = rel;
1705
1706         return (int)ip;
1707 }
1708
1709         /*----------------------------------------------------------*/
1710         /*      
1711         /*                      g_rel_form
1712         /*      
1713         /*      Format a relation on output logging file for
1714         /*      debugging.
1715         /*      
1716         /*----------------------------------------------------------*/
1717
1718 int
1719 g_rel_form(name, dp)
1720 char *name;                                     /* relation name of the field */
1721 char *dp;                                       /* pointer to the data */
1722 {
1723         register RELATION rel = *((RELATION *)dp); /* deref as relation */
1724         register TUPLE t;
1725         int count =0;
1726         char buffer[50];
1727
1728        /*
1729         * Handle special case where relation is null
1730         */
1731
1732         if (rel == NULL) {
1733                 fprintf(gdb_log,"\nRELATION Name=%s is NULL\n===========================\n",name);
1734                 return;
1735         }
1736
1737         GDB_CHECK_REL(rel,"g_rel_form: format relation")
1738
1739        /*
1740         * Print a header
1741         */
1742
1743         fprintf(gdb_log,"\nRELATION at address: 0x%x Name=%s\n===========================\n",rel,name);
1744
1745        /*
1746         * Now, for each field, print it
1747         */
1748         
1749         for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL; 
1750              t = NEXT_TUPLE_IN_RELATION(rel,t)){
1751                 (void) sprintf(buffer,"Number %d",++count);
1752                 g_tdt_form(buffer,(char *)t);
1753         }
1754         
1755         fprintf(gdb_log,"END_OF_RELATION\n");
1756 }
1757 \f
1758 /************************************************************************/
1759 /*      
1760 /*         DECLARE AND INITIALIZE THE SYSTEM TYPE DEFINITION 
1761 /*                             TABLES
1762 /*      
1763 /*      This representation is clearly a real pain to keep up to date
1764 /*      properly, mostly because C has such a lousy pre-processor.
1765 /*      Probably this should be re-arranged so an initialization routine
1766 /*      is called to set up the tables, but even that might be a nuissance.
1767 /*      
1768 /************************************************************************/
1769
1770         /*----------------------------------------------------------*/
1771         /*      
1772         /*                      gdb_i_stype
1773         /*      
1774         /*      Called at startup to initialize the type table with
1775         /*      the entries for the system types.
1776         /*      
1777         /*----------------------------------------------------------*/
1778
1779 #define ITYPE(inx,lp,ap,np,clp,ep,dp,fp,name) {\
1780         g_type_table[inx][LENGTH_PROPERTY].i = lp; \
1781         g_type_table[inx][ALIGNMENT_PROPERTY].i = ap; \
1782         g_type_table[inx][NULL_PROPERTY].f = np; \
1783         g_type_table[inx][CODED_LENGTH_PROPERTY].f = clp; \
1784         g_type_table[inx][ENCODE_PROPERTY].f = ep; \
1785         g_type_table[inx][DECODE_PROPERTY].f = dp; \
1786         g_type_table[inx][FORMAT_PROPERTY].f = fp; \
1787         g_type_table[inx][NAME_PROPERTY].cp = name; \
1788 }
1789
1790 int
1791 gdb_i_stype()
1792 {
1793         gdb_n_types = SYSTEM_TYPE_COUNT;
1794
1795         ITYPE(INTEGER_T,IN_LEN,IN_ALI,IN_NULL,IN_CDLEN,IN_ENC,IN_DEC,IN_FORM,
1796               IN_NAME)
1797         ITYPE(STRING_T,ST_LEN,ST_ALI,ST_NULL,ST_CDLEN,ST_ENC,ST_DEC,ST_FORM,
1798               ST_NAME)
1799         ITYPE(REAL_T,RL_LEN,RL_ALI,RL_NULL,RL_CDLEN,RL_ENC,RL_DEC,RL_FORM,
1800               RL_NAME)
1801         ITYPE(DATE_T,DT_LEN,DT_ALI,DT_NULL,DT_CDLEN,DT_ENC,DT_DEC,DT_FORM,
1802               DT_NAME)
1803         ITYPE(TUPLE_DESCRIPTOR_T,TPD_LEN,TPD_ALI,TPD_NULL,TPD_CDLEN,TPD_ENC,
1804               TPD_DEC,TPD_FORM,TPD_NAME)
1805         ITYPE(TUPLE_T,TP_LEN,TP_ALI,TP_NULL,TP_CDLEN,TP_ENC,TP_DEC,TP_FORM,
1806               TP_NAME)
1807         ITYPE(TUPLE_DATA_T,TDT_LEN,TDT_ALI,TDT_NULL,TDT_CDLEN,TDT_ENC,TDT_DEC,
1808               TDT_FORM,TDT_NAME)
1809         ITYPE(RELATION_T,REL_LEN,REL_ALI,REL_NULL,REL_CDLEN,REL_ENC,REL_DEC,
1810               REL_FORM,REL_NAME)
1811 }
This page took 0.24019 seconds and 5 git commands to generate.