/****************************************************************************/
/** Copyright (c) Quest Engineering Technologies, 1991                     **/
/**                                                                        **/
/** All Rights Reserved.  Unpublished rights reserved under the  copyright **/
/** laws of the United States.                                             **/
/**                                                                        **/
/** The software contained on this media is proprietary  to  and  embodies **/
/** the   confidential   technology  of  Quest  Engineering  Technologies. **/
/** Possession, use, duplication or  dissemination  of  the  software  and **/
/** media  is  authorized  only  pursuant  to a valid written license from **/
/** Quest Engineering Technologies.                                        **/
/**                                                                        **/
/** RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure by  the  U.S. **/
/** Government  is  subject  to  restrictions as set forth in Subparagraph **/
/** (c)(1)(ii) of DFARS 252.227-7013, or in FAR 52.227-19, as applicable.  **/
/****************************************************************************/

#ifndef dllinter
#define dllinter

#ifndef  ezdsp_h

class    AllArray;

// #define  boolean int
// #define  NIL     0

#if defined(WIN32)

    #  include "windef.h"		  // for defining FAR PASCAL boolean
    typedef long            INDINT;

#elif defined(__unix__)

    # define HINSTANCE long
    typedef char* LPSTR;

#else

#endif  // defined(WIN32)

//#include "eztypes.h"

typedef union
{
    int           Cmnd;
    AllArray      *a;
}   EZDSP_DATA_I ;
#endif


#ifndef symblntr_h
#define  SYM_STRING         0x0004
#define  SYM_IN_TABLE       0x0008

class ISymbolEntry  {

public:
// COMPILER DEPENDENT ! because definition here doesnt 
// have methods, compiler will not allocate the 2 extra bytes !
// This is the public interface to SymbolEntry (no methods here and no
// superclass either). It is COMPILER AND CLASS LIBRARY DEPENDENT!!
#if defined(CV_WIN32) || defined(__WATCOMC__)
   char        dummy[8];  // only eight bytes under CV_WIN32
#elif WIN32
   char        dummy[5];  // only five bytes under CV_WIN16/VC22
#else
   char        dummy[8];  // default.
#endif

   int          Type;
   int          SymFlags;
   EZDSP_DATA_I u;

   int          Index;          // own index in the SymbolTable
   int          DupIndex;       // alias index in the SymbolTable (only CST will use it)

   ISymbolEntry *MyDataOwner;
   ISymbolEntry *MyDataUser;
};

typedef ISymbolEntry Datum;
#endif

//#include "ytaball.h"
#define UNDEF  269
#define DARRAY 270
#define CARRAY 278
#define STRING 262
#define EMPTY  290


#define MAX_DLL_ARGS        50
#define MAX_WHO          16000

//#include "ez_inter.h"
#ifndef ez_inter_h
#define MAX_SYMBOL_NAME     50
#define MAX_INPUT_LINE     256
#define MAX_FILE_NAME_LEN   12
#define MAX_PATH_LEN       120
#define MAX_ERROR_MESSAGE 1024
#define PATH_VARIABLE "_MVPATH"
#endif

#define REAL_TYPE            0
#define COMPLEX_TYPE         1
#define UNDEF_TYPE           2

#define GS_WIN_FAC           8000

typedef Datum *    (FAR PASCAL *NewDatumPROC)  (void *);
typedef void       (FAR PASCAL *DelDatumPROC)  (void *, Datum *);
typedef AllArray * (FAR PASCAL *NewArrayPROC)  (void *, INDINT, INDINT, int);
typedef void       (FAR PASCAL *DelArrayPROC)  (void *, AllArray *);
typedef Datum *    (FAR PASCAL *GetGlobalPROC) (void *, char *, int);
typedef void       (FAR PASCAL *FevalPROC)     (void *, char *, 
                                                int *, Datum **, int, Datum *);
typedef Datum *    (FAR PASCAL *EvalPROC)      (void *, char *); 
typedef void       (FAR PASCAL *ArrayInfoPROC) (void *, AllArray *, double **, INDINT *, INDINT *, int *);
typedef void       (FAR PASCAL *PrintPROC)     (void *, char *);
typedef void       (FAR PASCAL *ErrorPROC)     (void *, int, char *);
typedef void       (FAR PASCAL *YieldPROC)     (void *);
typedef void       (FAR PASCAL *WhoPROC)       (void *, char *);
typedef Datum *    (FAR PASCAL *SetGlobalPROC) (void *, char *, Datum *, int);
typedef void       (FAR PASCAL *GuiPROC)(void *, long Option, long lParam, long *Result);

typedef struct {
   void  *          Program; // The calling program
   HINSTANCE        hInst;   // Instance
   NewDatumPROC     MVNewDatum;
   DelDatumPROC     MVDelDatum;
   NewArrayPROC     MVNewArray;
   DelArrayPROC     MVDelArray;
   GetGlobalPROC    MVGetGlobal;
   FevalPROC        MVFeval;
   EvalPROC         MVEval;
   ArrayInfoPROC    MVArrayInfo;
   PrintPROC        MVPrint;
   ErrorPROC        MVError;
   YieldPROC        MVYield;
   WhoPROC          MVWho;
   SetGlobalPROC    MVSetGlobal;
   GuiPROC          GuiCall;
   FARPROC          temp17;
   FARPROC          temp16;
   FARPROC          temp15;
   FARPROC          temp14;
   FARPROC          temp13;
   FARPROC          temp12;
   FARPROC          temp11;
   FARPROC          temp10;
   FARPROC          temp9;
   FARPROC          temp8;
   FARPROC          temp7;
   FARPROC          temp6;
   FARPROC          temp5;
   FARPROC          temp4;
   FARPROC          temp3;
   FARPROC          temp2;
   FARPROC          temp1;
} MV_INTERFACE;

#ifdef MV_UTILITIES
double MVGetElement (MV_INTERFACE * mv, AllArray * a, INDINT iCol, INDINT jRow)
{
   double  *p; 
   INDINT   m, n, mn, offset; 
   int      type; 

   (* mv->MVArrayInfo) (mv->Program, a, &p, &m, &n, &type); 

   mn = m*n;
   offset = jRow*n+iCol;
   if(offset >= 0 && offset < mn)
      return(p[offset]);

   return(0.0);
}
  
void MVSetElement(MV_INTERFACE * mv, AllArray * a, INDINT iCol, INDINT jRow, double x)
{ 
   double  *p; 
   INDINT   m, n, offset, mn; 
   int      type; 
   (* mv->MVArrayInfo)(mv->Program, a, &p, &m, &n, &type); 
   mn = m*n;
   offset = jRow*n+iCol;
   if(offset >= 0 && offset < mn)
      p[offset] = x;
}

void MVSetComplexElement(MV_INTERFACE * mv, AllArray * a,
                         INDINT iCol, INDINT jRow,
                         double xr, double xi)
{ 
   double  *p; 
   INDINT   m, n, offset, mn; 
   int      type; 
   int      cplxSize = 2;   // Complex size in doubles

   (* mv->MVArrayInfo)(mv->Program, a, &p, &m, &n, &type); 

   mn = m*n*cplxSize;
   offset = jRow*n*cplxSize+iCol;
   if(offset >= 0 && offset < mn-(cplxSize-1))
   {
      p[offset]   = xr; // real part
      p[offset+1] = xi; // imaginary part
   }
}

int MVIsString (Datum * d) 
{
   return ( d->Type == DARRAY &&
            d->u.a            &&
           (d->SymFlags | SYM_STRING) );
}

int MVIsArray (Datum * d) 
{
   return (d->Type == DARRAY && d->u.a);
}

#endif
#endif // dllinter
