コード例 #1
0
ファイル: cmdparse.c プロジェクト: frolv/lynxbot
/* readquotes: process a quoted sequence in s */
static char *readquotes(char *s)
{
	int quot;

	quot = *s;
	shift_l(s);
	for (++s; *s && *s != quot; ++s) {
		if (*s == '\\' && s[1] == quot)
			shift_l(s);
	}
	if (!*s) {
		snprintf(err, ERR_LEN, "error: unterminated quote");
		return NULL;
	}
	shift_l(s);
	return s - 1;
}
コード例 #2
0
stBigNum multiply(stBigNum tNumX, stBigNum tNumY){
	stBigNum tResult;
	clean_number(&tResult);
	while(!equal_zero(&tNumX)){
		if(odd(tNumX.aiBlock[0])){
			tResult = add(tResult, tNumY);
		}
		shift_r(&tNumX);
		shift_l(&tNumY);
	}
	return (tResult);
}
コード例 #3
0
ファイル: cmdparse.c プロジェクト: frolv/lynxbot
/* escseq: process an escape sequence in s */
static int escseq(char *s)
{
	static const char *esc = " \\'\"";

	if (!s[1]) {
		snprintf(err, ERR_LEN, "error: unexpected end of line");
		return 0;
	}
	if (!strchr(esc, s[1])) {
		snprintf(err, ERR_LEN, "error: unrecognized "
				"escape sequence \\%c", s[1]);
		return 0;
	}
	shift_l(s);
	return 1;
}
コード例 #4
0
ファイル: sed.cpp プロジェクト: frolv/lynxbot
/* parsecmd: break up the sed command into its parts */
static int parsecmd(struct sedinfo *s, char *cmd)
{
	char *t;
	int delim;

	s->global = s->ignore = 0;
	if (cmd[0] != 's') {
		s->error = INVCMD;
		s->errtok = cmd[0];
		return 0;
	}
	if (!(delim = cmd[1]) || !*(s->regex = cmd + 2)) {
		s->error = UNTERM;
		return 0;
	}
	t = s->regex;
	for (t = s->regex; *t; ++t) {
		if ((*t == '(' || *t == '[')
				&& (t == s->regex || *(t - 1) != '\\')) {
			if (!(t = readbrackets(t))) {
				s->error = UNTERM;
				return 0;
			}
		} else if (*t == delim) {
			if (*(t - 1) != '\\')
				break;
			shift_l(t - 1);
			--t;
		}
	}
	if (!t) {
		s->error = UNTERM;
		return 0;
	}
	*t++ = '\0';
	if (!*(s->replace = t)) {
		s->error = UNTERM;
		return 0;
	}
	while ((t = strchr(t, delim)) && *(t - 1) == '\\')
		shift_l(t - 1);
	if (!t) {
		s->error = UNTERM;
		return 0;
	}
	*t++ = '\0';
	for (; *t; ++t) {
		switch (*t) {
		case 'g':
			s->global = 1;
			break;
		case 'i':
			s->ignore = 1;
			break;
		default:
			s->error = BADOPT;
			s->errtok = *t;
			return 0;
		}
	}

	return 1;
}