/* Postgres command executor */
Command = ''
nArg = ''
rc = ''
pgsql = ''
Path = ''
Dll = ''
CurDir = ''
etc = ''

nArg = arg()
rc = CheckEnv()
if rc = "False" then do
   say "PostgreSQL V8.4.1 command executor"
   say "Please set PGSQL and/or PGDATA to correct value"
   say "For example:"
   say "    set pgsql=c:\apps\pgsql841"
   say "    set pgdata=d:\apps\pgsqldata (different hard disk)"
   exit
   end

if nArg = 0 then do
   say "PostgreSQL V8.4.1 command executor"
   say "Use pgcmd <postgresql command> <arguments>"
   say "For example:"
   say "    pgcmd.cmd initdb.exe"
   exit
   end

rc = setlocal()
pgsql = value('PGSQL',,'OS2ENVIRONMENT')
etc = PGSQL || "\etc"
path = PGSQL || "\lib"
dll = PGSQL || "\lib"
rc = value('PGLIB',path,'OS2ENVIRONMENT')
path = PGSQL || "\bin"
rc = value('PGPATH',path,'OS2ENVIRONMENT')

rc = value('PGUSER','postgres','OS2ENVIRONMENT')
rc = value('USER','postgres','OS2ENVIRONMENT')
rc = value('GROUP','users','OS2ENVIRONMENT')
rc = value('USERNAME','postgres','OS2ENVIRONMENT')

'@copy ' || value('ETC',,'OS2ENVIRONMENT') || '\resolv2 ' || etc || '> nul'
'@copy ' || value('ETC',,'OS2ENVIRONMENT') || '\protocol ' || etc || '> nul'
'@copy ' || value('ETC',,'OS2ENVIRONMENT') || '\services ' || etc || '> nul'
'@copy ' || value('ETC',,'OS2ENVIRONMENT') || '\hosts ' || etc || '> nul'

rc = value('ETC',etc,'OS2ENVIRONMENT')

CurDir = directory()
NewDir = directory(PGSQL || "\bin")

Path = ''
do i = 1 to narg
   Path = Path || arg(i) || " "
end

Path /* execute a PostgreSQl command + arguments*/

CurDir = directory(CurDir)
rc = endlocal()
exit

CheckEnv: procedure
          irc = 'True'
          iPGSQL = value('PGSQL',,'OS2ENVIRONMENT')
          iPGDATA = value('PGDATA',,'OS2ENVIRONMENT')
          if iPGSQL = '' then
              irc = 'False'
              else
                  if iPGDATA = '' then
                     irc = 'False'
          return irc
/*
@echo off
setlocal

REM *** POSTGRESQL V8.4.1 ***
rem set PGSQL=d:\pgsql841

REM This variable point to data directory (container of all databases)
rem set PGDATA=d:\pgsqldata

REM This variable point to library directory
set PGLIB=%PGSQL%\lib

REM This variable point to binary directory (for all scripts)
set PGPATH=%PGSQL%\bin

REM There are the variables for administrator of databases:
set PGUSER=postgres
set USER=postgres
set GROUP=users
set USERNAME=postgres

REM Miscellaneus sets
set TMP=/TEMP
set TEMP=/TEMP
set TMPDIR=/TEMP
rem set ETC=%PGSQL%\etc
rem set ENDLIBPATH=%ENDLIBPATH%;%PGSQL%\bin;%PGSQL%\lib;d:\openldap\bin;

MD \TEMP 2> NUL
MD \TMP 2> NUL

cd %PGSQL%\bin

cmd.exe /C %1 %2 %3 %4 %5 %6 %7 %8 %9

endlocal
*/
