1111
1212struct assignment * assignments ;
1313
14- void push_assignment (char * var ,char * value )
14+ void push_assignment (char * var , char * value )
1515{
16- struct assignment * new = (struct assignment * )mm_alloc (sizeof (struct assignment ));
16+ struct assignment * new = (struct assignment * )mm_alloc (sizeof (struct assignment ));
1717
18- new -> next = assignments ;
19- new -> variable = mm_alloc (strlen (var )+ 1 );
18+ new -> next = assignments ;
19+ new -> variable = mm_alloc (strlen (var )+ 1 );
2020 strcpy (new -> variable ,var );
21- new -> value = mm_alloc (strlen (value )+ 1 );
21+ new -> value = mm_alloc (strlen (value )+ 1 );
2222 strcpy (new -> value ,value );
23- assignments = new ;
23+ assignments = new ;
2424}
2525
2626static void
2727drop_assignments (void )
28- { while (assignments )
29- { struct assignment * old_head = assignments ;
28+ {
29+ while (assignments )
30+ {
31+ struct assignment * old_head = assignments ;
3032
31- assignments = old_head -> next ;
33+ assignments = old_head -> next ;
3234 free (old_head -> variable );
3335 free (old_head -> value );
3436 free (old_head );
3537 }
3638}
3739
38- /* XXX: these should be more accurate (consider ECPGdump_a_* ) */
3940static void ECPGnumeric_lvalue (FILE * f ,char * name )
40- { const struct variable * v = find_variable (name );
41+ {
42+ const struct variable * v = find_variable (name );
4143
4244 switch (v -> type -> typ )
4345 {
@@ -54,10 +56,10 @@ static void ECPGnumeric_lvalue(FILE *f,char *name)
5456 ,name );
5557 mmerror (ET_ERROR ,errortext );
5658 break ;
57- }
59+ }
5860}
5961
60- static void ECPGstring_buffer (FILE * f ,char * name )
62+ static void ECPGstring_buffer (FILE * f , char * name )
6163{
6264 const struct variable * v = find_variable (name );
6365
@@ -167,30 +169,94 @@ static void ECPGdata_assignment(char *variable,char *index_plus_1)
167169 }
168170}
169171
172+ /*
173+ * descriptor name lookup
174+ */
175+
176+ static struct descriptor * descriptors ;
177+
178+ void add_descriptor (char * name ,char * connection )
179+ {
180+ struct descriptor * new = (struct descriptor * )mm_alloc (sizeof (struct descriptor ));
181+
182+ new -> next = descriptors ;
183+ new -> name = mm_alloc (strlen (name )+ 1 );
184+ strcpy (new -> name ,name );
185+ if (connection )
186+ { new -> connection = mm_alloc (strlen (connection )+ 1 );
187+ strcpy (new -> connection ,connection );
188+ }
189+ else new -> connection = connection ;
190+ descriptors = new ;
191+ }
192+
193+ void
194+ drop_descriptor (char * name ,char * connection )
195+ {
196+ struct descriptor * i ;
197+ struct descriptor * * lastptr = & descriptors ;
198+
199+ for (i = descriptors ;i ;lastptr = & i -> next ,i = i -> next )
200+ {
201+ if (!strcmp (name ,i -> name ))
202+ {
203+ if ((!connection && !i -> connection )
204+ || (connection && i -> connection
205+ && !strcmp (connection ,i -> connection )))
206+ {
207+ * lastptr = i -> next ;
208+ if (i -> connection ) free (i -> connection );
209+ free (i -> name );
210+ free (i );
211+ return ;
212+ }
213+ }
214+ }
215+ snprintf (errortext ,sizeof errortext ,"unknown descriptor %s" ,name );
216+ mmerror (ET_WARN ,errortext );
217+ }
218+
219+ struct descriptor
220+ * lookup_descriptor (char * name ,char * connection )
221+ {
222+ struct descriptor * i ;
223+
224+ for (i = descriptors ;i ;i = i -> next )
225+ {
226+ if (!strcmp (name ,i -> name ))
227+ {
228+ if ((!connection && !i -> connection )
229+ || (connection && i -> connection
230+ && !strcmp (connection ,i -> connection )))
231+ {
232+ return i ;
233+ }
234+ }
235+ }
236+ snprintf (errortext ,sizeof errortext ,"unknown descriptor %s" ,name );
237+ mmerror (ET_WARN ,errortext );
238+ return NULL ;
239+ }
240+
170241void
171242output_get_descr_header (char * desc_name )
172243{
173244 struct assignment * results ;
174245
175- fprintf (yyout ,"{\tPGresult *ECPGresult=ECPGresultByDescriptor(%d, \"%s\");\n" ,yylineno ,desc_name );
176- fputs ("\tif (ECPGresult)\n\t{" ,yyout );
177- for (results = assignments ;results != NULL ;results = results -> next )
246+ fprintf (yyout , "{ ECPGget_desc_header(%d, \"%s\", &(" , yylineno , desc_name );
247+ for (results = assignments ; results != NULL ; results = results -> next )
178248 {
179- if (!strcasecmp (results -> value ,"count" ))
180- {
181- fputs ("\t\t" ,yyout );
249+ if (!strcasecmp (results -> value , "count" ))
182250 ECPGnumeric_lvalue (yyout ,results -> variable );
183- fputs ("=PQnfields(ECPGresult);\n" ,yyout );
184- }
185251 else
186- { snprintf (errortext ,sizeof errortext ,"unknown descriptor header item '%s'" ,results -> value );
187- mmerror (ET_WARN ,errortext );
252+ { snprintf (errortext , sizeof errortext , "unknown descriptor header item '%s'" , results -> value );
253+ mmerror (ET_WARN , errortext );
188254 }
189255 }
190- drop_assignments ();
191- fputs ("}" ,yyout );
192256
193- whenever_action (2 |1 );
257+ drop_assignments ();
258+ fprintf (yyout , "));\n" );
259+ whenever_action (3 );
194260}
195261
196262void
@@ -305,96 +371,3 @@ output_get_descr(char *desc_name)
305371
306372 whenever_action (2 |1 );
307373}
308-
309- /*
310- * descriptor name lookup
311- */
312-
313- static struct descriptor * descriptors ;
314-
315- void add_descriptor (char * name ,char * connection )
316- {
317- struct descriptor * new = (struct descriptor * )mm_alloc (sizeof (struct descriptor ));
318-
319- new -> next = descriptors ;
320- new -> name = mm_alloc (strlen (name )+ 1 );
321- strcpy (new -> name ,name );
322- if (connection )
323- { new -> connection = mm_alloc (strlen (connection )+ 1 );
324- strcpy (new -> connection ,connection );
325- }
326- else new -> connection = connection ;
327- descriptors = new ;
328- }
329-
330- void drop_descriptor (char * name ,char * connection )
331- {
332- struct descriptor * i ;
333- struct descriptor * * lastptr = & descriptors ;
334-
335- for (i = descriptors ;i ;lastptr = & i -> next ,i = i -> next )
336- {
337- if (!strcmp (name ,i -> name ))
338- {
339- if ((!connection && !i -> connection )
340- || (connection && i -> connection
341- && !strcmp (connection ,i -> connection )))
342- {
343- * lastptr = i -> next ;
344- if (i -> connection ) free (i -> connection );
345- free (i -> name );
346- free (i );
347- return ;
348- }
349- }
350- }
351- snprintf (errortext ,sizeof errortext ,"unknown descriptor %s" ,name );
352- mmerror (ET_WARN ,errortext );
353- }
354-
355- struct descriptor * lookup_descriptor (char * name ,char * connection )
356- {
357- struct descriptor * i ;
358-
359- for (i = descriptors ;i ;i = i -> next )
360- {
361- if (!strcmp (name ,i -> name ))
362- {
363- if ((!connection && !i -> connection )
364- || (connection && i -> connection
365- && !strcmp (connection ,i -> connection )))
366- {
367- return i ;
368- }
369- }
370- }
371- snprintf (errortext ,sizeof errortext ,"unknown descriptor %s" ,name );
372- mmerror (ET_WARN ,errortext );
373- return NULL ;
374- }
375-
376- void
377- output_statement_desc (char * stmt , int mode )
378- {
379- int i , j = strlen (stmt );
380-
381- fprintf (yyout , "{ ECPGdo_descriptor(__LINE__, %s, \"%s\", \"" ,
382- connection ? connection : "NULL" , descriptor_name );
383-
384- /* do this char by char as we have to filter '\"' */
385- for (i = 0 ;i < j ; i ++ ) {
386- if (stmt [i ] != '\"' )
387- fputc (stmt [i ], yyout );
388- else
389- fputs ("\\\"" , yyout );
390- }
391-
392- fputs ("\");" , yyout );
393-
394- mode |= 2 ;
395- whenever_action (mode );
396- free (stmt );
397- if (connection != NULL )
398- free (connection );
399- free (descriptor_name );
400- }
0 commit comments