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