.ad 8
.bm 8
.fm 4
.bt $Copyright (c) 2000-2005 SAP AG$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $SQL$Project Distributed Database System$VPC30C$
.tt 2 $$$
.tt 3 $$C_Precompiler_Main_Program$2000-09-05$
***********************************************************
.nf

.nf

.nf

    ========== licence begin  GPL
    Copyright (c) 2000-2005 SAP AG

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    ========== licence end
.fo


.fo


.fo
Module  :
=========
.sp
Purpose :
.CM *-END-* purpose -------------------------------------
Define  :
&ifdef DEBUG
&else
#line 22 "vpc30c"
&endif

.CM *-END-* define --------------------------------------
Use     :
 
.CM *-END-* use -----------------------------------------
Synonym :
 
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : 
.sp
.cp 3
Created : 1995-05-15
.sp
.cp 3
Version : 1995-05-15
.sp
.cp 3
Release :      Date : 2000-09-05
Specification:
.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:
.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:
 
.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.sp
.CM -lll-
Code    :
/*PRETTY */
&ifdef DEBUG
&else
#line 73 "vpc30c"
&endif

&ifdef TRACE
extern void m90init (void);
extern void m90setswitch_parms ( int, const char*, const char*);
&endif

&ifdef DEBUG
&else
#line 83 "vpc30c"
&endif

#ifdef WIN32
extern HINSTANCE m90s_hModule;
#endif

#include <stdio.h>
#include <stdarg.h>
#include "vpr01Env.h"

#if defined(WIN32)
typedef wchar_t UCS2CHAR;
#else
typedef unsigned short UCS2CHAR;
#endif

void *p03caci (sqlcatype *sqlcar, sqlxatype *sqlxar, 
               tpr01_Precompiledfor pcfor);

static void pc30cDeleteConDescs (tpc_globals *pc)
{
  tpr01_EnvDesc *EnvDesc = (&pc->sqlca)->sqlEnvDesc;
  tpr01_EnvContainer *Env = EnvDesc->Env;
  tpr01_ConContainer *Connection = Env->GetConnectionCont(EnvDesc);
  tpr01_ConDesc *ConDesc = NULL;
  tpr00_DatabaseName szDatabaseName;

  int nSession = 1;
  sprintf(szDatabaseName, ":%d", nSession);
  if (ConDesc = Connection->FindDesc (Connection, szDatabaseName, SessionPrimary_epr01Con))
    Connection->DeleteDesc (ConDesc);

  for (nSession = 2; nSession < sqlgamax; nSession++) {
    sprintf(szDatabaseName, ":%d", nSession);
    if (ConDesc = Connection->FindDesc (Connection, szDatabaseName, SessionDefault_epr01Con))
      Connection->DeleteDesc (ConDesc);
  }
}

static void p30finishprecom (tpc_globals *pc)
{
	tsp00_Int2 i, va1sav;
	tsp00_Int4 oldkano;
	
	va1sav = pc->pcSqlva.va1cnt;
	p32vamax (&pc->pcSqlva.va1cnt);
	pc->pcCodeInd = CPC_WORK1FILE;
	if (pc->pcOpts.variant.C_sp4co_sql_precompiler.opt_trace_F != CPR_TRACE_LONG)
		pc->pcSqlva.va3cnt = 1;
	p13dynparameter (p31outstmt, p31outstmt, pc, &p31code);
	pc->pcCodeInd = CPC_WORK3FILE;
	p11copyworkfile (pc, CPC_WORK2FILE, 1);
	p11vfopen (pc, CPC_WORK2FILE);
	pc->pcCodeInd = CPC_WORK2FILE;
	pc->pcSqlva.va1cnt = va1sav;
	p13bsqlstart(p31outstmt, pc, &p31code);
	p13cabind(p31outstmt, pc, &p31code);
	p13xabind(p31outstmt, pc, &p31code);
	for (i = 0; i < pc->pcSqlva.ndmax; i++)
	{
		tpc_nd_entry *nd = pc->pcSqlva.ndtabp + i;
		tpc_varent *vt = pc->pcSymtab.vartablep + nd->ndVarmainIx - 1;
		tpc_typent *tt = pc->pcSymtab.typtablep + vt->vatypix - 1;
		if (nd->ndVarmainIx <= pc->pcSymtab.varCnt &&
			nd->ndExpanlen > 0 && tt->sc.tyPtr >= 0)
			p31vnref (pc, nd->ndVarmainIx, nd->ndTypentIx,
				nd->ndSqlva1St, 0, nd->ndExpanlen,
				nd->ndNamePtr);
	}
	for (i = 0; i < pc->pcSqlva.va2cnt; i++)
		p13va2bind (p31outstmt, pc, &p31code, i);
	if (pc->pcOpts.variant.C_sp4co_sql_precompiler.opt_trace_F == CPR_TRACE_LONG)
		for (i = 0; i < pc->pcSqlva.va3cnt; i++)
			p13va3bind (p31outstmt, pc, &p31code, i);
	for (i = 0; i < pc->pcPa; i++)
		p13pabind (p31outstmt, pc, &p31code, i);
	for (i = 0; i < pc->pcKa; i++)
		p13kabind (p31outstmt, pc, &p31code, i);
	for (i = 0; i < pc->pcPr; i++)
		p13prbind (p31outstmt, p31outcnt, p31quocnt, pc, &p31code, i);
	oldkano = 0;
	for (i = 0; i < pc->pcSt; i++) {
	  tpr01_SQLStatementOptionEnum fOption;
	  if (oldkano != (pc->sqlxa.sqlstp+i)->stkano) {
	    oldkano = (pc->sqlxa.sqlstp+i)->stkano;
	    fOption = First_epr01;	    
	  }
	  else
	    fOption = Append_epr01;
	  p13stbind (p31outstmt, p31outcnt, p31quocnt, pc, &p31code, i, -1, fOption);
	}
	for (i = 0; i < pc->pcFn; i++)
		p13fnbind (p31outstmt, pc, &p31code, i);
	p13modtrace (p31outstmt, p31outcnt, p31quocnt, pc, &p31code);
	for (i = 0; i < pc->pcAt; i++)
		p13atbind (p31outstmt, pc, &p31code, i);
	p13esqlstart (p31outstmt, pc, &p31code);
}

static void p30localparameters (tpc_globals *pc)
{
	tsp00_Int2 workfile = pc->pcCodeInd;
	tsp00_Int2 i, varix;
	
	pc->pcCodeInd = CPC_WORK3FILE;
	for (i = 1; i <= pc->pcSymtab.typCnt; i++)
		p31vndef (pc, i);
	pc->pcCodeInd = workfile;
	p13start (p31outstmt, pc, &p31code);
	p13daaddr (p31outstmt, p31outcnt, pc, &p31code);
	p32toplevel (&varix);
	pc->pcSymtab.varBot = varix;
	for (i = 0; i < pc->pcSqlva.ndmax; i++)
	{
		tpc_nd_entry *nd = pc->pcSqlva.ndtabp + i;
		if (nd->ndKano == pc->sqlxa.xakano)
		{
			tpc_varent *vt = pc->pcSymtab.vartablep +
				nd->ndVarmainIx - 1;
			tpc_typent *tt = pc->pcSymtab.typtablep +
				vt->vatypix - 1;
			if ((nd->ndVarmainIx > pc->pcSymtab.varBot ||
				tt->sc.tyPtr < 0) && nd->ndExpanlen > 0)
				p31vnref (pc, nd->ndVarmainIx, nd->ndTypentIx,
					nd->ndSqlva1St, 0, nd->ndExpanlen,
					nd->ndNamePtr);
		}
	}
	pc->pcSymtab.varBot = 0;
}

static void p30sqlstatement1 (tpc_globals *pc, tsp00_Int4 cursorparampos)
{
	if (pc->pcError != CPC_PRE_OK)
		return;
	
	switch (pc->pcAn.ansection)
	{
	case CPC_SE_OFF: {
          if (cursorparampos > 0) {
            char *partbuf = pc->pccmdpart.partbufp;
            char ch = partbuf [cursorparampos - 1];
            partbuf[cursorparampos - 1] = '#';
            p14an1sqlstatement (p32nextsymbol, pc);
            partbuf[cursorparampos - 1] = ch;
            p14putsqlstarea (pc);
          }
          else {
            p14ansqlstatement (p32nextsymbol, pc);
          }            
          p30localparameters (pc);
          p14ifstbind (pc, pc->sqlxa.xakano);
          p13sqlstm (p31outstmt, p31outcnt, p31quocnt, pc,
                     &p31code);
          p13whenever(p31outstmt, pc, &p31code);
          break;
        }
	case CPC_SE_VAR:
		p32section (pc);
		break;
	default:
		p11precomerror (pc, CPC_UNKNOWN_SQL_COMMAND);
	}
}

static void p30sqlstatement (tpc_globals *pc)
{
  p30sqlstatement1 (pc, 0);
}

static void p30set (tpc_globals *pc)
{
  tsp00_Int4 *part1len = &pc->pccmdpart.part1len;
  char *partbuf = pc->pccmdpart.partbufp;
  int seno, dbpos, dblen, dbnodepos, dbnodelen, keyind;
  tsp00_Int2 macno;
	
  if (pc->pcError != CPC_PRE_OK)
    return;
	
  p32nextsymbol (pc, partbuf, *part1len);
  p10getkeyword (pc, partbuf, &keyind);
  switch (keyind)	{
  case cpc_i_dbname:
  case cpc_i_serverdb: {
    p14gdbsname (p32nextsymbol, pc, &seno, &dbpos, &dblen,
		 &dbnodepos, &dbnodelen);
    if (pc->pcError == CPC_PRE_OK) {
      p30localparameters (pc);
      p13dbsname (p31outstmt, p31outcnt, p31quocnt, pc,
		  &p31code, seno, dbpos, dblen, dbnodepos,
		  dbnodelen);
    }
    break;
  }
  case cpc_i_nolog: {
    p14nolog  (p32nextsymbol, pc);
    if (pc->pcError == CPC_PRE_OK) {
      p30localparameters (pc);
      p13nolog (p31outstmt, pc, &p31code);
    }
    break;
  }
  case cpc_i_option: {
    int statemno;
    p14option  (p32nextsymbol, pc, &statemno);
    if (pc->pcError == CPC_PRE_OK) {
      p30localparameters (pc);
      p13option (p31outstmt, pc, &p31code);
    }
    break;
  }
  case cpc_i_macro: {
    p11precomerror (pc, CPC_MACROS_NOT_ALLOWED);	
    break;
  }
  case cpc_i_trace: {
    int statemno;
    p32nextsymbol (pc, partbuf, *part1len);
    p10getkeyword (pc, partbuf, &keyind);
    if (keyind == cpc_i_line) {
      p14traceline (p32nextsymbol, pc, &statemno);
      p30localparameters (pc);
      p13trcline (p31outstmt, pc, &p31code);
    }
    else {
      p14gtrace (p32nextsymbol, pc, keyind);
      p30localparameters (pc);
      p13trace (p31outstmt, pc, &p31code);
    }
    break;
  }
  default:
    p30sqlstatement (pc);
  }
}

static void p30analysereflexcommand (tpc_globals *pc)
{
	tsp00_Int2 *symb = &pc->pcScan.symb;
	tsp00_Int4 *part1len = &pc->pccmdpart.part1len;
	char *partbuf = pc->pccmdpart.partbufp;
	int keyind;
	
	pc->sqlxa.xadescpos = pc->sqlxa.xadesclen = 0;
	pc->pcPaLoop = pc->pcKaCuind = 0;
	pc->pcUsage.uscom = 0;
	p10getkeyword (pc, partbuf, &keyind);
	switch (pc->pcAn.ancomtyp)
	{
	case cpr_com_empty:
		p30sqlstatement (pc);
		break;
	case cpr_com_command:
		p14command (p32nextsymbol, pc);
		p30localparameters (pc);
		p13command(p31outstmt, pc, &p31code);
		p13whenever (p31outstmt, pc, &p31code);
		break;
	case cpr_com_oracle:
		p14oracle (p32nextsymbol, pc);
		break;
	default:
		switch (keyind)
		{
			int statemno, immediate;
			char dclg;
			tsp00_Int2 typix;
		case cpc_i_abort:
			p14abortsession (p32nextsymbol, pc);
			p30sqlstatement (pc);
                        pc->pcAn.ancheck = CPC_CH_NO;
			break;
		case cpc_i_alter:
			p14balter (p32nextsymbol, pc);
			if (pc->sqlca.sqloap->oamodsettrty == CPR_TRACE_EMPTY)
				p30sqlstatement (pc);
			else
			{
				p30localparameters (pc);
				p13trace (p31outstmt, pc, &p31code);
			}
			break;
		case cpc_i_begin:
			pc->pcAn.anbegin = 1;
			p14begin (p32nextsymbol, pc);
			pc->pcSymtab.varSav = pc->pcSymtab.varCnt;
			break;
		case cpc_i_cancel:
			p14cancel (p32nextsymbol, pc);
			p30localparameters (pc);
			p13cancel (p31outstmt, pc, &p31code);
			p13whenever (p31outstmt, pc, &p31code);
			break;
		case cpc_i_close:
			p14close (p32nextsymbol, pc);
			p30sqlstatement (pc);
			break;
		case cpc_i_connect:
			pc->pcAn.ancomtyp = cpr_com_sql_conn;
			p30sqlstatement (pc);
			break;
		case cpc_i_create:
			p32nextsymbol (pc, partbuf, *part1len);
			p10getkeyword (pc, partbuf, &keyind);
			if (keyind == cpc_i_index || keyind == cpc_i_unique)
				pc->pcAn.ancomtyp = cpr_com_crea_ind;
			p30sqlstatement (pc);
			break;
		case cpc_i_declare:
			pc->pcAn.ancomtyp = cpr_com_declare_cursor;
			p14declare (p32nextsymbol, pc, &keyind, &statemno);
			p30localparameters (pc);
			if (statemno != 0)
			  p13declare (p31outstmt, pc, &p31code, statemno);
			p13whenever (p31outstmt, pc, &p31code);
			break;
		case cpc_i_describe:
			p14describe (p32nextsymbol, pc);
			p30localparameters (pc);
			p13describe (p31outstmt, pc, &p31code);
			p13whenever (p31outstmt, pc, &p31code);
			break;
		case cpc_i_end:
			pc->pcAn.anbegin = 0;
			p14end (p32nextsymbol, pc);
			break;
		case cpc_i_execute:
			p14execute (p32nextsymbol, pc, &statemno, &immediate);
			p30localparameters (pc);
			if (immediate != CPC_IMM_NO)
			{
				p13immediateexecute (p31outstmt ,pc, &p31code,
					statemno);
				p13whenever (p31outstmt, pc, &p31code);
			}
			else
			{
				p13open (p31outstmt, pc, &p31code, statemno);
				p13whenever (p31outstmt, pc, &p31code);
			}
			break;
		case cpc_i_fetch: {
		  tsp00_Int4 pos;
		  tsp00_Int4 cursorparampos;
		  p14fetch (p32nextsymbol, pc, &keyind, &pos, &cursorparampos);
                  pc->pcScan.sypos = pos;
		  p30sqlstatement1 (pc, cursorparampos);
		  if (keyind == cpc_i_descriptor) {
		    pc->sqlxa.sqlkap [pc->pcKa -1].kapacount = -2;
		    pc->pcDa = sqlnmax;
		  }
		  break;
		}
		case cpc_i_putval: {
		  tsp00_Int4 pos;
		  p14putval (p32nextsymbol, pc, &keyind, &pos);
		  p30sqlstatement (pc);
		  if (keyind == cpc_i_descriptor) {
		    pc->sqlxa.sqlkap [pc->pcKa -1].kapacount = -2;
		    pc->pcDa = sqlnmax;
		  }
		  break;
                }
		case cpc_i_getval: {
		  tsp00_Int4 pos;
		  p14getval (p32nextsymbol, pc, &keyind, &pos);
		  p30sqlstatement (pc);
		  if (keyind == cpc_i_descriptor) {
		    pc->sqlxa.sqlkap [pc->pcKa -1].kapacount = -2;
		    pc->pcDa = sqlnmax;
		  }
		  break;
		}
		case cpc_i_for:
			p14forloop (p32nextsymbol, pc);
			p30localparameters (pc);
			if (pc->sqlxa.xakano > 0)
				if ((pc->sqlxa.sqlkap [pc->sqlxa.xakano - 1]
					.kapacount == -1)
                                || (pc->sqlxa.sqlkap [pc->sqlxa.xakano - 1]
					.katyp == cpr_com_sql_open)
                                || (pc->sqlxa.sqlkap [pc->sqlxa.xakano - 1]
					.katyp == cpr_com_sql_open_keep))
					p13open(p31outstmt, pc, &p31code,
						pc->sqlxa.xakano);
				else
				{
					p14ifstbind (pc, pc->sqlxa.xakano);
					p13sqlstm (p31outstmt, p31outcnt,
						p31quocnt, pc, &p31code);
				}
			p13whenever (p31outstmt, pc, &p31code);
			break;
		case cpc_i_include:
			p14include (p32nextsymbol, pc, &keyind, &dclg);
			if (pc->pcInpInd == CPC_INCLUDEFILE)
			{
				p11schar (pc);
				*symb = CPC_CS_EOF;
			}
			else if (pc->pcDclgen.asclause != CPC_AS_EMPTY)
			{
				if (pc->pcAn.ansection == CPC_SE_OFF)
					p11precomerror (pc,
						CPC_INVALID_SQL_COMMAND);
				else if (dclg)
				{
					tsp00_Int2 workfile = pc->pcCodeInd;
					pc->pcCodeInd = CPC_INCLUDEFILE;
					p31comment (pc);
					p32dclgen (pc, &typix);
					if (pc->pcError == CPC_PRE_OK)
					{
						p31dclgen (pc, typix);
						pc->pcCodeInd = workfile;
						p11copyworkfile (pc,
							CPC_INCLUDEFILE, 0);
					}
				}
			}
			break;
		case cpc_i_open:
			p14open (p32nextsymbol, pc, &statemno);
			p30localparameters (pc);
			if (statemno != 0)
				p13open (p31outstmt, pc, &p31code, statemno);
			else
			{
				p14ifstbind (pc, pc->sqlxa.xakano);
				p13sqlstm (p31outstmt, p31outcnt, p31quocnt,
					pc, &p31code);
			}
			p13whenever (p31outstmt, pc, &p31code);
			break;
		case cpc_i_prepare:
			p14prepare (p32nextsymbol, pc);
			p30localparameters (pc);
			p13prepare (p31outstmt, pc, &p31code);
			p13whenever (p31outstmt, pc, &p31code);
			break;
		case cpc_i_reconnect:
			p32nextsymbol (pc, partbuf, *part1len);
			if (*symb != CPC_CS_EOF)
				p11precomerror (pc, CPC_INVALID_SQL_COMMAND);
			while (*symb != CPC_CS_EOF && *symb != CPC_CS_BUFEOF)
				p32nextsymbol (pc, partbuf, *part1len);
			p30localparameters (pc);
			p13reconnect (p31outstmt, pc, &p31code);
			p13whenever (p31outstmt, pc, &p31code);
			break;
		case cpc_i_select:
			p32nextsymbol (pc, partbuf, *part1len);
			p10getkeyword (pc, partbuf, &keyind);
			p30sqlstatement (pc);
			break;
		case cpc_i_set:
			p30set (pc);
			break;
		case cpc_i_stop:
			p32nextsymbol (pc, partbuf, *part1len);
			if (*symb != CPC_CS_EOF)
				p11precomerror (pc, CPC_INVALID_SQL_COMMAND);
			while (*symb != CPC_CS_EOF && *symb != CPC_CS_BUFEOF)
				p32nextsymbol (pc, partbuf, *part1len);
			p13exit (p31outstmt, pc, &p31code);
			break;
		case cpc_i_type:
			p32typequ (pc);
			break;
		case cpc_i_var:
			p32varequ (pc);
			break;
		case cpc_i_version:
			p14version (p32nextsymbol, pc);
			p30localparameters (pc);
			p13version (p31outstmt, pc, &p31code);
			p13whenever (p31outstmt, pc, &p31code);
			break;
		case cpc_i_whenever:
			p14whenever (p32nextsymbol, pc);
			if (pc->pcAn.ansection != CPC_SE_OFF)
				pc->pcSqlCom = 1;
			break;
		default:
			p30sqlstatement (pc);
		}
	}
	pc->pcSqlCom = pc->pcAn.anbegin;
}

static void p30initprecomvariable (tpc_globals *pc)
{
	pc->pcSqlva.va1cnt = 0;
	pc->pcSqlva.va2cnt = 0;
	pc->pcSqlva.va3cnt = 0;
	pc->pcSqlva.ndcnt = 0;
	pc->pcSqlva.ndmax = 0;
	pc->pcCodeInd = CPC_WORK2FILE;
	p32itab (pc);
}

static void p30startprecompiler (tsp00_Int2 lang)
{
	static tpc_globals pc;
	static sqldatype sqlda;
	tsp00_Int4 *syposacc = &pc.pcScan.syposacc;
	tsp00_Int4 *sypos = &pc.pcScan.sypos;
	tsp00_Int2 *symb = &pc.pcScan.symb;
	tsp00_Int4 *part1len;
	char *partbuf;
	tsp00_Int2 len;
	int keyind, i;
	tsp00_Int4 pos;
	int diastm = 0, sqlplstm = 0;
	unsigned char stat, indecl = 0;
	tpr01_Precompiledfor pcfor = 0;
	
&	ifdef TRACE
	m90init ();
	m90setswitch_parms ( 1, "PC                  ",
		"PC                  ");
&	endif

&ifdef DEBUG
&else
#line 515 "vpc30c"
&endif

	p03caci (&pc.sqlca, &pc.sqlxa, pcfor);        
	p03csqlinit (pc.sqlca.sqlrap, 'C', lang);
	pc.sqlca.sqlcxap->xasqldap = &sqlda;
	p19itab (&pc);
	pc.pcError = CPC_PRE_OK;
	pc.pcSqlCom = 0;
	pc.pcExecSql = 0;
	p10initprecomvariable (&pc);
	p30initprecomvariable (&pc);
	*symb = CPC_CS_UNKNOWN;
	p11i1char (&pc, sizeof (sqlargline));
	pc.pcAn.ancomtyp = cpr_com_opt;
	p15precomoptionsget (&pc);
	if (pc.pcOpts.variant.C_sp4co_sql_precompiler.opt_version_F == 1) {
	  tpc_prelinetype vers;
	  memset(vers, ' ', sizeof(tpc_prelinetype));
	  p07version(&vers);
	  sqlwrite ((unsigned char*)vers);
	  return;
	}
	p31initcode (&pc);
	if (pc.pcError != CPC_PRE_OK)
	{
	  p11finisherror (&pc);
	  sqlresult (127);
	  return;
	}
	p11initfiles (&pc);
	if (pc.pcError == CPC_PRE_OK)
		p11openstandardfiles (&pc);
	if (pc.pcError != CPC_PRE_OK) {
	  p11finisherror (&pc);
	  sqlresult (126);
	  return;
	}
	pc.pcAn.ancheck = pc.pcOpts.variant.C_sp4co_sql_precompiler.opt_mode_F;
	*symb = CPC_CS_EOF;
	p11ichar (&pc);
	part1len = &pc.pccmdpart.part1len;
	partbuf = pc.pccmdpart.partbufp;
	do
	{
		pc.pcAn.ancomtyp = cpr_com_empty;
		p32nextsymbol (&pc, partbuf, *part1len);
		if (pc.pcAn.ansection == CPC_SE_OFF)
			if (*symb == CPC_CS_LEFTBRC)
				p32push (&pc);
			else if (*symb == CPC_CS_RIGHTBRC)
				p32pop (&pc);
		p10getkeyword (&pc, partbuf, &keyind);
		if (keyind == cpc_i_exec)
		{
			pos = *sypos;
			p11flout (&pc);
			p11gout (&len);
			len -= *syposacc - *sypos;
			p32nextsymbol (&pc, partbuf, *part1len);
			p10getkeyword (&pc, partbuf, &keyind);
			pc.pcSqlCom = 1;
			pc.sqlca.sqlrap->rakamode = pc.sqlca.sqldbmode;
			switch (keyind)
			{
			case cpc_i_sqldb:
			case cpc_i_adabas:
			case cpc_i_internal:
				pc.sqlca.sqlrap->rakamode = CPR_KIND_INTERNAL;
			case cpc_i_sql:
				pc.pcAn.ancomtyp = cpr_com_sql;
				break;
			case cpc_i_command:
				pc.pcAn.ancomtyp = cpr_com_command;
				break;
			case cpc_i_oracle:
				pc.pcAn.ancomtyp = cpr_com_oracle;
				break;
			default:
				pc.pcSqlCom = (BOOLEAN)
					(pc.pcAn.ansection != CPC_SE_OFF);
				if (pc.pcSqlCom)
				{
					*syposacc = pos;
					p32nextsymbol (&pc, partbuf, *part1len);
				}
			}
			if (pc.pcAn.ancomtyp != cpr_com_empty)
			{
				char ch;
			/**	p03packetinit (&pc.sqlca, CSP_M_ADBSPARSE);**/
				if (pc.pcAn.ansection == CPC_SE_OFF && len > 0)
					p11vfwrite (&pc, pc.pcCodeInd,
						pc.pcOutLine.lline, len);
				*symb = CPC_CS_BUFEOF;
				p32nextsymbol (&pc, partbuf, *part1len);
				ch = partbuf [*sypos - 1];
				if (strchr ("12345678", ch))
				{
					pc.sqlca.sqlrap->raactsession =
						ch - (char) '0';
					*symb = CPC_CS_BUFEOF;
					p32nextsymbol (&pc, partbuf, *part1len);
				}
				else if (strchr ("90", ch))
					p11precomerror (&pc,
						CPC_SESSION_NOT_ALLOWED);
				else
				{
					pc.sqlca.sqlrap->raactsession = 1;
					if (pc.sqlca.sqlrap->rakamode ==
						CPR_KIND_ORACLE ||
						pc.sqlca.sqlrap->rakamode ==
						CPR_KIND_SAPR3)
					{
						p10getkeyword (&pc, partbuf,
							&keyind);
						p14batdbname (p32nextsymbol,
							&pc, partbuf, *part1len,
							keyind);
					}
				}
			}
		}
		if (pc.pcSqlCom)
		{
			if (pc.pcError == CPC_PRE_OK)
			{
				pc.pcAn.ancheck = CPC_CH_NO;
				pc.pcExecSql = 1;
				p30analysereflexcommand (&pc);
				if (!pc.pcSqlCom)
					p11rsout ();
				if (pc.pcAn.ancheck != CPC_CH_NO)
					p16sqlopcheck (&pc);
			}
		}
		else if (pc.sqlca.sqlrap->rasqlansi == CPR_KIND_ANSI)
			p32fansi (&pc, &indecl);
		if (pc.pcError != CPC_PRE_REFLEX_START_REQUIRED &&
			pc.pcError != CPC_INVALID_SECTION_BEGIN_OR_END)
			pc.pcError = CPC_PRE_OK;
		if (pc.pcInpEof && pc.pcInpInd == CPC_INCLUDEFILE)
		{
			sqlfnentry *fn = pc.sqlxa.sqlfnp + pc.pcFn - 1;
			if (fn->fnkanomin == pc.pcKa + (tsp00_Int2) 1)
				pc.pcFn--;
			else
				fn->fnkanomax = pc.pcKa;
			p11rchar (&pc, part1len);
			p11rsout ();
			pc.pcInpInd = CPC_INPUTFILE;
			pc.pcInpEof = 0;
			*symb = CPC_CS_EOF;
		}
	}
	while (!pc.pcInpEof && pc.pcError != CPC_INVALID_SECTION_BEGIN_OR_END &&
		pc.pcError != CPC_PRE_REFLEX_START_REQUIRED);
	if (pc.pcError == CPC_PRE_OK)
	{
		if (pc.pcOpts.variant.C_sp4co_sql_precompiler.opt_mode_F != CPC_CH_NO)
			p16offusage (&pc);
		if (pc.pcExecSql != 0)
			p30finishprecom (&pc);
		p11finisherror (&pc);
	}
	else 
		p11finisherror (&pc);
	for (i = 1; i <= 5; i++)
		p11vfclose (&pc, i);
	if (pc.pcLno.lnoinp == cpr_is_true)
		p11vfclose (&pc, CPC_LNOINPUT);
	if (pc.pcLno.lnoout == cpr_is_true)
		p11vfclose (&pc, CPC_LNOOUTPUT);
        pc30cDeleteConDescs (&pc);
	if (pc.sqlca.sqlrap->rasqlinit != cpr_is_false)
		sqlfinish (1);
}

extern int _argc;
extern char **_argv, **_envp;
extern int WinArgc;
extern char** WinArgv;

/*
  Function: [w]main
  Description: Main entry routine
  
  The read parameter are converted into UTF8 character strings and parsed
  to c_main. This function does the work.

  Arguments: argc [in] Argument count
             wargv [in] UCS2 encoded argument array (WindowsNT)
             argv[in] UTF8 or ascii encoded argument array (UNIX)
 */
#if defined(WIN32)
int wmain(int argc, UCS2CHAR *wargv[])
{
  char **returnedUTF8argv;
  /* Convert into UTF8 parameter array... */
  if ( !sp83UTF8ArrayFromUCS2Array ( argc, 
                                     (tsp81_UCS2Char **)wargv,
                                     &returnedUTF8argv ) )
  {
    printf("Failed to convert to UTF8 argument array\n");
    return -1;
  }

  return c_main(argc, returnedUTF8argv);
}
#else
int main(int argc, char *argv[])
{
  return c_main(argc, argv);
}
#endif

int c_main (int argc, char **argv)
{
	_argc = argc;
	_argv = argv;
#if defined(WIN32)	
	WinArgc = argc;
	WinArgv = argv;
	sql__pmain(1);
	m90s_hModule = NULL;
#endif     
	p30startprecompiler (CPR_LA_C);

	return 0;
}

.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
*-PRETTY-*  statements    :       0000
*-PRETTY-*  lines of code :       0000        PRETTY  3.09 
*-PRETTY-*  lines in file :       0000         1992-11-23 
.PA 
