mirror of https://github.com/postgres/postgres
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:
parent
516b87502d
commit
97add39c03
|
@ -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); }
|
||||
|
@ -44,10 +46,13 @@ ECPG: stmtExecuteStmt block
|
|||
else
|
||||
{
|
||||
/* case of ecpg_ident or CSTRING */
|
||||
char *length = mm_alloc(sizeof(int) * CHAR_BIT * 10 / 3);
|
||||
char *str = mm_strdup($1.name + 1);
|
||||
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);
|
||||
|
@ -62,7 +67,8 @@ ECPG: stmtPrepareStmt block
|
|||
output_prepare_statement($1.name, $1.stmt);
|
||||
else if (strlen($1.type) == 0)
|
||||
{
|
||||
char *stmt = cat_str(3, mm_strdup("\""), $1.stmt, mm_strdup("\""));
|
||||
char *stmt = cat_str(3, mm_strdup("\""), $1.stmt, mm_strdup("\""));
|
||||
|
||||
output_prepare_statement($1.name, stmt);
|
||||
}
|
||||
else
|
||||
|
@ -72,10 +78,13 @@ ECPG: stmtPrepareStmt block
|
|||
add_variable_to_tail(&argsinsert, find_variable($1.name), &no_indicator);
|
||||
else
|
||||
{
|
||||
char *length = mm_alloc(sizeof(int) * CHAR_BIT * 10 / 3);
|
||||
char *str = mm_strdup($1.name + 1);
|
||||
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);
|
||||
}
|
||||
|
@ -118,11 +127,11 @@ ECPG: stmtViewStmt rule
|
|||
}
|
||||
| ECPGCursorStmt
|
||||
{
|
||||
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);
|
||||
}
|
||||
| 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);
|
||||
|
||||
|
@ -244,13 +256,14 @@ 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);
|
||||
char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
|
||||
|
||||
$$ = 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 &&
|
||||
(strcmp($7, "stdin") == 0 || strcmp($7, "stdout") == 0))
|
||||
mmerror(PARSE_ERROR, ET_WARNING, "COPY FROM STDIN is not implemented");
|
||||
if (strcmp($6, "from") == 0 &&
|
||||
(strcmp($7, "stdin") == 0 || strcmp($7, "stdout") == 0))
|
||||
mmerror(PARSE_ERROR, ET_WARNING, "COPY FROM STDIN is not implemented");
|
||||
ECPG: var_valueNumericOnly addon
|
||||
if ($1[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);
|
||||
|
@ -337,13 +350,14 @@ ECPG: fetch_argsBACKWARDSignedIconstopt_from_incursor_name addon
|
|||
}
|
||||
ECPG: cursor_namename rule
|
||||
| char_civar
|
||||
{
|
||||
char *curname = mm_alloc(strlen($1) + 2);
|
||||
sprintf(curname, ":%s", $1);
|
||||
free($1);
|
||||
$1 = curname;
|
||||
$$ = $1;
|
||||
}
|
||||
{
|
||||
char *curname = mm_alloc(strlen($1) + 2);
|
||||
|
||||
sprintf(curname, ":%s", $1);
|
||||
free($1);
|
||||
$1 = curname;
|
||||
$$ = $1;
|
||||
}
|
||||
ECPG: ExplainableStmtExecuteStmt block
|
||||
{
|
||||
$$ = $1.name;
|
||||
|
@ -367,28 +381,31 @@ 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;
|
||||
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);
|
||||
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);
|
||||
|
||||
if (INFORMIX_MODE && pg_strcasecmp($2, "database") == 0)
|
||||
mmfatal(PARSE_ERROR, "\"database\" cannot be used as cursor name in INFORMIX mode");
|
||||
if (INFORMIX_MODE && pg_strcasecmp($2, "database") == 0)
|
||||
mmfatal(PARSE_ERROR, "\"database\" cannot be used as cursor name in INFORMIX mode");
|
||||
|
||||
for (ptr = cur; ptr != NULL; ptr = ptr->next)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -401,7 +418,7 @@ ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectSt
|
|||
this->function = (current_function ? mm_strdup(current_function) : NULL);
|
||||
this->connection = connection ? mm_strdup(connection) : NULL;
|
||||
this->opened = false;
|
||||
this->command = cat_str(7, mm_strdup("declare"), cursor_marker, $3, mm_strdup("cursor"), $5, mm_strdup("for"), $7);
|
||||
this->command = cat_str(7, mm_strdup("declare"), cursor_marker, $3, mm_strdup("cursor"), $5, mm_strdup("for"), $7);
|
||||
this->argsinsert = argsinsert;
|
||||
this->argsinsert_oos = NULL;
|
||||
this->argsresult = argsresult;
|
||||
|
@ -422,15 +439,15 @@ ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectSt
|
|||
}
|
||||
ECPG: ClosePortalStmtCLOSEcursor_name block
|
||||
{
|
||||
char *cursor_marker = $2[0] == ':' ? mm_strdup("$0") : $2;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -444,15 +461,22 @@ ECPG: opt_hold block
|
|||
$$ = EMPTY;
|
||||
}
|
||||
ECPG: into_clauseINTOOptTempTableName block
|
||||
{
|
||||
FoundInto = 1;
|
||||
$$= cat2_str(mm_strdup("into"), $2);
|
||||
}
|
||||
| ecpg_into { $$ = EMPTY; }
|
||||
{
|
||||
FoundInto = 1;
|
||||
$$ = cat2_str(mm_strdup("into"), $2);
|
||||
}
|
||||
| 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,22 +501,24 @@ 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; }
|
||||
| civar { $$ = $1; }
|
||||
| civarind { $$ = $1; }
|
||||
ECPG: ColIdcol_name_keyword rule
|
||||
| ECPGKeywords { $$ = $1; }
|
||||
| ECPGCKeywords { $$ = $1; }
|
||||
| CHAR_P { $$ = mm_strdup("char"); }
|
||||
| VALUES { $$ = mm_strdup("values"); }
|
||||
| ECPGKeywords { $$ = $1; }
|
||||
| ECPGCKeywords { $$ = $1; }
|
||||
| CHAR_P { $$ = mm_strdup("char"); }
|
||||
| VALUES { $$ = mm_strdup("values"); }
|
||||
ECPG: type_function_nametype_func_name_keyword rule
|
||||
| ECPGKeywords { $$ = $1; }
|
||||
| ECPGTypeName { $$ = $1; }
|
||||
| ECPGCKeywords { $$ = $1; }
|
||||
| ECPGKeywords { $$ = $1; }
|
||||
| ECPGTypeName { $$ = $1; }
|
||||
| ECPGCKeywords { $$ = $1; }
|
||||
ECPG: VariableShowStmtSHOWALL block
|
||||
{
|
||||
mmerror(PARSE_ERROR, ET_ERROR, "SHOW ALL is not implemented");
|
||||
|
@ -505,73 +531,81 @@ ECPG: FetchStmtMOVEfetch_args rule
|
|||
}
|
||||
| FETCH FORWARD cursor_name opt_ecpg_fetch_into
|
||||
{
|
||||
char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
|
||||
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);
|
||||
}
|
||||
| FETCH FORWARD from_in cursor_name opt_ecpg_fetch_into
|
||||
{
|
||||
char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
|
||||
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);
|
||||
}
|
||||
| FETCH BACKWARD cursor_name opt_ecpg_fetch_into
|
||||
{
|
||||
char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
|
||||
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);
|
||||
}
|
||||
| FETCH BACKWARD from_in cursor_name opt_ecpg_fetch_into
|
||||
{
|
||||
char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
|
||||
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);
|
||||
}
|
||||
| MOVE FORWARD cursor_name
|
||||
{
|
||||
char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
|
||||
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);
|
||||
}
|
||||
| MOVE FORWARD from_in cursor_name
|
||||
{
|
||||
char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
|
||||
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);
|
||||
}
|
||||
| MOVE BACKWARD cursor_name
|
||||
{
|
||||
char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
|
||||
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);
|
||||
}
|
||||
| MOVE BACKWARD from_in cursor_name
|
||||
{
|
||||
char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -37,24 +37,25 @@ extern int base_yynerrs;
|
|||
/*
|
||||
* Variables containing simple states.
|
||||
*/
|
||||
int struct_level = 0;
|
||||
int braces_open; /* brace level counter */
|
||||
char *current_function;
|
||||
int ecpg_internal_var = 0;
|
||||
char *connection = NULL;
|
||||
char *input_filename = NULL;
|
||||
int struct_level = 0;
|
||||
int braces_open; /* brace level counter */
|
||||
char *current_function;
|
||||
int ecpg_internal_var = 0;
|
||||
char *connection = NULL;
|
||||
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,11 +155,11 @@ cat2_str(char *str1, char *str2)
|
|||
}
|
||||
|
||||
static char *
|
||||
cat_str(int count, ...)
|
||||
cat_str(int count,...)
|
||||
{
|
||||
va_list args;
|
||||
int i;
|
||||
char *res_str;
|
||||
char *res_str;
|
||||
|
||||
va_start(args, count);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -210,13 +211,18 @@ static char *
|
|||
create_questionmarks(char *name, bool array)
|
||||
{
|
||||
struct variable *p = find_variable(name);
|
||||
int count;
|
||||
char *result = EMPTY;
|
||||
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,42 +246,45 @@ 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;
|
||||
int insert;
|
||||
char *result = EMPTY;
|
||||
int insert;
|
||||
|
||||
for (insert = 1; insert >= 0; insert--)
|
||||
{
|
||||
struct arguments *list;
|
||||
struct arguments *ptr;
|
||||
struct arguments *newlist = NULL;
|
||||
struct variable *newvar, *newind;
|
||||
struct variable *newvar,
|
||||
*newind;
|
||||
|
||||
list = (insert ? cur->argsinsert : cur->argsresult);
|
||||
|
||||
for (ptr = list; ptr != NULL; ptr = ptr->next)
|
||||
{
|
||||
char var_text[20];
|
||||
char *original_var;
|
||||
bool skip_set_var = false;
|
||||
bool var_ptr = false;
|
||||
char var_text[20];
|
||||
char *original_var;
|
||||
bool skip_set_var = false;
|
||||
bool var_ptr = false;
|
||||
|
||||
/* change variable name to "ECPGget_var(<counter>)" */
|
||||
original_var = ptr->variable->name;
|
||||
|
@ -350,10 +359,10 @@ adjust_outofscope_cursor_vars(struct cursor *cur)
|
|||
|| ptr->variable->type->u.element->type == ECPGt_union)
|
||||
{
|
||||
newvar = new_variable(cat_str(5, mm_strdup("(*("),
|
||||
mm_strdup(ptr->variable->type->u.element->type_name),
|
||||
mm_strdup(" *)(ECPGget_var("),
|
||||
mm_strdup(var_text),
|
||||
mm_strdup(")")),
|
||||
mm_strdup(ptr->variable->type->u.element->type_name),
|
||||
mm_strdup(" *)(ECPGget_var("),
|
||||
mm_strdup(var_text),
|
||||
mm_strdup(")")),
|
||||
ECPGmake_struct_type(ptr->variable->type->u.element->u.members,
|
||||
ptr->variable->type->u.element->type,
|
||||
ptr->variable->type->u.element->type_name,
|
||||
|
@ -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;
|
||||
|
@ -412,10 +427,10 @@ adjust_outofscope_cursor_vars(struct cursor *cur)
|
|||
|| ptr->indicator->type->type == ECPGt_union)
|
||||
{
|
||||
newind = new_variable(cat_str(5, mm_strdup("(*("),
|
||||
mm_strdup(ptr->indicator->type->type_name),
|
||||
mm_strdup(" *)(ECPGget_var("),
|
||||
mm_strdup(var_text),
|
||||
mm_strdup(")")),
|
||||
mm_strdup(ptr->indicator->type->type_name),
|
||||
mm_strdup(" *)(ECPGget_var("),
|
||||
mm_strdup(var_text),
|
||||
mm_strdup(")")),
|
||||
ECPGmake_struct_type(ptr->indicator->type->u.members,
|
||||
ptr->indicator->type->type,
|
||||
ptr->indicator->type->type_name,
|
||||
|
@ -429,10 +444,10 @@ adjust_outofscope_cursor_vars(struct cursor *cur)
|
|||
|| ptr->indicator->type->u.element->type == ECPGt_union)
|
||||
{
|
||||
newind = new_variable(cat_str(5, mm_strdup("(*("),
|
||||
mm_strdup(ptr->indicator->type->u.element->type_name),
|
||||
mm_strdup(" *)(ECPGget_var("),
|
||||
mm_strdup(var_text),
|
||||
mm_strdup(")")),
|
||||
mm_strdup(ptr->indicator->type->u.element->type_name),
|
||||
mm_strdup(" *)(ECPGget_var("),
|
||||
mm_strdup(var_text),
|
||||
mm_strdup(")")),
|
||||
ECPGmake_struct_type(ptr->indicator->type->u.element->u.members,
|
||||
ptr->indicator->type->u.element->type,
|
||||
ptr->indicator->type->u.element->type_name,
|
||||
|
@ -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) &&
|
||||
|
@ -570,7 +593,7 @@ add_typedef(char *name, char *dimension, char *length, enum ECPGttype type_enum,
|
|||
this->type->type_index = length; /* length of string */
|
||||
this->type->type_sizeof = ECPGstruct_sizeof;
|
||||
this->struct_member_list = (type_enum == ECPGt_struct || type_enum == ECPGt_union) ?
|
||||
ECPGstruct_member_dup(struct_member_list[struct_level]) : NULL;
|
||||
ECPGstruct_member_dup(struct_member_list[struct_level]) : NULL;
|
||||
|
||||
if (type_enum != ECPGt_varchar &&
|
||||
type_enum != ECPGt_bytea &&
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -614,18 +638,18 @@ check_declared_list(const char *name)
|
|||
%locations
|
||||
|
||||
%union {
|
||||
double dval;
|
||||
char *str;
|
||||
int ival;
|
||||
struct when action;
|
||||
struct index index;
|
||||
int tagname;
|
||||
struct this_type type;
|
||||
enum ECPGttype type_enum;
|
||||
enum ECPGdtype dtype_enum;
|
||||
struct fetch_desc descriptor;
|
||||
struct su_symbol struct_union;
|
||||
struct prep prep;
|
||||
struct exec exec;
|
||||
struct describe describe;
|
||||
double dval;
|
||||
char *str;
|
||||
int ival;
|
||||
struct when action;
|
||||
struct index index;
|
||||
int tagname;
|
||||
struct this_type type;
|
||||
enum ECPGttype type_enum;
|
||||
enum ECPGdtype dtype_enum;
|
||||
struct fetch_desc descriptor;
|
||||
struct su_symbol struct_union;
|
||||
struct prep prep;
|
||||
struct exec exec;
|
||||
struct describe describe;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue