/****************************************************************************
*
* (C) 1999 by BECK IPC GmbH
*
*  BECK IPC GmbH
*  Garbenheimerstr. 38
*  D-35578 Wetzlar
*
*  Phone : (49)-6441-905-240
*  Fax   : (49)-6441-905-245
*
* ---------------------------------------------------------------------------
* Module      : IPC@CHIP SC12 API: cgiapi.c
* Function    : cgi api functions

* Author        : Bartat
* Date          : 27.01.00
* ---------------------------------------------------------------------------

$Header: CGIAPI.C, 7, 16.01.2002 12:37:30, Christoph Stoidner$


$Log:
 7    IPC@CHIP  1.6         16.01.2002 12:37:30  Christoph Stoidner remove waste
      SREGS
 6    IPC@CHIP  1.5         16.01.2002 11:44:57  Christoph Stoidner add starteam
      directives
 5    IPC@CHIP  1.4         14.01.2002 13:18:14  Christoph Stoidner add new
      functions
 4    IPC@CHIP  1.3         19.06.2001 13:35:05  Markus Bartat   start: Added
      comments to the c functions
 3    IPC@CHIP  1.2         31.05.2001 16:18:22  Christoph Stoidner
 2    IPC@CHIP  1.1         28.03.2001 14:14:44  Ernest Schlösser Changed
      include directive to include cgiapi.h instead of only cgi.h
 1    IPC@CHIP  1.0         14.02.2001 16:09:08  Christoph Stoidner
$

* History       :
*
*  Vx.yy        Author  Changes
*
*                 mb    Create
                  cs    add Get/Set RootDir/MainPage
*
*****************************************************************************/

#include <DOS.H>
#include <STDLIB.H>
#include "CLIB/CGIAPI.H"
/*************************************************************************/

#define CGIVECT       0xAB
/*************************************************************************/
//install cgi function
/*************************************************************************/
int CGI_Install(CGI_Entry far  * cgiptr)
{
   union  REGS  inregs;
   union  REGS  outregs;

   inregs.h.ah   = CGI_INSTALL;
   inregs.x.dx   = FP_SEG(cgiptr);
   inregs.x.si   = FP_OFF(cgiptr);

   int86(CGIVECT,&inregs,&outregs);
   return outregs.x.dx;
}


/*************************************************************************/
//delete cgi function
/*************************************************************************/
int CGI_Delete(char far * PathPtr)
{
   union  REGS  inregs;
   union  REGS  outregs;


   inregs.h.ah   = CGI_REMOVE;
   inregs.x.dx   = FP_SEG(PathPtr);
   inregs.x.si   = FP_OFF(PathPtr);
   int86(CGIVECT,&inregs,&outregs);

   return outregs.x.dx;

}


/*************************************************************************/
//Get formitem
/*************************************************************************/
void CGI_GetFormItem(char far * ArgumentBufferPtr,FormItem far * formitem)
{
	union  REGS  inregs;
	union  REGS  outregs;
	struct SREGS segregs;

	inregs.h.ah = CGI_GETFORMITEM;
	inregs.x.bx = FP_SEG(ArgumentBufferPtr);
	inregs.x.si = FP_OFF(ArgumentBufferPtr);
	segregs.es    = FP_SEG(formitem);
	inregs.x.di = FP_OFF(formitem);
	int86x(CGIVECT,&inregs,&outregs,&segregs);
}

/*************************************************************************/
//Get next formitem
/*************************************************************************/
#pragma argsused
int CGI_GetNextItem(char far * ArgumentBufferPtr, char far * * nextItemString)
{
	union  REGS  inregs;
	union  REGS  outregs;
	struct SREGS segregs;

	inregs.h.ah = CGI_FINDNEXTITEM;
	inregs.x.bx = FP_SEG(ArgumentBufferPtr);
	inregs.x.si = FP_OFF(ArgumentBufferPtr);
	int86x(CGIVECT,&inregs,&outregs,&segregs);

	if(outregs.x.dx==0)
	 *nextItemString = (char*)MK_FP(segregs.es, outregs.x.di);
	else
	 *nextItemString = NULL;

	return outregs.x.dx;
}


/*************************************************************************/
//Set main page
/*************************************************************************/
int CGI_SetMainPage(char *mainPageName)
{
	union  REGS  inregs;
	union  REGS  outregs;

	inregs.h.ah = CGI_SETMAIN;
	inregs.x.dx = FP_SEG(mainPageName);
	inregs.x.si = FP_OFF(mainPageName);
	int86(CGIVECT,&inregs,&outregs);

   return outregs.x.dx;
}


/*************************************************************************/
//Set root dir
/*************************************************************************/
int CGI_SetRootDir(char *rootDirName)
{
	union  REGS  inregs;
	union  REGS  outregs;
   struct SREGS segregs;

	inregs.h.ah = CGI_SETROOTDIR;
	inregs.x.dx = FP_SEG(rootDirName);
	inregs.x.si = FP_OFF(rootDirName);
	int86x(CGIVECT,&inregs,&outregs,&segregs);

   return outregs.x.dx;
}


/*************************************************************************/
//Get root dir
/*************************************************************************/
int CGI_GetRootDir(char **rootDirName)
{
	union  REGS  inregs;
	union  REGS  outregs;
   struct SREGS segregs;

	inregs.h.ah = CGI_GETROOTDIR;
	int86x(CGIVECT,&inregs,&outregs,&segregs);

   *rootDirName = (char *)MK_FP( segregs.es, outregs.x.di );

   return outregs.x.dx;
}



/*************************************************************************/
//Get main page name
/*************************************************************************/
int CGI_GetMainPage(char **mainPageName)
{
	union  REGS  inregs;
	union  REGS  outregs;
   struct SREGS segregs;

	inregs.h.ah = CGI_GETMAIN;
	int86x(CGIVECT,&inregs,&outregs,&segregs);

   *mainPageName = (char *)MK_FP( segregs.es, outregs.x.di );

   return outregs.x.dx;
}


/*************************************************************************/
//end cgiapi.c