/*
 * Lex.
 */
#include <stdio.h>
#include <stdlib.h>
#include "asm.h"

#ifndef lint
static char
# ifdef __GNUC__
    __attribute__ ((unused))
# endif
*sccsid = "@(#)as83.c        1.2";
#endif


/*
 * Get the next non white
 * character.
 */
int
_getnb(void)
{
	register int c;

	do {
		c = getraw();
	} while (space(c));
	return c;
}

/*
 * Get next character from
 * the input.
 * Apply string mappings.
 */
int
getmap()
{
	register int n, c, v;

	c = getraw();
	if (c == '\\')
		switch (c = getraw()) {

		case 'n':
			c = '\n';
			break;

		case 'r':
			c = '\r';
			break;

		case 't':
			c = '\t';
			break;

		case 'b':
			c = '\b';
			break;

		case '0':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
			v = n = 0;
			while (++n <= 3 && c >= '0' && c <= '7') {
				v = 8 * v + c - '0';
				c = getraw();
			}
			putback(c);
			c = v;
			break;

		default:
			putback(c);
			c = '\\';
		}
	return(c);
}

/*
 * Read in an indentifier.
 * Store it (padded with nulls) into the
 * supplied buffer.
 */
void
getid(int c, char *id)
{
	register char *p, *end;

	p = id;
	end = &id[NCPS];
	while (alpha(c) || digit(c) || c == '$') {
		if (p < end) {
			if (upper(c))
				c |= ' ';
			if (c != '$')
				*p++ = c;
		}
		c = getraw();
	}
	*p = '\0';
	putback(c);
}

/* Replacement macro function to "undo" previous get character.
   Note that 'c' isn't put back into the buffer - it's assumed
   that the previous character and c are the same.
 */
inline void
putback(int c)
{
        if (c != 0 && --sptr < sbuf)
                abort();
}
