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

📄 config.cc

📁 Unix下的MUD客户端程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
#include "mcl.h"#include <sys/stat.h>#include <unistd.h>#include "Action.h"#include "cui.h"#include "Alias.h"#include "Plugin.h"#include "Interpreter.h"// This table contain names of all options, corresponding switch names// and the variable that is to be set when the option is giventypedef enum {pt_bool, pt_int, pt_hex, pt_char, pt_string} ptype_t; // Parameter typeconst struct{	char opt_char;		// e.g. -w. 0 = end of table	char *name;			// Name used i config file, e.g. histwordsize=1	ptype_t ptype;		// Is it a toggle or does it take a number?	option_t option;	// Which option does it set?	char *description;	// Description, for config file saving	int default_value;	// Default value	int min;			// Maximum value    int max;			// Minimum value} option_table[] ={	{	'?',		"commandcharacter",		pt_char, opt_commandcharacter,		"The character to prefix internal mcl commands with",		'#',	'!',	 '~'	},    {	'?',		"escapecharacter",		pt_char, opt_escape_character,		"Lines starting with this character are passed as-is",		'\\',	'!',	 '~'	},	{	'w',		"histwordsize",			pt_int,	opt_histwordsize,		"Minimum number of chars in a command to save into history",		5, 1, 999		},	{	'l',		"scrollback",			pt_int, opt_scrollback_lines,		"Number of lines in scrollback",		10000, 5000, 250000		 },	{	'H',		"histsize",				pt_int,	opt_histsize,		"Number of lines saved in the command history",		25, 5, 1000		 },		{	's',		"showprompt",			pt_bool,opt_showprompt,		"Should the prompt be echoed on the main output screen?",		false, false, true		 },			{	'e',		"echoinput",			pt_bool,opt_echoinput,		"Should input be sent to MUD be echoed on the main output screen?",		false, false, true		},			{	'b',		"beep",					pt_int,opt_beep,		"What frequency to beep with on errors? 0 disables, max 10",		1, 0, 10		},				{	'r',		"readonly",				pt_bool, opt_readonly,		"If set, configuration file will not be saved on exiting",		false, false, true	},    {	'r',		"nodefaults",	   		pt_bool, opt_nodefaults,		"If set, only options that do not equal their default are saved in the config file",		false, false, true	},    {	'r',		"save_history",	   		pt_bool, opt_save_history,		"Save the input history between sessions into ~/.mcl/history",		true, false, true	},		{	'W',		"historywindow",		pt_int,	opt_historywindow,		"Number of lines in the pop-up history window. 0 disables",		10,	0,	25	},		{	'B',		"mudbeep",				pt_bool,	opt_mudbeep,		"Should beeps from the MUD be honored?",		false, false, true	},		{	'T',		"tabsize",				pt_int,		opt_tabsize,		"Tabstop size",		8,	2,	16	},	{	'?',		"statcolor",			pt_hex,		opt_statcolor,		"Color of the stat window (activated with Alt-S); see README for values",		bg_green|fg_red, 0, 255	},		{	'?',		"inputcolor",			pt_hex,		opt_inputcolor,		"Color of the input line",		bg_cyan|fg_black, 0, 255	},		{	'?',		"statuscolor",			pt_hex,		opt_statuscolor,		"Color of the status line",		bg_cyan|fg_black, 0, 255	},		{	'?',		"autostatwin",			pt_bool,	opt_autostatwin,		"Automatically bring up the stat window",		false, false, true	},		{	'?',		"speedwalk",			pt_bool,	opt_speedwalk,		"Speedwalk enabled? (toggle in mcl with #enable speedwalk)",		true, false, true	},		{	'?',		"timercolor",			pt_hex,		opt_timercolor,		"Color of timer window",		bg_cyan|fg_black,0,255	},		{	'?',		"autotimerwin",			pt_bool,	opt_autotimerwin,		"Automatically bring up the clock/timer window",		true,	false,	true	},		{	'?',		"timerstate",			pt_int,		opt_timerstate,		"Default timer state (from 0 to 6)",		0,		0,		6    },    {   '?',        "borg",                 pt_bool,    opt_borg,        "Check for a new version of mcl on startup",        true,       false,  true    },    {   '?',        "borg_verbose",         pt_bool,    opt_borg_verbose,        "If BORG is set, show some extra info to user",        true,       false,  true    },    {   'D',        "interp_debug",           pt_bool,    opt_interpdebug,        "Display debugging messages for embedded interpreter",        true,       false,  true    },    {   '?',        "multiinput",           pt_bool,    opt_multiinput,        "Input line expands to multiple lines automatically",        true,       false,  true    },    {   '?',        "copyover",             pt_bool,     opt_copyover,        "Use the hot reconnect feature when using Alt-T",        false,       false,   true    },    {   '?',        "snarf_prompt", pt_bool, opt_snarf_prompt,        "Change the prompt when a new one is recieved",        true, false, true    },    {   '?',        "speedwalk_character", pt_char, opt_speedwalk_character,        "What character starts a speedwalk",        '.', '!', '~'    },    {   '?',        "expand_semicolon", pt_bool, opt_expand_semicolon,        "Is ; expanded on the command line or just in aliases",        false, false, true    },    {   'p',        "plugins",          pt_string, opt_plugins,        "Dynamically loaded modules (seperate with ,)",        0,0,0,    },    // MudMaster/ZCHAT chat specific stuff    {        '?',        "chat.name",       pt_string,    opt_chat_name,        "Your name in the MudMaster chat system (see doc/Chat). If set to nothing, chat is fully disabled",        0,0,0    },    {        '?',        "chat.port",       pt_int,    opt_chat_baseport,        "Base port to listen on for MudMaster chat. mcl will try up to this+10 ports",        4050, 1, 65535    },    {        '?',        "chat.autoaccept",       pt_bool,    opt_chat_autoaccept,        "Automatically accept all incoming chat connections or ask for confirmation?",        false, false, true    },    {        '?',        "chat.nodisturb",       pt_bool,    opt_chat_nodisturb,        "Automatically reject all incoming chat connections?",        false, false, true    },    {        '?',        "chat.debug",       pt_bool,    opt_chat_debug,        "Show extra debug information about chat requests?",        false, false, true    },    {        '?',        "chat.download",       pt_string,    opt_chat_download,        "Directory where files transferred via chat are placed (default: ~/.mcl/download/)",        0,0,0    },    {        '?',        "chat.email",       pt_string,    opt_chat_email,        "E-mail address displayed to others",        0,0,0    },    {        '?',        "chat.interfaces",       pt_string,    opt_chat_interfaces,        "What network interfaces should mcl look at to determine what IP address to use? Delimiter with space (default: ppp0 eth0 lo)",        0,0,0    },    {        '?',        "chat.icon",       pt_string,    opt_chat_icon,        "Icon file sent to others",        0,0,0    },    {        '?',        "chat.protocol",       pt_bool,    opt_chat_protocol,        "0 to use standard Chat, 1 to use zChat",        1,0,1    },    {        '?',        "chat.paranoia",       pt_bool,    opt_chat_paranoia,        "Prefix all messages with their source (e.g. [Drylock@127.0.0.1] Drylock chats 'hi'.",        0,0,1    },    {        '?',        "chat.chatcolor",       pt_hex,    opt_chat_chatcolor,        "Color of messages from others (e.g. CHAT: Drylock chats 'hullo'",        bg_black|fg_yellow|fg_bold, 0, 255    },    {        '?',        "chat.syscolor",       pt_hex,    opt_chat_syscolor,        "Color of system messages (e.g. CHAT: Connection to 127.0.0.1 failed)",        bg_black|fg_white, 0, 255    },    {   0, 0, pt_bool, max_option, 0, 0, 0, 0 }};// Old obsolete optionsstatic const char *obsolete_options[] = {    "ttyok", "embedded_interpreter",    NULL};    // Load the config file. if fname = NULL, default to ~/.mclrcvoid    Config::Load (const char *fname){    FILE   *fp;    char    buf[INPUT_SIZE], mudname[INPUT_SIZE], hostname[INPUT_SIZE];    char    commands[INPUT_SIZE];    int     port, count;    struct stat stat_buf;    MUD * last_mud = &globalMUD;    const char *home = getenv("HOME");        if (!home)        error ("The HOME environment variable is not set. This is bad.");        if (fname) {        fp = fopen (fname, "r");        filename = fname;    }    else    {        snprintf (buf, 256, "%s/.mcl/mclrc", home);        if (!(fp = fopen(buf, "r")) && errno == ENOENT) {            snprintf (buf, 256, "%s/.mclrc", home);            fp = fopen (buf, "r");        }                filename = buf;    }        if (!fp) {        if (errno == ENOENT) {            fprintf (stderr, "Could not open config file: %s (%m)\n", fname ? fname : buf);            fprintf (stderr, "I will create the directory %s/.mcl for you and a sample configuration file inside it.\n", home);            fprintf (stderr, "When you leave mcl, the file will contain all the default settings.\n");            sprintf(buf, "%s/.mcl", home);            if (mkdir(buf ,0700) < 0)                error("I failed creating the directory. I give up now (%m)!\n");            sprintf(buf, "%s/.mcl/mclrc", home);            if (!(fp = fopen(buf, "w")))                error("I failed (%m). I give up now.\n");            fprintf(fp, "# Automatically generated. It should get overwritten with a lot of setting next time you exit mcl.\n");            fchmod(fileno(fp), 0600);            fclose(fp);            fprintf(stderr, "OK. The file was created. Press enter to confirm this happy news.\n");            fgets(buf, 1, stdin);                        Load(fname);            return;        }    }            fstat (fileno (fp), &stat_buf);        if (stat_buf.st_mode & 077)        error ("Your configuration file is publically accessible.\n"               "Please use chmod 600 %s before proceeding.\n", ~filename);        mud_list = new MUDList;    save_time = stat_buf.st_mtime; // save the time        while (fgets (buf, INPUT_SIZE, fp))    {        int     match, len;        char    name[INPUT_SIZE], keyword[INPUT_SIZE];        char *nl , *value;        const char *rest;                if (buf[0] == '#')		// comment            continue;                if ((nl = strchr(buf, '\n')))            *nl = NUL;                rest = one_argument(buf, keyword, true);        len = 0;                if (!strcmp(keyword, "macro") ||            !strcmp(keyword, "alias") ||            !strcmp(keyword, "action") ||            !strcmp(keyword, "subst")) {            parseMUDLine(keyword, rest, last_mud);

⌨️ 快捷键说明

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