1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-04 20:11:56 +03:00

OK, folks, here is the pgindent output.

This commit is contained in:
Bruce Momjian
1998-09-01 04:40:42 +00:00
parent af74855a60
commit fa1a8d6a97
574 changed files with 26509 additions and 24033 deletions

View File

@@ -9,8 +9,9 @@
#include <getopt.h>
#else
#include <unistd.h>
extern int optind;
extern int optind;
extern char *optarg;
#endif
#include <stdlib.h>
#if defined(HAVE_STRING_H)
@@ -22,7 +23,7 @@ extern char *optarg;
#include "extern.h"
struct _include_path *include_paths;
int no_auto_trans = 0;
int no_auto_trans = 0;
struct cursor *cur = NULL;
static void
@@ -33,22 +34,24 @@ usage(char *progname)
}
static void
add_include_path(char * path)
add_include_path(char *path)
{
struct _include_path *ip = include_paths;
include_paths = mm_alloc(sizeof(struct _include_path));
include_paths->path = path;
include_paths->next = ip;
include_paths = mm_alloc(sizeof(struct _include_path));
include_paths->path = path;
include_paths->next = ip;
}
int
main(int argc, char *const argv[])
{
int fnr, c, out_option = 0;
struct _include_path *ip;
add_include_path("/usr/include");
int fnr,
c,
out_option = 0;
struct _include_path *ip;
add_include_path("/usr/include");
add_include_path(INCLUDE_PATH);
add_include_path("/usr/local/include");
add_include_path(".");
@@ -66,10 +69,10 @@ main(int argc, char *const argv[])
break;
case 'I':
add_include_path(optarg);
break;
case 't':
no_auto_trans = 1;
break;
break;
case 't':
no_auto_trans = 1;
break;
case 'v':
fprintf(stderr, "ecpg - the postgresql preprocessor, version: %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
fprintf(stderr, "exec sql include ... search starts here:\n");
@@ -86,14 +89,15 @@ main(int argc, char *const argv[])
if (optind >= argc) /* no files specified */
{
usage(argv[0]);
return(ILLEGAL_OPTION);
return (ILLEGAL_OPTION);
}
else
{
/* after the options there must not be anything but filenames */
for (fnr = optind; fnr < argc; fnr++)
{
char *output_filename = NULL, *ptr2ext;
char *output_filename = NULL,
*ptr2ext;
input_filename = mm_alloc(strlen(argv[fnr]) + 5);
@@ -104,7 +108,7 @@ main(int argc, char *const argv[])
if (ptr2ext == NULL)
{
ptr2ext = input_filename + strlen(input_filename);
/* no extension => add .pgc */
ptr2ext[0] = '.';
ptr2ext[1] = 'p';
@@ -116,12 +120,12 @@ main(int argc, char *const argv[])
if (out_option == 0)/* calculate the output name */
{
output_filename = strdup(input_filename);
ptr2ext = strrchr(output_filename, '.');
/* make extension = .c */
ptr2ext[1] = 'c';
ptr2ext[2] = '\0';
yyout = fopen(output_filename, "w");
if (yyout == NULL)
{
@@ -139,13 +143,14 @@ main(int argc, char *const argv[])
{
struct cursor *ptr;
struct _defines *defptr;
/* remove old cursor definitions if any are still there */
for (ptr = cur; ptr != NULL;)
{
struct cursor *this = ptr;
struct arguments *l1, *l2;
struct arguments *l1,
*l2;
free(ptr->command);
free(ptr->name);
for (l1 = argsinsert; l1; l1 = l2)
@@ -161,20 +166,21 @@ main(int argc, char *const argv[])
ptr = ptr->next;
free(this);
}
/* remove old defines as well */
for (defptr = defines; defptr != NULL;)
{
struct _defines *this = defptr;
free(defptr->new);
free(defptr->old);
defptr = defptr->next;
free(this);
}
/* initialize lex */
lex_init();
/* we need two includes and a constant */
fprintf(yyout, "/* Processed by ecpg (%d.%d.%d) */\n/* These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
@@ -189,7 +195,7 @@ main(int argc, char *const argv[])
if (output_filename)
free(output_filename);
free(input_filename);
}
}

View File

@@ -30,8 +30,8 @@ static ScanKeyword ScanKeywords[] = {
{"found", SQL_FOUND},
{"go", SQL_GO},
{"goto", SQL_GOTO},
{"identified", SQL_IDENTIFIED},
{"immediate", SQL_IMMEDIATE},
{"identified", SQL_IDENTIFIED},
{"immediate", SQL_IMMEDIATE},
{"indicator", SQL_INDICATOR},
{"open", SQL_OPEN},
{"release", SQL_RELEASE},

View File

@@ -3,55 +3,63 @@
/* variables */
extern int braces_open, no_auto_trans;
extern int braces_open,
no_auto_trans;
extern char *yytext;
extern int yylineno,
yyleng;
extern FILE *yyin,
*yyout;
struct _include_path { char * path;
struct _include_path * next;
};
struct _include_path
{
char *path;
struct _include_path *next;
};
extern struct _include_path *include_paths;
struct cursor { char *name;
char *command;
struct arguments * argsinsert;
struct arguments * argsresult;
struct cursor *next;
};
struct cursor
{
char *name;
char *command;
struct arguments *argsinsert;
struct arguments *argsresult;
struct cursor *next;
};
extern struct cursor *cur;
struct _defines { char *old;
char *new;
struct _defines *next;
};
struct _defines
{
char *old;
char *new;
struct _defines *next;
};
extern struct _defines *defines;
/* This is a linked list of the variable names and types. */
struct variable
{
char * name;
struct ECPGtype * type;
int brace_level;
struct variable * next;
char *name;
struct ECPGtype *type;
int brace_level;
struct variable *next;
};
extern struct ECPGtype ecpg_no_indicator;
extern struct variable no_indicator;
struct arguments {
struct variable * variable;
struct variable * indicator;
struct arguments * next;
struct arguments
{
struct variable *variable;
struct variable *indicator;
struct arguments *next;
};
extern struct arguments * argsinsert;
extern struct arguments * argsresult;
extern struct arguments *argsinsert;
extern struct arguments *argsresult;
/* functions */
@@ -59,15 +67,15 @@ extern void lex_init(void);
extern char *input_filename;
extern int yyparse(void);
extern void *mm_alloc(size_t), *mm_realloc(void *, size_t);
ScanKeyword * ScanECPGKeywordLookup(char *);
ScanKeyword * ScanCKeywordLookup(char *);
ScanKeyword *ScanECPGKeywordLookup(char *);
ScanKeyword *ScanCKeywordLookup(char *);
extern void yyerror(char *);
/* return codes */
#define OK 0
#define PARSE_ERROR -1
#define PARSE_ERROR -1
#define ILLEGAL_OPTION -2
#define NO_INCLUDE_FILE ENOENT
#define NO_INCLUDE_FILE ENOENT
#define OUT_OF_MEMORY ENOMEM

View File

@@ -24,31 +24,31 @@ mm_alloc(size_t size)
static struct ECPGstruct_member *
struct_member_dup(struct ECPGstruct_member * rm)
{
struct ECPGstruct_member *new = NULL;
struct ECPGstruct_member *new = NULL;
while (rm)
{
struct ECPGtype *type;
switch(rm->typ->typ)
{
case ECPGt_struct:
type = ECPGmake_struct_type(rm->typ->u.members);
break;
case ECPGt_array:
type = ECPGmake_array_type(ECPGmake_simple_type(rm->typ->u.element->typ, rm->typ->u.element->size), rm->typ->size);
break;
default:
type = ECPGmake_simple_type(rm->typ->typ, rm->typ->size);
break;
}
ECPGmake_struct_member(rm->name, type, &new);
rm = rm->next;
}
while (rm)
{
struct ECPGtype *type;
return(new);
switch (rm->typ->typ)
{
case ECPGt_struct:
type = ECPGmake_struct_type(rm->typ->u.members);
break;
case ECPGt_array:
type = ECPGmake_array_type(ECPGmake_simple_type(rm->typ->u.element->typ, rm->typ->u.element->size), rm->typ->size);
break;
default:
type = ECPGmake_simple_type(rm->typ->typ, rm->typ->size);
break;
}
ECPGmake_struct_member(rm->name, type, &new);
rm = rm->next;
}
return (new);
}
/* The NAME argument is copied. The type argument is preserved as a pointer. */
@@ -103,51 +103,52 @@ ECPGmake_struct_type(struct ECPGstruct_member * rm)
return ne;
}
static const char *get_type(enum ECPGttype typ)
static const char *
get_type(enum ECPGttype typ)
{
switch (typ)
{
case ECPGt_char:
return("ECPGt_char");
break;
case ECPGt_unsigned_char:
return("ECPGt_unsigned_char");
break;
case ECPGt_short:
return("ECPGt_short");
break;
case ECPGt_unsigned_short:
return("ECPGt_unsigned_short");
break;
case ECPGt_int:
return("ECPGt_int");
break;
case ECPGt_unsigned_int:
return("ECPGt_unsigned_int");
break;
case ECPGt_long:
return("ECPGt_long");
break;
case ECPGt_unsigned_long:
return("ECPGt_unsigned_int");
break;
case ECPGt_float:
return("ECPGt_float");
break;
case ECPGt_double:
return("ECPGt_double");
break;
case ECPGt_bool:
return("ECPGt_bool");
break;
case ECPGt_varchar:
return("ECPGt_varchar");
case ECPGt_NO_INDICATOR: /* no indicator */
return("ECPGt_NO_INDICATOR");
break;
default:
abort();
}
switch (typ)
{
case ECPGt_char:
return ("ECPGt_char");
break;
case ECPGt_unsigned_char:
return ("ECPGt_unsigned_char");
break;
case ECPGt_short:
return ("ECPGt_short");
break;
case ECPGt_unsigned_short:
return ("ECPGt_unsigned_short");
break;
case ECPGt_int:
return ("ECPGt_int");
break;
case ECPGt_unsigned_int:
return ("ECPGt_unsigned_int");
break;
case ECPGt_long:
return ("ECPGt_long");
break;
case ECPGt_unsigned_long:
return ("ECPGt_unsigned_int");
break;
case ECPGt_float:
return ("ECPGt_float");
break;
case ECPGt_double:
return ("ECPGt_double");
break;
case ECPGt_bool:
return ("ECPGt_bool");
break;
case ECPGt_varchar:
return ("ECPGt_varchar");
case ECPGt_NO_INDICATOR: /* no indicator */
return ("ECPGt_NO_INDICATOR");
break;
default:
abort();
}
}
/* Dump a type.
@@ -164,13 +165,11 @@ static const char *get_type(enum ECPGttype typ)
size is the maxsize in case it is a varchar. Otherwise it is the size of
the variable (required to do array fetches of structs).
*/
static void
ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
static void ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
long varcharsize,
long arrsiz, const char *siz, const char *prefix);
static void
ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz,
struct ECPGtype * typ, struct ECPGtype * ind_typ, const char *offset, const char *prefix, const char * ind_prefix);
static void ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz,
struct ECPGtype * typ, struct ECPGtype * ind_typ, const char *offset, const char *prefix, const char *ind_prefix);
void
@@ -181,41 +180,39 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * typ, const char *in
ind_typ = &ecpg_no_indicator;
ind_name = "no_indicator";
}
switch(typ->typ)
{
case ECPGt_array:
if (IS_SIMPLE_TYPE(typ->u.element->typ))
{
ECPGdump_a_simple(o, name, typ->u.element->typ,
typ->u.element->size, typ->size, NULL, prefix);
if (ind_typ == &ecpg_no_indicator)
ECPGdump_a_simple(o, ind_name, ind_typ->typ, ind_typ->size, -1, NULL, ind_prefix);
else
ECPGdump_a_simple(o, ind_name, ind_typ->u.element->typ,
ind_typ->u.element->size, ind_typ->size, NULL, prefix);
}
else if (typ->u.element->typ == ECPGt_array)
{
yyerror("No nested arrays allowed (except strings)"); /* Array of array, */
}
else if (typ->u.element->typ == ECPGt_struct)
{
/* Array of structs. */
ECPGdump_a_struct(o, name, ind_name, typ->size, typ->u.element, ind_typ->u.element, NULL, prefix, ind_prefix);
}
else
{
yyerror("Internal error: unknown datatype, pleqase inform pgsql-bugs@postgresql.org");
}
break;
case ECPGt_struct:
ECPGdump_a_struct(o, name, ind_name, 1, typ, ind_typ, NULL, prefix, ind_prefix);
break;
default:
ECPGdump_a_simple(o, name, typ->typ, typ->size, -1, NULL, prefix);
ECPGdump_a_simple(o, ind_name, ind_typ->typ, ind_typ->size, -1, NULL, ind_prefix);
break;
switch (typ->typ)
{
case ECPGt_array:
if (IS_SIMPLE_TYPE(typ->u.element->typ))
{
ECPGdump_a_simple(o, name, typ->u.element->typ,
typ->u.element->size, typ->size, NULL, prefix);
if (ind_typ == &ecpg_no_indicator)
ECPGdump_a_simple(o, ind_name, ind_typ->typ, ind_typ->size, -1, NULL, ind_prefix);
else
ECPGdump_a_simple(o, ind_name, ind_typ->u.element->typ,
ind_typ->u.element->size, ind_typ->size, NULL, prefix);
}
else if (typ->u.element->typ == ECPGt_array)
{
yyerror("No nested arrays allowed (except strings)"); /* Array of array, */
}
else if (typ->u.element->typ == ECPGt_struct)
{
/* Array of structs. */
ECPGdump_a_struct(o, name, ind_name, typ->size, typ->u.element, ind_typ->u.element, NULL, prefix, ind_prefix);
}
else
yyerror("Internal error: unknown datatype, pleqase inform pgsql-bugs@postgresql.org");
break;
case ECPGt_struct:
ECPGdump_a_struct(o, name, ind_name, 1, typ, ind_typ, NULL, prefix, ind_prefix);
break;
default:
ECPGdump_a_simple(o, name, typ->typ, typ->size, -1, NULL, prefix);
ECPGdump_a_simple(o, ind_name, ind_typ->typ, ind_typ->size, -1, NULL, ind_prefix);
break;
}
}
@@ -228,51 +225,51 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
long arrsize,
const char *siz,
const char *prefix
)
)
{
if (typ == ECPGt_NO_INDICATOR)
fprintf(o, "\n\tECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ");
else
{
char *variable = (char *)mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 4);
char *offset = (char *)mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1);
if (typ == ECPGt_NO_INDICATOR)
fprintf(o, "\n\tECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ");
else
{
char *variable = (char *) mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 4);
char *offset = (char *) mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1);
if (varcharsize == 0 || arrsize >= 0)
sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
else
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
if (varcharsize == 0 || arrsize >= 0)
sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
else
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
switch (typ)
{
case ECPGt_varchar:
sprintf(offset, "sizeof(struct varchar_%s)", name);
break;
case ECPGt_char:
case ECPGt_unsigned_char:
sprintf(offset, "%ld*sizeof(char)", varcharsize);
break;
default:
sprintf(offset, "sizeof(%s)", ECPGtype_name(typ));
break;
switch (typ)
{
case ECPGt_varchar:
sprintf(offset, "sizeof(struct varchar_%s)", name);
break;
case ECPGt_char:
case ECPGt_unsigned_char:
sprintf(offset, "%ld*sizeof(char)", varcharsize);
break;
default:
sprintf(offset, "sizeof(%s)", ECPGtype_name(typ));
break;
}
if (arrsize < 0)
arrsize = 1;
if (siz == NULL)
fprintf(o, "\n\t%s,%s,%ldL,%ldL,%s, ", get_type(typ), variable, varcharsize, arrsize, offset);
else
fprintf(o, "\n\t%s,%s,%ldL,%ldL,%s, ", get_type(typ), variable, varcharsize, arrsize, siz);
free(variable);
free(offset);
}
if (arrsize < 0)
arrsize = 1;
if (siz == NULL)
fprintf(o, "\n\t%s,%s,%ldL,%ldL,%s, ", get_type(typ), variable, varcharsize, arrsize, offset);
else
fprintf(o, "\n\t%s,%s,%ldL,%ldL,%s, ", get_type(typ), variable, varcharsize, arrsize, siz);
free(variable);
free(offset);
}
}
/* Penetrate a struct and dump the contents. */
static void
ECPGdump_a_struct(FILE *o, const char *name, const char * ind_name, long arrsiz, struct ECPGtype * typ, struct ECPGtype * ind_typ, const char *offsetarg, const char *prefix, const char *ind_prefix)
ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz, struct ECPGtype * typ, struct ECPGtype * ind_typ, const char *offsetarg, const char *prefix, const char *ind_prefix)
{
/*
@@ -280,9 +277,11 @@ ECPGdump_a_struct(FILE *o, const char *name, const char * ind_name, long arrsiz,
* then we are in a struct in a struct and the offset is used as
* offset.
*/
struct ECPGstruct_member *p, *ind_p = NULL;
struct ECPGstruct_member *p,
*ind_p = NULL;
char obuf[BUFSIZ];
char pbuf[BUFSIZ], ind_pbuf[BUFSIZ];
char pbuf[BUFSIZ],
ind_pbuf[BUFSIZ];
const char *offset;
if (offsetarg == NULL)
@@ -291,36 +290,36 @@ ECPGdump_a_struct(FILE *o, const char *name, const char * ind_name, long arrsiz,
offset = obuf;
}
else
{
offset = offsetarg;
}
sprintf(pbuf, "%s%s.", prefix ? prefix : "", name);
prefix = pbuf;
sprintf(ind_pbuf, "%s%s.", ind_prefix ? ind_prefix : "", ind_name);
ind_prefix = ind_pbuf;
if (ind_typ != NULL) ind_p = ind_typ->u.members;
if (ind_typ != NULL)
ind_p = ind_typ->u.members;
for (p = typ->u.members; p; p = p->next)
{
ECPGdump_a_type(o, p->name, p->typ, (ind_p != NULL) ? ind_p->name : NULL, (ind_p != NULL) ? ind_p->typ : NULL, prefix, ind_prefix);
if (ind_p != NULL) ind_p = ind_p->next;
if (ind_p != NULL)
ind_p = ind_p->next;
}
}
void
ECPGfree_struct_member(struct ECPGstruct_member * rm)
{
while (rm)
{
struct ECPGstruct_member *p = rm;
rm = rm->next;
free(p->name);
free(p->typ);
free(p);
}
while (rm)
{
struct ECPGstruct_member *p = rm;
rm = rm->next;
free(p->name);
free(p->typ);
free(p);
}
}
void
@@ -337,7 +336,7 @@ ECPGfree_type(struct ECPGtype * typ)
else if (typ->u.element->typ == ECPGt_struct)
{
/* Array of structs. */
ECPGfree_struct_member(typ->u.element->u.members);
ECPGfree_struct_member(typ->u.element->u.members);
free(typ->u.members);
}
else
@@ -345,13 +344,11 @@ ECPGfree_type(struct ECPGtype * typ)
}
else if (typ->typ == ECPGt_struct)
{
ECPGfree_struct_member(typ->u.members);
ECPGfree_struct_member(typ->u.members);
free(typ->u.members);
}
else
{
abort();
}
}
free(typ);
}

View File

@@ -25,7 +25,7 @@ struct ECPGtype
};
/* Everything is malloced. */
void ECPGmake_struct_member(char *, struct ECPGtype *, struct ECPGstruct_member **);
void ECPGmake_struct_member(char *, struct ECPGtype *, struct ECPGstruct_member **);
struct ECPGtype *ECPGmake_simple_type(enum ECPGttype, long);
struct ECPGtype *ECPGmake_varchar_type(enum ECPGttype, long);
struct ECPGtype *ECPGmake_array_type(struct ECPGtype *, long);
@@ -45,7 +45,7 @@ void ECPGfree_type(struct ECPGtype *);
size is the maxsize in case it is a varchar. Otherwise it is the size of
the variable (required to do array fetches of structs).
*/
void ECPGdump_a_type(FILE *, const char *, struct ECPGtype *, const char *, struct ECPGtype *, const char *, const char *);
void ECPGdump_a_type(FILE *, const char *, struct ECPGtype *, const char *, struct ECPGtype *, const char *, const char *);
/* A simple struct to keep a variable and its type. */
struct ECPGtemp_type
@@ -71,19 +71,19 @@ enum WHEN
struct when
{
enum WHEN code;
char *command;
char *str;
char *command;
char *str;
};
struct index
{
int index1;
int index2;
char *str;
int index1;
int index2;
char *str;
};
struct this_type
{
enum ECPGttype type_enum;
char *type_str;
enum ECPGttype type_enum;
char *type_str;
};