LCOV - differential code coverage report
Current view: top level - src/interfaces/ecpg/preproc - ecpg.c (source / functions) Coverage Total Hit UNC LBC UIC UBC GBC GIC GNC CBC EUB ECB DUB DCB
Current: Differential Code Coverage HEAD vs 15 Lines: 43.5 % 255 111 19 6 32 87 7 39 16 49 36 41 14 15
Current Date: 2023-04-08 17:13:01 Functions: 50.0 % 4 2 2 1 1
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 (60,120] days: 45.7 % 35 16 19 16
Legend: Lines: hit not hit (240..) days: 43.2 % 220 95 6 32 87 7 39 49 36 41
Function coverage date bins:
(240..) days: 50.0 % 4 2 2 1 1

 Age         Owner                  TLA  Line data    Source code
                                  1                 : /* src/interfaces/ecpg/preproc/ecpg.c */
                                  2                 : 
                                  3                 : /* Main for ecpg, the PostgreSQL embedded SQL precompiler. */
                                  4                 : /* Copyright (c) 1996-2023, PostgreSQL Global Development Group */
                                  5                 : 
                                  6                 : #include "postgres_fe.h"
                                  7                 : 
                                  8                 : #include <unistd.h>
                                  9                 : 
                                 10                 : #include "getopt_long.h"
                                 11                 : 
                                 12                 : #include "preproc_extern.h"
                                 13                 : 
                                 14                 : int         ret_value = 0;
                                 15                 : bool        autocommit = false,
                                 16                 :             auto_create_c = false,
                                 17                 :             system_includes = false,
                                 18                 :             force_indicator = true,
                                 19                 :             questionmarks = false,
                                 20                 :             regression_mode = false,
                                 21                 :             auto_prepare = false;
                                 22                 : 
                                 23                 : char       *output_filename;
                                 24                 : 
                                 25                 : enum COMPAT_MODE compat = ECPG_COMPAT_PGSQL;
                                 26                 : 
                                 27                 : struct _include_path *include_paths = NULL;
                                 28                 : struct cursor *cur = NULL;
                                 29                 : struct typedefs *types = NULL;
                                 30                 : struct _defines *defines = NULL;
                                 31                 : struct declared_list *g_declared_list = NULL;
                                 32                 : 
                                 33                 : static void
 7898 peter_e                    34 UBC           0 : help(const char *progname)
                                 35                 : {
 5441                            36               0 :     printf(_("%s is the PostgreSQL embedded SQL preprocessor for C programs.\n\n"),
                                 37                 :            progname);
                                 38               0 :     printf(_("Usage:\n"
                                 39                 :              "  %s [OPTION]... FILE...\n\n"),
                                 40                 :            progname);
                                 41               0 :     printf(_("Options:\n"));
                                 42               0 :     printf(_("  -c             automatically generate C code from embedded SQL code;\n"
                                 43                 :              "                 this affects EXEC SQL TYPE\n"));
 5189                            44               0 :     printf(_("  -C MODE        set compatibility mode; MODE can be one of\n"
                                 45                 :              "                 \"INFORMIX\", \"INFORMIX_SE\", \"ORACLE\"\n"));
                                 46                 : #ifdef YYDEBUG
                                 47                 :     printf(_("  -d             generate parser debug output\n"));
                                 48                 : #endif
 5441                            49               0 :     printf(_("  -D SYMBOL      define SYMBOL\n"));
                                 50               0 :     printf(_("  -h             parse a header file, this option includes option \"-c\"\n"));
                                 51               0 :     printf(_("  -i             parse system include files as well\n"));
                                 52               0 :     printf(_("  -I DIRECTORY   search DIRECTORY for include files\n"));
                                 53               0 :     printf(_("  -o OUTFILE     write result to OUTFILE\n"));
 5189                            54               0 :     printf(_("  -r OPTION      specify run-time behavior; OPTION can be:\n"
                                 55                 :              "                 \"no_indicator\", \"prepare\", \"questionmarks\"\n"));
 5156                            56               0 :     printf(_("  --regression   run in regression testing mode\n"));
 5441                            57               0 :     printf(_("  -t             turn on autocommit of transactions\n"));
 2394 heikki.linnakangas         58               0 :     printf(_("  -V, --version  output version information, then exit\n"));
 3947 peter_e                    59               0 :     printf(_("  -?, --help     show this help, then exit\n"));
 5441                            60               0 :     printf(_("\nIf no output file is specified, the name is formed by adding .c to the\n"
                                 61                 :              "input file name, after stripping off .pgc if present.\n"));
 1136 peter                      62               0 :     printf(_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
                                 63               0 :     printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
 9151 bruce                      64               0 : }
                                 65                 : 
                                 66                 : static void
 8986 bruce                      67 CBC         393 : add_include_path(char *path)
                                 68                 : {
 7188                            69             393 :     struct _include_path *ip = include_paths,
                                 70                 :                *new;
                                 71                 : 
 7271 meskes                     72             393 :     new = mm_alloc(sizeof(struct _include_path));
                                 73             393 :     new->path = path;
                                 74             393 :     new->next = NULL;
                                 75                 : 
                                 76             393 :     if (ip == NULL)
                                 77              64 :         include_paths = new;
                                 78                 :     else
                                 79                 :     {
 7188 bruce                      80            1014 :         for (; ip->next != NULL; ip = ip->next);
 7271 meskes                     81             329 :         ip->next = new;
                                 82                 :     }
 9193 scrappy                    83             393 : }
                                 84                 : 
                                 85                 : static void
 8482 meskes                     86 UBC           0 : add_preprocessor_define(char *define)
                                 87                 : {
                                 88               0 :     struct _defines *pd = defines;
                                 89                 :     char       *ptr,
 7188 bruce                      90               0 :                *define_copy = mm_strdup(define);
                                 91                 : 
 8482 meskes                     92               0 :     defines = mm_alloc(sizeof(struct _defines));
                                 93                 : 
                                 94                 :     /* look for = sign */
 7327                            95               0 :     ptr = strchr(define_copy, '=');
                                 96               0 :     if (ptr != NULL)
                                 97                 :     {
                                 98                 :         char       *tmp;
                                 99                 : 
                                100                 :         /* symbol has a value */
 7188 bruce                     101               0 :         for (tmp = ptr - 1; *tmp == ' '; tmp--);
 7327 meskes                    102               0 :         tmp[1] = '\0';
 1409 tgl                       103               0 :         defines->olddef = define_copy;
                                104               0 :         defines->newdef = ptr + 1;
                                105                 :     }
                                106                 :     else
                                107                 :     {
                                108               0 :         defines->olddef = define_copy;
                                109               0 :         defines->newdef = mm_strdup("1");
                                110                 :     }
 8482 meskes                    111               0 :     defines->pertinent = true;
 6837                           112               0 :     defines->used = NULL;
 8482                           113               0 :     defines->next = pd;
                                114               0 : }
                                115                 : 
                                116                 : #define ECPG_GETOPT_LONG_REGRESSION     1
                                117                 : int
 9193 scrappy                   118 CBC          64 : main(int argc, char *const argv[])
                                119                 : {
                                120                 :     static struct option ecpg_options[] = {
                                121                 :         {"regression", no_argument, NULL, ECPG_GETOPT_LONG_REGRESSION},
                                122                 :         {NULL, 0, NULL, 0}
                                123                 :     };
                                124                 : 
                                125                 :     int         fnr,
                                126                 :                 c,
 8986 bruce                     127              64 :                 out_option = 0;
 4382                           128              64 :     bool        verbose = false,
 4541 meskes                    129              64 :                 header_mode = false;
                                130                 :     struct _include_path *ip;
                                131                 :     const char *progname;
                                132                 :     char        my_exec_path[MAXPGPATH];
                                133                 :     char        include_path[MAXPGPATH];
                                134                 : 
 5232 peter_e                   135              64 :     set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("ecpg"));
                                136                 : 
 7310 bruce                     137              64 :     progname = get_progname(argv[0]);
                                138                 : 
 3326 sfrost                    139              64 :     if (find_my_exec(argv[0], my_exec_path) < 0)
                                140                 :     {
 3326 sfrost                    141 UBC           0 :         fprintf(stderr, _("%s: could not locate my own executable path\n"), argv[0]);
 2061 peter_e                   142               0 :         return ILLEGAL_OPTION;
                                143                 :     }
                                144                 : 
 2394 heikki.linnakangas        145 CBC          64 :     if (argc > 1)
                                146                 :     {
                                147              64 :         if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
                                148                 :         {
 2394 heikki.linnakangas        149 UBC           0 :             help(progname);
                                150               0 :             exit(0);
                                151                 :         }
 2394 heikki.linnakangas        152 CBC          64 :         if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
                                153                 :         {
 1670 peter_e                   154 UBC           0 :             printf("ecpg (PostgreSQL) %s\n", PG_VERSION);
 2394 heikki.linnakangas        155               0 :             exit(0);
                                156                 :         }
                                157                 :     }
                                158                 : 
 5781 meskes                    159 CBC          64 :     output_filename = NULL;
  118 peter                     160 GNC         336 :     while ((c = getopt_long(argc, argv, "cC:dD:hiI:o:r:tv", ecpg_options, NULL)) != -1)
                                161                 :     {
 9193 scrappy                   162 CBC         272 :         switch (c)
                                163                 :         {
 7689 meskes                    164 GBC           2 :             case 'c':
                                165               2 :                 auto_create_c = true;
                                166               2 :                 break;
 7360                           167              10 :             case 'C':
 1913                           168              10 :                 if (pg_strcasecmp(optarg, "INFORMIX") == 0 || pg_strcasecmp(optarg, "INFORMIX_SE") == 0)
 7327 meskes                    169 CBC           9 :                 {
 6797 bruce                     170 ECB             :                     char        pkginclude_path[MAXPGPATH];
                                171                 :                     char        informix_path[MAXPGPATH];
                                172                 : 
 1913 meskes                    173 CBC           9 :                     compat = (pg_strcasecmp(optarg, "INFORMIX") == 0) ? ECPG_COMPAT_INFORMIX : ECPG_COMPAT_INFORMIX_SE;
 6901 bruce                     174               9 :                     get_pkginclude_path(my_exec_path, pkginclude_path);
                                175               9 :                     snprintf(informix_path, MAXPGPATH, "%s/informix/esql", pkginclude_path);
                                176               9 :                     add_include_path(informix_path);
 7327 meskes                    177 ECB             :                 }
 1377 meskes                    178 GBC           1 :                 else if (pg_strcasecmp(optarg, "ORACLE") == 0)
                                179                 :                 {
 1852 meskes                    180 CBC           1 :                     compat = ECPG_COMPAT_ORACLE;
                                181                 :                 }
 7360 meskes                    182 ECB             :                 else
                                183                 :                 {
 5441 peter_e                   184 UBC           0 :                     fprintf(stderr, _("Try \"%s --help\" for more information.\n"), argv[0]);
 7360 meskes                    185               0 :                     return ILLEGAL_OPTION;
 7188 bruce                     186 EUB             :                 }
 7360 meskes                    187 GIC          10 :                 break;
  118 peter                     188 UNC           0 :             case 'd':
                                189                 : #ifdef YYDEBUG
                                190                 :                 base_yydebug = 1;
                                191                 : #else
                                192               0 :                 fprintf(stderr, _("%s: parser debug support (-d) not available\n"),
                                193                 :                         progname);
                                194                 : #endif
                                195               0 :                 break;
                                196               0 :             case 'D':
                                197               0 :                 add_preprocessor_define(optarg);
                                198               0 :                 break;
                                199               0 :             case 'h':
                                200               0 :                 header_mode = true;
                                201                 :                 /* this must include "-c" to make sense: */
                                202               0 :                 auto_create_c = true;
                                203               0 :                 break;
  118 peter                     204 GNC           1 :             case 'i':
                                205               1 :                 system_includes = true;
                                206               1 :                 break;
                                207             128 :             case 'I':
                                208             128 :                 add_include_path(optarg);
                                209             128 :                 break;
                                210              64 :             case 'o':
                                211              64 :                 output_filename = mm_strdup(optarg);
                                212              64 :                 if (strcmp(output_filename, "-") == 0)
  118 peter                     213 UNC           0 :                     base_yyout = stdout;
                                214                 :                 else
  118 peter                     215 GNC          64 :                     base_yyout = fopen(output_filename, PG_BINARY_W);
                                216                 : 
                                217              64 :                 if (base_yyout == NULL)
                                218                 :                 {
  118 peter                     219 UNC           0 :                     fprintf(stderr, _("%s: could not open file \"%s\": %s\n"),
                                220               0 :                             progname, output_filename, strerror(errno));
                                221               0 :                     output_filename = NULL;
                                222                 :                 }
                                223                 :                 else
  118 peter                     224 GNC          64 :                     out_option = 1;
                                225              64 :                 break;
 7228 meskes                    226 GIC           3 :             case 'r':
 1377 meskes                    227 CBC           3 :                 if (pg_strcasecmp(optarg, "no_indicator") == 0)
 7228                           228               1 :                     force_indicator = false;
 1377                           229               2 :                 else if (pg_strcasecmp(optarg, "prepare") == 0)
 5717                           230               1 :                     auto_prepare = true;
 1377                           231               1 :                 else if (pg_strcasecmp(optarg, "questionmarks") == 0)
 5717                           232               1 :                     questionmarks = true;
 7228 meskes                    233 ECB             :                 else
                                234                 :                 {
 5441 peter_e                   235 LBC           0 :                     fprintf(stderr, _("Try \"%s --help\" for more information.\n"), argv[0]);
 7228 meskes                    236 UIC           0 :                     return ILLEGAL_OPTION;
                                237                 :                 }
 7228 meskes                    238 GBC           3 :                 break;
  118 peter                     239 UNC           0 :             case 't':
                                240               0 :                 autocommit = true;
 8397 bruce                     241 LBC           0 :                 break;
  118 peter                     242 UNC           0 :             case 'v':
                                243               0 :                 verbose = true;
                                244               0 :                 break;
  118 peter                     245 GNC          64 :             case ECPG_GETOPT_LONG_REGRESSION:
                                246              64 :                 regression_mode = true;
 7898 peter_e                   247 CBC          64 :                 break;
 9193 scrappy                   248 LBC           0 :             default:
 5441 peter_e                   249 UBC           0 :                 fprintf(stderr, _("Try \"%s --help\" for more information.\n"), argv[0]);
 8986 bruce                     250               0 :                 return ILLEGAL_OPTION;
 9193 scrappy                   251 EUB             :         }
                                252                 :     }
                                253                 : 
 7271 meskes                    254 GIC          64 :     add_include_path(".");
 7271 meskes                    255 CBC          64 :     add_include_path("/usr/local/include");
 6901 bruce                     256              64 :     get_include_path(my_exec_path, include_path);
                                257              64 :     add_include_path(include_path);
 7271 meskes                    258              64 :     add_include_path("/usr/include");
 7271 meskes                    259 ECB             : 
 8508 meskes                    260 GIC          64 :     if (verbose)
 8508 meskes                    261 ECB             :     {
 2427 tgl                       262 UIC           0 :         fprintf(stderr,
 2427 tgl                       263 UBC           0 :                 _("%s, the PostgreSQL embedded C preprocessor, version %s\n"),
 2427 tgl                       264 EUB             :                 progname, PG_VERSION);
 5189 peter_e                   265 UIC           0 :         fprintf(stderr, _("EXEC SQL INCLUDE ... search starts here:\n"));
 8508 meskes                    266 UBC           0 :         for (ip = include_paths; ip != NULL; ip = ip->next)
                                267               0 :             fprintf(stderr, " %s\n", ip->path);
 5441 peter_e                   268               0 :         fprintf(stderr, _("end of search list\n"));
 7898                           269               0 :         return 0;
 8508 meskes                    270 EUB             :     }
                                271                 : 
 9173 bruce                     272 GIC          64 :     if (optind >= argc)          /* no files specified */
 9151 bruce                     273 ECB             :     {
 5441 peter_e                   274 UIC           0 :         fprintf(stderr, _("%s: no input files specified\n"), progname);
 5441 peter_e                   275 UBC           0 :         fprintf(stderr, _("Try \"%s --help\" for more information.\n"), argv[0]);
 2061                           276               0 :         return ILLEGAL_OPTION;
 9151 bruce                     277 EUB             :     }
                                278                 :     else
                                279                 :     {
                                280                 :         /* after the options there must not be anything but filenames */
 9188 scrappy                   281 GIC         128 :         for (fnr = optind; fnr < argc; fnr++)
 9193 scrappy                   282 ECB             :         {
                                283                 :             char       *ptr2ext;
                                284                 : 
                                285                 :             /* If argv[fnr] is "-" we have to read from stdin */
 7257 meskes                    286 GIC          64 :             if (strcmp(argv[fnr], "-") == 0)
 7257 meskes                    287 ECB             :             {
 7188 bruce                     288 UIC           0 :                 input_filename = mm_alloc(strlen("stdin") + 1);
 7257 meskes                    289 UBC           0 :                 strcpy(input_filename, "stdin");
 2310 tgl                       290               0 :                 base_yyin = stdin;
 7257 meskes                    291 EUB             :             }
                                292                 :             else
                                293                 :             {
 7257 meskes                    294 GIC          64 :                 input_filename = mm_alloc(strlen(argv[fnr]) + 5);
 7257 meskes                    295 CBC          64 :                 strcpy(input_filename, argv[fnr]);
 9193 scrappy                   296 ECB             : 
                                297                 :                 /* take care of relative paths */
 6877 bruce                     298 GIC          64 :                 ptr2ext = last_dir_separator(input_filename);
 7257 meskes                    299 CBC          64 :                 ptr2ext = (ptr2ext ? strrchr(ptr2ext, '.') : strrchr(input_filename, '.'));
 8397 bruce                     300 ECB             : 
                                301                 :                 /* no extension? */
 7257 meskes                    302 GIC          64 :                 if (ptr2ext == NULL)
 7257 meskes                    303 ECB             :                 {
 7257 meskes                    304 UIC           0 :                     ptr2ext = input_filename + strlen(input_filename);
 7257 meskes                    305 EUB             : 
                                306                 :                     /* no extension => add .pgc or .pgh */
 7257 meskes                    307 UIC           0 :                     ptr2ext[0] = '.';
 7257 meskes                    308 UBC           0 :                     ptr2ext[1] = 'p';
                                309               0 :                     ptr2ext[2] = 'g';
 6797 bruce                     310               0 :                     ptr2ext[3] = (header_mode == true) ? 'h' : 'c';
 7257 meskes                    311               0 :                     ptr2ext[4] = '\0';
 7257 meskes                    312 EUB             :                 }
                                313                 : 
 2310 tgl                       314 GIC          64 :                 base_yyin = fopen(input_filename, PG_BINARY_R);
 9188 scrappy                   315 ECB             :             }
                                316                 : 
 7833 bruce                     317 GIC          64 :             if (out_option == 0)    /* calculate the output name */
 9189 scrappy                   318 ECB             :             {
 7257 meskes                    319 UIC           0 :                 if (strcmp(input_filename, "stdin") == 0)
 2310 tgl                       320 UBC           0 :                     base_yyout = stdout;
 7257 meskes                    321 EUB             :                 else
                                322                 :                 {
 2299 meskes                    323 UIC           0 :                     output_filename = mm_alloc(strlen(input_filename) + 3);
 2299 meskes                    324 UBC           0 :                     strcpy(output_filename, input_filename);
 8986 bruce                     325 EUB             : 
 7257 meskes                    326 UIC           0 :                     ptr2ext = strrchr(output_filename, '.');
 7011 meskes                    327 EUB             :                     /* make extension = .c resp. .h */
 6797 bruce                     328 UIC           0 :                     ptr2ext[1] = (header_mode == true) ? 'h' : 'c';
 7257 meskes                    329 UBC           0 :                     ptr2ext[2] = '\0';
 8986 bruce                     330 EUB             : 
 2310 tgl                       331 UIC           0 :                     base_yyout = fopen(output_filename, PG_BINARY_W);
 2310 tgl                       332 UBC           0 :                     if (base_yyout == NULL)
 7257 meskes                    333 EUB             :                     {
 5441 peter_e                   334 UIC           0 :                         fprintf(stderr, _("%s: could not open file \"%s\": %s\n"),
 6725 peter_e                   335 UBC           0 :                                 progname, output_filename, strerror(errno));
 7257 meskes                    336               0 :                         free(output_filename);
 1852                           337               0 :                         output_filename = NULL;
 7257                           338               0 :                         free(input_filename);
                                339               0 :                         continue;
 7257 meskes                    340 EUB             :                     }
                                341                 :                 }
                                342                 :             }
                                343                 : 
 2310 tgl                       344 GIC          64 :             if (base_yyin == NULL)
 5441 peter_e                   345 LBC           0 :                 fprintf(stderr, _("%s: could not open file \"%s\": %s\n"),
 6725 peter_e                   346 UBC           0 :                         progname, argv[fnr], strerror(errno));
 9188 scrappy                   347 EUB             :             else
                                348                 :             {
                                349                 :                 struct cursor *ptr;
                                350                 :                 struct _defines *defptr;
                                351                 :                 struct typedefs *typeptr;
                                352                 :                 struct declared_list *list;
                                353                 : 
                                354                 :                 /* remove old cursor definitions if any are still there */
 1297 tgl                       355 GIC          64 :                 for (ptr = cur; ptr != NULL;)
 9007 bruce                     356 ECB             :                 {
 1297 tgl                       357 UIC           0 :                     struct cursor *this = ptr;
 1297 tgl                       358 EUB             :                     struct arguments *l1,
                                359                 :                                *l2;
                                360                 : 
 1297 tgl                       361 UIC           0 :                     free(ptr->command);
 1297 tgl                       362 UBC           0 :                     free(ptr->connection);
                                363               0 :                     free(ptr->name);
                                364               0 :                     for (l1 = ptr->argsinsert; l1; l1 = l2)
 1297 tgl                       365 EUB             :                     {
 1297 tgl                       366 UIC           0 :                         l2 = l1->next;
 1297 tgl                       367 UBC           0 :                         free(l1);
 1297 tgl                       368 EUB             :                     }
 1297 tgl                       369 UIC           0 :                     for (l1 = ptr->argsresult; l1; l1 = l2)
 1297 tgl                       370 EUB             :                     {
 1297 tgl                       371 UIC           0 :                         l2 = l1->next;
 1297 tgl                       372 UBC           0 :                         free(l1);
 1297 tgl                       373 EUB             :                     }
 1297 tgl                       374 UIC           0 :                     ptr = ptr->next;
 1297 tgl                       375 UBC           0 :                     free(this);
 9007 bruce                     376 EUB             :                 }
 1297 tgl                       377 GIC          64 :                 cur = NULL;
 8986 bruce                     378 ECB             : 
                                379                 :                 /* remove old declared statements if any are still there */
  746 meskes                    380 GIC          64 :                 for (list = g_declared_list; list != NULL;)
  746 meskes                    381 ECB             :                 {
  746 meskes                    382 UIC           0 :                     struct declared_list *this = list;
  697 tgl                       383 EUB             : 
  746 meskes                    384 UIC           0 :                     list = list->next;
  746 meskes                    385 UBC           0 :                     free(this);
  746 meskes                    386 EUB             :                 }
                                387                 : 
                                388                 :                 /* remove non-pertinent old defines as well */
 8397 bruce                     389 GIC          64 :                 while (defines && !defines->pertinent)
 8397 bruce                     390 ECB             :                 {
 8397 bruce                     391 UIC           0 :                     defptr = defines;
 8397 bruce                     392 UBC           0 :                     defines = defines->next;
 8482 meskes                    393 EUB             : 
 1409 tgl                       394 UIC           0 :                     free(defptr->newdef);
 1409 tgl                       395 UBC           0 :                     free(defptr->olddef);
 8397 bruce                     396               0 :                     free(defptr);
 8482 meskes                    397 EUB             :                 }
                                398                 : 
 8397 bruce                     399 GIC          64 :                 for (defptr = defines; defptr != NULL; defptr = defptr->next)
 8993 scrappy                   400 ECB             :                 {
 8397 bruce                     401 UIC           0 :                     struct _defines *this = defptr->next;
 8986 bruce                     402 EUB             : 
 8397 bruce                     403 UIC           0 :                     if (this && !this->pertinent)
 8397 bruce                     404 EUB             :                     {
 8397 bruce                     405 UIC           0 :                         defptr->next = this->next;
 8397 bruce                     406 EUB             : 
 1409 tgl                       407 UIC           0 :                         free(this->newdef);
 1409 tgl                       408 UBC           0 :                         free(this->olddef);
 8397 bruce                     409               0 :                         free(this);
 8397 bruce                     410 EUB             :                     }
                                411                 :                 }
                                412                 : 
                                413                 :                 /* and old typedefs */
 8814 scrappy                   414 GIC          64 :                 for (typeptr = types; typeptr != NULL;)
 8814 scrappy                   415 ECB             :                 {
 8814 scrappy                   416 UIC           0 :                     struct typedefs *this = typeptr;
 8986 bruce                     417 EUB             : 
 8814 scrappy                   418 UIC           0 :                     free(typeptr->name);
 8814 scrappy                   419 UBC           0 :                     ECPGfree_struct_member(typeptr->struct_member_list);
 8482 meskes                    420               0 :                     free(typeptr->type);
 8814 scrappy                   421               0 :                     typeptr = typeptr->next;
                                422               0 :                     free(this);
 8814 scrappy                   423 EUB             :                 }
 8482 meskes                    424 GIC          64 :                 types = NULL;
 8397 bruce                     425 ECB             : 
                                426                 :                 /* initialize whenever structures */
 8482 meskes                    427 GIC          64 :                 memset(&when_error, 0, sizeof(struct when));
 8482 meskes                    428 CBC          64 :                 memset(&when_nf, 0, sizeof(struct when));
                                429              64 :                 memset(&when_warn, 0, sizeof(struct when));
 8397 bruce                     430 ECB             : 
                                431                 :                 /* and structure member lists */
 8482 meskes                    432 GIC          64 :                 memset(struct_member_list, 0, sizeof(struct_member_list));
 8397 bruce                     433 ECB             : 
                                434                 :                 /*
                                435                 :                  * and our variable counter for out of scope cursors'
                                436                 :                  * variables
                                437                 :                  */
 4821 meskes                    438 GIC          64 :                 ecpg_internal_var = 0;
 7240 meskes                    439 ECB             : 
                                440                 :                 /* finally the actual connection */
 8452 meskes                    441 GIC          64 :                 connection = NULL;
 7188 bruce                     442 ECB             : 
                                443                 :                 /* initialize lex */
 9188 scrappy                   444 GIC          64 :                 lex_init();
 8986 bruce                     445 ECB             : 
                                446                 :                 /* we need several includes */
                                447                 :                 /* but not if we are in header mode */
 5624 bruce                     448 GIC          64 :                 if (regression_mode)
 2310 tgl                       449 CBC          64 :                     fprintf(base_yyout, "/* Processed by ecpg (regression mode) */\n");
 5932 meskes                    450 ECB             :                 else
 2310 tgl                       451 UIC           0 :                     fprintf(base_yyout, "/* Processed by ecpg (%s) */\n", PG_VERSION);
 6797 bruce                     452 EUB             : 
 7011 meskes                    453 GIC          64 :                 if (header_mode == false)
 7011 meskes                    454 ECB             :                 {
 2310 tgl                       455 GIC          64 :                     fprintf(base_yyout, "/* These include files are added by the preprocessor */\n#include <ecpglib.h>\n#include <ecpgerrno.h>\n#include <sqlca.h>\n");
 9193 scrappy                   456 ECB             : 
                                457                 :                     /* add some compatibility headers */
 7011 meskes                    458 GIC          64 :                     if (INFORMIX_MODE)
 2310 tgl                       459 CBC           9 :                         fprintf(base_yyout, "/* Needed for informix compatibility */\n#include <ecpg_informix.h>\n");
 7188 bruce                     460 ECB             : 
 2310 tgl                       461 GIC          64 :                     fprintf(base_yyout, "/* End of automatic include section */\n");
 7011 meskes                    462 ECB             :                 }
                                463                 : 
 5624 bruce                     464 GIC          64 :                 if (regression_mode)
 2310 tgl                       465 CBC          64 :                     fprintf(base_yyout, "#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))\n");
 5931 meskes                    466 ECB             : 
 6269 meskes                    467 GIC          64 :                 output_line_number();
 6797 bruce                     468 ECB             : 
                                469                 :                 /* and parse the source */
 5867 meskes                    470 GIC          64 :                 base_yyparse();
 9193 scrappy                   471 ECB             : 
                                472                 :                 /*
                                473                 :                  * Check whether all cursors were indeed opened.  It does not
                                474                 :                  * really make sense to declare a cursor but not open it.
                                475                 :                  */
 5189 peter_e                   476 GIC         100 :                 for (ptr = cur; ptr != NULL; ptr = ptr->next)
 7011 meskes                    477 CBC          36 :                     if (!(ptr->opened))
 5189 peter_e                   478 LBC           0 :                         mmerror(PARSE_ERROR, ET_WARNING, "cursor \"%s\" has been declared but not opened", ptr->name);
 6797 bruce                     479 EUB             : 
 2310 tgl                       480 GIC          64 :                 if (base_yyin != NULL && base_yyin != stdin)
 2310 tgl                       481 CBC          64 :                     fclose(base_yyin);
                                482              64 :                 if (out_option == 0 && base_yyout != stdout)
 2310 tgl                       483 LBC           0 :                     fclose(base_yyout);
 4660 bruce                     484 EUB             : 
                                485                 :                 /*
                                486                 :                  * If there was an error, delete the output file.
                                487                 :                  */
 4754 meskes                    488 GIC          64 :                 if (ret_value != 0)
 4754 meskes                    489 ECB             :                 {
 4754 meskes                    490 UIC           0 :                     if (strcmp(output_filename, "-") != 0 && unlink(output_filename) != 0)
 4754 meskes                    491 UBC           0 :                         fprintf(stderr, _("could not remove output file \"%s\"\n"), output_filename);
 4754 meskes                    492 EUB             :                 }
                                493                 :             }
                                494                 : 
 1809 tgl                       495 GIC          64 :             if (output_filename && out_option == 0)
 1809 tgl                       496 ECB             :             {
 9119 scrappy                   497 UIC           0 :                 free(output_filename);
 1852 meskes                    498 UBC           0 :                 output_filename = NULL;
 1852 meskes                    499 EUB             :             }
                                500                 : 
 9151 bruce                     501 GIC          64 :             free(input_filename);
 9188 scrappy                   502 ECB             :         }
                                503                 :     }
 8523 meskes                    504 GIC          64 :     return ret_value;
 9194 scrappy                   505 ECB             : }
        

Generated by: LCOV version v1.16-55-g56c0a2a