Files
strans/dat.h

223 lines
2.8 KiB
C

#include <u.h>
#include <libc.h>
#include <thread.h>
#include <bio.h>
#include "ipc.h"
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
enum
{
LangEN = 0x14,
LangJP = 0x0e,
LangJPK = 0x0b,
LangKO = 0x13,
LangHANJA = 0x08,
LangEMOJI = 0x05,
LangVI = 0x16,
Fontsz = 32,
PopupPad = 4,
PopupSep = 1,
PopupNumw = Fontsz,
PopupTextw = 12*Fontsz,
Maxrunes = 64,
Maxutf = Maxrunes * UTFmax + 1,
};
enum
{
Maxclients = 64,
Maxkouho = 32,
Maxdisp = 9,
Imgw = 2*PopupPad + PopupNumw + PopupTextw,
Imgh = 2*PopupPad + (Maxdisp + 2)*Fontsz + PopupSep,
Colfg = 0x000000,
Colbg = 0xffffff,
Colsep = 0xd0d0d0,
Colsel = 0x333333,
Colselfg = 0xffffff,
};
typedef struct Str Str;
struct Str
{
Rune r[Maxrunes];
int n;
};
typedef struct Emit Emit;
struct Emit
{
int eat;
Str s;
Str next;
Str dict;
};
typedef struct Hnode Hnode;
struct Hnode
{
int filled;
int next;
char *key;
int klen;
char *val;
int vlen;
};
typedef struct Tnode Tnode;
struct Tnode
{
int child;
int sibling;
char c;
char *val;
int vlen;
};
typedef struct Trie Trie;
struct Trie
{
int root;
Tnode *nodes;
int n;
int cap;
};
typedef struct Hmap Hmap;
struct Hmap
{
int nbs;
int nsz;
int len;
int cap;
uchar *nodes;
};
typedef struct Lang Lang;
typedef struct Im Im;
struct Lang
{
int lang;
char *mapname;
char *dictname;
Emit (*trans)(Im*, Rune);
void (*back)(Im*);
void (*dictq)(Im*);
Trie *map;
Hmap *dict;
};
struct Im
{
Lang *l;
Str pre;
/* Telex history, or the short pending romaji in a Japanese mode. */
Str raw;
Str kouho[Maxkouho];
int nkouho;
int sel;
};
typedef struct Drawcmd Drawcmd;
typedef struct Caret Caret;
struct Caret
{
int valid;
int x;
int y;
int h;
};
struct Drawcmd
{
Str pre;
Str kouho[Maxdisp];
int nkouho;
int sel;
int first;
int total;
Caret caret;
};
typedef struct Popup Popup;
struct Popup
{
int w;
int h;
int n;
int prey;
int sepy;
int rowsy;
int numx;
int textx;
int textw;
int markx;
int marky;
int markw;
int selx;
int sely;
int selw;
};
typedef struct Keyreq Keyreq;
typedef struct Keyres Keyres;
enum
{
Cclientpreedit = 1<<0,
};
enum
{
Keypress,
Keyreset,
Keyrelease,
Keycaret,
Keycap,
};
struct Keyres
{
int eaten; /* Keycap: caller is active and capability was applied. */
Str commit;
Str preedit;
};
struct Keyreq
{
void *owner; /* stable until the context's release is acknowledged */
int cap;
int op;
u32int ks;
u32int mod;
Caret caret;
Channel *reply;
};
typedef struct Dictreq Dictreq;
struct Dictreq
{
Str key;
Str pre;
int lang;
u32int seq;
};
typedef struct Dictres Dictres;
struct Dictres
{
Str key;
Str kouho[Maxkouho];
int nkouho;
int lang;
u32int seq;
};
extern Lang langs[];
extern int nlang;
extern Channel *drawc;
extern Channel *keyc;
extern Channel *dictreqc;
extern Channel *dictresc;