case ECPGd_di_precision:
case ECPGd_precision:
case ECPGd_scale:
- mmerror(PARSE_ERROR, ET_FATAL, "descriptor item \"%s\" is not implemented",
+ mmfatal(PARSE_ERROR, "descriptor item \"%s\" is not implemented",
descriptor_item_name(results->value));
break;
case ECPGd_octet:
case ECPGd_ret_length:
case ECPGd_ret_octet:
- mmerror(PARSE_ERROR, ET_FATAL, "descriptor item \"%s\" cannot be set",
+ mmfatal(PARSE_ERROR, "descriptor item \"%s\" cannot be set",
descriptor_item_name(results->value));
break;
/*
* Handle parsing errors and warnings
*/
-void
-mmerror(int error_code, enum errortype type, const char *error, ...)
+static void __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)))
+vmmerror(int error_code, enum errortype type, const char *error, va_list ap)
{
- va_list ap;
-
/* internationalize the error message string */
error = _(error);
fprintf(stderr, _("WARNING: "));
break;
case ET_ERROR:
- case ET_FATAL:
fprintf(stderr, _("ERROR: "));
break;
}
- va_start(ap, error);
vfprintf(stderr, error, ap);
- va_end(ap);
fprintf(stderr, "\n");
case ET_ERROR:
ret_value = error_code;
break;
- case ET_FATAL:
- if (yyin)
- fclose(yyin);
- if (yyout)
- fclose(yyout);
-
- if (strcmp(output_filename, "-") != 0 && unlink(output_filename) != 0)
- fprintf(stderr, _("could not remove output file \"%s\"\n"), output_filename);
- exit(error_code);
}
}
+void
+mmerror(int error_code, enum errortype type, const char *error, ...)
+{
+ va_list ap;
+
+ va_start(ap, error);
+ vmmerror(error_code, type, error, ap);
+ va_end(ap);
+}
+
+void
+mmfatal(int error_code, const char *error, ...)
+{
+ va_list ap;
+
+ va_start(ap, error);
+ vmmerror(error_code, ET_ERROR, error, ap);
+ va_end(ap);
+
+ if (yyin)
+ fclose(yyin);
+ if (yyout)
+ fclose(yyout);
+
+ if (strcmp(output_filename, "-") != 0 && unlink(output_filename) != 0)
+ fprintf(stderr, _("could not remove output file \"%s\"\n"), output_filename);
+ exit(error_code);
+}
+
/*
* string concatenation
*/
{
case '[':
if (brace)
- mmerror(PARSE_ERROR, ET_FATAL, "multidimensional arrays for simple data types are not supported");
+ mmfatal(PARSE_ERROR, "multidimensional arrays for simple data types are not supported");
brace_open++;
break;
case ']':
extern void base_yyerror(const char *);
extern void *mm_alloc(size_t), *mm_realloc(void *, size_t);
extern char *mm_strdup(const char *);
-extern void
-mmerror(int, enum errortype, const char *,...)
-/* This extension allows gcc to check the format string */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
+extern void mmerror(int errorcode, enum errortype type, const char *error, ...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
+extern void mmfatal(int errorcode, const char *error, ...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3),noreturn));
extern void output_get_descr_header(char *);
extern void output_get_descr(char *, char *);
extern void output_set_descr_header(char *);
CATALOG_NAME = ecpg
AVAIL_LANGUAGES = cs de es fr it ja ko pl pt_BR ru tr zh_CN zh_TW
GETTEXT_FILES = descriptor.c ecpg.c pgc.c preproc.c type.c variable.c
-GETTEXT_TRIGGERS = mmerror:3
-GETTEXT_FLAGS = mmerror:3:c-format
+GETTEXT_TRIGGERS = mmerror:3 mmfatal:2
+GETTEXT_FLAGS = mmerror:3:c-format mmfatal:2:c-format
<xc>{op_chars} { ECHO; }
<xc>\*+ { ECHO; }
-<xc><<EOF>> { mmerror(PARSE_ERROR, ET_FATAL, "unterminated /* comment"); }
+<xc><<EOF>> { mmfatal(PARSE_ERROR, "unterminated /* comment"); }
<SQL>{xbstart} {
token_start = yytext;
<xb>{xbinside} { addlit(yytext, yyleng); }
<xh>{quotecontinue} |
<xb>{quotecontinue} { /* ignore */ }
-<xb><<EOF>> { mmerror(PARSE_ERROR, ET_FATAL, "unterminated bit string literal"); }
+<xb><<EOF>> { mmfatal(PARSE_ERROR, "unterminated bit string literal"); }
<SQL>{xhstart} {
token_start = yytext;
return XCONST;
}
-<xh><<EOF>> { mmerror(PARSE_ERROR, ET_FATAL, "unterminated hexadecimal string literal"); }
+<xh><<EOF>> { mmfatal(PARSE_ERROR, "unterminated hexadecimal string literal"); }
<SQL>{xnstart} {
/* National character.
* Transfer it as-is to the backend.
/* This is only needed for \ just before EOF */
addlitchar(yytext[0]);
}
-<xq,xqc,xe,xn,xus><<EOF>> { mmerror(PARSE_ERROR, ET_FATAL, "unterminated quoted string"); }
+<xq,xqc,xe,xn,xus><<EOF>> { mmfatal(PARSE_ERROR, "unterminated quoted string"); }
<SQL>{dolqfailed} {
/* throw back all but the initial "$" */
yyless(1);
}
<xd,xui>{xddouble} { addlitchar('"'); }
<xd,xui>{xdinside} { addlit(yytext, yyleng); }
-<xd,xdc,xui><<EOF>> { mmerror(PARSE_ERROR, ET_FATAL, "unterminated quoted identifier"); }
+<xd,xdc,xui><<EOF>> { mmfatal(PARSE_ERROR, "unterminated quoted identifier"); }
<C,SQL>{xdstart} {
state_before = YYSTATE;
BEGIN(xdc);
BEGIN(C);
}
<undef>{other}|\n {
- mmerror(PARSE_ERROR, ET_FATAL, "missing identifier in EXEC SQL UNDEF command");
+ mmfatal(PARSE_ERROR, "missing identifier in EXEC SQL UNDEF command");
yyterminate();
}
<C>{exec_sql}{include}{space}* { BEGIN(incl); }
}
<C,xskip>{exec_sql}{elif}{space}* { /* pop stack */
if ( preproc_tos == 0 ) {
- mmerror(PARSE_ERROR, ET_FATAL, "missing matching \"EXEC SQL IFDEF\" / \"EXEC SQL IFNDEF\"");
+ mmfatal(PARSE_ERROR, "missing matching \"EXEC SQL IFDEF\" / \"EXEC SQL IFNDEF\"");
}
else if ( stacked_if_value[preproc_tos].else_branch )
- mmerror(PARSE_ERROR, ET_FATAL, "missing \"EXEC SQL ENDIF;\"");
+ mmfatal(PARSE_ERROR, "missing \"EXEC SQL ENDIF;\"");
else
preproc_tos--;
if (INFORMIX_MODE)
{
if (preproc_tos == 0)
- mmerror(PARSE_ERROR, ET_FATAL, "missing matching \"EXEC SQL IFDEF\" / \"EXEC SQL IFNDEF\"");
+ mmfatal(PARSE_ERROR, "missing matching \"EXEC SQL IFDEF\" / \"EXEC SQL IFNDEF\"");
else if (stacked_if_value[preproc_tos].else_branch)
- mmerror(PARSE_ERROR, ET_FATAL, "missing \"EXEC SQL ENDIF;\"");
+ mmfatal(PARSE_ERROR, "missing \"EXEC SQL ENDIF;\"");
else
preproc_tos--;
<C,xskip>{exec_sql}{else}{space}*";" { /* only exec sql endif pops the stack, so take care of duplicated 'else' */
if (stacked_if_value[preproc_tos].else_branch)
- mmerror(PARSE_ERROR, ET_FATAL, "more than one EXEC SQL ELSE");
+ mmfatal(PARSE_ERROR, "more than one EXEC SQL ELSE");
else
{
stacked_if_value[preproc_tos].else_branch = TRUE;
if (INFORMIX_MODE)
{
if (stacked_if_value[preproc_tos].else_branch)
- mmerror(PARSE_ERROR, ET_FATAL, "more than one EXEC SQL ELSE");
+ mmfatal(PARSE_ERROR, "more than one EXEC SQL ELSE");
else
{
stacked_if_value[preproc_tos].else_branch = TRUE;
}
<C,xskip>{exec_sql}{endif}{space}*";" {
if (preproc_tos == 0)
- mmerror(PARSE_ERROR, ET_FATAL, "unmatched EXEC SQL ENDIF");
+ mmfatal(PARSE_ERROR, "unmatched EXEC SQL ENDIF");
else
preproc_tos--;
if (INFORMIX_MODE)
{
if (preproc_tos == 0)
- mmerror(PARSE_ERROR, ET_FATAL, "unmatched EXEC SQL ENDIF");
+ mmfatal(PARSE_ERROR, "unmatched EXEC SQL ENDIF");
else
preproc_tos--;
<xcond>{identifier}{space}*";" {
if (preproc_tos >= MAX_NESTED_IF-1)
- mmerror(PARSE_ERROR, ET_FATAL, "too many nested EXEC SQL IFDEF conditions");
+ mmfatal(PARSE_ERROR, "too many nested EXEC SQL IFDEF conditions");
else
{
struct _defines *defptr;
}
<xcond>{other}|\n {
- mmerror(PARSE_ERROR, ET_FATAL, "missing identifier in EXEC SQL IFDEF command");
+ mmfatal(PARSE_ERROR, "missing identifier in EXEC SQL IFDEF command");
yyterminate();
}
<def_ident>{identifier} {
startlit();
}
<def_ident>{other}|\n {
- mmerror(PARSE_ERROR, ET_FATAL, "missing identifier in EXEC SQL DEFINE command");
+ mmfatal(PARSE_ERROR, "missing identifier in EXEC SQL DEFINE command");
yyterminate();
}
<def>{space}*";" {
<incl>{dquote}{xdinside}{dquote}{space}*";"? { parse_include(); }
<incl>[^;\<\>\"]+";" { parse_include(); }
<incl>{other}|\n {
- mmerror(PARSE_ERROR, ET_FATAL, "syntax error in EXEC SQL INCLUDE command");
+ mmfatal(PARSE_ERROR, "syntax error in EXEC SQL INCLUDE command");
yyterminate();
}
if ( preproc_tos > 0 )
{
preproc_tos = 0;
- mmerror(PARSE_ERROR, ET_FATAL, "missing \"EXEC SQL ENDIF;\"");
+ mmfatal(PARSE_ERROR, "missing \"EXEC SQL ENDIF;\"");
}
yyterminate();
}
}
}
-<INITIAL>{other}|\n { mmerror(PARSE_ERROR, ET_FATAL, "internal error: unreachable state; please report this to <pgsql-bugs@postgresql.org>"); }
+<INITIAL>{other}|\n { mmfatal(PARSE_ERROR, "internal error: unreachable state; please report this to <pgsql-bugs@postgresql.org>"); }
%%
void
lex_init(void)
}
}
if (!yyin)
- mmerror(NO_INCLUDE_FILE, ET_FATAL, "could not open include file \"%s\" on line %d", yytext, yylineno);
+ 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 ));
void *ptr = malloc(size);
if (ptr == NULL)
- mmerror(OUT_OF_MEMORY, ET_FATAL, "out of memory");
+ mmfatal(OUT_OF_MEMORY, "out of memory");
return ptr;
}
char *new = strdup(string);
if (new == NULL)
- mmerror(OUT_OF_MEMORY, ET_FATAL, "out of memory");
+ mmfatal(OUT_OF_MEMORY, "out of memory");
return new;
}
{
case ECPGt_array:
if (indicator_set && ind_type->type != ECPGt_array)
- mmerror(INDICATOR_NOT_ARRAY, ET_FATAL, "indicator for array/pointer has to be array/pointer");
+ mmfatal(INDICATOR_NOT_ARRAY, "indicator for array/pointer has to be array/pointer");
switch (type->u.element->type)
{
case ECPGt_array:
break;
case ECPGt_struct:
if (indicator_set && ind_type->type != ECPGt_struct)
- mmerror(INDICATOR_NOT_STRUCT, ET_FATAL, "indicator for struct has to be a struct");
+ mmfatal(INDICATOR_NOT_STRUCT, "indicator for struct has to be a struct");
ECPGdump_a_struct(o, name, ind_name, mm_strdup("1"), type, ind_type, prefix, ind_prefix);
break;
break;
case ECPGt_char_variable:
if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
- mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "indicator for simple data type has to be simple");
+ mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
ECPGdump_a_simple(o, name, type->type, mm_strdup("1"), (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : mm_strdup("1"), struct_sizeof, prefix, 0);
if (ind_type != NULL)
break;
case ECPGt_descriptor:
if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
- mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "indicator for simple data type has to be simple");
+ mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
ECPGdump_a_simple(o, name, type->type, NULL, mm_strdup("-1"), NULL, prefix, 0);
if (ind_type != NULL)
break;
default:
if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
- mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "indicator for simple data type has to be simple");
+ mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
ECPGdump_a_simple(o, name, type->type, type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : mm_strdup("-1"), struct_sizeof, prefix, type->counter);
if (ind_type != NULL)
enum errortype
{
- ET_WARNING, ET_ERROR, ET_FATAL
+ ET_WARNING, ET_ERROR
};
struct fetch_desc
case '\0': /* found the end, but this time it has to be
* an array element */
if (members->type->type != ECPGt_array)
- mmerror(PARSE_ERROR, ET_FATAL, "incorrectly formed variable \"%s\"", name);
+ mmfatal(PARSE_ERROR, "incorrectly formed variable \"%s\"", name);
switch (members->type->u.element->type)
{
return (find_struct_member(name, end, members->type->u.members, brace_level));
break;
default:
- mmerror(PARSE_ERROR, ET_FATAL, "incorrectly formed variable \"%s\"", name);
+ mmfatal(PARSE_ERROR, "incorrectly formed variable \"%s\"", name);
break;
}
}
if (c == '-')
{
if (p->type->type != ECPGt_array)
- mmerror(PARSE_ERROR, ET_FATAL, "variable \"%s\" is not a pointer", name);
+ mmfatal(PARSE_ERROR, "variable \"%s\" is not a pointer", name);
if (p->type->u.element->type != ECPGt_struct && p->type->u.element->type != ECPGt_union)
- mmerror(PARSE_ERROR, ET_FATAL, "variable \"%s\" is not a pointer to a structure or a union", name);
+ mmfatal(PARSE_ERROR, "variable \"%s\" is not a pointer to a structure or a union", name);
/* restore the name, we will need it later */
*next = c;
if (next == end)
{
if (p->type->type != ECPGt_struct && p->type->type != ECPGt_union)
- mmerror(PARSE_ERROR, ET_FATAL, "variable \"%s\" is neither a structure nor a union", name);
+ mmfatal(PARSE_ERROR, "variable \"%s\" is neither a structure nor a union", name);
/* restore the name, we will need it later */
*next = c;
else
{
if (p->type->type != ECPGt_array)
- mmerror(PARSE_ERROR, ET_FATAL, "variable \"%s\" is not an array", name);
+ mmfatal(PARSE_ERROR, "variable \"%s\" is not an array", name);
if (p->type->u.element->type != ECPGt_struct && p->type->u.element->type != ECPGt_union)
- mmerror(PARSE_ERROR, ET_FATAL, "variable \"%s\" is not a pointer to a structure or a union", name);
+ mmfatal(PARSE_ERROR, "variable \"%s\" is not a pointer to a structure or a union", name);
/* restore the name, we will need it later */
*next = c;
*next = '\0';
p = find_simple(name);
if (p == NULL)
- mmerror(PARSE_ERROR, ET_FATAL, "variable \"%s\" is not declared", name);
+ mmfatal(PARSE_ERROR, "variable \"%s\" is not declared", name);
*next = c;
switch (p->type->u.element->type)
p = find_simple(name);
if (p == NULL)
- mmerror(PARSE_ERROR, ET_FATAL, "variable \"%s\" is not declared", name);
+ mmfatal(PARSE_ERROR, "variable \"%s\" is not declared", name);
return (p);
}
for (this = types; this && strcmp(this->name, name) != 0; this = this->next);
if (!this)
- mmerror(PARSE_ERROR, ET_FATAL, "unrecognized data type name \"%s\"", name);
+ mmfatal(PARSE_ERROR, "unrecognized data type name \"%s\"", name);
return (this);
}
if (atoi(type_index) >= 0)
{
if (atoi(*length) >= 0)
- mmerror(PARSE_ERROR, ET_FATAL, "multidimensional arrays are not supported");
+ mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
*length = type_index;
}
if (atoi(type_dimension) >= 0)
{
if (atoi(*dimension) >= 0 && atoi(*length) >= 0)
- mmerror(PARSE_ERROR, ET_FATAL, "multidimensional arrays are not supported");
+ mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
if (atoi(*dimension) >= 0)
*length = *dimension;
}
if (pointer_len > 2)
- mmerror(PARSE_ERROR, ET_FATAL, ngettext("multilevel pointers (more than 2 levels) are not supported; found %d level",
+ mmfatal(PARSE_ERROR, ngettext("multilevel pointers (more than 2 levels) are not supported; found %d level",
"multilevel pointers (more than 2 levels) are not supported; found %d levels", pointer_len),
pointer_len);
if (pointer_len > 1 && type_enum != ECPGt_char && type_enum != ECPGt_unsigned_char && type_enum != ECPGt_string)
- mmerror(PARSE_ERROR, ET_FATAL, "pointer to pointer is not supported for this data type");
+ mmfatal(PARSE_ERROR, "pointer to pointer is not supported for this data type");
if (pointer_len > 1 && (atoi(*length) >= 0 || atoi(*dimension) >= 0))
- mmerror(PARSE_ERROR, ET_FATAL, "multidimensional arrays are not supported");
+ mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
if (atoi(*length) >= 0 && atoi(*dimension) >= 0 && pointer_len)
- mmerror(PARSE_ERROR, ET_FATAL, "multidimensional arrays are not supported");
+ mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
switch (type_enum)
{
}
if (atoi(*length) >= 0)
- mmerror(PARSE_ERROR, ET_FATAL, "multidimensional arrays for structures are not supported");
+ mmfatal(PARSE_ERROR, "multidimensional arrays for structures are not supported");
break;
case ECPGt_varchar:
}
if (atoi(*length) >= 0)
- mmerror(PARSE_ERROR, ET_FATAL, "multidimensional arrays for simple data types are not supported");
+ mmfatal(PARSE_ERROR, "multidimensional arrays for simple data types are not supported");
break;
}