PostgreSQL Source Code  git master
preproc_extern.h File Reference
#include "common/keywords.h"
#include "type.h"
#include <limits.h>
Include dependency graph for preproc_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)
 
#define ORACLE_MODE   (compat == ECPG_COMPAT_ORACLE)
 

Enumerations

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

Functions

const char * get_dtype (enum ECPGdtype)
 
void lex_init (void)
 
void output_line_number (void)
 
void output_statement (char *stmt, int whenever_mode, enum ECPG_statement_type st)
 
void output_prepare_statement (char *name, char *stmt)
 
void output_deallocate_prepare_statement (char *name)
 
void output_simple_statement (char *stmt, int whenever_mode)
 
char * hashline_number (void)
 
int base_yyparse (void)
 
int base_yylex (void)
 
void base_yyerror (const char *error)
 
void * mm_alloc (size_t size)
 
char * mm_strdup (const char *string)
 
void mmerror (int error_code, enum errortype type, const char *error,...) pg_attribute_printf(3
 
void void mmfatal (int error_code, const char *error,...) pg_attribute_printf(2
 
void void pg_attribute_noreturn ()
 
void output_get_descr_header (char *desc_name)
 
void output_get_descr (char *desc_name, char *index)
 
void output_set_descr_header (char *desc_name)
 
void output_set_descr (char *desc_name, char *index)
 
void push_assignment (char *var, enum ECPGdtype value)
 
struct variablefind_variable (char *name)
 
void whenever_action (int mode)
 
void add_descriptor (char *name, char *connection)
 
void drop_descriptor (char *name, char *connection)
 
struct descriptorlookup_descriptor (char *name, char *connection)
 
struct variabledescriptor_variable (const char *name, int input)
 
struct variablesqlda_variable (const char *name)
 
void add_variable_to_head (struct arguments **list, struct variable *var, struct variable *ind)
 
void add_variable_to_tail (struct arguments **list, struct variable *var, struct variable *ind)
 
void remove_variable_from_list (struct arguments **list, struct variable *var)
 
void dump_variables (struct arguments *list, int mode)
 
struct typedefsget_typedef (const char *name, bool noerror)
 
void adjust_array (enum ECPGttype type_enum, char **dimension, char **length, char *type_dimension, char *type_index, int pointer_len, bool type_definition)
 
void reset_variables (void)
 
void check_indicator (struct ECPGtype *var)
 
void remove_typedefs (int brace_level)
 
void remove_variables (int brace_level)
 
struct variablenew_variable (const char *name, struct ECPGtype *type, int brace_level)
 
int ScanCKeywordLookup (const char *text)
 
int ScanECPGKeywordLookup (const char *text)
 
void parser_init (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_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 declared_listg_declared_list
 
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 uint16 SQLScanKeywordTokens []
 
enum COMPAT_MODE compat
 

Macro Definition Documentation

◆ EMPTY

#define EMPTY   mm_strdup("")

Definition at line 16 of file preproc_extern.h.

◆ ILLEGAL_OPTION

#define ILLEGAL_OPTION   1

Definition at line 119 of file preproc_extern.h.

◆ INDICATOR_NOT_ARRAY

#define INDICATOR_NOT_ARRAY   4

Definition at line 122 of file preproc_extern.h.

◆ INDICATOR_NOT_SIMPLE

#define INDICATOR_NOT_SIMPLE   7

Definition at line 125 of file preproc_extern.h.

◆ INDICATOR_NOT_STRUCT

#define INDICATOR_NOT_STRUCT   6

Definition at line 124 of file preproc_extern.h.

◆ INFORMIX_MODE

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

Definition at line 133 of file preproc_extern.h.

◆ NO_INCLUDE_FILE

#define NO_INCLUDE_FILE   2

Definition at line 120 of file preproc_extern.h.

◆ ORACLE_MODE

#define ORACLE_MODE   (compat == ECPG_COMPAT_ORACLE)

Definition at line 134 of file preproc_extern.h.

◆ OUT_OF_MEMORY

#define OUT_OF_MEMORY   5

Definition at line 123 of file preproc_extern.h.

◆ PARSE_ERROR

#define PARSE_ERROR   3

Definition at line 121 of file preproc_extern.h.

◆ STRUCT_DEPTH

#define STRUCT_DEPTH   128

Definition at line 15 of file preproc_extern.h.

Enumeration Type Documentation

◆ COMPAT_MODE

Enumerator
ECPG_COMPAT_PGSQL 
ECPG_COMPAT_INFORMIX 
ECPG_COMPAT_INFORMIX_SE 
ECPG_COMPAT_ORACLE 
ECPG_COMPAT_PGSQL 
ECPG_COMPAT_INFORMIX 
ECPG_COMPAT_INFORMIX_SE 
ECPG_COMPAT_ORACLE 

Definition at line 127 of file preproc_extern.h.

128 {
130 };
@ ECPG_COMPAT_PGSQL
@ ECPG_COMPAT_ORACLE
@ ECPG_COMPAT_INFORMIX
@ ECPG_COMPAT_INFORMIX_SE

Function Documentation

◆ add_descriptor()

void add_descriptor ( char *  name,
char *  connection 
)

Definition at line 76 of file descriptor.c.

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 }
const char * name
Definition: encode.c:571
static struct descriptor * descriptors
Definition: descriptor.c:73
char * connection
void * mm_alloc(size_t size)
Definition: type.c:13

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

◆ add_variable_to_head()

void add_variable_to_head ( struct arguments **  list,
struct variable var,
struct variable ind 
)

Definition at line 379 of file variable.c.

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:187
struct arguments * next
Definition: type.h:188
struct variable * variable
Definition: type.h:186

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

◆ add_variable_to_tail()

void add_variable_to_tail ( struct arguments **  list,
struct variable var,
struct variable ind 
)

Definition at line 391 of file variable.c.

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 }

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

◆ adjust_array()

void adjust_array ( enum ECPGttype  type_enum,
char **  dimension,
char **  length,
char *  type_dimension,
char *  type_index,
int  pointer_len,
bool  type_definition 
)

Definition at line 517 of file variable.c.

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

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

◆ base_yyerror()

void base_yyerror ( const char *  error)

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 var)

Definition at line 467 of file variable.c.

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 }
@ ECPGt_long_long
Definition: ecpgtype.h:45
@ ECPGt_short
Definition: ecpgtype.h:43
@ ECPGt_unsigned_short
Definition: ecpgtype.h:43
@ ECPGt_int
Definition: ecpgtype.h:44
@ ECPGt_long
Definition: ecpgtype.h:44
@ ECPGt_array
Definition: ecpgtype.h:56
@ ECPGt_unsigned_long
Definition: ecpgtype.h:44
@ ECPGt_unsigned_long_long
Definition: ecpgtype.h:45
@ ECPGt_unsigned_int
Definition: ecpgtype.h:44
void check_indicator(struct ECPGtype *var)
Definition: variable.c:467
void mmerror(int error_code, enum errortype type, const char *error,...) pg_attribute_printf(3
struct ECPGtype * type
Definition: type.h:13
struct ECPGstruct_member * next
Definition: type.h:14
union ECPGtype::@147 u
enum ECPGttype type
Definition: type.h:19
struct ECPGstruct_member * members
Definition: type.h:30
struct ECPGtype * element
Definition: type.h:28
@ ET_ERROR
Definition: type.h:207

References check_indicator(), 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.

Referenced by check_indicator().

◆ descriptor_variable()

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

Definition at line 337 of file descriptor.c.

338 {
339  static char descriptor_names[2][MAX_DESCRIPTOR_NAMELEN];
340  static struct ECPGtype descriptor_type = {ECPGt_descriptor, NULL, NULL, NULL, {NULL}, 0};
341  static struct variable varspace[2] = {
342  {descriptor_names[0], &descriptor_type, 0, NULL},
343  {descriptor_names[1], &descriptor_type, 0, NULL}
344  };
345 
346  strlcpy(descriptor_names[input], name, sizeof(descriptor_names[input]));
347  return &varspace[input];
348 }
@ ECPGt_descriptor
Definition: ecpgtype.h:59
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define MAX_DESCRIPTOR_NAMELEN
Definition: descriptor.c:335
Definition: type.h:18

References ECPGt_descriptor, MAX_DESCRIPTOR_NAMELEN, name, and strlcpy().

◆ drop_descriptor()

void drop_descriptor ( char *  name,
char *  connection 
)

Definition at line 99 of file descriptor.c.

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  free(i->connection);
117  free(i->name);
118  free(i);
119  return;
120  }
121  }
122  }
123  if (connection)
124  mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to connection %s does not exist", name, connection);
125  else
126  mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to the default connection does not exist", name);
127 }
#define free(a)
Definition: header.h:65
int i
Definition: isn.c:73
@ ET_WARNING
Definition: type.h:207

References descriptors, ET_WARNING, free, i, mmerror(), name, and PARSE_ERROR.

◆ dump_variables()

void dump_variables ( struct arguments list,
int  mode 
)

Definition at line 438 of file variable.c.

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
static PgChecksumMode mode
Definition: pg_checksums.c:65
FILE * base_yyout
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:241

References base_yyout, dump_variables(), ECPGdump_a_type(), free, sort-test::list, mm_strdup(), and mode.

Referenced by dump_variables(), and output_statement().

◆ filtered_base_yylex()

int filtered_base_yylex ( void  )

Definition at line 56 of file parser.c.

57 {
58  int cur_token;
59  int next_token;
60  YYSTYPE cur_yylval;
61  YYLTYPE cur_yylloc;
62  char *cur_yytext;
63 
64  /* Get next token --- we might already have it */
65  if (have_lookahead)
66  {
67  cur_token = lookahead_token;
68  base_yylval = lookahead_yylval;
69  base_yylloc = lookahead_yylloc;
71  have_lookahead = false;
72  }
73  else
74  cur_token = base_yylex();
75 
76  /*
77  * If this token isn't one that requires lookahead, just return it.
78  */
79  switch (cur_token)
80  {
81  case NOT:
82  case NULLS_P:
83  case WITH:
84  case UIDENT:
85  case USCONST:
86  break;
87  default:
88  return cur_token;
89  }
90 
91  /* Save and restore lexer output variables around the call */
92  cur_yylval = base_yylval;
93  cur_yylloc = base_yylloc;
94  cur_yytext = base_yytext;
95 
96  /* Get next token, saving outputs into lookahead variables */
98 
100  lookahead_yylval = base_yylval;
101  lookahead_yylloc = base_yylloc;
103 
104  base_yylval = cur_yylval;
105  base_yylloc = cur_yylloc;
106  base_yytext = cur_yytext;
107 
108  have_lookahead = true;
109 
110  /* Replace cur_token if needed, based on lookahead */
111  switch (cur_token)
112  {
113  case NOT:
114  /* Replace NOT by NOT_LA if it's followed by BETWEEN, IN, etc */
115  switch (next_token)
116  {
117  case BETWEEN:
118  case IN_P:
119  case LIKE:
120  case ILIKE:
121  case SIMILAR:
122  cur_token = NOT_LA;
123  break;
124  }
125  break;
126 
127  case NULLS_P:
128  /* Replace NULLS_P by NULLS_LA if it's followed by FIRST or LAST */
129  switch (next_token)
130  {
131  case FIRST_P:
132  case LAST_P:
133  cur_token = NULLS_LA;
134  break;
135  }
136  break;
137 
138  case WITH:
139  /* Replace WITH by WITH_LA if it's followed by TIME or ORDINALITY */
140  switch (next_token)
141  {
142  case TIME:
143  case ORDINALITY:
144  cur_token = WITH_LA;
145  break;
146  }
147  break;
148  case UIDENT:
149  case USCONST:
150  /* Look ahead for UESCAPE */
151  if (next_token == UESCAPE)
152  {
153  /* Yup, so get third token, which had better be SCONST */
154  const char *escstr;
155 
156  /*
157  * Again save and restore lexer output variables around the
158  * call
159  */
160  cur_yylval = base_yylval;
161  cur_yylloc = base_yylloc;
162  cur_yytext = base_yytext;
163 
164  /* Get third token */
166 
167  if (next_token != SCONST)
168  mmerror(PARSE_ERROR, ET_ERROR, "UESCAPE must be followed by a simple string literal");
169 
170  /*
171  * Save and check escape string, which the scanner returns
172  * with quotes
173  */
174  escstr = base_yylval.str;
175  if (strlen(escstr) != 3 || !check_uescapechar(escstr[1]))
176  mmerror(PARSE_ERROR, ET_ERROR, "invalid Unicode escape character");
177 
178  base_yylval = cur_yylval;
179  base_yylloc = cur_yylloc;
180  base_yytext = cur_yytext;
181 
182  /* Combine 3 tokens into 1 */
183  base_yylval.str = psprintf("%s UESCAPE %s", base_yylval.str, escstr);
184 
185  /* Clear have_lookahead, thereby consuming all three tokens */
186  have_lookahead = false;
187  }
188 
189  if (cur_token == UIDENT)
190  cur_token = IDENT;
191  else if (cur_token == USCONST)
192  cur_token = SCONST;
193  break;
194  }
195 
196  return cur_token;
197 }
int base_yylex(YYSTYPE *lvalp, YYLTYPE *llocp, core_yyscan_t yyscanner)
Definition: parser.c:111
static bool next_token(char **lineptr, char *buf, int bufsz, bool *initial_quote, bool *terminating_comma, int elevel, char **err_msg)
Definition: hba.c:199
static YYLTYPE lookahead_yylloc
Definition: parser.c:31
static bool have_lookahead
Definition: parser.c:28
static int lookahead_token
Definition: parser.c:29
static YYSTYPE lookahead_yylval
Definition: parser.c:30
static char * lookahead_yytext
Definition: parser.c:32
static bool check_uescapechar(unsigned char escape)
Definition: parser.c:206
char * base_yytext
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define YYLTYPE
Definition: scanner.h:44

References base_yylex(), base_yytext, check_uescapechar(), ET_ERROR, have_lookahead, lookahead_token, lookahead_yylloc, lookahead_yylval, lookahead_yytext, mmerror(), next_token(), PARSE_ERROR, psprintf(), and YYLTYPE.

◆ find_variable()

struct variable* find_variable ( char *  name)

Definition at line 194 of file variable.c.

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 }
static int32 next
Definition: blutils.c:219
static struct variable * find_struct(char *name, char *next, char *end)
Definition: variable.c:127
static struct variable * find_simple(char *name)
Definition: variable.c:178
struct variable * new_variable(const char *name, struct ECPGtype *type, int brace_level)
Definition: variable.c:10
char * c
enum ECPGttype type
int brace_level
Definition: type.h:180
struct ECPGtype * ECPGmake_array_type(struct ECPGtype *type, char *size)
Definition: type.c:111
struct ECPGtype * ECPGmake_simple_type(enum ECPGttype type, char *size, int counter)
Definition: type.c:96
struct ECPGtype * ECPGmake_struct_type(struct ECPGstruct_member *rm, enum ECPGttype type, char *type_name, char *struct_sizeof)
Definition: type.c:121

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

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

◆ get_dtype()

const char* get_dtype ( enum  ECPGdtype)

Definition at line 693 of file type.c.

694 {
695  switch (type)
696  {
697  case ECPGd_count:
698  return "ECPGd_countr";
699  break;
700  case ECPGd_data:
701  return "ECPGd_data";
702  break;
703  case ECPGd_di_code:
704  return "ECPGd_di_code";
705  break;
706  case ECPGd_di_precision:
707  return "ECPGd_di_precision";
708  break;
709  case ECPGd_indicator:
710  return "ECPGd_indicator";
711  break;
712  case ECPGd_key_member:
713  return "ECPGd_key_member";
714  break;
715  case ECPGd_length:
716  return "ECPGd_length";
717  break;
718  case ECPGd_name:
719  return "ECPGd_name";
720  break;
721  case ECPGd_nullable:
722  return "ECPGd_nullable";
723  break;
724  case ECPGd_octet:
725  return "ECPGd_octet";
726  break;
727  case ECPGd_precision:
728  return "ECPGd_precision";
729  break;
730  case ECPGd_ret_length:
731  return "ECPGd_ret_length";
732  case ECPGd_ret_octet:
733  return "ECPGd_ret_octet";
734  break;
735  case ECPGd_scale:
736  return "ECPGd_scale";
737  break;
738  case ECPGd_type:
739  return "ECPGd_type";
740  break;
741  case ECPGd_cardinality:
742  return "ECPGd_cardinality";
743  default:
744  mmerror(PARSE_ERROR, ET_ERROR, "unrecognized descriptor item code %d", type);
745  }
746 
747  return NULL;
748 }
@ ECPGd_scale
Definition: ecpgtype.h:86
@ ECPGd_precision
Definition: ecpgtype.h:83
@ ECPGd_length
Definition: ecpgtype.h:79
@ ECPGd_nullable
Definition: ecpgtype.h:81
@ ECPGd_di_precision
Definition: ecpgtype.h:76
@ ECPGd_type
Definition: ecpgtype.h:87
@ ECPGd_cardinality
Definition: ecpgtype.h:89
@ ECPGd_indicator
Definition: ecpgtype.h:77
@ ECPGd_ret_length
Definition: ecpgtype.h:84
@ ECPGd_di_code
Definition: ecpgtype.h:75
@ ECPGd_count
Definition: ecpgtype.h:73
@ ECPGd_name
Definition: ecpgtype.h:80
@ ECPGd_key_member
Definition: ecpgtype.h:78
@ ECPGd_octet
Definition: ecpgtype.h:82
@ ECPGd_ret_octet
Definition: ecpgtype.h:85
@ ECPGd_data
Definition: ecpgtype.h:74

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(), PARSE_ERROR, and generate_unaccent_rules::type.

Referenced by output_get_descr(), and output_set_descr().

◆ get_typedef()

struct typedefs* get_typedef ( const char *  name,
bool  noerror 
)

Definition at line 500 of file variable.c.

501 {
502  struct typedefs *this;
503 
504  for (this = types; this != NULL; this = this->next)
505  {
506  if (strcmp(this->name, name) == 0)
507  return this;
508  }
509 
510  if (!noerror)
511  mmfatal(PARSE_ERROR, "unrecognized data type name \"%s\"", name);
512 
513  return NULL;
514 }
struct typedefs * types
Definition: ecpg.c:29
Definition: type.h:158

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

◆ hashline_number()

char* hashline_number ( void  )

Definition at line 94 of file output.c.

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

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

Referenced by output_line_number().

◆ lex_init()

void lex_init ( void  )

Referenced by main().

◆ lookup_descriptor()

struct descriptor* lookup_descriptor ( char *  name,
char *  connection 
)

Definition at line 131 of file descriptor.c.

132 {
133  struct descriptor *i;
134 
135  if (name[0] != '"')
136  return NULL;
137 
138  for (i = descriptors; i; i = i->next)
139  {
140  if (strcmp(name, i->name) == 0)
141  {
142  if ((!connection && !i->connection)
143  || (connection && i->connection
144  && strcmp(connection, i->connection) == 0))
145  return i;
146  if (connection && !i->connection)
147  {
148  /* overwrite descriptor's connection */
149  i->connection = mm_strdup(connection);
150  return i;
151  }
152  }
153  }
154  if (connection)
155  mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to connection %s does not exist", name, connection);
156  else
157  mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to the default connection does not exist", name);
158  return NULL;
159 }

References descriptors, ET_WARNING, i, mm_strdup(), mmerror(), name, and PARSE_ERROR.

◆ mm_alloc()

void* mm_alloc ( size_t  size)

Definition at line 13 of file type.c.

14 {
15  void *ptr = malloc(size);
16 
17  if (ptr == NULL)
18  mmfatal(OUT_OF_MEMORY, "out of memory");
19 
20  return ptr;
21 }
#define malloc(a)
Definition: header.h:50
#define OUT_OF_MEMORY

References malloc, mmfatal(), and OUT_OF_MEMORY.

Referenced by add_descriptor(), add_include_path(), add_preprocessor_define(), add_variable_to_head(), add_variable_to_tail(), ECPGdump_a_simple(), ECPGdump_a_struct(), ECPGmake_simple_type(), ECPGmake_struct_member(), hashline_number(), main(), new_variable(), push_assignment(), and sqlda_variable().

◆ mm_strdup()

char* mm_strdup ( const char *  string)

Definition at line 25 of file type.c.

26 {
27  char *new = strdup(string);
28 
29  if (new == NULL)
30  mmfatal(OUT_OF_MEMORY, "out of memory");
31 
32  return new;
33 }

References mmfatal(), and OUT_OF_MEMORY.

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

◆ mmerror()

◆ mmfatal()

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

◆ new_variable()

struct variable* new_variable ( const char *  name,
struct ECPGtype type,
int  brace_level 
)

Definition at line 10 of file variable.c.

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 }
static struct variable * allvariables
Definition: variable.c:7
char * name
Definition: type.h:178
struct variable * next

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

Referenced by find_struct_member(), and find_variable().

◆ output_deallocate_prepare_statement()

void output_deallocate_prepare_statement ( char *  name)

Definition at line 182 of file output.c.

183 {
184  const char *con = connection ? connection : "NULL";
185 
186  if (strcmp(name, "all") != 0)
187  {
188  fprintf(base_yyout, "{ ECPGdeallocate(__LINE__, %d, %s, ", compat, con);
189  output_escaped_str(name, true);
190  fputs(");", base_yyout);
191  }
192  else
193  fprintf(base_yyout, "{ ECPGdeallocate_all(__LINE__, %d, %s);", compat, con);
194 
195  whenever_action(2);
196  free(name);
197 }
enum COMPAT_MODE compat
Definition: ecpg.c:25
void whenever_action(int mode)
Definition: output.c:66
static void output_escaped_str(char *str, bool quoted)
Definition: output.c:200
#define fprintf
Definition: port.h:242

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

◆ output_get_descr()

void output_get_descr ( char *  desc_name,
char *  index 
)

Definition at line 181 of file descriptor.c.

182 {
183  struct assignment *results;
184 
185  fprintf(base_yyout, "{ ECPGget_desc(__LINE__, %s, %s,", desc_name, index);
186  for (results = assignments; results != NULL; results = results->next)
187  {
188  const struct variable *v = find_variable(results->variable);
189  char *str_zero = mm_strdup("0");
190 
191  switch (results->value)
192  {
193  case ECPGd_nullable:
194  mmerror(PARSE_ERROR, ET_WARNING, "nullable is always 1");
195  break;
196  case ECPGd_key_member:
197  mmerror(PARSE_ERROR, ET_WARNING, "key_member is always 0");
198  break;
199  default:
200  break;
201  }
202  fprintf(base_yyout, "%s,", get_dtype(results->value));
204  NULL, NULL, -1, NULL, NULL, str_zero, NULL, NULL);
205  free(str_zero);
206  }
208  fputs("ECPGd_EODT);\n", base_yyout);
209 
210  whenever_action(2 | 1);
211 }
static struct assignment * assignments
Definition: descriptor.c:18
static void drop_assignments(void)
Definition: descriptor.c:33
struct variable * find_variable(char *name)
Definition: variable.c:194
const char * get_dtype(enum ECPGdtype)
Definition: type.c:693
char * variable
Definition: type.h:200
enum ECPGdtype value
Definition: type.h:201
struct assignment * next
Definition: type.h:202
Definition: type.h:95

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

◆ output_get_descr_header()

void output_get_descr_header ( char *  desc_name)

Definition at line 162 of file descriptor.c.

163 {
164  struct assignment *results;
165 
166  fprintf(base_yyout, "{ ECPGget_desc_header(__LINE__, %s, &(", desc_name);
167  for (results = assignments; results != NULL; results = results->next)
168  {
169  if (results->value == ECPGd_count)
170  ECPGnumeric_lvalue(results->variable);
171  else
172  mmerror(PARSE_ERROR, ET_WARNING, "descriptor header item \"%d\" does not exist", results->value);
173  }
174 
176  fprintf(base_yyout, "));\n");
177  whenever_action(3);
178 }
static void ECPGnumeric_lvalue(char *name)
Definition: descriptor.c:46

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

◆ output_line_number()

void output_line_number ( void  )

Definition at line 10 of file output.c.

11 {
12  char *line = hashline_number();
13 
14  fprintf(base_yyout, "%s", line);
15  free(line);
16 }
char * hashline_number(void)
Definition: output.c:94

References base_yyout, fprintf, free, and hashline_number().

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

◆ output_prepare_statement()

void output_prepare_statement ( char *  name,
char *  stmt 
)

Definition at line 170 of file output.c.

171 {
172  fprintf(base_yyout, "{ ECPGprepare(__LINE__, %s, %d, ", connection ? connection : "NULL", questionmarks);
173  output_escaped_str(name, true);
174  fputs(", ", base_yyout);
175  output_escaped_str(stmt, true);
176  fputs(");", base_yyout);
177  whenever_action(2);
178  free(name);
179 }
bool questionmarks
Definition: ecpg.c:19

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

◆ output_set_descr()

void output_set_descr ( char *  desc_name,
char *  index 
)

Definition at line 275 of file descriptor.c.

276 {
277  struct assignment *results;
278 
279  fprintf(base_yyout, "{ ECPGset_desc(__LINE__, %s, %s,", desc_name, index);
280  for (results = assignments; results != NULL; results = results->next)
281  {
282  const struct variable *v = find_variable(results->variable);
283 
284  switch (results->value)
285  {
286  case ECPGd_cardinality:
287  case ECPGd_di_code:
288  case ECPGd_di_precision:
289  case ECPGd_precision:
290  case ECPGd_scale:
291  mmfatal(PARSE_ERROR, "descriptor item \"%s\" is not implemented",
292  descriptor_item_name(results->value));
293  break;
294 
295  case ECPGd_key_member:
296  case ECPGd_name:
297  case ECPGd_nullable:
298  case ECPGd_octet:
299  case ECPGd_ret_length:
300  case ECPGd_ret_octet:
301  mmfatal(PARSE_ERROR, "descriptor item \"%s\" cannot be set",
302  descriptor_item_name(results->value));
303  break;
304 
305  case ECPGd_data:
306  case ECPGd_indicator:
307  case ECPGd_length:
308  case ECPGd_type:
309  {
310  char *str_zero = mm_strdup("0");
311 
312  fprintf(base_yyout, "%s,", get_dtype(results->value));
314  NULL, NULL, -1, NULL, NULL, str_zero, NULL, NULL);
315  free(str_zero);
316  }
317  break;
318 
319  default:
320  ;
321  }
322  }
324  fputs("ECPGd_EODT);\n", base_yyout);
325 
326  whenever_action(2 | 1);
327 }
static const char * descriptor_item_name(enum ECPGdtype itemcode)
Definition: descriptor.c:233

References assignments, 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(), fprintf, free, get_dtype(), mm_strdup(), mmfatal(), variable::name, assignment::next, PARSE_ERROR, variable::type, assignment::value, assignment::variable, and whenever_action().

◆ output_set_descr_header()

void output_set_descr_header ( char *  desc_name)

Definition at line 214 of file descriptor.c.

215 {
216  struct assignment *results;
217 
218  fprintf(base_yyout, "{ ECPGset_desc_header(__LINE__, %s, (int)(", desc_name);
219  for (results = assignments; results != NULL; results = results->next)
220  {
221  if (results->value == ECPGd_count)
222  ECPGnumeric_lvalue(results->variable);
223  else
224  mmerror(PARSE_ERROR, ET_WARNING, "descriptor header item \"%d\" does not exist", results->value);
225  }
226 
228  fprintf(base_yyout, "));\n");
229  whenever_action(3);
230 }

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

◆ output_simple_statement()

void output_simple_statement ( char *  stmt,
int  whenever_mode 
)

Definition at line 19 of file output.c.

20 {
21  output_escaped_str(stmt, false);
22  if (whenever_mode)
23  whenever_action(whenever_mode);
25  free(stmt);
26 }
void output_line_number(void)
Definition: output.c:10

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

◆ output_statement()

void output_statement ( char *  stmt,
int  whenever_mode,
enum ECPG_statement_type  st 
)

Definition at line 136 of file output.c.

137 {
138  fprintf(base_yyout, "{ ECPGdo(__LINE__, %d, %d, %s, %d, ", compat, force_indicator, connection ? connection : "NULL", questionmarks);
139 
140  if (st == ECPGst_prepnormal && !auto_prepare)
141  st = ECPGst_normal;
142 
143  /*
144  * In following cases, stmt is CSTRING or char_variable. They must be
145  * output directly. - prepared_name of EXECUTE without exprlist -
146  * execstring of EXECUTE IMMEDIATE
147  */
149  if (st == ECPGst_execute || st == ECPGst_exec_immediate)
150  fprintf(base_yyout, "%s, ", stmt);
151  else
152  {
153  fputs("\"", base_yyout);
154  output_escaped_str(stmt, false);
155  fputs("\", ", base_yyout);
156  }
157 
158  /* dump variables to C file */
160  fputs("ECPGt_EOIT, ", base_yyout);
162  fputs("ECPGt_EORT);", base_yyout);
163  reset_variables();
164 
165  whenever_action(whenever_mode | 2);
166  free(stmt);
167 }
bool auto_prepare
Definition: ecpg.c:21
bool force_indicator
Definition: ecpg.c:18
@ ECPGst_normal
Definition: ecpgtype.h:97
@ ECPGst_execute
Definition: ecpgtype.h:98
@ ECPGst_exec_immediate
Definition: ecpgtype.h:99
@ ECPGst_prepnormal
Definition: ecpgtype.h:100
static char * ecpg_statement_type_name[]
Definition: output.c:126
void dump_variables(struct arguments *list, int mode)
Definition: variable.c:438
void reset_variables(void)
Definition: variable.c:369
struct arguments * argsresult
Definition: variable.c:366
struct arguments * argsinsert
Definition: variable.c:365

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

◆ parser_init()

void parser_init ( void  )

◆ pg_attribute_noreturn()

void void pg_attribute_noreturn ( )

◆ push_assignment()

void push_assignment ( char *  var,
enum ECPGdtype  value 
)

Definition at line 21 of file descriptor.c.

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 @143 value

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

◆ remove_typedefs()

void remove_typedefs ( int  brace_level)

Definition at line 261 of file variable.c.

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 }
enum ECPGttype type_enum
Definition: type.h:123
int brace_level
Definition: type.h:162
char * name
Definition: type.h:159
struct ECPGstruct_member * struct_member_list
Definition: type.h:161
struct typedefs * next
Definition: type.h:163
struct this_type * type
Definition: type.h:160

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.

◆ remove_variable_from_list()

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

Definition at line 409 of file variable.c.

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 }

References sort-test::list, arguments::next, and arguments::variable.

◆ remove_variables()

void remove_variables ( int  brace_level)

Definition at line 295 of file variable.c.

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 }
struct cursor * cur
Definition: ecpg.c:28
Definition: type.h:137
struct arguments * argsinsert
Definition: type.h:143
struct cursor * next
Definition: type.h:147
struct arguments * argsresult
Definition: type.h:145
void ECPGfree_type(struct ECPGtype *type)
Definition: type.c:655

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.

◆ reset_variables()

void reset_variables ( void  )

Definition at line 369 of file variable.c.

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

References argsinsert, and argsresult.

Referenced by output_statement().

◆ ScanCKeywordLookup()

int ScanCKeywordLookup ( const char *  text)

Definition at line 36 of file c_keywords.c.

37 {
38  size_t len;
39  int h;
40  const char *kw;
41 
42  /*
43  * Reject immediately if too long to be any keyword. This saves useless
44  * hashing work on long strings.
45  */
46  len = strlen(text);
47  if (len > ScanCKeywords.max_kw_len)
48  return -1;
49 
50  /*
51  * Compute the hash function. Since it's a perfect hash, we need only
52  * match to the specific keyword it identifies.
53  */
54  h = ScanCKeywords_hash_func(text, len);
55 
56  /* An out-of-range result implies no match */
57  if (h < 0 || h >= ScanCKeywords.num_keywords)
58  return -1;
59 
60  kw = GetScanKeyword(h, &ScanCKeywords);
61 
62  if (strcmp(kw, text) == 0)
63  return ScanCKeywordTokens[h];
64 
65  return -1;
66 }
static const uint16 ScanCKeywordTokens[]
Definition: c_keywords.c:20
static const char * GetScanKeyword(int n, const ScanKeywordList *keywords)
Definition: kwlookup.h:39
const void size_t len
Definition: c.h:671

References GetScanKeyword(), len, and ScanCKeywordTokens.

◆ ScanECPGKeywordLookup()

int ScanECPGKeywordLookup ( const char *  text)

Definition at line 39 of file ecpg_keywords.c.

40 {
41  int kwnum;
42 
43  /* First check SQL symbols defined by the backend. */
45  if (kwnum >= 0)
46  return SQLScanKeywordTokens[kwnum];
47 
48  /* Try ECPG-specific keywords. */
49  kwnum = ScanKeywordLookup(text, &ScanECPGKeywords);
50  if (kwnum >= 0)
51  return ECPGScanKeywordTokens[kwnum];
52 
53  return -1;
54 }
static const uint16 ECPGScanKeywordTokens[]
Definition: ecpg_keywords.c:24
const uint16 SQLScanKeywordTokens[]
Definition: keywords.c:34
PGDLLIMPORT const ScanKeywordList ScanKeywords
int ScanKeywordLookup(const char *str, const ScanKeywordList *keywords)
Definition: kwlookup.c:38

References ECPGScanKeywordTokens, ScanKeywordLookup(), ScanKeywords, and SQLScanKeywordTokens.

◆ sqlda_variable()

struct variable* sqlda_variable ( const char *  name)

Definition at line 351 of file descriptor.c.

352 {
353  struct variable *p = (struct variable *) mm_alloc(sizeof(struct variable));
354 
355  p->name = mm_strdup(name);
356  p->type = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
357  p->type->type = ECPGt_sqlda;
358  p->type->size = NULL;
359  p->type->struct_sizeof = NULL;
360  p->type->u.element = NULL;
361  p->type->counter = 0;
362  p->brace_level = 0;
363  p->next = NULL;
364 
365  return p;
366 }
@ ECPGt_sqlda
Definition: ecpgtype.h:66

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

◆ whenever_action()

void whenever_action ( int  mode)

Definition at line 66 of file output.c.

67 {
68  if ((mode & 1) == 1 && when_nf.code != W_NOTHING)
69  {
71  fprintf(base_yyout, "\nif (sqlca.sqlcode == ECPG_NOT_FOUND) ");
72  print_action(&when_nf);
73  }
74  if (when_warn.code != W_NOTHING)
75  {
77  fprintf(base_yyout, "\nif (sqlca.sqlwarn[0] == 'W') ");
79  }
80  if (when_error.code != W_NOTHING)
81  {
83  fprintf(base_yyout, "\nif (sqlca.sqlcode < 0) ");
84  print_action(&when_error);
85  }
86 
87  if ((mode & 2) == 2)
88  fputc('}', base_yyout);
89 
91 }
struct when when_error when_nf when_warn
Definition: output.c:32
static void print_action(struct when *w)
Definition: output.c:37
enum WHEN_TYPE code
Definition: type.h:89
@ W_NOTHING
Definition: type.h:78

References base_yyout, when::code, fprintf, mode, 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(), output_simple_statement(), and output_statement().

Variable Documentation

◆ argsinsert

struct arguments* argsinsert
extern

Definition at line 365 of file variable.c.

Referenced by output_statement(), and reset_variables().

◆ argsresult

struct arguments* argsresult
extern

Definition at line 366 of file variable.c.

Referenced by output_statement(), and reset_variables().

◆ auto_create_c

bool auto_create_c

Definition at line 21 of file preproc_extern.h.

◆ auto_prepare

bool auto_prepare

Definition at line 26 of file preproc_extern.h.

◆ autocommit

bool autocommit
extern

Definition at line 15 of file ecpg.c.

Referenced by ECPGconnect(), and main().

◆ base_yyin

FILE* base_yyin
extern

Referenced by main().

◆ base_yylineno

int base_yylineno
extern

Referenced by hashline_number().

◆ base_yyout

◆ base_yytext

char* base_yytext
extern

Referenced by filtered_base_yylex().

◆ braces_open

int braces_open
extern

◆ compat

◆ connection

◆ cur

◆ current_function

char* current_function
extern

◆ defines

struct _defines* defines
extern

Definition at line 30 of file ecpg.c.

Referenced by add_preprocessor_define(), and main().

◆ descriptor_name

char* descriptor_name
extern

◆ ecpg_internal_var

int ecpg_internal_var

Definition at line 30 of file preproc_extern.h.

Referenced by main().

◆ ecpg_no_indicator

struct ECPGtype ecpg_no_indicator
extern

Referenced by ECPGdump_a_struct().

◆ force_indicator

bool force_indicator

Definition at line 23 of file preproc_extern.h.

◆ g_declared_list

struct declared_list* g_declared_list
extern

Definition at line 31 of file ecpg.c.

Referenced by main().

◆ include_paths

struct _include_path* include_paths
extern

Definition at line 27 of file ecpg.c.

Referenced by add_include_path(), and main().

◆ input_filename

char* input_filename
extern

Referenced by hashline_number(), and main().

◆ no_indicator

struct variable no_indicator
extern

◆ output_filename

char* output_filename
extern

Definition at line 23 of file ecpg.c.

Referenced by main().

◆ questionmarks

bool questionmarks

Definition at line 24 of file preproc_extern.h.

◆ regression_mode

bool regression_mode

Definition at line 25 of file preproc_extern.h.

◆ ret_value

int ret_value

Definition at line 28 of file preproc_extern.h.

◆ SQLScanKeywordTokens

const uint16 SQLScanKeywordTokens[]
extern

Definition at line 34 of file keywords.c.

Referenced by ScanECPGKeywordLookup().

◆ struct_level

int struct_level

Definition at line 29 of file preproc_extern.h.

◆ struct_member_list

struct ECPGstruct_member* struct_member_list[STRUCT_DEPTH]
extern

Referenced by main().

◆ system_includes

bool system_includes

Definition at line 22 of file preproc_extern.h.

◆ token_start

char * token_start

Definition at line 36 of file preproc_extern.h.

◆ types

◆ when_warn

struct when when_error when_nf when_warn
extern

Definition at line 19 of file output.c.

Referenced by main(), and whenever_action().