aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/preproc
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/ecpg/preproc')
-rw-r--r--src/interfaces/ecpg/preproc/descriptor.c104
-rw-r--r--src/interfaces/ecpg/preproc/ecpg.c56
-rw-r--r--src/interfaces/ecpg/preproc/ecpg_keywords.c3
-rw-r--r--src/interfaces/ecpg/preproc/extern.h39
-rw-r--r--src/interfaces/ecpg/preproc/output.c97
-rw-r--r--src/interfaces/ecpg/preproc/type.c36
-rw-r--r--src/interfaces/ecpg/preproc/type.h23
-rw-r--r--src/interfaces/ecpg/preproc/variable.c430
8 files changed, 416 insertions, 372 deletions
diff --git a/src/interfaces/ecpg/preproc/descriptor.c b/src/interfaces/ecpg/preproc/descriptor.c
index e55aa886cf8..792b286d8c0 100644
--- a/src/interfaces/ecpg/preproc/descriptor.c
+++ b/src/interfaces/ecpg/preproc/descriptor.c
@@ -3,18 +3,19 @@
*/
#include "postgres.h"
-#include "extern.h"
+#include "extern.h"
/*
* assignment handling function (descriptor)
*/
-
+
struct assignment *assignments;
-void push_assignment(char *var, enum ECPGdtype value)
+void
+push_assignment(char *var, enum ECPGdtype value)
{
- struct assignment *new = (struct assignment *)mm_alloc(sizeof(struct assignment));
-
+ struct assignment *new = (struct assignment *) mm_alloc(sizeof(struct assignment));
+
new->next = assignments;
new->variable = mm_alloc(strlen(var) + 1);
strcpy(new->variable, var);
@@ -35,91 +36,94 @@ drop_assignments(void)
}
}
-static void ECPGnumeric_lvalue(FILE *f,char *name)
+static void
+ECPGnumeric_lvalue(FILE *f, char *name)
{
- const struct variable *v=find_variable(name);
+ const struct variable *v = find_variable(name);
- switch(v->type->typ)
+ switch (v->type->typ)
{
case ECPGt_short:
- case ECPGt_int:
+ case ECPGt_int:
case ECPGt_long:
case ECPGt_unsigned_short:
case ECPGt_unsigned_int:
case ECPGt_unsigned_long:
- fputs(name,yyout);
+ fputs(name, yyout);
break;
default:
- snprintf(errortext,sizeof errortext,"variable %s: numeric type needed"
- ,name);
- mmerror(ET_ERROR,errortext);
+ snprintf(errortext, sizeof errortext, "variable %s: numeric type needed"
+ ,name);
+ mmerror(ET_ERROR, errortext);
break;
- }
+ }
}
/*
* descriptor name lookup
*/
-
+
static struct descriptor *descriptors;
-void add_descriptor(char *name,char *connection)
+void
+add_descriptor(char *name, char *connection)
{
- struct descriptor *new = (struct descriptor *)mm_alloc(sizeof(struct descriptor));
-
+ struct descriptor *new = (struct descriptor *) mm_alloc(sizeof(struct descriptor));
+
new->next = descriptors;
new->name = mm_alloc(strlen(name) + 1);
- strcpy(new->name,name);
- if (connection)
+ strcpy(new->name, name);
+ if (connection)
{
new->connection = mm_alloc(strlen(connection) + 1);
strcpy(new->connection, connection);
}
- else new->connection = connection;
+ else
+ new->connection = connection;
descriptors = new;
}
void
-drop_descriptor(char *name,char *connection)
+drop_descriptor(char *name, char *connection)
{
struct descriptor *i;
- struct descriptor **lastptr=&descriptors;
-
- for (i=descriptors;i;lastptr=&i->next,i=i->next)
+ struct descriptor **lastptr = &descriptors;
+
+ for (i = descriptors; i; lastptr = &i->next, i = i->next)
{
- if (!strcmp(name,i->name))
+ if (!strcmp(name, i->name))
{
- if ((!connection && !i->connection)
- || (connection && i->connection
- && !strcmp(connection,i->connection)))
+ if ((!connection && !i->connection)
+ || (connection && i->connection
+ && !strcmp(connection, i->connection)))
{
- *lastptr=i->next;
- if (i->connection) free(i->connection);
+ *lastptr = i->next;
+ if (i->connection)
+ free(i->connection);
free(i->name);
free(i);
return;
}
}
}
- snprintf(errortext,sizeof errortext,"unknown descriptor %s",name);
- mmerror(ET_WARN,errortext);
+ snprintf(errortext, sizeof errortext, "unknown descriptor %s", name);
+ mmerror(ET_WARN, errortext);
}
struct descriptor
-*lookup_descriptor(char *name, char *connection)
+ *
+lookup_descriptor(char *name, char *connection)
{
struct descriptor *i;
-
+
for (i = descriptors; i; i = i->next)
{
if (!strcmp(name, i->name))
{
- if ((!connection && !i->connection)
- || (connection && i->connection
- && !strcmp(connection,i->connection)))
- {
+ if ((!connection && !i->connection)
+ || (connection && i->connection
+ && !strcmp(connection, i->connection)))
return i;
- }
}
}
snprintf(errortext, sizeof errortext, "unknown descriptor %s", name);
@@ -136,14 +140,14 @@ output_get_descr_header(char *desc_name)
for (results = assignments; results != NULL; results = results->next)
{
if (results->value == ECPGd_count)
- ECPGnumeric_lvalue(yyout,results->variable);
+ ECPGnumeric_lvalue(yyout, results->variable);
else
{
snprintf(errortext, sizeof errortext, "unknown descriptor header item '%d'", results->value);
mmerror(ET_WARN, errortext);
}
}
-
+
drop_assignments();
fprintf(yyout, "));\n");
whenever_action(3);
@@ -154,27 +158,27 @@ output_get_descr(char *desc_name, char *index)
{
struct assignment *results;
- fprintf(yyout, "{ ECPGget_desc(%d,\"%s\",%s,", yylineno, desc_name, index);
+ fprintf(yyout, "{ ECPGget_desc(%d,\"%s\",%s,", yylineno, desc_name, index);
for (results = assignments; results != NULL; results = results->next)
{
const struct variable *v = find_variable(results->variable);
-
+
switch (results->value)
{
case ECPGd_nullable:
- mmerror(ET_WARN,"nullable is always 1");
+ mmerror(ET_WARN, "nullable is always 1");
break;
case ECPGd_key_member:
- mmerror(ET_WARN,"key_member is always 0");
+ mmerror(ET_WARN, "key_member is always 0");
break;
default:
- break;
+ break;
}
fprintf(yyout, "%s,", get_dtype(results->value));
ECPGdump_a_type(yyout, v->name, v->type, NULL, NULL, NULL, NULL);
}
drop_assignments();
- fputs("ECPGd_EODT);\n",yyout);
-
- whenever_action(2|1);
+ fputs("ECPGd_EODT);\n", yyout);
+
+ whenever_action(2 | 1);
}
diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c
index 31bc48752f7..1cc00dbcc7c 100644
--- a/src/interfaces/ecpg/preproc/ecpg.c
+++ b/src/interfaces/ecpg/preproc/ecpg.c
@@ -11,7 +11,8 @@
#include "extern.h"
-int ret_value = OK, autocommit = 0;
+int ret_value = OK,
+ autocommit = 0;
struct _include_path *include_paths = NULL;
struct cursor *cur = NULL;
struct typedefs *types = NULL;
@@ -85,8 +86,8 @@ main(int argc, char *const argv[])
verbose = true;
break;
case 'D':
- add_preprocessor_define(optarg);
- break;
+ add_preprocessor_define(optarg);
+ break;
default:
usage(argv[0]);
return ILLEGAL_OPTION;
@@ -102,7 +103,7 @@ main(int argc, char *const argv[])
fprintf(stderr, "End of search list.\n");
return OK;
}
-
+
if (optind >= argc) /* no files specified */
{
usage(argv[0]);
@@ -123,7 +124,7 @@ main(int argc, char *const argv[])
/* take care of relative paths */
ptr2ext = strrchr(input_filename, '/');
ptr2ext = (ptr2ext ? strrchr(ptr2ext, '.') : strrchr(input_filename, '.'));
-
+
/* no extension? */
if (ptr2ext == NULL)
{
@@ -137,7 +138,7 @@ main(int argc, char *const argv[])
ptr2ext[4] = '\0';
}
- if (out_option == 0) /* calculate the output name */
+ if (out_option == 0)/* calculate the output name */
{
output_filename = strdup(input_filename);
@@ -177,7 +178,8 @@ main(int argc, char *const argv[])
for (ptr = cur; ptr != NULL;)
{
struct cursor *this = ptr;
- struct arguments *l1, *l2;
+ struct arguments *l1,
+ *l2;
free(ptr->command);
free(ptr->connection);
@@ -198,26 +200,28 @@ main(int argc, char *const argv[])
cur = NULL;
/* remove non-pertinent old defines as well */
- while ( defines && !defines->pertinent ) {
- defptr = defines;
- defines = defines->next;
+ while (defines && !defines->pertinent)
+ {
+ defptr = defines;
+ defines = defines->next;
- free(defptr->new);
- free(defptr->old);
- free(defptr);
+ free(defptr->new);
+ free(defptr->old);
+ free(defptr);
}
- for (defptr = defines; defptr != NULL; defptr = defptr->next )
+ for (defptr = defines; defptr != NULL; defptr = defptr->next)
{
- struct _defines *this = defptr->next;
-
- if ( this && !this->pertinent ) {
- defptr->next = this->next;
+ struct _defines *this = defptr->next;
- free(this->new);
- free(this->old);
- free(this);
- }
+ if (this && !this->pertinent)
+ {
+ defptr->next = this->next;
+
+ free(this->new);
+ free(this->old);
+ free(this);
+ }
}
/* and old typedefs */
@@ -232,18 +236,18 @@ main(int argc, char *const argv[])
free(this);
}
types = NULL;
-
+
/* initialize whenever structures */
memset(&when_error, 0, sizeof(struct when));
memset(&when_nf, 0, sizeof(struct when));
memset(&when_warn, 0, sizeof(struct when));
-
+
/* and structure member lists */
memset(struct_member_list, 0, sizeof(struct_member_list));
-
+
/* finally the actual connection */
connection = NULL;
-
+
/* initialize lex */
lex_init();
diff --git a/src/interfaces/ecpg/preproc/ecpg_keywords.c b/src/interfaces/ecpg/preproc/ecpg_keywords.c
index 0a468c041ea..a1a0452e1cb 100644
--- a/src/interfaces/ecpg/preproc/ecpg_keywords.c
+++ b/src/interfaces/ecpg/preproc/ecpg_keywords.c
@@ -61,7 +61,8 @@ static ScanKeyword ScanKeywords[] = {
{"section", SQL_SECTION},
{"short", SQL_SHORT},
{"signed", SQL_SIGNED},
- {"sql",SQL_SQL}, /* strange thing, used for into sql descriptor MYDESC; */
+ {"sql", SQL_SQL}, /* strange thing, used for into sql
+ * descriptor MYDESC; */
{"sqlerror", SQL_SQLERROR},
{"sqlprint", SQL_SQLPRINT},
{"sqlwarning", SQL_SQLWARNING},
diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h
index bcdba111915..779985ac169 100644
--- a/src/interfaces/ecpg/preproc/extern.h
+++ b/src/interfaces/ecpg/preproc/extern.h
@@ -10,16 +10,19 @@
/* variables */
extern int braces_open,
- autocommit,
- ret_value,
- struct_level;
+ autocommit,
+ ret_value,
+ struct_level;
extern char *descriptor_index;
extern char *descriptor_name;
extern char *connection;
-extern char *input_filename;
-extern char *yytext, errortext[128];
-extern int yylineno, yyleng;
-extern FILE *yyin, *yyout;
+extern char *input_filename;
+extern char *yytext,
+ errortext[128];
+extern int yylineno,
+ yyleng;
+extern FILE *yyin,
+ *yyout;
extern struct _include_path *include_paths;
extern struct cursor *cur;
@@ -29,7 +32,9 @@ extern struct ECPGtype ecpg_no_indicator;
extern struct variable no_indicator;
extern struct arguments *argsinsert;
extern struct arguments *argsresult;
-extern struct when when_error, when_nf, when_warn;
+extern struct when when_error,
+ when_nf,
+ when_warn;
extern struct ECPGstruct_member *struct_member_list[STRUCT_DEPTH];
extern struct descriptor *descriptors;
@@ -47,19 +52,19 @@ extern int yylex(void);
extern void yyerror(char *);
extern void *mm_alloc(size_t), *mm_realloc(void *, size_t);
extern char *mm_strdup(const char *);
-extern void mmerror(enum errortype, char * );
+extern void mmerror(enum errortype, char *);
extern ScanKeyword *ScanECPGKeywordLookup(char *);
extern ScanKeyword *ScanCKeywordLookup(char *);
extern void output_get_descr_header(char *);
extern void output_get_descr(char *, char *);
extern void push_assignment(char *, enum ECPGdtype);
-extern struct variable * find_variable(char *);
+extern struct variable *find_variable(char *);
extern void whenever_action(int);
-extern void add_descriptor(char *,char *);
-extern void drop_descriptor(char *,char *);
-extern struct descriptor *lookup_descriptor(char *,char *);
-extern void add_variable(struct arguments ** , struct variable * , struct variable *);
-extern void append_variable(struct arguments ** , struct variable * , struct variable *);
+extern void add_descriptor(char *, char *);
+extern void drop_descriptor(char *, char *);
+extern struct descriptor *lookup_descriptor(char *, char *);
+extern void add_variable(struct arguments **, struct variable *, struct variable *);
+extern void append_variable(struct arguments **, struct variable *, struct variable *);
extern void dump_variables(struct arguments *, int);
extern struct typedefs *get_typedef(char *);
extern void adjust_array(enum ECPGttype, int *, int *, int, int, bool);
@@ -67,13 +72,13 @@ extern void reset_variables(void);
extern void check_indicator(struct ECPGtype *);
extern void remove_variables(int);
extern struct variable *new_variable(const char *, struct ECPGtype *);
-
+
/* return codes */
#define OK 0
#define PARSE_ERROR -1
#define ILLEGAL_OPTION -2
-#define INDICATOR_NOT_ARRAY -3
+#define INDICATOR_NOT_ARRAY -3
#define NO_INCLUDE_FILE ENOENT
#define OUT_OF_MEMORY ENOMEM
diff --git a/src/interfaces/ecpg/preproc/output.c b/src/interfaces/ecpg/preproc/output.c
index 760751affd3..7fe282586f6 100644
--- a/src/interfaces/ecpg/preproc/output.c
+++ b/src/interfaces/ecpg/preproc/output.c
@@ -6,74 +6,83 @@
void
output_line_number()
{
- if (input_filename)
- fprintf(yyout, "\n#line %d \"%s\"\n", yylineno, input_filename);
+ if (input_filename)
+ fprintf(yyout, "\n#line %d \"%s\"\n", yylineno, input_filename);
}
void
output_simple_statement(char *cmd)
{
- int i, j = strlen(cmd);;
-
+ int i,
+ j = strlen(cmd);;
+
/* do this char by char as we have to filter '\"' */
- for (i = 0; i < j; i++) {
+ for (i = 0; i < j; i++)
+ {
if (cmd[i] != '"')
fputc(cmd[i], yyout);
else
fputs("\\\"", yyout);
}
output_line_number();
- free(cmd);
+ free(cmd);
}
/*
* store the whenever action here
*/
-struct when when_error, when_nf, when_warn;
+struct when when_error,
+ when_nf,
+ when_warn;
static void
-print_action(struct when *w)
+print_action(struct when * w)
{
switch (w->code)
{
- case W_SQLPRINT: fprintf(yyout, "sqlprint();");
- break;
- case W_GOTO: fprintf(yyout, "goto %s;", w->command);
- break;
- case W_DO: fprintf(yyout, "%s;", w->command);
- break;
- case W_STOP: fprintf(yyout, "exit (1);");
- break;
- case W_BREAK: fprintf(yyout, "break;");
- break;
- default: fprintf(yyout, "{/* %d not implemented yet */}", w->code);
- break;
+ case W_SQLPRINT:fprintf(yyout, "sqlprint();");
+ break;
+ case W_GOTO:
+ fprintf(yyout, "goto %s;", w->command);
+ break;
+ case W_DO:
+ fprintf(yyout, "%s;", w->command);
+ break;
+ case W_STOP:
+ fprintf(yyout, "exit (1);");
+ break;
+ case W_BREAK:
+ fprintf(yyout, "break;");
+ break;
+ default:
+ fprintf(yyout, "{/* %d not implemented yet */}", w->code);
+ break;
}
}
void
whenever_action(int mode)
{
- if ((mode&1) == 1 && when_nf.code != W_NOTHING)
+ if ((mode & 1) == 1 && when_nf.code != W_NOTHING)
{
output_line_number();
fprintf(yyout, "\nif (sqlca.sqlcode == ECPG_NOT_FOUND) ");
print_action(&when_nf);
}
if (when_warn.code != W_NOTHING)
- {
+ {
output_line_number();
- fprintf(yyout, "\nif (sqlca.sqlwarn[0] == 'W') ");
+ fprintf(yyout, "\nif (sqlca.sqlwarn[0] == 'W') ");
print_action(&when_warn);
- }
+ }
if (when_error.code != W_NOTHING)
- {
+ {
output_line_number();
- fprintf(yyout, "\nif (sqlca.sqlcode < 0) ");
+ fprintf(yyout, "\nif (sqlca.sqlcode < 0) ");
print_action(&when_error);
- }
+ }
- if ((mode&2) == 2)
+ if ((mode & 2) == 2)
fputc('}', yyout);
output_line_number();
@@ -82,30 +91,33 @@ whenever_action(int mode)
char *
hashline_number(void)
{
- if (input_filename)
- {
- char* line = mm_alloc(strlen("\n#line %d \"%s\"\n") + 21 + strlen(input_filename));
- sprintf(line, "\n#line %d \"%s\"\n", yylineno, input_filename);
+ if (input_filename)
+ {
+ char *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + 21 + strlen(input_filename));
- return line;
- }
+ sprintf(line, "\n#line %d \"%s\"\n", yylineno, input_filename);
- return EMPTY;
+ return line;
+ }
+
+ return EMPTY;
}
void
-output_statement(char * stmt, int mode, char *descriptor, char *con)
+output_statement(char *stmt, int mode, char *descriptor, char *con)
{
- int i, j = strlen(stmt);
+ int i,
+ j = strlen(stmt);
if (descriptor == NULL)
fprintf(yyout, "{ ECPGdo(__LINE__, %s, \"", con ? con : "NULL");
else
- fprintf(yyout, "{ ECPGdo_descriptor(__LINE__, %s, \"%s\", \"",
- con ? con : "NULL", descriptor);
+ fprintf(yyout, "{ ECPGdo_descriptor(__LINE__, %s, \"%s\", \"",
+ con ? con : "NULL", descriptor);
/* do this char by char as we have to filter '\"' */
- for (i = 0; i < j; i++) {
+ for (i = 0; i < j; i++)
+ {
if (stmt[i] != '"')
fputc(stmt[i], yyout);
else
@@ -115,7 +127,7 @@ output_statement(char * stmt, int mode, char *descriptor, char *con)
if (descriptor == NULL)
{
fputs("\", ", yyout);
-
+
/* dump variables to C file */
dump_variables(argsinsert, 1);
fputs("ECPGt_EOIT, ", yyout);
@@ -125,7 +137,7 @@ output_statement(char * stmt, int mode, char *descriptor, char *con)
}
else
fputs("\");", yyout);
-
+
mode |= 2;
whenever_action(mode);
free(stmt);
@@ -134,4 +146,3 @@ output_statement(char * stmt, int mode, char *descriptor, char *con)
if (connection != NULL)
free(connection);
}
-
diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c
index 95c79e3f09e..8d292e11098 100644
--- a/src/interfaces/ecpg/preproc/type.c
+++ b/src/interfaces/ecpg/preproc/type.c
@@ -124,7 +124,7 @@ get_type(enum ECPGttype typ)
{
switch (typ)
{
- case ECPGt_char:
+ case ECPGt_char:
return ("ECPGt_char");
break;
case ECPGt_unsigned_char:
@@ -163,7 +163,7 @@ get_type(enum ECPGttype typ)
return ("ECPGt_NO_INDICATOR");
break;
case ECPGt_char_variable: /* string that should not be
- * quoted */
+ * quoted */
return ("ECPGt_char_variable");
break;
default:
@@ -200,10 +200,10 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * typ, const char *in
{
switch (typ->typ)
{
- case ECPGt_array:
+ case ECPGt_array:
switch (typ->u.element->typ)
{
- case ECPGt_array:
+ case ECPGt_array:
yyerror("No nested arrays allowed (except strings)"); /* array of array */
break;
case ECPGt_struct:
@@ -269,7 +269,11 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
switch (typ)
{
case ECPGt_varchar:
- /* we have to use the pointer except for arrays with given bounds */
+
+ /*
+ * we have to use the pointer except for arrays with given
+ * bounds
+ */
if (arrsize > 0)
sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
else
@@ -280,7 +284,11 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
case ECPGt_char:
case ECPGt_unsigned_char:
case ECPGt_char_variable:
- /* we have to use the pointer except for arrays with given bounds */
+
+ /*
+ * we have to use the pointer except for arrays with given
+ * bounds
+ */
if (varcharsize > 1 || arrsize > 0)
sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
else
@@ -289,7 +297,11 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
sprintf(offset, "%ld*sizeof(char)", varcharsize == 0 ? 1 : varcharsize);
break;
default:
- /* we have to use the pointer except for arrays with given bounds */
+
+ /*
+ * we have to use the pointer except for arrays with given
+ * bounds
+ */
if (arrsize > 0)
sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
else
@@ -375,10 +387,10 @@ ECPGfree_type(struct ECPGtype * typ)
{
switch (typ->typ)
{
- case ECPGt_array:
+ case ECPGt_array:
switch (typ->u.element->typ)
{
- case ECPGt_array:
+ case ECPGt_array:
yyerror("internal error, found multi-dimensional array\n");
break;
case ECPGt_struct:
@@ -412,7 +424,7 @@ get_dtype(enum ECPGdtype typ)
{
switch (typ)
{
- case ECPGd_count:
+ case ECPGd_count:
return ("ECPGd_countr");
break;
case ECPGd_data:
@@ -450,10 +462,10 @@ get_dtype(enum ECPGdtype typ)
case ECPGd_ret_octet:
return ("ECPGd_ret_octet");
break;
- case ECPGd_scale:
+ case ECPGd_scale:
return ("ECPGd_scale");
break;
- case ECPGd_type:
+ case ECPGd_type:
return ("ECPGd_type");
break;
default:
diff --git a/src/interfaces/ecpg/preproc/type.h b/src/interfaces/ecpg/preproc/type.h
index 29525c392c3..7ce1e892870 100644
--- a/src/interfaces/ecpg/preproc/type.h
+++ b/src/interfaces/ecpg/preproc/type.h
@@ -119,7 +119,7 @@ struct _defines
{
char *old;
char *new;
- int pertinent;
+ int pertinent;
struct _defines *next;
};
@@ -141,22 +141,25 @@ struct arguments
struct descriptor
{
- char *name;
- char *connection;
+ char *name;
+ char *connection;
struct descriptor *next;
};
struct assignment
-{
- char *variable;
- enum ECPGdtype value;
- struct assignment *next;
+{
+ char *variable;
+ enum ECPGdtype value;
+ struct assignment *next;
};
-enum errortype {ET_WARN, ET_ERROR, ET_FATAL};
+enum errortype
+{
+ ET_WARN, ET_ERROR, ET_FATAL
+};
struct fetch_desc
{
- char *str;
- char *name;
+ char *str;
+ char *name;
};
diff --git a/src/interfaces/ecpg/preproc/variable.c b/src/interfaces/ecpg/preproc/variable.c
index 3de45350b1c..f3d2dca0597 100644
--- a/src/interfaces/ecpg/preproc/variable.c
+++ b/src/interfaces/ecpg/preproc/variable.c
@@ -2,174 +2,177 @@
#include "extern.h"
-struct variable * allvariables = NULL;
+struct variable *allvariables = NULL;
struct variable *
-new_variable(const char * name, struct ECPGtype * type)
+new_variable(const char *name, struct ECPGtype * type)
{
- struct variable * p = (struct variable*) mm_alloc(sizeof(struct variable));
+ struct variable *p = (struct variable *) mm_alloc(sizeof(struct variable));
- p->name = mm_strdup(name);
- p->type = type;
- p->brace_level = braces_open;
+ p->name = mm_strdup(name);
+ p->type = type;
+ p->brace_level = braces_open;
- p->next = allvariables;
- allvariables = p;
+ p->next = allvariables;
+ allvariables = p;
- return(p);
+ return (p);
}
static struct variable *
-find_struct_member(char *name, char *str, struct ECPGstruct_member *members)
+find_struct_member(char *name, char *str, struct ECPGstruct_member * members)
{
- char *next = strchr(++str, '.'), c = '\0';
+ char *next = strchr(++str, '.'),
+ c = '\0';
- if (next != NULL)
- {
- c = *next;
- *next = '\0';
- }
+ if (next != NULL)
+ {
+ c = *next;
+ *next = '\0';
+ }
- for (; members; members = members->next)
- {
- if (strcmp(members->name, str) == 0)
+ for (; members; members = members->next)
{
- if (c == '\0')
+ if (strcmp(members->name, str) == 0)
{
- /* found the end */
- switch (members->typ->typ)
+ if (c == '\0')
{
- case ECPGt_array:
- return(new_variable(name, ECPGmake_array_type(members->typ->u.element, members->typ->size)));
- case ECPGt_struct:
- case ECPGt_union:
- return(new_variable(name, ECPGmake_struct_type(members->typ->u.members, members->typ->typ)));
- default:
- return(new_variable(name, ECPGmake_simple_type(members->typ->typ, members->typ->size)));
+ /* found the end */
+ switch (members->typ->typ)
+ {
+ case ECPGt_array:
+ return (new_variable(name, ECPGmake_array_type(members->typ->u.element, members->typ->size)));
+ case ECPGt_struct:
+ case ECPGt_union:
+ return (new_variable(name, ECPGmake_struct_type(members->typ->u.members, members->typ->typ)));
+ default:
+ return (new_variable(name, ECPGmake_simple_type(members->typ->typ, members->typ->size)));
+ }
}
- }
- else
- {
- *next = c;
- if (c == '-')
+ else
{
- next++;
- return(find_struct_member(name, next, members->typ->u.element->u.members));
+ *next = c;
+ if (c == '-')
+ {
+ next++;
+ return (find_struct_member(name, next, members->typ->u.element->u.members));
+ }
+ else
+ return (find_struct_member(name, next, members->typ->u.members));
}
- else return(find_struct_member(name, next, members->typ->u.members));
}
}
- }
- return(NULL);
+ return (NULL);
}
static struct variable *
-find_struct(char * name, char *next)
+find_struct(char *name, char *next)
{
- struct variable * p;
- char c = *next;
-
- /* first get the mother structure entry */
- *next = '\0';
- p = find_variable(name);
-
- if (c == '-')
- {
- if (p->type->typ != ECPGt_struct && p->type->typ != ECPGt_union)
- {
- sprintf(errortext, "variable %s is not a pointer", name);
- mmerror(ET_FATAL, errortext);
- }
-
- if (p->type->u.element->typ != ECPGt_struct && p->type->u.element->typ != ECPGt_union)
- {
- sprintf(errortext, "variable %s is not a pointer to a structure or a union", name);
- mmerror(ET_FATAL, errortext);
- }
-
- /* restore the name, we will need it later on */
- *next = c;
- next++;
-
- return find_struct_member(name, next, p->type->u.element->u.members);
- }
- else
- {
- if (p->type->typ != ECPGt_struct && p->type->typ != ECPGt_union)
+ struct variable *p;
+ char c = *next;
+
+ /* first get the mother structure entry */
+ *next = '\0';
+ p = find_variable(name);
+
+ if (c == '-')
{
- sprintf(errortext, "variable %s is neither a structure nor a union", name);
- mmerror(ET_FATAL, errortext);
+ if (p->type->typ != ECPGt_struct && p->type->typ != ECPGt_union)
+ {
+ sprintf(errortext, "variable %s is not a pointer", name);
+ mmerror(ET_FATAL, errortext);
+ }
+
+ if (p->type->u.element->typ != ECPGt_struct && p->type->u.element->typ != ECPGt_union)
+ {
+ sprintf(errortext, "variable %s is not a pointer to a structure or a union", name);
+ mmerror(ET_FATAL, errortext);
+ }
+
+ /* restore the name, we will need it later on */
+ *next = c;
+ next++;
+
+ return find_struct_member(name, next, p->type->u.element->u.members);
}
+ else
+ {
+ if (p->type->typ != ECPGt_struct && p->type->typ != ECPGt_union)
+ {
+ sprintf(errortext, "variable %s is neither a structure nor a union", name);
+ mmerror(ET_FATAL, errortext);
+ }
- /* restore the name, we will need it later on */
- *next = c;
+ /* restore the name, we will need it later on */
+ *next = c;
- return find_struct_member(name, next, p->type->u.members);
- }
+ return find_struct_member(name, next, p->type->u.members);
+ }
}
static struct variable *
-find_simple(char * name)
+find_simple(char *name)
{
- struct variable * p;
+ struct variable *p;
- for (p = allvariables; p; p = p->next)
- {
- if (strcmp(p->name, name) == 0)
- return p;
- }
+ for (p = allvariables; p; p = p->next)
+ {
+ if (strcmp(p->name, name) == 0)
+ return p;
+ }
- return(NULL);
+ return (NULL);
}
/* Note that this function will end the program in case of an unknown */
/* variable */
struct variable *
-find_variable(char * name)
+find_variable(char *name)
{
- char * next;
- struct variable * p;
-
- if ((next = strchr(name, '.')) != NULL)
- p = find_struct(name, next);
- else if ((next = strstr(name, "->")) != NULL)
- p = find_struct(name, next);
- else
- p = find_simple(name);
-
- if (p == NULL)
- {
- sprintf(errortext, "The variable %s is not declared", name);
- mmerror(ET_FATAL, errortext);
- }
-
- return(p);
+ char *next;
+ struct variable *p;
+
+ if ((next = strchr(name, '.')) != NULL)
+ p = find_struct(name, next);
+ else if ((next = strstr(name, "->")) != NULL)
+ p = find_struct(name, next);
+ else
+ p = find_simple(name);
+
+ if (p == NULL)
+ {
+ sprintf(errortext, "The variable %s is not declared", name);
+ mmerror(ET_FATAL, errortext);
+ }
+
+ return (p);
}
void
remove_variables(int brace_level)
{
- struct variable * p, *prev;
+ struct variable *p,
+ *prev;
- for (p = prev = allvariables; p; p = p ? p->next : NULL)
- {
- if (p->brace_level >= brace_level)
+ for (p = prev = allvariables; p; p = p ? p->next : NULL)
{
- /* remove it */
- if (p == allvariables)
- prev = allvariables = p->next;
- else
- prev->next = p->next;
-
- ECPGfree_type(p->type);
- free(p->name);
- free(p);
- p = prev;
+ if (p->brace_level >= brace_level)
+ {
+ /* remove it */
+ if (p == allvariables)
+ prev = allvariables = p->next;
+ else
+ prev->next = p->next;
+
+ ECPGfree_type(p->type);
+ free(p->name);
+ free(p);
+ p = prev;
+ }
+ else
+ prev = p;
}
- else
- prev = p;
- }
}
@@ -179,44 +182,45 @@ remove_variables(int brace_level)
* I will make two lists for them.
*/
-struct arguments * argsinsert = NULL;
-struct arguments * argsresult = NULL;
+struct arguments *argsinsert = NULL;
+struct arguments *argsresult = NULL;
void
reset_variables(void)
{
- argsinsert = NULL;
- argsresult = NULL;
+ argsinsert = NULL;
+ argsresult = NULL;
}
/* Insert a new variable into our request list. */
void
add_variable(struct arguments ** list, struct variable * var, struct variable * ind)
{
- struct arguments *p = (struct arguments *)mm_alloc(sizeof(struct arguments));
-
- p->variable = var;
- p->indicator = ind;
- p->next = *list;
- *list = p;
+ struct arguments *p = (struct arguments *) mm_alloc(sizeof(struct arguments));
+
+ p->variable = var;
+ p->indicator = ind;
+ p->next = *list;
+ *list = p;
}
/* Append a new variable to our request list. */
void
append_variable(struct arguments ** list, struct variable * var, struct variable * ind)
{
- struct arguments *p, *new = (struct arguments *)mm_alloc(sizeof(struct arguments));
-
- for (p = *list; p && p->next; p = p->next);
-
- new->variable = var;
- new->indicator = ind;
- new->next = NULL;
-
- if (p)
- p->next = new;
- else
- *list = new;
+ struct arguments *p,
+ *new = (struct arguments *) mm_alloc(sizeof(struct arguments));
+
+ for (p = *list; p && p->next; p = p->next);
+
+ new->variable = var;
+ new->indicator = ind;
+ new->next = NULL;
+
+ if (p)
+ p->next = new;
+ else
+ *list = new;
}
/* Dump out a list of all the variable on this list.
@@ -226,33 +230,32 @@ append_variable(struct arguments ** list, struct variable * var, struct variable
void
dump_variables(struct arguments * list, int mode)
{
- if (list == NULL)
- {
- return;
- }
+ if (list == NULL)
+ return;
- /* The list is build up from the beginning so lets first dump the
- end of the list:
- */
+ /*
+ * The list is build up from the beginning so lets first dump the end
+ * of the list:
+ */
- dump_variables(list->next, mode);
+ dump_variables(list->next, mode);
- /* Then the current element and its indicator */
- ECPGdump_a_type(yyout, list->variable->name, list->variable->type,
- list->indicator->name, list->indicator->type, NULL, NULL);
+ /* Then the current element and its indicator */
+ ECPGdump_a_type(yyout, list->variable->name, list->variable->type,
+ list->indicator->name, list->indicator->type, NULL, NULL);
- /* Then release the list element. */
- if (mode != 0)
- free(list);
+ /* Then release the list element. */
+ if (mode != 0)
+ free(list);
}
void
-check_indicator(struct ECPGtype *var)
+check_indicator(struct ECPGtype * var)
{
/* make sure this is a valid indicator variable */
switch (var->typ)
{
- struct ECPGstruct_member *p;
+ struct ECPGstruct_member *p;
case ECPGt_short:
case ECPGt_int:
@@ -271,7 +274,7 @@ check_indicator(struct ECPGtype *var)
case ECPGt_array:
check_indicator(var->u.element);
break;
- default:
+ default:
mmerror(ET_ERROR, "indicator variable must be integer type");
break;
}
@@ -289,20 +292,20 @@ get_typedef(char *name)
mmerror(ET_FATAL, errortext);
}
- return(this);
+ return (this);
}
void
adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dimension, int type_index, bool pointer)
{
- if (type_index >= 0)
+ if (type_index >= 0)
{
if (*length >= 0)
- mmerror(ET_FATAL, "No multi-dimensional array support");
+ mmerror(ET_FATAL, "No multi-dimensional array support");
*length = type_index;
}
-
+
if (type_dimension >= 0)
{
if (*dimension >= 0 && *length >= 0)
@@ -319,56 +322,57 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim
switch (type_enum)
{
- case ECPGt_struct:
- case ECPGt_union:
- /* pointer has to get dimension 0 */
- if (pointer)
- {
- *length = *dimension;
- *dimension = 0;
- }
-
- if (*length >= 0)
- mmerror(ET_FATAL, "No multi-dimensional array support for structures");
-
- break;
- case ECPGt_varchar:
- /* pointer has to get dimension 0 */
- if (pointer)
- *dimension = 0;
-
- /* one index is the string length */
- if (*length < 0)
- {
- *length = *dimension;
- *dimension = -1;
- }
-
- break;
- case ECPGt_char:
- case ECPGt_unsigned_char:
- /* pointer has to get length 0 */
- if (pointer)
- *length=0;
-
- /* one index is the string length */
- if (*length < 0)
- {
- *length = (*dimension < 0) ? 1 : *dimension;
- *dimension = -1;
- }
-
- break;
- default:
- /* a pointer has dimension = 0 */
- if (pointer) {
- *length = *dimension;
- *dimension = 0;
- }
-
- if (*length >= 0)
- mmerror(ET_FATAL, "No multi-dimensional array support for simple data types");
-
- break;
+ case ECPGt_struct:
+ case ECPGt_union:
+ /* pointer has to get dimension 0 */
+ if (pointer)
+ {
+ *length = *dimension;
+ *dimension = 0;
+ }
+
+ if (*length >= 0)
+ mmerror(ET_FATAL, "No multi-dimensional array support for structures");
+
+ break;
+ case ECPGt_varchar:
+ /* pointer has to get dimension 0 */
+ if (pointer)
+ *dimension = 0;
+
+ /* one index is the string length */
+ if (*length < 0)
+ {
+ *length = *dimension;
+ *dimension = -1;
+ }
+
+ break;
+ case ECPGt_char:
+ case ECPGt_unsigned_char:
+ /* pointer has to get length 0 */
+ if (pointer)
+ *length = 0;
+
+ /* one index is the string length */
+ if (*length < 0)
+ {
+ *length = (*dimension < 0) ? 1 : *dimension;
+ *dimension = -1;
+ }
+
+ break;
+ default:
+ /* a pointer has dimension = 0 */
+ if (pointer)
+ {
+ *length = *dimension;
+ *dimension = 0;
+ }
+
+ if (*length >= 0)
+ mmerror(ET_FATAL, "No multi-dimensional array support for simple data types");
+
+ break;
}
}