Clean up indentation and whitespace inconsistencies in ecpg.

ecpg's lexer and parser files aren't normally processed by
pgindent, and unsurprisingly there's a lot of code in there
that doesn't really match project style.  I spent some time
running pgindent over the fragments of these files that are
C code, and this is the result.  This is in the same spirit
as commit 30ed71e42, though apparently Peter used a different
method for that one, since it didn't find these problems.

Discussion: https://postgr.es/m/2011420.1713493114@sss.pgh.pa.us
This commit is contained in:
Tom Lane 2024-08-15 11:41:46 -04:00
parent 516b87502d
commit 97add39c03
4 changed files with 2602 additions and 2005 deletions

View File

@ -3,7 +3,7 @@ ECPG: stmtClosePortalStmt block
{
if (INFORMIX_MODE)
{
if (pg_strcasecmp($1+strlen("close "), "database") == 0)
if (pg_strcasecmp($1 + strlen("close "), "database") == 0)
{
if (connection)
mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in CLOSE DATABASE statement");
@ -22,7 +22,9 @@ ECPG: stmtDeallocateStmt block
output_deallocate_prepare_statement($1);
}
ECPG: stmtDeclareCursorStmt block
{ output_simple_statement($1, (strncmp($1, "ECPGset_var", strlen("ECPGset_var")) == 0) ? 4 : 0); }
{
output_simple_statement($1, (strncmp($1, "ECPGset_var", strlen("ECPGset_var")) == 0) ? 4 : 0);
}
ECPG: stmtDiscardStmt block
ECPG: stmtFetchStmt block
{ output_statement($1, 1, ECPGst_normal); }
@ -47,7 +49,10 @@ ECPG: stmtExecuteStmt block
char *length = mm_alloc(sizeof(int) * CHAR_BIT * 10 / 3);
char *str = mm_strdup($1.name + 1);
/* It must be cut off double quotation because new_variable() double-quotes. */
/*
* It must be cut off double quotation because new_variable()
* double-quotes.
*/
str[strlen(str) - 1] = '\0';
sprintf(length, "%zu", strlen(str));
add_variable_to_tail(&argsinsert, new_variable(str, ECPGmake_simple_type(ECPGt_const, length, 0), 0), &no_indicator);
@ -63,6 +68,7 @@ ECPG: stmtPrepareStmt block
else if (strlen($1.type) == 0)
{
char *stmt = cat_str(3, mm_strdup("\""), $1.stmt, mm_strdup("\""));
output_prepare_statement($1.name, stmt);
}
else
@ -75,7 +81,10 @@ ECPG: stmtPrepareStmt block
char *length = mm_alloc(sizeof(int) * CHAR_BIT * 10 / 3);
char *str = mm_strdup($1.name + 1);
/* It must be cut off double quotation because new_variable() double-quotes. */
/*
* It must be cut off double quotation because new_variable()
* double-quotes.
*/
str[strlen(str) - 1] = '\0';
sprintf(length, "%zu", strlen(str));
add_variable_to_tail(&argsinsert, new_variable(str, ECPGmake_simple_type(ECPGt_const, length, 0), 0), &no_indicator);
@ -98,7 +107,7 @@ ECPG: toplevel_stmtTransactionStmtLegacy block
ECPG: stmtViewStmt rule
| ECPGAllocateDescr
{
fprintf(base_yyout,"ECPGallocate_desc(__LINE__, %s);",$1);
fprintf(base_yyout, "ECPGallocate_desc(__LINE__, %s);", $1);
whenever_action(0);
free($1);
}
@ -122,7 +131,7 @@ ECPG: stmtViewStmt rule
}
| ECPGDeallocateDescr
{
fprintf(base_yyout,"ECPGdeallocate_desc(__LINE__, %s);",$1);
fprintf(base_yyout, "ECPGdeallocate_desc(__LINE__, %s);", $1);
whenever_action(0);
free($1);
}
@ -152,7 +161,10 @@ ECPG: stmtViewStmt rule
whenever_action(2);
free($1);
}
| ECPGExecuteImmediateStmt { output_statement($1, 0, ECPGst_exec_immediate); }
| ECPGExecuteImmediateStmt
{
output_statement($1, 0, ECPGst_exec_immediate);
}
| ECPGFree
{
const char *con = connection ? connection : "NULL";
@ -160,7 +172,7 @@ ECPG: stmtViewStmt rule
if (strcmp($1, "all") == 0)
fprintf(base_yyout, "{ ECPGdeallocate_all(__LINE__, %d, %s);", compat, con);
else if ($1[0] == ':')
fprintf(base_yyout, "{ ECPGdeallocate(__LINE__, %d, %s, %s);", compat, con, $1+1);
fprintf(base_yyout, "{ ECPGdeallocate(__LINE__, %d, %s, %s);", compat, con, $1 + 1);
else
fprintf(base_yyout, "{ ECPGdeallocate(__LINE__, %d, %s, \"%s\");", compat, con, $1);
@ -245,7 +257,8 @@ ECPG: stmtViewStmt rule
ECPG: where_or_current_clauseWHERECURRENT_POFcursor_name block
{
char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
$$ = cat_str(2,mm_strdup("where current of"), cursor_marker);
$$ = cat_str(2, mm_strdup("where current of"), cursor_marker);
}
ECPG: CopyStmtCOPYopt_binaryqualified_nameopt_column_listcopy_fromopt_programcopy_file_namecopy_delimiteropt_withcopy_optionswhere_clause addon
if (strcmp($6, "from") == 0 &&
@ -259,9 +272,9 @@ ECPG: var_valueNumericOnly addon
}
ECPG: fetch_argscursor_name addon
struct cursor *ptr = add_additional_variables($1, false);
if (ptr -> connection)
connection = mm_strdup(ptr -> connection);
if (ptr->connection)
connection = mm_strdup(ptr->connection);
if ($1[0] == ':')
{
free($1);
@ -269,9 +282,9 @@ ECPG: fetch_argscursor_name addon
}
ECPG: fetch_argsfrom_incursor_name addon
struct cursor *ptr = add_additional_variables($2, false);
if (ptr -> connection)
connection = mm_strdup(ptr -> connection);
if (ptr->connection)
connection = mm_strdup(ptr->connection);
if ($2[0] == ':')
{
free($2);
@ -283,9 +296,9 @@ ECPG: fetch_argsFIRST_Popt_from_incursor_name addon
ECPG: fetch_argsLAST_Popt_from_incursor_name addon
ECPG: fetch_argsALLopt_from_incursor_name addon
struct cursor *ptr = add_additional_variables($3, false);
if (ptr -> connection)
connection = mm_strdup(ptr -> connection);
if (ptr->connection)
connection = mm_strdup(ptr->connection);
if ($3[0] == ':')
{
free($3);
@ -293,9 +306,9 @@ ECPG: fetch_argsALLopt_from_incursor_name addon
}
ECPG: fetch_argsSignedIconstopt_from_incursor_name addon
struct cursor *ptr = add_additional_variables($3, false);
if (ptr -> connection)
connection = mm_strdup(ptr -> connection);
if (ptr->connection)
connection = mm_strdup(ptr->connection);
if ($3[0] == ':')
{
free($3);
@ -309,9 +322,9 @@ ECPG: fetch_argsSignedIconstopt_from_incursor_name addon
ECPG: fetch_argsFORWARDALLopt_from_incursor_name addon
ECPG: fetch_argsBACKWARDALLopt_from_incursor_name addon
struct cursor *ptr = add_additional_variables($4, false);
if (ptr -> connection)
connection = mm_strdup(ptr -> connection);
if (ptr->connection)
connection = mm_strdup(ptr->connection);
if ($4[0] == ':')
{
free($4);
@ -322,9 +335,9 @@ ECPG: fetch_argsRELATIVE_PSignedIconstopt_from_incursor_name addon
ECPG: fetch_argsFORWARDSignedIconstopt_from_incursor_name addon
ECPG: fetch_argsBACKWARDSignedIconstopt_from_incursor_name addon
struct cursor *ptr = add_additional_variables($4, false);
if (ptr -> connection)
connection = mm_strdup(ptr -> connection);
if (ptr->connection)
connection = mm_strdup(ptr->connection);
if ($4[0] == ':')
{
free($4);
@ -339,6 +352,7 @@ ECPG: cursor_namename rule
| char_civar
{
char *curname = mm_alloc(strlen($1) + 2);
sprintf(curname, ":%s", $1);
free($1);
$1 = curname;
@ -367,18 +381,21 @@ ECPG: ExecuteStmtEXECUTEprepared_nameexecute_param_clauseexecute_rest block
}
ECPG: ExecuteStmtCREATEOptTempTABLEcreate_as_targetASEXECUTEprepared_nameexecute_param_clauseopt_with_dataexecute_rest block
{
$$.name = cat_str(8,mm_strdup("create"),$2,mm_strdup("table"),$4,mm_strdup("as execute"),$7,$8,$9);
$$.name = cat_str(8, mm_strdup("create"), $2, mm_strdup("table"), $4, mm_strdup("as execute"), $7, $8, $9);
}
ECPG: ExecuteStmtCREATEOptTempTABLEIF_PNOTEXISTScreate_as_targetASEXECUTEprepared_nameexecute_param_clauseopt_with_dataexecute_rest block
{
$$.name = cat_str(8,mm_strdup("create"),$2,mm_strdup("table if not exists"),$7,mm_strdup("as execute"),$10,$11,$12);
$$.name = cat_str(8, mm_strdup("create"), $2, mm_strdup("table if not exists"), $7, mm_strdup("as execute"), $10, $11, $12);
}
ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectStmt block
{
struct cursor *ptr, *this;
struct cursor *ptr,
*this;
char *cursor_marker = $2[0] == ':' ? mm_strdup("$0") : mm_strdup($2);
char *comment, *c1, *c2;
int (* strcmp_fn)(const char *, const char *) = (($2[0] == ':' || $2[0] == '"') ? strcmp : pg_strcasecmp);
char *comment,
*c1,
*c2;
int (*strcmp_fn) (const char *, const char *) = (($2[0] == ':' || $2[0] == '"') ? strcmp : pg_strcasecmp);
if (INFORMIX_MODE && pg_strcasecmp($2, "database") == 0)
mmfatal(PARSE_ERROR, "\"database\" cannot be used as cursor name in INFORMIX mode");
@ -388,7 +405,7 @@ ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectSt
if (strcmp_fn($2, ptr->name) == 0)
{
if ($2[0] == ':')
mmerror(PARSE_ERROR, ET_ERROR, "using variable \"%s\" in different declare statements is not supported", $2+1);
mmerror(PARSE_ERROR, ET_ERROR, "using variable \"%s\" in different declare statements is not supported", $2 + 1);
else
mmerror(PARSE_ERROR, ET_ERROR, "cursor \"%s\" is already defined", $2);
}
@ -424,13 +441,13 @@ ECPG: ClosePortalStmtCLOSEcursor_name block
{
char *cursor_marker = $2[0] == ':' ? mm_strdup("$0") : $2;
struct cursor *ptr = NULL;
for (ptr = cur; ptr != NULL; ptr = ptr -> next)
{
if (strcmp($2, ptr -> name) == 0)
{
if (ptr -> connection)
connection = mm_strdup(ptr -> connection);
for (ptr = cur; ptr != NULL; ptr = ptr->next)
{
if (strcmp($2, ptr->name) == 0)
{
if (ptr->connection)
connection = mm_strdup(ptr->connection);
break;
}
}
@ -446,13 +463,20 @@ ECPG: opt_hold block
ECPG: into_clauseINTOOptTempTableName block
{
FoundInto = 1;
$$= cat2_str(mm_strdup("into"), $2);
$$ = cat2_str(mm_strdup("into"), $2);
}
| ecpg_into
{
$$ = EMPTY;
}
| ecpg_into { $$ = EMPTY; }
ECPG: TypenameSimpleTypenameopt_array_bounds block
{ $$ = cat2_str($1, $2.str); }
{
$$ = cat2_str($1, $2.str);
}
ECPG: TypenameSETOFSimpleTypenameopt_array_bounds block
{ $$ = cat_str(3, mm_strdup("setof"), $2, $3.str); }
{
$$ = cat_str(3, mm_strdup("setof"), $2, $3.str);
}
ECPG: opt_array_boundsopt_array_bounds'['']' block
{
$$.index1 = $1.index1;
@ -477,10 +501,12 @@ ECPG: opt_array_bounds
{
$$.index1 = mm_strdup("-1");
$$.index2 = mm_strdup("-1");
$$.str= EMPTY;
$$.str = EMPTY;
}
ECPG: IconstICONST block
{ $$ = make_name(); }
{
$$ = make_name();
}
ECPG: AexprConstNULL_P rule
| civar { $$ = $1; }
| civarind { $$ = $1; }
@ -507,8 +533,9 @@ ECPG: FetchStmtMOVEfetch_args rule
{
char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
struct cursor *ptr = add_additional_variables($3, false);
if (ptr -> connection)
connection = mm_strdup(ptr -> connection);
if (ptr->connection)
connection = mm_strdup(ptr->connection);
$$ = cat_str(2, mm_strdup("fetch forward"), cursor_marker);
}
@ -516,8 +543,9 @@ ECPG: FetchStmtMOVEfetch_args rule
{
char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
struct cursor *ptr = add_additional_variables($4, false);
if (ptr -> connection)
connection = mm_strdup(ptr -> connection);
if (ptr->connection)
connection = mm_strdup(ptr->connection);
$$ = cat_str(2, mm_strdup("fetch forward from"), cursor_marker);
}
@ -525,8 +553,9 @@ ECPG: FetchStmtMOVEfetch_args rule
{
char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
struct cursor *ptr = add_additional_variables($3, false);
if (ptr -> connection)
connection = mm_strdup(ptr -> connection);
if (ptr->connection)
connection = mm_strdup(ptr->connection);
$$ = cat_str(2, mm_strdup("fetch backward"), cursor_marker);
}
@ -534,8 +563,9 @@ ECPG: FetchStmtMOVEfetch_args rule
{
char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
struct cursor *ptr = add_additional_variables($4, false);
if (ptr -> connection)
connection = mm_strdup(ptr -> connection);
if (ptr->connection)
connection = mm_strdup(ptr->connection);
$$ = cat_str(2, mm_strdup("fetch backward from"), cursor_marker);
}
@ -543,8 +573,9 @@ ECPG: FetchStmtMOVEfetch_args rule
{
char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
struct cursor *ptr = add_additional_variables($3, false);
if (ptr -> connection)
connection = mm_strdup(ptr -> connection);
if (ptr->connection)
connection = mm_strdup(ptr->connection);
$$ = cat_str(2, mm_strdup("move forward"), cursor_marker);
}
@ -552,8 +583,9 @@ ECPG: FetchStmtMOVEfetch_args rule
{
char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
struct cursor *ptr = add_additional_variables($4, false);
if (ptr -> connection)
connection = mm_strdup(ptr -> connection);
if (ptr->connection)
connection = mm_strdup(ptr->connection);
$$ = cat_str(2, mm_strdup("move forward from"), cursor_marker);
}
@ -561,8 +593,9 @@ ECPG: FetchStmtMOVEfetch_args rule
{
char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
struct cursor *ptr = add_additional_variables($3, false);
if (ptr -> connection)
connection = mm_strdup(ptr -> connection);
if (ptr->connection)
connection = mm_strdup(ptr->connection);
$$ = cat_str(2, mm_strdup("move backward"), cursor_marker);
}
@ -570,8 +603,9 @@ ECPG: FetchStmtMOVEfetch_args rule
{
char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
struct cursor *ptr = add_additional_variables($4, false);
if (ptr -> connection)
connection = mm_strdup(ptr -> connection);
if (ptr->connection)
connection = mm_strdup(ptr->connection);
$$ = cat_str(2, mm_strdup("move backward from"), cursor_marker);
}
@ -581,4 +615,7 @@ ECPG: limit_clauseLIMITselect_limit_value','select_offset_value block
$$ = cat_str(4, mm_strdup("limit"), $2, mm_strdup(","), $4);
}
ECPG: SignedIconstIconst rule
| civar { $$ = $1; }
| civar
{
$$ = $1;
}

View File

@ -47,14 +47,15 @@ char *input_filename = NULL;
static int FoundInto = 0;
static int initializer = 0;
static int pacounter = 1;
static char pacounter_buffer[sizeof(int) * CHAR_BIT * 10 / 3]; /* a rough guess at the size we need */
static char pacounter_buffer[sizeof(int) * CHAR_BIT * 10 / 3]; /* a rough guess at the
* size we need */
static struct this_type actual_type[STRUCT_DEPTH];
static char *actual_startline[STRUCT_DEPTH];
static int varchar_counter = 1;
static int bytea_counter = 1;
/* temporarily store struct members while creating the data structure */
struct ECPGstruct_member *struct_member_list[STRUCT_DEPTH] = { NULL };
struct ECPGstruct_member *struct_member_list[STRUCT_DEPTH] = {NULL};
/* also store struct type so we can do a sizeof() later */
static char *ECPGstruct_sizeof = NULL;
@ -82,7 +83,7 @@ vmmerror(int error_code, enum errortype type, const char *error, va_list ap)
fprintf(stderr, "%s:%d: ", input_filename, base_yylineno);
switch(type)
switch (type)
{
case ET_WARNING:
fprintf(stderr, _("WARNING: "));
@ -96,7 +97,7 @@ vmmerror(int error_code, enum errortype type, const char *error, va_list ap)
fprintf(stderr, "\n");
switch(type)
switch (type)
{
case ET_WARNING:
break;
@ -107,7 +108,7 @@ vmmerror(int error_code, enum errortype type, const char *error, va_list ap)
}
void
mmerror(int error_code, enum errortype type, const char *error, ...)
mmerror(int error_code, enum errortype type, const char *error,...)
{
va_list ap;
@ -117,7 +118,7 @@ mmerror(int error_code, enum errortype type, const char *error, ...)
}
void
mmfatal(int error_code, const char *error, ...)
mmfatal(int error_code, const char *error,...)
{
va_list ap;
@ -142,7 +143,7 @@ mmfatal(int error_code, const char *error, ...)
static char *
cat2_str(char *str1, char *str2)
{
char * res_str = (char *)mm_alloc(strlen(str1) + strlen(str2) + 2);
char *res_str = (char *) mm_alloc(strlen(str1) + strlen(str2) + 2);
strcpy(res_str, str1);
if (strlen(str1) != 0 && strlen(str2) != 0)
@ -154,7 +155,7 @@ cat2_str(char *str1, char *str2)
}
static char *
cat_str(int count, ...)
cat_str(int count,...)
{
va_list args;
int i;
@ -176,7 +177,7 @@ cat_str(int count, ...)
static char *
make2_str(char *str1, char *str2)
{
char * res_str = (char *)mm_alloc(strlen(str1) + strlen(str2) + 1);
char *res_str = (char *) mm_alloc(strlen(str1) + strlen(str2) + 1);
strcpy(res_str, str1);
strcat(res_str, str2);
@ -188,7 +189,7 @@ make2_str(char *str1, char *str2)
static char *
make3_str(char *str1, char *str2, char *str3)
{
char * res_str = (char *)mm_alloc(strlen(str1) + strlen(str2) +strlen(str3) + 1);
char *res_str = (char *) mm_alloc(strlen(str1) + strlen(str2) + strlen(str3) + 1);
strcpy(res_str, str1);
strcat(res_str, str2);
@ -213,10 +214,15 @@ create_questionmarks(char *name, bool array)
int count;
char *result = EMPTY;
/* In case we have a struct, we have to print as many "?" as there are attributes in the struct
/*
* In case we have a struct, we have to print as many "?" as there are
* attributes in the struct
*
* An array is only allowed together with an element argument
* This is essentially only used for inserts, but using a struct as input parameter is an error anywhere else
* so we don't have to worry here. */
*
* This is essentially only used for inserts, but using a struct as input
* parameter is an error anywhere else so we don't have to worry here.
*/
if (p->type->type == ECPGt_struct || (array && p->type->type == ECPGt_array && p->type->u.element->type == ECPGt_struct))
{
@ -227,12 +233,12 @@ create_questionmarks(char *name, bool array)
else
m = p->type->u.element->u.members;
for (count = 0; m != NULL; m=m->next, count++);
for (count = 0; m != NULL; m = m->next, count++);
}
else
count = 1;
for (; count > 0; count --)
for (; count > 0; count--)
{
sprintf(pacounter_buffer, "$%d", pacounter++);
result = cat_str(3, result, mm_strdup(pacounter_buffer), mm_strdup(" , "));
@ -240,22 +246,24 @@ create_questionmarks(char *name, bool array)
/* removed the trailing " ," */
result[strlen(result)-3] = '\0';
result[strlen(result) - 3] = '\0';
return result;
}
static char *
adjust_outofscope_cursor_vars(struct cursor *cur)
{
/* Informix accepts DECLARE with variables that are out of scope when OPEN is called.
* For instance you can DECLARE a cursor in one function, and OPEN/FETCH/CLOSE
* it in another functions. This is very useful for e.g. event-driver programming,
* but may also lead to dangerous programming. The limitation when this is allowed
* and doesn't cause problems have to be documented, like the allocated variables
* must not be realloc()'ed.
/*
* Informix accepts DECLARE with variables that are out of scope when OPEN
* is called. For instance you can DECLARE a cursor in one function, and
* OPEN/FETCH/CLOSE it in another functions. This is very useful for e.g.
* event-driver programming, but may also lead to dangerous programming.
* The limitation when this is allowed and doesn't cause problems have to
* be documented, like the allocated variables must not be realloc()'ed.
*
* We have to change the variables to our own struct and just store the pointer
* instead of the variable. Do it only for local variables, not for globals.
* We have to change the variables to our own struct and just store the
* pointer instead of the variable. Do it only for local variables, not
* for globals.
*/
char *result = EMPTY;
@ -266,7 +274,8 @@ adjust_outofscope_cursor_vars(struct cursor *cur)
struct arguments *list;
struct arguments *ptr;
struct arguments *newlist = NULL;
struct variable *newvar, *newind;
struct variable *newvar,
*newind;
list = (insert ? cur->argsinsert : cur->argsresult);
@ -387,7 +396,10 @@ adjust_outofscope_cursor_vars(struct cursor *cur)
var_ptr = true;
}
/* create call to "ECPGset_var(<counter>, <connection>, <pointer>. <line number>)" */
/*
* create call to "ECPGset_var(<counter>, <connection>, <pointer>.
* <line number>)"
*/
if (!skip_set_var)
{
sprintf(var_text, "%d, %s", ecpg_internal_var++, var_ptr ? "&(" : "(");
@ -396,7 +408,10 @@ adjust_outofscope_cursor_vars(struct cursor *cur)
mm_strdup("), __LINE__);\n"));
}
/* now the indicator if there is one and it's not a global variable */
/*
* now the indicator if there is one and it's not a global
* variable
*/
if ((ptr->indicator->type->type == ECPGt_NO_INDICATOR) || (ptr->indicator->brace_level == 0))
{
newind = ptr->indicator;
@ -476,7 +491,10 @@ adjust_outofscope_cursor_vars(struct cursor *cur)
var_ptr = true;
}
/* create call to "ECPGset_var(<counter>, <pointer>. <line number>)" */
/*
* create call to "ECPGset_var(<counter>, <pointer>. <line
* number>)"
*/
sprintf(var_text, "%d, %s", ecpg_internal_var++, var_ptr ? "&(" : "(");
result = cat_str(5, result, mm_strdup("ECPGset_var("),
mm_strdup(var_text), mm_strdup(original_var),
@ -505,9 +523,9 @@ add_additional_variables(char *name, bool insert)
{
struct cursor *ptr;
struct arguments *p;
int (* strcmp_fn)(const char *, const char *) = ((name[0] == ':' || name[0] == '"') ? strcmp : pg_strcasecmp);
int (*strcmp_fn) (const char *, const char *) = ((name[0] == ':' || name[0] == '"') ? strcmp : pg_strcasecmp);
for (ptr = cur; ptr != NULL; ptr=ptr->next)
for (ptr = cur; ptr != NULL; ptr = ptr->next)
{
if (strcmp_fn(ptr->name, name) == 0)
break;
@ -521,8 +539,12 @@ add_additional_variables(char *name, bool insert)
if (insert)
{
/* add all those input variables that were given earlier
* note that we have to append here but have to keep the existing order */
/*
* add all those input variables that were given earlier
*
* note that we have to append here but have to keep the existing
* order
*/
for (p = (SAMEFUNC(ptr) ? ptr->argsinsert : ptr->argsinsert_oos); p; p = p->next)
add_variable_to_tail(&argsinsert, p->variable, p->indicator);
}
@ -539,7 +561,8 @@ add_typedef(char *name, char *dimension, char *length, enum ECPGttype type_enum,
char *type_dimension, char *type_index, int initializer, int array)
{
/* add entry to list */
struct typedefs *ptr, *this;
struct typedefs *ptr,
*this;
if ((type_enum == ECPGt_struct ||
type_enum == ECPGt_union) &&
@ -593,15 +616,16 @@ static bool
check_declared_list(const char *name)
{
struct declared_list *ptr = NULL;
for (ptr = g_declared_list; ptr != NULL; ptr = ptr -> next)
for (ptr = g_declared_list; ptr != NULL; ptr = ptr->next)
{
if (!ptr->connection)
continue;
if (strcmp(name, ptr -> name) == 0)
if (strcmp(name, ptr->name) == 0)
{
if (connection && strcmp(ptr->connection, connection) != 0)
mmerror(PARSE_ERROR, ET_WARNING, "connection %s is overwritten with %s by DECLARE statement %s", connection, ptr->connection, name);
connection = mm_strdup(ptr -> connection);
connection = mm_strdup(ptr->connection);
return true;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -541,7 +541,9 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
<xb>{xbinside} {
addlit(yytext, yyleng);
}
<xb><<EOF>> { mmfatal(PARSE_ERROR, "unterminated bit string literal"); }
<xb><<EOF>> {
mmfatal(PARSE_ERROR, "unterminated bit string literal");
}
<SQL>{xhstart} {
token_start = yytext;
@ -549,7 +551,9 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
BEGIN(xh);
startlit();
}
<xh><<EOF>> { mmfatal(PARSE_ERROR, "unterminated hexadecimal string literal"); }
<xh><<EOF>> {
mmfatal(PARSE_ERROR, "unterminated hexadecimal string literal");
}
<C>{xqstart} {
token_start = yytext;
@ -560,9 +564,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
<SQL>{
{xnstart} {
/* National character.
* Transfer it as-is to the backend.
*/
/* National character. Transfer it as-is to the backend. */
token_start = yytext;
state_before_str_start = YYSTATE;
BEGIN(xn);
@ -651,9 +653,15 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
}
}
<xq,xe,xn,xus>{xqdouble} { addlit(yytext, yyleng); }
<xqc>{xqcquote} { addlit(yytext, yyleng); }
<xq,xqc,xn,xus>{xqinside} { addlit(yytext, yyleng); }
<xq,xe,xn,xus>{xqdouble} {
addlit(yytext, yyleng);
}
<xqc>{xqcquote} {
addlit(yytext, yyleng);
}
<xq,xqc,xn,xus>{xqinside} {
addlit(yytext, yyleng);
}
<xe>{xeinside} {
addlit(yytext, yyleng);
}
@ -673,7 +681,9 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
/* This is only needed for \ just before EOF */
addlitchar(yytext[0]);
}
<xq,xqc,xe,xn,xus><<EOF>> { mmfatal(PARSE_ERROR, "unterminated quoted string"); }
<xq,xqc,xe,xn,xus><<EOF>> {
mmfatal(PARSE_ERROR, "unterminated quoted string");
}
<SQL>{
{dolqdelim} {
@ -724,7 +734,9 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
/* single quote or dollar sign */
addlitchar(yytext[0]);
}
<xdolq><<EOF>> { mmfatal(PARSE_ERROR, "unterminated dollar-quoted string"); }
<xdolq><<EOF>> {
mmfatal(PARSE_ERROR, "unterminated dollar-quoted string");
}
<SQL>{
{xdstart} {
@ -743,6 +755,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
BEGIN(state_before_str_start);
if (literallen == 0)
mmerror(PARSE_ERROR, ET_ERROR, "zero-length delimited identifier");
/*
* The server will truncate the identifier here. We do
* not, as (1) it does not change the result; (2) we don't
@ -763,7 +776,11 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
BEGIN(state_before_str_start);
if (literallen == 0)
mmerror(PARSE_ERROR, ET_ERROR, "zero-length delimited identifier");
/* The backend will truncate the identifier here. We do not as it does not change the result. */
/*
* The backend will truncate the identifier here. We do
* not as it does not change the result.
*/
base_yylval.str = psprintf("U&\"%s\"", literalbuf);
return UIDENT;
}
@ -773,7 +790,9 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
<xd,xui>{xdinside} {
addlit(yytext, yyleng);
}
<xd,xui><<EOF>> { mmfatal(PARSE_ERROR, "unterminated quoted identifier"); }
<xd,xui><<EOF>> {
mmfatal(PARSE_ERROR, "unterminated quoted identifier");
}
<C>{xdstart} {
state_before_str_start = YYSTATE;
BEGIN(xdc);
@ -782,7 +801,9 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
<xdc>{xdcinside} {
addlit(yytext, yyleng);
}
<xdc><<EOF>> { mmfatal(PARSE_ERROR, "unterminated quoted string"); }
<xdc><<EOF>> {
mmfatal(PARSE_ERROR, "unterminated quoted string");
}
<SQL>{
{typecast} {
@ -831,9 +852,8 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
{self} {
/*
* We may find a ';' inside a structure
* definition in a TYPE or VAR statement.
* This is not an EOL marker.
* We may find a ';' inside a structure definition in a
* TYPE or VAR statement. This is not an EOL marker.
*/
if (yytext[0] == ';' && struct_level == 0)
BEGIN(C);
@ -879,6 +899,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
for (ic = nchars - 2; ic >= 0; ic--)
{
char c = yytext[ic];
if (c == '~' || c == '!' || c == '@' ||
c == '#' || c == '^' || c == '&' ||
c == '|' || c == '`' || c == '?' ||
@ -891,7 +912,8 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
* didn't find a qualifying character, so remove
* all trailing [+-]
*/
do {
do
{
nchars--;
} while (nchars > 1 &&
(yytext[nchars - 1] == '+' ||
@ -903,6 +925,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
{
/* Strip the unwanted chars from the token */
yyless(nchars);
/*
* If what we have left is only one char, and it's
* one of the characters matching "self", then
@ -912,6 +935,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
if (nchars == 1 &&
strchr(",()[].;:+-*/%^<>=", yytext[0]))
return yytext[0];
/*
* Likewise, if what we have left is two chars, and
* those match the tokens ">=", "<=", "=>", "<>" or
@ -1019,7 +1043,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
}
:{identifier}((("->"|\.){identifier})|(\[{array}\]))* {
base_yylval.str = mm_strdup(yytext+1);
base_yylval.str = mm_strdup(yytext + 1);
return CVARIABLE;
}
@ -1053,8 +1077,8 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
*
* The backend will attempt to truncate and case-fold
* the identifier, but I see no good reason for ecpg
* to do so; that's just another way that ecpg could get
* out of step with the backend.
* to do so; that's just another way that ecpg could
* get out of step with the backend.
*/
base_yylval.str = mm_strdup(yytext);
return IDENT;
@ -1070,7 +1094,10 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
* Begin ECPG-specific rules
*/
<C>{exec_sql} { BEGIN(SQL); return SQL_START; }
<C>{exec_sql} {
BEGIN(SQL);
return SQL_START;
}
<C>{informix_special} {
/* are we simulating Informix? */
if (INFORMIX_MODE)
@ -1081,7 +1108,9 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
else
return S_ANYTHING;
}
<C>{ccomment} { ECHO; }
<C>{ccomment} {
ECHO;
}
<C>{cppinclude} {
if (system_includes)
{
@ -1138,7 +1167,9 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
}
}
}
<C>{xcstop} { mmerror(PARSE_ERROR, ET_ERROR, "nested /* ... */ comments"); }
<C>{xcstop} {
mmerror(PARSE_ERROR, ET_ERROR, "nested /* ... */ comments");
}
<C>":" { return ':'; }
<C>";" { return ';'; }
<C>"," { return ','; }
@ -1185,7 +1216,9 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
return S_ANYTHING;
}
}
<C>{exec_sql}{undef}{space}* { BEGIN(undef); }
<C>{exec_sql}{undef}{space}* {
BEGIN(undef);
}
<C>{informix_special}{undef}{space}* {
/* are we simulating Informix? */
if (INFORMIX_MODE)
@ -1199,19 +1232,19 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
}
}
<undef>{identifier}{space}*";" {
struct _defines *ptr, *ptr2 = NULL;
struct _defines *ptr,
*ptr2 = NULL;
int i;
/*
* Skip the ";" and trailing whitespace. Note that yytext
* contains at least one non-space character plus the ";"
*/
for (i = strlen(yytext)-2;
for (i = strlen(yytext) - 2;
i > 0 && ecpg_isspace(yytext[i]);
i--)
;
yytext[i+1] = '\0';
yytext[i + 1] = '\0';
/* Find and unset any matching define; should be only 1 */
for (ptr = defines; ptr; ptr2 = ptr, ptr = ptr->next)
@ -1240,7 +1273,9 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
mmfatal(PARSE_ERROR, "missing identifier in EXEC SQL UNDEF command");
yyterminate();
}
<C>{exec_sql}{include}{space}* { BEGIN(incl); }
<C>{exec_sql}{include}{space}* {
BEGIN(incl);
}
<C>{informix_special}{include}{space}* {
/* are we simulating Informix? */
if (INFORMIX_MODE)
@ -1254,7 +1289,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
}
}
<C,xskip>{exec_sql}{ifdef}{space}* {
if (preproc_tos >= MAX_NESTED_IF-1)
if (preproc_tos >= MAX_NESTED_IF - 1)
mmfatal(PARSE_ERROR, "too many nested EXEC SQL IFDEF conditions");
preproc_tos++;
stacked_if_value[preproc_tos].active = false;
@ -1267,7 +1302,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
/* are we simulating Informix? */
if (INFORMIX_MODE)
{
if (preproc_tos >= MAX_NESTED_IF-1)
if (preproc_tos >= MAX_NESTED_IF - 1)
mmfatal(PARSE_ERROR, "too many nested EXEC SQL IFDEF conditions");
preproc_tos++;
stacked_if_value[preproc_tos].active = false;
@ -1283,7 +1318,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
}
}
<C,xskip>{exec_sql}{ifndef}{space}* {
if (preproc_tos >= MAX_NESTED_IF-1)
if (preproc_tos >= MAX_NESTED_IF - 1)
mmfatal(PARSE_ERROR, "too many nested EXEC SQL IFDEF conditions");
preproc_tos++;
stacked_if_value[preproc_tos].active = false;
@ -1296,7 +1331,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
/* are we simulating Informix? */
if (INFORMIX_MODE)
{
if (preproc_tos >= MAX_NESTED_IF-1)
if (preproc_tos >= MAX_NESTED_IF - 1)
mmfatal(PARSE_ERROR, "too many nested EXEC SQL IFDEF conditions");
preproc_tos++;
stacked_if_value[preproc_tos].active = false;
@ -1337,7 +1372,8 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
}
}
<C,xskip>{exec_sql}{else}{space}*";" { /* only exec sql endif pops the stack, so take care of duplicated 'else' */
<C,xskip>{exec_sql}{else}{space}*";" {
/* only exec sql endif pops the stack, so take care of duplicated 'else' */
if (preproc_tos == 0)
mmfatal(PARSE_ERROR, "missing matching \"EXEC SQL IFDEF\" / \"EXEC SQL IFNDEF\"");
else if (stacked_if_value[preproc_tos].else_branch)
@ -1346,7 +1382,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
{
stacked_if_value[preproc_tos].else_branch = true;
stacked_if_value[preproc_tos].active =
(stacked_if_value[preproc_tos-1].active &&
(stacked_if_value[preproc_tos - 1].active &&
!stacked_if_value[preproc_tos].saw_active);
stacked_if_value[preproc_tos].saw_active = true;
@ -1368,7 +1404,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
{
stacked_if_value[preproc_tos].else_branch = true;
stacked_if_value[preproc_tos].active =
(stacked_if_value[preproc_tos-1].active &&
(stacked_if_value[preproc_tos - 1].active &&
!stacked_if_value[preproc_tos].saw_active);
stacked_if_value[preproc_tos].saw_active = true;
@ -1425,14 +1461,15 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
bool this_active;
/*
* Skip the ";" and trailing whitespace. Note that yytext
* contains at least one non-space character plus the ";"
* Skip the ";" and trailing whitespace. Note that
* yytext contains at least one non-space character
* plus the ";"
*/
for (i = strlen(yytext)-2;
for (i = strlen(yytext) - 2;
i > 0 && ecpg_isspace(yytext[i]);
i--)
;
yytext[i+1] = '\0';
/* skip */ ;
yytext[i + 1] = '\0';
/* Does a definition exist? */
for (defptr = defines; defptr; defptr = defptr->next)
@ -1448,7 +1485,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
this_active = (defptr ? ifcond : !ifcond);
stacked_if_value[preproc_tos].active =
(stacked_if_value[preproc_tos-1].active &&
(stacked_if_value[preproc_tos - 1].active &&
!stacked_if_value[preproc_tos].saw_active &&
this_active);
stacked_if_value[preproc_tos].saw_active |= this_active;
@ -1559,11 +1596,12 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
if (i != 0)
output_line_number();
}
}
<INITIAL>{other}|\n { mmfatal(PARSE_ERROR, "internal error: unreachable state; please report this to <%s>", PACKAGE_BUGREPORT); }
<INITIAL>{other}|\n {
mmfatal(PARSE_ERROR, "internal error: unreachable state; please report this to <%s>", PACKAGE_BUGREPORT);
}
%%
@ -1599,15 +1637,15 @@ static void
addlit(char *ytext, int yleng)
{
/* enlarge buffer if needed */
if ((literallen+yleng) >= literalalloc)
if ((literallen + yleng) >= literalalloc)
{
do
literalalloc *= 2;
while ((literallen+yleng) >= literalalloc);
while ((literallen + yleng) >= literalalloc);
literalbuf = (char *) realloc(literalbuf, literalalloc);
}
/* append new data, add trailing null */
memcpy(literalbuf+literallen, ytext, yleng);
memcpy(literalbuf + literallen, ytext, yleng);
literallen += yleng;
literalbuf[literallen] = '\0';
}
@ -1616,7 +1654,7 @@ static void
addlitchar(unsigned char ychar)
{
/* enlarge buffer if needed */
if ((literallen+1) >= literalalloc)
if ((literallen + 1) >= literalalloc)
{
literalalloc *= 2;
literalbuf = (char *) realloc(literalbuf, literalalloc);
@ -1668,10 +1706,10 @@ parse_include(void)
yy_buffer = yb;
/*
* skip the ";" if there is one and trailing whitespace. Note that
* yytext contains at least one non-space character plus the ";"
* skip the ";" if there is one and trailing whitespace. Note that yytext
* contains at least one non-space character plus the ";"
*/
for (i = strlen(yytext)-2;
for (i = strlen(yytext) - 2;
i > 0 && ecpg_isspace(yytext[i]);
i--)
;
@ -1679,17 +1717,21 @@ parse_include(void)
if (yytext[i] == ';')
i--;
yytext[i+1] = '\0';
yytext[i + 1] = '\0';
yyin = NULL;
/* If file name is enclosed in '"' remove these and look only in '.' */
/* Informix does look into all include paths though, except filename starts with '/' */
/*
* Informix does look into all include paths though, except filename
* starts with '/'
*/
if (yytext[0] == '"' && yytext[i] == '"' &&
((compat != ECPG_COMPAT_INFORMIX && compat != ECPG_COMPAT_INFORMIX_SE) || yytext[1] == '/'))
{
yytext[i] = '\0';
memmove(yytext, yytext+1, strlen(yytext));
memmove(yytext, yytext + 1, strlen(yytext));
strlcpy(inc_file, yytext, sizeof(inc_file));
yyin = fopen(inc_file, "r");
@ -1708,7 +1750,7 @@ parse_include(void)
if ((yytext[0] == '"' && yytext[i] == '"') || (yytext[0] == '<' && yytext[i] == '>'))
{
yytext[i] = '\0';
memmove(yytext, yytext+1, strlen(yytext));
memmove(yytext, yytext + 1, strlen(yytext));
}
for (ip = include_paths; yyin == NULL && ip != NULL; ip = ip->next)
@ -1718,7 +1760,7 @@ parse_include(void)
fprintf(stderr, _("Error: include path \"%s/%s\" is too long on line %d, skipping\n"), ip->path, yytext, yylineno);
continue;
}
snprintf (inc_file, sizeof(inc_file), "%s/%s", ip->path, yytext);
snprintf(inc_file, sizeof(inc_file), "%s/%s", ip->path, yytext);
yyin = fopen(inc_file, "r");
if (!yyin)
{
@ -1728,10 +1770,14 @@ parse_include(void)
yyin = fopen(inc_file, "r");
}
}
/* if the command was "include_next" we have to disregard the first hit */
/*
* if the command was "include_next" we have to disregard the
* first hit
*/
if (yyin && include_next)
{
fclose (yyin);
fclose(yyin);
yyin = NULL;
include_next = false;
}
@ -1741,7 +1787,7 @@ parse_include(void)
mmfatal(NO_INCLUDE_FILE, "could not open include file \"%s\" on line %d", yytext, yylineno);
input_filename = mm_strdup(inc_file);
yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
yylineno = 1;
output_line_number();