Ejemplo n.º 1
1
static struct imaptoken *do_readtoken(int touc)
{
int	c=0;
unsigned l;

#define	appendch(c)	alloc_tokenbuf(l+1); curtoken.tokenbuf[l++]=(c);

	if (curtoken.tokentype == IT_ERROR)	return (&curtoken);

	do
	{
		c=READ();
	} while (c == '\r' || c == ' ' || c == '\t');

	if (c == '\n')
	{
		UNREAD(c);
		curtoken.tokentype=IT_EOL;
		return (&curtoken);
	}
	c=(unsigned char)c;
	if (c == LPAREN_CHAR)
	{
		curtoken.tokentype=IT_LPAREN;
		return (&curtoken);
	}

	if (c == RPAREN_CHAR)
	{
		curtoken.tokentype=IT_RPAREN;
		return (&curtoken);
	}

	if (c == LBRACKET_CHAR)
	{
		curtoken.tokentype=IT_LBRACKET;
		return (&curtoken);
	}

	if (c == RBRACKET_CHAR)
	{
		curtoken.tokentype=IT_RBRACKET;
		return (&curtoken);
	}

	if (c == '"')
	{
		l=0;
		while ((c=READ()) != '"')
		{
			if (c == '\\')
				c=READ();
			if (c == '\r' || c == '\n')
			{
				UNREAD(c);
				curtoken.tokentype=IT_ERROR;
				return (&curtoken);
			}
			if (l < 8192)
			{
				appendch(c);
			}
		}
		appendch(0);
		curtoken.tokentype=IT_QUOTED_STRING;
		return (&curtoken);
	}

	if (c == '{')
	{
		curtoken.tokennum=0;
		while ((c=READ()) != '}')
		{
			if (!isdigit((int)(unsigned char)c))
			{
				UNREAD(c);
				curtoken.tokentype=IT_ERROR;
				return (&curtoken);
			}
			curtoken.tokennum = curtoken.tokennum*10 + (c-'0');
		}
		c=READ();
		if (c == '\r')
		{
			c=READ();
		}
		if (c != '\n')
		{
			curtoken.tokentype=IT_ERROR;
			return (&curtoken);
		}
		curtoken.tokentype=IT_LITERAL_STRING_START;
		return (&curtoken);
	}

	l=0;
	if (c == '\\')
	{
		appendch(c);	/* Message flag */
		c=READ();
	}
	else if (isdigit(c))
	{
		curtoken.tokentype=IT_NUMBER;
		curtoken.tokennum=0;
		do
		{
			appendch(c);
			curtoken.tokennum = curtoken.tokennum*10 +
				(c-'0');
			c=READ();
		} while (isdigit( (int)(unsigned char)c));

		/* Could be stuff like mime.spec, so continue reading. */
	}

	while (c != '\r' && c != '\n'
		&& !isspace((int)(unsigned char)c)
		&& c != '\\' && c != '"' && c != LPAREN_CHAR && c != RPAREN_CHAR
		&& c != '{' && c != '}' && c != LBRACKET_CHAR && c != RBRACKET_CHAR)
	{
		curtoken.tokentype=IT_ATOM;
		if (l < IT_MAX_ATOM_SIZE)
		{
			if (touc)
				c=toupper(c);
			appendch(c);
		}
		else
		{
			write_error_exit("max atom size too small");  
		}
		c=READ();
	}
	if (l == 0)
	{
		curtoken.tokentype=IT_ERROR;
		return (&curtoken);
	}
	appendch(0);
	UNREAD(c);

	if (strcmp(curtoken.tokenbuf, "NIL") == 0)
		curtoken.tokentype=IT_NIL;
	return (&curtoken);
}
Ejemplo n.º 2
0
/*
 * Return a pointer in "ap" which is the same as p.
 * If p is NULL, ap can be enlarged as necessary to create such a pointer.
 * If a pointer is found, return a pointer to it. Otherwise, return 0.
 */
static vptr *get_alloc_pointer(vptr p)
{
	static vptr *ap = NULL;
	static size_t num_ap = 0;
	vptr *pp;

	/* Search the existing array. */
	if (num_ap)
	{
		for (pp = ap; pp < ap+num_ap; pp++)
		{
			if (*pp == p) return pp;
		}
	}

	/* Grow the array (start at 128 and double as needed) to find a NULL. */
	if (!p)
	{
		vptr *new_ap;
		size_t UNREAD(new_num), max_num = 65535U / sizeof(vptr);

		/* Paranoia - 65535 should be more than enough. */
		if (num_ap == max_num) quit("Out of safe malloc space.");
		else if (max_num < 2 * num_ap) new_num = max_num;
		else if (num_ap) new_num = num_ap * 2;
		else new_num = 128;

		/* Grow the array. */
		C_MAKE(new_ap, new_num, vptr);
		if (num_ap) C_COPY(new_ap, ap, num_ap, vptr);

		/* Set ap and num_ap to the new values, and new_ap to the first newly
		 * allocated pointer.
		 */
		ap = new_ap;
		new_ap += num_ap;
		num_ap = new_num;

		/* Return the pointer. */
		return new_ap;
	}
	/* Reject any other request for an absent pointer. */
	else
	{
		return NULL;
	}
}
Ejemplo n.º 3
0
void unread(int c)
{
	UNREAD(c);
}
Ejemplo n.º 4
0
int
brc_un_read(struct fileheader *fh)
{
	return UNREAD(fh, pbrc);
}