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

📄 trunkmap.cpp

📁 multi-line Adjunct Communication Server
💻 CPP
📖 第 1 页 / 共 2 页
字号:
void Trunkmap::scrLastItem(void){	char *target = getOption(NULL);	char *list = getOption(NULL);	char *cp, *last;	if(!target)		return scrErrorStep("missing-arg");	last = list;	item = 0;	if(!list)	{		list = target;		target = NULL;	}	while(NULL != (cp = strchr(last, ':')))	{		last = ++cp;		++item;	}	if(!target)		return scrStep();	setsym(target, last, id);	scrStep();}void Trunkmap::scrFirstItem(void){	char *target = getOption(NULL);	char *list = getOption(NULL);	char env[256];	int i = 0;	if(!target)		return scrErrorStep("missing-arg");	item = 0;	if(!list)		return scrStep();	while(*list && *list != ':')		env[i++] = *(list++);	env[i] = 0;	setsym(target, env, id);	scrStep();}	void Trunkmap::scrPrevItem(void){	char *target = getOption(NULL);	char *list = getOption(NULL);	char env[256];	int i = 1;	char *cp;	if(!target)		return scrErrorStep("missing-arg");	if(!item)		return scrErrorStep("start-of-list");	if(!list)	{		list = target;		target = NULL;	}	cp = list;	while(i++ < item)	{		cp = strchr(cp, ':');		if(!cp)			return scrErrorStep("end-of-list");		++cp;	}	i = 0;	--item;	if(!target)		return scrStep();	while(*cp && *cp != ':')		env[i++] = *(cp++);	env[i] = 0;	setsym(target, env, id);}void Trunkmap::scrNextItem(void){	char *target = getOption(NULL);	char *list = getOption(NULL);	char env[256];	int i = 0;	char *cp;	if(!target)		return scrErrorStep("missing-arg");	if(!list)	{		list = target;		target = NULL;	}	cp = list;	while(i++ < item)	{		cp = strchr(cp, ':');		if(!cp)			return scrErrorStep("end-of-list");		++cp;	}	i = 0;	++item;	if(!target)		return scrStep();	while(*cp && *cp != ':')		env[i++] = *(cp++);	env[i] = 0;	setsym(target, env, id);}	void Trunkmap::scrSet(void){	char env[256];	char *target = getOption(NULL);	int var;	char *e;	int vol;	if(!target)		return scrErrorStep("missing-arg");	if(mailbox)	{		if(!stricmp(target, "password"))			return mailbox->setPassword(getOption(""));			if(!stricmp(target, "order"))			return mailbox->setOrder(getOption(""));	}	if(!strnicmp(target, "var", 3))	{		var = atoi(target + 3) % 10;		vars[var][0] = 0;		while(NULL != (target = getOption(NULL)))			strcat(vars[var], target);	}	else if(!strnicmp(target, "lang", 4))	{		strcpy(lang, getOption("UsEngM"));		vocab = getVocabulary(lang);		if(!vocab)			debug(1, "%s(%d): no vocabulary found", lang, id);		return;	}	else if(!strnicmp(target, "temp", 4))	{		var = atoi(target + 4) % 4;		temp[var][0] = 0;		while(NULL != (target = getOption(NULL)))			strcat(vars[var], target);	}	else if(!strnicmp(target, "digit", 5))	{		strncpy(digit, getOption(""), 32);		digit[32] = 0;		digits = strlen(digit);	}	else if(!strnicmp(target, "record", 6))	{		vol = atoi(getOption("80"));		if(vol < 0)			vol = 0;		if(vol > 99)			vol = 99;		volume = volume & 0x00ff | (vol * 256);	}	else if(!strnicmp(target, "play", 4))	{		vol = atoi(getOption("80"));		if(vol < 0)			vol = 0;		if(vol > 99)			vol = 99; 		volume = volume & 0xff00 | atoi(getOption("80"));	}	else	{				env[0] = 0;		while(NULL != (e = getOption(NULL)))			strcat(env, e);		setsym(target, env, id);	} 	scrStep();}void Trunkmap::scrDefine(void){	char env[256];	char *target = getOption(NULL);	char *e;	if(!target)		return scrErrorStep("missing-arg");		env[0] = 0;	while(NULL != (e = getOption(NULL)))		strcat(env, e);	setsym(target, env, 0);	scrStep();}void Trunkmap::scrInit(void){	char env[256];	char *target = getOption(NULL);	char *e;	if(!target)		return scrErrorStep("missing-arg");	target = getsym(target, id);	if(target)	{		scrStep();		return;	}	env[0] = 0;	while(NULL != (e = getOption(NULL)))		strcat(env, e);		setsym(target, env, id);	scrStep();}void Trunkmap::scrNext(void){	cmd[stack] = cmd[stack]->next;	scrExecute();}#ifdef	HAVE_MODULESvoid Trunkmap::scrMailbox(void){	MBIModule *mbi = (MBIModule *)cmd[stack]->module;	char *err;	if(mailbox)	{		delete mailbox;		mailbox = NULL;	}	if(!mbi)		return scrErrorStep("no-mbi");	err = mbi->Mailbox(this);	if(err)		return scrErrorStep(err);	if(mbi->getTimeout())		scrModule();	else		scrStep();}void Trunkmap::scrExtension(void){	MBIModule *mbi = (MBIModule *)cmd[stack]->module;	char *err;	if(mailbox)	{		delete mailbox;		mailbox = NULL;	}	if(!mbi)		return scrErrorStep("no-mbi");	err = mbi->Extension(this);	if(err)		return scrErrorStep(err);	if(mbi->getTimeout())		scrModule();	else		scrStep();}void Trunkmap::scrCommit(void){	MBIModule *mbi = (MBIModule *)cmd[stack]->module;	char *err;	if(!mbi)		return scrErrorStep("no-mbi");	err = mbi->Commit(this);	if(err)		return scrErrorStep(err);	if(mbi->getTimeout())		scrModule();	else		scrStep();}void Trunkmap::scrDeliver(void){	MBIModule *mbi = (MBIModule *)cmd[stack]->module;	char *err;	if(!mbi)		return scrErrorStep("no-mbi");	err = mbi->Deliver(this);	if(err)		return scrErrorStep(err);	if(mbi->getTimeout())		scrModule();	else		scrStep();}void Trunkmap::scrInsert(void){	DBIModule *dbi = (DBIModule *)cmd[stack]->module;	char *err;	if(!dbi)		return scrErrorStep("no-dbi");	err = dbi->Insert(this);	if(err)		return scrErrorStep(err);	if(dbi->getTimeout())		scrModule();	else		scrStep();}void Trunkmap::scrUpdate(void){	DBIModule *dbi = (DBIModule *)cmd[stack]->module;	char *err;	if(!dbi)		return scrErrorStep("no-dbi");	err = dbi->Update(this);	if(err)		return scrErrorStep(err);	if(dbi->getTimeout())		scrModule();	else		scrStep();}void Trunkmap::scrDelete(void){	DBIModule *dbi = (DBIModule *)cmd[stack]->module;	char *err;	if(!dbi)		return scrErrorStep("no-dbi");	err = dbi->Delete(this);	if(err)		return scrErrorStep(err);	if(dbi->getTimeout())		scrModule();	else		scrStep();}void Trunkmap::scrSearch(void){	DBIModule *dbi = (DBIModule *)cmd[stack]->module;	char *err;	if(!dbi)		return scrErrorStep("no-dbi");	err = dbi->Search(this);	if(err)		return scrErrorStep(err);	if(dbi->getTimeout())		scrModule();	else		scrStep();}#endifvoid Trunkmap::setVariable(char *sym, char *value){	int var;	char env[256];	if(!strnicmp(sym, "var", 3))	{		var = atoi(sym + 3);		if(var >= -1 && var < 10)		{			strncpy(vars[var], value, 32);			temp[var][33] = 0;		}		return;	}		if(!strnicmp(sym, "temp", 4))	{		var = atoi(sym + 4);		if(var >= -1 && var < 4)		{			strncpy(temp[var], value, 32);			temp[var][33] = 0;		}		return;	}	if(!stricmp(sym, "digits"))	{		var = strlen(value);		if(var > 32)			var = 32;		if(var)			strncpy(digit, value, var);		digit[var] = 0;		digits = var;		return;	}		setsym(sym, value, id);}		void Trunkmap::setPid(int pid){	if(exstatus != -1)		return;	waitpid = pid;}char *Trunkmap::getVariable(char *var){	char env[40];	if(!strnicmp(var, "var", 3))		return vars[atoi(var + 4) % 10];	if(!strnicmp(var, "digit", 5)) 		return digit;	if(!stricmp(var, "script"))		return menu->name;	return getsym(var, id);}time_t Trunkmap::getIdleTime(void){	time_t now;	if(idle)	{		time(&now);		return now - idletime;	}	else		return 0;}	void Trunkmap::sayWord(char *word){	char *buf = wordbuffer;	char *dec;	char *tail;	if(!word)		return;	tail = word + strlen(word) - 1;	wordcount = wordlast = 0;	if(!stricmp(word, "<spell>"))	{		wordmask |= WORD_SPELL;		return;	}	if(!stricmp(word, "</spell>"))	{		wordmask &= ~WORD_SPELL;		return;	}	if(!stricmp(word, "<order>"))	{		wordmask |= WORD_ORDER;		return;	}	if(!stricmp(word, "</order>"))	{		wordmask &= ~WORD_ORDER;		return;	}	if(strchr(word, '/') || strchr(word, ':'))	{		wordlist[wordcount++] = word;		return;	}	if(wordmask & WORD_SPELL)	{		while(*word && buf < wordbuffer + 60)		{			if(*word == '.')				wordlist[wordcount++] = "DOT";			if(isalnum(*word))			{				buf[0] = toupper(*word);				buf[1] = 0;				wordlist[wordcount++] = buf;				buf += 2;			}			++word;		}		return;	}	if(isdigit(*word))	{		dec = strchr(word, '.');		if(wordmask & WORD_ORDER)		{			sayNumber(atol(word), NUMBER_ORDER);			return;		}		sayNumber(atol(word), NUMBER_NORMAL);		if(dec)		{			wordlist[wordcount++] = "POINT";			while(isdigit(*(++dec)))			{				buf[0] = *dec;				buf[1] = 0;				wordlist[wordcount++] = buf;				buf += 2;			}		}		if(*tail == '%')			wordlist[wordcount++] = "PERCENT";		return;	}						if(strchr(word, '.'))		if(*tail != '.')		{			wordlist[wordcount++] = word;			return;		}	while(*word && buf < wordbuffer + 60)	{		if(isalnum(*word))			*(buf++) = toupper(*word);		++word;	}	*buf = 0;	if(buf > wordbuffer)		wordlist[wordcount++] = wordbuffer;}void Trunkmap::newWord(void){	wordlast = wordcount = wordmask = 0;}char *Trunkmap::getWord(void){	if(wordlast >= wordcount)		return NULL;	return wordlist[wordlast++];}void Trunkmap::sayNumber(long nbr, int mode){	static char *norm[] =		{"0", "1", "2", "3", "4",		 "5", "6", "7", "8", "9",		 "10", "11", "12", "13", "14",		 "15", "16", "17", "18", "19"};	static char *ords[] =		{"0TH", "1ST", "2ND", "3RD", "4TH",		 "5TH", "6TH", "7TH", "8TH", "9TH",		 "10TH", "11TH", "12TH", "13TH", "14TH",		 "15TH", "16TH", "17TH", "18TH", "19TH"};	static char *tens[] =		{"0",  "10", "20", "30", "40",		 "50", "60", "70", "80", "90"};	static char *tenths[] =		{"0th", "10TH", "20TH", "30TH", "40TH",		"50TH", "60TH", "70TH", "80TH", "90TH"};	char **nums = norm;	long power = 1000000;	long hi, lo;	if(mode == NUMBER_ORDER)		nums = ords;	if(!nbr)	{		wordlist[wordcount++] = nums[0];		return;	}	nums = norm;	while(power && nbr)	{		if(nbr < power)		{			power /= 1000;			continue;		}		hi = nbr / power;		nbr %= power;		if(!nbr && mode == NUMBER_ORDER)			nums = ords;		if(hi > 99)		{			wordlist[wordcount++] = norm[hi / 100];			hi %= 100;			if(!hi && !nbr && mode == NUMBER_ORDER)				wordlist[wordcount++] = "100TH";			else 				wordlist[wordcount++] = "100";		}		if(hi < 20)		{			if(hi)				wordlist[wordcount++] = nums[hi];		}		else		{			lo = hi % 10;			if(!lo && !nbr && mode == NUMBER_ORDER)				wordlist[wordcount++] = tenths[hi / 10];			else				wordlist[wordcount++] = tens[hi / 10];			if(lo)				wordlist[wordcount++] = nums[lo];		}		if(power == 1000000)		{			if(mode == NUMBER_ORDER && !nbr)				wordlist[wordcount++] = "1000000TH";			else				wordlist[wordcount++] = "1000000";		}		if(power == 1000)		{			if(mode == NUMBER_ORDER && !nbr)				wordlist[wordcount++] = "1000TH";			else				wordlist[wordcount++] = "1000";		}		power /= 1000;	}}			char *Trunkmap::getOption(char *def){	char env[40];	int var;	char *option = cmd[stack]->argv[argc];	temps % 4;	time_t now;	struct tm *dt;	char *cp;	if(!option)		return def;	++argc;	if(*option == '@')	{		option = getsym(++option, 0);			if(!option)			option = "";		return option;	}	if(*option != '%')		return option;	if(!stricmp(option, "%empty"))		return "";	if(!strnicmp(option, "%temp", 5))	{		sprintf(temp[temps], "tmp/l%02sx%08lx%s",			id, starttime & 0xffffffff, option + 5);		return temp[temps++];	}	if(!strnicmp(option, "%var", 4))	{		var = atoi(option + 4) % 10;		return vars[var];	}	if(!stricmp(option, "%language"))		return lang;	if(!stricmp(option, "%cid"))		return cid;	if(!stricmp(option, "%ani"))		return ani;	if(!stricmp(option, "%dnid"))		return dnid;	if(!stricmp(option, "%digits"))		return digit;	if(!stricmp(option, "%extension"))	{		strcpy(temp[temps], getExtension());		return temp[temps++];	}	if(!stricmp(option, "%script"))		return menu->name;	if(!stricmp(option, "%count"))	{		sprintf(temp[temps], "%d", digits);		return temp[temps++];	}	if(!stricmp(option, "%rings"))	{		sprintf(temp[temps], "%d", rings);		return temp[temps++];	}	if(!stricmp(option, "%item"))	{		sprintf(temp[temps], "%d", item);		return temp[temps++];	}	if(!stricmp(option, "%error"))		return error;	if(!stricmp(option, "%offset"))	{		sprintf(temp[temps], "%ld", offset);		return temp[temps++];	}	if(!stricmp(option, "%date"))	{		time(&now);		dt = localtime(&now);		sprintf(temp[temps], "%04d%02d%02d",			dt->tm_year + 1900, dt->tm_mon + 1, dt->tm_mday);		return temp[temps++];	}	if(!stricmp(option, "%logdate"))	{		time(&now);		dt = localtime(&now);		sprintf(temp[temps], "%02d/%02d/%04d",			dt->tm_mon + 1, dt->tm_mday, dt->tm_year);		return temp[temps++];	}	if(!stricmp(option, "%time"))	{		time(&now);		dt = localtime(&now);		sprintf(temp[temps], "%02d%02d%02d",			dt->tm_hour, dt->tm_min, dt->tm_sec);		return temp[temps++];	}	if(!stricmp(option, "%logtime"))	{		time(&now);		dt = localtime(&now);		sprintf(temp[temps], "%02d:%02d:%02d",			dt->tm_hour, dt->tm_min, dt->tm_sec);		return temp[temps];	}	if(!stricmp(option, "%runtime"))	{		time(&now);		sprintf(temp[temps], "%d", now - starttime);		return temp[temps++];	}		if(!stricmp(option, "%status"))	{		sprintf(temp[temps], "%d", exstatus);		return temp[temps++];	}	if(!stricmp(option, "%version"))	{		strcpy(temp[temps], VERSION);		return temp[temps++];	}	if(!stricmp(option, "%release"))	{		strcpy(temp[temps], VERSION);		cp = strchr(temp[temps], '.');		if(cp)			*cp = 0;		return temp[temps++];	}	if(!stricmp(option, "%id"))	{		sprintf(temp[temps], "%d", id);		return temp[temps++];	}	if(!strnicmp(option, "*:", 2))	{		sprintf(wordbuffer, "%s:%s", lang, option + 2);		return wordbuffer;	}	if(mailbox)	{		if(!stricmp(option, "%message"))			return mailbox->getMessage();		if(!stricmp(option, "%password"))			return mailbox->getPassword();		if(!stricmp(option, "%term"))			return mailbox->getTerm();		if(!stricmp(option, "%user"))			return mailbox->getUser();		if(!stricmp(option, "%#record"))			return mailbox->getRecordSize();		if(!stricmp(option, "%mailbox"))			return mailbox->getMailbox();		if(!stricmp(option, "%extension"))			return mailbox->getExtension();		if(!stricmp(option, "%#new"))			return mailbox->getNewCount();		if(!stricmp(option, "%#old"))			return mailbox->getOldCount();		if(!stricmp(option, "%#saved"))			return mailbox->getSavedCount();	}	option = getsym(++option, id);	if(!option)		option = "";	return option;}

⌨️ 快捷键说明

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