提交 4e1ed3da 编写于 作者: M Michael Meskes

- Added more compatibility functions.

	- Accept CPP defines for type definitions.
	- Do not parse system include files automatically for Informix mode
上级 78b08584
...@@ -1408,6 +1408,12 @@ Tue May 6 11:51:33 CEST 2003 ...@@ -1408,6 +1408,12 @@ Tue May 6 11:51:33 CEST 2003
Tue May 13 13:34:12 CEST 2003 Tue May 13 13:34:12 CEST 2003
- Fixed order of include search path. - Fixed order of include search path.
Wed May 14 13:05:49 CEST 2003
- Added more compatibility functions.
- Accept CPP defines for type definitions.
- Do not parse system include files automatically for Informix mode
- Set ecpg version to 2.12.0. - Set ecpg version to 2.12.0.
- Set ecpg library to 3.4.2. - Set ecpg library to 3.4.2.
- Set pgtypes library to 1.0.0 - Set pgtypes library to 1.0.0
......
...@@ -609,6 +609,28 @@ rfmtlong(long lng_val, char *fmt, char *outbuf) ...@@ -609,6 +609,28 @@ rfmtlong(long lng_val, char *fmt, char *outbuf)
return 0; return 0;
} }
void
rupshift(char *str)
{
for (; *str != '\0'; str++)
if (islower(*str)) *str = toupper(*str);
return;
}
int
byleng(char *str, int len)
{
for (len--; str[len] && str[len] == ' '; len--);
return (len+1);
}
void
ldchar(char *src, int len, char *dest)
{
memmove(dest, src, len);
dest[len]=0;
}
int int
rgetmsg(int msgnum, char *s, int maxsize) rgetmsg(int msgnum, char *s, int maxsize)
{ {
...@@ -639,13 +661,15 @@ rtypmsize(int type, int len) ...@@ -639,13 +661,15 @@ rtypmsize(int type, int len)
return 0; return 0;
} }
void int
rupshift(char *str) rtypwidth(int sqltype, int sqllen)
{ {
for (; *str != '\0'; str++) return 0;
if (islower(*str)) *str = toupper(*str);
return;
} }
int
dtcvfmtasc (char *inbuf, char *fmtstr, dtime_t *dtvalue)
{
return 0;
}
...@@ -15,4 +15,4 @@ extern int dtsub (dtime_t *, dtime_t *, intrvl_t *); ...@@ -15,4 +15,4 @@ extern int dtsub (dtime_t *, dtime_t *, intrvl_t *);
extern int dttoasc (dtime_t *, char *); extern int dttoasc (dtime_t *, char *);
extern int dttofmtasc (dtime_t *, char *, int, char *); extern int dttofmtasc (dtime_t *, char *, int, char *);
extern int intoasc(intrvl_t *, char *); extern int intoasc(intrvl_t *, char *);
extern int dtcvfmtasc(char *, char *, dtime_t *);
...@@ -26,6 +26,9 @@ extern int risnull(int, char *); ...@@ -26,6 +26,9 @@ extern int risnull(int, char *);
extern int rsetnull(int, char *); extern int rsetnull(int, char *);
extern int rtypalign(int, int); extern int rtypalign(int, int);
extern int rtypmsize(int, int); extern int rtypmsize(int, int);
extern int rtypwidth(int, int);
extern void rupshift(char *); extern void rupshift(char *);
extern int byleng(char *, int);
extern void ldchar(char *, int, char *);
...@@ -192,7 +192,7 @@ output_get_descr(char *desc_name, char *index) ...@@ -192,7 +192,7 @@ output_get_descr(char *desc_name, char *index)
break; break;
} }
fprintf(yyout, "%s,", get_dtype(results->value)); fprintf(yyout, "%s,", get_dtype(results->value));
ECPGdump_a_type(yyout, v->name, v->type, NULL, NULL, NULL, NULL, 0L, NULL, NULL); ECPGdump_a_type(yyout, v->name, v->type, NULL, NULL, NULL, NULL, make_str("0"), NULL, NULL);
} }
drop_assignments(); drop_assignments();
fputs("ECPGd_EODT);\n", yyout); fputs("ECPGd_EODT);\n", yyout);
......
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.69 2003/05/13 11:29:14 meskes Exp $ */ /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.70 2003/05/14 14:37:35 meskes Exp $ */
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */ /* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */ /* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
...@@ -162,7 +162,7 @@ main(int argc, char *const argv[]) ...@@ -162,7 +162,7 @@ main(int argc, char *const argv[])
if (strcmp(optarg, "INFORMIX") == 0) if (strcmp(optarg, "INFORMIX") == 0)
{ {
compat = ECPG_COMPAT_INFORMIX; compat = ECPG_COMPAT_INFORMIX;
system_includes = true; /* system_includes = true; */
add_preprocessor_define("dec_t=Numeric"); add_preprocessor_define("dec_t=Numeric");
add_preprocessor_define("intrvl_t=Interval"); add_preprocessor_define("intrvl_t=Interval");
} }
......
...@@ -77,7 +77,7 @@ extern void add_variable(struct arguments **, struct variable *, struct variable ...@@ -77,7 +77,7 @@ extern void add_variable(struct arguments **, struct variable *, struct variable
extern void append_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 void dump_variables(struct arguments *, int);
extern struct typedefs *get_typedef(char *); extern struct typedefs *get_typedef(char *);
extern void adjust_array(enum ECPGttype, int *, int *, int, int, int); extern void adjust_array(enum ECPGttype, char **, char **, char *, char *, int);
extern void reset_variables(void); extern void reset_variables(void);
extern void check_indicator(struct ECPGtype *); extern void check_indicator(struct ECPGtype *);
extern void remove_variables(int); extern void remove_variables(int);
......
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.216 2003/05/02 14:43:25 meskes Exp $ */ /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.217 2003/05/14 14:37:35 meskes Exp $ */
/* Copyright comment */ /* Copyright comment */
%{ %{
...@@ -139,8 +139,8 @@ make_name(void) ...@@ -139,8 +139,8 @@ make_name(void)
%union { %union {
double dval; double dval;
int ival;
char *str; char *str;
int ival;
struct when action; struct when action;
struct index index; struct index index;
int tagname; int tagname;
...@@ -289,7 +289,7 @@ make_name(void) ...@@ -289,7 +289,7 @@ make_name(void)
%type <str> CreateAsElement OptCreateAs CreateAsList CreateAsStmt %type <str> CreateAsElement OptCreateAs CreateAsList CreateAsStmt
%type <str> comment_text ConstraintDeferrabilitySpec TableElementList %type <str> comment_text ConstraintDeferrabilitySpec TableElementList
%type <str> key_match ColLabel SpecialRuleRelation ColId columnDef %type <str> key_match ColLabel SpecialRuleRelation ColId columnDef
%type <str> ColConstraint ColConstraintElem drop_type Bconst %type <str> ColConstraint ColConstraintElem drop_type Bconst Iresult
%type <str> TableConstraint OptTableElementList Xconst opt_transaction %type <str> TableConstraint OptTableElementList Xconst opt_transaction
%type <str> ConstraintElem key_actions ColQualList type_name %type <str> ConstraintElem key_actions ColQualList type_name
%type <str> target_list target_el update_target_list alias_clause %type <str> target_list target_el update_target_list alias_clause
...@@ -405,8 +405,6 @@ make_name(void) ...@@ -405,8 +405,6 @@ make_name(void)
%type <index> opt_array_bounds %type <index> opt_array_bounds
%type <ival> Iresult
%% %%
prog: statements; prog: statements;
...@@ -2955,34 +2953,33 @@ Typename: SimpleTypename opt_array_bounds ...@@ -2955,34 +2953,33 @@ Typename: SimpleTypename opt_array_bounds
opt_array_bounds: '[' ']' opt_array_bounds opt_array_bounds: '[' ']' opt_array_bounds
{ {
$$.index1 = 0; $$.index1 = make_str("0");
$$.index2 = $3.index1; $$.index2 = $3.index1;
$$.str = cat2_str(make_str("[]"), $3.str); $$.str = cat2_str(make_str("[]"), $3.str);
} }
| '[' Iresult ']' opt_array_bounds | '[' Iresult ']' opt_array_bounds
{ {
char *txt = mm_alloc(20L); $$.index1 = strdup($2);
sprintf (txt, "%d", $2);
$$.index1 = $2;
$$.index2 = $4.index1; $$.index2 = $4.index1;
$$.str = cat_str(4, make_str("["), txt, make_str("]"), $4.str); $$.str = cat_str(4, make_str("["), $2, make_str("]"), $4.str);
} }
| /* EMPTY */ | /* EMPTY */
{ {
$$.index1 = -1; $$.index1 = make_str("-1");
$$.index2 = -1; $$.index2 = make_str("-1");
$$.str= EMPTY; $$.str= EMPTY;
} }
; ;
Iresult: PosIntConst { $$ = atol($1); } Iresult: PosIntConst { $$ = $1; }
| '(' Iresult ')' { $$ = $2; } | '(' Iresult ')' { $$ = cat_str(3, make_str("("), $2, make_str(")")); }
| Iresult '+' Iresult { $$ = $1 + $3; } | Iresult '+' Iresult { $$ = cat_str(3, $1, make_str("+"), $3); }
| Iresult '-' Iresult { $$ = $1 - $3; } | Iresult '-' Iresult { $$ = cat_str(3, $1, make_str("-"), $3); }
| Iresult '*' Iresult { $$ = $1 * $3; } | Iresult '*' Iresult { $$ = cat_str(3, $1, make_str("*"), $3); }
| Iresult '/' Iresult { $$ = $1 / $3; } | Iresult '/' Iresult { $$ = cat_str(3, $1, make_str("/"), $3); }
| Iresult '%' Iresult { $$ = $1 % $3; } | Iresult '%' Iresult { $$ = cat_str(3, $1, make_str("%"), $3); }
| Sconst { $$ = $1; }
| ColId { $$ = $1; }
; ;
SimpleTypename: GenericType { $$ = $1; } SimpleTypename: GenericType { $$ = $1; }
...@@ -4199,72 +4196,72 @@ single_vt_type: common_type ...@@ -4199,72 +4196,72 @@ single_vt_type: common_type
{ {
$$.type_enum = ECPGt_varchar; $$.type_enum = ECPGt_varchar;
$$.type_str = EMPTY; $$.type_str = EMPTY;
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else if (strcmp($1, "float") == 0) else if (strcmp($1, "float") == 0)
{ {
$$.type_enum = ECPGt_float; $$.type_enum = ECPGt_float;
$$.type_str = make_str("float"); $$.type_str = make_str("float");
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else if (strcmp($1, "double") == 0) else if (strcmp($1, "double") == 0)
{ {
$$.type_enum = ECPGt_double; $$.type_enum = ECPGt_double;
$$.type_str = make_str("double"); $$.type_str = make_str("double");
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else if (strcmp($1, "numeric") == 0) else if (strcmp($1, "numeric") == 0)
{ {
$$.type_enum = ECPGt_numeric; $$.type_enum = ECPGt_numeric;
$$.type_str = EMPTY; $$.type_str = EMPTY;
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else if (strcmp($1, "decimal") == 0) else if (strcmp($1, "decimal") == 0)
{ {
$$.type_enum = ECPGt_numeric; $$.type_enum = ECPGt_numeric;
$$.type_str = EMPTY; $$.type_str = EMPTY;
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else if (strcmp($1, "date") == 0) else if (strcmp($1, "date") == 0)
{ {
$$.type_enum = ECPGt_date; $$.type_enum = ECPGt_date;
$$.type_str = make_str("Date"); $$.type_str = make_str("Date");
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else if (strcmp($1, "timestamp") == 0) else if (strcmp($1, "timestamp") == 0)
{ {
$$.type_enum = ECPGt_timestamp; $$.type_enum = ECPGt_timestamp;
$$.type_str = make_str("Timestamp"); $$.type_str = make_str("Timestamp");
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else if (strcmp($1, "datetime") == 0) else if (strcmp($1, "datetime") == 0)
{ {
$$.type_enum = ECPGt_timestamp; $$.type_enum = ECPGt_timestamp;
$$.type_str = make_str("Timestamp"); $$.type_str = make_str("Timestamp");
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else if (strcmp($1, "interval") == 0) else if (strcmp($1, "interval") == 0)
{ {
$$.type_enum = ECPGt_interval; $$.type_enum = ECPGt_interval;
$$.type_str = EMPTY; $$.type_str = EMPTY;
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else else
...@@ -4323,8 +4320,8 @@ type_declaration: S_TYPEDEF ...@@ -4323,8 +4320,8 @@ type_declaration: S_TYPEDEF
{ {
/* add entry to list */ /* add entry to list */
struct typedefs *ptr, *this; struct typedefs *ptr, *this;
int dimension = $6.index1; char * dimension = $6.index1;
int length = $6.index2; char * length = $6.index2;
if (($3.type_enum == ECPGt_struct || if (($3.type_enum == ECPGt_struct ||
$3.type_enum == ECPGt_union) && $3.type_enum == ECPGt_union) &&
...@@ -4364,7 +4361,7 @@ type_declaration: S_TYPEDEF ...@@ -4364,7 +4361,7 @@ type_declaration: S_TYPEDEF
if ($3.type_enum != ECPGt_varchar && if ($3.type_enum != ECPGt_varchar &&
$3.type_enum != ECPGt_char && $3.type_enum != ECPGt_char &&
$3.type_enum != ECPGt_unsigned_char && $3.type_enum != ECPGt_unsigned_char &&
this->type->type_index >= 0) atoi(this->type->type_index) >= 0)
mmerror(PARSE_ERROR, ET_ERROR, "No multi-dimensional array support for simple data types"); mmerror(PARSE_ERROR, ET_ERROR, "No multi-dimensional array support for simple data types");
types = this; types = this;
...@@ -4420,32 +4417,32 @@ common_type: simple_type ...@@ -4420,32 +4417,32 @@ common_type: simple_type
{ {
$$.type_enum = $1; $$.type_enum = $1;
$$.type_str = mm_strdup(ECPGtype_name($1)); $$.type_str = mm_strdup(ECPGtype_name($1));
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
| struct_type | struct_type
{ {
$$.type_enum = ECPGt_struct; $$.type_enum = ECPGt_struct;
$$.type_str = $1; $$.type_str = $1;
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = ECPGstruct_sizeof; $$.type_sizeof = ECPGstruct_sizeof;
} }
| union_type | union_type
{ {
$$.type_enum = ECPGt_union; $$.type_enum = ECPGt_union;
$$.type_str = $1; $$.type_str = $1;
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
| enum_type | enum_type
{ {
$$.type_str = $1; $$.type_str = $1;
$$.type_enum = ECPGt_int; $$.type_enum = ECPGt_int;
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
| ECPGColLabelCommon '(' precision opt_scale ')' | ECPGColLabelCommon '(' precision opt_scale ')'
...@@ -4455,8 +4452,8 @@ common_type: simple_type ...@@ -4455,8 +4452,8 @@ common_type: simple_type
$$.type_enum = ECPGt_numeric; $$.type_enum = ECPGt_numeric;
$$.type_str = EMPTY; $$.type_str = EMPTY;
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
; ;
...@@ -4475,72 +4472,72 @@ var_type: common_type ...@@ -4475,72 +4472,72 @@ var_type: common_type
{ {
$$.type_enum = ECPGt_varchar; $$.type_enum = ECPGt_varchar;
$$.type_str = EMPTY; /*make_str("varchar");*/ $$.type_str = EMPTY; /*make_str("varchar");*/
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else if (strcmp($1, "float") == 0) else if (strcmp($1, "float") == 0)
{ {
$$.type_enum = ECPGt_float; $$.type_enum = ECPGt_float;
$$.type_str = make_str("float"); $$.type_str = make_str("float");
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else if (strcmp($1, "double") == 0) else if (strcmp($1, "double") == 0)
{ {
$$.type_enum = ECPGt_double; $$.type_enum = ECPGt_double;
$$.type_str = make_str("double"); $$.type_str = make_str("double");
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else if (strcmp($1, "numeric") == 0) else if (strcmp($1, "numeric") == 0)
{ {
$$.type_enum = ECPGt_numeric; $$.type_enum = ECPGt_numeric;
$$.type_str = EMPTY; $$.type_str = EMPTY;
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else if (strcmp($1, "decimal") == 0) else if (strcmp($1, "decimal") == 0)
{ {
$$.type_enum = ECPGt_numeric; $$.type_enum = ECPGt_numeric;
$$.type_str = EMPTY; $$.type_str = EMPTY;
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else if (strcmp($1, "date") == 0) else if (strcmp($1, "date") == 0)
{ {
$$.type_enum = ECPGt_date; $$.type_enum = ECPGt_date;
$$.type_str = make_str("Date"); $$.type_str = make_str("Date");
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else if (strcmp($1, "timestamp") == 0) else if (strcmp($1, "timestamp") == 0)
{ {
$$.type_enum = ECPGt_timestamp; $$.type_enum = ECPGt_timestamp;
$$.type_str = make_str("Timestamp"); $$.type_str = make_str("Timestamp");
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else if (strcmp($1, "interval") == 0) else if (strcmp($1, "interval") == 0)
{ {
$$.type_enum = ECPGt_interval; $$.type_enum = ECPGt_interval;
$$.type_str = EMPTY; $$.type_str = EMPTY;
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else if (strcmp($1, "datetime") == 0) else if (strcmp($1, "datetime") == 0)
{ {
$$.type_enum = ECPGt_timestamp; $$.type_enum = ECPGt_timestamp;
$$.type_str = make_str("Timestamp"); $$.type_str = make_str("Timestamp");
$$.type_dimension = -1; $$.type_dimension = make_str("-1");
$$.type_index = -1; $$.type_index = make_str("-1");
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
} }
else else
...@@ -4672,8 +4669,8 @@ variable_list: variable ...@@ -4672,8 +4669,8 @@ variable_list: variable
variable: opt_pointer ECPGColLabelCommon opt_array_bounds opt_initializer variable: opt_pointer ECPGColLabelCommon opt_array_bounds opt_initializer
{ {
struct ECPGtype * type; struct ECPGtype * type;
int dimension = $3.index1; /* dimension of array */ char *dimension = $3.index1; /* dimension of array */
int length = $3.index2; /* lenght of string */ char *length = $3.index2; /* lenght of string */
char dim[14L], ascii_len[12]; char dim[14L], ascii_len[12];
adjust_array(actual_type[struct_level].type_enum, &dimension, &length, actual_type[struct_level].type_dimension, actual_type[struct_level].type_index, strlen($1)); adjust_array(actual_type[struct_level].type_enum, &dimension, &length, actual_type[struct_level].type_dimension, actual_type[struct_level].type_index, strlen($1));
...@@ -4682,7 +4679,7 @@ variable: opt_pointer ECPGColLabelCommon opt_array_bounds opt_initializer ...@@ -4682,7 +4679,7 @@ variable: opt_pointer ECPGColLabelCommon opt_array_bounds opt_initializer
{ {
case ECPGt_struct: case ECPGt_struct:
case ECPGt_union: case ECPGt_union:
if (dimension < 0) if (atoi(dimension) < 0)
type = ECPGmake_struct_type(struct_member_list[struct_level], actual_type[struct_level].type_enum, actual_type[struct_level].type_sizeof); type = ECPGmake_struct_type(struct_member_list[struct_level], actual_type[struct_level].type_enum, actual_type[struct_level].type_sizeof);
else else
type = ECPGmake_array_type(ECPGmake_struct_type(struct_member_list[struct_level], actual_type[struct_level].type_enum, actual_type[struct_level].type_sizeof), dimension); type = ECPGmake_array_type(ECPGmake_struct_type(struct_member_list[struct_level], actual_type[struct_level].type_enum, actual_type[struct_level].type_sizeof), dimension);
...@@ -4691,36 +4688,27 @@ variable: opt_pointer ECPGColLabelCommon opt_array_bounds opt_initializer ...@@ -4691,36 +4688,27 @@ variable: opt_pointer ECPGColLabelCommon opt_array_bounds opt_initializer
break; break;
case ECPGt_varchar: case ECPGt_varchar:
if (dimension < 0) if (atoi(dimension) < 0)
type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length); type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length);
else else
type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension); type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension);
switch(dimension) if (strcmp(dimension, "0") == 0 || abs(atoi(dimension)) == 1)
{
case 0:
case -1:
case 1:
*dim = '\0'; *dim = '\0';
break; else
default: sprintf(dim, "[%s]", dimension);
sprintf(dim, "[%d]", dimension); if (strcmp(length, "0") == 0)
break;
}
sprintf(ascii_len, "%d", length);
if (length == 0)
mmerror(PARSE_ERROR, ET_ERROR, "pointer to varchar are not implemented"); mmerror(PARSE_ERROR, ET_ERROR, "pointer to varchar are not implemented");
if (dimension == 0) if (strcmp(dimension, "0") == 0)
$$ = cat_str(7, mm_strdup(actual_storage[struct_level]), make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(ascii_len), make_str("]; } *"), mm_strdup($2), $4); $$ = cat_str(7, mm_strdup(actual_storage[struct_level]), make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } *"), mm_strdup($2), $4);
else else
$$ = cat_str(8, mm_strdup(actual_storage[struct_level]), make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(ascii_len), make_str("]; } "), mm_strdup($2), mm_strdup(dim), $4); $$ = cat_str(8, mm_strdup(actual_storage[struct_level]), make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } "), mm_strdup($2), mm_strdup(dim), $4);
break; break;
case ECPGt_char: case ECPGt_char:
case ECPGt_unsigned_char: case ECPGt_unsigned_char:
if (dimension == -1) if (atoi(dimension) == -1)
type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length); type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length);
else else
type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension); type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension);
...@@ -4729,34 +4717,34 @@ variable: opt_pointer ECPGColLabelCommon opt_array_bounds opt_initializer ...@@ -4729,34 +4717,34 @@ variable: opt_pointer ECPGColLabelCommon opt_array_bounds opt_initializer
break; break;
case ECPGt_numeric: case ECPGt_numeric:
if (dimension < 0) if (atoi(dimension) < 0)
type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length); type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length);
else else
type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension); type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension);
if (dimension < 0) if (atoi(dimension) < 0)
$$ = cat_str(4, mm_strdup(actual_storage[struct_level]), make_str("Numeric"), mm_strdup($2), $4); $$ = cat_str(4, mm_strdup(actual_storage[struct_level]), make_str("Numeric"), mm_strdup($2), $4);
else else
$$ = cat_str(5, mm_strdup(actual_storage[struct_level]), make_str("Numeric"), mm_strdup($2), mm_strdup(dim), $4); $$ = cat_str(5, mm_strdup(actual_storage[struct_level]), make_str("Numeric"), mm_strdup($2), mm_strdup(dim), $4);
break; break;
case ECPGt_interval: case ECPGt_interval:
if (dimension < 0) if (atoi(dimension) < 0)
type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length); type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length);
else else
type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension); type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension);
if (dimension < 0) if (atoi(dimension) < 0)
$$ = cat_str(4, mm_strdup(actual_storage[struct_level]), make_str("Interval"), mm_strdup($2), $4); $$ = cat_str(4, mm_strdup(actual_storage[struct_level]), make_str("Interval"), mm_strdup($2), $4);
else else
$$ = cat_str(5, mm_strdup(actual_storage[struct_level]), make_str("Interval"), mm_strdup($2), mm_strdup(dim), $4); $$ = cat_str(5, mm_strdup(actual_storage[struct_level]), make_str("Interval"), mm_strdup($2), mm_strdup(dim), $4);
break; break;
default: default:
if (dimension < 0) if (atoi(dimension) < 0)
type = ECPGmake_simple_type(actual_type[struct_level].type_enum, 1); type = ECPGmake_simple_type(actual_type[struct_level].type_enum, make_str("1"));
else else
type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, 1), dimension); type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, make_str("1")), dimension);
$$ = cat_str(4, $1, mm_strdup($2), $3.str, $4); $$ = cat_str(4, $1, mm_strdup($2), $3.str, $4);
break; break;
...@@ -5026,8 +5014,8 @@ ECPGTypedef: TYPE_P ...@@ -5026,8 +5014,8 @@ ECPGTypedef: TYPE_P
{ {
/* add entry to list */ /* add entry to list */
struct typedefs *ptr, *this; struct typedefs *ptr, *this;
int dimension = $6.index1; char *dimension = $6.index1;
int length = $6.index2; char *length = $6.index2;
if (($5.type_enum == ECPGt_struct || if (($5.type_enum == ECPGt_struct ||
$5.type_enum == ECPGt_union) && $5.type_enum == ECPGt_union) &&
...@@ -5064,7 +5052,7 @@ ECPGTypedef: TYPE_P ...@@ -5064,7 +5052,7 @@ ECPGTypedef: TYPE_P
if ($5.type_enum != ECPGt_varchar && if ($5.type_enum != ECPGt_varchar &&
$5.type_enum != ECPGt_char && $5.type_enum != ECPGt_char &&
$5.type_enum != ECPGt_unsigned_char && $5.type_enum != ECPGt_unsigned_char &&
this->type->type_index >= 0) atoi(this->type->type_index) >= 0)
mmerror(PARSE_ERROR, ET_ERROR, "No multi-dimensional array support for simple data types"); mmerror(PARSE_ERROR, ET_ERROR, "No multi-dimensional array support for simple data types");
types = this; types = this;
...@@ -5093,8 +5081,8 @@ ECPGVar: SQL_VAR ...@@ -5093,8 +5081,8 @@ ECPGVar: SQL_VAR
ColLabel IS var_type opt_array_bounds opt_reference ColLabel IS var_type opt_array_bounds opt_reference
{ {
struct variable *p = find_variable($3); struct variable *p = find_variable($3);
int dimension = $6.index1; char *dimension = $6.index1;
int length = $6.index2; char *length = $6.index2;
struct ECPGtype * type; struct ECPGtype * type;
if (($5.type_enum == ECPGt_struct || if (($5.type_enum == ECPGt_struct ||
...@@ -5109,14 +5097,14 @@ ECPGVar: SQL_VAR ...@@ -5109,14 +5097,14 @@ ECPGVar: SQL_VAR
{ {
case ECPGt_struct: case ECPGt_struct:
case ECPGt_union: case ECPGt_union:
if (dimension < 0) if (atoi(dimension) < 0)
type = ECPGmake_struct_type(struct_member_list[struct_level], $5.type_enum, $5.type_sizeof); type = ECPGmake_struct_type(struct_member_list[struct_level], $5.type_enum, $5.type_sizeof);
else else
type = ECPGmake_array_type(ECPGmake_struct_type(struct_member_list[struct_level], $5.type_enum,$5.type_sizeof), dimension); type = ECPGmake_array_type(ECPGmake_struct_type(struct_member_list[struct_level], $5.type_enum,$5.type_sizeof), dimension);
break; break;
case ECPGt_varchar: case ECPGt_varchar:
if (dimension == -1) if (atoi(dimension) == -1)
type = ECPGmake_simple_type($5.type_enum, length); type = ECPGmake_simple_type($5.type_enum, length);
else else
type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, length), dimension); type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, length), dimension);
...@@ -5124,20 +5112,20 @@ ECPGVar: SQL_VAR ...@@ -5124,20 +5112,20 @@ ECPGVar: SQL_VAR
case ECPGt_char: case ECPGt_char:
case ECPGt_unsigned_char: case ECPGt_unsigned_char:
if (dimension == -1) if (atoi(dimension) == -1)
type = ECPGmake_simple_type($5.type_enum, length); type = ECPGmake_simple_type($5.type_enum, length);
else else
type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, length), dimension); type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, length), dimension);
break; break;
default: default:
if (length >= 0) if (atoi(length) >= 0)
mmerror(PARSE_ERROR, ET_ERROR, "No multi-dimensional array support for simple data types"); mmerror(PARSE_ERROR, ET_ERROR, "No multi-dimensional array support for simple data types");
if (dimension < 0) if (atoi(dimension) < 0)
type = ECPGmake_simple_type($5.type_enum, 1); type = ECPGmake_simple_type($5.type_enum, make_str("1"));
else else
type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, 1), dimension); type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, make_str("1")), dimension);
break; break;
} }
......
...@@ -83,7 +83,7 @@ ECPGmake_struct_member(char *name, struct ECPGtype * type, struct ECPGstruct_mem ...@@ -83,7 +83,7 @@ ECPGmake_struct_member(char *name, struct ECPGtype * type, struct ECPGstruct_mem
} }
struct ECPGtype * struct ECPGtype *
ECPGmake_simple_type(enum ECPGttype type, long size) ECPGmake_simple_type(enum ECPGttype type, char *size)
{ {
struct ECPGtype *ne = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype)); struct ECPGtype *ne = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
...@@ -96,7 +96,7 @@ ECPGmake_simple_type(enum ECPGttype type, long size) ...@@ -96,7 +96,7 @@ ECPGmake_simple_type(enum ECPGttype type, long size)
} }
struct ECPGtype * struct ECPGtype *
ECPGmake_array_type(struct ECPGtype * type, long size) ECPGmake_array_type(struct ECPGtype * type, char *size)
{ {
struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_array, size); struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_array, size);
...@@ -108,7 +108,7 @@ ECPGmake_array_type(struct ECPGtype * type, long size) ...@@ -108,7 +108,7 @@ ECPGmake_array_type(struct ECPGtype * type, long size)
struct ECPGtype * struct ECPGtype *
ECPGmake_struct_type(struct ECPGstruct_member * rm, enum ECPGttype type, char *struct_sizeof) ECPGmake_struct_type(struct ECPGstruct_member * rm, enum ECPGttype type, char *struct_sizeof)
{ {
struct ECPGtype *ne = ECPGmake_simple_type(type, 1); struct ECPGtype *ne = ECPGmake_simple_type(type, make_str("1"));
ne->u.members = ECPGstruct_member_dup(rm); ne->u.members = ECPGstruct_member_dup(rm);
ne->struct_sizeof = struct_sizeof; ne->struct_sizeof = struct_sizeof;
...@@ -207,13 +207,17 @@ get_type(enum ECPGttype type) ...@@ -207,13 +207,17 @@ get_type(enum ECPGttype type)
the variable (required to do array fetches of structs). the variable (required to do array fetches of structs).
*/ */
static void ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, static void ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
long varcharsize, char *varcharsize,
long arrsiz, const char *siz, const char *prefix); char *arrsiz, const char *siz, const char *prefix);
static void ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz, static void ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, char *arrsiz,
struct ECPGtype * type, struct ECPGtype * ind_type, const char *offset, const char *prefix, const char *ind_prefix); struct ECPGtype * type, struct ECPGtype * ind_type, const char *offset, const char *prefix, const char *ind_prefix);
void void
ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *ind_name, struct ECPGtype * ind_type, const char *prefix, const char *ind_prefix, const long arr_str_siz, const char *struct_sizeof, const char *ind_struct_sizeof) ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type,
const char *ind_name, struct ECPGtype * ind_type,
const char *prefix, const char *ind_prefix,
char *arr_str_siz, const char *struct_sizeof,
const char *ind_struct_sizeof)
{ {
switch (type->type) switch (type->type)
{ {
...@@ -239,7 +243,7 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *i ...@@ -239,7 +243,7 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *i
if (ind_type != NULL) if (ind_type != NULL)
{ {
if (ind_type->type == ECPGt_NO_INDICATOR) if (ind_type->type == ECPGt_NO_INDICATOR)
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, -1, NULL, ind_prefix); ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, make_str("-1"), NULL, ind_prefix);
else else
ECPGdump_a_simple(o, ind_name, ind_type->u.element->type, ECPGdump_a_simple(o, ind_name, ind_type->u.element->type,
ind_type->u.element->size, ind_type->size, NULL, prefix); ind_type->u.element->size, ind_type->size, NULL, prefix);
...@@ -250,7 +254,7 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *i ...@@ -250,7 +254,7 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *i
if (indicator_set && ind_type->type != ECPGt_struct) if (indicator_set && ind_type->type != ECPGt_struct)
mmerror(INDICATOR_NOT_STRUCT, ET_FATAL, "Indicator for struct has to be struct.\n"); mmerror(INDICATOR_NOT_STRUCT, ET_FATAL, "Indicator for struct has to be struct.\n");
ECPGdump_a_struct(o, name, ind_name, 1, type, ind_type, NULL, prefix, ind_prefix); ECPGdump_a_struct(o, name, ind_name, make_str("1"), type, ind_type, NULL, prefix, ind_prefix);
break; break;
case ECPGt_union: /* cannot dump a complete union */ case ECPGt_union: /* cannot dump a complete union */
yyerror("Type of union has to be specified"); yyerror("Type of union has to be specified");
...@@ -259,23 +263,23 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *i ...@@ -259,23 +263,23 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *i
if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array)) if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n"); mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n");
ECPGdump_a_simple(o, name, type->type, 1, arr_str_siz ? arr_str_siz : 1, struct_sizeof, prefix); ECPGdump_a_simple(o, name, type->type, make_str("1"), (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("1"), struct_sizeof, prefix);
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, arr_str_siz ? arr_str_siz : -1, ind_struct_sizeof, ind_prefix); ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), ind_struct_sizeof, ind_prefix);
break; break;
case ECPGt_descriptor: case ECPGt_descriptor:
if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array)) if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n"); mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n");
ECPGdump_a_simple(o, name, type->type, 0, -1, NULL, prefix); ECPGdump_a_simple(o, name, type->type, 0, make_str("-1"), NULL, prefix);
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, -1, NULL, ind_prefix); ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, make_str("-1"), NULL, ind_prefix);
break; break;
default: default:
if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array)) if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n"); mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n");
ECPGdump_a_simple(o, name, type->type, type->size, arr_str_siz ? arr_str_siz : -1, struct_sizeof, prefix); ECPGdump_a_simple(o, name, type->type, type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), struct_sizeof, prefix);
if (ind_type != NULL) if (ind_type != NULL)
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, arr_str_siz ? arr_str_siz : -1, ind_struct_sizeof, ind_prefix); ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), ind_struct_sizeof, ind_prefix);
break; break;
} }
} }
...@@ -285,8 +289,8 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *i ...@@ -285,8 +289,8 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *i
string, it represents the offset needed if we are in an array of structs. */ string, it represents the offset needed if we are in an array of structs. */
static void static void
ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
long varcharsize, char *varcharsize,
long arrsize, char *arrsize,
const char *siz, const char *siz,
const char *prefix const char *prefix
) )
...@@ -309,7 +313,9 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, ...@@ -309,7 +313,9 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
* we have to use the pointer except for arrays with given * we have to use the pointer except for arrays with given
* bounds * bounds
*/ */
if (arrsize > 0 && siz == NULL) if (((atoi(arrsize) > 0) ||
(atoi(arrsize) == 0) && strcmp(arrsize, "0") != 0) &&
siz == NULL)
sprintf(variable, "(%s%s)", prefix ? prefix : "", name); sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
else else
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name); sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
...@@ -324,12 +330,16 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, ...@@ -324,12 +330,16 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
* we have to use the pointer except for arrays with given * we have to use the pointer except for arrays with given
* bounds * bounds
*/ */
if ((varcharsize > 1 || arrsize > 0) && siz == NULL) if ((atoi(varcharsize) > 1 ||
(atoi(arrsize) > 0) ||
(atoi(varcharsize) == 0 && strcmp(varcharsize, "0") != 0) ||
(atoi(arrsize) == 0 && strcmp(arrsize, "0") != 0))
&& siz == NULL)
sprintf(variable, "(%s%s)", prefix ? prefix : "", name); sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
else else
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name); sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
sprintf(offset, "%ld*sizeof(char)", varcharsize == 0 ? 1 : varcharsize); sprintf(offset, "%s*sizeof(char)", strcmp(varcharsize, "0") == 0 ? "1" : varcharsize);
break; break;
case ECPGt_numeric: case ECPGt_numeric:
...@@ -369,7 +379,9 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, ...@@ -369,7 +379,9 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
* we have to use the pointer except for arrays with given * we have to use the pointer except for arrays with given
* bounds * bounds
*/ */
if (arrsize > 0 && siz == NULL) if (((atoi(arrsize) > 0) ||
(atoi(arrsize) == 0) && strcmp(arrsize, "0") != 0) &&
siz == NULL)
sprintf(variable, "(%s%s)", prefix ? prefix : "", name); sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
else else
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name); sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
...@@ -378,13 +390,13 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, ...@@ -378,13 +390,13 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
break; break;
} }
if (arrsize < 0) if (atoi(arrsize) < 0)
arrsize = 1; strcpy(arrsize, "1");
if (siz == NULL || arrsize <= 1) if (siz == NULL || strcmp(arrsize, "0") == 0 || strcmp(arrsize, "1") == 0)
fprintf(o, "\n\t%s,%s,%ldL,%ldL,%s, ", get_type(type), variable, varcharsize, arrsize, offset); fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, offset);
else else
fprintf(o, "\n\t%s,%s,%ldL,%ldL,%s, ", get_type(type), variable, varcharsize, arrsize, siz); fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, siz);
free(variable); free(variable);
free(offset); free(offset);
...@@ -394,7 +406,7 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, ...@@ -394,7 +406,7 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
/* Penetrate a struct and dump the contents. */ /* Penetrate a struct and dump the contents. */
static void static void
ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz, struct ECPGtype * type, struct ECPGtype * ind_type, const char *offsetarg, const char *prefix, const char *ind_prefix) ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, char *arrsiz, struct ECPGtype * type, struct ECPGtype * ind_type, const char *offsetarg, const char *prefix, const char *ind_prefix)
{ {
/* /*
* If offset is NULL, then this is the first recursive level. If not * If offset is NULL, then this is the first recursive level. If not
...@@ -416,7 +428,7 @@ ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz, ...@@ -416,7 +428,7 @@ ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz,
else else
offset = offsetarg; offset = offsetarg;
if (arrsiz == 1) if (atoi(arrsiz) == 1)
sprintf(pbuf, "%s%s.", prefix ? prefix : "", name); sprintf(pbuf, "%s%s.", prefix ? prefix : "", name);
else else
sprintf(pbuf, "%s%s->", prefix ? prefix : "", name); sprintf(pbuf, "%s%s->", prefix ? prefix : "", name);
...@@ -427,7 +439,7 @@ ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz, ...@@ -427,7 +439,7 @@ ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz,
ind_p = &struct_no_indicator; ind_p = &struct_no_indicator;
else if (ind_type != NULL) else if (ind_type != NULL)
{ {
if (arrsiz == 1) if (atoi(arrsiz) == 1)
sprintf(ind_pbuf, "%s%s.", ind_prefix ? ind_prefix : "", ind_name); sprintf(ind_pbuf, "%s%s.", ind_prefix ? ind_prefix : "", ind_name);
else else
sprintf(ind_pbuf, "%s%s->", ind_prefix ? ind_prefix : "", ind_name); sprintf(ind_pbuf, "%s%s->", ind_prefix ? ind_prefix : "", ind_name);
......
...@@ -14,7 +14,7 @@ struct ECPGstruct_member ...@@ -14,7 +14,7 @@ struct ECPGstruct_member
struct ECPGtype struct ECPGtype
{ {
enum ECPGttype type; enum ECPGttype type;
long size; /* For array it is the number of elements. char *size; /* For array it is the number of elements.
* For varchar it is the maxsize of the * For varchar it is the maxsize of the
* area. */ * area. */
char *struct_sizeof; /* For a struct this is the sizeof() type char *struct_sizeof; /* For a struct this is the sizeof() type
...@@ -23,17 +23,15 @@ struct ECPGtype ...@@ -23,17 +23,15 @@ struct ECPGtype
{ {
struct ECPGtype *element; /* For an array this is the type struct ECPGtype *element; /* For an array this is the type
* of the element */ * of the element */
struct ECPGstruct_member *members; /* A pointer to a list of members. */
struct ECPGstruct_member *members;
/* A pointer to a list of members. */
} u; } u;
}; };
/* Everything is malloced. */ /* 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_simple_type(enum ECPGttype, char *);
struct ECPGtype *ECPGmake_varchar_type(enum ECPGttype, long); struct ECPGtype *ECPGmake_varchar_type(enum ECPGttype, long);
struct ECPGtype *ECPGmake_array_type(struct ECPGtype *, long); struct ECPGtype *ECPGmake_array_type(struct ECPGtype *, char *);
struct ECPGtype *ECPGmake_struct_type(struct ECPGstruct_member *, enum ECPGttype, char *); struct ECPGtype *ECPGmake_struct_type(struct ECPGstruct_member *, enum ECPGttype, char *);
struct ECPGstruct_member *ECPGstruct_member_dup(struct ECPGstruct_member *); struct ECPGstruct_member *ECPGstruct_member_dup(struct ECPGstruct_member *);
...@@ -51,7 +49,9 @@ void ECPGfree_type(struct ECPGtype *); ...@@ -51,7 +49,9 @@ void ECPGfree_type(struct ECPGtype *);
size is the maxsize in case it is a varchar. Otherwise it is the size of 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). 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 *, const long, const char *, const char *); void ECPGdump_a_type(FILE *, const char *, struct ECPGtype *, const char *,
struct ECPGtype *, const char *, const char *, char *,
const char *, const char *);
/* A simple struct to keep a variable and its type. */ /* A simple struct to keep a variable and its type. */
struct ECPGtemp_type struct ECPGtemp_type
...@@ -83,8 +83,8 @@ struct when ...@@ -83,8 +83,8 @@ struct when
struct index struct index
{ {
int index1; char *index1;
int index2; char *index2;
char *str; char *str;
}; };
...@@ -92,8 +92,8 @@ struct this_type ...@@ -92,8 +92,8 @@ struct this_type
{ {
enum ECPGttype type_enum; enum ECPGttype type_enum;
char *type_str; char *type_str;
int type_dimension; char *type_dimension;
int type_index; char *type_index;
char *type_sizeof; char *type_sizeof;
}; };
......
...@@ -298,22 +298,22 @@ get_typedef(char *name) ...@@ -298,22 +298,22 @@ get_typedef(char *name)
} }
void void
adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dimension, int type_index, int pointer_len) adjust_array(enum ECPGttype type_enum, char **dimension, char **length, char *type_dimension, char *type_index, int pointer_len)
{ {
if (type_index >= 0) if (atoi(type_index) >= 0)
{ {
if (*length >= 0) if (atoi(*length) >= 0)
mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support"); mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support");
*length = type_index; *length = type_index;
} }
if (type_dimension >= 0) if (atoi(type_dimension) >= 0)
{ {
if (*dimension >= 0 && *length >= 0) if (atoi(*dimension) >= 0 && atoi(*length) >= 0)
mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support"); mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support");
if (*dimension >= 0) if (atoi(*dimension) >= 0)
*length = *dimension; *length = *dimension;
*dimension = type_dimension; *dimension = type_dimension;
...@@ -328,10 +328,10 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim ...@@ -328,10 +328,10 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim
if (pointer_len > 1 && type_enum != ECPGt_char && type_enum != ECPGt_unsigned_char) if (pointer_len > 1 && type_enum != ECPGt_char && type_enum != ECPGt_unsigned_char)
mmerror(PARSE_ERROR, ET_FATAL, "No pointer to pointer supported for this type"); mmerror(PARSE_ERROR, ET_FATAL, "No pointer to pointer supported for this type");
if (pointer_len > 1 && (*length >= 0 || *dimension >= 0)) if (pointer_len > 1 && (atoi(*length) >= 0 || atoi(*dimension) >= 0))
mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support"); mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support");
if (*length >= 0 && *dimension >= 0 && pointer_len) if (atoi(*length) >= 0 && atoi(*dimension) >= 0 && pointer_len)
mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support"); mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support");
switch (type_enum) switch (type_enum)
...@@ -342,23 +342,23 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim ...@@ -342,23 +342,23 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim
if (pointer_len) if (pointer_len)
{ {
*length = *dimension; *length = *dimension;
*dimension = 0; *dimension = make_str("0");
} }
if (*length >= 0) if (atoi(*length) >= 0)
mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support for structures"); mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support for structures");
break; break;
case ECPGt_varchar: case ECPGt_varchar:
/* pointer has to get dimension 0 */ /* pointer has to get dimension 0 */
if (pointer_len) if (pointer_len)
*dimension = 0; *dimension = make_str("0");
/* one index is the string length */ /* one index is the string length */
if (*length < 0) if (atoi(*length) < 0)
{ {
*length = *dimension; *length = *dimension;
*dimension = -1; *dimension = make_str("-1");
} }
break; break;
...@@ -367,19 +367,19 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim ...@@ -367,19 +367,19 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim
/* char ** */ /* char ** */
if (pointer_len == 2) if (pointer_len == 2)
{ {
*length = *dimension = 0; *length = *dimension = make_str("0");
break; break;
} }
/* pointer has to get length 0 */ /* pointer has to get length 0 */
if (pointer_len == 1) if (pointer_len == 1)
*length = 0; *length = make_str("0");
/* one index is the string length */ /* one index is the string length */
if (*length < 0) if (atoi(*length) < 0)
{ {
*length = (*dimension < 0) ? 1 : *dimension; *length = (atoi(*dimension) < 0) ? make_str("1") : *dimension;
*dimension = -1; *dimension = make_str("-1");
} }
break; break;
default: default:
...@@ -387,10 +387,10 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim ...@@ -387,10 +387,10 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim
if (pointer_len) if (pointer_len)
{ {
*length = *dimension; *length = *dimension;
*dimension = 0; *dimension = make_str("0");
} }
if (*length >= 0) if (atoi(*length) >= 0)
mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support for simple data types"); mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support for simple data types");
break; break;
......
...@@ -9,7 +9,8 @@ typedef char* c; ...@@ -9,7 +9,8 @@ typedef char* c;
exec sql type ind is union { int integer; short smallint; }; exec sql type ind is union { int integer; short smallint; };
typedef union { int integer; short smallint; } ind; typedef union { int integer; short smallint; } ind;
exec sql type str is varchar[8]; #define BUFSIZ 8
exec sql type str is varchar[BUFSIZ];
int int
main () main ()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册