⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interpreter.cc

📁 Unix下的MUD客户端程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
                            default:                status->setf("%cexec: %s", CMDCHAR, (const char*)res);                return;            }                // Do some sanity checking        if (h < 3 || w < 3 || x < 0 || y < 0)            status->setf("Value too low.");        else if (w+x > screen->width || y+h > screen->height)            status->setf("Value too large.");        else            new Shell(screen, res, w,h,x,y,t);            }    else if (!strcmp(cmd, "window"))    {        int w = 80, h=10, x=0, y=3, t=10;        int c;        bool popup = true;        bool noborder = false;        int color = bg_black|fg_white;        String logfile;        String res;                OptionParser o(s, "w:h:x:y:t:Hl:Bc:");                while((c = o.nextOption(res)))            switch (c)            {            case 'w':                w  = atoi(res);                break;                            case 'h':                h = atoi(res);                break;                            case 'x':                x = atoi(res);                break;                            case 'y':                y = atoi(res);                break;                            case 't':                t = atoi(res);                break;                            case 'l':                logfile = res;                break;                            case 'H':                popup = false;                break;            case 'B':                noborder = true;                break;                            case 'c':                color = atoi(res);                break;                            default:                status->setf("%cwindow: %s", CMDCHAR, (const char*)res);                return;            }                int min_h = 3;        if (noborder)            min_h = 1;                // Do some sanity checking        if (h < min_h || w < min_h)            status->setf("%cwindow: Value too low.", CMDCHAR);        else if (w+abs(x) > screen->width || abs(y)+h > screen->height)            status->setf("%cwindow: Value too large.", CMDCHAR);        else if (!res.len())            status->setf("%cwindow needs a name", CMDCHAR);        else if (MessageWindow::find(res))        {            status->setf("Window %s already exists", (const char*) res);        }        else  {            Window::Style style;            if (!noborder)                style = Window::Bordered;            else                style = Window::None;                        MessageWindow *mw =  new MessageWindow(screen, res, logfile, w,h,x,y, style, t, popup, color);                        if (!popup)                mw->show(false);        }            }        else if (!strcmp(cmd, "kill")) {        MessageWindow *w;        if (!(w = MessageWindow::find(s)))            status->setf ("No such window: %s", s);        else            w->die();    }    else if (!strcmp(cmd, "clear")) {        char name[128];                s = one_argument(s, name, false);                if (!name[0])            status->setf("%cclear what window?", CMDCHAR);        else {            MessageWindow *w = MessageWindow::find(name);            if (!w)                status->setf("%cclear: %s: no such window", CMDCHAR, name);            else                w->clear();        }    }    else if (!strcmp(cmd, "prompt")) {        inputLine->set_prompt(s);    }    else if (!strcmp(cmd, "print")) {        char name[128];                s = one_argument(s, name, false);                if (!name[0])            status->setf("%cprint to what window?", CMDCHAR);        else        {            MessageWindow *w = MessageWindow::find(name);            if (!w)                status->setf("%cprint: %s: no such window", CMDCHAR, name);            else                w->addInput(s);        }    } else if (!strcmp(cmd, "disable")) {        if (!strcasecmp(s, "aliases")) {            aliases_disabled = true;            status->setf("Aliases disabled.");        }        else if (!strcasecmp(s, "actions")) {            actions_disabled = true;            status->setf("Actions disabled.");        }        else if (!strcasecmp(s, "speedwalk")) {            config->setOption(opt_speedwalk,false);            status->setf("Speedwalk disabled.");        }        else if (!strcasecmp(s, "macros")) {            macros_disabled = true;            status->setf("Keyboard macros disabled.");        }        else if (!strcasecmp(s, "semicolon")) {            config->setOption(opt_expand_semicolon, false);            status->setf("Semicolon NOT expanded on input line");        }        else            status->setf("%cdisable (actions|aliases|speedwalk|macros|semicolon)", CMDCHAR);    } else if (!strcmp(cmd, "enable")) {        if (!strcasecmp(s, "aliases")) {            status->setf("Aliases enabled.");            aliases_disabled = false;        }        else if (!strcasecmp(s, "speedwalk")) {            config->setOption(opt_speedwalk, true);            status->setf("Speedwalk enabled.");        }        else if (!strcasecmp(s, "actions")) {            status->setf("Actions enabled.");            actions_disabled = false;        }        else if (!strcasecmp(s, "macros")) {            macros_disabled = false;            status->setf("Keyboard macros enabled.");        }        else if (!strcasecmp(s, "semicolon")) {            config->setOption(opt_expand_semicolon, true);            status->setf("Semicolon expanded on input line.");        }        else            status->setf("%cenable (actions|aliases|speedwalk|macros|semicolon)", CMDCHAR);    }        else if (!strcmp(cmd, "writeconfig")) {        status->setf("Saving configuration to %s", s ? s : ~config->filename);        config->Save(s);    }    else if (!strcmp(cmd, "alias")) // add alias    {        char name[MAX_INPUT_BUF];                if (!s[0])            status->setf ("Press Alt-A to list active aliases; Alt-O then A to list local ones");        else         {            s = one_argument(s, name, false);            Alias *a = globalMUD.findAlias(name);                        if (!s[0]) {                if (!a)                    status->setf ("There is no global alias named '%s'", name);                else  {                    status->setf ("Removed global alias '%s'", name);                    globalMUD.alias_list.remove(a);                    delete a;                }            } else {                if (a) {                    status->setf ("Replaced alias '%s' with %s", ~a->name, s);                    a->text = s;                } else {                    status->setf ("Added new alias %s = %s", name,s);                    globalMUD.alias_list.insert(new Alias(name,s));                }            }        }    }    else if (!strcmp(cmd, "close")) {        if (!currentSession || currentSession->state == disconnected)            status->setf ("You are not connected - nothing to close");        else        {            status->setf ("Closing link to %s@%s:%d", ~currentSession->mud.name, currentSession->mud.getHostname(), currentSession->mud.getPort());            inputLine->set_default_prompt();            delete currentSession;            currentSession = NULL;        }    }    else if (!strcmp(cmd, "open")) {        if (currentSession && currentSession->state != disconnected)            status->setf ("You are connected to %s, use %cclose first", ~currentSession->mud.name, CMDCHAR);        else if (!s[0])            status->setf ("%copen connection to where?", CMDCHAR);        else        {            MUD *mud;            if (!(mud = config->findMud (s)))                status->setf ("MUD '%s' was not found", s);            else            {                delete currentSession;                currentSession = new Session(*mud, output);                currentSession->open();                lastMud = mud;            }        }    }        else if (!strcmp(cmd, "macro")) {        char name[MAX_INPUT_BUF];        Macro *m;                s = one_argument(s, name, true);        int key = key_lookup(name);                if (key < 0)            status->setf ("Unknown key in macro definition: %s", name);        else {            m = globalMUD.findMacro(key, false);                        if (!s[0]) { // remove macro                if (!m)                    status->setf("No such macro");                else {                    globalMUD.macro_list.remove(m);                    status->setf("Removed macro %s => %s", name, ~m->text);                    delete m;                }            } else { // Add new or change existing                if (!m) {                    m = new Macro(key, s);                    status->setf("Added new macro: %s => %s", name,s);                    globalMUD.macro_list.append(m);                } else {                    status->setf("Changed macro %s: from %s to %s", name, ~m->text, s);                    m->text = s;                }            }        }    }    else if (!strcmp(cmd, "action") || !strcmp(cmd, "subst"))    {        char name[256];        s = one_argument(s, name, false);                if (!name[0])            status->setf ("Add/remove what action?");        else if (!s[0]) {            FOREACH(Action*, a, globalMUD.action_list)                if (a->pattern == name)                {                    status->setf ("Action %s => %s removed", (const char*) a->pattern, (const char *) a->commands);                    globalMUD.action_list.remove(a);                    delete a;                    return;                }                        status->setf("Action '%s' was not found", name);        } else {            char buf[MAX_MUD_BUF];            String res;                        sprintf(buf, "\"%s\" %s", name, s);                        Action *new_action = Action::parse (buf, res, (!strcmp(cmd, "action")) ? Action::Trigger : Action::Replacement);            if (!new_action)                status->setf ("Error compiling action: %s", ~res);            else {                FOREACH(Action*,a, globalMUD.action_list)                    if (a->pattern == name)  {                        status->setf ("Replaced action '%s' with '%s'", (const char*) new_action->pattern, (const char *) new_action->commands);                        globalMUD.action_list.remove(a);                        delete a;                        globalMUD.action_list.insert(new_action);                        return;                    }                                globalMUD.action_list.insert(new_action);                status->setf ("Added action '%s' => '%s'", (const char*) new_action->pattern, (const char *) new_action->commands);            }        }    }        else if (!strcmp(cmd, "send")) {        if (!currentSession)            status->setf("No session active");        else            currentSession->writeMUD(s);    }    else if (!strcmp(cmd, "send_unbuffered")) {        if (!currentSession)            status->setf("No session active");        else            currentSession->writeUnbuffered(Sprintf("%s\n", s),strlen(s)+1);    }    else if (!strcmp(cmd, "reopen")) {        if (!lastMud)            status->setf ("There is no MUD to reconnect to");        else        {            char buf[256];            snprintf (buf, 256, "open %s", ~lastMud->name);            mclCommand(buf);        }    }    else if (!strcmp(cmd, "help"))        status->setf("Press Alt-O, or Alt-C, or Alt-Q or RTFM");    else if (!strcmp(cmd, "run")) {        char fun[256];        s = one_argument(s, fun, false);        embed_interp->run(fun, s, NULL);    }    else if (!strcmp(cmd, "eval")) {        char out[MAX_MUD_BUF];        embed_interp->eval(s, out);        output->printf("%s\n", out);    } else if (!strcmp(cmd, "load"))        embed_interp->load_file(s);    else if (!strcmp(cmd, "setinput"))        inputLine->set(s);    else if (!strcmp(cmd, "magic")) {        s = one_argument(s, cmd, false);        if (!strcmp(cmd, "enableFunction"))            embed_interp->enable_function(s);        else            status->setf("%s is not a valid callback command", cmd);    }    else if (!strcmp(cmd, "save")) {        char fname[MAX_MUD_BUF];        bool color = false;                s = one_argument(s, fname, false);        if (!strcmp(fname, "-c")) {            color = true;            s = one_argument(s, fname, false);        }        if (!fname[0])            status->setf("Specify file to save scrollback to.");        else            output->saveToFile(fname, color);    }        // Chat subcommands    else if (!strncmp(cmd, "chat.", strlen("chat."))) {        const char *subcmd = cmd+strlen("chat.");        if (!chatServerSocket)            status->setf("CHAT is not active. Set chat.name option in the config file");        else            chatServerSocket->handleUserCommand(subcmd,s);    }    // Chat aliases    else if (!strcmp(cmd, "chat"))        mclCommand(Sprintf("%s %s", "chat.to", s));    else if (!strcmp(cmd, "chatall"))        mclCommand(Sprintf("%s %s", "chat.all", s));    else {        if (embed_interp->run_quietly(Sprintf("mclcmd_%s", cmd),s, NULL, true))            return;                status->setf ("Unknown command: %s", cmd);    }}void Interpreter::setCommandCharacter(int c) {  commandCharacter = c;}char Interpreter::getCommandCharacter() {  return commandCharacter;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -