/*乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗//
    bolbas.h
//乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗乗*/

#define  WINAPI  __stdcall
#define  WINAPIV __cdecl

#define  LOCALF  static __stdcall
#define  LOCALFV static __cdecl

#ifdef __cplusplus
extern "C" {
#endif

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

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

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

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

pSTR WINAPI mbschr(rSTR st, I4B c);
pSTR WINAPI mbsrchr(rSTR st, I4B c);
U4B  WINAPI 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  WINAPI strmatchx(rSTR s1, rSTR s2, I4B flg);
BOOL WINAPI strmatch(rSTR s1, rSTR s2);
pSTR WINAPI strfindx(rSTR s1, rSTR s2, I4B flg);
pSTR WINAPI strfind(rSTR s1, rSTR s2);
BOOL WINAPI strlfind(rSTR s1, rSTR s2);
BOOL WINAPI strrfind(rSTR s1, rSTR s2);
pSTR WINAPI strifind(rSTR s1, rSTR s2);
BOOL WINAPI strilfind(rSTR s1, rSTR s2);
BOOL WINAPI strirfind(rSTR s1, rSTR s2);
BOOL WINAPI strlike(rSTR s1, rSTR s2);
BOOL WINAPI strmlike(rSTR s1, rSTR s2);
BOOL WINAPI strllike(rSTR s1, rSTR s2);
BOOL WINAPI strrlike(rSTR s1, rSTR s2);
I4B  WINAPI strcount(rSTR s1, rSTR s2);

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

#define  LSTR  LBUF
typedef  I1B  STRBUF[LSTR];

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

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

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

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

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

BOOL WINAPI is_leap_year(I4B yr);
I4B  WINAPI 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  WINAPI day_of_week(I4B yr, I4B mo, I4B dy);

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

I4B  WINAPI today(void);

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

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

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

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

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

I4B  WINAPI ztot(rSTR st);

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

F8B  WINAPI now(void);

F8B  WINAPI ztodt(rSTR st);

I4B  WINAPI dtprintf(pSTR st, rSTR fmt, F8B dt);
rSTR WINAPI 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 WINAPI get_system_time(pSTMI lp);
void WINAPI get_local_time(pSTMI lp);
U4B  WINAPI get_tick_count(void);
void WINAPI wait_millisec(U4B ms);

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

I4B  WINAPI compare_file_time(rFTMI ft1, rFTMI ft2);
BOOL WINAPI file_time_to_system_time(pSTMI lp, rFTMI ft);
BOOL WINAPI 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  WINAPI check_path(rSTR nam);
pSTR WINAPI 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 WINAPI open_file(rSTR nam, U4B flg);
BOOL WINAPI close_file(HFIL hf);

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

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

U4B  WINAPI get_file_size(HFIL hf);

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

BOOL WINAPI read_line(HFIL hf, pSTR bf, I4B sz);
BOOL WINAPI 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 WINAPI find_first_file(rSTR nam, pFFDI lp);
BOOL WINAPI find_next_file(HFIL hf, pFFDI lp);
BOOL WINAPI find_close(HFIL hf);

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

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

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

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

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

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

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

HWND WINAPI set_error_message_box_owner(HWND hwnd);
HWND WINAPI error_message_box_owner(void);

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

pSTR WINAPI error_reporting_message(pSTR msg, rSTR em, U4B er, rSTR fn, U4B lo);
pSTR WINAPI error_logging_message(pSTR msg, rSTR em, U4B er, rSTR fn, U4B lo);

void WINAPI start_debug(BOOL rm);
void WINAPI stop_debug(void);

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

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

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

#define  CreateStrBlk(cap)  CreateBinBlk(cap)
#define  DeleteStrBlk(sb)  DeleteBinBlk(sb)

#define  MakeStrBlk(pv, len, cap)  MakeBinBlk(pv, len, cap)

HBLK WINAPI SelectStrBlk(HBLK sb);

rSTR WINAPI stostr(rSTR st);

rSTR WINAPI dirnam(rSTR nam);
rSTR WINAPI basnam(rSTR nam);
rSTR WINAPI basnamx(rSTR nam);
rSTR WINAPI adddir(rSTR dir, rSTR nam);
rSTR WINAPI addext(rSTR nam, rSTR ext);

HBLK WINAPI CreateTXT(I4B cap);
#define  DeleteTXT(xb)  DeleteArray(xb)
#define  UnloadTXT(xb)  DeleteTXT(xb)

HBLK WINAPI DuplicateTXT(HBLK xb);
HBLK WINAPI MakeTXT(rSTR st);
HBLK WINAPI MoveTXT(HBLK xb, HBLK xx);
I4B  WINAPI CompareTXT(HBLK xb, HBLK xx);

HBLK WINAPI LoadTXT(HBLK xb, rSTR nam);
BOOL WINAPI SaveTXT(HBLK xb, rSTR nam);

U4B  WINAPI RowExt(HBLK xb);
U4B  WINAPI PtrRow(HBLK xb, rSTR pc);
pSTR WINAPI RowPtr(HBLK xb, U4B rc);
I4B  WINAPI RowLen(HBLK xb, U4B rc);

U4B  WINAPI CharPos(HBLK xb, U4B rc);
U4B  WINAPI PrevPos(HBLK xb, U4B rc);
U4B  WINAPI NextPos(HBLK xb, U4B rc);

pSTR WINAPI CopyStr(pSTR st, HBLK xb, U4B r1, U4B r2);
BOOL WINAPI InsertStr(HBLK xb, U4B rc, rSTR st);
BOOL WINAPI DeleteStr(HBLK xb, U4B r1, U4B r2);
BOOL WINAPI AddStr(HBLK xb, rSTR st);
U4B  WINAPI SearchStr(HBLK xb, U4B r0, rSTR st, I4B flg);
BOOL WINAPI ReplaceStr(HBLK xb, rSTR s1, rSTR s2);

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

enum {
  CT_VOI,  CT_I1B,  CT_U1B,  CT_I2B,  CT_U2B,  CT_I4B,  CT_U4B,  CT_I8B,  // 00-07
  CT_U8B,  CT_F4B,  CT_F8B,                                               // 08-0a
  CT_ERR = -1,
};

I4B  WINAPI ctpsiz(I4B typ);

typedef I4B  (CALLBACK *FTKN)(rSTR *pp, pBIN bf, uANY pa);

typedef struct {
  FTKN  fspc;
  FTKN  fcns;
  FTKN  fstr;
  FTKN  fkwd;
  FTKN  fopr;
  uANY  pa;
} LEXI;
typedef LEXI *pLEXI, *PLEXI;
typedef const LEXI *rLEXI, *PCLEXI;

typedef struct { I4B unused;} HLEX_;
typedef HLEX_ *HLEX;

HLEX WINAPI CreateParsEnv(rLEXI li);
void WINAPI DeleteParsEnv(HLEX le);
HLEX WINAPI SelectParsEnv(HLEX le);

void WINAPI start(rSTR pt);
void WINAPI restart(rSTR pt);
rSTR WINAPI cpos(void);
pANY WINAPI buf(void);

enum {
  TKN_ERR =  0,
  TKN_I4B =  5,
  TKN_U4B =  6,
  TKN_I8B =  7,
  TKN_U8B =  8,
  TKN_F8B = 10,
  TKN_STR = 11,
  TKN_IDN = 12,
  TKN_OPR = 32,
  TKN_KWD = 96,
  TKN_END = -1,
  TKN_I32 = TKN_I4B,
  TKN_U32 = TKN_U4B,
  TKN_I64 = TKN_I8B,
  TKN_U64 = TKN_U8B,
  TKN_F64 = TKN_F8B,
};

I4B  WINAPI token(void);
BOOL WINAPI token_is(I4B cd);
BOOL WINAPI lookahead_is(I4B cd);
I4B  WINAPI lookahead(void);
I4B  WINAPI lookbehind(void);
U4B  WINAPI errpos(void);

BOOL WINAPI isidn(rSTR st);

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

U4B  WINAPI BOLBASVer(void);

BOOL WINAPI InitBOLBAS(uANY pa);
void WINAPI TermBOLBAS(void);

#ifdef __cplusplus
}
#endif

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