示例#1
0
/*
 * break into words for -w option
 */
void
putwords(void)
{
	Rune *p, *p1;
	int i, nlet;


	for(p1 = line;;) {
		/*
		 * skip initial specials ampersands and apostrophes
		 */
		while((i = charclass(*p1)) != EXTENDED && i < DIGIT)
			if(*p1++ == '\0')
				return;
		nlet = 0;
		for(p = p1; (i = charclass(*p)) != SPECIAL || (underscoreflag && *p=='_'); p++)
			if(i == LETTER || (underscoreflag && *p == '_'))
				nlet++;
		/*
		 * MDM definition of word
		 */
		if(nlet > 1) {
			/*
			 * delete trailing ampersands and apostrophes
			 */
			while(*--p == '\'' || *p == '&'
					   || charclass(*p) == PUNCT)
				;
			while(p1 <= p)
				Bputrune(&(bout.Biobufhdr), *p1++);
			Bputc(&(bout.Biobufhdr), '\n');
		} else
			p1 = p;
	}
}
示例#2
0
void
putmac(Rune *rp, int vconst)
{
	Rune *t;
	int found;
	Rune last;

	found = 0;
	last = 0;
	while(*rp) {
		while(*rp == ' ' || *rp == '\t')
			Bputrune(&(bout.Biobufhdr), *rp++);
		for(t = rp; *t != ' ' && *t != '\t' && *t != '\0'; t++)
			;
		if(*rp == '\"')
			rp++;
		if(t > rp+vconst && charclass(*rp) == LETTER
				&& charclass(rp[1]) == LETTER) {
			while(rp < t)
				if(*rp == '\"')
					rp++;
				else
					Bputrune(&(bout.Biobufhdr), *rp++);
			last = t[-1];
			found++;
		} else
		if(found && charclass(*rp) == PUNCT && rp[1] == '\0')
			Bputrune(&(bout.Biobufhdr), *rp++);
		else {
			last = t[-1];
			rp = t;
		}
	}
	Bputc(&(bout.Biobufhdr), '\n');
	if(msflag && charclass(last) == PUNCT)
		Bprint(&(bout.Biobufhdr), " %C\n", last);
}
示例#3
0
void
refer(int c1)
{
	int c2;

	if(c1 != '\n')
		SKIP;
	c2 = 0;
	for(;;) {
		if(C != '.')
			SKIP;
		else {
			if(C != ']')
				SKIP;
			else {
				while(C != '\n')
					c2 = c;
				if(charclass(c2) == PUNCT)
					Bprint(&(bout.Biobufhdr), " %C",c2);
				return;
			}
		}
	}
}
示例#4
0
文件: rex.c 项目: DeadZen/qse
static int charset (comp_t* com, qse_rex_node_t* node)
{
	QSE_ASSERT (node->id == QSE_REX_NODE_CSET);
	QSE_ASSERT (node->u.cset.negated == 0);
	QSE_ASSERT (node->u.cset.member	== QSE_NULL);

	if (IS_SPE(com,QSE_T('^')))
	{
		/* negate an expression */
		node->u.cset.negated = 1;
		if (getc_noesc(com) <= -1) return -1;
	}


	/* initialize the member array */
	node->u.cset.member = qse_str_open (com->rex->mmgr, 0, 64);
	if (node->u.cset.member == QSE_NULL)
	{
		com->rex->errnum = QSE_REX_ENOMEM;
		return -1;
	}

	/* if ] is the first character or the second character following ^,
	 * it is treated literally */

	do
	{
		int x1, x2;
		qse_char_t c1, c2;

		x1 = com->c.escaped;
		c1 = com->c.value;
		if (c1 == QSE_CHAR_EOF)
		{
			com->rex->errnum = QSE_REX_EPREEND;
			return -1;
		}

		if (getc_esc(com) <= -1) return -1;
		x2 = com->c.escaped;
		c2 = com->c.value;

		if (!x1 && c1 == QSE_T('[') && 
		    !x2 && c2 == QSE_T(':'))
		{
			int n;
			qse_char_t tmp[2];

			/* begins with [: 
			 * don't read in the next character as charclass() 
			 * matches a class name differently from other routines.
			 * if (getc_noesc(com) <= -1) return -1;
			 */
			if ((n = charclass(com)) <= -1) return -1;
			
			QSE_ASSERT (n < QSE_TYPE_MAX(qse_char_t));

			tmp[0] = QSE_REX_CSET_CLASS;
			tmp[1] = n;
			ADD_CSET_CODE (com, node, tmp, QSE_COUNTOF(tmp));
		}
		else if (!x2 && c2 == QSE_T('-'))
		{
			if (getc_esc(com) <= -1) return -1;
			if (IS_SPE(com, QSE_T(']')))
			{
				qse_char_t tmp[4];

				/* '-' is the last character in the set.
				 * treat it literally */

				tmp[0] = QSE_REX_CSET_CHAR;
				tmp[1] = c1;
				tmp[2] = QSE_REX_CSET_CHAR;
				tmp[3] = c2;

				ADD_CSET_CODE (com, node, tmp, QSE_COUNTOF(tmp));
				break;
			}

			if (c1 > com->c.value)
			{
				/* range end must be >= range start */
				com->rex->errnum = QSE_REX_ECRANGE;
				return -1;
			}
			else if (c1 == com->c.value)
			{
				/* if two chars in the range are the same,
				 * treat it as a single character */
				qse_char_t tmp[2];
				tmp[0] = QSE_REX_CSET_CHAR;
				tmp[1] = c1;
				ADD_CSET_CODE (com, node, tmp, QSE_COUNTOF(tmp));
			}
			else
			{
				qse_char_t tmp[3];
				tmp[0] = QSE_REX_CSET_RANGE;
				tmp[1] = c1;
				tmp[2] = com->c.value;
				ADD_CSET_CODE (com, node, tmp, QSE_COUNTOF(tmp));
			}
			
			if (getc_esc(com) <= -1) return -1;
		}
		else
		{
			qse_char_t tmp[2];
			tmp[0] = QSE_REX_CSET_CHAR;
			tmp[1] = c1;
			ADD_CSET_CODE (com, node, tmp, QSE_COUNTOF(tmp));
		}
	}
	while (!IS_SPE(com,QSE_T(']')));

	if (getc_esc(com) <= -1) return -1;
	return 0;
}