#ifndef __CHINESE_H
#define __CHINESE_H


#define MAX_FONT_NUMBER 15200
#define MAX_READ_BUFFER 128
#define HASH2_SIZE      20


#include <stdio.h>
typedef unsigned char CHAR;
typedef unsigned short int WORD;
typedef int (*INTFUNC)(const char *,char *,int);
extern FILE *chinese_debug;


void ch_write_to_screen(int);
void ch_graphicmode(int);
void ch_textmode(int);
void ch_redraw();
void ch_change_console(int);
void adm_init();
void adm_end();
void ch_tran_code(int,CHAR,CHAR);
void ch_clear();
void ch_clreol();
void ch_gotoxy(int,int);
void ch_showch(CHAR);
void ch_showstr(CHAR *);
int ch_wherex();
int ch_wherey();
void ch_setdim(int,int);
void ch_scroll(int,int,int);
void ch_rscroll(int,int,int);
void ch_setscroll(int,int);
int ch_DimX();
int ch_DimY();
void ch_end();
void ch_cursoron(),ch_cursoroff(),ch_cursor_blink(int);
void ch_clearblock(int,int,int,int);
void ch_deletechar();
void ch_insertchar();
void insertline();

void ch_have_cursor(int);
void ch_setwsize(int,int,int);

void sys_error(char *,...);
void sys_fatel(char *,...);
#define CODE_BIG5    0
#define CODE_GB      1 
#define CODE_TCA     2
#define CODE_ET      3

/* stdio ouput & input replacement function */
int chinese_printf(const char *,...);
int chinese_fprintf(FILE *,const char *,...);
int chinese_scanf(const char *,...);
int chinese_fscanf(FILE *,const char *,...);
int chinese_write(int,const char *,int);
int chinese_read(int,char *,int);
int chinese_fread(char *,int,int,FILE *);
int chinese_fwrite(const char *,int,int,FILE *);
int chinese_fputc(char,FILE *);
int chinese_fgetc(FILE *);
int chinese_putc(char,FILE *);
char *chinese_fgets(char *,int,FILE *);
void chinese_exit(int);
int _cwrite(int con,const char *,int);
int _cread(char *,int);
char *_cgets(char *,int);


/* Multiple input method driver */
typedef struct 
{
  char mark[7];
  int bell:1;
  int full:1;
  CHAR keymap[256];
  CHAR mapkey[256];
  union {
    CHAR chkey[512];
    WORD CHKEY[256];
  } cmap;
} InputHead;

typedef struct 
{
  char seqs[4];
  union {
    short big5;
    char code[2];
  } word;
} WordMap;

typedef struct 
{
  short num;
  short maxnum;
  WordMap *map;
} HITEMLIST;

typedef struct
{
  HITEMLIST item[HASH2_SIZE];
} HASH2;

typedef struct
{
  InputHead head;
  int num;
  HASH2 *hash;
} MultipleTable;


/* CHINESE COMMAND CODE */
#define CCMD_TEXT      1
#define CCMD_GRAPH     2
#define CCMD_INPUT     3
#define CCMD_PRINT     4
#define CCMD_ACK       5
#define CCMD_START     6
#define CCMD_END       7
#define CCMD_SWINSZ    8
#define CCMD_CHTTY     9

#define NORMAL 0
#define CHECK 1


extern int Chinese_server;
extern int Chinese_sharememid;
#define CONS_NUM 6
typedef struct {
  int curx,cury;
  int dimx,dimy;
  CHAR *scrtext,*scrattr;
  int cursor_x,cursor_y;
  int cursor_blinked,cursor_rate;
  char c_stack;
  char sys_attr;
  int pos;
  char inv,und;
  int cursor_on;
  int no_cursor;
  int codesys;
  char screenmode;
  char isscrolled;
  char *origin;
  int topline;
  int cur_mode;
  WORD top,bottom;
} VSC;

#define MAX_VGA_LINES    960
#define MAX_DIMY 29
#define MAX_DIMX 80
#define MIN_DIMY 5
#define MIN_DIMX 20
/* chtran.c */
extern int logintty;

/* ttyserver.c */
typedef struct {
  int type;
  int tty;
  int lines_of_screen;
  int width_of_screen;
  int is_a_script:1;
  int length_of_name;
  int length_of_home;
  int pid;
  int uid;
  int pgrp;
} CMSG;
#define CHTTY_EXIST 0
#define CHTTY_OPENTTY 1
extern char *version;
#endif /* __CHINESE_H */

