/*乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//
    bolyai_c.h  亂拲堄亃偙偺僼傽僀儖傪嶍彍(曄峏)偟側偄偱偔偩偝偄丅
//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗*/

typedef void *_p32, *P4B, *pANY, *PVOID;
typedef I1B  _i08, *pI1B, *pSTR, *PSTR;
typedef U1B  _u08, *pU1B, *pBIN, *PBYTE;
typedef I2B  _i16, *pI2B;
typedef U2B  _u16, *pU2B, *PWORD;
typedef I4B  _i32, *pI4B, iANY, *PINT;
typedef U4B  _u32, *pU4B, uANY, *PUINT;
typedef I8B  _i64, *pI8B;
typedef U8B  _u64, *pU8B;
typedef F4B  _f32, *pF4B;
typedef F8B  _f64, *pF8B, REAL;

typedef const void *rANY, *PCVOID, *HFIL, *HANDLE, FILE;
typedef const I1B  *rI1B, *rSTR, *PCSTR;
typedef const U1B  *rU1B, *rBIN, *PCBYTE;
typedef const I2B  *rI2B;
typedef const U2B  *rU2B, *PCWORD;
typedef const I4B  *rI4B, *PCINT;
typedef const U4B  *rU4B, *PCUINT;
typedef const I8B  *rI8B;
typedef const U8B  *rU8B;
typedef const F4B  *rF4B;
typedef const F8B  *rF8B;

#define  FALSE  0
#define  TRUE   1
#define  RAND_MAX  32767

F8B  sqrt(F8B x);
F8B  sin(F8B x);
F8B  cos(F8B x);
F8B  tan(F8B x);
F8B  asin(F8B x);
F8B  acos(F8B x);
F8B  atan(F8B x);
F8B  atan2(F8B y, F8B x);
F8B  exp(F8B x);
F8B  pow(F8B x, F8B y);
F8B  log(F8B x);
F8B  log10(F8B x);
F8B  ceil(F8B x);
F8B  floor(F8B x);
F8B  fabs(F8B x);
I4B  abs(I4B n);

I4B  atoi(rSTR st);
F8B  atof(rSTR st);
I4B  rand(void);
void srand(U4B sd);

pANY calloc(U4B n, U4B sz);
pANY malloc(U4B sz);
pANY realloc(pANY pv, U4B sz);
void free(pANY pv);

pANY memchr(rANY pv, I4B c, U4B n);
I4B  memcmp(rANY p1, rANY p2, U4B n);
pANY memcpy(pANY p1, rANY p2, U4B n);
pANY memmove(pANY p1, rANY p2, U4B n);
pANY memset(pANY pv, I4B c, U4B n);

pSTR strchr(rSTR st, I4B c);
I4B  strcmp(rSTR s1, rSTR s2);
I4B  stricmp(rSTR s1, rSTR s2);
I4B  strncmp(rSTR s1, rSTR s2, U4B n);
I4B  strnicmp(rSTR s1, rSTR s2, U4B n);
pSTR strcpy(pSTR ds, rSTR ss);
pSTR strcat(pSTR ds, rSTR ss);
U4B  strlen(rSTR st);
U4B  strspn(rSTR s1, rSTR s2);
I4B  strtol(rSTR st, pSTR *ep, I4B ra);
U4B  strtoul(rSTR st, pSTR *ep, I4B ra);
F8B  strtod(rSTR st, pSTR *ep);

I4B  sprintf(pSTR st, rSTR fmt, ...);

I8B  _atoi64(rSTR st);

I8B  _strtoi64(rSTR st, pSTR *ep, I4B ra);
U8B  _strtoui64(rSTR st, pSTR *ep, I4B ra);

void rsv_046(void);
void rsv_047(void);
void rsv_048(void);
void rsv_049(void);
void rsv_050(void);
void rsv_051(void);
void rsv_052(void);
void rsv_053(void);
HFIL fopen(rSTR fn, rSTR md);
I4B  fclose(HFIL fp);
I4B  fprintf(HFIL fp, rSTR fmt, ...);
void rsv_057(void);
void rsv_058(void);
void rsv_059(void);
void rsv_060(void);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

//#define  NULL  ((void *)0)

//#define  _countof(a)  (sizeof(a) / sizeof(a[0]))
//#define  NELEM(a)  _countof(a)

//#define  LOU1B(w)  ((U1B)((U4B)(w) & 0x00ff))
//#define  HIU1B(w)  ((U1B)((U4B)(w) >> 8))
//#define  LOU2B(u)  ((U2B)((U4B)(u) & 0xffff))
//#define  HIU2B(u)  ((U2B)((U4B)(u) >> 16))

//#define  MKU2B(l, h)  ((U2B)(((U4B)(l) & 0x00ff)|((U4B)(h) << 8)))
//#define  MKU4B(l, h)  ((U4B)(((U4B)(l) & 0xffff)|((U4B)(h) << 16)))

//#define  LOBYTE(w)  LOU1B(w)
//#define  HIBYTE(w)  HIU1B(w)
//#define  LOWORD(u)  LOU2B(u)
//#define  HIWORD(u)  HIU2B(u)

//#define  MAKEWORD(l, h)  MKU2B(l, h)
//#define  MAKEUINT(l, h)  MKU4B(l, h)

#define  LBUF  512

void memswap(pANY p1, pANY p2, I4B n);
void memrotl(pANY pv, I4B ln, I4B n);
void memrotr(pANY pv, I4B ln, I4B n);

I4B  sign(F8B d);
I4B  iround(F8B d);

U4B  hash(rSTR st, U4B hs);

U4B  nbound(U4B i, U4B n);

pANY halloc(U4B sz, BOOL clr);
pANY hrealloc(pANY pv, U4B sz);
BOOL hfree(pANY pv);

void rsv_071(void);

pANY talloc(U4B sz);
pANY ualloc(U4B sz);
pANY valloc(U4B sz);

void rsv_075(void);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

typedef struct {
  pI4B  pi;
  I4B   ni;
} IDXS;
typedef IDXS *pIDXS, *PIDXS;
typedef const IDXS *rIDXS, *PCIDXS;

I4B  idxval(rIDXS ls, I4B id);
I4B  srchidx(rIDXS ls, I4B va);

typedef struct {
  I4B   ky;
  I4B   va;
} MAPI;
typedef MAPI *pMAPI, *PMAPI;
typedef const MAPI *rMAPI, *PCMAPI;

typedef struct {
  pMAPI pv;
  I4B   ni;
} MAPS;
typedef MAPS *pMAPS, *PMAPS;
typedef const MAPS *rMAPS, *PCMAPS;

I4B  mapval(rMAPS ls, I4B ky);
I4B  srchmap(rMAPS ls, I4B va);

typedef struct {
  rSTR  *ps;
  I4B   ni;
} ENMS;
typedef ENMS *pENMS, *PENMS;
typedef const ENMS *rENMS, *PCENMS;

rSTR enmstr(rENMS ls, I4B va);
I4B  srchenm0(rENMS ls, rSTR st);

typedef struct {
  I4B   va;
  rSTR  st;
} CODI;
typedef CODI *pCODI, *PCODI;
typedef const CODI *rCODI, *PCCODI;

typedef struct {
  pCODI pv;
  I4B   ni;
} CODS;
typedef CODS *pCODS, *PCODS;
typedef const CODS *rCODS, *PCCODS;

rSTR codstr(rCODS ls, I4B va);
I4B  srchcod0(rCODS ls, rSTR st);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

enum {
  e_000, E_MEM, E_DAT, E_PAR, E_FIR, E_FIW, E_DIR, E_ALO, E_CAP, E_DLL,
};

BOOL register_error_descriptions(rCODS ed);
rSTR error_description(U4B ec);
I4B  first_error(void);
I4B  last_error(void);
void reset_error(void);
BOOL enable_error_reporting(void);
BOOL disable_error_reporting(void);
BOOL enable_error_logging(void);
BOOL disable_error_logging(void);

pANY ierr(I4B ec);
pANY ferr(I4B ec, rSTR nam);
pANY serr(I4B ec, rSTR nam, I4B ir, I4B ic);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

typedef U4B  RGBC;
typedef RGBC  *pRGBC;
typedef const RGBC *rRGBC;

typedef struct {
  pRGBC bi;
  I4B   w;
  I4B   h;
} HIMG_;
typedef HIMG_ IMGI, *HIMG;

HIMG CreateIMG(I4B w, I4B h, RGBC cb);
HIMG DuplicateIMG(HIMG im);
void DeleteIMG(HIMG im);
HIMG MoveIMG(HIMG im, HIMG ix);

void PasteIMG(HIMG im, HIMG ix, I4B x, I4B y);
void TrimIMG(HIMG im, I4B x, I4B y, I4B w, I4B h, RGBC cb);

typedef struct {
  I4B   x1, y1;
  I4B   x2, y2;
  I4B   x3, y3;
  I4B   x4, y4;
} XFMQ;
typedef XFMQ *pXFMQ, *PXFMQ;
typedef const XFMQ *rXFMQ, *PCXFMQ;

void SetXFMQ(PXFMQ q, I4B x1, I4B y1, I4B x2, I4B y2, I4B x3, I4B y3, I4B x4, I4B y4);

void TransformIMG(HIMG im, rXFMQ q, RGBC cb);

#define  IMG_HORIZONTAL  1
#define  IMG_VERTICAL    2

#define  IMG_HRZ  IMG_HORIZONTAL
#define  IMG_VRT  IMG_VERTICAL

void InvertIMG(HIMG im, I4B sw);
void RotateIMG(HIMG im, F8B dg, RGBC cb);

#define  IMG_MEAN    0
#define  IMG_LINEAR  1
#define  IMG_SMOOTH  2
#define  IMG_SHARP   3

#define  IMG_MEA  IMG_MEAN
#define  IMG_LIN  IMG_LINEAR
#define  IMG_SMO  IMG_SMOOTH
#define  IMG_SHA  IMG_SHARP

void ResizeIMGX(HIMG im, I4B w, I4B h, I4B sw);
void ResizeIMG(HIMG im, I4B w, I4B h);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

BOOL isspc(rSTR st);
BOOL isctl(rSTR st);
BOOL issym(rSTR st);
BOOL isdig(rSTR st);
BOOL isodig(rSTR st);
BOOL isxdig(rSTR st);
BOOL isupr(rSTR st);
BOOL islwr(rSTR st);
BOOL isalp(rSTR st);
BOOL isalpx(rSTR st);
BOOL isaln(rSTR st);
BOOL isalnx(rSTR st);
BOOL isasc(rSTR st);
BOOL ishan(rSTR st);
BOOL isprn(rSTR st);
BOOL iszen1(rSTR st);
BOOL iszen2(rSTR st);
BOOL iszen(rSTR st);
BOOL isret(rSTR st);
BOOL iszspc(rSTR st);

pSTR spncpy(pSTR sd, rSTR p1, rSTR p2);
pSTR strcpyn(pSTR sd, rSTR ss, I4B n);
pSTR strcpyx(pSTR sd, rSTR ss, I4B n);

BOOL nthzen1(rSTR st, I4B n);
BOOL nthyen(rSTR st, I4B n);

pSTR mbschr(rSTR st, I4B c);
pSTR mbsrchr(rSTR st, I4B c);
U4B  mbslen(rSTR st);

#define  STX_CASEINSENSITIVE   0x01
#define  STX_WIDTHINSENSITIVE  0x02
#define  STX_SPACEINSENSITIVE  0x04
#define  STX_WHOLEWORDS        0x08
#define  STX_PREFIX            0x10
#define  STX_SUFFIX            0x20
#define  STX_PATTERN           0x80

#define  STX_UPR  STX_CASEINSENSITIVE
#define  STX_ZEN  STX_WIDTHINSENSITIVE
#define  STX_DSP  STX_SPACEINSENSITIVE
#define  STX_ALL  STX_WHOLEWORDS
#define  STX_LFT  STX_PREFIX
#define  STX_RGT  STX_SUFFIX
#define  STX_PAT  STX_PATTERN

I4B  strmatchx(rSTR s1, rSTR s2, I4B flg);
BOOL strmatch(rSTR s1, rSTR s2);
pSTR strfindx(rSTR s1, rSTR s2, I4B flg);
pSTR strfind(rSTR s1, rSTR s2);
BOOL strlfind(rSTR s1, rSTR s2);
BOOL strrfind(rSTR s1, rSTR s2);
pSTR strifind(rSTR s1, rSTR s2);
BOOL strilfind(rSTR s1, rSTR s2);
BOOL strirfind(rSTR s1, rSTR s2);
BOOL strlike(rSTR s1, rSTR s2);
BOOL strmlike(rSTR s1, rSTR s2);
BOOL strllike(rSTR s1, rSTR s2);
BOOL strrlike(rSTR s1, rSTR s2);
I4B  strcount(rSTR s1, rSTR s2);

pSTR tozenb(pSTR bf, rSTR st);
pSTR tohanb(pSTR bf, rSTR st);
pSTR touprb(pSTR bf, rSTR st);
pSTR tolwrb(pSTR bf, rSTR st);
pSTR tohirab(pSTR bf, rSTR st);
pSTR tokatab(pSTR bf, rSTR st);
pSTR ltrimb(pSTR bf, rSTR st);
pSTR rtrimb(pSTR bf, rSTR st);
pSTR btrimb(pSTR bf, rSTR st);
pSTR delspcb(pSTR bf, rSTR st);
pSTR delctlb(pSTR bf, rSTR st);
pSTR ctlspcb(pSTR bf, rSTR st);
pSTR cipherb(pSTR bf, rSTR st);
pSTR inscmab(pSTR bf, rSTR st);
pSTR delcmab(pSTR bf, rSTR st);
pSTR extascb(pSTR bf, rSTR st);
pSTR midstrb(pSTR bf, rSTR st, I4B n1, I4B n2);
pSTR strreplb(pSTR bf, rSTR st, rSTR s1, rSTR s2);
pSTR strconcb(pSTR bf, rSTR s1, rSTR s2);

#define  LSTR  LBUF
typedef  I1B  STRBUF[LSTR];

rSTR tozen(rSTR st);
rSTR tohan(rSTR st);
rSTR toupr(rSTR st);
rSTR tolwr(rSTR st);
rSTR tohira(rSTR st);
rSTR tokata(rSTR st);
rSTR ltrim(rSTR st);
rSTR rtrim(rSTR st);
rSTR btrim(rSTR st);
rSTR delspc(rSTR st);
rSTR delctl(rSTR st);
rSTR ctlspc(rSTR st);
rSTR cipher(rSTR st);
rSTR inscma(rSTR st);
rSTR delcma(rSTR st);
rSTR extasc(rSTR st);
rSTR midstr(rSTR st, I4B n1, I4B n2);
rSTR strrepl(rSTR st, rSTR s1, rSTR s2);
rSTR strconc(rSTR s1, rSTR s2);

I4B  sprintfs(pSTR st, rSTR fmt, ...);
I4B  csprintf(pSTR st, rSTR fmt, ...);
rSTR format(rSTR fmt, ...);
rSTR cformat(rSTR fmt, ...);

I4B  ztoi(rSTR st);
U4B  ztou(rSTR st);
I8B  ztoi64(rSTR st);
U8B  ztou64(rSTR st);
F8B  ztof(rSTR st);
I4B  cztoi(rSTR st);
U4B  cztou(rSTR st);
I8B  cztoi64(rSTR st);
U8B  cztou64(rSTR st);
F8B  cztof(rSTR st);

pSTR strcpys(pSTR sd, rSTR ss);
pSTR strcats(pSTR sd, rSTR ss);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

BOOL is_leap_year(I4B yr);
I4B  days_of_month(I4B yr, I4B mo);

enum {
  DW_SUNDAY,   // 0
  DW_MONDAY,
  DW_TUESDAY,
  DW_WEDNESDAY,
  DW_THURSDAY,
  DW_FRIDAY,
  DW_SATURDAY, // 6
  DW_SUN = DW_SUNDAY,
  DW_MON = DW_MONDAY,
  DW_TUE = DW_TUESDAY,
  DW_WED = DW_WEDNESDAY,
  DW_THU = DW_THURSDAY,
  DW_FRI = DW_FRIDAY,
  DW_SAT = DW_SATURDAY,
};

I4B  day_of_week(I4B yr, I4B mo, I4B dy);

I4B  date_serial(I4B yr, I4B mo, I4B dy);
I4B  year(I4B sr);
I4B  month(I4B sr);
I4B  day(I4B sr);
I4B  youbi(I4B sr);
I4B  era_year(I4B sr);

I4B  today(void);

enum {
  DD_YEAR  = 1,
  DD_MONTH = 2,
  DD_YEA = DD_YEAR,
  DD_MON = DD_MONTH,
};

I4B  date_diff(I4B s1, I4B s2, I4B sw);

I4B  ztod(rSTR st);
I4B  ztod2(rSTR st, I4B sr0);
I4B  ztom(rSTR st);

I4B  dprintf(pSTR st, rSTR fmt, I4B sr);
rSTR dformat(rSTR fmt, I4B sr);

I4B  time_serial(I4B hr, I4B mn, I4B sc);
I4B  hour(I4B tm);
I4B  minute(I4B tm);
I4B  second(I4B tm);

I4B  ztot(rSTR st);

I4B  tprintf(pSTR st, rSTR fmt, I4B tm);
rSTR tformat(rSTR fmt, I4B tm);

F8B  now(void);

F8B  ztodt(rSTR st);

I4B  dtprintf(pSTR st, rSTR fmt, F8B dt);
rSTR dtformat(rSTR fmt, F8B dt);

typedef struct {
  U2B   yr, mo, dw, dy;
  U2B   hr, mn, sc, ms;
} STMI;
typedef STMI *pSTMI, *PSTMI;
typedef const STMI *rSTMI, *PCSTMI;

void get_system_time(pSTMI lp);
void get_local_time(pSTMI lp);
U4B  get_tick_count(void);
void wait_millisec(U4B ms);

typedef struct {
  U4B   ldt;
  U4B   hdt;
} FTMI;
typedef FTMI *pFTMI, *PFTMI;
typedef const FTMI *rFTMI, *PCFTMI;

I4B  compare_file_time(rFTMI ft1, rFTMI ft2);
BOOL file_time_to_system_time(pSTMI lp, rFTMI ft);
BOOL system_time_to_file_time(pFTMI ft, rSTMI lp);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

#define  CHP_DIR   0x01
#define  CHP_NAME  0x02
#define  CHP_EXT   0x04

#define  CHP_NAM  CHP_NAME

I4B  check_path(rSTR nam);
pSTR change_path(pSTR nam, rSTR src, I4B flg);

#define  GENERIC_READ   0x80000000
#define  GENERIC_WRITE  0x40000000

#define  CREATE_NEW     1
#define  CREATE_ALWAYS  2
#define  OPEN_EXISTING  3
#define  OPEN_ALWAYS    4

#define  OP_READ       (GENERIC_READ|OPEN_EXISTING)
#define  OP_WRITE      (GENERIC_WRITE|CREATE_ALWAYS)
#define  OP_APPEND     (GENERIC_WRITE|OPEN_ALWAYS)
#define  OP_READWRITE  (GENERIC_READ|GENERIC_WRITE|OPEN_EXISTING)

#define  OP_RDO  OP_READ
#define  OP_WRI  OP_WRITE
#define  OP_APD  OP_APPEND
#define  OP_RDW  OP_READWRITE

HFIL open_file(rSTR nam, U4B flg);
BOOL close_file(HFIL hf);

#define  FILE_BEGIN    0
#define  FILE_CURRENT  1
#define  FILE_END      2

U4B  set_file_ptr(HFIL hf, I4B ds, U4B md);
BOOL set_end_of_file(HFIL hf);

U4B  get_file_size(HFIL hf);

BOOL read_file(HFIL hf, pANY bf, U4B sz);
BOOL write_file(HFIL hf, rANY bf, U4B sz);

BOOL read_line(HFIL hf, pSTR bf, I4B sz);
BOOL write_line(HFIL hf, rSTR bf);

typedef struct {
  U4B   atr;
  FTMI  cre;
  FTMI  acc;
  FTMI  wri;
  U4B   szh;
  U4B   szl;
  U4B   rs0;
  U4B   rs1;
  I1B   nam[260];
  I1B   alt[14];
  U2B   rs2;
} FFDI;
typedef FFDI *pFFDI, *PFFDI;

HFIL find_first_file(rSTR nam, pFFDI lp);
BOOL find_next_file(HFIL hf, pFFDI lp);
BOOL find_close(HFIL hf);

BOOL path_exists(rSTR dir);
BOOL file_exists(rSTR nam);

typedef struct {
  U4B   atr;
  FTMI  cre;
  FTMI  acc;
  FTMI  wri;
  U4B   szh;
  U4B   szl;
} FADI;
typedef FADI *pFADI, *PFADI;

BOOL get_file_info(rSTR nam, pFADI lp);
U4B  file_size(rSTR nam);

BOOL new_file(rSTR nam);
BOOL new_file_if_not_exists(rSTR nam);
BOOL move_file(rSTR nam, rSTR src);
BOOL force_move_file(rSTR nam, rSTR src);
BOOL copy_file(rSTR nam, rSTR src);
BOOL delete_file(rSTR nam);

BOOL new_path(rSTR dir);
BOOL new_path_if_not_exists(rSTR dir);
BOOL move_file_to(rSTR dir, rSTR src);
BOOL copy_file_to(rSTR dir, rSTR src);
void get_working_path(pSTR dir, I4B sz);
BOOL set_working_path(rSTR dir);

void get_user_name(pSTR nam, I4B sz);
void get_computer_name(pSTR nam, I4B sz);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

I4B  set_error_message_index_base(I4B i);
I4B  error_message_index_base(void);
void set_error_log_file(rSTR nam);
rSTR error_log_file(void);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

HFIL hfopen(rSTR fn, rSTR md);
I4B  hfclose(HFIL hf);
I4B  hfprintf(HFIL hf, rSTR fmt, ...);

I4B  srchenm(rENMS ls, rSTR st);
I4B  srchcod(rCODS ls, rSTR st);

void rsv_279(void);
void rsv_280(void);
void rsv_281(void);
void rsv_282(void);
void rsv_283(void);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

rANY i32Box(I4B va);
rANY i64Box(I8B va);
rANY f32Box(F4B va);
rANY f64Box(F8B va);

rANY I4BBox(I4B va);
rANY I8BBox(I8B va);
rANY F4BBox(F4B va);
rANY F8BBox(F8B va);

enum {
  TID_VOI,  // 00
  TID_I1B,  // 01
  TID_U1B,
  TID_I2B,
  TID_U2B,
  TID_I4B,
  TID_U4B,
  TID_I8B,
  TID_U8B,
  TID_F4B,
  TID_F8B,  // 10
  TID_STR,  // 11
  TID_BIN,  // 12
  TID_HEX,
  TID_M4B,
  TID_M8B,
  TID_YMD,
  TID_YMN,
  TID_TIM,
  TID_DTM,
  TID_E1B,
  TID_E2B,
  TID_E4B,
  TID_C1B,
  TID_C2B,
  TID_C4B,
  TID_S1B,
  TID_S2B,
  TID_S4B,
  TID_A1B,
  TID_A2B,
  TID_A4B,
  TID_ASC,  // 32
  TID_LIB = 40,
  TID_USR = 64,
  TID_I08 = TID_I1B,
  TID_U08 = TID_U1B,
  TID_I16 = TID_I2B,
  TID_U16 = TID_U2B,
  TID_I32 = TID_I4B,
  TID_U32 = TID_U4B,
  TID_I64 = TID_I8B,
  TID_U64 = TID_U8B,
  TID_F32 = TID_F4B,
  TID_F64 = TID_F8B,
  TID_M32 = TID_M4B,
  TID_M64 = TID_M8B,
  TID_E08 = TID_E1B,
  TID_E16 = TID_E2B,
  TID_E32 = TID_E4B,
  TID_C08 = TID_C1B,
  TID_C16 = TID_C2B,
  TID_C32 = TID_C4B,
  TID_S08 = TID_S1B,
  TID_S16 = TID_S2B,
  TID_S32 = TID_S4B,
  TID_A08 = TID_A1B,
  TID_A16 = TID_A2B,
  TID_A32 = TID_A4B,
  TID_USER= TID_USR,
};

//#define  STR(n)  MKU4B(TID_STR, n)
//#define  BIN(n)  MKU4B(TID_BIN, n)
//#define  ASC(n)  MKU4B(TID_ASC, n)

#define  CAL_BIT  0x80

//#define  CAL(id)  ((id) | CAL_BIT)

enum {
  CAL_I1B = CAL(TID_I1B),
  CAL_U1B = CAL(TID_U1B),
  CAL_I2B = CAL(TID_I2B),
  CAL_U2B = CAL(TID_U2B),
  CAL_I4B = CAL(TID_I4B),
  CAL_U4B = CAL(TID_U4B),
  CAL_I8B = CAL(TID_I8B),
  CAL_U8B = CAL(TID_U8B),
  CAL_F4B = CAL(TID_F4B),
  CAL_F8B = CAL(TID_F8B),
  CAL_M4B = CAL(TID_M4B),
  CAL_M8B = CAL(TID_M8B),
  CAL_YMD = CAL(TID_YMD),
  CAL_YMN = CAL(TID_YMN),
  CAL_E1B = CAL(TID_E1B),
  CAL_E2B = CAL(TID_E2B),
  CAL_E4B = CAL(TID_E4B),
  CAL_C1B = CAL(TID_C1B),
  CAL_C2B = CAL(TID_C2B),
  CAL_C4B = CAL(TID_C4B),
  CAL_S1B = CAL(TID_S1B),
  CAL_S2B = CAL(TID_S2B),
  CAL_S4B = CAL(TID_S4B),
  CAL_A1B = CAL(TID_A1B),
  CAL_A2B = CAL(TID_A2B),
  CAL_A4B = CAL(TID_A4B),
  CAL_I32 = CAL_I4B,
  CAL_F64 = CAL_F8B,
  CAL_M32 = CAL_M4B,
  CAL_M64 = CAL_M8B,
  CAL_E32 = CAL_E4B,
  CAL_C32 = CAL_C4B,
  CAL_S32 = CAL_S4B,
};

//#define  ITP(id, bt)  MKU2B(id, bt)

#define  WID_DEFAULT    0
#define  WID_HIDE       0
#define  WID_FORCEHIDE  255

#define  WID_DEF  WID_DEFAULT
#define  WID_HID  WID_HIDE
#define  WID_FRC  WID_FORCEHIDE

#define  ALN_DEFAULT    0
#define  ALN_LEFT       0
#define  ALN_CENTER     1
#define  ALN_RIGHT      2
#define  ALN_FORCELEFT  255

#define  ALN_DEF  ALN_DEFAULT
#define  ALN_LFT  ALN_LEFT
#define  ALN_CEN  ALN_CENTER
#define  ALN_RGT  ALN_RIGHT
#define  ALN_FRC  ALN_FORCELEFT

//#define  ATR(wd, al)  MKU2B(wd, al)
//#define  ALT(id, ic)  MKU4B(id, ic)
//#define  RKY(id, ic)  MKU4B(id, ic)

typedef void *pCOLI, *PCOLI;
typedef const void *rCOLI, *PCCOLI;

typedef pANY (*FSCN)(pANY pv, rSTR st, rCOLI co);
typedef pSTR (*FPRN)(pSTR st, rANY pv, rCOLI co);
typedef I4B  (*FCMP)(rANY p1, rANY p2, rCOLI co);
typedef uANY (*FLST)(I4B im, rCOLI co);

typedef struct {
  I4B   itp;
  I4B   atr;
  FSCN  fscn;
  FPRN  fprn;
  FCMP  fcmp;
  FLST  flst;
  uANY  pa0;
  uANY  pa1;
  uANY  pa2;
  I4B   flg;
} TYPI;
typedef TYPI *pTYPI, *PTYPI;
typedef const TYPI *rTYPI, *PCTYPI;

BOOL RegisterColumnType(rTYPI pe);

#define  CF_ALLOWCTL        0x00000001
#define  CF_DELCTL          0x00000002
#define  CF_LTRIM           0x00000004
#define  CF_RTRIM           0x00000008
#define  CF_DELSPC          0x00000010
#define  CF_HANKAKU         0x00000020
#define  CF_ZENKAKU         0x00000040
#define  CF_HIDEZERO        0x00000080
#define  CF_HIDECHAR        0x00000100
#define  CF_READONLY        0x00000200
#define  CF_DROPDOWNLIST    0x00000400
#define  CF_DROPDOWN        0x00000800
#define  CF_LINK            0x00001000
#define  CF_DISABLEEDITING  0x00002000
#define  CF_GRID1           0x00004000
#define  CF_GRID2           0x00008000
#define  CF_GRID3           0x00010000
#define  CF_PACK            0x00020000
#define  CF_PRIMARYKEY      0x00040000
#define  CF_REFERENCES      0x00080000
#define  CF_NOTZERO         0x00100000
#define  CF_UNIQUE          0x00200000
#define  CF_OVERRIDECALC    0x00400000
#define  CF_OVERRIDECHECK   0x00800000
#define  CF_OVERRIDESCAN    0x01000000
#define  CF_OVERRIDEPRINT   0x02000000
#define  CF_OVERRIDECOMPARE 0x04000000
#define  CF_OVERRIDELIST    0x08000000

#define  CF_ACT  CF_ALLOWCTL
#define  CF_DCT  CF_DELCTL
#define  CF_LTR  CF_LTRIM
#define  CF_RTR  CF_RTRIM
#define  CF_DSP  CF_DELSPC
#define  CF_HAN  CF_HANKAKU
#define  CF_ZEN  CF_ZENKAKU
#define  CF_HZR  CF_HIDEZERO
#define  CF_HCH  CF_HIDECHAR
#define  CF_RDO  CF_READONLY
#define  CF_DDL  CF_DROPDOWNLIST
#define  CF_DDN  CF_DROPDOWN
#define  CF_LNK  CF_LINK
#define  CF_DED  CF_DISABLEEDITING
#define  CF_GR1  CF_GRID1
#define  CF_GR2  CF_GRID2
#define  CF_GR3  CF_GRID3
#define  CF_PAC  CF_PACK
#define  CF_KEY  CF_PRIMARYKEY
#define  CF_REF  CF_REFERENCES
#define  CF_NZR  CF_NOTZERO
#define  CF_UNI  CF_UNIQUE
#define  CF_OCL  CF_OVERRIDECALC
#define  CF_OCK  CF_OVERRIDECHECK
#define  CF_OSC  CF_OVERRIDESCAN
#define  CF_OPR  CF_OVERRIDEPRINT
#define  CF_OCM  CF_OVERRIDECOMPARE
#define  CF_OLS  CF_OVERRIDELIST

typedef pANY (*FCAL)(pANY pv, rANY pb, rCOLI co);
typedef BOOL (*FCHK)(rANY pb, rCOLI co);

typedef struct {
  I4B   itp;
  I4B   atr;
  rSTR  nam;
  rSTR  tit;
  rSTR  dsc;
  I4B   flg;
  FCAL  fcal;
  FCHK  fchk;
  uANY  pa0;
  uANY  pa1;
  uANY  pa2;
  uANY  pa3;
} COLI;

typedef struct {
  COLI  *co;
  I4B   nc;
} COLS;
typedef COLS *pCOLS, *PCOLS;
typedef const COLS *rCOLS, *PCCOLS;

pANY ColumnScan(pANY pv, rSTR st, rCOLI co);
pSTR ColumnPrint(pSTR st, rANY pv, rCOLI co);
uANY ColumnList(I4B im, rCOLI co);

rANY VPtr(rANY pb, rCOLI co);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

typedef struct { I4B unused;} HTBL_;
typedef HTBL_ *HTBL;

HTBL CHTBL(rCOLI co);

#define  TF_READONLY        0x0001
#define  TF_FIXEDLEN        0x0002
#define  TF_IMPORT          0x0010
#define  TF_ENCRYPT         0x0020
#define  TF_DISABLETRIGGER  0x0040
#define  TF_NOALIGN         0x0080
#define  TF_STATIC          0x0100
#define  TF_STATICROWBUF    0x0200
#define  TF_VIEW            0x0400
#define  TF_TEMPORARY       0x0800
#define  TF_OVERRIDETRIGGER 0x1000

#define  TF_RDO  TF_READONLY
#define  TF_FIX  TF_FIXEDLEN
#define  TF_IMP  TF_IMPORT
#define  TF_CYP  TF_ENCRYPT
#define  TF_DTR  TF_DISABLETRIGGER
#define  TF_NOA  TF_NOALIGN
#define  TF_STA  TF_STATIC
#define  TF_STB  TF_STATICROWBUF
#define  TF_VIW  TF_VIEW
#define  TF_TMP  TF_TEMPORARY
#define  TF_OTR  TF_OVERRIDETRIGGER

typedef BOOL (*FTRG)(HTBL tb, I4B msg, I4B ir, pANY pb);

typedef struct {
  rSTR  nam;
  I4B   fc;
  rSTR  arr;
  rSTR  cnd;
  rSTR  srt;
} VIWI;
typedef VIWI *pVIWI, *PVIWI;
typedef const VIWI *rVIWI, *PCVIWI;

typedef struct {
  pVIWI vi;
  I4B   ni;
} VIWS;
typedef VIWS *pVIWS, *PVIWS;
typedef const VIWS *rVIWS, *PCVIWS;

typedef struct {
  pCOLS cs;
  pVIWS vs;
  rSTR  nam;
  rSTR  tit;
  rSTR  dsc;
  I4B   flg;
  FTRG  ftrg;
  rSTR  imp;
  uANY  ext;
  U4B   rsz;
} TBLI;
typedef TBLI *pTBLI, *PTBLI;
typedef const TBLI *rTBLI, *PCTBLI;

HTBL CreateTableX(pANY pv, I4B len, I4B cap, rTBLI ti);
HTBL CreateTable(I4B cap, rTBLI ti);
void DeleteTable(HTBL tb);

I4B  NTableKeys(HTBL tb);
I4B  NTableRefs(HTBL tb, pI4B pi);

HTBL CreateCompatibleTable(HTBL tb, I4B cap);
BOOL IsCompatible(HTBL tb, HTBL tx);
HTBL DuplicateTable(HTBL tb);

I4B  TableRowSize(HTBL tb);
I4B  NTableRows(HTBL tb);

pANY TablePtr(HTBL tb);

pANY TableRow(HTBL tb, I4B ir);
I4B  TableRowIndex(HTBL tb, rANY pb);

I4B  TableCapacity(HTBL tb);
BOOL ChangeTableCapacity(HTBL tb, I4B cap);

rSTR TableName(HTBL tb);
void SetTableTitle(HTBL tb, rSTR tit);
rSTR TableTitle(HTBL tb);

void SetTableDescription(HTBL tb, rSTR dsc);
rSTR TableDescription(HTBL tb);

void SetTableFlags(HTBL tb, I4B flg);
I4B  TableFlags(HTBL tb);

void SetTableFileName(HTBL tb, rSTR nam);
rSTR TableFileName(HTBL tb);

void SetTableExtra(HTBL tb, uANY pa);
uANY TableExtra(HTBL tb);

#define  TRGM_BEFOREUPDATEOF  1
#define  TRGM_AFTERUPDATEOF   2
#define  TRGM_BEFOREUPDATE    3
#define  TRGM_AFTERUPDATE     4
#define  TRGM_AFTERINSERT     6
#define  TRGM_BEFOREDELETE    7
#define  TRGM_CHECK           TRGM_BEFOREUPDATE
#define  TRGM_DEFAULT         TRGM_AFTERINSERT
#define  TRGM_UPDATERECORD   11
#define  TRGM_INSERTRECORD   12
#define  TRGM_DELETERECORD   13

BOOL DefaultTableTrigger(HTBL tb, I4B msg, I4B ir, pANY pb);
BOOL TableTrigger(HTBL tb, I4B msg, I4B ir, pANY pb);

BOOL EnableTableTrigger(HTBL tb);
BOOL DisableTableTrigger(HTBL tb);

I4B  NTableColumns(HTBL tb);

rCOLI TableColumnInfo(HTBL tb, I4B ic);

void SetTableColumnWidth(HTBL tb, I4B ic, I4B wd);
I4B  TableColumnWidth(HTBL tb, I4B ic);

void SetTableColumnTextAlign(HTBL tb, I4B ic, I4B al);
I4B  TableColumnTextAlign(HTBL tb, I4B ic);

I4B  TableColumnOffset(HTBL tb, I4B ic);
rSTR TableColumnName(HTBL tb, I4B ic);
I4B  TableColumnIndex(HTBL tb, rSTR nam);

void SetTableColumnTitle(HTBL tb, I4B ic, rSTR tit);
rSTR TableColumnTitle(HTBL tb, I4B ic);

void SetTableColumnDescription(HTBL tb, I4B ic, rSTR dsc);
rSTR TableColumnDescription(HTBL tb, I4B ic);

void SetTableColumnFlags(HTBL tb, I4B ic, I4B flg);
I4B  TableColumnFlags(HTBL tb, I4B ic);

void SetTableColumnExtra(HTBL tb, I4B ic, uANY pa);
uANY TableColumnExtra(HTBL tb, I4B ic);

BOOL SetTableCellValue(HTBL tb, I4B ir, I4B ic, rANY pv);
pANY GetTableCellValue(pANY pv, HTBL tb, I4B ir, I4B ic);
BOOL ScanTableCellValue(HTBL tb, I4B ir, I4B ic, rSTR st);
pSTR PrintTableCellValue(pSTR st, HTBL tb, I4B ir, I4B ic);

BOOL ClearTableRow(HTBL tb, I4B ir);
BOOL ClearTableRows(HTBL tb, I4B ir, I4B nr);
BOOL InsertTableRow(HTBL tb, I4B ir);
BOOL InsertTableRows(HTBL tb, I4B ir, I4B nr);
BOOL DeleteTableRow(HTBL tb, I4B ir);
BOOL DeleteTableRows(HTBL tb, I4B ir, I4B nr);
BOOL AddTableRow(HTBL tb);

pANY NewTableRow(HTBL tb);

HTBL CopyTable(HTBL tb, HTBL tx);
HTBL MergeTableX(HTBL tb, HTBL tx);

I4B  CompareTable(HTBL tb, HTBL tx);

typedef BOOL (*FSEL)(rANY pb, uANY pa);

I4B  SearchTableRowX(HTBL tb, I4B i0, FSEL fsel, uANY pa);
I4B  CountTableRowsX(HTBL tb, FSEL fsel, uANY pa);
I4B  SelectTableRowsX(HTBL tb, FSEL fsel, uANY pa);

HTBL SelectCopyTableX(HTBL tb, HTBL tx, FSEL fsel, uANY pa);
HTBL SelectMergeTableX(HTBL tb, HTBL tx, FSEL fsel, uANY pa);

typedef BOOL (*FAGG)(rANY pb, uANY pa);

I4B  AggregateTableX(HTBL tb, FSEL fsel, uANY ps, FAGG fagg, uANY pa);

typedef I4B  (*FSRT)(rANY p1, rANY p2, uANY pa);

void SortTableRowsX(HTBL tb, FSRT fcmp, uANY pa);

I4B  SearchTableCellValue(HTBL tb, I4B i0, I4B ic, rANY pv);

I4B  SearchTableCellText(HTBL tb, I4B i0, I4B ic, rSTR st, I4B flg);

I4B  SearchAlt(HTBL tb, I4B ic, rSTR st);

BOOL CheckTable(HTBL tb);

BOOL LoadBTB(HTBL tb);
BOOL SaveBTB(HTBL tb);

void rsv_383(void);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

typedef struct { I4B unused;} HBUF_;
typedef HBUF_ *HBUF;

HBUF CreateRowBufX(pANY pv, rTBLI ti);
HBUF CreateRowBuf(HTBL tb);
void DeleteRowBuf(HBUF rb);

HBUF DuplicateRowBuf(HBUF rb);

HTBL RowBufHTBL(HBUF rb);
pANY RowBufPtr(HBUF rb);

HBUF MakeRowBuf(HTBL tb, pANY pb);
HBUF TableRowBuf(HTBL tb, I4B ir);
HBUF NewTableRowBuf(HTBL tb);

BOOL SetRowBufCellValue(HBUF rb, I4B ic, rANY pv);
pANY GetRowBufCellValue(pANY pv, HBUF rb, I4B ic);
BOOL ScanRowBufCellValue(HBUF rb, I4B ic, rSTR st);
pSTR PrintRowBufCellValue(pSTR st, HBUF rb, I4B ic);

BOOL ClearRowBuf(HBUF rb);

HBUF CopyRowBuf(HBUF rb, HBUF rx);
BOOL SetTableRow(HTBL tb, I4B ir, HBUF rb);
HBUF GetTableRow(HBUF rb, HTBL tb, I4B ir);
BOOL SetNewTableRow(HTBL tb, HBUF rb);
HBUF CopyValues(HBUF rb, HBUF rx);

HBUF CopyKey(HBUF rb, HBUF rx);

I4B  CompareRowBuf(HBUF rb, HBUF rx);

I4B  SearchKey(HTBL tb, HBUF rb);

HTBL MergeTable(HTBL tb, HTBL tx);

I4B  UniqueKey(HTBL tb, I4B ic, U4B h0, U4B hs);

HTBL CreateSummaryV(HTBL tb, rSTR grp, rSTR cnd, rSTR srt);

BOOL IsConflict(HTBL tb, HTBL tx);
BOOL IsDependent(HTBL tb, I4B i1, I4B i2, rANY p1, rANY p2);

void rsv_411(void);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

typedef struct { I4B unused;} HVIW_;
typedef HVIW_ *HVIW;

HVIW CreateViewX(HTBL tb, rIDXS pa, FSEL fsel, uANY ps, FSRT fcmp, uANY pc);
HVIW CreateView(HTBL tb, rSTR arr, rSTR cnd, rSTR srt);
void DeleteView(HVIW vw);

HTBL ViewHTBL(HVIW vw);

I4B  NViewRows(HVIW vw);

pANY ViewRow(HVIW vw, I4B ir);
I4B  ViewRowIndex(HVIW vw, I4B ir);

I4B  NViewColumns(HVIW vw);

rCOLI ViewColumnInfo(HVIW vw, I4B ic);

void SetViewColumnWidth(HVIW vw, I4B ic, I4B wd);
I4B  ViewColumnWidth(HVIW vw, I4B ic);

#define  DEFCWID  5

I4B  ViewColumnWidthF(HVIW vw, I4B ic);

void SetViewColumnTextAlign(HVIW vw, I4B ic, I4B al);
I4B  ViewColumnTextAlign(HVIW vw, I4B ic);
I4B  ViewColumnTextAlignF(HVIW vw, I4B ic);

rSTR ViewColumnName(HVIW vw, I4B ic);
I4B  ViewColumnIndex(HVIW vw, I4B ic);

void SetViewColumnTitle(HVIW vw, I4B ic, rSTR tit);
rSTR ViewColumnTitle(HVIW vw, I4B ic);

void SetViewColumnDescription(HVIW vw, I4B ic, rSTR dsc);
rSTR ViewColumnDescription(HVIW vw, I4B ic);
rSTR ViewColumnDescriptionR(HVIW vw, I4B ic);

void SetViewColumnFlags(HVIW vw, I4B ic, I4B flg);
I4B  ViewColumnFlags(HVIW vw, I4B ic);
I4B  ViewColumnFlagsF(HVIW vw, I4B ic);

void SetViewColumnExtra(HVIW vw, I4B ic, uANY pa);
uANY ViewColumnExtra(HVIW vw, I4B ic);

BOOL SetViewCellValue(HVIW vw, I4B ir, I4B ic, rANY pv);
pANY GetViewCellValue(pANY pv, HVIW vw, I4B ir, I4B ic);
BOOL ScanViewCellValue(HVIW vw, I4B ir, I4B ic, rSTR st);
BOOL ScanViewCellValueF(HVIW vw, I4B ir, I4B ic, rSTR st);
pSTR PrintViewCellValue(pSTR st, HVIW vw, I4B ir, I4B ic);

#define  PVF_ZEROBASEDINDEX  0x00
#define  PVF_ONEBASEDINDEX   0x01
#define  PVF_COLUMNNAME      0x00
#define  PVF_COLUMNTITLE     0x02
#define  PVF_COLUMNINDEX     0x04

#define  PVF_ZBI  PVF_ZEROBASEDINDEX
#define  PVF_OBI  PVF_ONEBASEDINDEX
#define  PVF_NAM  PVF_COLUMNNAME
#define  PVF_TIT  PVF_COLUMNTITLE
#define  PVF_IDX  PVF_COLUMNINDEX

pSTR PrintViewCellValueF(pSTR st, HVIW vw, I4B ir, I4B ic, I4B flg);

BOOL ClearViewRow(HVIW vw, I4B ir);
BOOL ClearViewRows(HVIW vw, I4B ir, I4B nr);
BOOL InsertViewRow(HVIW vw, I4B ir);
BOOL InsertViewRows(HVIW vw, I4B ir, I4B nr);
BOOL DeleteViewRow(HVIW vw, I4B ir);
BOOL DeleteViewRows(HVIW vw, I4B ir, I4B nr);
BOOL AddViewRow(HVIW vw);

pANY NewViewRow(HVIW vw);

void ArrangeViewColumnsX(HVIW vw, rIDXS pa);
I4B  SearchViewRowX(HVIW vw, I4B i0, FSEL fsel, uANY pa);
I4B  CountViewRowsX(HVIW vw, FSEL fsel, uANY pa);
I4B  SelectViewRowsX(HVIW vw, FSEL fsel, uANY pa);
void SortViewRowsX(HVIW vw, FSRT fcmp, uANY pa);

void ArrangeViewColumns(HVIW vw, rSTR arr);
I4B  SearchViewRow(HVIW vw, I4B i0, rSTR cnd);
I4B  CountViewRows(HVIW vw, rSTR cnd);
I4B  SelectViewRows(HVIW vw, rSTR cnd);
void SortViewRows(HVIW vw, rSTR srt);
void SortTableRowsByView(HVIW vw);

HTBL CreateSummary(HVIW vw, rSTR grp);

I4B  SearchViewCellValue(HVIW vw, I4B i0, I4B ic, rANY pv);
I4B  SearchViewCellText(HVIW vw, I4B i0, I4B ic, rSTR st, I4B flg);

#define  TSW_NAME   0
#define  TSW_NONE   1
#define  TSW_TITLE  2

#define  TSW_NAM  TSW_NAME
#define  TSW_NON  TSW_NONE
#define  TSW_TIT  TSW_TITLE

typedef struct {
  I1B   dlm;
  I1B   quo;
  U2B   tsw;
} CSVI;
typedef CSVI *pCSVI, *PCSVI;
typedef const CSVI *rCSVI, *PCCSVI;

BOOL ReadCSV(HVIW vw, rSTR nam, rCSVI cv);
BOOL WriteCSV(HVIW vw, rSTR nam, rCSVI cv);

void rsv_469(void);
void rsv_470(void);
void rsv_471(void);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

rSTR SiteName(void);
rSTR SiteTitle(void);
rSTR SiteDescription(void);
F8B  TaxRate(void);
I4B  FYearMonth(void);
I4B  NMonthFYear(void);

rSTR UserPath(void);

void SetCurDate(I4B sr);
I4B  CurDate(void);
I4B  BFYear(void);
I4B  EFYear(void);
I4B  BMonth(void);
I4B  EMonth(void);

void rsv_485(void);
void rsv_486(void);
void rsv_487(void);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

rSTR CurUser(void);
I4B  CurAuth(void);

typedef struct {
  pTBLI ti;
  I4B   ni;
} TBLS;
typedef TBLS *pTBLS, *PTBLS;
typedef const TBLS *rTBLS, *PCTBLS;

typedef struct {
  rTBLS ts;
  rSTR  nam;
  rSTR  tit;
  rSTR  dsc;
} BDBI;
typedef BDBI *pBDBI, *PBDBI;
typedef const BDBI *rBDBI, *PCBDBI;

BOOL ConnectDBX(rBDBI db);
BOOL ConnectDB(rSTR nam);
void DisconnectDB(void);

rSTR CurDBName(void);
rSTR CurDBTitle(void);
rSTR CurDBDescription(void);
I4B  CurDBStatus(void);

I4B  NDBTables(void);
HTBL DBTable(I4B id);
rSTR DBTableName(I4B id);
rSTR DBTableTitle(I4B id);
rSTR DBTableDescription(I4B id);
rSTR DBTableFileName(I4B id);
pVIWS DBTableVIWS(I4B id);

I4B  DBTableIndex(rSTR nam);
HTBL DBHTBL(rSTR nam);

typedef struct { I4B unused;} HOPN_;
typedef HOPN_ *HOPN;

#define  OM_READONLY   0x01
#define  OM_READWRITE  0x02
#define  OM_LOCK       0x04
#define  OM_INDIVIDUAL 0x10

#define  OM_RDO  OM_READONLY
#define  OM_RDW  OM_READWRITE
#define  OM_LCK  OM_LOCK
#define  OM_IND  OM_INDIVIDUAL

HOPN OpenTableX(rIDXS pt, I4B md);
HOPN OpenTablesX(rIDXS pt, I4B md);
HOPN OpenTable(rSTR tbs, I4B md);
HOPN OpenTables(rSTR tbs, I4B md);
BOOL SaveTable(HOPN op);
BOOL SaveTables(HOPN op);
BOOL CloseTable(HOPN op, BOOL sv);
BOOL CloseTables(HOPN op, BOOL sv);

HTBL OHTBL(HOPN op);
I4B  NOTables(HOPN op);
HTBL OTable(HOPN op, I4B i);
BOOL IsReadOnly(HOPN op);
BOOL IsLocked(HOPN op);
BOOL IsModified(HOPN op);

BOOL NewDBFiles(void);
BOOL BackupDBFiles(rSTR dir);
BOOL TrashDBFiles(rSTR dir);

void rsv_523(void);
void rsv_524(void);
void rsv_525(void);
void rsv_526(void);
void rsv_527(void);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

typedef U4B  BGRC, COLORREF;

#define  DIB_24BITS    0x00000000
#define  DIB_32BITS    0x00000020
#define  DIB_BOTTOMUP  0x00000000
#define  DIB_TOPDOWN   0x00000080

#define  DIB_24B  DIB_24BITS
#define  DIB_32B  DIB_32BITS
#define  DIB_BUP  DIB_BOTTOMUP
#define  DIB_TDN  DIB_TOPDOWN

typedef struct { pANY bi;} HDIB_;
typedef HDIB_ *HDIB;

HDIB CreateDIB(I4B w, I4B h, I4B flg);

I4B  DIB_WIDTH(HDIB bm);
I4B  DIB_HEIGHT(HDIB bm);
I4B  DIB_BITS(HDIB bm);
pBIN DIB_IMAGE(HDIB bm);

I4B  DIB_WID(HDIB bm);
I4B  DIB_HEI(HDIB bm);
I4B  DIB_BTS(HDIB bm);
pBIN DIB_IMG(HDIB bm);

HDIB CreateCompatibleDIB(HDIB bm);
HDIB DuplicateDIB(HDIB bm);
void DeleteDIB(HDIB bm);
HDIB MoveDIB(HDIB bm, HDIB bx);

typedef struct {
  I4B   cx;
  I4B   cy;
} SIZE;
typedef SIZE *pSIZE, *PSIZE;
typedef const SIZE *rSIZE;

pSIZE GetDIBSize(pSIZE sz, HDIB bm);

HDIB LoadDIB(HDIB bm, rSTR nam);
BOOL SaveDIB(HDIB bm, rSTR nam);

BOOL ConvertDIB(HDIB bm, I4B flg);

HDIB LoadBMP(HDIB bm, rSTR nam);
BOOL SaveBMP(HDIB bm, rSTR nam);

BOOL PasteDIB(HDIB bm, HDIB bx, I4B x, I4B y);
BOOL TrimDIB(HDIB bm, I4B x, I4B y, I4B w, I4B h, RGBC cb);

BOOL TransformDIB(HDIB bm, rXFMQ q, RGBC cb);

#define  DIB_HORIZONTAL  IMG_HORIZONTAL
#define  DIB_VERTICAL    IMG_VERTICAL

#define  DIB_HRZ  DIB_HORIZONTAL
#define  DIB_VRT  DIB_VERTICAL

BOOL InvertDIB(HDIB bm, I4B sw);
BOOL RotateDIB(HDIB bm, F8B dg, RGBC cb);

#define  DIB_MEAN    IMG_MEAN
#define  DIB_LINEAR  IMG_LINEAR
#define  DIB_SMOOTH  IMG_SMOOTH
#define  DIB_SHARP   IMG_SHARP

#define  DIB_MEA  DIB_MEAN
#define  DIB_LIN  DIB_LINEAR
#define  DIB_SMO  DIB_SMOOTH
#define  DIB_SHA  DIB_SHARP

BOOL ResizeDIBX(HDIB bm, I4B w, I4B h, I4B sw);
BOOL ResizeDIB(HDIB bm, I4B w, I4B h);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

typedef struct { I4B unused;} HREP_;
typedef HREP_ *HREP;

void SetOrigin(HREP cv, F8B xorg, F8B yorg);
F8B  OriginX(HREP cv);
F8B  OriginY(HREP cv);
void SetScale(HREP cv, F8B xscl, F8B yscl);
F8B  ScaleX(HREP cv);
F8B  ScaleY(HREP cv);

typedef struct {
  F8B   x1;
  F8B   y1;
  F8B   x2;
  F8B   y2;
} CELL;
typedef CELL *pCELL, *PCELL;
typedef const CELL *rCELL, *PCCELL;

pCELL SetCell(pCELL pc, F8B x1, F8B y1, F8B x2, F8B y2);

pCELL MoveCell(pCELL pc, F8B dx, F8B dy);
pCELL ResizeCell(pCELL pc, F8B dx, F8B dy);
pCELL ReshapeCell(pCELL pc, F8B lm, F8B tm, F8B rm, F8B bm);

void SetCellMargin(HREP cv, F8B hcmg, F8B vcmg);
F8B  CellMarginH(HREP cv);
F8B  CellMarginV(HREP cv);

#define  LST_NULL        0x00
#define  LST_THIN        0x01
#define  LST_REGULAR     0x02
#define  LST_MEDIUM      0x03
#define  LST_THICK       0x04
#define  LST_EXTRATHICK  0x05
#define  LST_DASH        0x10
#define  LST_DOT         0x20
#define  LST_DASHDOT     0x30
#define  LST_DASHDOTDOT  0x40

#define  LST_NUL  LST_NULL
#define  LST_THN  LST_THIN
#define  LST_REG  LST_REGULAR
#define  LST_MED  LST_MEDIUM
#define  LST_THK  LST_THICK
#define  LST_XTK  LST_EXTRATHICK
#define  LST_DSH  LST_DASH
#define  LST_DSD  LST_DASHDOT
#define  LST_DDD  LST_DASHDOTDOT

#define  lstN  LST_NUL
#define  lstI  LST_THN
#define  lstR  LST_REG
#define  lstM  LST_MED
#define  lstB  LST_THK
#define  lstX  LST_XTK
#define  lstD  LST_DOT

I4B  SetLineStyle(HREP cv, I4B lst);
BGRC SetLineColor(HREP cv, BGRC col);

#define  TFF_BOLD       0x0070
#define  TFF_ITALIC     0x0100
#define  TFF_UNDERLINE  0x0200
#define  TFF_STRIKEOUT  0x0400
#define  TFF_VERTICAL   0x1000

#define  TFF_BLD  TFF_BOLD
#define  TFF_ITA  TFF_ITALIC
#define  TFF_UND  TFF_UNDERLINE
#define  TFF_STO  TFF_STRIKEOUT
#define  TFF_VRT  TFF_VERTICAL

void SetTextFont(HREP cv, rSTR face, F8B ch, I4B flg, BGRC col);
void SetTextStyle(HREP cv, F8B cw, F8B ch, F8B cd, rSTR face);

typedef struct {
  F8B   w;
  F8B   h;
} WHSZ;
typedef WHSZ *pWHSZ, *PWHSZ;

pWHSZ TextSize(pWHSZ sz, HREP cv, rSTR st, I4B cb);
pWHSZ AveCharSize(pWHSZ sz, HREP cv);
pWHSZ ZenCharSize(pWHSZ sz, HREP cv);

void DrawLine(HREP cv, F8B x1, F8B y1, F8B x2, F8B y2);
void DrawCirc(HREP cv, F8B xc, F8B yc, F8B rc, F8B t1, F8B t2);

#define  RST_NULL                 0
#define  RST_DEFAULT            (-1)
#define  RST_THIN        0x01010101
#define  RST_REGULAR     0x02020202
#define  RST_MEDIUM      0x03030303
#define  RST_THICK       0x04040404
#define  RST_EXTRATHICK  0x05050505
#define  RST_DASH        0x10101010
#define  RST_DOT         0x20202020
#define  RST_DASHDOT     0x30303030
#define  RST_DASHDOTDOT  0x40404040

#define  RST_NUL  RST_NULL
#define  RST_DEF  RST_DEFAULT
#define  RST_THN  RST_THIN
#define  RST_REG  RST_REGULAR
#define  RST_MED  RST_MEDIUM
#define  RST_THK  RST_THICK
#define  RST_XTK  RST_EXTRATHICK
#define  RST_DSH  RST_DASH
#define  RST_DSD  RST_DASHDOT
#define  RST_DDD  RST_DASHDOTDOT

I4B  RST(I4B llst, I4B tlst, I4B rlst, I4B blst);

void DrawCell(HREP cv, rCELL pc, I4B rst);
void FillCell(HREP cv, rCELL pc, I4B rst, BGRC col);

typedef struct {
  F8B   x;
  F8B   y;
} XYPT;
typedef XYPT *pXYPT, *PXYPT;
typedef const XYPT *rXYPT, *PCXYPT;

void FillPoly(HREP cv, rXYPT pt, I4B np, BGRC col);
void FillCirc(HREP cv, F8B xc, F8B yc, F8B rc, F8B t1, F8B t2, BGRC col);

#define  DT_FORCETOP      0x00000004
#define  DT_LEFT          0x00000000
#define  DT_CENTER        0x00000001
#define  DT_RIGHT         0x00000002
#define  DT_DEFAULT       0x00000000
#define  DT_BOTTOM        0x00000008
#define  DT_CALCRECT      0x00000400
#define  DT_PATH_ELLIPSIS 0x00004000
#define  DT_END_ELLIPSIS  0x00008000
#define  DT_MULTILINE     0x01000000
#define  DT_JUSTIFY       0x02000000
#define  DT_AUTONARROWING 0x04000000
#define  DT_PREFIX        0x08000000
#define  DT_CLIP          0x40000000

#define  DT_FRC  DT_FORCETOP
#define  DT_LFT  DT_LEFT
#define  DT_CEN  DT_CENTER
#define  DT_RGT  DT_RIGHT
#define  DT_MID  DT_DEFAULT
#define  DT_BTM  DT_BOTTOM
#define  DT_CAL  DT_CALCRECT
#define  DT_PEL  DT_PATH_ELLIPSIS
#define  DT_EEL  DT_END_ELLIPSIS
#define  DT_MUL  DT_MULTILINE
#define  DT_JST  DT_JUSTIFY
#define  DT_AUT  DT_AUTONARROWING
#define  DT_PRE  DT_PREFIX
#define  DT_CLP  DT_CLIP

void CellText(HREP cv, pCELL pc, rSTR st, I4B fmt);

#define  VT_LEFT          0x00000001
#define  VT_CENTER        0x00000000
#define  VT_RIGHT         0x00000002
#define  VT_TOP           0x00000000
#define  VT_VCENTER       0x00000004
#define  VT_BOTTOM        0x00000008
#define  VT_CALCRECT      0x00000400

#define  VT_LFT  VT_LEFT
#define  VT_CEN  VT_CENTER
#define  VT_RGT  VT_RIGHT
#define  VT_MID  VT_VCENTER
#define  VT_BTM  VT_BOTTOM
#define  VT_CAL  VT_CALCRECT

void VCellText(HREP cv, pCELL pc, rSTR st, I4B fmt);

typedef struct {
  F8B   x0;
  F8B   y0;
  F8B   dcw;
  F8B   drh;
  F8B   *cw;
  I4B   nc;
  F8B   *rh;
  I4B   nr;
} GRID;
typedef GRID *pGRID, *PGRID;
typedef const GRID *rGRID, *PCGRID;

void SetGrid0(pGRID gr, F8B x0, F8B y0, I4B nc, I4B nr, F8B dcw, F8B drh);
void SetGrid1(pGRID gr, F8B x0, F8B y0, I4B nc, I4B nr, F8B *cw, F8B drh);
void SetGrid2(pGRID gr, F8B x0, F8B y0, I4B nc, I4B nr, F8B dcw, F8B *rh);
void SetGrid3(pGRID gr, F8B x0, F8B y0, I4B nc, I4B nr, F8B *cw, F8B *rh);

pCELL GridCell(pCELL pc, rGRID gr, I4B ir, I4B ic);

#define  RST_THIN_REGULAR       (-2)
#define  RST_THIN_MEDIUM        (-3)
#define  RST_THIN_THICK         (-4)
#define  RST_REGULAR_MEDIUM     (-5)
#define  RST_REGULAR_THICK      (-6)
#define  RST_REGULAR_EXTRATHICK (-7)

#define  RST_I_R  RST_THIN_REGULAR
#define  RST_I_M  RST_THIN_MEDIUM
#define  RST_I_B  RST_THIN_THICK
#define  RST_R_M  RST_REGULAR_MEDIUM
#define  RST_R_B  RST_REGULAR_THICK
#define  RST_R_X  RST_REGULAR_EXTRATHICK

void DrawGridCell(HREP cv, rGRID gr, I4B ir, I4B ic, I4B rst);
void GridCellText(HREP cv, rGRID gr, I4B ir, I4B ic, I4B rst, rSTR st, I4B fmt);

typedef struct {
  I4B   sty;
  rSTR  st1;
  rSTR  st2;
  rSTR  st3;
  F8B   dc;
} STMP;
typedef STMP *pSTMP, *PSTMP;
typedef const STMP *rSTMP, *PCSTMP;

void SetStamp0(pSTMP ps, F8B dc, rSTR st);
void SetStamp1(pSTMP ps, F8B dc, rSTR st);
void SetStamp2(pSTMP ps, F8B dc, rSTR st1, rSTR st2);
void SetStamp3(pSTMP ps, F8B dc, rSTR st1, rSTR st2, rSTR st3);

void CellStamp(HREP cv, rCELL pc, rSTMP ps);

#define  DT_ADJUSTWIDTH   0x02000000
#define  DT_ADJUSTHEIGHT  0x04000000
#define  DT_GRAYED        0x08000000
#define  DT_STRETCH      (DT_ADJUSTWIDTH|DT_ADJUSTHEIGHT)

#define  DT_AJW  DT_ADJUSTWIDTH
#define  DT_AJH  DT_ADJUSTHEIGHT
#define  DT_GRY  DT_GRAYED
#define  DT_STB  DT_STRETCH

void CellImage(HREP cv, pCELL pc, HDIB bm, I4B fmt);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

typedef struct { I4B unused;} HWND_;
typedef HWND_ *HWND;

#define  IDOK      1
#define  IDCANCEL  2
#define  IDABORT   3
#define  IDRETRY   4
#define  IDIGNORE  5
#define  IDYES     6
#define  IDNO      7

I4B  OkBox(HWND hwnd, rSTR st, rSTR ca);
I4B  OkCanBox(HWND hwnd, rSTR st, rSTR ca);
I4B  YesNoBox(HWND hwnd, rSTR st, rSTR ca);
I4B  YesNoCanBox(HWND hwnd, rSTR st, rSTR ca);
I4B  ErrorBox(HWND hwnd, rSTR st, rSTR ca);
I4B  WarningBox(HWND hwnd, rSTR st, rSTR ca);
I4B  AlertBox(HWND hwnd, rSTR st, rSTR ca);
I4B  ResultBox(HWND hwnd, rSTR st, rSTR ca, BOOL re);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

#define  REPM_SKIPPAGE   0
#define  REPM_DRAWPAGE   1
#define  REPM_STARTPRINT 2
#define  REPM_ENDPRINT   3
#define  REPM_SETUP      4
#define  REPM_PAGESETUP  5
#define  REPM_CREATE     6
#define  REPM_DESTROY    7

HWND hWND(HREP rp);

void SetReportInfo(HREP rp, rSTR tit, rSTR usr, I4B sr, I4B tm);
rSTR ReportTitle(HREP rp);
rSTR ReportAuthor(HREP rp);
I4B  ReportDate(HREP rp);
I4B  ReportTime(HREP rp);

void SetReportExtra(HREP rp, U4B pa);
uANY ReportExtra(HREP rp);

void SetNPages(HREP rp, I4B npg);
I4B  NPages(HREP rp);

void SetPaperSize(HREP rp, F8B w, F8B h, F8B scl);
F8B  PaperWidth(HREP rp);
F8B  PaperHeight(HREP rp);

void SetPageSize(HREP rp, F8B w, F8B h);
F8B  PageWidth(HREP rp);
F8B  PageHeight(HREP rp);
F8B  PageLeft(HREP rp);
F8B  PageTop(HREP rp);
F8B  PageRight(HREP rp);
F8B  PageBottom(HREP rp);

void SetPageMargin(HREP rp, F8B lm, F8B tm, F8B rm, F8B bm);
F8B  BodyWidth(HREP rp);
F8B  BodyHeight(HREP rp);
F8B  BodyLeft(HREP rp);
F8B  BodyTop(HREP rp);
F8B  BodyRight(HREP rp);
F8B  BodyBottom(HREP rp);

void SetHeaderHeight(HREP rp, F8B hh);
void SetFooterHeight(HREP rp, F8B fh);
F8B  HeaderWidth(HREP rp);
F8B  HeaderHeight(HREP rp);
F8B  HeaderLeft(HREP rp);
F8B  HeaderTop(HREP rp);
F8B  HeaderRight(HREP rp);
F8B  HeaderBottom(HREP rp);
F8B  FooterWidth(HREP rp);
F8B  FooterHeight(HREP rp);
F8B  FooterLeft(HREP rp);
F8B  FooterTop(HREP rp);
F8B  FooterRight(HREP rp);
F8B  FooterBottom(HREP rp);

#define  RSW_AUTOSETTING    0x01
#define  RSW_SKIPPAGESETUP  0x02

#define  RSW_AUT  RSW_AUTOSETTING
#define  RSW_SKP  RSW_SKIPPAGESETUP

void SetReqBodyWidth(HREP rp, F8B w, I4B sw);
F8B  ReqBodyWidth(HREP rp);

pCELL PageCell(pCELL pc, HREP rp);
pCELL BodyCell(pCELL pc, HREP rp);
pCELL HeaderCell(pCELL pc, HREP rp);
pCELL FooterCell(pCELL pc, HREP rp);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

BOOL EditRowDlgBox(HWND hwnd, HBUF rb, rSTR tit);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

HIMG LoadIMG(HIMG im, rSTR nam);
BOOL SaveIMG(HIMG im, rSTR nam);

HDIB LoadJPG(HDIB bm, rSTR nam);
BOOL SaveJPG(HDIB bm, rSTR nam);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//

void StatMsg(HWND hwnd, rSTR st);
void BusyMsg(HWND hwnd, rSTR st);
void EndBusy(HWND hwnd);

//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//
