2000-02-17 20:48:58 +01:00
|
|
|
/*
|
|
|
|
* functions needed for descriptor handling
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "postgres.h"
|
2000-04-12 19:17:23 +02:00
|
|
|
#include "extern.h"
|
2000-02-17 20:48:58 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* assignment handling function (descriptor)
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-02-17 20:48:58 +01:00
|
|
|
struct assignment *assignments;
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
void
|
|
|
|
push_assignment(char *var, enum ECPGdtype value)
|
2000-02-17 20:48:58 +01:00
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
struct assignment *new = (struct assignment *) mm_alloc(sizeof(struct assignment));
|
|
|
|
|
2000-02-18 15:34:12 +01:00
|
|
|
new->next = assignments;
|
2000-02-22 20:57:12 +01:00
|
|
|
new->variable = mm_alloc(strlen(var) + 1);
|
|
|
|
strcpy(new->variable, var);
|
|
|
|
new->value = value;
|
2000-02-18 15:34:12 +01:00
|
|
|
assignments = new;
|
2000-02-17 20:48:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drop_assignments(void)
|
2000-02-18 15:34:12 +01:00
|
|
|
{
|
|
|
|
while (assignments)
|
|
|
|
{
|
|
|
|
struct assignment *old_head = assignments;
|
2000-02-17 20:48:58 +01:00
|
|
|
|
2000-02-18 15:34:12 +01:00
|
|
|
assignments = old_head->next;
|
2000-02-17 20:48:58 +01:00
|
|
|
free(old_head->variable);
|
|
|
|
free(old_head);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
static void
|
|
|
|
ECPGnumeric_lvalue(FILE *f, char *name)
|
2000-02-18 15:34:12 +01:00
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
const struct variable *v = find_variable(name);
|
2000-02-17 20:48:58 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
switch (v->type->typ)
|
2000-02-17 20:48:58 +01:00
|
|
|
{
|
|
|
|
case ECPGt_short:
|
2000-04-12 19:17:23 +02:00
|
|
|
case ECPGt_int:
|
2000-02-17 20:48:58 +01:00
|
|
|
case ECPGt_long:
|
|
|
|
case ECPGt_unsigned_short:
|
|
|
|
case ECPGt_unsigned_int:
|
|
|
|
case ECPGt_unsigned_long:
|
2000-04-12 19:17:23 +02:00
|
|
|
fputs(name, yyout);
|
2000-02-17 20:48:58 +01:00
|
|
|
break;
|
|
|
|
default:
|
2000-04-12 19:17:23 +02:00
|
|
|
snprintf(errortext, sizeof errortext, "variable %s: numeric type needed"
|
|
|
|
,name);
|
|
|
|
mmerror(ET_ERROR, errortext);
|
2000-02-17 20:48:58 +01:00
|
|
|
break;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
2000-02-17 20:48:58 +01:00
|
|
|
}
|
|
|
|
|
2000-02-18 15:34:12 +01:00
|
|
|
/*
|
|
|
|
* descriptor name lookup
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-02-18 15:34:12 +01:00
|
|
|
static struct descriptor *descriptors;
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
void
|
|
|
|
add_descriptor(char *name, char *connection)
|
2000-02-18 15:34:12 +01:00
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
struct descriptor *new = (struct descriptor *) mm_alloc(sizeof(struct descriptor));
|
|
|
|
|
2000-02-22 20:57:12 +01:00
|
|
|
new->next = descriptors;
|
|
|
|
new->name = mm_alloc(strlen(name) + 1);
|
2000-04-12 19:17:23 +02:00
|
|
|
strcpy(new->name, name);
|
|
|
|
if (connection)
|
2000-02-22 20:57:12 +01:00
|
|
|
{
|
|
|
|
new->connection = mm_alloc(strlen(connection) + 1);
|
|
|
|
strcpy(new->connection, connection);
|
2000-02-18 15:34:12 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
else
|
|
|
|
new->connection = connection;
|
2000-02-22 20:57:12 +01:00
|
|
|
descriptors = new;
|
2000-02-18 15:34:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-04-12 19:17:23 +02:00
|
|
|
drop_descriptor(char *name, char *connection)
|
2000-02-18 15:34:12 +01:00
|
|
|
{
|
|
|
|
struct descriptor *i;
|
2000-04-12 19:17:23 +02:00
|
|
|
struct descriptor **lastptr = &descriptors;
|
|
|
|
|
|
|
|
for (i = descriptors; i; lastptr = &i->next, i = i->next)
|
2000-02-18 15:34:12 +01:00
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
if (!strcmp(name, i->name))
|
2000-02-18 15:34:12 +01:00
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
if ((!connection && !i->connection)
|
|
|
|
|| (connection && i->connection
|
|
|
|
&& !strcmp(connection, i->connection)))
|
2000-02-18 15:34:12 +01:00
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
*lastptr = i->next;
|
|
|
|
if (i->connection)
|
|
|
|
free(i->connection);
|
2000-02-18 15:34:12 +01:00
|
|
|
free(i->name);
|
|
|
|
free(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
snprintf(errortext, sizeof errortext, "unknown descriptor %s", name);
|
|
|
|
mmerror(ET_WARN, errortext);
|
2000-02-18 15:34:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct descriptor
|
2000-04-12 19:17:23 +02:00
|
|
|
*
|
|
|
|
lookup_descriptor(char *name, char *connection)
|
2000-02-18 15:34:12 +01:00
|
|
|
{
|
|
|
|
struct descriptor *i;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-02-22 20:57:12 +01:00
|
|
|
for (i = descriptors; i; i = i->next)
|
2000-02-18 15:34:12 +01:00
|
|
|
{
|
2000-02-22 20:57:12 +01:00
|
|
|
if (!strcmp(name, i->name))
|
2000-02-18 15:34:12 +01:00
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
if ((!connection && !i->connection)
|
|
|
|
|| (connection && i->connection
|
|
|
|
&& !strcmp(connection, i->connection)))
|
2000-02-18 15:34:12 +01:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2000-02-22 20:57:12 +01:00
|
|
|
snprintf(errortext, sizeof errortext, "unknown descriptor %s", name);
|
|
|
|
mmerror(ET_WARN, errortext);
|
2000-02-18 15:34:12 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:48:58 +01:00
|
|
|
void
|
|
|
|
output_get_descr_header(char *desc_name)
|
|
|
|
{
|
|
|
|
struct assignment *results;
|
|
|
|
|
2000-02-18 15:34:12 +01:00
|
|
|
fprintf(yyout, "{ ECPGget_desc_header(%d, \"%s\", &(", yylineno, desc_name);
|
|
|
|
for (results = assignments; results != NULL; results = results->next)
|
2000-02-17 20:48:58 +01:00
|
|
|
{
|
2000-02-22 20:57:12 +01:00
|
|
|
if (results->value == ECPGd_count)
|
2000-04-12 19:17:23 +02:00
|
|
|
ECPGnumeric_lvalue(yyout, results->variable);
|
2000-02-17 20:48:58 +01:00
|
|
|
else
|
2000-02-22 20:57:12 +01:00
|
|
|
{
|
|
|
|
snprintf(errortext, sizeof errortext, "unknown descriptor header item '%d'", results->value);
|
2000-02-18 15:34:12 +01:00
|
|
|
mmerror(ET_WARN, errortext);
|
2000-02-17 20:48:58 +01:00
|
|
|
}
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-02-18 15:34:12 +01:00
|
|
|
drop_assignments();
|
|
|
|
fprintf(yyout, "));\n");
|
|
|
|
whenever_action(3);
|
2000-02-17 20:48:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-02-22 20:57:12 +01:00
|
|
|
output_get_descr(char *desc_name, char *index)
|
2000-02-17 20:48:58 +01:00
|
|
|
{
|
|
|
|
struct assignment *results;
|
2000-02-22 20:57:12 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
fprintf(yyout, "{ ECPGget_desc(%d,\"%s\",%s,", yylineno, desc_name, index);
|
2000-02-22 20:57:12 +01:00
|
|
|
for (results = assignments; results != NULL; results = results->next)
|
2000-02-17 20:48:58 +01:00
|
|
|
{
|
2000-02-22 20:57:12 +01:00
|
|
|
const struct variable *v = find_variable(results->variable);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-02-22 20:57:12 +01:00
|
|
|
switch (results->value)
|
2000-02-17 20:48:58 +01:00
|
|
|
{
|
2000-02-22 20:57:12 +01:00
|
|
|
case ECPGd_nullable:
|
2000-04-12 19:17:23 +02:00
|
|
|
mmerror(ET_WARN, "nullable is always 1");
|
2000-02-22 20:57:12 +01:00
|
|
|
break;
|
|
|
|
case ECPGd_key_member:
|
2000-04-12 19:17:23 +02:00
|
|
|
mmerror(ET_WARN, "key_member is always 0");
|
2000-02-22 20:57:12 +01:00
|
|
|
break;
|
|
|
|
default:
|
2000-04-12 19:17:23 +02:00
|
|
|
break;
|
2000-02-17 20:48:58 +01:00
|
|
|
}
|
2000-02-22 20:57:12 +01:00
|
|
|
fprintf(yyout, "%s,", get_dtype(results->value));
|
|
|
|
ECPGdump_a_type(yyout, v->name, v->type, NULL, NULL, NULL, NULL);
|
2000-02-17 20:48:58 +01:00
|
|
|
}
|
|
|
|
drop_assignments();
|
2000-04-12 19:17:23 +02:00
|
|
|
fputs("ECPGd_EODT);\n", yyout);
|
|
|
|
|
|
|
|
whenever_action(2 | 1);
|
2000-02-17 20:48:58 +01:00
|
|
|
}
|