/* Copyright (C) 1994 - 2002 by Telelogic AB.
Copyright (C) 1991, 1992, 1993, 1994 by Telelogic Malmoe AB.
Copyright (C) 1990, 1991, 1999 by Telesoft Europe AB.
This Program is owned by Telelogic and is protected by national
copyright laws and international copyright treaties. Telelogic
grants you the right to use this Program on one computer or in
one local computer network at any one time.
Under this License you may only modify the source code for the purpose
of adapting it to your environment. You must reproduce and include
any copyright and trademark notices on all copies of the source code.
You may not use, copy, merge, modify or transfer the Program except as
provided in this License.
Telelogic does not warrant that the Program will meet your
requirements or that the operation of the Program will be
uninterrupted and error free. You are solely responsible that the
selection of the Program and the modification of the source code
will achieve your intended result and that the results are actually
obtained. */

#ifndef __cucf_h
#define __cucf_h

#include "cucf_cfg.h"

typedef struct sCoder tCoder;
typedef tCoder* tBuffer;

typedef const struct sASN1TypeInfo tASN1TypeInfo;

/* EMS */

typedef struct
{
  void*          Fields[CODER_PATH_DEEP];
  unsigned long  NumOfFields;
#ifdef CODER_EO_USER
  char*          Path;
  unsigned long  PathLength;
#endif
} tErrorPath;

typedef struct
{
  int           ErrorCode;
  jmp_buf       ReturnPoint;
  unsigned char IsAssigned;
#ifndef CODER_REMOVE_PATH
  tErrorPath    ErrorPath;
#endif
} tEMS;

#define EMSInit(coder) \
  { (coder)->EMS.ErrorCode = 0; \
    (coder)->EMS.IsAssigned = 0; }

#include "ems/ems.h"

/* MMS */

typedef struct sMMSItem tMMSItem;

struct sMMSItem
{
  void*     MemPtr;
  size_t    MemSize;
  tMMSItem* Next;
};

typedef struct
{
  tMMSItem* MMSFirst;
} tMMS;

#define MMSInit(coder) \
  (coder)->MMS.MMSFirst = NULL;

#include "mms/mms.h"

/* BMS */

typedef void (*tBufAppendBufFunc)(tCoder* Coder, unsigned int len);

typedef unsigned char tBMSMode;

#include "bms/bms.h"

#ifdef CODER_BMS_SMALLBUF
typedef tBMSSmallBuffer tBMSBuffer;
#elif defined(CODER_BMS_USERBUF)
typedef tBMSUserBuffer tBMSBuffer;
#else
typedef tBMSBaseBuffer tBMSBuffer;
#endif

typedef struct {
  tBufAppendBufFunc AppendFunc;
#ifndef CODER_REMOVE_PATH
  tBufErrInitFunc   ErrInitFunc;
#endif
  tBMSMode          Mode;
  tBMSBuffer        BMSBuffer;
} tBMS;

#ifndef CODER_REMOVE_PATH
#define BMSInit(coder) \
  { (coder)->BMS.AppendFunc = NULL; \
    (coder)->BMS.ErrInitFunc = NULL; \
    (coder)->BMS.Mode = bms_NoMode; }
#else
#define BMSInit(coder) \
  { (coder)->BMS.AppendFunc = NULL; \
    (coder)->BMS.Mode = bms_NoMode; }
#endif
/* VMS */

#include "vms/vms.h"
#include "vms/vms_type.h"
#include "vms/vms_base.h"
#include "vms/vms_print.h"
#include "vms/vms_macro.h"
#include "vms/vms_export.h"

typedef struct {
  tASN1TypeInfo* Type;
#ifndef CODER_REMOVE_PATH
  void*          Value;
#endif
} tVMS;

#ifndef CODER_REMOVE_PATH
#define VMSInit(coder, type, value) \
  (coder)->VMS.Type = type; \
  (coder)->VMS.Value = value
#else
#define VMSInit(coder, type, value) \
  (coder)->VMS.Type = type
#endif

/* ER */

typedef unsigned long tERRule;

typedef struct
{
  tERRule        Rule;
  unsigned long  ValueBitLength;
  unsigned char* MemStart;
  unsigned char* MemEnd;
  unsigned char* DataEnd;
  unsigned char* DataCurr;
  unsigned char  BitEnd;
  unsigned char  BitCurr;
} tER;

#define ERInit(coder) \
  { (coder)->ER.Rule = CUCF_ER_DEFAULT; \
    (coder)->ER.ValueBitLength = 0; }

#ifdef CODER_NOUSE_OPEN
#define ER_OLIST(List)
#else
#define ER_OLIST(List) ,List
#endif

#include "cucf_er.h"

/* Coder */

#ifdef CODER_USER_DATA
#include "user_data.h"
#else
typedef void* tUserData;
#endif

struct sCoder {
  tEMS            EMS;
  tMMS            MMS;
  tBMS            BMS;
  tVMS            VMS;
  tER             ER;
  tUserData       UserData;
  unsigned char   IsAssigned;
};


#ifdef CODER_VMS_SDT
#include "cucf_er_sdt.h"
#endif

#ifdef CODER_VMS_TTCN
#include "cucf_er_ttcn.h"
#endif

#endif /* __cucf_h */
