.ad 8
.bm 8
.fm 4
.bt $Copyright (c) 1992-2005 SAP AG-2002$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $SQL$Project Distributed Database System$VPS10C$
.tt 2 $$$
.tt 3 $$General Driver option utilities$1998-11-16$
****************************************************************
.nf

.nf

.nf

    ========== licence begin  GPL
    Copyright (c) 1992-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  :

void p10opt (int argc, char *argv [], const char *prpath, const char *hlppath,
	tsp4_xuser_record *userparams, struct tsp4_args_options *opt);

.CM *-END-* define --------------------------------------
Use     :
.CM *-END-* use -----------------------------------------
Synonym :
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  :
.sp
.cp 3
Created : 1994-03-15
.sp
.cp 3
Version : 1994-03-15
.sp
.cp 3
Release :      Date : 1998-11-16
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*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

&if $OS = WIN32
  /* #define SQLUSER_RUNNING 1 */

  #define CHAR WINDOWS_CHAR
  #include <windows.h>

  #define _argc (*NtArgc)
  #define _argv (*NtArgv)

  extern char *getenv (const char*);

  #if !defined(SQLUSER_RUNNING)
     int          WinArgc;
     char **WinArgv;
  #endif
&elif $OS = OS2
  #define _argc os2_argc
  #define _argv os2_argv
&endif
&if $OS = MSDOS
  #define CALL _pascal
&else
  #define CALL
&endif

extern void exit (int);

int p10_optind;

extern void CALL sqlarg3 (tsp4_xuser_record*, tsp00_CryptPw,
	struct tsp4_args_options*,
        tsp4_xuserset, tsp_c40, BOOLEAN*);

int _argc;
char **_argv;

void p10opt (int argc, char *argv [], const char *prpath, const char *hlppath,
	tsp4_xuser_record *userparams, struct tsp4_args_options *opt)

/*      Get precompiler options from a command line. This function may be
        called only once. If an error occurres, an error message is issued
        and exit (1) is called. After successfull completion p10_optind is set
        to the index of the filename argument in optarg.
        Prpath points to the null terminated path name of the precompiler.
        Hlppath points to the null terminated path name of the options help
        file.
        The parameters userparams and opt are used to return the results of
	the option analysis as defined by sqlarg3.
*/

{
        tsp00_CryptPw                    password;
        tsp4_xuserset                   xusertype;
        tsp_c40                         errtext;
        BOOLEAN                         ok;
        const char *OPTSTR =
                "cd:D:eE:F:GH:hiI:lm:M:n:opqsS:t:Tu:U:VwXy:Yz";
        const char *USG1  = "usage: ";
        const char *USG2  = " [";
        const char *USG3  = "] fname [compopts]";
        const char *USGH1 = "       ";
        const char *USGH2 = " -h : display help information";
        const char *VCMD = " -V";
&if $OS = WIN32
        const char *SHELL = NULL;
        static char *varg [] = {0, "/c", 0, 0};
&else
        const char *SHELL = "/bin/sh";
        static char *varg [] = {"sh", "-c", 0, 0};
&endif
        static char **vcmdp = &varg [2];
        const int vlen = strlen (VCMD);
&if $OS = WIN32
        HANDLE hDll;
&endif

        *vcmdp = (char*) malloc (vlen + strlen (prpath) +1);
        strcpy (*vcmdp, prpath);
        strcat (*vcmdp, VCMD);

&if $OS = WIN32
        #if defined(SQLUSER_RUNNING)
                if (hDll = LoadLibrary("SqlUser.dll")) {
                    NtArgc =        (int  *)GetProcAddress (hDll, "WinArgc");
                    NtArgv = (const char***)GetProcAddress (hDll, "WinArgv");
                }
        #else
                NtArgc = &WinArgc;
                NtArgv = &WinArgv;
        #endif
&endif

        _argc = argc;
        _argv = argv;
        opt->opt_component = sp4co_sql_precompiler;
        sqlarg3 (userparams, password, opt, xusertype, errtext, &ok);
        if (ok)
        {
                if (opt->variant.C_sp4co_sql_precompiler.opt_version_F)
                {
&if $OS = WIN32
                        char fname [_MAX_FNAME];
                        ok = FALSE;
                        if ((SHELL = getenv ("COMSPEC")) != NULL)
                        {
                                _splitpath (SHELL, NULL, NULL, fname, NULL);
                                if (fname [0] != '\0')
                                {
                                        varg [0] = fname;
                                        ok = TRUE;
                                }
                        }
                        else
                                fprintf (stderr, "Missing environment variable 'COMSPEC'\n");
                        if (ok) {
			  p01exec (SHELL, varg, 0, 0, 0);
			  exit(0);
			}
&else
                        if (ok)
                                p01exec (SHELL, varg, 1, 0, 0);
&endif
                                /* no return from p01exec */
                }
                else if (opt->variant.C_sp4co_sql_precompiler.opt_help_F)
                {
                        p01mdisp (hlppath);
                        exit (1);
                }
                else
                        ok = (BOOLEAN)
                        (opt->variant.C_sp4co_sql_precompiler.opt_modulefn_F [0] !=  ' ');
        }
        else
                fprintf (stderr, "%.*s\n", sizeof (tsp_c40), errtext);
        free (*vcmdp);
        if (ok)
                p10_optind = opt->variant.C_sp4co_sql_precompiler.opt_fnind_F;
        else
        {
                fprintf (stderr, "%s%s%s%s%s\n", USG1, argv [0], USG2, OPTSTR,
                        USG3);
                fprintf (stderr, "%s%s%s\n", USGH1, argv [0], USGH2);
                exit (1);
        }
}

.CM *-END-* code ----------------------------------------
.SP 2
***********************************************************
