diff options
Diffstat (limited to 'src/interfaces/ecpg/preproc/output.c')
-rw-r--r-- | src/interfaces/ecpg/preproc/output.c | 97 |
1 files changed, 54 insertions, 43 deletions
diff --git a/src/interfaces/ecpg/preproc/output.c b/src/interfaces/ecpg/preproc/output.c index 760751affd3..7fe282586f6 100644 --- a/src/interfaces/ecpg/preproc/output.c +++ b/src/interfaces/ecpg/preproc/output.c @@ -6,74 +6,83 @@ void output_line_number() { - if (input_filename) - fprintf(yyout, "\n#line %d \"%s\"\n", yylineno, input_filename); + if (input_filename) + fprintf(yyout, "\n#line %d \"%s\"\n", yylineno, input_filename); } void output_simple_statement(char *cmd) { - int i, j = strlen(cmd);; - + int i, + j = strlen(cmd);; + /* do this char by char as we have to filter '\"' */ - for (i = 0; i < j; i++) { + for (i = 0; i < j; i++) + { if (cmd[i] != '"') fputc(cmd[i], yyout); else fputs("\\\"", yyout); } output_line_number(); - free(cmd); + free(cmd); } /* * store the whenever action here */ -struct when when_error, when_nf, when_warn; +struct when when_error, + when_nf, + when_warn; static void -print_action(struct when *w) +print_action(struct when * w) { switch (w->code) { - case W_SQLPRINT: fprintf(yyout, "sqlprint();"); - break; - case W_GOTO: fprintf(yyout, "goto %s;", w->command); - break; - case W_DO: fprintf(yyout, "%s;", w->command); - break; - case W_STOP: fprintf(yyout, "exit (1);"); - break; - case W_BREAK: fprintf(yyout, "break;"); - break; - default: fprintf(yyout, "{/* %d not implemented yet */}", w->code); - break; + case W_SQLPRINT:fprintf(yyout, "sqlprint();"); + break; + case W_GOTO: + fprintf(yyout, "goto %s;", w->command); + break; + case W_DO: + fprintf(yyout, "%s;", w->command); + break; + case W_STOP: + fprintf(yyout, "exit (1);"); + break; + case W_BREAK: + fprintf(yyout, "break;"); + break; + default: + fprintf(yyout, "{/* %d not implemented yet */}", w->code); + break; } } void whenever_action(int mode) { - if ((mode&1) == 1 && when_nf.code != W_NOTHING) + if ((mode & 1) == 1 && when_nf.code != W_NOTHING) { output_line_number(); fprintf(yyout, "\nif (sqlca.sqlcode == ECPG_NOT_FOUND) "); print_action(&when_nf); } if (when_warn.code != W_NOTHING) - { + { output_line_number(); - fprintf(yyout, "\nif (sqlca.sqlwarn[0] == 'W') "); + fprintf(yyout, "\nif (sqlca.sqlwarn[0] == 'W') "); print_action(&when_warn); - } + } if (when_error.code != W_NOTHING) - { + { output_line_number(); - fprintf(yyout, "\nif (sqlca.sqlcode < 0) "); + fprintf(yyout, "\nif (sqlca.sqlcode < 0) "); print_action(&when_error); - } + } - if ((mode&2) == 2) + if ((mode & 2) == 2) fputc('}', yyout); output_line_number(); @@ -82,30 +91,33 @@ whenever_action(int mode) char * hashline_number(void) { - if (input_filename) - { - char* line = mm_alloc(strlen("\n#line %d \"%s\"\n") + 21 + strlen(input_filename)); - sprintf(line, "\n#line %d \"%s\"\n", yylineno, input_filename); + if (input_filename) + { + char *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + 21 + strlen(input_filename)); - return line; - } + sprintf(line, "\n#line %d \"%s\"\n", yylineno, input_filename); - return EMPTY; + return line; + } + + return EMPTY; } void -output_statement(char * stmt, int mode, char *descriptor, char *con) +output_statement(char *stmt, int mode, char *descriptor, char *con) { - int i, j = strlen(stmt); + int i, + j = strlen(stmt); if (descriptor == NULL) fprintf(yyout, "{ ECPGdo(__LINE__, %s, \"", con ? con : "NULL"); else - fprintf(yyout, "{ ECPGdo_descriptor(__LINE__, %s, \"%s\", \"", - con ? con : "NULL", descriptor); + fprintf(yyout, "{ ECPGdo_descriptor(__LINE__, %s, \"%s\", \"", + con ? con : "NULL", descriptor); /* do this char by char as we have to filter '\"' */ - for (i = 0; i < j; i++) { + for (i = 0; i < j; i++) + { if (stmt[i] != '"') fputc(stmt[i], yyout); else @@ -115,7 +127,7 @@ output_statement(char * stmt, int mode, char *descriptor, char *con) if (descriptor == NULL) { fputs("\", ", yyout); - + /* dump variables to C file */ dump_variables(argsinsert, 1); fputs("ECPGt_EOIT, ", yyout); @@ -125,7 +137,7 @@ output_statement(char * stmt, int mode, char *descriptor, char *con) } else fputs("\");", yyout); - + mode |= 2; whenever_action(mode); free(stmt); @@ -134,4 +146,3 @@ output_statement(char * stmt, int mode, char *descriptor, char *con) if (connection != NULL) free(connection); } - |