mirror of
https://github.com/postgres/postgres.git
synced 2025-11-07 19:06:32 +03:00
pgindent run before 6.3 release, with Thomas' requested changes.
This commit is contained in:
@@ -6,15 +6,15 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#if HAVE_GETOPT_H
|
||||
# include <getopt.h>
|
||||
#include <getopt.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#if defined(HAVE_STRING_H)
|
||||
# include <string.h>
|
||||
#include <string.h>
|
||||
#else
|
||||
# include <strings.h>
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
#include "extern.h"
|
||||
@@ -29,7 +29,8 @@ usage(char *progname)
|
||||
int
|
||||
main(int argc, char *const argv[])
|
||||
{
|
||||
char c, out_option = 0;
|
||||
char c,
|
||||
out_option = 0;
|
||||
int fnr;
|
||||
|
||||
while ((c = getopt(argc, argv, "vdo:")) != EOF)
|
||||
@@ -52,15 +53,16 @@ main(int argc, char *const argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (optind >= argc) /* no files specified */
|
||||
if (optind >= argc) /* no files specified */
|
||||
usage(argv[0]);
|
||||
else
|
||||
{
|
||||
/* after the options there must not be anything but filenames */
|
||||
for (fnr = optind; fnr < argc; fnr++)
|
||||
{
|
||||
char *filename, *ptr2ext;
|
||||
int ext = 0;
|
||||
char *filename,
|
||||
*ptr2ext;
|
||||
int ext = 0;
|
||||
|
||||
filename = mm_alloc(strlen(argv[fnr]) + 4);
|
||||
|
||||
@@ -69,9 +71,9 @@ main(int argc, char *const argv[])
|
||||
ptr2ext = strrchr(filename, '.');
|
||||
/* no extension or extension not equal .pgc */
|
||||
if (ptr2ext == NULL || strcmp(ptr2ext, ".pgc") != 0)
|
||||
{
|
||||
{
|
||||
if (ptr2ext == NULL)
|
||||
ext = 1; /* we need this information a while later */
|
||||
ext = 1; /* we need this information a while later */
|
||||
ptr2ext = filename + strlen(filename);
|
||||
ptr2ext[0] = '.';
|
||||
}
|
||||
@@ -80,7 +82,7 @@ main(int argc, char *const argv[])
|
||||
ptr2ext[1] = 'c';
|
||||
ptr2ext[2] = '\0';
|
||||
|
||||
if (out_option == 0) /* calculate the output name */
|
||||
if (out_option == 0)/* calculate the output name */
|
||||
{
|
||||
yyout = fopen(filename, "w");
|
||||
if (yyout == NULL)
|
||||
@@ -91,7 +93,7 @@ main(int argc, char *const argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (ext == 1)
|
||||
if (ext == 1)
|
||||
{
|
||||
/* no extension => add .pgc */
|
||||
ptr2ext = strrchr(filename, '.');
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
/* variables */
|
||||
|
||||
extern int debugging, braces_open;
|
||||
extern char * yytext;
|
||||
extern int yylineno, yyleng;
|
||||
extern FILE *yyin, *yyout;
|
||||
extern int debugging,
|
||||
braces_open;
|
||||
extern char *yytext;
|
||||
extern int yylineno,
|
||||
yyleng;
|
||||
extern FILE *yyin,
|
||||
*yyout;
|
||||
|
||||
|
||||
/* functions */
|
||||
|
||||
extern void lex_init(void);
|
||||
extern char * input_filename;
|
||||
extern int yyparse(void);
|
||||
extern char *input_filename;
|
||||
extern int yyparse(void);
|
||||
extern void *mm_alloc(size_t), *mm_realloc(void *, size_t);
|
||||
|
||||
@@ -5,31 +5,33 @@
|
||||
#include "type.h"
|
||||
|
||||
/* malloc + error check */
|
||||
void *mm_alloc(size_t size)
|
||||
void *
|
||||
mm_alloc(size_t size)
|
||||
{
|
||||
void *ptr = malloc(size);
|
||||
void *ptr = malloc(size);
|
||||
|
||||
if (ptr == NULL)
|
||||
{
|
||||
fprintf(stderr, "Out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
if (ptr == NULL)
|
||||
{
|
||||
fprintf(stderr, "Out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return (ptr);
|
||||
return (ptr);
|
||||
}
|
||||
|
||||
/* realloc + error check */
|
||||
void *mm_realloc(void * ptr, size_t size)
|
||||
void *
|
||||
mm_realloc(void *ptr, size_t size)
|
||||
{
|
||||
ptr = realloc(ptr, size);
|
||||
ptr = realloc(ptr, size);
|
||||
|
||||
if (ptr == NULL)
|
||||
{
|
||||
fprintf(stderr, "Out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
if (ptr == NULL)
|
||||
{
|
||||
fprintf(stderr, "Out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return (ptr);
|
||||
return (ptr);
|
||||
}
|
||||
|
||||
/* Constructors
|
||||
@@ -38,75 +40,76 @@ void *mm_realloc(void * ptr, size_t size)
|
||||
|
||||
/* The NAME argument is copied. The type argument is preserved as a pointer. */
|
||||
struct ECPGrecord_member *
|
||||
ECPGmake_record_member(char *name, struct ECPGtype *type, struct ECPGrecord_member **start)
|
||||
ECPGmake_record_member(char *name, struct ECPGtype * type, struct ECPGrecord_member ** start)
|
||||
{
|
||||
struct ECPGrecord_member *ptr, *ne =
|
||||
(struct ECPGrecord_member *) mm_alloc(sizeof(struct ECPGrecord_member));
|
||||
struct ECPGrecord_member *ptr,
|
||||
*ne =
|
||||
(struct ECPGrecord_member *) mm_alloc(sizeof(struct ECPGrecord_member));
|
||||
|
||||
ne->name = strdup(name);
|
||||
ne->typ = type;
|
||||
ne->next = NULL;
|
||||
ne->name = strdup(name);
|
||||
ne->typ = type;
|
||||
ne->next = NULL;
|
||||
|
||||
for (ptr = *start; ptr && ptr->next; ptr = ptr->next);
|
||||
for (ptr = *start; ptr && ptr->next; ptr = ptr->next);
|
||||
|
||||
if (ptr)
|
||||
ptr->next=ne;
|
||||
else
|
||||
*start=ne;
|
||||
return ne;
|
||||
if (ptr)
|
||||
ptr->next = ne;
|
||||
else
|
||||
*start = ne;
|
||||
return ne;
|
||||
}
|
||||
|
||||
struct ECPGtype *
|
||||
ECPGmake_simple_type(enum ECPGttype typ, long siz)
|
||||
{
|
||||
struct ECPGtype *ne = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
|
||||
struct ECPGtype *ne = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
|
||||
|
||||
ne->typ = typ;
|
||||
ne->size = siz;
|
||||
ne->u.element = 0;
|
||||
ne->typ = typ;
|
||||
ne->size = siz;
|
||||
ne->u.element = 0;
|
||||
|
||||
return ne;
|
||||
return ne;
|
||||
}
|
||||
|
||||
struct ECPGtype *
|
||||
ECPGmake_varchar_type(enum ECPGttype typ, long siz)
|
||||
{
|
||||
struct ECPGtype *ne = ECPGmake_simple_type(typ, 1);
|
||||
struct ECPGtype *ne = ECPGmake_simple_type(typ, 1);
|
||||
|
||||
ne->size = siz;
|
||||
ne->size = siz;
|
||||
|
||||
return ne;
|
||||
return ne;
|
||||
}
|
||||
|
||||
struct ECPGtype *
|
||||
ECPGmake_array_type(struct ECPGtype *typ, long siz)
|
||||
ECPGmake_array_type(struct ECPGtype * typ, long siz)
|
||||
{
|
||||
struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_array, siz);
|
||||
struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_array, siz);
|
||||
|
||||
ne->size = siz;
|
||||
ne->u.element = typ;
|
||||
ne->size = siz;
|
||||
ne->u.element = typ;
|
||||
|
||||
return ne;
|
||||
return ne;
|
||||
}
|
||||
|
||||
struct ECPGtype *
|
||||
ECPGmake_record_type(struct ECPGrecord_member *rm)
|
||||
ECPGmake_record_type(struct ECPGrecord_member * rm)
|
||||
{
|
||||
struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_record, 1);
|
||||
struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_record, 1);
|
||||
|
||||
ne->u.members = rm;
|
||||
ne->u.members = rm;
|
||||
|
||||
return ne;
|
||||
return ne;
|
||||
}
|
||||
|
||||
|
||||
/* Dump a type.
|
||||
The type is dumped as:
|
||||
type-tag <comma> - enum ECPGttype
|
||||
type-tag <comma> - enum ECPGttype
|
||||
reference-to-variable <comma> - void *
|
||||
size <comma> - long size of this field (if varchar)
|
||||
arrsize <comma> - long number of elements in the arr
|
||||
offset <comma> - offset to the next element
|
||||
size <comma> - long size of this field (if varchar)
|
||||
arrsize <comma> - long number of elements in the arr
|
||||
offset <comma> - offset to the next element
|
||||
Where:
|
||||
type-tag is one of the simple types or varchar.
|
||||
reference-to-variable can be a reference to a struct element.
|
||||
@@ -114,47 +117,49 @@ ECPGmake_record_type(struct ECPGrecord_member *rm)
|
||||
size is the maxsize in case it is a varchar. Otherwise it is the size of
|
||||
the variable (required to do array fetches of records).
|
||||
*/
|
||||
void ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
|
||||
long varcharsize,
|
||||
long arrsiz, const char *siz, const char *prefix);
|
||||
void ECPGdump_a_record(FILE *o, const char *name, long arrsiz,
|
||||
struct ECPGtype *typ, const char *offset, const char *prefix);
|
||||
void
|
||||
ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
|
||||
long varcharsize,
|
||||
long arrsiz, const char *siz, const char *prefix);
|
||||
void
|
||||
ECPGdump_a_record(FILE *o, const char *name, long arrsiz,
|
||||
struct ECPGtype * typ, const char *offset, const char *prefix);
|
||||
|
||||
|
||||
void
|
||||
ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype *typ, const char *prefix)
|
||||
ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * typ, const char *prefix)
|
||||
{
|
||||
if (IS_SIMPLE_TYPE(typ->typ))
|
||||
{
|
||||
ECPGdump_a_simple(o, name, typ->typ, typ->size, 0, 0, prefix);
|
||||
}
|
||||
else if (typ->typ == 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, 0, prefix);
|
||||
else if (typ->u.element->typ == ECPGt_array)
|
||||
{
|
||||
abort(); /* Array of array, */
|
||||
}
|
||||
else if (typ->u.element->typ == ECPGt_record)
|
||||
{
|
||||
/* Array of records. */
|
||||
ECPGdump_a_record(o, name, typ->size, typ->u.element, 0, prefix);
|
||||
}
|
||||
else
|
||||
{
|
||||
abort();
|
||||
}
|
||||
}
|
||||
else if (typ->typ == ECPGt_record)
|
||||
{
|
||||
ECPGdump_a_record(o, name, 0, typ, 0, prefix);
|
||||
}
|
||||
else
|
||||
{
|
||||
abort();
|
||||
}
|
||||
if (IS_SIMPLE_TYPE(typ->typ))
|
||||
{
|
||||
ECPGdump_a_simple(o, name, typ->typ, typ->size, 0, 0, prefix);
|
||||
}
|
||||
else if (typ->typ == 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, 0, prefix);
|
||||
else if (typ->u.element->typ == ECPGt_array)
|
||||
{
|
||||
abort(); /* Array of array, */
|
||||
}
|
||||
else if (typ->u.element->typ == ECPGt_record)
|
||||
{
|
||||
/* Array of records. */
|
||||
ECPGdump_a_record(o, name, typ->size, typ->u.element, 0, prefix);
|
||||
}
|
||||
else
|
||||
{
|
||||
abort();
|
||||
}
|
||||
}
|
||||
else if (typ->typ == ECPGt_record)
|
||||
{
|
||||
ECPGdump_a_record(o, name, 0, typ, 0, prefix);
|
||||
}
|
||||
else
|
||||
{
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -162,163 +167,170 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype *typ, const char *pre
|
||||
string, it represents the offset needed if we are in an array of records. */
|
||||
void
|
||||
ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
|
||||
long varcharsize,
|
||||
long arrsiz,
|
||||
const char *siz,
|
||||
const char *prefix)
|
||||
long varcharsize,
|
||||
long arrsiz,
|
||||
const char *siz,
|
||||
const char *prefix)
|
||||
{
|
||||
switch (typ)
|
||||
{
|
||||
case ECPGt_char:
|
||||
if (varcharsize == 0) /* pointer */
|
||||
fprintf(o, "\n\tECPGt_char,%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz,
|
||||
siz == NULL ? "sizeof(char)" : siz);
|
||||
else
|
||||
fprintf(o, "\n\tECPGt_char,&%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz,
|
||||
siz == NULL ? "sizeof(char)" : siz);
|
||||
break;
|
||||
case ECPGt_unsigned_char:
|
||||
if (varcharsize == 0) /* pointer */
|
||||
fprintf(o, "\n\tECPGt_unsigned_char,%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz,
|
||||
siz == NULL ? "sizeof(char)" : siz);
|
||||
else
|
||||
fprintf(o, "\n\tECPGt_unsigned_char,&%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz,
|
||||
siz == NULL ? "sizeof(unsigned char)" : siz);
|
||||
break;
|
||||
case ECPGt_short:
|
||||
fprintf(o, "\n\tECPGt_short,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(short)" : siz);
|
||||
break;
|
||||
case ECPGt_unsigned_short:
|
||||
fprintf(o,
|
||||
"\n\tECPGt_unsigned_short,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(unsigned short)" : siz);
|
||||
break;
|
||||
case ECPGt_int:
|
||||
fprintf(o, "\n\tECPGt_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(int)" : siz);
|
||||
break;
|
||||
case ECPGt_unsigned_int:
|
||||
fprintf(o, "\n\tECPGt_unsigned_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(unsigned int)" : siz);
|
||||
break;
|
||||
case ECPGt_long:
|
||||
fprintf(o, "\n\tECPGt_long,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(long)" : siz);
|
||||
break;
|
||||
case ECPGt_unsigned_long:
|
||||
fprintf(o, "\n\tECPGt_unsigned_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(unsigned int)" : siz);
|
||||
break;
|
||||
case ECPGt_float:
|
||||
fprintf(o, "\n\tECPGt_float,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(float)" : siz);
|
||||
break;
|
||||
case ECPGt_double:
|
||||
fprintf(o, "\n\tECPGt_double,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(double)" : siz);
|
||||
break;
|
||||
case ECPGt_bool:
|
||||
fprintf(o, "\n\tECPGt_bool,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(bool)" : siz);
|
||||
break;
|
||||
case ECPGt_varchar:
|
||||
case ECPGt_varchar2:
|
||||
if (siz == NULL)
|
||||
fprintf(o, "\n\tECPGt_varchar,&%s%s,%ldL,%ldL,sizeof(struct varchar_%s), ",
|
||||
prefix ? prefix : "", name,
|
||||
varcharsize,
|
||||
arrsiz, name);
|
||||
else
|
||||
fprintf(o, "\n\tECPGt_varchar,&%s%s,%ldL,%ldL,%s, ",
|
||||
prefix ? prefix : "", name,
|
||||
varcharsize,
|
||||
arrsiz, siz);
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
switch (typ)
|
||||
{
|
||||
case ECPGt_char:
|
||||
if (varcharsize == 0) /* pointer */
|
||||
fprintf(o, "\n\tECPGt_char,%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz,
|
||||
siz == NULL ? "sizeof(char)" : siz);
|
||||
else
|
||||
fprintf(o, "\n\tECPGt_char,&%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz,
|
||||
siz == NULL ? "sizeof(char)" : siz);
|
||||
break;
|
||||
case ECPGt_unsigned_char:
|
||||
if (varcharsize == 0) /* pointer */
|
||||
fprintf(o, "\n\tECPGt_unsigned_char,%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz,
|
||||
siz == NULL ? "sizeof(char)" : siz);
|
||||
else
|
||||
fprintf(o, "\n\tECPGt_unsigned_char,&%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz,
|
||||
siz == NULL ? "sizeof(unsigned char)" : siz);
|
||||
break;
|
||||
case ECPGt_short:
|
||||
fprintf(o, "\n\tECPGt_short,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(short)" : siz);
|
||||
break;
|
||||
case ECPGt_unsigned_short:
|
||||
fprintf(o,
|
||||
"\n\tECPGt_unsigned_short,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(unsigned short)" : siz);
|
||||
break;
|
||||
case ECPGt_int:
|
||||
fprintf(o, "\n\tECPGt_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(int)" : siz);
|
||||
break;
|
||||
case ECPGt_unsigned_int:
|
||||
fprintf(o, "\n\tECPGt_unsigned_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(unsigned int)" : siz);
|
||||
break;
|
||||
case ECPGt_long:
|
||||
fprintf(o, "\n\tECPGt_long,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(long)" : siz);
|
||||
break;
|
||||
case ECPGt_unsigned_long:
|
||||
fprintf(o, "\n\tECPGt_unsigned_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(unsigned int)" : siz);
|
||||
break;
|
||||
case ECPGt_float:
|
||||
fprintf(o, "\n\tECPGt_float,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(float)" : siz);
|
||||
break;
|
||||
case ECPGt_double:
|
||||
fprintf(o, "\n\tECPGt_double,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(double)" : siz);
|
||||
break;
|
||||
case ECPGt_bool:
|
||||
fprintf(o, "\n\tECPGt_bool,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
|
||||
siz == NULL ? "sizeof(bool)" : siz);
|
||||
break;
|
||||
case ECPGt_varchar:
|
||||
case ECPGt_varchar2:
|
||||
if (siz == NULL)
|
||||
fprintf(o, "\n\tECPGt_varchar,&%s%s,%ldL,%ldL,sizeof(struct varchar_%s), ",
|
||||
prefix ? prefix : "", name,
|
||||
varcharsize,
|
||||
arrsiz, name);
|
||||
else
|
||||
fprintf(o, "\n\tECPGt_varchar,&%s%s,%ldL,%ldL,%s, ",
|
||||
prefix ? prefix : "", name,
|
||||
varcharsize,
|
||||
arrsiz, siz);
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Penetrate a record and dump the contents. */
|
||||
void
|
||||
ECPGdump_a_record(FILE *o, const char *name, long arrsiz, struct ECPGtype *typ, const char *offsetarg, const char *prefix)
|
||||
ECPGdump_a_record(FILE *o, const char *name, long arrsiz, struct ECPGtype * typ, const char *offsetarg, const char *prefix)
|
||||
{
|
||||
/* If offset is NULL, then this is the first recursive level. If not then
|
||||
we are in a record in a record and the offset is used as offset.
|
||||
*/
|
||||
struct ECPGrecord_member *p;
|
||||
char obuf[BUFSIZ];
|
||||
char pbuf[BUFSIZ];
|
||||
const char *offset;
|
||||
|
||||
if (offsetarg == NULL)
|
||||
{
|
||||
sprintf(obuf, "sizeof(%s)", name);
|
||||
offset = obuf;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = offsetarg;
|
||||
}
|
||||
|
||||
sprintf(pbuf, "%s%s.", prefix ? prefix : "", name);
|
||||
prefix = pbuf;
|
||||
/*
|
||||
* If offset is NULL, then this is the first recursive level. If not
|
||||
* then we are in a record in a record and the offset is used as
|
||||
* offset.
|
||||
*/
|
||||
struct ECPGrecord_member *p;
|
||||
char obuf[BUFSIZ];
|
||||
char pbuf[BUFSIZ];
|
||||
const char *offset;
|
||||
|
||||
for (p = typ->u.members; p; p=p->next)
|
||||
{
|
||||
if (offsetarg == NULL)
|
||||
{
|
||||
sprintf(obuf, "sizeof(%s)", name);
|
||||
offset = obuf;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = offsetarg;
|
||||
}
|
||||
|
||||
sprintf(pbuf, "%s%s.", prefix ? prefix : "", name);
|
||||
prefix = pbuf;
|
||||
|
||||
for (p = typ->u.members; p; p = p->next)
|
||||
{
|
||||
#if 0
|
||||
if (IS_SIMPLE_TYPE(p->typ->typ))
|
||||
{
|
||||
sprintf(buf, "%s.%s", name, p->name);
|
||||
ECPGdump_a_simple(o, buf, p->typ->typ, p->typ->size,
|
||||
arrsiz, offset);
|
||||
}
|
||||
else if (p->typ->typ == ECPGt_array)
|
||||
{
|
||||
int i;
|
||||
if (IS_SIMPLE_TYPE(p->typ->typ))
|
||||
{
|
||||
sprintf(buf, "%s.%s", name, p->name);
|
||||
ECPGdump_a_simple(o, buf, p->typ->typ, p->typ->size,
|
||||
arrsiz, offset);
|
||||
}
|
||||
else if (p->typ->typ == ECPGt_array)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < p->typ->size; i++)
|
||||
{
|
||||
if (IS_SIMPLE_TYPE(p->typ->u.element->typ))
|
||||
{
|
||||
/* sprintf(buf, "%s.%s[%d]", name, p->name, i); */
|
||||
sprintf(buf, "%s.%s", name, p->name);
|
||||
ECPGdump_a_simple(o, buf, p->typ->u.element->typ, p->typ->u.element->size,
|
||||
p->typ->u.element->size, offset);
|
||||
}
|
||||
else if (p->typ->u.element->typ == ECPGt_array)
|
||||
{
|
||||
/* Array within an array. NOT implemented. */
|
||||
abort();
|
||||
}
|
||||
else if (p->typ->u.element->typ == ECPGt_record)
|
||||
{
|
||||
/* Record within array within record. NOT implemented yet. */
|
||||
abort();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Unknown type */
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (p->typ->typ == ECPGt_record)
|
||||
{
|
||||
/* Record within a record */
|
||||
sprintf(buf, "%s.%s", name, p->name);
|
||||
ECPGdump_a_record(o, buf, arrsiz, p->typ, offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Unknown type */
|
||||
abort();
|
||||
}
|
||||
for (i = 0; i < p->typ->size; i++)
|
||||
{
|
||||
if (IS_SIMPLE_TYPE(p->typ->u.element->typ))
|
||||
{
|
||||
/* sprintf(buf, "%s.%s[%d]", name, p->name, i); */
|
||||
sprintf(buf, "%s.%s", name, p->name);
|
||||
ECPGdump_a_simple(o, buf, p->typ->u.element->typ, p->typ->u.element->size,
|
||||
p->typ->u.element->size, offset);
|
||||
}
|
||||
else if (p->typ->u.element->typ == ECPGt_array)
|
||||
{
|
||||
/* Array within an array. NOT implemented. */
|
||||
abort();
|
||||
}
|
||||
else if (p->typ->u.element->typ == ECPGt_record)
|
||||
{
|
||||
|
||||
/*
|
||||
* Record within array within record. NOT implemented
|
||||
* yet.
|
||||
*/
|
||||
abort();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Unknown type */
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (p->typ->typ == ECPGt_record)
|
||||
{
|
||||
/* Record within a record */
|
||||
sprintf(buf, "%s.%s", name, p->name);
|
||||
ECPGdump_a_record(o, buf, arrsiz, p->typ, offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Unknown type */
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
ECPGdump_a_type(o, p->name, p->typ, prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -326,43 +338,43 @@ ECPGdump_a_record(FILE *o, const char *name, long arrsiz, struct ECPGtype *typ,
|
||||
anyway. Lets implement that last! */
|
||||
|
||||
void
|
||||
ECPGfree_record_member(struct ECPGrecord_member *rm)
|
||||
ECPGfree_record_member(struct ECPGrecord_member * rm)
|
||||
{
|
||||
while (rm)
|
||||
{
|
||||
struct ECPGrecord_member *p = rm;
|
||||
while (rm)
|
||||
{
|
||||
struct ECPGrecord_member *p = rm;
|
||||
|
||||
rm = rm->next;
|
||||
free(p->name);
|
||||
free(p);
|
||||
}
|
||||
rm = rm->next;
|
||||
free(p->name);
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ECPGfree_type(struct ECPGtype *typ)
|
||||
ECPGfree_type(struct ECPGtype * typ)
|
||||
{
|
||||
if (!IS_SIMPLE_TYPE(typ->typ))
|
||||
{
|
||||
if (typ->typ == ECPGt_array)
|
||||
{
|
||||
if (IS_SIMPLE_TYPE(typ->u.element->typ))
|
||||
free(typ->u.element);
|
||||
else if (typ->u.element->typ == ECPGt_array)
|
||||
abort(); /* Array of array, */
|
||||
else if (typ->u.element->typ == ECPGt_record)
|
||||
/* Array of records. */
|
||||
ECPGfree_record_member(typ->u.members);
|
||||
else
|
||||
abort();
|
||||
}
|
||||
else if (typ->typ == ECPGt_record)
|
||||
{
|
||||
ECPGfree_record_member(typ->u.members);
|
||||
}
|
||||
else
|
||||
{
|
||||
abort();
|
||||
}
|
||||
}
|
||||
free(typ);
|
||||
if (!IS_SIMPLE_TYPE(typ->typ))
|
||||
{
|
||||
if (typ->typ == ECPGt_array)
|
||||
{
|
||||
if (IS_SIMPLE_TYPE(typ->u.element->typ))
|
||||
free(typ->u.element);
|
||||
else if (typ->u.element->typ == ECPGt_array)
|
||||
abort(); /* Array of array, */
|
||||
else if (typ->u.element->typ == ECPGt_record)
|
||||
/* Array of records. */
|
||||
ECPGfree_record_member(typ->u.members);
|
||||
else
|
||||
abort();
|
||||
}
|
||||
else if (typ->typ == ECPGt_record)
|
||||
{
|
||||
ECPGfree_record_member(typ->u.members);
|
||||
}
|
||||
else
|
||||
{
|
||||
abort();
|
||||
}
|
||||
}
|
||||
free(typ);
|
||||
}
|
||||
|
||||
@@ -1,36 +1,39 @@
|
||||
#include <ecpgtype.h>
|
||||
|
||||
struct ECPGtype;
|
||||
struct ECPGrecord_member {
|
||||
char * name;
|
||||
struct ECPGtype * typ;
|
||||
struct ECPGrecord_member * next;
|
||||
struct ECPGrecord_member
|
||||
{
|
||||
char *name;
|
||||
struct ECPGtype *typ;
|
||||
struct ECPGrecord_member *next;
|
||||
};
|
||||
|
||||
struct ECPGtype {
|
||||
enum ECPGttype typ;
|
||||
long size; /* For array it is the number of elements.
|
||||
* For varchar it is the maxsize of the area.
|
||||
*/
|
||||
union {
|
||||
struct ECPGtype * element; /* For an array this is the type of the
|
||||
* element */
|
||||
struct ECPGtype
|
||||
{
|
||||
enum ECPGttype typ;
|
||||
long size; /* For array it is the number of elements.
|
||||
* For varchar it is the maxsize of the
|
||||
* area. */
|
||||
union
|
||||
{
|
||||
struct ECPGtype *element; /* For an array this is the type
|
||||
* of the element */
|
||||
|
||||
struct ECPGrecord_member * members;
|
||||
/* A pointer to a list of members. */
|
||||
} u;
|
||||
struct ECPGrecord_member *members;
|
||||
/* A pointer to a list of members. */
|
||||
} u;
|
||||
};
|
||||
|
||||
/* Everything is malloced. */
|
||||
struct ECPGrecord_member * ECPGmake_record_member(char *, struct ECPGtype *, struct ECPGrecord_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);
|
||||
struct ECPGtype * ECPGmake_record_type(struct ECPGrecord_member *);
|
||||
struct ECPGrecord_member *ECPGmake_record_member(char *, struct ECPGtype *, struct ECPGrecord_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);
|
||||
struct ECPGtype *ECPGmake_record_type(struct ECPGrecord_member *);
|
||||
|
||||
/* Frees a type. */
|
||||
void ECPGfree_record_member(struct ECPGrecord_member *);
|
||||
void ECPGfree_type(struct ECPGtype *);
|
||||
void ECPGfree_record_member(struct ECPGrecord_member *);
|
||||
void ECPGfree_type(struct ECPGtype *);
|
||||
|
||||
/* Dump a type.
|
||||
The type is dumped as:
|
||||
@@ -39,32 +42,34 @@ void ECPGfree_type(struct ECPGtype *);
|
||||
type-tag is one of the simple types or varchar.
|
||||
reference-to-variable can be a reference to a struct element.
|
||||
arrsize is the size of the array in case of array fetches. Otherwise 0.
|
||||
size is the maxsize in case it is a varchar. Otherwise it is the size of
|
||||
the variable (required to do array fetches of records).
|
||||
size is the maxsize in case it is a varchar. Otherwise it is the size of
|
||||
the variable (required to do array fetches of records).
|
||||
*/
|
||||
void ECPGdump_a_type(FILE *, const char * name, struct ECPGtype *, const char *);
|
||||
void ECPGdump_a_type(FILE *, const char *name, struct ECPGtype *, const char *);
|
||||
|
||||
/* A simple struct to keep a variable and its type. */
|
||||
struct ECPGtemp_type {
|
||||
struct ECPGtype * typ;
|
||||
const char * name;
|
||||
struct ECPGtemp_type
|
||||
{
|
||||
struct ECPGtype *typ;
|
||||
const char *name;
|
||||
};
|
||||
|
||||
extern const char * ECPGtype_name(enum ECPGttype typ);
|
||||
extern const char *ECPGtype_name(enum ECPGttype typ);
|
||||
|
||||
/* some stuff for whenever statements */
|
||||
enum WHEN {
|
||||
W_NOTHING,
|
||||
W_CONTINUE,
|
||||
W_BREAK,
|
||||
W_SQLPRINT,
|
||||
W_GOTO,
|
||||
W_DO,
|
||||
W_STOP
|
||||
enum WHEN
|
||||
{
|
||||
W_NOTHING,
|
||||
W_CONTINUE,
|
||||
W_BREAK,
|
||||
W_SQLPRINT,
|
||||
W_GOTO,
|
||||
W_DO,
|
||||
W_STOP
|
||||
};
|
||||
|
||||
struct when
|
||||
{
|
||||
enum WHEN code;
|
||||
char * str;
|
||||
{
|
||||
enum WHEN code;
|
||||
char *str;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user