#ifndef __CCOMMON_H
#define __CCOMMON_H

#define         M_TERMINFO

#ifdef __WATCOMC__
#pragma aux MS_C "_*" parm caller [] value struct float struct routine [ax] modify [ax bx cx dx es];
#endif 

#ifdef XVT
#include <xvt.h> 
#undef BOOLEAN
#include <checks.h>
#endif

#ifdef __GNUC__
#define __PACKED__ __attribute__ ((packed))
#define __ALIGNED__ __attribute__ ((aligned(2))) 
#define __PACK_1__
#else
#define __PACKED__
#define __ALIGNED__
#endif

#ifdef DOS
#include        <stdio.h>
#include        <stdlib.h>
#define         _NO_STDIO
#include        <ctype.h>
#include        <string.h>
#include        <errno.h>
#include        <time.h>
#include        <fcntl.h>
#include        <signal.h>
#else
#ifdef __cplusplus
#include        <stddef.h>
#include        <stdio.h>
#include        <stdlib.h>
#define         _NO_STDIO
#include        <sys/types.h>
#include        <string.h>
#include        <ctype.h>
#include        <errno.h>
#include        <time.h>
#include        <fcntl.h>
#include        <signal.h>
#include        <setjmp.h>
#else
#include        <stdio.h>
#include        <stdlib.h>
#include        <sys/types.h>
#include        <ctype.h>
#include        <string.h>
#include        <errno.h>
#include        <time.h>
#include        <fcntl.h>
#include        <signal.h>
#include        <setjmp.h>
#endif
#endif

#ifdef __LONGDOUBLE__
typedef unsigned int word;
#define ELLIPSES ...
#else
#include        <gm.h>
#endif

#if !defined(__MSHELL_H) && !defined(FOXPRO)
#include        "mshell.h"
#endif

#define         CHR(c)                                  (c)
#define         ORD(c)                                  (c)
#define         ODD(c)                                  (((c) % 2) != 0)
#ifdef DOS
/* @(!) 2.3.01.316 modif.  #define         TMPFNAME(p,n)           sprintf(p, "\\tmp\\%s.tmp", (n));       */
#define         TMPFNAME(p,n)           tmpfname((p),(n))
/* @(:) 2.3.01.316 */
#define         DIRSEP                                  '\\'    
#else
#define         TMPFNAME(p,n)           sprintf(p, "/usr/tmp/%s%-d", (n), getpid());    
#define         DIRSEP                                  '/'     
#endif
#define         HIDDEN                                  static
#define         UPCASE(c)                               toupper(c)
#define         LOWCASE(c)                      tolower(c)
#define         LENGTH(s)                               strlen(s)
#define         STREMPTY(s)     (!(LENGTH(s)))
#define         STRNOTEMPTY(s)  (!STREMPTY(s))
#define         STRCMP(s1,op,s2)        (strcmp(s1,s2) op 0)
#define         CSTR(n,s)                       sprintf((s), "%-d", (n))
#define         CSTR4(n,s)                      sprintf((s), "%-ld", (n))
#define         MAXDATA                                 cpackdata("31-12-50")
#define         MINDATA                                 cpackdata("01-01-51")
#define         EMPTYDATA                               cpackdata("  -  -  ")
#define         MONTHNAME(i)            months[(i) - 1]
#define         CCONVINT(s)             atoi(s)
#define         CONVLONG(s)             atol(s)
#define         BADR(x)                                 ((x) - 1)       
#define         WINHND(hw)                      warr[(hw)].w
/* @(!) 2.3.01.69 */
#define         WINHNDB(hw)                     warr[(hw)].wb
/* @(:) 2.3.01.69 */
#define         WINFLD(hw,f)            warr[(hw)].f
#define         POSTWIN(hw)                     WINFLD(hw,posted)       = TRUE  
#define         UNPOSTWIN(hw)           WINFLD(hw,posted)       = FALSE 
#define         CCLEAREOL(w)            xwclrtoeol(WINHND(w))
#define         CCLEAREOS(w)            xwclrtobot(WINHND(w))
#define         CCLEARWIN(w)            xpaint(WINHND(w), setattr[warr[(w)].bkat][iscolordisp])
#define         INSET(c,s)                      (ustrchr((s), (c)) != (uchar *) NULL)
#define         CBITTEST(w,p)           (((w) & (0x0001 << (p))) != 0)
#define         CBITSET(w,p,v)  ((v) ? ((w) |= (0x0001 << (p))) : ((w) &= (~(0x0001 << (p)))))
/* @(!) 2.3.01.temp */
#ifdef M_I386
#define         BOOLEAN                                 short
#else
/* @(:) 2.3.01.temp */
#define         BOOLEAN                                 int
/* @(!) 2.3.01.temp */
#endif
/* @(:) 2.3.01.temp */
#define         NoErr                                           0
#define         BADSIG                                  (int (*)()) -1
#define         MAXMENUITEM         21
#define         MAXWIN                  20
#define         MAXBORDERS                      8
#define         MAXATTRS                        20
#define         BackCh                  '_'
#define         directory       "dir.gen"
#define         ntrrec          "trc.gen"
#define         nditta          "dta.gen"
#define         printers                                "prt.gen"
#define         prcodes                                 "prc.gen"
#define         WWMESS                                  0
#define         WWBAR                                           1

/* gia' definito in gm.h
   typedef         unsigned int    word;
   */
typedef unsigned char           byte;
#ifndef DOS
typedef unsigned char           uchar;
#endif
#ifdef XVT_OS
#ifdef DOS
typedef unsigned char           uchar;
#endif
typedef   long       HWND;
#else
#endif
typedef struct  {
  char    nome[52] __PACKED__ ;
  char    indirizzo[32] __PACKED__ ;
  char    citta[32] __PACKED__ ;
  char    cap[6] __PACKED__ ;
  char    partiva[12] __PACKED__ ;
  char    codfisc[18] __PACKED__ ;
  /* @(!) 2.3.01.temp */
#ifdef M_I386
  short   numero __PACKED__ ;
  short   tab0[20] __PACKED__ ;
#else
  /* @(:) 2.3.01.temp */
  int             numero;
  int             tab0[20];
  /* @(!) 2.3.01.temp */
#endif
  /* @(:) 2.3.01.temp */
  long    tab1 __PACKED__ ;
  char    nome1[52] __PACKED__ ;
  char    indirizzo1[32] __PACKED__ ;
  char    citta1[32] __PACKED__ ;
  char    cap1[6] __PACKED__ ;
  char    partiva1[12] __PACKED__ ;
  char    codfisc1[18] __PACKED__ ;
} TDitta;
typedef char    Str8[9];
typedef char    Str25[26];
typedef char    Str30[32];
typedef char    Str80[82];
typedef char    Str255[256];
typedef uchar   StCh[256];
typedef long    TrDate;
typedef struct  {
  char    name[26];
  char    explic[82];
} MenuItem;
typedef MenuItem        MenuArray[MAXMENUITEM + 1];
typedef char                    PathSt[42];

extern Str80            cprefix;
extern TDitta           cditta;
extern TrDate           dt;
extern Str8             sdt;
extern char             months[12][12];
extern BOOLEAN          iscolordisp;

#ifdef __cplusplus
extern "C" {
#endif
  uchar *ustrchr(uchar *, uchar);
  uchar *setof(uchar *, ELLIPSES);
  uchar *delset(uchar *, ELLIPSES);
  int positn(char *, char *, int);
  void cdate(char *);
  void ctimeloc(char *);
  uchar CReadKeyb(void);
  char *ToASCIIZ(char *);
  char *ToASCII(char *);
  void CDispStatus(char *); 
  BOOLEAN cverdata(char *);
  TrDate cpackdata(char *);
  void ceditdata(TrDate ,char *);
  void cgetdata(TrDate *,char *);
  void cputdata(char *);
  int month(TrDate);
  int year(TrDate);
  int day(TrDate);
  TrDate makedata(int,int,int);
  TrDate addmonth(TrDate,int);
  TrDate addyear(TrDate,int);
  void cgettime(char *);
  char *CCopy(char *,int ,int );
  int CBitPos(int );
  BOOLEAN CGetAut(int );
  char *CGetConf(int );
  void CMaskP(char *,char *,int , int);
  char *CUpString(char *);
  char *CLowString(char *);
  /* @(!) 2.3.00.21 */
  char *strfset(char *, char *);
  /* @(:) 2.3.00.21 */
  char CSetDrive(char );
  char CGetDrive(void );
  int CMkDir(char *);
  int CRmDir(char *);
  int CChgDir(char *);
  int CRenameFil(char *,char *);
  int CRenameDir(char *,char *);
  int CGetDir(char *);
  long CDiskSpace(char );
  void CSetString(char *,char *,BOOLEAN, BOOLEAN, int ,int ,char );
  BOOLEAN ckeypress(void );
  void genhelp(void );
  uchar CReadKeyb(void );
  char *esc(char *);
  void CInitProg(void );
  void CEndProg(void );
  int execprog(int ,char *, ELLIPSES);

#ifndef __LONGDOUBLE__  
  void CEditDec(DEC *,int ,int ,char *);
  void CConvDec(char *,DEC *);
#endif

  int CIOResult(void );
  TDitta *CGetDitta(char *);
  void CPutDitta(char *,TDitta *); 
  void CClearKb(void );
  void crtrim(char *);
  void cltrim(char *);
  void CSplitString(char *,int ,char *,char *);
  void CSpace(char *, int);
  uchar editpref(BOOLEAN, BOOLEAN, BOOLEAN); 
  char    **getlinefd(char        *, char, char);
  word getkeyid(void);
  void addtokeybar(char *, word);
  void delfromkeybar(word);
  uchar *setofkeybar(word);
  /* @(!) 2.3.01.134 */
  uchar *strsetofkeybar(char *);
  /* @(:) 2.3.01.134 */
  /* @(!) 2.3.01.223 */
  void suspendkey(char *);
  void resumekey(char *);
  /* @(:) 2.3.01.223 */
  /* @(!) 2.3.01.316 */
#ifdef DOS
  void tmpfname(char *,char *);
#endif
  /* @(:) 2.3.01.316 */
#ifdef __cplusplus
};
#endif
#endif /* __CCOMMON_H */
