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