PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
descriptor.c File Reference
#include "postgres_fe.h"
#include "extern.h"
Include dependency graph for descriptor.c:

Go to the source code of this file.

Macros

#define MAX_DESCRIPTOR_NAMELEN   128
 

Functions

void push_assignment (char *var, enum ECPGdtype value)
 
static void drop_assignments (void)
 
static void ECPGnumeric_lvalue (char *name)
 
void add_descriptor (char *name, char *connection)
 
void drop_descriptor (char *name, char *connection)
 
struct descriptorlookup_descriptor (char *name, char *connection)
 
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)
 
static const char * descriptor_item_name (enum ECPGdtype itemcode)
 
void output_set_descr (char *desc_name, char *index)
 
struct variabledescriptor_variable (const char *name, int input)
 
struct variablesqlda_variable (const char *name)
 

Variables

static struct assignmentassignments
 
static struct descriptordescriptors
 

Macro Definition Documentation

#define MAX_DESCRIPTOR_NAMELEN   128

Definition at line 324 of file descriptor.c.

Referenced by descriptor_variable().

Function Documentation

void add_descriptor ( char *  name,
char *  connection 
)

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
static const char* descriptor_item_name ( enum ECPGdtype  itemcode)
static

Definition at line 222 of file descriptor.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, and NULL.

Referenced by output_set_descr().

223 {
224  switch (itemcode)
225  {
226  case ECPGd_cardinality:
227  return "CARDINALITY";
228  case ECPGd_count:
229  return "COUNT";
230  case ECPGd_data:
231  return "DATA";
232  case ECPGd_di_code:
233  return "DATETIME_INTERVAL_CODE";
234  case ECPGd_di_precision:
235  return "DATETIME_INTERVAL_PRECISION";
236  case ECPGd_indicator:
237  return "INDICATOR";
238  case ECPGd_key_member:
239  return "KEY_MEMBER";
240  case ECPGd_length:
241  return "LENGTH";
242  case ECPGd_name:
243  return "NAME";
244  case ECPGd_nullable:
245  return "NULLABLE";
246  case ECPGd_octet:
247  return "OCTET_LENGTH";
248  case ECPGd_precision:
249  return "PRECISION";
250  case ECPGd_ret_length:
251  return "RETURNED_LENGTH";
252  case ECPGd_ret_octet:
253  return "RETURNED_OCTET_LENGTH";
254  case ECPGd_scale:
255  return "SCALE";
256  case ECPGd_type:
257  return "TYPE";
258  default:
259  return NULL;
260  }
261 }
#define NULL
Definition: c.h:226
struct variable* descriptor_variable ( const char *  name,
int  input 
)

Definition at line 326 of file descriptor.c.

References ECPGt_descriptor, MAX_DESCRIPTOR_NAMELEN, NULL, 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
#define NULL
Definition: c.h:226
const char * name
Definition: encode.c:521
static void drop_assignments ( void  )
static

Definition at line 33 of file descriptor.c.

References assignments, free, assignment::next, and assignment::variable.

Referenced by output_get_descr(), output_get_descr_header(), output_set_descr(), and output_set_descr_header().

34 {
35  while (assignments)
36  {
37  struct assignment *old_head = assignments;
38 
39  assignments = old_head->next;
40  free(old_head->variable);
41  free(old_head);
42  }
43 }
static struct assignment * assignments
Definition: descriptor.c:18
struct assignment * next
Definition: type.h:184
char * variable
Definition: type.h:182
#define free(a)
Definition: header.h:60
void drop_descriptor ( char *  name,
char *  connection 
)

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:176
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:60
const char * name
Definition: encode.c:521
#define PARSE_ERROR
Definition: extern.h:117
int i
char * name
Definition: extern.h:92
static void ECPGnumeric_lvalue ( char *  name)
static

Definition at line 46 of file descriptor.c.

References base_yyout, ECPGt_const, ECPGt_int, ECPGt_long, ECPGt_long_long, ECPGt_short, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, ET_ERROR, find_variable(), mmerror(), PARSE_ERROR, and variable::type.

Referenced by output_get_descr_header(), and output_set_descr_header().

47 {
48  const struct variable *v = find_variable(name);
49 
50  switch (v->type->type)
51  {
52  case ECPGt_short:
53  case ECPGt_int:
54  case ECPGt_long:
55  case ECPGt_long_long:
57  case ECPGt_unsigned_int:
60  case ECPGt_const:
61  fputs(name, base_yyout);
62  break;
63  default:
64  mmerror(PARSE_ERROR, ET_ERROR, "variable \"%s\" must have a numeric type", name);
65  break;
66  }
67 }
struct variable * find_variable(char *)
Definition: variable.c:194
Definition: type.h:189
enum ECPGttype type
Definition: extern.h:113
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
FILE * base_yyout
const char * name
Definition: encode.c:521
#define PARSE_ERROR
Definition: extern.h:117
struct descriptor* lookup_descriptor ( char *  name,
char *  connection 
)

Definition at line 129 of file descriptor.c.

References descriptor::connection, ET_WARNING, i, mmerror(), descriptor::name, descriptor::next, NULL, 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:176
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 NULL
Definition: c.h:226
const char * name
Definition: encode.c:521
#define PARSE_ERROR
Definition: extern.h:117
int i
char * name
Definition: extern.h:92
void output_get_descr ( char *  desc_name,
char *  index 
)

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, NULL, 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:162
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
Definition: type.h:90
struct assignment * next
Definition: type.h:184
char * variable
Definition: type.h:182
FILE * base_yyout
#define free(a)
Definition: header.h:60
void whenever_action(int)
Definition: output.c:61
#define NULL
Definition: c.h:226
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_siz, const char *struct_sizeof, const char *ind_struct_sizeof)
Definition: type.c:239
#define PARSE_ERROR
Definition: extern.h:117
char * mm_strdup(const char *)
Definition: type.c:25
enum ECPGdtype value
Definition: type.h:183
char * name
Definition: type.h:160
const char * get_dtype(enum ECPGdtype)
Definition: type.c:672
void output_get_descr_header ( char *  desc_name)

Definition at line 151 of file descriptor.c.

References base_yyout, drop_assignments(), ECPGd_count, ECPGnumeric_lvalue(), ET_WARNING, mmerror(), assignment::next, NULL, 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:184
char * variable
Definition: type.h:182
FILE * base_yyout
void whenever_action(int)
Definition: output.c:61
#define NULL
Definition: c.h:226
#define PARSE_ERROR
Definition: extern.h:117
enum ECPGdtype value
Definition: type.h:183
void output_set_descr ( char *  desc_name,
char *  index 
)

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, NULL, 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:162
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
Definition: type.h:90
struct assignment * next
Definition: type.h:184
char * variable
Definition: type.h:182
FILE * base_yyout
void void mmfatal(int errorcode, const char *error,...) pg_attribute_printf(2
#define free(a)
Definition: header.h:60
void whenever_action(int)
Definition: output.c:61
#define NULL
Definition: c.h:226
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_siz, const char *struct_sizeof, const char *ind_struct_sizeof)
Definition: type.c:239
#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:183
char * name
Definition: type.h:160
const char * get_dtype(enum ECPGdtype)
Definition: type.c:672
void output_set_descr_header ( char *  desc_name)

Definition at line 203 of file descriptor.c.

References base_yyout, drop_assignments(), ECPGd_count, ECPGnumeric_lvalue(), ET_WARNING, mmerror(), assignment::next, NULL, 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:184
char * variable
Definition: type.h:182
FILE * base_yyout
void whenever_action(int)
Definition: output.c:61
#define NULL
Definition: c.h:226
#define PARSE_ERROR
Definition: extern.h:117
enum ECPGdtype value
Definition: type.h:183
void push_assignment ( char *  var,
enum ECPGdtype  value 
)

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 @76 value
static struct assignment * assignments
Definition: descriptor.c:18
void * mm_alloc(size_t)
char * variable
Definition: type.h:182
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, NULL, 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:162
enum ECPGttype type
Definition: extern.h:113
struct variable * next
Definition: extern.h:125
Definition: type.h:17
void * mm_alloc(size_t)
#define NULL
Definition: c.h:226
const char * name
Definition: encode.c:521
char * mm_strdup(const char *)
Definition: type.c:25
char * name
Definition: type.h:160

Variable Documentation

struct assignment* assignments
static

Definition at line 18 of file descriptor.c.

Referenced by drop_assignments(), and push_assignment().

struct descriptor* descriptors
static

Definition at line 73 of file descriptor.c.

Referenced by add_descriptor(), and drop_descriptor().