[comp.databases] Convert Database: Ingres 5.0 -> Sybase 4.0

jng@jax.org (John Guidi) (03/16/91)

								March 15, 1991

	ing5tosyb4 - Convert Database from Ingres 5.0 to Sybase 4.0
	===========================================================

    The program in this directory, ing5tosyb4, is useful in helping to automate
the process of moving databases from the Ingres environment to the Sybase
environment. The program is minimalist - it makes no attempt to be complete,
and error checking is practically non-existant. Many assumptions are made,
and some issues, for example NULLS, are simply ignored. The framework is from
a grammar used to parse bibliographic references, and there are definitely some
skeletons left behind. In spite of these facts, the program was useful in
assisting us to port a number of databases. 
    The program is offered in the spirit that someone else may find it useful,
or will improve it, or better yet, someone else has done a proper job and
is willing to make it available. This program does not deal with the important
issue of converting Ingres applications to Sybase. I would be very interested
to hear from people who have experiences in converting databases and/or
programs between these two environments, in either direction.

Contents:
	README
	Makefile
	ing5tosyb4_lex.l
	ing5tosyb4_gram.y

Environment:
	System - Sun-4/280S  SunOS V4.1.1
	Relation Technology INGRES SunOS Release 5.0/05a (su4.u42/02)
	SYBASE 4.0.1/P/Sun4/os4.x/2

Instructions:
	1) Build the distribution. Hopefully, as simple as:
		   % make

	2) Move to a clean directory with plenty of space.
		   % mkdir rrr
		   % cd rrr

	3) Have Ingres create a command script for the database {dbname}.
      	   This script consists of instructions that Ingres uses to restore
	   the database. The -c flag is necessary to create a portable
           (ie ASCII rather than binary) format for data files in a later step.
		   % copydb -c {dbname} 
	   This step produces two files: 
	   copy.out - ignore, we do not care about this.
           copy.in  - script of Ingres restore instructions.

	4) Use the script of Ingres restore instructions as input to
	   ing5tosyb4. For any tables described in the copy.in script from
	   above which are referred to in the create statments as:
	   {locationname}:{tablename}, appropriate entries are made in the
	   following files. Statments with this syntax exclude Ingres system
	   tables,which we are not interested in. Examine the scripts produced
	   and modify to your liking. For example, the program does not catch
	   usage of reserved SQL words. Defaults and NULLS can be added. Etc.
	           % ing5tosyb4 <copy.in
	   ingres.copy.out - Ingres script to copy database tables onto 
			     file system files.
	   sybase.create   - Sybase command script which creates tables.
	   sybase.index    - Sybase command script which attempts to mimic
			     Ingres choices for indicies.
	   bcp.fmt.{tablename} - For each {tablename}, Sybase bulkcopy format.
		   
	5) Create Sybase database, and within Sybase, execute system procedure
	   to set default database to this. For example:
		   sp_defaultdb {loginname},{dbname}

	6) Create the Sybase definitions.
		   % isql -U {user} -P {password} <sybase.create

	7) Copy the Ingres database tables on the file system.
		   % quel {dbname} <ingres.copy.out
	   db.{tablebname} - file system file with contents of Ingres database
		             table {tablename}.

	8) Perform select into/bulkcopy magic.

	9) Run Sybase bcp command for each of the files created in step 7.
	   For example, the following csh script:
		   #
		   cp /dev/null SUMMARY
		   foreach i (bcp.fmt.*)
		       echo -------- $i ------------ >>SUMMARY
		       bcp $i:e in db.$i:e -f bcp.fmt.$i:e  \
		           -U {user} -P {password} >>& SUMMARY
		   end

	10) Take a very good look at your data and begin to tweak and modify
	    things as necessary. When you are really confident that you
            have things under control, you may want to consider cleaning 
	    up the mess left behind.



John Guidi
The Jackson Laboratory
600 Maine Street
Bar Harbor, ME 04609-0800
USA
Internet: jng@aretha.jax.org
Phone:   (207)288-3371 X-1391


#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  Makefile README ing5tosyb4_gram.y ing5tosyb4_lex.l
# Wrapped by jng@gandalf on Fri Mar 15 16:37:03 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(607 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X#  Author     - John Guidi
X#               The Jackson Laboratory
X#               600 Main Street
X#               Bar Harbor, ME  04609-0800
X#               USA
X#               Phone: (207)288-3371 X-1391
X#               Internet: jng@jax.org
X#  Date       - October 10, 1990
X#  Residence  - Makefile
X#  Hardware   - SPARCstation 1 
X#  System     - SunOS V4.1
X#  Abstract   - Makefile for ing5tosyb4.
X#
X
XCFLAGS = -g
X
X.y.o:
X	$(YACC) -d $<
X	$(YACC.y) $<
X	$(COMPILE.c) -o $@ y.tab.c
X	$(RM) y.tab.c
X
X
Xing5tosyb4:	ing5tosyb4_gram.o ing5tosyb4_lex.o
X		cc -g -o ing5tosyb4 ing5tosyb4_gram.o ing5tosyb4_lex.o -ll
X
X
END_OF_FILE
if test 607 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(4121 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X								March 15, 1991
X
X	ing5tosyb4 - Convert Database from Ingres 5.0 to Sybase 4.0
X	===========================================================
X
X    The program in this directory, ing5tosyb4, is useful in helping to automate
Xthe process of moving databases from the Ingres environment to the Sybase
Xenvironment. The program is minimalist - it makes no attempt to be complete,
Xand error checking is practically non-existant. Many assumptions are made,
Xand some issues, for example NULLS, are simply ignored. The framework is from
Xa grammar used to parse bibliographic references, and there are definitely some
Xskeletons left behind. In spite of these facts, the program was useful in
Xassisting us to port a number of databases. 
X    The program is offered in the spirit that someone else may find it useful,
Xor will improve it, or better yet, someone else has done a proper job and
Xis willing to make it available. This program does not deal with the important
Xissue of converting Ingres applications to Sybase. I would be very interested
Xto hear from people who have experiences in converting databases and/or
Xprograms between these two environments, in either direction.
X
XContents:
X	README
X	Makefile
X	ing5tosyb4_lex.l
X	ing5tosyb4_gram.y
X
XEnvironment:
X	System - Sun-4/280S  SunOS V4.1.1
X	Relation Technology INGRES SunOS Release 5.0/05a (su4.u42/02)
X	SYBASE 4.0.1/P/Sun4/os4.x/2
X
XInstructions:
X	1) Build the distribution. Hopefully, as simple as:
X		   % make
X
X	2) Move to a clean directory with plenty of space.
X		   % mkdir rrr
X		   % cd rrr
X
X	3) Have Ingres create a command script for the database {dbname}.
X      	   This script consists of instructions that Ingres uses to restore
X	   the database. The -c flag is necessary to create a portable
X           (ie ASCII rather than binary) format for data files in a later step.
X		   % copydb -c {dbname} 
X	   This step produces two files: 
X	   copy.out - ignore, we do not care about this.
X           copy.in  - script of Ingres restore instructions.
X
X	4) Use the script of Ingres restore instructions as input to
X	   ing5tosyb4. For any tables described in the copy.in script from
X	   above which are referred to in the create statments as:
X	   {locationname}:{tablename}, appropriate entries are made in the
X	   following files. Statments with this syntax exclude Ingres system
X	   tables,which we are not interested in. Examine the scripts produced
X	   and modify to your liking. For example, the program does not catch
X	   usage of reserved SQL words. Defaults and NULLS can be added. Etc.
X	           % ing5tosyb4 <copy.in
X	   ingres.copy.out - Ingres script to copy database tables onto 
X			     file system files.
X	   sybase.create   - Sybase command script which creates tables.
X	   sybase.index    - Sybase command script which attempts to mimic
X			     Ingres choices for indicies.
X	   bcp.fmt.{tablename} - For each {tablename}, Sybase bulkcopy format.
X		   
X	5) Create Sybase database, and within Sybase, execute system procedure
X	   to set default database to this. For example:
X		   sp_defaultdb {loginname},{dbname}
X
X	6) Create the Sybase definitions.
X		   % isql -U {user} -P {password} <sybase.create
X
X	7) Copy the Ingres database tables on the file system.
X		   % quel {dbname} <ingres.copy.out
X	   db.{tablebname} - file system file with contents of Ingres database
X		             table {tablename}.
X
X	8) Perform select into/bulkcopy magic.
X
X	9) Run Sybase bcp command for each of the files created in step 7.
X	   For example, the following csh script:
X		   #
X		   cp /dev/null SUMMARY
X		   foreach i (bcp.fmt.*)
X		       echo -------- $i ------------ >>SUMMARY
X		       bcp $i:e in db.$i:e -f bcp.fmt.$i:e  \
X		           -U {user} -P {password} >>& SUMMARY
X		   end
X
X	10) Take a very good look at your data and begin to tweak and modify
X	    things as necessary. When you are really confident that you
X            have things under control, you may want to consider cleaning 
X	    up the mess left behind.
X
X
X
XJohn Guidi
XThe Jackson Laboratory
X600 Maine Street
XBar Harbor, ME 04609
XUSA
XInternet: jng@aretha.jax.org
XPhone:   (207)288-3371 X-1391
X
X
END_OF_FILE
if test 4121 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'ing5tosyb4_gram.y' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ing5tosyb4_gram.y'\"
else
echo shar: Extracting \"'ing5tosyb4_gram.y'\" \(16407 characters\)
sed "s/^X//" >'ing5tosyb4_gram.y' <<'END_OF_FILE'
X/*
X * Author    	- John Guidi
X *                The Jackson Laboratory
X *                600 Main Street
X *                Bar Harbor, ME  04609-0800
X *                USA
X *                Phone: (207)288-3371 X-1391
X *                Internet: jng@aretha.jax.org
X * Date		- March 4, 1991
X * Residence	- ing5tosyb4_gram.y
X * Language	- yacc
X * Hardware	- Sun-4/280S
X * System	- SunOS V4.1.1
X * Abstract	- Grammar for Relational Technology INGRES V5.0
X *		  copydb output command script. No error checking is done. It 
X *                is assumed that the INGRES commands created by the copydb
X *                command are correct.
X*/
X
X
X%{
X#include <stdio.h>
X#include <strings.h>
X#include <sys/param.h>
X
X#define MAXFIELDS	200	/* Maximum number of fields for a table. */
X#define DELIMFIELD	"|"	/* Field delimiter w/ ASCII files. */
X
X#define MEGA_SIZE  1000
X#define MINI_SIZE  100
X#define MICRO_SIZE 20
X
Xstatic char ing_i1_str[MICRO_SIZE];
Xstatic char ing_i2_str[MICRO_SIZE];
Xstatic char ing_i4_str[MICRO_SIZE];
Xstatic char ing_f4_str[MICRO_SIZE];
Xstatic char ing_f8_str[MICRO_SIZE];
Xstatic char ing_c_str[MICRO_SIZE];
Xstatic char ing_text_str[MICRO_SIZE];
Xstatic char ing_date_str[MICRO_SIZE];
Xstatic char ing_money_str[MICRO_SIZE];
X
Xstatic char alphanumeric_str[MEGA_SIZE];
Xstatic char integer_str[MEGA_SIZE];
X
Xstatic char comma_str[MINI_SIZE];
Xstatic char colon_str[MINI_SIZE];
Xstatic char equal_str[MINI_SIZE];
Xstatic char openparen_str[MINI_SIZE];
Xstatic char closeparen_str[MINI_SIZE];
X
Xstatic char quel_create_str[MINI_SIZE];
Xstatic char quel_modify_str[MINI_SIZE];
Xstatic char quel_index_str[MINI_SIZE];
X
Xstatic char is_str[MICRO_SIZE];
Xstatic char on_str[MICRO_SIZE];
Xstatic char to_str[MICRO_SIZE];
Xstatic char unique_str[MICRO_SIZE];
X
Xstatic char locationname_str[MINI_SIZE];
Xstatic char tablename_str[MINI_SIZE];
Xstatic char indexname_str[MINI_SIZE];
Xstatic char storagestructure_str[MINI_SIZE];
Xstatic char columns_str[MEGA_SIZE];
Xstatic char modindexcolumns_str[MEGA_SIZE];
Xstatic char indexcolumns_str[MEGA_SIZE];
Xstatic char columnname_str[MINI_SIZE];
Xstatic char sortorder_str[MINI_SIZE];
Xstatic char format_str[MINI_SIZE];
X
Xstatic int byte;
X
Xstatic struct {
X    char column[80];		/* Name of database field. */
X    char ing_format[40];	/* Ingres format for create command. */
X    char ing_copydbformat[20];	/* Output format from Ingres copydb. */
X    char syb_format[40];	/* Sybase format for create command. */
X    char syb_bcplength[6];	/* Input field length for Sybase bcp. */
X} table[MAXFIELDS];
Xstatic int ntable = 0;
Xstatic struct {
X    char column[80];
X} indexlist[MAXFIELDS];
Xstatic int nindexlist = 0;
Xstatic int i;
Xstatic char pwdpathname[MAXPATHLEN];
X
X
Xstatic char ing_copydbformat[20];	/* Output format from Ingres copydb. */
Xstatic char syb_format[40];	/* Sybase format for create command. */
Xstatic char syb_bcplength[6];	/* Input field length for Sybase bcp. */
Xstatic bcp_fmt_filename[80];
Xstatic FILE *fp_copyin;
X
Xextern char GLBL_line[];
Xstatic FILE *fp_create;
Xstatic FILE *fp_copyout;
Xstatic FILE *fp_index;
X
X%}
X
X
X%union
X{
X    int num;
X    char *ptr;
X};
X
X%start	source
X
X%token  <ptr> ING_I1
X%token  <ptr> ING_I2
X%token  <ptr> ING_I4
X%token  <ptr> ING_F4
X%token  <ptr> ING_F8
X%token  <ptr> ING_C
X%token  <ptr> ING_TEXT
X%token  <ptr> ING_DATE
X%token  <ptr> ING_MONEY
X
X%token  <ptr> ALPHANUMERIC
X%token  <ptr> INTEGER
X
X%token  <ptr> COMMA
X%token  <ptr> COLON
X%token  <ptr> EQUAL
X%token	<ptr> OPENPAREN
X%token	<ptr> CLOSEPAREN
X
X%token  <ptr> QUEL_CREATE
X%token  <ptr> QUEL_MODIFY
X%token  <ptr> QUEL_INDEX
X
X%token  <ptr> IS
X%token  <ptr> ON
X%token  <ptr> TO
X%token  <ptr> UNIQUE
X
X/* non-terminals we create so we can catch the values passed by lex. */
X%type   <ptr> ing_i1
X%type   <ptr> ing_i2
X%type   <ptr> ing_i4
X%type   <ptr> ing_f4
X%type   <ptr> ing_f8
X%type   <ptr> ing_c
X%type   <ptr> ing_text
X%type   <ptr> ing_date
X%type   <ptr> ing_money
X
X%type   <ptr> alphanumeric
X%type   <ptr> integer
X
X%type   <ptr> comma
X%type   <ptr> colon
X%type   <ptr> equal
X%type   <ptr> openparen
X%type   <ptr> closeparen
X
X%type   <ptr> quel_create
X%type   <ptr> quel_modify
X%type   <ptr> quel_index
X
X%type   <ptr> is
X%type   <ptr> on
X%type   <ptr> to
X%type   <ptr> unique
X
X%type   <ptr> locationname
X%type   <ptr> tablename
X%type   <ptr> indexname
X%type   <ptr> storagestructure
X%type   <ptr> columns
X%type   <ptr> modindexcolumns
X%type   <ptr> indexcolumns
X%type   <ptr> columnname
X%type   <ptr> sortorder
X%type   <ptr> format
X
X%%
Xsource : stmt_create
X       | stmt_modify
X       | stmt_index
X       ;
X
Xstmt_create :  quel_create locationname colon tablename 
X                           openparen columns closeparen
X           { /* Write the create statments for Sybase. */
X	     fprintf(fp_create, "create table %s (\n", tablename_str);
X	     for (i=0; i < ntable - 1; ++i) {
X		 fprintf(fp_create, "    %s %s not null,  /* Ingres: %s */\n", 
X			table[i].column, 
X			table[i].syb_format,
X			table[i].ing_format); 
X	     }
X	     fprintf(fp_create, "    %s %s not null   /* Ingres: %s */\n)\n", 
X		    table[i].column, 
X		    table[i].syb_format,
X		    table[i].ing_format); 
X	     fprintf(fp_create, "go\n");
X
X	     /* Write the copydb statments for Ingres. */
X	     fprintf(fp_copyout, "copy %s (\n", tablename_str);
X	     for (i=0; i < ntable - 1; ++i) {
X		 fprintf(fp_copyout, "    %s\t= %s,\n",
X			 table[i].column, 
X			 table[i].ing_copydbformat); 
X	     }
X	     fprintf(fp_copyout, "    %s\t= %s,\n",
X		     table[i].column, 
X		     table[i].ing_copydbformat); 
X	     fprintf(fp_copyout, 
X		     "    nl\t= d1)\ninto \"%s/db.%s\"\n\\p\\g\n",
X		     pwdpathname, tablename_str);
X	     
X	     /* Write the bcp statments for Sybase for this table. */
X	     sprintf(bcp_fmt_filename, "bcp.fmt.%s", tablename_str);
X	     fp_copyin  = fopen(bcp_fmt_filename, "w");
X             fprintf(fp_copyin, "4.0\n");
X	     fprintf(fp_copyin, "%d\n", ntable);
X	     for (i=0; i < ntable - 1; ++i) {
X		 fprintf(fp_copyin, "%d\tSYBCHAR\t0\t%s\t\"%s\"\t%d\t%s\n",
X			 i+1, 
X			 table[i].syb_bcplength,
X			 DELIMFIELD,
X			 i+1,
X			 table[i].column);
X	     }
X	     fprintf(fp_copyin, "%d\tSYBCHAR\t0\t%s\t\"%s\\n\"\t%d\t%s\n",
X		     i+1, 
X		     table[i].syb_bcplength,
X		     DELIMFIELD,
X		     i+1,
X		     table[i].column);
X	     fclose(fp_copyin);
X	     
X	     /* All done with this table. Reset for the next one. */
X	     ntable = 0;
X           }
X       ;
X
Xstmt_modify :  quel_modify tablename to storagestructure on modindexcolumns
X               {
X	          fprintf(fp_index, "create clustered index inx_%s on %s (\n",
X			  tablename_str, tablename_str);
X		  for (i=0; i < nindexlist - 1; ++i) {
X		      fprintf(fp_index, "    %s,\n", indexlist[i].column);
X		  }
X		  fprintf(fp_index, "    %s\n)\n", indexlist[i].column);
X		  fprintf(fp_index, "go\n");
X		  nindexlist = 0;
X	       }
X            |  quel_modify tablename to storagestructure unique
X  			   on modindexcolumns
X               {
X	          fprintf(fp_index, 
X			  "create unique clustered index %s on %s (\n",
X			  indexname_str, tablename_str);
X		  for (i=0; i < nindexlist - 1; ++i) {
X		      fprintf(fp_index, "    %s,\n", indexlist[i].column);
X		  }
X		  fprintf(fp_index, "    %s\n)\n", indexlist[i].column);
X		  fprintf(fp_index, "go\n");
X		  nindexlist = 0;
X	       }
X
X            ;
X
Xstmt_index :  quel_index on tablename is indexname
X                   openparen indexcolumns closeparen 
X              { 
X	          fprintf(fp_index, "create nonclustered index %s on %s (\n",
X			  indexname_str, tablename_str);
X		  for (i=0; i < nindexlist - 1; ++i) {
X		      fprintf(fp_index, "    %s,\n", indexlist[i].column);
X		  }
X		  fprintf(fp_index, "    %s\n)\n", indexlist[i].column);
X		  fprintf(fp_index, "go\n");
X		  nindexlist = 0;
X	      }
X           ;
X
Xquel_create : QUEL_CREATE
X              {
X		  strcpy(quel_create_str, $1);
X		  $$ = quel_create_str;
X	      }
X            ;
X
Xquel_modify : QUEL_MODIFY
X              {
X		  strcpy(quel_modify_str, $1);
X		  $$ = quel_modify_str;
X	      }
X            ;
X
Xquel_index  : QUEL_INDEX
X              {
X		  strcpy(quel_index_str, $1);
X		  $$ = quel_index_str;
X	      }
X            ;
X
Xlocationname : alphanumeric
X               { strcpy(locationname_str, $1);
X		 $$ = locationname_str;
X	       }  
X             ;
X
Xtablename : alphanumeric
X               { strcpy(tablename_str, $1);
X		 $$ = tablename_str;
X	       }  
X             ;
X
Xindexname : alphanumeric
X               { strcpy(indexname_str, $1);
X		 $$ = indexname_str;
X	       }  
X             ;
X
Xstoragestructure : alphanumeric
X                   { strcpy(storagestructure_str, $1);
X		     $$ = storagestructure_str;
X		   }  
X                 ;
X
Xcolumns : columnname equal format
X           { 
X	       strcpy(table[ntable].column, $1);
X	       strcpy(table[ntable].ing_format, $3);
X	       strcpy(table[ntable].ing_copydbformat, ing_copydbformat);
X	       strcpy(table[ntable].syb_format, syb_format);
X	       strcpy(table[ntable].syb_bcplength, syb_bcplength);
X	       ++ntable;
X	   }
X        | columns comma columnname equal format
X           {
X	       strcpy(table[ntable].column, $3);
X	       strcpy(table[ntable].ing_format, $5);
X	       strcpy(table[ntable].ing_copydbformat, ing_copydbformat);
X	       strcpy(table[ntable].syb_format, syb_format);
X	       strcpy(table[ntable].syb_bcplength, syb_bcplength);
X	       ++ntable;
X	   }
X        ;
X
Xmodindexcolumns : columnname 
X                  { 
X		      strcpy(indexlist[nindexlist].column, $1);
X		      ++nindexlist;
X		  }
X                | columnname colon sortorder
X                  { 
X		      strcpy(indexlist[nindexlist].column, $1);
X		      ++nindexlist;
X		  }
X                | modindexcolumns comma columnname
X                  {
X		      strcpy(indexlist[nindexlist].column, $3);
X		      ++nindexlist;
X		  }
X                | modindexcolumns comma columnname colon sortorder
X                  {
X		      strcpy(indexlist[nindexlist].column, $3);
X		      ++nindexlist;
X		  }
X                ;
X
Xindexcolumns : columnname 
X               { 
X		   strcpy(indexlist[nindexlist].column, $1);
X		   ++nindexlist;
X	       }
X             | indexcolumns comma columnname
X               {
X		   strcpy(indexlist[nindexlist].column, $3);
X		   ++nindexlist;
X	       }
X             ;
X
Xcolumnname : alphanumeric
X               { 
X		   strcpy(columnname_str, $1);
X		   $$ = columnname_str;
X	       }
X           ;
X
Xsortorder : alphanumeric
X               { 
X		   strcpy(sortorder_str, $1);
X		   $$ = sortorder_str;
X	       }
X           ;
X
Xformat : ing_i1
X         {
X	     sprintf(ing_copydbformat, "\"c0%s\"", DELIMFIELD);
X	     strcpy(syb_format, "smallint");
X	     strcpy(syb_bcplength, "6");
X	     strcpy(format_str, $1);
X	     $$ = format_str;
X         }
X       | ing_i2
X         {
X	     sprintf(ing_copydbformat, "\"c0%s\"", DELIMFIELD);
X	     strcpy(syb_format, "smallint");
X	     strcpy(syb_bcplength, "6");
X	     strcpy(format_str, $1);
X	     $$ = format_str;
X         }
X       | ing_i4
X         {
X	     sprintf(ing_copydbformat, "\"c0%s\"", DELIMFIELD);
X	     strcpy(syb_format, "int");
X	     strcpy(syb_bcplength, "12");
X	     strcpy(format_str, $1);
X	     $$ = format_str;
X         }
X       | ing_f4
X         {
X	     sprintf(ing_copydbformat, "\"c0%s\"", DELIMFIELD);
X	     strcpy(syb_format, "float");
X	     strcpy(syb_bcplength, "25");
X	     strcpy(format_str, $1);
X	     $$ = format_str;
X         }
X       | ing_f8
X         {
X	     sprintf(ing_copydbformat, "\"c0%s\"", DELIMFIELD);
X	     strcpy(syb_format, "float");
X	     strcpy(syb_bcplength, "25");
X	     strcpy(format_str, $1);
X	     $$ = format_str;
X         }
X       | ing_c
X         {
X	     sprintf(ing_copydbformat, "\"c0%s\"", DELIMFIELD);
X	     sprintf(syb_format, "char(%s)", ($1)+1);
X	     strcpy(syb_bcplength, ($1)+1);
X	     strcpy(format_str, $1);
X	     $$ = format_str;
X         }
X       | ing_text openparen integer closeparen
X         {
X	     sprintf(ing_copydbformat, "text(0)\"%s\"", DELIMFIELD);
X	     sscanf(integer_str, "%d", &i);
X	     if (i <= 255) {
X		 sprintf(syb_format, "varchar(%d)", i);
X	     } else {
X		 strcpy(syb_format, "text");
X	     }
X	     strcpy(syb_bcplength, integer_str);
X	     strcpy(format_str, $1);
X	     strcat(format_str, $2);
X	     strcat(format_str, $3);
X	     strcat(format_str, $4);
X	     $$ = format_str;
X         }
X       | ing_date
X         {
X	     sprintf(ing_copydbformat, "\"c0%s\"", DELIMFIELD);
X	     strcpy(syb_format, "datetime");
X	     strcpy(syb_bcplength, "26");
X	     strcpy(format_str, $1);
X	     $$ = format_str;
X         }
X       | ing_money
X         {
X	     sprintf(ing_copydbformat, "\"c0%s\"", DELIMFIELD);
X	     strcpy(syb_format, "money");
X	     strcpy(syb_bcplength, "24");
X	     strcpy(format_str, $1);
X	     $$ = format_str;
X         }
X       ;
X
Xalphanumeric : ALPHANUMERIC
X               { 
X		   strcpy(alphanumeric_str, $1);
X		   $$ = alphanumeric_str;
X	       }
X             ;
X
Xinteger		: INTEGER
X                    { 
X                        strcpy(integer_str, $1);
X                        $$ = integer_str;
X                    }
X                ;
X
X
Xis          : IS
X                  { strcpy(is_str, $1);
X                    $$ = is_str;
X	          }
X                ;
X
Xon          : ON
X                  { strcpy(on_str, $1);
X                    $$ = on_str;
X	          }
X                ;
X
Xto          : TO
X                  { strcpy(to_str, $1);
X                    $$ = to_str;
X	          }
X                ;
X
Xunique      : UNIQUE
X                { strcpy(unique_str, $1);
X		  $$ = unique_str;
X	        }
X            ;
X
Xcomma          : COMMA
X                  { strcpy(comma_str, $1);
X                    $$ = comma_str;
X	          }
X                ;
X
Xcolon          : COLON
X                  { strcpy(colon_str, $1);
X                    $$ = colon_str;
X	          }
X                ;
X
Xequal          : EQUAL
X                  { strcpy(equal_str, $1);
X                    $$ = equal_str;
X	          }
X                ;
X
Xopenparen       : OPENPAREN
X		  { strcpy(openparen_str, $1);
X		    $$ = openparen_str;
X                  }
X                ;
X
Xcloseparen       : CLOSEPAREN
X		  { strcpy(closeparen_str, $1);
X		    $$ = closeparen_str;
X                  }
X                ;
X
Xing_i1           : ING_I1
X                   { 
X		       strcpy(ing_i1_str, $1);
X		       $$ = ing_i1_str;
X		   }
X                 ;
X
Xing_i2           : ING_I2
X                   { 
X		       strcpy(ing_i2_str, $1);
X		       $$ = ing_i2_str;
X		   }
X                 ;
X
Xing_i4           : ING_I4
X                   { 
X		       strcpy(ing_i4_str, $1);
X		       $$ = ing_i4_str;
X		   }
X                 ;
X
Xing_f4           : ING_F4
X                   { 
X		       strcpy(ing_f4_str, $1);
X		       $$ = ing_f4_str;
X		   }
X                 ;
X
Xing_f8           : ING_F8
X                   { 
X		       strcpy(ing_f8_str, $1);
X		       $$ = ing_f8_str;
X		   }
X                 ;
X
Xing_c           : ING_C
X                   { 
X		       strcpy(ing_c_str, $1);
X		       $$ = ing_c_str;
X		   }
X                 ;
X
Xing_text         : ING_TEXT
X                   { 
X		       strcpy(ing_text_str, $1);
X		       $$ = ing_text_str;
X		   }
X                 ;
X
Xing_date        : ING_DATE
X                   { 
X		       strcpy(ing_date_str, $1);
X		       $$ = ing_date_str;
X		   }
X                 ;
X
Xing_money        : ING_MONEY
X                   { 
X		       strcpy(ing_money_str, $1);
X		       $$ = ing_money_str;
X		   }
X                 ;
X
X
X%%
X
Xmain()
X{ 
X    extern int yydebug;
X    int byte;
X
X    yydebug = 1;
X    (void)getwd(pwdpathname);
X    fp_create  = fopen("sybase.create", "w");
X    fprintf(fp_create, "/******************************/\n");
X    fprintf(fp_create, "/* Generated from: ing5tosyb4 */\n");
X    fprintf(fp_create, "/******************************/\n\n");
X
X    fp_index  = fopen("sybase.index", "w");
X    fprintf(fp_index, "/******************************/\n");
X    fprintf(fp_index, "/* Generated from: ing5tosyb4 */\n");
X    fprintf(fp_index, "/******************************/\n\n");
X
X    fp_copyout = fopen("ingres.copy.out", "w");
X    fprintf(fp_copyout, "/******************************/\n");
X    fprintf(fp_copyout, "/* Generated from: ing5tosyb4 */\n");
X    fprintf(fp_copyout, "/******************************/\n\n");
X
X    for (;;) {
X/* 	printf("> "); */ 
X	if ( (byte=getchar()) != EOF ) {
X	    ungetc(byte, stdin);
X	} else {
X	    exit(0);
X	}
X	yyparse();
X    }
X}
X
X#include <stdio.h>
Xyyerror(s)
Xchar *s;
X{
X/*     fprintf(stderr, "%s\n", s);  */
X}
X
END_OF_FILE
if test 16407 -ne `wc -c <'ing5tosyb4_gram.y'`; then
    echo shar: \"'ing5tosyb4_gram.y'\" unpacked with wrong size!
fi
# end of 'ing5tosyb4_gram.y'
fi
if test -f 'ing5tosyb4_lex.l' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ing5tosyb4_lex.l'\"
else
echo shar: Extracting \"'ing5tosyb4_lex.l'\" \(3190 characters\)
sed "s/^X//" >'ing5tosyb4_lex.l' <<'END_OF_FILE'
X%{
X/*
X * Author    	- John Guidi
X *                The Jackson Laboratory
X *                600 Main Street
X *                Bar Harbor, ME  04609-0800
X *                USA
X *                Phone: (207)288-3371 X-1391
X *                Internet: jng@jax.org
X * Date		- March 4, 1991
X * Residence	- ing5tosyb4_lex.l
X * Language	- lex
X * Hardware	- SPARstation 1
X * System	- SunOS V4.0.3
X * Abstract	- Lexical analyzer for reading INGRES V5 copydb command 
X *                scripts. These are to be converted to SYBASE V4 analogs.
X*/
X
X#include <stdio.h>
X#include "y.tab.h"
X
Xchar GLBL_line[YYLMAX];
X
X%}
X
Xwhitespace	[\t ]
Xalpha		[A-Za-z]
Xalphanum	[A-Za-z0-9_]
Xint		[0-9]
X
X%%
X{whitespace}+ {
X
X}
X
X[Cc][Rr][Ee][Aa][Tt][Ee] {
X    yylval.ptr = (char *)yytext;
X    return (QUEL_CREATE);
X}
X
X[Mm][Oo][Dd][Ii][Ff][Yy] {
X    yylval.ptr = (char *)yytext;
X    return (QUEL_MODIFY);
X}
X
X[Ii][Nn][Dd][Ee][Xx] {
X    yylval.ptr = (char *)yytext;
X    return (QUEL_INDEX);
X}
X
X[Ii][Ss] {
X    yylval.ptr = (char *)yytext;
X    return (IS);
X}
X
X[Oo][Nn] {
X    yylval.ptr = (char *)yytext;
X    return (ON);
X}
X
X
X[Tt][Oo] {
X    yylval.ptr = (char *)yytext;
X    return (TO);
X}
X
X[Uu][Nn][Ii][Qq][Uu][Ee] {
X    yylval.ptr = (char *)yytext;
X    return (UNIQUE);
X}
X
X[Ii]1 {
X    yylval.ptr = (char *)yytext;
X    return (ING_I1);
X}
X
X[Ii]2 {
X    yylval.ptr = (char *)yytext;
X    return (ING_I2);
X}
X
X[Ii]4 {
X    yylval.ptr = (char *)yytext;
X    return (ING_I4);
X}
X
X[Ff]4 {
X    yylval.ptr = (char *)yytext;
X    return (ING_F4);
X}
X
X[Ff]8 {
X    yylval.ptr = (char *)yytext;
X    return (ING_F8);
X}
X
X[Cc]{int}+ {
X    yylval.ptr = (char *)yytext;
X    return (ING_C);
X}
X
X[Tt][Ee][Xx][Tt] {
X    yylval.ptr = (char *)yytext;
X    return (ING_TEXT);
X}
X
X[Dd][Aa][Tt][Ee] {
X    yylval.ptr = (char *)yytext;
X    return (ING_DATE);
X}
X
X[Mm][Oo][Nn][Ee][Yy] {
X    yylval.ptr = (char *)yytext;
Xreturn (ING_MONEY);
X}
X
X"," {
X        yylval.ptr = (char *)yytext;
X	return (COMMA);
X    }
X
X":" {
X    yylval.ptr = (char *)yytext;
X    return (COLON);
X}
X
X"=" {
X    yylval.ptr = (char *)yytext;
X    return (EQUAL);
X}
X
X"(" {
X    yylval.ptr = (char *)yytext;
X    return (OPENPAREN);
X}
X
X")" {
X    yylval.ptr = (char *)yytext;
X    return (CLOSEPAREN);
X}
X
X
X
X{int}+  {
X    yylval.ptr = (char *)yytext;
X    return (INTEGER);
X}
X
X{alpha}{alphanum}* {
X    yylval.ptr = (char *)yytext;
X    return (ALPHANUMERIC);
X}
X
X. {
X
X}
X
X"\n" {
X
X}
X
X%%
X
X#undef output
X#undef input
X#undef unput
X
X# define output(c) putc(c,yyout)
X# define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
X
X#define input() ( \
X(((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10? \
X(yylineno++, saveline(yyin), yytchar):yytchar)==EOF?0:yytchar) \
X)
X
X
X/* Not perfect, but everytime we get a newline, save the next string, and */
X/* stuff it into global line. */
Xsaveline(filep)
XFILE *filep;
X{
X    int iline;
X    int i;
X    
X    iline = 0; 
X    for (;;) {
X 	GLBL_line[iline] = getc(filep);
X 	if ( (GLBL_line[iline] == '\n') || (GLBL_line[iline] == EOF) ) {
Xif (GLBL_line[iline] == EOF) {
X/*     printf("yylineno = %d\n", yylineno); */
X}
X	    for (i=iline; 0 <= i; --i) {
X		ungetc(GLBL_line[i], filep);
X	    } 	 
X	    break;
X 	}
X	++iline;
X    } 
X    GLBL_line[iline] = '\0'; 
X}
X
END_OF_FILE
if test 3190 -ne `wc -c <'ing5tosyb4_lex.l'`; then
    echo shar: \"'ing5tosyb4_lex.l'\" unpacked with wrong size!
fi
# end of 'ing5tosyb4_lex.l'
fi
echo shar: End of shell archive.
echo "See README for instructions"
exit 0