/*乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//
    boldbe.h
//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗*/

#define  WINAPI  __stdcall
#define  WINAPIV __cdecl

#define  LOCALF  static __stdcall
#define  LOCALFV static __cdecl

#ifdef __cplusplus
extern "C" {
#endif

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

#ifdef OWN_USE
enum {
  E_STA = 70,
         E_RDO, E_FIX, E_CAL, E_CMP, E_IRO, E_ICO, E_ITB, e_078, E_NIN, // 70- 79
  E_NOL, E_DUL, E_BSA, E_BSD, E_RDW, E_DBN, E_DBT, E_DBD, e_088, E_NOC, // 80- 89
  E_DUC, e_091, e_092, E_LCK, E_ORO, E_ORW, E_CNF, E_NZR, E_UNI, E_CHK, // 90- 99
  E_KEY, E_REF, E_NUS, E_NPW, E_MIS, E_TBN, E_TBT, E_TBD, E_CON, E_COT, //100-109
  E_COD, E_NTP, E_NFC, E_NEN, E_NCO, E_NSE, E_ALN, E_RSZ, E_NKY, E_NRF, //110-119
  E_CSZ, E_CKY, E_RKY, E_NUN, E_NOA, e_125, e_126, e_127,               //120-127
};
#endif

#define  i32Box(va)  I4BBox(va)
#define  i64Box(va)  I8BBox(va)
#define  f32Box(va)  F4BBox(va)
#define  f64Box(va)  F8BBox(va)

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

enum {
  TID_VOI,  // 00
  TID_I1B,  // 01 = CT_I1B
  TID_U1B,
  TID_I2B,
  TID_U2B,
  TID_I4B,
  TID_U4B,
  TID_I8B,
  TID_U8B,
  TID_F4B,
  TID_F8B,  // 10 = CT_F8B
  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 struct COLI *pCOLI, *PCOLI;
typedef const struct COLI *rCOLI, *PCCOLI;

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

#ifdef OWN_USE
void WINAPI override_tp_fscn(FSCN fscn);
void WINAPI override_tp_fprn(FPRN fprn);
void WINAPI override_tp_fcmp(FCMP fcmp);
void WINAPI override_tp_flst(FLST flst);
#endif

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 WINAPI RegisterColumnTypeX(rTYPI tp, BOOL ov);
BOOL WINAPI RegisterColumnType(rTYPI tp);
rTYPI WINAPI ColumnType(rCOLI co);

#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 (CALLBACK *FCAL)(pANY pv, rANY pb, rCOLI co);
typedef BOOL (CALLBACK *FCHK)(rANY pb, rCOLI co);

#ifdef OWN_USE
void WINAPI override_co_fcal(FCAL fcal);
void WINAPI override_co_fchk(FCHK fchk);
#endif

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

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

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

rANY WINAPI VPtr(rANY pb, rCOLI co);

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

typedef struct HTBL_ *HTBL;

HTBL WINAPI 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 (CALLBACK *FTRG)(HTBL tb, I4B msg, I4B ir, pANY pb);

#ifdef OWN_USE
void WINAPI override_tb_ftrg(FTRG ftrg);
#endif

#ifdef OWN_USE
typedef struct HTBL_ {
  HBLK  mb;
  pCOLS cs;
  pIDXS vr;
  pIDXS vc;
  HTBL  otb;
  rSTR  nam;
  rSTR  tit;
  rSTR  dsc;
  I4B   flg;
  FTRG  ftrg;
  rSTR  imp;
  uANY  ext;
} TBLE;
#else
typedef struct HTBL_ { I4B unused;};
#endif

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 WINAPI CreateTableX(pANY pv, I4B len, I4B cap, rTBLI ti);
HTBL WINAPI CreateTable(I4B cap, rTBLI ti);
void WINAPI DeleteTable(HTBL tb);

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

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

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

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

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

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

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

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

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

void WINAPI SetTableExtra(HTBL tb, uANY pa);
uANY WINAPI 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 WINAPI DefaultTableTrigger(HTBL tb, I4B msg, I4B ir, pANY pb);
BOOL WINAPI TableTrigger(HTBL tb, I4B msg, I4B ir, pANY pb);

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

I4B  WINAPI NTableColumns(HTBL tb);

rCOLI WINAPI TableColumnInfo(HTBL tb, I4B ic);

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

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

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

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

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

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

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

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

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

pANY WINAPI NewTableRow(HTBL tb);

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

I4B  WINAPI CompareTable(HTBL tb, HTBL tx);

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

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

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

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

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

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

void WINAPI SortTableRowsX(HTBL tb, FSRT fsrt, uANY pa);

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

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

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

BOOL WINAPI CheckTable(HTBL tb);

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

BOOL WINAPI OpenBTB(HTBL tb);
BOOL WINAPI CloseBTB(HTBL tb, BOOL sv);

void WINAPI OverrideTableTrigger(HTBL tb, FTRG ftrg);

HTBL WINAPI CreateARRTable(I4B cap, HTBL tb);
BOOL WINAPI ScanARRTable(HTBL ta, rSTR arr);
pSTR WINAPI PrintARRTable(pSTR arr, HTBL ta);
void WINAPI InsertARRTableRow(HTBL ta, I4B i1, I4B i2);
I4B  WINAPI DeleteARRTableRow(HTBL ta, I4B i1);

#define  VIWCAP 10

HTBL WINAPI CreateCNDTable(I4B cap, HTBL tb);
BOOL WINAPI ScanCNDTable(HTBL tc, rSTR cnd);
pSTR WINAPI PrintCNDTable(pSTR cnd, HTBL tc);

HTBL WINAPI CreateSRTTable(I4B cap, HTBL tb);
BOOL WINAPI ScanSRTTable(HTBL ts, rSTR srt);
pSTR WINAPI PrintSRTTable(pSTR srt, HTBL ts);

HTBL WINAPI CreateGRPTable(I4B cap, HTBL tb);
BOOL WINAPI ScanGRPTable(HTBL tg, rSTR grp);
pSTR WINAPI PrintGRPTable(pSTR grp, HTBL tg);

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

typedef struct {
#ifdef OWN_USE
  HBLK  mb;
  pCOLS cs;
  pIDXS vr;
  pIDXS vc;
  HTBL  otb;
  rSTR  nam;
  rSTR  tit;
  rSTR  dsc;
  I4B   flg;
  FTRG  ftrg;
  rSTR  imp;
  uANY  ext;
#else
  I4B unused;
#endif
} HBUF_;
typedef HBUF_ *HBUF;

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

HBUF WINAPI DuplicateRowBuf(HBUF rb);

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

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

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

BOOL WINAPI ClearRowBuf(HBUF rb);

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

HBUF WINAPI CopyKey(HBUF rb, HBUF rx);

I4B  WINAPI CompareRowBuf(HBUF rb, HBUF rx);

I4B  WINAPI SearchKey(HTBL tb, HBUF rb);

HTBL WINAPI MergeTable(HTBL tb, HTBL tx);

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

I4B  WINAPI SearchTableRow(HTBL tb, I4B i0, rSTR cnd);
I4B  WINAPI CountTableRows(HTBL tb, rSTR cnd);
I4B  WINAPI SelectTableRows(HTBL tb, rSTR cnd);

HTBL WINAPI SelectCopyTable(HTBL tb, HTBL tx, rSTR cnd);
HTBL WINAPI SelectMergeTable(HTBL tb, HTBL tx, rSTR cnd);

#define  AGG_SUM  1
#define  AGG_AVG  2
#define  AGG_MAX  3
#define  AGG_MIN  4
#define  AGG_COU  5
#define  AGG_GRP 10

F8B  WINAPI AggregateTable(HTBL tb, I4B ic, I4B sw, rSTR cnd);

void WINAPI SortTableRows(HTBL tb, rSTR srt);

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

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

typedef struct {
  I1B   nam[32];
  U1B   ud;
  U1B   us;
  U2B   fc;
  I1B   arr[510];
  I1B   cnd[320];
  I1B   srt[320];
} VIWE;
typedef VIWE *pVIWE, *PVIWE;
typedef const VIWE *rVIWE, *PCVIWE;

HTBL WINAPI CreateVIWTable(I4B cap, rVIWS vs);

pVIWI WINAPI SetVIWInfo(pVIWI vi, HBUF bv);
I4B  WINAPI SearchVIWTableRow(HTBL tv, HBUF bv);
I4B  WINAPI SearchVIWTableRowByName(HTBL tv, rSTR nam);
void WINAPI SetLastVIW(HTBL tv, HBUF bv);
I4B  WINAPI GetLastVIW(HTBL tv);
void WINAPI CopyUserVIWTable(HTBL tv, HTBL tx);

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

typedef struct {
#ifdef OWN_USE
  HBLK  mb;
  pCOLS cs;
  pIDXS vr;
  pIDXS vc;
  HTBL  otb;
  rSTR  nam;
  rSTR  tit;
  rSTR  dsc;
  I4B   flg;
  FTRG  ftrg;
  rSTR  imp;
  uANY  ext;
#else
  I4B unused;
#endif
} HVIW_;
typedef HVIW_ *HVIW;

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

HTBL WINAPI ViewHTBL(HVIW vw);

I4B  WINAPI NViewRows(HVIW vw);

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

I4B  WINAPI NViewColumns(HVIW vw);

rCOLI WINAPI ViewColumnInfo(HVIW vw, I4B ic);

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

#define  DEFCWID  5

I4B  WINAPI ViewColumnWidthF(HVIW vw, I4B ic);

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

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

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

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

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

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

BOOL WINAPI SetViewCellValue(HVIW vw, I4B ir, I4B ic, rANY pv);
pANY WINAPI GetViewCellValue(pANY pv, HVIW vw, I4B ir, I4B ic);
BOOL WINAPI ScanViewCellValue(HVIW vw, I4B ir, I4B ic, rSTR st);
BOOL WINAPI ScanViewCellValueF(HVIW vw, I4B ir, I4B ic, rSTR st);
pSTR WINAPI 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 WINAPI PrintViewCellValueF(pSTR st, HVIW vw, I4B ir, I4B ic, I4B flg);

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

pANY WINAPI NewViewRow(HVIW vw);

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

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

HTBL WINAPI CreateSummary(HVIW vw, rSTR grp);

I4B  WINAPI SearchViewCellValue(HVIW vw, I4B i0, I4B ic, rANY pv);
I4B  WINAPI 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 WINAPI ReadCSV(HVIW vw, rSTR nam, rCSVI cv);
BOOL WINAPI WriteCSV(HVIW vw, rSTR nam, rCSVI cv);

BOOL WINAPI ReadINI(pANY pb, rTBLI ti);
BOOL WINAPI WriteINI(pANY pb, rTBLI ti);

BOOL WINAPI ReadATR(pANY pb, rTBLI ti, rSTR st);

I4B  WINAPI RowBlkSize(HVIW vw, I4B nr);
void WINAPI CopyRowBlk(pANY pv, HVIW vw, I4B i0, I4B nr);
BOOL WINAPI InsertRowBlk(HVIW vw, I4B i0, rANY pv);

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

typedef struct {
  rSTR  nam;
  rSTR  tit;
  rSTR  dsc;
  rSTR  dir;
  F8B   tax;
  I4B   fym;
  I4B   nmf;
} SITI;
typedef SITI *pSITI, *PSITI;
typedef const SITI *rSITI, *PCSITI;

void WINAPI SetSiteVariables(rSITI sv);

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

void WINAPI SetUserPath(rSTR dir);
rSTR WINAPI UserPath(void);

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

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

#define  PRO_DEF  1
#define  EXT_DEF  ".BCF"

typedef I4B  (CALLBACK *FENM)(HTBL tb, I4B pro);
typedef void (CALLBACK *FDIS)(void);

#ifdef OWN_USE
void WINAPI override_db_fenm(FENM fenm);
void WINAPI override_db_fdis(FDIS fdis);
#endif

typedef struct {
  I1B   usr[32];
  I1B   pwd[32];
  I4B   lev;
} BSAI;
typedef BSAI *pBSAI, *PBSAI;
typedef const BSAI *rBSAI, *PCBSAI;

HTBL WINAPI CreateBSATable(I4B cap, BOOL ld);

typedef struct {
  I1B   nam[16];
  I1B   tit[32];
  I1B   dsc[64];
} BSDI;
typedef BSDI *pBSDI, *PBSDI;
typedef const BSDI *rBSDI, *PCBSDI;

HTBL WINAPI CreateBSDTable(I4B cap, I4B pro);

typedef struct {
  I1B   usr[32];
} BSUI;
typedef BSUI *pBSUI, *PBSUI;
typedef const BSUI *rBSUI, *PCBSUI;

HTBL WINAPI CreateBSUTable(I4B cap, BOOL ld);

typedef BSDI BDDI;
typedef BDDI *pBDDI, *PBDDI;
typedef const BDDI *rBDDI, *PCBDDI;

HTBL WINAPI CreateBDDTable(I4B cap, BOOL ld);

typedef BSUI BDUI;
typedef BDUI *pBDUI, *PBDUI;
typedef const BDUI *rBDUI, *PCBDUI;

HTBL WINAPI CreateBDUTable(I4B cap, BOOL ld);

typedef struct {
  I4B   id;
  I1B   usr[32];
} LCKI;
typedef LCKI *pLCKI, *PLCKI;
typedef const LCKI *rLCKI, *PCLCKI;

HTBL WINAPI CreateLCKTable(I4B cap, BOOL ld);

BOOL WINAPI LoginSite(rSTR usr, rSTR pwd);
void WINAPI LogoutSite(void);
void WINAPI ForceLogoutSite(rSTR usr);

rSTR WINAPI CurUser(void);
I4B  WINAPI 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;

typedef HTBL (CALLBACK *FCRE)(I4B cap, rTBLI ti);
BOOL WINAPI ConnectDBXX(rBDBI db, FCRE fcre);

BOOL WINAPI ConnectDBX(rBDBI db);

void WINAPI DisconnectDB(void);

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

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

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

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

HOPN WINAPI CreateHOPN(HTBL tb, BOOL rw);
HOPN WINAPI OpenBSATable(BOOL rw);

#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 WINAPI OpenTableX(rIDXS pt, I4B md);
#define  OpenTablesX(pt, md)  OpenTableX(pt, md)
HOPN WINAPI OpenTable(rSTR tbs, I4B md);
#define  OpenTables(tbs, md)  OpenTable(tbs, md)
BOOL WINAPI SaveTable(HOPN op);
#define  SaveTables(op)  SaveTable(op)
BOOL WINAPI CloseTable(HOPN op, BOOL sv);
#define  CloseTables(op, sv)  CloseTable(op, sv)

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

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

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

U4B  WINAPI BOLDBEVer(void);

BOOL WINAPI InitBOLDBE(uANY pa);
void WINAPI TermBOLDBE(void);

#ifdef __cplusplus
}
#endif

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