PostgreSQL Source Code  git master
extern.h File Reference
#include "type.h"
#include "common/keywords.h"
#include <errno.h>
#include <limits.h>
Include dependency graph for extern.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define STRUCT_DEPTH   128
 
#define EMPTY   mm_strdup("")
 
#define ILLEGAL_OPTION   1
 
#define NO_INCLUDE_FILE   2
 
#define PARSE_ERROR   3
 
#define INDICATOR_NOT_ARRAY   4
 
#define OUT_OF_MEMORY   5
 
#define INDICATOR_NOT_STRUCT   6
 
#define INDICATOR_NOT_SIMPLE   7
 
#define INFORMIX_MODE   (compat == ECPG_COMPAT_INFORMIX || compat == ECPG_COMPAT_INFORMIX_SE)
 

Enumerations

enum  COMPAT_MODE {
  ECPG_COMPAT_PGSQL = 0, ECPG_COMPAT_INFORMIX, ECPG_COMPAT_INFORMIX_SE, ECPG_COMPAT_PGSQL = 0,
  ECPG_COMPAT_INFORMIX, ECPG_COMPAT_INFORMIX_SE
}
 

Functions

const char * get_dtype (enum ECPGdtype)
 
void lex_init (void)
 
void output_line_number (void)
 
void output_statement (char *, int, enum ECPG_statement_type)
 
void output_prepare_statement (char *, char *)
 
void output_deallocate_prepare_statement (char *)
 
void output_simple_statement (char *)
 
char * hashline_number (void)
 
int base_yyparse (void)
 
int base_yylex (void)
 
void base_yyerror (const char *)
 
void * mm_alloc (size_t)
 
void * mm_realloc (void *, size_t)
 
char * mm_strdup (const char *)
 
void mmerror (int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
 
void void mmfatal (int errorcode, const char *error,...) pg_attribute_printf(2
 
void void pg_attribute_noreturn ()
 
void output_get_descr_header (char *)
 
void output_get_descr (char *, char *)
 
void output_set_descr_header (char *)
 
void output_set_descr (char *, char *)
 
void push_assignment (char *, enum ECPGdtype)
 
struct variablefind_variable (char *)
 
void whenever_action (int)
 
void add_descriptor (char *, char *)
 
void drop_descriptor (char *, char *)
 
struct descriptorlookup_descriptor (char *, char *)
 
struct variabledescriptor_variable (const char *name, int input)
 
struct variablesqlda_variable (const char *name)
 
void add_variable_to_head (struct arguments **, struct variable *, struct variable *)
 
void add_variable_to_tail (struct arguments **, struct variable *, struct variable *)
 
void remove_variable_from_list (struct arguments **list, struct variable *var)
 
void dump_variables (struct arguments *, int)
 
struct typedefsget_typedef (char *)
 
void adjust_array (enum ECPGttype, char **, char **, char *, char *, int, bool)
 
void reset_variables (void)
 
void check_indicator (struct ECPGtype *)
 
void remove_typedefs (int)
 
void remove_variables (int)
 
struct variablenew_variable (const char *, struct ECPGtype *, int)
 
const ScanKeywordScanCKeywordLookup (const char *)
 
const ScanKeywordScanECPGKeywordLookup (const char *text)
 
void scanner_init (const char *)
 
void parser_init (void)
 
void scanner_finish (void)
 
int filtered_base_yylex (void)
 

Variables

bool autocommit
 
bool auto_create_c
 
bool system_includes
 
bool force_indicator
 
bool questionmarks
 
bool regression_mode
 
bool auto_prepare
 
int braces_open
 
int ret_value
 
int struct_level
 
int ecpg_internal_var
 
char * current_function
 
char * descriptor_index
 
char * descriptor_name
 
char * connection
 
char * input_filename
 
char * base_yytext
 
char * token_start
 
int base_yylineno
 
FILE * base_yyin
 
FILE * base_yyout
 
char * output_filename
 
struct _include_pathinclude_paths
 
struct cursorcur
 
struct typedefstypes
 
struct _definesdefines
 
struct ECPGtype ecpg_no_indicator
 
struct variable no_indicator
 
struct argumentsargsinsert
 
struct argumentsargsresult
 
struct when when_error when_nf when_warn
 
struct ECPGstruct_memberstruct_member_list [STRUCT_DEPTH]
 
const ScanKeyword SQLScanKeywords []
 
const int NumSQLScanKeywords
 
enum COMPAT_MODE compat
 

Macro Definition Documentation

◆ EMPTY

#define EMPTY   mm_strdup("")

Definition at line 18 of file extern.h.

◆ ILLEGAL_OPTION

#define ILLEGAL_OPTION   1

Definition at line 115 of file extern.h.

Referenced by main().

◆ INDICATOR_NOT_ARRAY

#define INDICATOR_NOT_ARRAY   4

Definition at line 118 of file extern.h.

Referenced by ECPGdump_a_type().

◆ INDICATOR_NOT_SIMPLE

#define INDICATOR_NOT_SIMPLE   7

Definition at line 121 of file extern.h.

Referenced by ECPGdump_a_type().

◆ INDICATOR_NOT_STRUCT

#define INDICATOR_NOT_STRUCT   6

Definition at line 120 of file extern.h.

Referenced by ECPGdump_a_type().

◆ INFORMIX_MODE

#define INFORMIX_MODE   (compat == ECPG_COMPAT_INFORMIX || compat == ECPG_COMPAT_INFORMIX_SE)

Definition at line 129 of file extern.h.

◆ NO_INCLUDE_FILE

#define NO_INCLUDE_FILE   2

Definition at line 116 of file extern.h.

◆ OUT_OF_MEMORY

#define OUT_OF_MEMORY   5

Definition at line 119 of file extern.h.

Referenced by mm_alloc(), and mm_strdup().

◆ PARSE_ERROR

◆ STRUCT_DEPTH

#define STRUCT_DEPTH   128

Definition at line 17 of file extern.h.

Enumeration Type Documentation

◆ COMPAT_MODE

Enumerator
ECPG_COMPAT_PGSQL 
ECPG_COMPAT_INFORMIX 
ECPG_COMPAT_INFORMIX_SE 
ECPG_COMPAT_PGSQL 
ECPG_COMPAT_INFORMIX 
ECPG_COMPAT_INFORMIX_SE 

Definition at line 123 of file extern.h.

Function Documentation

◆ add_descriptor()

void add_descriptor ( char *  ,
char *   
)

Definition at line 76 of file descriptor.c.

References connection, descriptors, mm_alloc(), and descriptor::name.

77 {
78  struct descriptor *new;
79 
80  if (name[0] != '"')
81  return;
82 
83  new = (struct descriptor *) mm_alloc(sizeof(struct descriptor));
84 
85  new->next = descriptors;
86  new->name = mm_alloc(strlen(name) + 1);
87  strcpy(new->name, name);
88  if (connection)
89  {
90  new->connection = mm_alloc(strlen(connection) + 1);
91  strcpy(new->connection, connection);
92  }
93  else
94  new->connection = connection;
95  descriptors = new;
96 }
static struct descriptor * descriptors
Definition: descriptor.c:73
char * connection
void * mm_alloc(size_t)
const char * name
Definition: encode.c:521
char * name
Definition: extern.h:92

◆ add_variable_to_head()

void add_variable_to_head ( struct arguments **  ,
struct variable ,
struct variable  
)

Definition at line 379 of file variable.c.

References arguments::indicator, sort-test::list, mm_alloc(), arguments::next, and arguments::variable.

380 {
381  struct arguments *p = (struct arguments *) mm_alloc(sizeof(struct arguments));
382 
383  p->variable = var;
384  p->indicator = ind;
385  p->next = *list;
386  *list = p;
387 }
struct variable * indicator
Definition: type.h:168
struct arguments * next
Definition: type.h:169
void * mm_alloc(size_t)
struct variable * variable
Definition: type.h:167

◆ add_variable_to_tail()

void add_variable_to_tail ( struct arguments **  ,
struct variable ,
struct variable  
)

Definition at line 391 of file variable.c.

References mm_alloc(), variable::next, and arguments::next.

392 {
393  struct arguments *p,
394  *new = (struct arguments *) mm_alloc(sizeof(struct arguments));
395 
396  for (p = *list; p && p->next; p = p->next);
397 
398  new->variable = var;
399  new->indicator = ind;
400  new->next = NULL;
401 
402  if (p)
403  p->next = new;
404  else
405  *list = new;
406 }
struct arguments * next
Definition: type.h:169
void * mm_alloc(size_t)

◆ adjust_array()

void adjust_array ( enum  ECPGttype,
char **  ,
char **  ,
char *  ,
char *  ,
int  ,
bool   
)

Definition at line 512 of file variable.c.

References ECPGt_char, ECPGt_string, ECPGt_struct, ECPGt_union, ECPGt_unsigned_char, ECPGt_varchar, mm_strdup(), mmfatal(), ngettext, and PARSE_ERROR.

513 {
514  if (atoi(type_index) >= 0)
515  {
516  if (atoi(*length) >= 0)
517  mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
518 
519  *length = type_index;
520  }
521 
522  if (atoi(type_dimension) >= 0)
523  {
524  if (atoi(*dimension) >= 0 && atoi(*length) >= 0)
525  mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
526 
527  if (atoi(*dimension) >= 0)
528  *length = *dimension;
529 
530  *dimension = type_dimension;
531  }
532 
533  if (pointer_len > 2)
534  mmfatal(PARSE_ERROR, ngettext("multilevel pointers (more than 2 levels) are not supported; found %d level",
535  "multilevel pointers (more than 2 levels) are not supported; found %d levels", pointer_len),
536  pointer_len);
537 
538  if (pointer_len > 1 && type_enum != ECPGt_char && type_enum != ECPGt_unsigned_char && type_enum != ECPGt_string)
539  mmfatal(PARSE_ERROR, "pointer to pointer is not supported for this data type");
540 
541  if (pointer_len > 1 && (atoi(*length) >= 0 || atoi(*dimension) >= 0))
542  mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
543 
544  if (atoi(*length) >= 0 && atoi(*dimension) >= 0 && pointer_len)
545  mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
546 
547  switch (type_enum)
548  {
549  case ECPGt_struct:
550  case ECPGt_union:
551  /* pointer has to get dimension 0 */
552  if (pointer_len)
553  {
554  *length = *dimension;
555  *dimension = mm_strdup("0");
556  }
557 
558  if (atoi(*length) >= 0)
559  mmfatal(PARSE_ERROR, "multidimensional arrays for structures are not supported");
560 
561  break;
562  case ECPGt_varchar:
563  /* pointer has to get dimension 0 */
564  if (pointer_len)
565  *dimension = mm_strdup("0");
566 
567  /* one index is the string length */
568  if (atoi(*length) < 0)
569  {
570  *length = *dimension;
571  *dimension = mm_strdup("-1");
572  }
573 
574  break;
575  case ECPGt_char:
576  case ECPGt_unsigned_char:
577  case ECPGt_string:
578  /* char ** */
579  if (pointer_len == 2)
580  {
581  *length = *dimension = mm_strdup("0");
582  break;
583  }
584 
585  /* pointer has to get length 0 */
586  if (pointer_len == 1)
587  *length = mm_strdup("0");
588 
589  /* one index is the string length */
590  if (atoi(*length) < 0)
591  {
592  /*
593  * make sure we return length = -1 for arrays without given
594  * bounds
595  */
596  if (atoi(*dimension) < 0 && !type_definition)
597 
598  /*
599  * do not change this for typedefs since it will be
600  * changed later on when the variable is defined
601  */
602  *length = mm_strdup("1");
603  else if (strcmp(*dimension, "0") == 0)
604  *length = mm_strdup("-1");
605  else
606  *length = *dimension;
607 
608  *dimension = mm_strdup("-1");
609  }
610  break;
611  default:
612  /* a pointer has dimension = 0 */
613  if (pointer_len)
614  {
615  *length = *dimension;
616  *dimension = mm_strdup("0");
617  }
618 
619  if (atoi(*length) >= 0)
620  mmfatal(PARSE_ERROR, "multidimensional arrays for simple data types are not supported");
621 
622  break;
623  }
624 }
int length(const List *list)
Definition: list.c:1271
void void mmfatal(int errorcode, const char *error,...) pg_attribute_printf(2
#define ngettext(s, p, n)
Definition: c.h:967
#define PARSE_ERROR
Definition: extern.h:117
char * mm_strdup(const char *)
Definition: type.c:25

◆ base_yyerror()

void base_yyerror ( const char *  )

Referenced by ECPGdump_a_type(), and ECPGfree_type().

◆ base_yylex()

int base_yylex ( void  )

◆ base_yyparse()

int base_yyparse ( void  )

◆ check_indicator()

void check_indicator ( struct ECPGtype )

Definition at line 467 of file variable.c.

References ECPGt_array, ECPGt_int, ECPGt_long, ECPGt_long_long, ECPGt_short, ECPGt_struct, ECPGt_union, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, ECPGtype::element, ET_ERROR, ECPGtype::members, mmerror(), ECPGstruct_member::next, PARSE_ERROR, ECPGstruct_member::type, ECPGtype::type, and ECPGtype::u.

468 {
469  /* make sure this is a valid indicator variable */
470  switch (var->type)
471  {
472  struct ECPGstruct_member *p;
473 
474  case ECPGt_short:
475  case ECPGt_int:
476  case ECPGt_long:
477  case ECPGt_long_long:
479  case ECPGt_unsigned_int:
480  case ECPGt_unsigned_long:
482  break;
483 
484  case ECPGt_struct:
485  case ECPGt_union:
486  for (p = var->u.members; p; p = p->next)
487  check_indicator(p->type);
488  break;
489 
490  case ECPGt_array:
491  check_indicator(var->u.element);
492  break;
493  default:
494  mmerror(PARSE_ERROR, ET_ERROR, "indicator variable must have an integer type");
495  break;
496  }
497 }
Definition: type.h:188
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
struct ECPGtype * type
Definition: type.h:13
#define PARSE_ERROR
Definition: extern.h:117
void check_indicator(struct ECPGtype *var)
Definition: variable.c:467
struct ECPGstruct_member * next
Definition: type.h:14

◆ descriptor_variable()

struct variable* descriptor_variable ( const char *  name,
int  input 
)

Definition at line 326 of file descriptor.c.

References ECPGt_descriptor, MAX_DESCRIPTOR_NAMELEN, and strlcpy().

327 {
328  static char descriptor_names[2][MAX_DESCRIPTOR_NAMELEN];
329  static struct ECPGtype descriptor_type = {ECPGt_descriptor, NULL, NULL, NULL, {NULL}, 0};
330  static struct variable varspace[2] = {
331  {descriptor_names[0], &descriptor_type, 0, NULL},
332  {descriptor_names[1], &descriptor_type, 0, NULL}
333  };
334 
335  strlcpy(descriptor_names[input], name, sizeof(descriptor_names[input]));
336  return &varspace[input];
337 }
Definition: type.h:17
#define MAX_DESCRIPTOR_NAMELEN
Definition: descriptor.c:324
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
const char * name
Definition: encode.c:521

◆ drop_descriptor()

void drop_descriptor ( char *  ,
char *   
)

Definition at line 99 of file descriptor.c.

References descriptor::connection, descriptors, ET_WARNING, free, i, mmerror(), descriptor::name, descriptor::next, and PARSE_ERROR.

100 {
101  struct descriptor *i;
102  struct descriptor **lastptr = &descriptors;
103 
104  if (name[0] != '"')
105  return;
106 
107  for (i = descriptors; i; lastptr = &i->next, i = i->next)
108  {
109  if (strcmp(name, i->name) == 0)
110  {
111  if ((!connection && !i->connection)
112  || (connection && i->connection
113  && strcmp(connection, i->connection) == 0))
114  {
115  *lastptr = i->next;
116  if (i->connection)
117  free(i->connection);
118  free(i->name);
119  free(i);
120  return;
121  }
122  }
123  }
124  mmerror(PARSE_ERROR, ET_WARNING, "descriptor \"%s\" does not exist", name);
125 }
char * connection
Definition: type.h:175
static struct descriptor * descriptors
Definition: descriptor.c:73
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
struct descriptor * next
Definition: extern.h:94
#define free(a)
Definition: header.h:65
const char * name
Definition: encode.c:521
#define PARSE_ERROR
Definition: extern.h:117
int i
char * name
Definition: extern.h:92

◆ dump_variables()

void dump_variables ( struct arguments ,
int   
)

Definition at line 438 of file variable.c.

References base_yyout, variable::brace_level, ECPGdump_a_type(), free, arguments::indicator, mm_strdup(), variable::name, arguments::next, variable::type, and arguments::variable.

Referenced by output_statement().

439 {
440  char *str_zero;
441 
442  if (list == NULL)
443  return;
444 
445  str_zero = mm_strdup("0");
446 
447  /*
448  * The list is build up from the beginning so lets first dump the end of
449  * the list:
450  */
451 
452  dump_variables(list->next, mode);
453 
454  /* Then the current element and its indicator */
455  ECPGdump_a_type(base_yyout, list->variable->name, list->variable->type, list->variable->brace_level,
456  list->indicator->name, list->indicator->type, list->indicator->brace_level,
457  NULL, NULL, str_zero, NULL, NULL);
458 
459  /* Then release the list element. */
460  if (mode != 0)
461  free(list);
462 
463  free(str_zero);
464 }
void dump_variables(struct arguments *list, int mode)
Definition: variable.c:438
void ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype *type, const int brace_level, const char *ind_name, struct ECPGtype *ind_type, const int ind_brace_level, const char *prefix, const char *ind_prefix, char *arr_str_size, const char *struct_sizeof, const char *ind_struct_sizeof)
Definition: type.c:239
FILE * base_yyout
#define free(a)
Definition: header.h:65
char * mm_strdup(const char *)
Definition: type.c:25

◆ filtered_base_yylex()

int filtered_base_yylex ( void  )

Definition at line 48 of file parser.c.

References Assert, base_yylex(), base_yytext, have_lookahead, lookahead_end, lookahead_hold_char, lookahead_token, lookahead_yylloc, lookahead_yylval, lookahead_yytext, next_token(), and YYLTYPE.

49 {
50  int cur_token;
51  int next_token;
52  int cur_token_length;
53  YYSTYPE cur_yylval;
54  YYLTYPE cur_yylloc;
55  char *cur_yytext;
56 
57  /* Get next token --- we might already have it */
58  if (have_lookahead)
59  {
60  cur_token = lookahead_token;
61  base_yylval = lookahead_yylval;
62  base_yylloc = lookahead_yylloc;
65  have_lookahead = false;
66  }
67  else
68  cur_token = base_yylex();
69 
70  /*
71  * If this token isn't one that requires lookahead, just return it. If it
72  * does, determine the token length. (We could get that via strlen(), but
73  * since we have such a small set of possibilities, hardwiring seems
74  * feasible and more efficient.)
75  */
76  switch (cur_token)
77  {
78  case NOT:
79  cur_token_length = 3;
80  break;
81  case NULLS_P:
82  cur_token_length = 5;
83  break;
84  case WITH:
85  cur_token_length = 4;
86  break;
87  default:
88  return cur_token;
89  }
90 
91  /*
92  * Identify end+1 of current token. base_yylex() has temporarily stored a
93  * '\0' here, and will undo that when we call it again. We need to redo
94  * it to fully revert the lookahead call for error reporting purposes.
95  */
96  lookahead_end = base_yytext + cur_token_length;
97  Assert(*lookahead_end == '\0');
98 
99  /* Save and restore lexer output variables around the call */
100  cur_yylval = base_yylval;
101  cur_yylloc = base_yylloc;
102  cur_yytext = base_yytext;
103 
104  /* Get next token, saving outputs into lookahead variables */
105  next_token = base_yylex();
106 
108  lookahead_yylval = base_yylval;
109  lookahead_yylloc = base_yylloc;
111 
112  base_yylval = cur_yylval;
113  base_yylloc = cur_yylloc;
114  base_yytext = cur_yytext;
115 
116  /* Now revert the un-truncation of the current token */
118  *lookahead_end = '\0';
119 
120  have_lookahead = true;
121 
122  /* Replace cur_token if needed, based on lookahead */
123  switch (cur_token)
124  {
125  case NOT:
126  /* Replace NOT by NOT_LA if it's followed by BETWEEN, IN, etc */
127  switch (next_token)
128  {
129  case BETWEEN:
130  case IN_P:
131  case LIKE:
132  case ILIKE:
133  case SIMILAR:
134  cur_token = NOT_LA;
135  break;
136  }
137  break;
138 
139  case NULLS_P:
140  /* Replace NULLS_P by NULLS_LA if it's followed by FIRST or LAST */
141  switch (next_token)
142  {
143  case FIRST_P:
144  case LAST_P:
145  cur_token = NULLS_LA;
146  break;
147  }
148  break;
149 
150  case WITH:
151  /* Replace WITH by WITH_LA if it's followed by TIME or ORDINALITY */
152  switch (next_token)
153  {
154  case TIME:
155  case ORDINALITY:
156  cur_token = WITH_LA;
157  break;
158  }
159  break;
160  }
161 
162  return cur_token;
163 }
static char lookahead_hold_char
Definition: parser.c:31
static bool have_lookahead
Definition: parser.c:25
static char * lookahead_end
Definition: parser.c:30
static bool next_token(char **lineptr, char *buf, int bufsz, bool *initial_quote, bool *terminating_comma, int elevel, char **err_msg)
Definition: hba.c:195
static char * lookahead_yytext
Definition: parser.c:29
#define YYLTYPE
Definition: scanner.h:44
int base_yylex(YYSTYPE *lvalp, YYLTYPE *llocp, core_yyscan_t yyscanner)
Definition: parser.c:83
static YYLTYPE lookahead_yylloc
Definition: parser.c:28
#define Assert(condition)
Definition: c.h:670
char * base_yytext
static int lookahead_token
Definition: parser.c:26
static YYSTYPE lookahead_yylval
Definition: parser.c:27

◆ find_variable()

struct variable* find_variable ( char *  )

Definition at line 194 of file variable.c.

References variable::brace_level, ECPGmake_array_type(), ECPGmake_simple_type(), ECPGmake_struct_type(), ECPGt_array, ECPGt_struct, ECPGt_union, find_simple(), find_struct(), mmfatal(), new_variable(), next, PARSE_ERROR, and variable::type.

Referenced by ECPGdump_a_type(), ECPGnumeric_lvalue(), find_struct(), output_get_descr(), and output_set_descr().

195 {
196  char *next,
197  *end;
198  struct variable *p;
199  int count;
200 
201  next = strpbrk(name, ".[-");
202  if (next)
203  {
204  if (*next == '[')
205  {
206  /*
207  * We don't care about what's inside the array braces so just eat
208  * up the characters
209  */
210  for (count = 1, end = next + 1; count; end++)
211  {
212  switch (*end)
213  {
214  case '[':
215  count++;
216  break;
217  case ']':
218  count--;
219  break;
220  default:
221  break;
222  }
223  }
224  if (*end == '.')
225  p = find_struct(name, next, end);
226  else
227  {
228  char c = *next;
229 
230  *next = '\0';
231  p = find_simple(name);
232  if (p == NULL)
233  mmfatal(PARSE_ERROR, "variable \"%s\" is not declared", name);
234 
235  *next = c;
236  switch (p->type->u.element->type)
237  {
238  case ECPGt_array:
239  return new_variable(name, ECPGmake_array_type(ECPGmake_simple_type(p->type->u.element->u.element->type, p->type->u.element->u.element->size, p->type->u.element->u.element->counter), p->type->u.element->size), p->brace_level);
240  case ECPGt_struct:
241  case ECPGt_union:
242  return new_variable(name, ECPGmake_struct_type(p->type->u.element->u.members, p->type->u.element->type, p->type->u.element->type_name, p->type->u.element->struct_sizeof), p->brace_level);
243  default:
244  return new_variable(name, ECPGmake_simple_type(p->type->u.element->type, p->type->u.element->size, p->type->u.element->counter), p->brace_level);
245  }
246  }
247  }
248  else
249  p = find_struct(name, next, next);
250  }
251  else
252  p = find_simple(name);
253 
254  if (p == NULL)
255  mmfatal(PARSE_ERROR, "variable \"%s\" is not declared", name);
256 
257  return p;
258 }
int brace_level
Definition: type.h:161
static int32 next
Definition: blutils.c:210
static struct variable * find_struct(char *name, char *next, char *end)
Definition: variable.c:127
struct ECPGtype * ECPGmake_array_type(struct ECPGtype *type, char *size)
Definition: type.c:111
enum ECPGttype type
Definition: extern.h:113
struct ECPGtype * ECPGmake_simple_type(enum ECPGttype type, char *size, int counter)
Definition: type.c:96
static struct variable * find_simple(char *name)
Definition: variable.c:178
char * c
void void mmfatal(int errorcode, const char *error,...) pg_attribute_printf(2
struct variable * new_variable(const char *name, struct ECPGtype *type, int brace_level)
Definition: variable.c:10
struct ECPGtype * ECPGmake_struct_type(struct ECPGstruct_member *rm, enum ECPGttype type, char *type_name, char *struct_sizeof)
Definition: type.c:121
const char * name
Definition: encode.c:521
#define PARSE_ERROR
Definition: extern.h:117

◆ get_dtype()

const char* get_dtype ( enum  ECPGdtype)

Definition at line 672 of file type.c.

References ECPGd_cardinality, ECPGd_count, ECPGd_data, ECPGd_di_code, ECPGd_di_precision, ECPGd_indicator, ECPGd_key_member, ECPGd_length, ECPGd_name, ECPGd_nullable, ECPGd_octet, ECPGd_precision, ECPGd_ret_length, ECPGd_ret_octet, ECPGd_scale, ECPGd_type, ET_ERROR, mmerror(), and PARSE_ERROR.

Referenced by output_get_descr(), and output_set_descr().

673 {
674  switch (type)
675  {
676  case ECPGd_count:
677  return "ECPGd_countr";
678  break;
679  case ECPGd_data:
680  return "ECPGd_data";
681  break;
682  case ECPGd_di_code:
683  return "ECPGd_di_code";
684  break;
685  case ECPGd_di_precision:
686  return "ECPGd_di_precision";
687  break;
688  case ECPGd_indicator:
689  return "ECPGd_indicator";
690  break;
691  case ECPGd_key_member:
692  return "ECPGd_key_member";
693  break;
694  case ECPGd_length:
695  return "ECPGd_length";
696  break;
697  case ECPGd_name:
698  return "ECPGd_name";
699  break;
700  case ECPGd_nullable:
701  return "ECPGd_nullable";
702  break;
703  case ECPGd_octet:
704  return "ECPGd_octet";
705  break;
706  case ECPGd_precision:
707  return "ECPGd_precision";
708  break;
709  case ECPGd_ret_length:
710  return "ECPGd_ret_length";
711  case ECPGd_ret_octet:
712  return "ECPGd_ret_octet";
713  break;
714  case ECPGd_scale:
715  return "ECPGd_scale";
716  break;
717  case ECPGd_type:
718  return "ECPGd_type";
719  break;
720  case ECPGd_cardinality:
721  return "ECPGd_cardinality";
722  default:
723  mmerror(PARSE_ERROR, ET_ERROR, "unrecognized descriptor item code %d", type);
724  }
725 
726  return NULL;
727 }
Definition: type.h:188
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
#define PARSE_ERROR
Definition: extern.h:117

◆ get_typedef()

struct typedefs* get_typedef ( char *  )

Definition at line 500 of file variable.c.

References mmfatal(), next, PARSE_ERROR, and types.

501 {
502  struct typedefs *this;
503 
504  for (this = types; this && strcmp(this->name, name) != 0; this = this->next);
505  if (!this)
506  mmfatal(PARSE_ERROR, "unrecognized data type name \"%s\"", name);
507 
508  return this;
509 }
static int32 next
Definition: blutils.c:210
struct typedefs * types
Definition: ecpg.c:29
Definition: type.h:138
void void mmfatal(int errorcode, const char *error,...) pg_attribute_printf(2
const char * name
Definition: encode.c:521
#define PARSE_ERROR
Definition: extern.h:117

◆ hashline_number()

char* hashline_number ( void  )

Definition at line 92 of file output.c.

References base_yylineno, generate_unaccent_rules::dest, EMPTY, input_filename, and mm_alloc().

Referenced by output_line_number().

93 {
94  /* do not print line numbers if we are in debug mode */
95  if (input_filename
96 #ifdef YYDEBUG
97  && !base_yydebug
98 #endif
99  )
100  {
101  /* "* 2" here is for escaping '\' and '"' below */
102  char *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + sizeof(int) * CHAR_BIT * 10 / 3 + strlen(input_filename) * 2);
103  char *src,
104  *dest;
105 
106  sprintf(line, "\n#line %d \"", base_yylineno);
107  src = input_filename;
108  dest = line + strlen(line);
109  while (*src)
110  {
111  if (*src == '\\' || *src == '"')
112  *dest++ = '\\';
113  *dest++ = *src++;
114  }
115  *dest = '\0';
116  strcat(dest, "\"\n");
117 
118  return line;
119  }
120 
121  return EMPTY;
122 }
int base_yylineno
void * mm_alloc(size_t)
char * input_filename
#define EMPTY
Definition: regcomp.c:274

◆ lex_init()

void lex_init ( void  )

Referenced by main().

◆ lookup_descriptor()

struct descriptor* lookup_descriptor ( char *  ,
char *   
)

Definition at line 129 of file descriptor.c.

References descriptor::connection, ET_WARNING, i, mmerror(), descriptor::name, descriptor::next, and PARSE_ERROR.

130 {
131  struct descriptor *i;
132 
133  if (name[0] != '"')
134  return NULL;
135 
136  for (i = descriptors; i; i = i->next)
137  {
138  if (strcmp(name, i->name) == 0)
139  {
140  if ((!connection && !i->connection)
141  || (connection && i->connection
142  && strcmp(connection, i->connection) == 0))
143  return i;
144  }
145  }
146  mmerror(PARSE_ERROR, ET_WARNING, "descriptor \"%s\" does not exist", name);
147  return NULL;
148 }
char * connection
Definition: type.h:175
static struct descriptor * descriptors
Definition: descriptor.c:73
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
struct descriptor * next
Definition: extern.h:94
const char * name
Definition: encode.c:521
#define PARSE_ERROR
Definition: extern.h:117
int i
char * name
Definition: extern.h:92

◆ mm_alloc()

◆ mm_realloc()

void * mm_realloc ( void *  ,
size_t   
)

◆ mm_strdup()

char* mm_strdup ( const char *  )

Definition at line 25 of file type.c.

References mmfatal(), and OUT_OF_MEMORY.

Referenced by add_preprocessor_define(), adjust_array(), dump_variables(), ECPGdump_a_type(), ECPGmake_struct_member(), ECPGmake_struct_type(), main(), new_variable(), output_get_descr(), output_set_descr(), and sqlda_variable().

26 {
27  char *new = strdup(string);
28 
29  if (new == NULL)
30  mmfatal(OUT_OF_MEMORY, "out of memory");
31 
32  return new;
33 }
#define OUT_OF_MEMORY
Definition: extern.h:119
void void mmfatal(int errorcode, const char *error,...) pg_attribute_printf(2

◆ mmerror()

◆ mmfatal()

void void mmfatal ( int  errorcode,
const char *  error,
  ... 
)

◆ new_variable()

struct variable* new_variable ( const char *  ,
struct ECPGtype ,
int   
)

Definition at line 10 of file variable.c.

References allvariables, variable::brace_level, mm_alloc(), mm_strdup(), variable::name, variable::next, variable::type, and generate_unaccent_rules::type.

Referenced by find_struct_member(), and find_variable().

11 {
12  struct variable *p = (struct variable *) mm_alloc(sizeof(struct variable));
13 
14  p->name = mm_strdup(name);
15  p->type = type;
17 
18  p->next = allvariables;
19  allvariables = p;
20 
21  return p;
22 }
int brace_level
Definition: type.h:161
enum ECPGttype type
Definition: extern.h:113
struct variable * next
Definition: extern.h:125
void * mm_alloc(size_t)
static struct variable * allvariables
Definition: variable.c:7
const char * name
Definition: encode.c:521
char * mm_strdup(const char *)
Definition: type.c:25
char * name
Definition: type.h:159

◆ output_deallocate_prepare_statement()

void output_deallocate_prepare_statement ( char *  )

Definition at line 178 of file output.c.

References base_yyout, compat, connection, free, output_escaped_str(), and whenever_action().

179 {
180  const char *con = connection ? connection : "NULL";
181 
182  if (strcmp(name, "all") != 0)
183  {
184  fprintf(base_yyout, "{ ECPGdeallocate(__LINE__, %d, %s, ", compat, con);
185  output_escaped_str(name, true);
186  fputs(");", base_yyout);
187  }
188  else
189  fprintf(base_yyout, "{ ECPGdeallocate_all(__LINE__, %d, %s);", compat, con);
190 
191  whenever_action(2);
192  free(name);
193  if (connection != NULL)
194  free(connection);
195 }
void whenever_action(int mode)
Definition: output.c:64
char * connection
static void output_escaped_str(char *cmd, bool quoted)
Definition: output.c:198
FILE * base_yyout
enum COMPAT_MODE compat
Definition: ecpg.c:25
#define free(a)
Definition: header.h:65
const char * name
Definition: encode.c:521

◆ output_get_descr()

void output_get_descr ( char *  ,
char *   
)

Definition at line 170 of file descriptor.c.

References base_yyout, variable::brace_level, drop_assignments(), ECPGd_key_member, ECPGd_nullable, ECPGdump_a_type(), ET_WARNING, find_variable(), free, get_dtype(), mm_strdup(), mmerror(), variable::name, assignment::next, PARSE_ERROR, variable::type, assignment::value, assignment::variable, and whenever_action().

171 {
172  struct assignment *results;
173 
174  fprintf(base_yyout, "{ ECPGget_desc(__LINE__, %s, %s,", desc_name, index);
175  for (results = assignments; results != NULL; results = results->next)
176  {
177  const struct variable *v = find_variable(results->variable);
178  char *str_zero = mm_strdup("0");
179 
180  switch (results->value)
181  {
182  case ECPGd_nullable:
183  mmerror(PARSE_ERROR, ET_WARNING, "nullable is always 1");
184  break;
185  case ECPGd_key_member:
186  mmerror(PARSE_ERROR, ET_WARNING, "key_member is always 0");
187  break;
188  default:
189  break;
190  }
191  fprintf(base_yyout, "%s,", get_dtype(results->value));
193  NULL, NULL, -1, NULL, NULL, str_zero, NULL, NULL);
194  free(str_zero);
195  }
197  fputs("ECPGd_EODT);\n", base_yyout);
198 
199  whenever_action(2 | 1);
200 }
int brace_level
Definition: type.h:161
struct variable * find_variable(char *)
Definition: variable.c:194
static struct assignment * assignments
Definition: descriptor.c:18
static void drop_assignments(void)
Definition: descriptor.c:33
enum ECPGttype type
Definition: extern.h:113
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
void ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype *type, const int brace_level, const char *ind_name, struct ECPGtype *ind_type, const int ind_brace_level, const char *prefix, const char *ind_prefix, char *arr_str_size, const char *struct_sizeof, const char *ind_struct_sizeof)
Definition: type.c:239
Definition: type.h:89
struct assignment * next
Definition: type.h:183
char * variable
Definition: type.h:181
FILE * base_yyout
#define free(a)
Definition: header.h:65
void whenever_action(int)
Definition: output.c:64
#define PARSE_ERROR
Definition: extern.h:117
char * mm_strdup(const char *)
Definition: type.c:25
enum ECPGdtype value
Definition: type.h:182
char * name
Definition: type.h:159
const char * get_dtype(enum ECPGdtype)
Definition: type.c:672

◆ output_get_descr_header()

void output_get_descr_header ( char *  )

Definition at line 151 of file descriptor.c.

References base_yyout, drop_assignments(), ECPGd_count, ECPGnumeric_lvalue(), ET_WARNING, mmerror(), assignment::next, PARSE_ERROR, assignment::value, assignment::variable, and whenever_action().

152 {
153  struct assignment *results;
154 
155  fprintf(base_yyout, "{ ECPGget_desc_header(__LINE__, %s, &(", desc_name);
156  for (results = assignments; results != NULL; results = results->next)
157  {
158  if (results->value == ECPGd_count)
159  ECPGnumeric_lvalue(results->variable);
160  else
161  mmerror(PARSE_ERROR, ET_WARNING, "descriptor header item \"%d\" does not exist", results->value);
162  }
163 
165  fprintf(base_yyout, "));\n");
166  whenever_action(3);
167 }
static struct assignment * assignments
Definition: descriptor.c:18
static void drop_assignments(void)
Definition: descriptor.c:33
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
static void ECPGnumeric_lvalue(char *name)
Definition: descriptor.c:46
struct assignment * next
Definition: type.h:183
char * variable
Definition: type.h:181
FILE * base_yyout
void whenever_action(int)
Definition: output.c:64
#define PARSE_ERROR
Definition: extern.h:117
enum ECPGdtype value
Definition: type.h:182

◆ output_line_number()

void output_line_number ( void  )

Definition at line 10 of file output.c.

References base_yyout, free, and hashline_number().

Referenced by main(), output_simple_statement(), and whenever_action().

11 {
12  char *line = hashline_number();
13 
14  fprintf(base_yyout, "%s", line);
15  free(line);
16 }
char * hashline_number(void)
Definition: output.c:92
FILE * base_yyout
#define free(a)
Definition: header.h:65

◆ output_prepare_statement()

void output_prepare_statement ( char *  ,
char *   
)

Definition at line 164 of file output.c.

References base_yyout, free, output_escaped_str(), questionmarks, and whenever_action().

165 {
166  fprintf(base_yyout, "{ ECPGprepare(__LINE__, %s, %d, ", connection ? connection : "NULL", questionmarks);
167  output_escaped_str(name, true);
168  fputs(", ", base_yyout);
169  output_escaped_str(stmt, true);
170  fputs(");", base_yyout);
171  whenever_action(2);
172  free(name);
173  if (connection != NULL)
174  free(connection);
175 }
void whenever_action(int mode)
Definition: output.c:64
static void output_escaped_str(char *cmd, bool quoted)
Definition: output.c:198
bool questionmarks
Definition: ecpg.c:19
FILE * base_yyout
#define free(a)
Definition: header.h:65
const char * name
Definition: encode.c:521

◆ output_set_descr()

void output_set_descr ( char *  ,
char *   
)

Definition at line 264 of file descriptor.c.

References base_yyout, variable::brace_level, descriptor_item_name(), drop_assignments(), ECPGd_cardinality, ECPGd_data, ECPGd_di_code, ECPGd_di_precision, ECPGd_indicator, ECPGd_key_member, ECPGd_length, ECPGd_name, ECPGd_nullable, ECPGd_octet, ECPGd_precision, ECPGd_ret_length, ECPGd_ret_octet, ECPGd_scale, ECPGd_type, ECPGdump_a_type(), find_variable(), free, get_dtype(), mm_strdup(), mmfatal(), variable::name, assignment::next, PARSE_ERROR, variable::type, assignment::value, assignment::variable, and whenever_action().

265 {
266  struct assignment *results;
267 
268  fprintf(base_yyout, "{ ECPGset_desc(__LINE__, %s, %s,", desc_name, index);
269  for (results = assignments; results != NULL; results = results->next)
270  {
271  const struct variable *v = find_variable(results->variable);
272 
273  switch (results->value)
274  {
275  case ECPGd_cardinality:
276  case ECPGd_di_code:
277  case ECPGd_di_precision:
278  case ECPGd_precision:
279  case ECPGd_scale:
280  mmfatal(PARSE_ERROR, "descriptor item \"%s\" is not implemented",
281  descriptor_item_name(results->value));
282  break;
283 
284  case ECPGd_key_member:
285  case ECPGd_name:
286  case ECPGd_nullable:
287  case ECPGd_octet:
288  case ECPGd_ret_length:
289  case ECPGd_ret_octet:
290  mmfatal(PARSE_ERROR, "descriptor item \"%s\" cannot be set",
291  descriptor_item_name(results->value));
292  break;
293 
294  case ECPGd_data:
295  case ECPGd_indicator:
296  case ECPGd_length:
297  case ECPGd_type:
298  {
299  char *str_zero = mm_strdup("0");
300 
301  fprintf(base_yyout, "%s,", get_dtype(results->value));
303  NULL, NULL, -1, NULL, NULL, str_zero, NULL, NULL);
304  free(str_zero);
305  }
306  break;
307 
308  default:
309  ;
310  }
311  }
313  fputs("ECPGd_EODT);\n", base_yyout);
314 
315  whenever_action(2 | 1);
316 }
int brace_level
Definition: type.h:161
struct variable * find_variable(char *)
Definition: variable.c:194
static struct assignment * assignments
Definition: descriptor.c:18
static void drop_assignments(void)
Definition: descriptor.c:33
enum ECPGttype type
Definition: extern.h:113
void ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype *type, const int brace_level, const char *ind_name, struct ECPGtype *ind_type, const int ind_brace_level, const char *prefix, const char *ind_prefix, char *arr_str_size, const char *struct_sizeof, const char *ind_struct_sizeof)
Definition: type.c:239
Definition: type.h:89
struct assignment * next
Definition: type.h:183
char * variable
Definition: type.h:181
FILE * base_yyout
void void mmfatal(int errorcode, const char *error,...) pg_attribute_printf(2
#define free(a)
Definition: header.h:65
void whenever_action(int)
Definition: output.c:64
#define PARSE_ERROR
Definition: extern.h:117
char * mm_strdup(const char *)
Definition: type.c:25
static const char * descriptor_item_name(enum ECPGdtype itemcode)
Definition: descriptor.c:222
enum ECPGdtype value
Definition: type.h:182
char * name
Definition: type.h:159
const char * get_dtype(enum ECPGdtype)
Definition: type.c:672

◆ output_set_descr_header()

void output_set_descr_header ( char *  )

Definition at line 203 of file descriptor.c.

References base_yyout, drop_assignments(), ECPGd_count, ECPGnumeric_lvalue(), ET_WARNING, mmerror(), assignment::next, PARSE_ERROR, assignment::value, assignment::variable, and whenever_action().

204 {
205  struct assignment *results;
206 
207  fprintf(base_yyout, "{ ECPGset_desc_header(__LINE__, %s, (int)(", desc_name);
208  for (results = assignments; results != NULL; results = results->next)
209  {
210  if (results->value == ECPGd_count)
211  ECPGnumeric_lvalue(results->variable);
212  else
213  mmerror(PARSE_ERROR, ET_WARNING, "descriptor header item \"%d\" does not exist", results->value);
214  }
215 
217  fprintf(base_yyout, "));\n");
218  whenever_action(3);
219 }
static struct assignment * assignments
Definition: descriptor.c:18
static void drop_assignments(void)
Definition: descriptor.c:33
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
static void ECPGnumeric_lvalue(char *name)
Definition: descriptor.c:46
struct assignment * next
Definition: type.h:183
char * variable
Definition: type.h:181
FILE * base_yyout
void whenever_action(int)
Definition: output.c:64
#define PARSE_ERROR
Definition: extern.h:117
enum ECPGdtype value
Definition: type.h:182

◆ output_simple_statement()

void output_simple_statement ( char *  )

Definition at line 19 of file output.c.

References free, output_escaped_str(), and output_line_number().

20 {
21  output_escaped_str(stmt, false);
23  free(stmt);
24 }
void output_line_number(void)
Definition: output.c:10
static void output_escaped_str(char *cmd, bool quoted)
Definition: output.c:198
#define free(a)
Definition: header.h:65

◆ output_statement()

void output_statement ( char *  ,
int  ,
enum  ECPG_statement_type 
)

Definition at line 132 of file output.c.

References argsinsert, argsresult, auto_prepare, base_yyout, compat, dump_variables(), ecpg_statement_type_name, ECPGst_exec_immediate, ECPGst_execute, ECPGst_prepnormal, force_indicator, free, output_escaped_str(), questionmarks, reset_variables(), and whenever_action().

133 {
134  fprintf(base_yyout, "{ ECPGdo(__LINE__, %d, %d, %s, %d, ", compat, force_indicator, connection ? connection : "NULL", questionmarks);
135  if (st == ECPGst_execute || st == ECPGst_exec_immediate)
136  {
137  fprintf(base_yyout, "%s, %s, ", ecpg_statement_type_name[st], stmt);
138  }
139  else
140  {
141  if (st == ECPGst_prepnormal && auto_prepare)
142  fputs("ECPGst_prepnormal, \"", base_yyout);
143  else
144  fputs("ECPGst_normal, \"", base_yyout);
145 
146  output_escaped_str(stmt, false);
147  fputs("\", ", base_yyout);
148  }
149 
150  /* dump variables to C file */
152  fputs("ECPGt_EOIT, ", base_yyout);
154  fputs("ECPGt_EORT);", base_yyout);
155  reset_variables();
156 
157  whenever_action(whenever_mode | 2);
158  free(stmt);
159  if (connection != NULL)
160  free(connection);
161 }
static char * ecpg_statement_type_name[]
Definition: output.c:124
void whenever_action(int mode)
Definition: output.c:64
struct arguments * argsresult
Definition: variable.c:366
static void output_escaped_str(char *cmd, bool quoted)
Definition: output.c:198
struct arguments * argsinsert
Definition: variable.c:365
bool questionmarks
Definition: ecpg.c:19
FILE * base_yyout
enum COMPAT_MODE compat
Definition: ecpg.c:25
#define free(a)
Definition: header.h:65
bool auto_prepare
Definition: ecpg.c:21
bool force_indicator
Definition: ecpg.c:18
void reset_variables(void)
Definition: variable.c:369
void dump_variables(struct arguments *, int)
Definition: variable.c:438

◆ parser_init()

void parser_init ( void  )

◆ pg_attribute_noreturn()

void void pg_attribute_noreturn ( )

◆ push_assignment()

void push_assignment ( char *  ,
enum  ECPGdtype 
)

Definition at line 21 of file descriptor.c.

References assignments, mm_alloc(), value, and assignment::variable.

22 {
23  struct assignment *new = (struct assignment *) mm_alloc(sizeof(struct assignment));
24 
25  new->next = assignments;
26  new->variable = mm_alloc(strlen(var) + 1);
27  strcpy(new->variable, var);
28  new->value = value;
29  assignments = new;
30 }
static struct assignment * assignments
Definition: descriptor.c:18
void * mm_alloc(size_t)
static struct @121 value
char * variable
Definition: type.h:181

◆ remove_typedefs()

void remove_typedefs ( int  )

Definition at line 261 of file variable.c.

References typedefs::brace_level, ECPGt_struct, ECPGt_union, free, typedefs::name, typedefs::next, typedefs::struct_member_list, typedefs::type, this_type::type_enum, and types.

262 {
263  struct typedefs *p,
264  *prev;
265 
266  for (p = prev = types; p;)
267  {
268  if (p->brace_level >= brace_level)
269  {
270  /* remove it */
271  if (p == types)
272  prev = types = p->next;
273  else
274  prev->next = p->next;
275 
276  if (p->type->type_enum == ECPGt_struct || p->type->type_enum == ECPGt_union)
278  free(p->type);
279  free(p->name);
280  free(p);
281  if (prev == types)
282  p = types;
283  else
284  p = prev ? prev->next : NULL;
285  }
286  else
287  {
288  prev = p;
289  p = prev->next;
290  }
291  }
292 }
struct typedefs * types
Definition: ecpg.c:29
Definition: type.h:138
struct typedefs * next
Definition: type.h:144
struct this_type * type
Definition: type.h:141
char * name
Definition: type.h:140
int brace_level
Definition: type.h:143
#define free(a)
Definition: header.h:65
enum ECPGttype type_enum
Definition: type.h:111
struct ECPGstruct_member * struct_member_list
Definition: type.h:142

◆ remove_variable_from_list()

void remove_variable_from_list ( struct arguments **  list,
struct variable var 
)

Definition at line 409 of file variable.c.

References arguments::next, and arguments::variable.

410 {
411  struct arguments *p,
412  *prev = NULL;
413  bool found = false;
414 
415  for (p = *list; p; p = p->next)
416  {
417  if (p->variable == var)
418  {
419  found = true;
420  break;
421  }
422  prev = p;
423  }
424  if (found)
425  {
426  if (prev)
427  prev->next = p->next;
428  else
429  *list = p->next;
430  }
431 }
struct arguments * next
Definition: type.h:169
struct variable * variable
Definition: type.h:167

◆ remove_variables()

void remove_variables ( int  )

Definition at line 295 of file variable.c.

References allvariables, cursor::argsinsert, cursor::argsresult, variable::brace_level, cur, ECPGfree_type(), free, variable::name, variable::next, cursor::next, arguments::next, variable::type, and arguments::variable.

296 {
297  struct variable *p,
298  *prev;
299 
300  for (p = prev = allvariables; p;)
301  {
302  if (p->brace_level >= brace_level)
303  {
304  /* is it still referenced by a cursor? */
305  struct cursor *ptr;
306 
307  for (ptr = cur; ptr != NULL; ptr = ptr->next)
308  {
309  struct arguments *varptr,
310  *prevvar;
311 
312  for (varptr = prevvar = ptr->argsinsert; varptr != NULL; varptr = varptr->next)
313  {
314  if (p == varptr->variable)
315  {
316  /* remove from list */
317  if (varptr == ptr->argsinsert)
318  ptr->argsinsert = varptr->next;
319  else
320  prevvar->next = varptr->next;
321  }
322  }
323  for (varptr = prevvar = ptr->argsresult; varptr != NULL; varptr = varptr->next)
324  {
325  if (p == varptr->variable)
326  {
327  /* remove from list */
328  if (varptr == ptr->argsresult)
329  ptr->argsresult = varptr->next;
330  else
331  prevvar->next = varptr->next;
332  }
333  }
334  }
335 
336  /* remove it */
337  if (p == allvariables)
338  prev = allvariables = p->next;
339  else
340  prev->next = p->next;
341 
342  ECPGfree_type(p->type);
343  free(p->name);
344  free(p);
345  if (prev == allvariables)
346  p = allvariables;
347  else
348  p = prev ? prev->next : NULL;
349  }
350  else
351  {
352  prev = p;
353  p = prev->next;
354  }
355  }
356 }
int brace_level
Definition: type.h:161
struct cursor * next
Definition: type.h:135
enum ECPGttype type
Definition: extern.h:113
struct cursor * cur
Definition: ecpg.c:28
struct variable * next
Definition: extern.h:125
struct arguments * next
Definition: type.h:169
struct arguments * argsinsert
Definition: type.h:131
static struct variable * allvariables
Definition: variable.c:7
Definition: type.h:124
struct arguments * argsresult
Definition: type.h:133
#define free(a)
Definition: header.h:65
void ECPGfree_type(struct ECPGtype *type)
Definition: type.c:634
struct variable * variable
Definition: type.h:167
char * name
Definition: type.h:159

◆ reset_variables()

void reset_variables ( void  )

Definition at line 369 of file variable.c.

Referenced by output_statement().

370 {
371  argsinsert = NULL;
372  argsresult = NULL;
373 }
struct arguments * argsinsert
Definition: variable.c:365
struct arguments * argsresult
Definition: variable.c:366

◆ ScanCKeywordLookup()

const ScanKeyword* ScanCKeywordLookup ( const char *  )

Definition at line 64 of file c_keywords.c.

References difference(), lengthof, and ScanKeyword::name.

65 {
66  const ScanKeyword *low = &ScanCKeywords[0];
67  const ScanKeyword *high = &ScanCKeywords[lengthof(ScanCKeywords) - 1];
68 
69  while (low <= high)
70  {
71  const ScanKeyword *middle;
72  int difference;
73 
74  middle = low + (high - low) / 2;
75  difference = strcmp(middle->name, text);
76  if (difference == 0)
77  return middle;
78  else if (difference < 0)
79  low = middle + 1;
80  else
81  high = middle - 1;
82  }
83 
84  return NULL;
85 }
#define lengthof(array)
Definition: c.h:600
static const ScanKeyword ScanCKeywords[]
Definition: c_keywords.c:23
const char * name
Definition: keywords.h:26
Datum difference(PG_FUNCTION_ARGS)
Definition: c.h:487

◆ ScanECPGKeywordLookup()

const ScanKeyword* ScanECPGKeywordLookup ( const char *  text)

Definition at line 83 of file ecpg_keywords.c.

References lengthof, NumSQLScanKeywords, ScanKeywordLookup(), and SQLScanKeywords.

84 {
85  const ScanKeyword *res;
86 
87  /* First check SQL symbols defined by the backend. */
89  if (res)
90  return res;
91 
92  /* Try ECPG-specific keywords. */
94  if (res)
95  return res;
96 
97  return NULL;
98 }
const ScanKeyword * ScanKeywordLookup(const char *text, const ScanKeyword *keywords, int num_keywords)
Definition: keywords.c:64
#define lengthof(array)
Definition: c.h:600
static const ScanKeyword ECPGScanKeywords[]
Definition: ecpg_keywords.c:25
const ScanKeyword SQLScanKeywords[]
Definition: keywords.c:36
const int NumSQLScanKeywords
Definition: keywords.c:40
Definition: c.h:487

◆ scanner_finish()

void scanner_finish ( void  )

◆ scanner_init()

void scanner_init ( const char *  )

◆ sqlda_variable()

struct variable* sqlda_variable ( const char *  name)

Definition at line 340 of file descriptor.c.

References variable::brace_level, ECPGt_sqlda, mm_alloc(), mm_strdup(), variable::name, variable::next, and variable::type.

341 {
342  struct variable *p = (struct variable *) mm_alloc(sizeof(struct variable));
343 
344  p->name = mm_strdup(name);
345  p->type = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
346  p->type->type = ECPGt_sqlda;
347  p->type->size = NULL;
348  p->type->struct_sizeof = NULL;
349  p->type->u.element = NULL;
350  p->type->counter = 0;
351  p->brace_level = 0;
352  p->next = NULL;
353 
354  return p;
355 }
int brace_level
Definition: type.h:161
enum ECPGttype type
Definition: extern.h:113
struct variable * next
Definition: extern.h:125
Definition: type.h:17
void * mm_alloc(size_t)
const char * name
Definition: encode.c:521
char * mm_strdup(const char *)
Definition: type.c:25
char * name
Definition: type.h:159

◆ whenever_action()

void whenever_action ( int  )

Definition at line 64 of file output.c.

References base_yyout, when::code, output_line_number(), print_action(), W_NOTHING, and when_warn.

Referenced by output_deallocate_prepare_statement(), output_get_descr(), output_get_descr_header(), output_prepare_statement(), output_set_descr(), output_set_descr_header(), and output_statement().

65 {
66  if ((mode & 1) == 1 && when_nf.code != W_NOTHING)
67  {
69  fprintf(base_yyout, "\nif (sqlca.sqlcode == ECPG_NOT_FOUND) ");
70  print_action(&when_nf);
71  }
72  if (when_warn.code != W_NOTHING)
73  {
75  fprintf(base_yyout, "\nif (sqlca.sqlwarn[0] == 'W') ");
77  }
78  if (when_error.code != W_NOTHING)
79  {
81  fprintf(base_yyout, "\nif (sqlca.sqlcode < 0) ");
82  print_action(&when_error);
83  }
84 
85  if ((mode & 2) == 2)
86  fputc('}', base_yyout);
87 
89 }
static void print_action(struct when *w)
Definition: output.c:35
Definition: type.h:73
void output_line_number(void)
Definition: output.c:10
enum WHEN_TYPE code
Definition: type.h:84
FILE * base_yyout
struct when when_error when_nf when_warn
Definition: output.c:30

Variable Documentation

◆ argsinsert

struct arguments* argsinsert

Definition at line 365 of file variable.c.

Referenced by output_statement().

◆ argsresult

struct arguments* argsresult

Definition at line 366 of file variable.c.

Referenced by output_statement().

◆ auto_create_c

bool auto_create_c

Definition at line 16 of file ecpg.c.

Referenced by main().

◆ auto_prepare

bool auto_prepare

Definition at line 21 of file ecpg.c.

Referenced by main(), and output_statement().

◆ autocommit

bool autocommit

Definition at line 15 of file ecpg.c.

Referenced by ECPGconnect(), and main().

◆ base_yyin

FILE* base_yyin

Referenced by main().

◆ base_yylineno

int base_yylineno

Referenced by hashline_number().

◆ base_yyout

◆ base_yytext

char* base_yytext

Referenced by filtered_base_yylex().

◆ braces_open

int braces_open

◆ compat

◆ connection

◆ cur

◆ current_function

char* current_function

◆ defines

struct _defines* defines

Definition at line 30 of file ecpg.c.

Referenced by add_preprocessor_define(), and main().

◆ descriptor_index

char* descriptor_index

◆ descriptor_name

char* descriptor_name

◆ ecpg_internal_var

int ecpg_internal_var

Referenced by main().

◆ ecpg_no_indicator

struct ECPGtype ecpg_no_indicator

Referenced by ECPGdump_a_struct().

◆ force_indicator

bool force_indicator

Definition at line 18 of file ecpg.c.

Referenced by ecpg_do_prologue(), main(), and output_statement().

◆ include_paths

struct _include_path* include_paths

Definition at line 27 of file ecpg.c.

Referenced by add_include_path().

◆ input_filename

char* input_filename

Referenced by hashline_number(), and main().

◆ no_indicator

struct variable no_indicator

◆ NumSQLScanKeywords

const int NumSQLScanKeywords

Definition at line 40 of file keywords.c.

Referenced by ScanECPGKeywordLookup().

◆ output_filename

char* output_filename

Definition at line 23 of file ecpg.c.

Referenced by main().

◆ questionmarks

bool questionmarks

Definition at line 19 of file ecpg.c.

Referenced by ecpg_do_prologue(), main(), output_prepare_statement(), and output_statement().

◆ regression_mode

bool regression_mode

Definition at line 20 of file ecpg.c.

Referenced by main().

◆ ret_value

int ret_value

Definition at line 14 of file ecpg.c.

Referenced by main().

◆ SQLScanKeywords

const ScanKeyword SQLScanKeywords[]

Definition at line 36 of file keywords.c.

Referenced by ScanECPGKeywordLookup().

◆ struct_level

int struct_level

◆ struct_member_list

struct ECPGstruct_member* struct_member_list[STRUCT_DEPTH]

Referenced by main().

◆ system_includes

bool system_includes

Definition at line 17 of file ecpg.c.

Referenced by main().

◆ token_start

char * token_start

◆ types

◆ when_warn

struct when when_error when_nf when_warn

Definition at line 30 of file output.c.

Referenced by main(), and whenever_action().