]> andersk Git - moira.git/blob - gdb/tst.c
Case-insensitive stuff.
[moira.git] / gdb / tst.c
1 /*
2  *      $Source$
3  *      $Header$
4  */
5
6 #ifndef lint
7 static char *rcsid_tst_c = "$Header$";
8 #endif  lint
9
10 /************************************************************************/
11 /*      
12 /*                              tst.c
13 /*      
14 /*      A test program for the client library interface.
15 /*      
16 /*      Author: Noah Mendelsohn
17 /*      
18 /*      Copyright: 1986 MIT Project Athena
19 /*      
20 /************************************************************************/
21
22 #include <stdio.h>
23 #include "gdb.h"
24
25 char *field_names[] = {"desc",  
26                        "code",
27                        "man",
28                        "cost",
29                        "count"};
30 FIELD_TYPE field_types[] = {STRING_T,       /* desc */
31                             INTEGER_T,      /* code */
32                             STRING_T,       /* man */
33                             REAL_T,         /* cost */
34                             INTEGER_T};     /* count */
35
36 FILE *coded_file;
37
38 int
39 main(argc, argv)
40 int     argc;
41 char    *argv[];
42 {
43
44 \f       /************************************************************
45          *                  DECLARATIONS                            *
46          ************************************************************/
47
48         /*
49          * Declare the names of fields to be retrieved and their types
50          */
51
52         int  field_count = 5;
53         int i;
54         /*
55          * The following defines are for convenience in addressing
56          * the fields.
57          */
58
59 #define DESC  0
60 #define CODE  1
61 #define MAN   2
62 #define COST  3
63 #define COUNT 4
64
65         /*
66          * Declare the relation and related data structures for
67          * storing the retrieved data.
68          */
69
70         TUPLE_DESCRIPTOR tuple_desc;
71         RELATION retrieved_data, decoded_rel;
72
73         /*
74          * Declarations for misc. variables
75          */
76         
77         TUPLE   t;                      /* next tuple to print */
78         int coded_len;
79         char *coded_dat;
80
81         int     rc;                     /* A return code */     
82
83 \f       /************************************************************
84          *             EXECUTION BEGINS HERE                        *
85          ************************************************************/
86
87         /*
88          * Build the descriptor describing the layout of the tuples
89          * to be retrieved, and create an empty relation into which
90          * the retrieval will be done.
91          */
92
93         gdb_init();                             /* initialize the global */
94                                                 /* database facility */
95
96         printf("tst.c: attempting to create tuple descriptor\n");       
97
98         tuple_desc = create_tuple_descriptor(field_count, field_names,
99                                              field_types);
100
101         printf("tst.c: tuple desc created.. attempting to create relation\n");
102         retrieved_data = create_relation(tuple_desc);
103
104         printf("tst.c: relation created, formatting descriptor\n");
105
106
107         print_tuple_descriptor("Test Tuple Descriptor", tuple_desc);
108
109         printf("tst.c: descriptor formatted, formatting relation\n");
110
111         print_relation("Test Relation", retrieved_data);
112
113         printf("Creating tuples\n");
114
115         for (i=0; i<3; i++) {
116                 t = create_tuple(tuple_desc);
117                 
118                 initialize_tuple(t);
119
120                 fprintf(stderr, "Following tuple should contain null fields:\n\n");
121
122                 print_tuple("A NULL TUPLE", t);
123
124                 *(int *)FIELD_FROM_TUPLE(t, CODE) = i+1;
125
126                 *(double *)FIELD_FROM_TUPLE(t, COST) = 12.34 * (i+1);
127                 string_alloc((STRING *)FIELD_FROM_TUPLE(t,MAN), 20);
128                 strcpy(STRING_DATA(*((STRING *)FIELD_FROM_TUPLE(t,MAN))),
129                        "Manager field data");
130                 ADD_TUPLE_TO_RELATION(retrieved_data, t);               
131         }
132
133
134         printf("tst.c: relation initialized, formatting relation\n");
135
136         print_relation("Test Relation", retrieved_data);
137
138
139 /*
140  *  Try to encode the entire relation!!
141  */
142
143         printf("Attempting to encode the relation\n");
144
145         coded_len = FCN_PROPERTY(RELATION_T, CODED_LENGTH_PROPERTY)
146               (&retrieved_data, NULL);
147
148         coded_dat = (char *)malloc(coded_len);
149
150         FCN_PROPERTY(RELATION_T, ENCODE_PROPERTY)
151           (&retrieved_data, NULL, coded_dat);
152
153         printf("Relation encoding complete, writing file \n\n");
154
155         coded_file = fopen("coded.dat", "w");
156
157         fwrite(coded_dat, 1, coded_len, coded_file);
158
159         fclose(coded_file);
160
161         printf("File written\n");
162
163         printf("Decoding relation\n\n");
164
165         FCN_PROPERTY(RELATION_T, DECODE_PROPERTY)
166           (&decoded_rel, NULL, coded_dat);
167
168         printf("Relation decoded!!  Printing it\n\n");
169
170         print_relation("Decoded Relation", decoded_rel);
171
172
173         printf("tst.c: exit\n");
174
175         return 0;
176 }
This page took 0.058521 seconds and 5 git commands to generate.