1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-03 20:02:46 +03:00

Ye-old pgindent run. Same 4-space tabs.

This commit is contained in:
Bruce Momjian
2000-04-12 17:17:23 +00:00
parent db4518729d
commit 52f77df613
434 changed files with 24799 additions and 21246 deletions

View File

@ -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;
if (next != NULL)
{
c = *next;
*next = '\0';
}
for (; members; members = members->next)
{
if (strcmp(members->name, str) == 0)
{
if (c == '\0')
{
/* 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 == '-')
{
next++;
return (find_struct_member(name, next, members->typ->u.element->u.members));
}
else
return (find_struct_member(name, next, members->typ->u.members));
}
}
}
return (NULL);
}
static struct variable *
find_struct(char *name, char *next)
{
struct variable *p;
char c = *next;
/* first get the mother structure entry */
*next = '\0';
}
p = find_variable(name);
for (; members; members = members->next)
{
if (strcmp(members->name, str) == 0)
if (c == '-')
{
if (c == '\0')
if (p->type->typ != ECPGt_struct && p->type->typ != ECPGt_union)
{
/* 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)));
}
sprintf(errortext, "variable %s is not a pointer", name);
mmerror(ET_FATAL, errortext);
}
else
{
*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));
}
}
}
return(NULL);
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;
return find_struct_member(name, next, p->type->u.members);
}
}
static struct variable *
find_struct(char * name, char *next)
find_simple(char *name)
{
struct variable * p;
char c = *next;
struct variable *p;
/* 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)
for (p = allvariables; p; p = p->next)
{
sprintf(errortext, "variable %s is neither a structure nor a union", name);
mmerror(ET_FATAL, errortext);
if (strcmp(p->name, name) == 0)
return p;
}
/* restore the name, we will need it later on */
*next = c;
return find_struct_member(name, next, p->type->u.members);
}
}
static struct variable *
find_simple(char * name)
{
struct variable * 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;
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 ((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);
}
if (p == NULL)
{
sprintf(errortext, "The variable %s is not declared", name);
mmerror(ET_FATAL, errortext);
}
return(p);
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;
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;
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));
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;
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;
}
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");
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;
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;
}
/* 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;
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;
}
/* 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;
}
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");
if (*length >= 0)
mmerror(ET_FATAL, "No multi-dimensional array support for simple data types");
break;
break;
}
}