/****************** CYBEX 0WS Include ***********************/

#include "w2.h"

extern int      Ing_Mihula_2;

extern int      Share;

extern char     Xfntpath[81];

/*************** SM gate labels *******************/

enum {
	PRT_GFONT = 1, PRT_XFONT, SPELLER, THESAURUS, PRT_LASER
};

/*************** TMEM gate labels *****************/

enum {
	TM_SPELLER = 1, TM_LASER
};

/******************************* Interface ********************************/

#define INTERFACE

/*
#include "dbf.cpp"
#include "progress.cpp"
#include "listbox.cpp"
#include "selector.cpp"
*/

/*
#include "calendar.cpp"
#include "cardfile.cpp"
*/

#undef  INTERFACE

/*************** Writer.H definitions *************/

#define        TULN       0X0001/*16*/
#define        TBLD       0X0002/*17*/
#define        TITA       0X0004/*18*/
#define        TSPS       0X0008/*19*/
#define        TSBS       0X0010/*20*/
#define        THGH       0X0020/*21*/
#define        TDBL       0X0040/*22*/
#define        RDBL       0X0080/*23*/

#define        TUS1       0x0100
#define        TUS2       0x0200
#define        TUS3       0x0300
#define        TUS4       0x0400
#define        TUS5       0x0500
#define        TUS6       0x0600

#define        TUSX       0x0700

#define        TFNT       0x0800/*27*/

#define        TOCT       0X1000/*28*/
#define        TIDX       0X2000/*29*/
#define        TMMG       0X4000/*30*/
#define        MARK       0X8000/*31*/

#define        TVIS       (TULN|TOCT|TIDX|TMMG|MARK|TFNT|TUSX)

#define        CONDENS    1
#define        AUTOPAGE   2
#define        MARKER     3
#define        HARDCR     4
#define        HARDPAGE   5
#define        IMAGE      6
#define        NOIMAGE    7

#define        XCODE      8

#define        R05        0
#define        R10        1
#define        R15        2
#define        R20        3

enum texttypes {
	DETECT = -1, MAT = 0, ASCII, T602CS, T602LT, ASCIIDOC, WORDPERFECT,
	WINWORD, DBFIMPORT1, DBFIMPORT2, VENTURA, T602KO, MAT_CRYPT, AZBUKA
};

#define C_KEYBCS    0x010
#define C_LATIN     0x020
#define C_WINCS     0x040
#define C_KOI8      0x080
#define C_MACCE     0x100

#define ispitchsq(c)   (c=='A'||c=='B'||c=='C'||c=='J'||c=='E'||c=='N')

enum blkselections {
	NOSEL, BLOCK, COLUMN, DRAGBLOCK, TEXTFOUND
};

enum vals {

	WORKSPACE=IDC_USER,

	VSCRLR, HSCRLR,
	
	WINCLOSE, WINZOOM, WINSIZE, WINSWAP,

	WINDOW0, WINDOW1, WINDOW2, WINDOW3, WINDOW4, WINDOW5, WINDOW6, WINDOW7,

	DESKFORM, MATFORM, RULER, SETFORMAT,
	CTABLE, ETABLE, FTABLE, SPELLING,
	STORESOME, STOREALL, KEYMENU, MOUSEMENU, SETCOLORS,
	SETWORDWRAP, SETJUSTIFY, SETJOINWORDS, SETDIWORDS, SETAUTOTAB, SETHARDCRS,
	SETSHOWSS, SETSHOWIMG, SETGRAFORM, SETSPELLING, SETINDENT,
	SETR10, SETR15, SETR20,
	PRTINSTALL, SETRULER,
	LOCK,	MACRO, ABOUT, REPLACEALL, INSERTTIME, INSERTDATE, GLOBAL,
	SINGLESTYLES, SORTBYCOLUMNA, SORTBYCOLUMND, EXPORT, IMPORT,
	SETIMAGE, EXPRESSION,
	SETXFNT, SETHDRFTR,
	HEADER1, HEADER2, FOOTER1, FOOTER2, DBF,
	FILETYPE, SAVEALL, WREPLACE,
	JUSTIFY, JUSTIFYC, UNJUSTIFY, UNJUSTIFYC,
	KEYBEDIT, SETAUTOFONT,
	NEWFILE, LANGUAGE, SETAUTOFORM, DOSSHELL,
	CASCADE, TILE, TILE1, TILE2,
	LASTMATID, SEARCH, UNJUSTIFYR, CALENDAR, SPELLFROM, CRYPT,
	
	FILE0, FILE1, FILE2, FILE3, CARDFILE,
	TRADIC
};

/******************* MAIN  *********************/

enum   GLOBALEVENTS { GLBL_OK = 0, OUT_OF_MEMORY, INTERNAL_ERROR,
                      _INTERNAL_ERROR };

extern jmp_buf Globaljmp;
void   mcset(void);

extern char  userdir[81];

char *homefile(char *s);

char *userfile(char *s);
char *shellfile(char *s);

char *backupname(int n);
char *nameofbackup(int n);

/******************************** Wcaption ********************************/

#define  CPS_EOS      0x01

class Wcaption : public Wlabel {
public:
	virtual void      paint();

protected:
	        int       state;
	        word      style;

public:
	        void      set(int l, char *atext, int r, int astate);

	Wcaption(Wobject *parent, word style);
};

/******************************** DESKTOP *********************************/

extern int   Doingframe;

class MatDesktop : public Desktop {
public:
	        Wobject *d1, *d2, *d3;
	virtual void     menudesc(int n);
	virtual void     desktoppaint();
	
	        void     edititems(int v);
	        void     editpars();
	        void     formingitems(int v);
	        void     toolitems(int v);
	        void     normalchar(int v);
	        void     normalline(int v);
	        void     framemenu(int no);
	        void     formatitems(void);
	        void     charitems();
	        void     bcmc(void);
	        void     blkmenu(int no);
	        void     clmmenu(int no);
	        void     picitems(int v);

	MatDesktop();
};

extern MatDesktop *Matdesk;

void  cicon(int c, int a);

class Chartab : public Window {
public:
	virtual void   paint();
	virtual int    event(Event *e);
	
	        void   paintchars();

	        int  c0;
	        int  dt;
	
	Chartab(int c0) : c0(c0), dt(0) {}
};

extern Chartab *ct1, *ct2;

/*************** Text position system **********/

#ifdef __FLAT__
#define MAXLINE 99999999
#else
#define MAXLINE 32700
#endif

class Text;

typedef struct {/******* MATASM.ASM dependent Structure !!! */
	int   line;       //16 = 0  | 32 = 0
	long  offset;     //16 = 2  | 32 = 4
	int   pageno;     //16 = 6  | 32 = 8
	int   pageline;   //16 = 8  | 32 = 12
	int   picline;    //16 = 10 | 32 = 16
	char  *pic;       //16 = 12 | 32 = 20
	long  picoffset;  //16 = 16 | 32 = 24
	int   pitch;      //16 = 20 | 32 = 28
	int   font;       //16 = 22 | 32 = 32
	
	void  bindpic(Text *t);
	void  bindpictxt();
} LP;

typedef struct position {
	int  scx, scy;
	int  cx, cy;
} POS;

enum TextParts {
	HDR1, HDR2, FTR1, FTR2, MAINTEXT
};


class Text : public Window {
public:
	virtual void  redraw(Rect *r);
	virtual int   event(Event *e);
	virtual void  neworder();
	virtual void  makesubpanes();
	
	        Pane  txb[1];
	        Pane  txp[1];

           int   inuse;
	        int   active;

           Text();
           
           int   rx()    { return txp->xx - txp->x; }
           int   ry()    { return txp->yy - txp->y; }

	        Wicon     closer;
	        Wicon     zoomer;
	        Wrepicon  sizer;
	        Wicon     swaper;
	        Wcaption  caption;
	        Wscrlbar  hscrl, vscrl;
	        Warea     locker, marginer;
	        
	        int       tracking;

	        void      paintframe();
	        Rect      prevsize[1];
	        int       zoomed;

public:
	        word      pgs[5];
   
   int    type;

   int    locked, view;
   int    changed, bchanged;
   int    compiled;
   
   word   edpars;
   int    aspaces;

	int    mf;
	int    format;

	int    part;
	long   hf[4];
	int    lastpart;

	long   offset;
	long   len;
	int    ll;

	LP     scx[1];

	int    scy;

	int    cx, cy;
	
	int    sel;
	int    selx, selx2, sely, sely2;
	
	int    oll, oscx, oscy;

	POS    pos[1], rpos[1];

	int    hmargins;
	int    lem, rim;
	int    lem1, rim1;
	char   rt[256];
	
	int    id1st, idnxt;
	
	int    tom, bom;	
	int    lfs;
	int    page1st;
	int    prtlm, prtlme;
	int    prtum;
	int    hdr, ftr;
	int    hfwidth;
	int    pagelen;

	int    repaint;
	int    paintline;
	int    paintpl;

	char   name[81];

// MAT 3.1 addons
	char   longname[65];
	int    crypted;
	byte   IV[9];
	int    chstyle[5];
	int    ch1st;
	int    tables;
	int    widows;
	int    pictures;
	int    pagech;
};

LP   *lp_reset(LP *lp);
char huge *lp_gofw(LP *lp, Text *t, int x, char huge *lim);

char huge *t_line(Text *t, LP *lp, int x);

char huge *lp_line(LP *lp, int x);
char huge *lineptr(int x);

void  scxgoto(int x);
void  incscx(void);
void  decscx(void);
void  scxreset(void);
void  scxredo(void);

void  lp_gotopg(LP *lp, int n);
int   txt_pgcount(void);

typedef struct {
	char  huge *ptr;
	int   hardcr;
	int   face;
	int   code;
	int   chr;
	int   x, y;
	int   lo;
	int   hardpage;
	int   pageline;
	int   pageno;
	char  *pic;
	int   picline;
} TP;

void  tpgetit(TP *p);
void  tpnext(TP *p);
void  tpgoto(TP *p, int x, int y);
void  tpgotopage(TP *p, int n);
void  tpgotopagef(LP *lp, TP *p, int n);
void  tpgotopart(TP *p, int part);

void  possave(POS *a);
void  postxtbeg(POS *a);
void  posrestore(POS *a);
void  posrecal(POS *a);
void  posrestorea(POS *a, int d);

int   hfollows(char huge *t, char huge *lim, int i);

/************* DISPLAY ***************/

void txt_caret();

void getblock(Text *t, int &sxl, int &syl, int &sxh, int &syh);

void paintall();
void txt_repaint(Rect *r);
void txt_repaint(int x, int y, int rx, int ry);
void txt_repaint(Rect *r, int l1, int l2);
void getrr(Rect *rr);

void textpaint(Text *t, int cx1, int cx2);
void paintpgs(Text *t, int cx1, int cx2);

void opst();
int  twupdate();

void  paintlh(Text *t, int a, int pd, int opd, int seq, int mark);

void  ruler(void);

void  showtime();
int   clock();

/****************** IMAGES *********************/

void *get_img_mem();

char *getpicline(char *name, int rx, int ry, int rl, int line, int n,
							int invert, char *textpath);
void  pic_round(char *p, char *textpath);
void  pic_prget(char *p, int mode, int *rx, int *ry, char *textpath);

/**************** Part system ******************/

char huge *t_beg(Text *txt);
char huge *t_lim(Text *txt);
char huge *t_ptr(Text *txt, long offset);
long t_offset(Text *txt, char huge *ptr);

#define           MAXF            16
#define           MAXTEXTNO       8

extern long  Total_Mem;
extern char  huge *Memory;

void  mf_init();

char  huge *mf_beg(int mf);
long  mf_len(int mf);
char huge *mf_lim(int mf);
char huge *mf_ptr(int mf, long offset);
long  mf_offset(int mf, char huge *s);
long  mf_avail(void);
void  mf_leave(long newlen);
long  mf_enter(int mf);
int   mf_get(void);
void  mf_remove(int mf);

int   txt_resize(long offset, long oldlen, long newlen);

extern int tmemlbl;

int   testtmem();
long  gettmemsize();
char huge *gettmemptr(int);

void  parstotxt(Text *t);
void  txttopars(Text *t);

void  txt_enter(Text *t);
void  txt_leave(void);
char huge *txt_beg(void);
char huge *txt_lim(void);
char huge *txt_ptr(long offset);
long  txt_offset(char huge *ptr);
void  txt_llcount(void);
void  txt_takepart(void);
long  txt_partoffset(int part);
char huge *txt_partptr(int part);
int   txt_hfllcount(int part);
void  txt_part(int a);


/***************** ONE TEXT ********************/

typedef struct {
	int  Marker;
	int  Hardcr;
	int  Hardpg;
	int  Iline;
	char Image[96];
	int  High;
	int  Hf;
	int  Efree;
	int  Elem;
	int  Elen;
} Lattr;

extern Text	*txt;
extern long	Txtlen;
extern long	Txtmaxlen;

extern char	  Line[257];
extern int	  Face[257];
extern char   Code[257];
extern long	  Lineoff;
extern int	  Linelen;
extern Lattr  Lineattr[1];
extern LP     Linelp[1];

extern int    Linechanged;

void  clearline(char *line, int *face, char *code);
int   clndline(void);
int   loadline(char huge *s, char *Line, int *Face, char *code, Lattr *la);
void  enterline(void);
void  clrline(void);
int   linelength(char *Line, int *Face, char *Code);
int   linelen(void);
int   linelc(void);
int   stylelen(int a);
char huge *stylesto(int a, char huge *s);
void  leaveline(void);

/******************************** TEXTWIN *********************************/

void txt_clear();
int  txt_load(char *s, int type);

void editlongname();
void sextfiletype();

int  saveas();
int  opentext(int x, int y, int rx, int ry, char *s, int type);
void newfile();

void reloadtext();
void del0file(char *file);
int  closefile(int ask, int mruregister);
void saveall();
void saveall(int beep);

/**************** CURSOR & ... *****************/

int   locked();
void  txt_dirty();

int   lineinsert(int a, int n);
int   insertchar(int a);
void  linedelete(int a, int n);

void  patest(void);

int   rtest(char huge *s);
int   rtestln(int ln);

void  bindcydbl(void);
void  bindcydblr(void);

void  scxcredo(void);
int   txt_lem(void);
int   txt_rim(void);

extern int   divid;
void   curwordwrap(int jsf, int lem);

void  putkey(int key, int style, int insert, int wordwrap, int lm);

void  curbound(void);
void  cgoto(int cx, int cy);
void  curgoto(int x, int y);
void  curgo(int x, int y);
int   curinschar(void);
void  curdelchar(void);
int   curchar(void);
int   curface(void);
int   curcode(void);
void  curset(int c, int f);
void  cursetf(int c, int f);
void  cursetfc(int c, int f, int o);
void  cursetkey(int c, int f);
void  curiup(void);
void  curidown(void);
void  curskiprup(void);
void  curskiprdown(void);
void  curup(void);
void  curdown(void);
void  curlbegin(void);
void  curlend(void);
void  curtbegin(void);
void  curtend(void);
void  curleft(void);
void  curright(void);
void  curwright(void);
void  curwleft(void);
void  curinsline(int r);
void  curnewline(int r);
int   curcatline(void);
void  curaddline(void);
void  curbckspc(int del);
void  curdelline(void);
void  curscrlup(void);
void  curscrldo(void);
void  curpageup(void);
void  curpagedo(void);
void  curscrlle(void);
void  curscrlri(void);
void  curfscrlle(void);
void  curfscrlri(void);

void  curhsdrag(Event *e);
void  curvsdrag(Event *e);

void  curgotomouse();
void  curmousepos(int &x, int &y);
int   mouseintxt();

int   autotest();

int   indentcy();
int   indent1st();
int   indentnxt();

int   curtestr(void);
int   cursetr(int newr);
int   cursetstyle(int cy, word style);
int   cursetStyle(int cy);
void  curdownnl(void);

void  sstyleset(int ss);

/******************************* Formating ********************************/

void  unjustify(int from, int to);
void  justify(int from, int to, int uto);
void  centre(int from, int to);

void  reform(int x1, int y1, int x2, int y2, int begin, int lem);
void  preformer(int all, int lem, int smart);

/****************** FILES    *******************/

int  matlongname(char *file, char *lname);

extern File file;

int   load_file(char *s, int type);

int   savefile(char *s, int nodelbak);
int   save();

extern int  contester;
void  filecon(void);

extern int impn, expn;

extern Filework eximp[1];
extern int icode[8];
extern int ecode[8];
extern int impexti[8];
extern int expexti[8];

int   savecrlf(void);

void  import();
void  export();

/******************************* CRYPT MODE *******************************/

void cryptform();

int  makeIV(char huge *s, long l, byte *IV, int version);
int  Cwrite(int d, long l, char huge *s, byte *IV);
int  Cread(int d, long l, char huge *s, byte *IV, int version);

/******************* VARS *********************/

void writeconfig();

enum Language_types {
	CZECH, SLOVAK, GERMAN, GB, USA
};

extern int   Backprint;
extern File  Backfile;
extern byte  Backbuffer[512];
extern int   Backpriority;

extern int   Cryptmode;
extern char  Password[21];

extern int   Longnames;

extern int   Indent, Showimg;
extern int   Backups, Latin2, Auto602, Savetime, Asound, Diwords;
extern int	 Insert, Wordwrap, Justify, Joinwords, Ctable, Hardcrs;
extern int   Autotab, Aspaces, Graform, Savedesk;
extern int   Etable, Ftable;
extern int   Spelling;
extern int   BeepSpell, ShowSpell;
extern int   Autoindent, Ender;
extern int   Autofont;
extern int   Autoform;
extern int   Teditpars;
extern int   Rtype;
extern int   Ditd, Drcd;
extern int   Insc, Rwrc;
extern int   Style, Usno, SStyles;
extern int   Actualdir;
extern int   Gotopg, Gotono;
extern int   Frame, Framed;
extern int   Language, SpellAlts, SpellLtrs;
extern char  Usl[5][81];

extern int   Dictype;
extern int   IsDic;

extern int   RevueEdit;

extern int   Nsaves;
extern int   CxlKeys;

extern int   One_normal;

extern int   Stdfile;
extern char  Stdfilename[81];

extern Filework Xfntfile[1];
extern Filework fwimage[1];
extern Filework fwusl[1];

extern int   pl_rx, pl_ry, pl_inv, pl_scl, pl_brdr;
extern int   stype;
extern int   sml;

extern char  clipline[256];
extern int   clipface[256];
extern char  clipcode[256];
extern int   clipflag;
extern int   cliphardcr;
extern int   cliplen;

extern int   Topw;

extern char  ext[8][4];

extern Filework files[1];

extern char  shelldir[81];
extern char  mrufile[4][81];

extern char  fstring[37];
extern char  rstring[37];
extern int   fword, fcase, ffrom, fgstyle, fgcase, fdiv, fwcs;
extern int   found;

extern char  ex[70];

extern int   alarm, ahour, amin;

extern Text  text[MAXTEXTNO];


void locktext();
void swapmargins(void);
void truemargins(void);
void clipccdel(void);
void clipcopyline(void);
void lsetstyle(int a);
void lenbound(void);
int  pslides(int a);

void mainconfig(void);

void clipccdel(void);

/****************** Accesories *******************/

int  kqkey(int k, int *tab);

void  spell_init(int reinit);

void  setadir();

char *datestring(int d);
char *timestring(void);
void  togglesq();
void  getcalc(int type);
void  getcalc();

void  wreplace(int style);
void  wreplace(void);
void  cascade();
void  tile();
void  tile1();
void  tile2();

/******************************** MAINLOOP ********************************/

extern int  keyplus;
extern Event *event;

void autoreform();
void smartreforms();
void mainloop();

/**************************** Dispatch area 1 *****************************/

void cdbackspace();
void cddelete();
void cddelword();
void cddelline();
void cdcpyline();
void cdctrlx();
void cdctrlhome();
void cdenter();
void curtab();
void curbcktab();
void curhome();

/**************************** Dispatch area 2 *****************************/

void  cdown();

void  findmark();
void  setmark();
void  dospell();
void  dospellfrom();
void  dofind();
void  dosearch();
void  dofindnext();
void  dofindword();
void  refcur();
void  refucur();
void  refpar();
void  smartreform();
void  swhcr();
void  paste();
void  overpaste();
void  centreline();

void  cursetstyle();
void  linesetstyle();
void  curlnsetstyle(int style);
void  pasteline();

int  stylekey(int key);
void takestyle();

/**************************** Dispatch area 3 *****************************/

void dragwin();
void zoomwin();
void sizewin();
void scrollwin();
void gototext();
void makehp();

void  settoct();
void  settidx();
void  setidxword();
void  settoctline();
void  resetsf();
void  setmmg();
void  resetsfline();

void  unjustlinec();
void  unjustline();
void  justlinec();
void  justline();
void  unjustifyright();

void  placepic();
void  insertpic();
void  sizepic();

void  header1();
void  header2();
void  footer1();
void  footer2();
void  maintext();
void  sethdrftr();

void  insertdate();
void  inserttime();

void  rulerhit(Event *e);
void  toggletab();
void  leftmarg();
void  rightmarg();

void  showpreview();
void  refreshtext();
void  cursbegin();
void  cursend();
void  dosave();
void  dogoback();

/**************************** Dispatch area 4 *****************************/

void  about();
void  loadxfnt();
void  setfileform();
void  exitmat();
char *swapfile();
void  dosshell();
void  setalarm();

/******************* SEARCH *************************/

int   findfrom(int all, int block, int replace);
int   findmark(int cx, int cy);
int   findform(void);
int   searchform(void);
int   bfindform(void);

/******************************** Block A *********************************/

void scrappaste(void);
void blockdelete(int x1, int y1, int x2, int y2);

/********************************* Blocks *********************************/

extern int   sml;

extern int   sclines;
extern int   scclmns;
extern char  slb[256];
extern int   sfb[256];
extern char  scb[256];
extern Lattr slab[1];

extern int   srtb;
extern int   sfrom;
extern char  sle[256];
extern int   sfe[256];
extern char  sce[256];
extern Lattr slae[1];

extern int   sto;

extern char *bcb;
extern int   bcbi;

void  bcop(int x1, int y1, int x2, int y2, 
           void (*op)(int from, int to), int t);
void  blockop0(int x1, int y1, int x2, int y2, void (*op)(int from, int to));
void  slupdate(void);
void  sluinit(void);
int   bcinsdel(int k);
void  ltoupper(int a, int b);
void  ltolower(int a, int b);
void  ltoanthr(int a, int b);
void  ltobcb(int a, int b);
int   gexpdo();
int   letterindex();
void  goletter(int a);
void  blkprepare();

int   blksetr(int x1, int x2);
void  sreform();
void  preform(int x1, int x2, int smart);
void  lenbound(void);
int   scrapcopy(int x1, int y1, int x2, int y2);
void  blockop(int x1, int y1, int x2, int y2, void (*op)(int from, int to));
void  blkleft(int a, int b);
void  blkright(int a, int b);
void  blkunj(int a, int b);
void  blkjust(int a, int b);
void  blkcentr(int a, int b);
void  blkstyle(int a, int b);
void  blockop(int x1, int y1, int x2, int y2, void (*op)(int from, int to));
void  blkchangestyle(int stk);

void  columnop(int x1, int y1, int x2, int y2, void (*op)(int from, int to));
void  clmchangestyle(int stk);

void  clmstyle(int a, int b);
void  clmleft(int a, int b);
void  clmright(int a, int b);
void  clmunj(int a, int b);
void  clmjust(int a, int b);
void  clmcentr(int a, int b);
void  columnop0(int x1, int y1, int x2, int y2, void (*op)(int from, int to));
void  clmclr(int y1, int y2);
void  clmcut(int y1, int y2);
void  clmsto(int y, int y2);
char huge *clmclip(int rx, int ry);
int   clmscrap(int x1, int y1, int x2, int y2, void (*fun)(int x, int y));
int   clmsort(int x1, int y1, int x2, int y2, int desc);
void  clmcompute(int x1, int y1, int x2, int y2);
void  conblock(void);
void  clmnumber(int x1, int y1, int x2, int y2);
void  clmpaste(int insert);
void  columnop(int x1, int y1, int x2, int y2, void (*op)(int from, int to));

void  block(int saa);
void  block();

char  huge *clmclip(int rx, int ry);
void  columnop0(int x1, int y1, int x2, int y2, void (*op)(int from, int to));
int   clmsort(int x1, int y1, int x2, int y2, int desc);
void  clmpaste(int insert);

void  column(int saa);
void  column(void);

void  conblock(void);

/************** Compilation - MAILMERGE ************/

void compilefile(char (*cd)[128], char (*cn)[13]);
void compile(void);

/*************** DBF browser **************/

void  condbf(void);
void  dbf_browse(void);

long  dbf_compile(long a, Dbf *dbf);

/************** Semigraphics ***********************/

extern char  Frames[11][16];
extern int   Frame, Framed;
extern int   Fdraw, Fclear;
extern int   Begx, Begy, Endx, Endy;

void  showframes();
void  frames();
int   infx(void);
int   infy(void);

/********* Table of contents & index **************/

void global();
void gotochapter();

/*************** VENTURA ************************/

void venexport(int code);
void conven(void);

/****************************** Dekstop Show ******************************/

void  showstyle();
void  showsets();

/******************** FORMS ************************/

void  styleitems(int e);
void  styleitems(int e);
void  formatitems(void);

void  thebar(void);
void  blkmenu(int no);
void  clmmenu(int no);
void  filetype(void);
void  fileform(void);
void  mymenu(int no);
void  matform(void);
void  formpars(void);

void  spellwarn(void);
void  language();
void  outofmem(void);

int   keybreak(void);

void  pic_form(char *pic);

/******************* PRINTER ********************/

enum outputs { LPT1, LPT2, LPT3, COM1, COM2, COM3, COM4, TOFILE };
enum pagends { MANUAL, SKIPBYLF, SENDFF };

extern int  PrtOut;

extern int  pagend, nlqmode, filemode, swapedges, oddprint, copies;

extern int  backprint;

extern int  paperlen, paperwidth;
extern int  plint, pwint;

extern int  frompage, topage, perpage;

extern int  mstno;
extern char MstFile[8][81];
extern char MstName[8][33];
extern int Prtout[8];

extern Filework Frst[1];

extern Filework Fprt[1];

extern int   printbreak;

void  lptinstall(void);
int   dpreview(void);
void  lprint(void);
void  lprintblock(int cx, int rx);

void  endbackprint();
int   isbackprint();

void  xlatcon(void);
void  prtcon(void);
void  npform(void);
void  printerform(void);

int   lprintform(int tofile);

void  RstInit(void);
int   RstLoad(void);
void  PrtInit(void);
void  PrtDownload(void);
void  PrtEnd(void);
void  RstEnd(void);

void  printit(int from, int to);

/*************** Expression **************/

extern int  bigexp;

int  Gexpress(char *e);
void Gexpress();

/***************** Spelink cecker *****************/

extern int   Nospeller;
extern char *mat_usl;

#define  SPELL_OK       0
#define  SPELL_FIRST  (-1)
#define  SPELL_TAIL   (-2)
#define  SPELL_ERROR  (-3)

int   SPELL_start();
void  SPELL_end();

int   SPELL_word(char *wordstr, int c);

int   SPELL_char(int c);
int   SPELL_ischar(int c);
void  SPELL_ignore(void);
void  SPELL_append(void);
char *SPELL_wordstr();

/******************************* Spellfrom ********************************/

int   spellfrom(void);

/******************************* Thesaurus ********************************/

struct Tword {
	char wordstr[60];
	byte flag;
	byte mode;
};

void   thesaurus();
void   dictionary();

/*************** Assembler interface **************/

extern "C" {
int    cdecl llcounts (char *ptr, long size);
char * cdecl gotos(char *ptr, LP *lp, int c, int pageline);
void   cdecl remap(int sr, char *s, int tr, char *t);
void   cdecl sr_6(char *s, int n);
void   cdecl or_6(char *t, char *s);
void   cdecl c5_img(char *s, int d);
};

/******************************** PRINTER *********************************/

extern int  pagend, nlqmode, filemode, swapedges, oddprint, copies, allcopy;

enum PrinterTypes {
	PREVIEW, PIN9, PIN24, LASER, PCXFAX, DESKJET
};

enum PrintingBreaks {
	PRT_OK, PRT_BREAK, PRT_ERROR
};

enum PrintType {
	PRINTALL, PRINTODDEVEN, PRINTODD, PRINTEVEN
};

extern int PrtType;

extern byte *Pfont;
extern int Typ, Dtx, Dty, Atr, Len;

struct Prtcntrl {
	char *ini, *res;
	char *dli, *dls;
	char *grs, *grd;
	char *gs1, *gd1;
	char *rdt, *rdd, *rdm;
	char *odd, *odt, *o05, *o10, *o15, *o20;
	char *tu1, *tu0, *ku1, *ku0, *hi1, *hi0;
	char *di1, *di0, *sr1, *sr0, *vy1, *vy0;
	char *pt1, *pt0;
	char *u1[6], *u0[6];
	char *sq[15];
	char *sqr;
	char *co1, *co0;
	char *ffd;
	char *rvp, *rff, *rvk;
	char *cop;
	char *lfn[32];
	char *su1[8], *su0[8];
	char *xlat[256];
	char font[81];
	char menustr[64];
	char prtpath[81];
};

extern Prtcntrl *Pca;

extern char *Pline;
extern int  *Pface;
extern char *Pcode;
extern char *Pline2;
extern int  *Pface2;
extern char *Plined;
extern int  *Pfaced;
extern char *Plined2;
extern int  *Pfaced2;

extern char  *Ppicptr;
extern int   Ppicline;

extern int   Sq_font, Sq_pitch;

extern File Prtfile;

void  p_char(int c);
void  p_esc(char *s);
void  p_tstbreak(void);

void  GetFont(void);
void  GetXFont(void);

void  PDinit(void);
void  PDend(void);

void  ctrlstr0(char *s, int chr, int dpass);
void  ctrlstr(char *s);

int   ggc(int c, int d);

void  dpassn(void);
void  tpassn(void);

void  Rdm(void);
void  Rdd(void);
void  Rdt(void);

void  clrlfs(void);

void  dolfs(void);

extern unsigned orbuffer[30];
void   clror(void);

int   dialength(char *line, int *face, int *face2, char *code);
int   italength(char *line, int *face, int *face2, char *code);
int   plinelength(char *line, int *face, char *code, char *line2, int *face2);
int   tocodelen(int a, int l);
int   xlength(char *line, int *face, int *face2);

char  *Lfont(int f);
void  clrpstyle(void);
void  resetdbl();
void  prtchrn(int c, int f, int code, int d);

void  clrpage(void);
void  printpage0(int page, int pbox);

/*************************************************************************/

extern int    Antialias;
extern int    Showfonts;

void  vprintline(void);
int   preview(int from, int go);

void  lprintline9(void);

void  lprintline24(void);

extern int  Lposx;
extern int  Jdbl;

void  Lcopies(int n);

void  Lprintline(void);
void  Jprintline(void);

void  lprintlinepcx(void);

void  PCXstart(void);
void  PCXend(void);
void  PCXprintline(void);

void  PCXsetres(int res);
void  PCXsethres(int res);


/******************************** TRC Part ********************************/

int  mwp(char *fn, int code); /* 0 = OK, -1 = creation, -2 = write error */
int  wpm(char *fn, int code); /* 0 = OK, -1 = open, -2 = syntax error */
int  mww(char *fn, int code); /* 0 = OK, -1 = creation, -2 = write error */
int  wwm(char *fn, int code); /* 0 = OK, -1 = open, -2 = syntax error */

/* --------------------------------------------------------------------- */

#define INTERFACE

#include "mstrings.cpp"

#undef  INTERFACE
