]> granicus.if.org Git - postgresql/commitdiff
From: Michael Meskes <meskes@topsystem.de>
authorMarc G. Fournier <scrappy@hub.org>
Wed, 11 Feb 1998 15:30:00 +0000 (15:30 +0000)
committerMarc G. Fournier <scrappy@hub.org>
Wed, 11 Feb 1998 15:30:00 +0000 (15:30 +0000)
Cleanups for ecpg, as well as a missing patch so that its configured in

src/interfaces/ecpg/include/Makefile.in
src/interfaces/ecpg/lib/Makefile.in
src/interfaces/ecpg/preproc/Makefile.in
src/interfaces/ecpg/preproc/ecpg.c
src/interfaces/ecpg/preproc/preproc.y
src/interfaces/ecpg/test/Makefile
src/interfaces/ecpg/test/test2.pgc

index 2f5c63ab07822d15b810d416c667c59885e6ba7c..d36757111d3b3b8d7899007a99c98a954b943a9f 100644 (file)
@@ -5,11 +5,11 @@ all clean::
        @echo Nothing to be done.
 
 install::
-       install ecpglib.h $(HEADERDIR)  
-       install ecpgtype.h $(HEADERDIR) 
-       install sqlca.h $(HEADERDIR)    
+       install ecpglib.h $(DESTDIR)$(HEADERDIR)        
+       install ecpgtype.h $(DESTDIR)$(HEADERDIR)       
+       install sqlca.h $(DESTDIR)$(HEADERDIR)  
 
 uninstall::
-       rm -f $(HEADERDIR)/ecpglib.h
-       rm -f $(HEADERDIR)/ecpgtype.h
-       rm -f $(HEADERDIR)/sqlca.h
+       rm -f $(DESTDIR)$(HEADERDIR)/ecpglib.h
+       rm -f $(DESTDIR)$(HEADERDIR)/ecpgtype.h
+       rm -f $(DESTDIR)$(HEADERDIR)/sqlca.h
index 7ed351ab7a9b2ba601267475c49fdb19f43be15a..49f6bdff2b089804fe15402a38ca8d3584491bc3 100644 (file)
@@ -3,18 +3,57 @@ include $(SRCDIR)/Makefile.global
 
 PQ_INCLUDE=-I$(SRCDIR)/include -I$(SRCDIR)/interfaces/libpq
 
-all: lib
+SO_MAJOR_VERSION=0
+SO_MINOR_VERSION=5
 
-lib: libecpg.a
+PORTNAME=@PORTNAME@
+
+# Shared library stuff
+shlib := 
+install-shlib-dep :=
+ifeq ($(PORTNAME), linux)
+  ifdef LINUX_ELF
+    install-shlib-dep := install-shlib
+    shlib := libecpg.so.$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
+    LDFLAGS_SL = -shared
+    CFLAGS += $(CFLAGS_SL)
+  endif
+endif
+ifeq ($(PORTNAME), bsd)
+  install-shlib-dep := install-shlib
+  shlib := libecpg.so.$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
+  LDFLAGS_SL = -x -Bshareable -Bforcearchive
+  CFLAGS += $(CFLAGS_SL)
+endif
+ifeq ($(PORTNAME), i386_solaris)
+  install-shlib-dep := install-shlib
+  shlib := libecpg.so.$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
+  LDFLAGS_SL = -G -z text
+  CFLAGS += $(CFLAGS_SL)
+endif
+ifeq ($(PORTNAME), univel)
+  install-shlib-dep := install-shlib
+  shlib := libecpg.so.1
+  LDFLAGS_SL = -G -z text
+  CFLAGS += $(CFLAGS_SL)
+endif
+
+all: libecpg.a $(shlib)
+
+$(shlib): ecpglib.o typename.o
+       $(LD) $(LDFLAGS_SL) -o $@ ecpglib.o typename.o 
+       ln -sf $@ libecpg.so
 
 clean:
-       rm -f *.o *.a core a.out *~
+       rm -f *.o *.a core a.out *~ $(shlib) libecpg.so
 
 install: libecpg.a
-       install -m 644 libecpg.a $(LIBDIR)
+       install -m 644 libecpg.a $(DESTDIR)$(LIBDIR)
+       install -m 644 $(shlib) $(DESTDIR)$(LIBDIR)
+       ln -sf $(shlib) $(DESTDIR)$(LIBDIR)/libecpg.so
 
 uninstall::
-       rm -f $(LIBDIR)/libecpg.a
+       rm -f $(DESTDIR)$(LIBDIR)/libecpg.a $(DESTDIR)$(LIBDIR)/$(shlib)
 
 # Rules that do something
 libecpg.a : libecpg.a(ecpglib.o) libecpg.a(typename.o)
index f3cb049e8c38e4cf784935df8f8312f8345b5664..8fbc4523e79d53f30a095fe487abd16abf7f5780 100644 (file)
@@ -1,13 +1,17 @@
 SRCDIR= ../../..
 include $(SRCDIR)/Makefile.global
 
+MAJOR_VERSION=0
+MINOR_VERSION=5
+PATCHLEVEL=1
+
 CC=@CC@
 LEX=@LEX@
 LEXLIB=@LEXLIB@
 YACC=@YACC@
 YFLAGS=@YFLAGS@
 
-CFLAGS=-I../include -O2 -g -Wall
+CFLAGS=-I../include -O2 -g -Wall -DMAJOR_VERSION=$(MAJOR_VERSION) -DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL)
 
 all:: ecpg
 
@@ -15,14 +19,14 @@ clean:
        rm -f *.o core a.out ecpg preproc.tab.h y.tab.c *~
 
 install: all
-       install -c -m 755 ecpg $(BINDIR)
+       install -c -m 755 ecpg $(DESTDIR)$(BINDIR)
 
 uninstall:
-       rm -f $(BINDIR)/ecpg
+       rm -f $(DESTDIR)$(BINDIR)/ecpg
 
 # Rule that really do something.
-ecpg: y.tab.o pgc.o type.o ecpg.o
-       $(CC) -g -O2 -Wall -o ecpg y.tab.o pgc.o type.o ecpg.o -L../lib -lecpg $(LEXLIB)
+ecpg: y.tab.o pgc.o type.o ecpg.o ../lib/typename.o
+       $(CC) -g -O2 -Wall -o ecpg y.tab.o pgc.o type.o ecpg.o ../lib/typename.o $(LEXLIB)
 
 y.tab.h y.tab.c: preproc.y
        $(YACC) $(YFLAGS) $<
index 08f4a3952505eb6ad8b90cc412badbb836e1c5e4..e4a1a78812af11b8b20aaf3f7ea985dcae8c1ff6 100644 (file)
@@ -7,25 +7,22 @@
 #include <stdlib.h>
 #include <strings.h>
 
-extern void lex_init(void);
-extern FILE *yyin, *yyout;
-extern char * input_filename;
-extern int yyparse(void);
+#include "extern.h"
 
 static void
 usage(char *progname)
 {
-       fprintf(stderr, "Usage: %s: [ -o outout file name] file1 [file2] ...\n", progname);
+       fprintf(stderr, "ecpg - the postgresql preprocessor, version: %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
+       fprintf(stderr, "Usage: %s: [-v] [-d] [ -o outout file name] file1 [file2] ...\n", progname);
 }
 
 int
 main(int argc, char *const argv[])
 {
-       char            c,
-                               out_option = 0;
+       char                    c, out_option = 0;
        int                     fnr;
 
-       while ((c = getopt(argc, argv, "o:")) != EOF)
+       while ((c = getopt(argc, argv, "vdo:")) != EOF)
        {
                switch (c)
                {
@@ -36,71 +33,77 @@ main(int argc, char *const argv[])
                                else
                                        out_option = 1;
                                break;
+                       case 'd':
+                               debugging = 1;
+                               break;
+                       case 'v':
                        default:
                                usage(argv[0]);
                }
        }
 
-       /* after the options there must not be anything but filenames */
-       for (fnr = optind; fnr < argc; fnr++)
+       if (optind >= argc) /* no files specified */
+               usage(argv[0]);
+       else
        {
-               char       *filename,
-                                  *ptr2ext;
-
-               filename = malloc(strlen(argv[fnr]) + 2);
-               if (filename == NULL)
+               /* after the options there must not be anything but filenames */
+               for (fnr = optind; fnr < argc; fnr++)
                {
-                       perror("malloc");
-                       continue;
-               }
+                       char       *filename, *ptr2ext;
 
-               strcpy(filename, argv[fnr]);
+                       filename = malloc(strlen(argv[fnr]) + 2);
+                       if (filename == NULL)
+                       {
+                               perror("malloc");
+                               continue;
+                       }
 
-               ptr2ext = strrchr(filename, '.');
-               /* no extension or extension not equal .pgc */
-               if (ptr2ext == NULL || strcmp(ptr2ext, ".pgc") != 0)
-               {
-                       ptr2ext = filename + strlen(filename);
-                       ptr2ext[0] = '.';
-               }
+                       strcpy(filename, argv[fnr]);
 
-               /* make extension = .c */
-               ptr2ext[1] = 'c';
-               ptr2ext[2] = '\0';
+                       ptr2ext = strrchr(filename, '.');
+                       /* no extension or extension not equal .pgc */
+                       if (ptr2ext == NULL || strcmp(ptr2ext, ".pgc") != 0)
+                       { 
+                               ptr2ext = filename + strlen(filename);
+                               ptr2ext[0] = '.';
+                       }
 
-               if (out_option == 0)    /* calculate the output name */
-               {
-                       yyout = fopen(filename, "w");
-                       if (yyout == NULL)
+                       /* make extension = .c */
+                       ptr2ext[1] = 'c';
+                       ptr2ext[2] = '\0';
+
+                       if (out_option == 0)    /* calculate the output name */
                        {
-                               perror(filename);
-                               free(filename);
-                               continue;
+                               yyout = fopen(filename, "w");
+                               if (yyout == NULL)
+                               {
+                                       perror(filename);
+                                       free(filename);
+                                       continue;
+                               }
                        }
-               }
 
-               yyin = fopen(input_filename = argv[fnr], "r");
-               if (yyin == NULL)
-               {
-                       perror(argv[fnr]);
-               }
-               else
-               {
-                       /* initialize lex */
-                       lex_init();
+                       yyin = fopen(input_filename = argv[fnr], "r");
+                       if (yyin == NULL)
+                               perror(argv[fnr]);
+                       else
+                       {
+                               /* initialize lex */
+                               lex_init();
 
-                       /* we need two includes everytime */
-                       fprintf(yyout, "/* These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n");
+                               /* we need two includes */
+                               fprintf(yyout, "/* Processed by ecpg (%d.%d.%d) */\n/*These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
 
-                       /* and parse the source */
-                       yyparse();
+                               /* and parse the source */
+                               yyparse();
 
-                       fclose(yyin);
-                       if (out_option == 0)
-                               fclose(yyout);
-               }
+                               fclose(yyin);
+                               if (out_option == 0)
+                                       fclose(yyout);
+                       }
 
-               free(filename);
+                       free(filename);
+               }
        }
        return (0);
 }
index b5a30c0d196b4cf929dd802adc60eedd545c0e27..4d4ba6279f9758563c5c39b08af87b08a0464f1e 100644 (file)
@@ -3,13 +3,11 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+
 #include "type.h"
+#include "extern.h"
 
-void yyerror(char *);
-extern FILE * yyout;
-extern char * yytext;
-extern int yylineno;
-extern int yyleng;
+static void yyerror(char *);
 
 /*
  * Variables containing simple states.
@@ -65,7 +63,7 @@ find_variable(char * name)
     {
        char * errorstring = (char *) malloc(strlen(name) + 100);
 
-       sprintf(errorstring, "The variabel :%s is not declared.", name);
+       sprintf(errorstring, "The variable :%s is not declared.", name);
 
        yyerror(errorstring);
     }
@@ -87,7 +85,7 @@ new_variable(const char * name, struct ECPGtype * type)
 
 
 /*
- * Here is the variables that need to be handled on every request.
+ * Here are the variables that need to be handled on every request.
  * These are of two kinds: input and output.
  * I will make two lists for them.
  */
@@ -359,7 +357,7 @@ both_anything : S_LENGTH | S_VARCHAR | S_VARCHAR2
          | S_ANYTHING;
 
 %%
-void yyerror(char * error)
+static void yyerror(char * error)
 {
     fprintf(stderr, "%s\n", error);
     exit(1);
index 0ec008964e51ad0c62c83823b2bc8135c99279b3..c72518540bddeb14a8c8d53f4d9a1eed9a740532 100644 (file)
@@ -1,14 +1,14 @@
 all: test2 perftest
 
 test2: test2.c
-       gcc -g -I ../include -I ../../../libpq -o test2 test2.c ../lib/libecpg.a ../../../libpq/libpq.a -lcrypt
+       gcc -g -I ../include -I ../../libpq -o test2 test2.c -L../lib -lecpg -L../../libpq -lpq -lcrypt
 test2.c: test2.pgc
-       ../preproc/ecpg test2.pgc
+       ecpg test2.pgc
 
 perftest: perftest.c
-       gcc -g -I ../include -I ../../../libpq -o perftest perftest.c ../lib/libecpg.a ../../../libpq/libpq.a -lcrypt
+       gcc -g -I ../include -I ../../libpq -o perftest perftest.c -L../lib -lecpg -L../../libpq -lpq -lcrypt
 perftest.c: perftest.pgc
-       ../preproc/ecpg perftest.pgc
+       ecpg perftest.pgc
 
 clean:
-       /bin/rm test2 test2.c perftest perftest.c
+       /bin/rm test2 test2.c perftest perftest.c log
index 5e944950876ffcbdefd21457c2d6b186dbb66ec6..923c9d0c380ed0cadfb151f6d96cfd9aca64e109 100644 (file)
@@ -1,7 +1,11 @@
+#include <stdio.h>
+
 exec sql include sqlca;
 
 #define       SQLCODE    sqlca.sqlcode
 
+extern void ECPGdebug(int n, FILE *dbgs);
+
 void
 db_error (char *msg)
 {
@@ -14,17 +18,20 @@ int
 main ()
 {
 exec sql begin declare section;
-       varchar text[8];
-       int count;
-       double control;
+       varchar name[8];
+       long born;
 exec sql end declare section;
+       FILE *dbgs;
+
+       if ((dbgs = fopen("log", "w")) != NULL)
+               ECPGdebug(1, dbgs);
 
        exec sql connect 'mm';
        if (SQLCODE)
                db_error ("connect");
 
        exec sql declare cur cursor for 
-               select text, control, count from test;
+               select name, born from meskes;
        if (SQLCODE) db_error ("declare");
 
        exec sql open cur;
@@ -32,10 +39,10 @@ exec sql end declare section;
                db_error ("open");
 
        while (1) {
-               exec sql fetch in cur into :text, :control, :count;
+               exec sql fetch in cur into :name, :born;
                if (SQLCODE)
                        break;
-               printf ("%8.8s %d %f\n", text.arr, count, control);
+               printf ("%8.8s was born %d\n", name.arr, born);
        }
 
        if (SQLCODE < 0)
@@ -46,5 +53,8 @@ exec sql end declare section;
        exec sql commit;
        if (SQLCODE) db_error ("commit");
 
+       if (dbgs != NULL)
+               fclose(dbgs);
+
        return (0);
 }