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