| 1 | #ifndef __SCN2K_CMD_H__ |
|---|
| 2 | #define __SCN2K_CMD_H__ |
|---|
| 3 | |
|---|
| 4 | #include <vector> |
|---|
| 5 | #include <string> |
|---|
| 6 | #include <map> |
|---|
| 7 | |
|---|
| 8 | #include "scn2k_flags.h" |
|---|
| 9 | |
|---|
| 10 | #define STRHEAP_SIZE 10000 |
|---|
| 11 | enum Cmdtype { |
|---|
| 12 | CMD_NOP, CMD_FLAGS, CMD_JMP, CMD_TEXT, CMD_OTHER, CMD_SYSVAR, |
|---|
| 13 | CMD_TEXTEND, |
|---|
| 14 | CMD_SAVECMDGRP, CMD_SAVECMDGRP_START, CMD_SAVECMDGRP_ONCE, CMD_SAVECMD_ONCE, CMD_WAITFRAMEUPDATE,CMD_SAVEPOINT, CMD_ROLLBACKPOINT, |
|---|
| 15 | CMD_SAVEREQ, CMD_SAVE, |
|---|
| 16 | CMD_LOADREQ, CMD_LOAD, |
|---|
| 17 | CMD_MENUREQ, |
|---|
| 18 | CMD_BACKLOGREQ, CMD_BACKLOGREQ_FWD, |
|---|
| 19 | CMD_END}; |
|---|
| 20 | |
|---|
| 21 | enum SkipMode { |
|---|
| 22 | SKIP_NO=0, SKIP_TEXT=1, SKIP_GRP_FAST=16, SKIP_GRP_NOEFFEC=32, |
|---|
| 23 | SKIP_GRP_NODRAW=64, SKIPEND_TEXT=256, SKIPEND_KEY=512, SKIP_IN_MENU=1024 |
|---|
| 24 | }; |
|---|
| 25 | |
|---|
| 26 | struct CmdSimplified { // Cmd ä¿åçš |
|---|
| 27 | int type, cmd1, cmd2, cmd3, cmd4, argc; |
|---|
| 28 | char* args; |
|---|
| 29 | void Save(std::string& save); |
|---|
| 30 | void Load(const char* save, char*& args_buffer); |
|---|
| 31 | void copy(const CmdSimplified& from, char*& args_buffer); |
|---|
| 32 | }; |
|---|
| 33 | |
|---|
| 34 | class SimpleCmd { |
|---|
| 35 | public: |
|---|
| 36 | SimpleCmd(int a, int b, int c); |
|---|
| 37 | SimpleCmd(); |
|---|
| 38 | |
|---|
| 39 | bool operator==(const SimpleCmd& cmd) const; |
|---|
| 40 | bool operator<(const SimpleCmd& cmd) const; |
|---|
| 41 | |
|---|
| 42 | public: |
|---|
| 43 | int cmd1, cmd2, cmd3; |
|---|
| 44 | }; |
|---|
| 45 | |
|---|
| 46 | class Cmd : public SimpleCmd{ |
|---|
| 47 | public: |
|---|
| 48 | Cmdtype cmd_type; |
|---|
| 49 | int cmd4; |
|---|
| 50 | int argc; |
|---|
| 51 | int pos, scn; |
|---|
| 52 | const char* rawdata; |
|---|
| 53 | char cmdstr[1024]; |
|---|
| 54 | std::vector<VarInfo> args; |
|---|
| 55 | |
|---|
| 56 | private: |
|---|
| 57 | const Flags& flags; |
|---|
| 58 | bool errorflag; |
|---|
| 59 | int system_version; |
|---|
| 60 | |
|---|
| 61 | int GetArgs(const char*& d); |
|---|
| 62 | int GetArgsSpecial(int normal_args,const char*& d); |
|---|
| 63 | void GetSelection(const char*& d); |
|---|
| 64 | int GetSwitch(const char*& d); |
|---|
| 65 | int GetSimpleSwitch(const char*& d); |
|---|
| 66 | int GetExpression(const char*& d, struct VarInfo* info = 0); |
|---|
| 67 | int GetExpressionCond(const char*& d); |
|---|
| 68 | int GetLeftToken(const char*& d, struct VarInfo& info); |
|---|
| 69 | int GetString(const char*& d); |
|---|
| 70 | int CopyString(const char* d); |
|---|
| 71 | int StrVar(int type, int number); |
|---|
| 72 | static char strtype[256]; |
|---|
| 73 | static int StrType(const char* d) { return strtype[*(unsigned const char*)d];} |
|---|
| 74 | |
|---|
| 75 | public: |
|---|
| 76 | const char* Str(const VarInfo& info) const; |
|---|
| 77 | int AddStr(char* s); |
|---|
| 78 | |
|---|
| 79 | private: |
|---|
| 80 | char strheap[STRHEAP_SIZE]; |
|---|
| 81 | int strend; |
|---|
| 82 | void SetError(void) { errorflag = true;} |
|---|
| 83 | void ResetString(void) { |
|---|
| 84 | strend = 0; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | public: |
|---|
| 88 | void GetCmd(Flags& f, const char*& d); |
|---|
| 89 | void SetSysvar(int n, int v); |
|---|
| 90 | void SetSysvar(int v) { SetSysvar(TYPE_SYS_SYS, v); } |
|---|
| 91 | void SetFlagvar(VarInfo info, int v); |
|---|
| 92 | void SetStrvar(VarInfo info, const std::string& s); |
|---|
| 93 | bool IsError() { return errorflag;} |
|---|
| 94 | void clear(void); |
|---|
| 95 | virtual const char * CmdDescr(int, int, int, int) { return "Not supported"; } |
|---|
| 96 | Cmd(const Flags& f, int _sys_ver); |
|---|
| 97 | void read(const CmdSimplified& cmd); |
|---|
| 98 | void write(CmdSimplified& cmd, char*& args_buffer) const; |
|---|
| 99 | }; |
|---|
| 100 | |
|---|
| 101 | class CommandHandler { |
|---|
| 102 | public: |
|---|
| 103 | typedef void (CommandHandler::*CmdImpl)(Cmd& cmd); |
|---|
| 104 | typedef struct { |
|---|
| 105 | const char* descr; |
|---|
| 106 | CmdImpl function; |
|---|
| 107 | } CommandInfo; |
|---|
| 108 | void RegisterCommand(int cmd1, int cmd2, int cmd3, const char* descr, CmdImpl func); |
|---|
| 109 | bool Exec(Cmd& cmd); |
|---|
| 110 | void PrintCmd(Cmd& cmd); |
|---|
| 111 | |
|---|
| 112 | private: |
|---|
| 113 | typedef std::map<SimpleCmd, CommandInfo> CommandMap; |
|---|
| 114 | CommandMap command_map; |
|---|
| 115 | }; |
|---|
| 116 | |
|---|
| 117 | #endif |
|---|