示例#1
0
static int scan_char(Token *tok, Tokenizer *tokz)
{
    int c, c2;
    
    c=GETCH();
    
    if(c==EOF)
        return E_TOKZ_UNEXPECTED_EOF;
    
    if(c=='\n')
        return E_TOKZ_UNEXPECTED_EOL;

    if(c=='\\'){
        c=scan_char_escape(tokz);    
        
        if(c==EOF)
            return E_TOKZ_UNEXPECTED_EOF;
        
        if(c==-2)
            return E_TOKZ_UNEXPECTED_EOL;
    }
    
    c2=GETCH();
    
    if(c2!='\'')
        return E_TOKZ_MULTICHAR;
    
    TOK_SET_CHAR(tok, c);
    
    return 0;
}
示例#2
0
int con_write(struct tty_struct *tty)
{
	char ch;
	int res = 0;
	cur_console = tty-tty_table-1;
	irq_lock();
	while (!isempty(tty->out)) {
		GETCH(tty->out, ch);
		if (ch == '\033') {
			char tmp_x = 0, tmp_y = 0;
			while (1) {
				GETCH(tty->out, ch);
				if (ch >= '0' && ch <= '9')
					tmp_x = tmp_x * 10 + ch - '0';
				else
					break;
			}
			if (ch == ';') {
				while (1) {
					GETCH(tty->out, ch);
					if (ch >= '0' && ch <= '9')
						tmp_y = tmp_y * 10 + ch - '0';
					else
						break;
				}
			}
			if (ch == 'P') {
				if (tmp_x >= 80)
					x = 79;
				else
					x = tmp_x;
				if (tmp_y >= 25)
					x = 24;
				else
					y = tmp_y;
			} else if (ch == 'C')
				color = ((tmp_x << 4) & 0xf0) | (tmp_y & 0xf);
			else if (ch=='E')
				__echo__=0;
			else if (ch=='e')
				__echo__=1;
		} else
			write_char(ch);
		res++;
	}
	if (fg_console == cur_console)
		set_cur();
	irq_unlock();
	return res;
}
示例#3
0
int
MyFGetC(FILE *file)
{
    if (isterm(file))
	return GETCH();
    return fgetc(file);
}
示例#4
0
文件: n7.c 项目: dank101/4.2BSD
text(){
	register i;
	static int spcnt;

	nflush++;
	if((dip == d) && (v.nl == -1)){newline(1); return;}
	setnel();
	if(ce || !fi){
		nofill();
		return;
	}
	if(pendw)goto t4;
	if(pendt)if(spcnt)goto t2; else goto t3;
	pendt++;
	if(spcnt)goto t2;
	while(((i = GETCH()) & CMASK) == ' ')spcnt++;
	if(nlflg){
	t1:
		nflush = pendt = ch = spcnt = 0;
		callsp();
		return;
	}
	ch = i;
	if(spcnt){
	t2:
		tbreak();
		if(nc || wch)goto rtn;
		un += spcnt*sps;
		spcnt = 0;
		setnel();
		if(trap)goto rtn;
		if(nlflg)goto t1;
	}
t3:
	if(spread)goto t5;
	if(pendw || !wch)
	t4:
		if(getword(0))goto t6;
	if(!movword())goto t3;
t5:
	if(nlflg)pendt = 0;
	adsp = adrem = 0;
	if(ad){
/* jfr */	if (nwd==1) adsp=nel; else adsp=nel/(nwd-1);
#ifdef NROFF
		adsp = (adsp/t.Adj)*t.Adj;
#endif
		adrem = nel - adsp*(nwd-1);
	}
	brflg = 1;
	tbreak();
	spread = 0;
	if(!trap)goto t3;
	if(!nlflg)goto rtn;
t6:
	pendt = 0;
	ckul();
rtn:
	nflush = 0;
}
示例#5
0
/****************************************************************************
 *  FUNCTION: main() - local routine                                        *
 ****************************************************************************/
int main(int argc, char *argv[])
    {
    int key_entered, Ch;

    intro();

    /* Set all 16 buffers to 0 */
    for (Ch = 0; Ch < 4; Ch++)
	   OUTPORT(base + (Ch * 2), Cal(0x000, Ch));

    inb(base+0xA);    // set automatic update mode
    inb(base+0XF);    // release zero latch

    do
	{
	CLRSCR();
	write_DAC();
	CPRINTF("\n\nWould you like to output another value (Y or N)?\n");
	key_entered = GETCH();
	} while((key_entered != 'N') && (key_entered != 'n'));

    /* Set all 16 buffers to 0 */
    for (Ch = 0; Ch < 4; Ch++)
	   OUTPORT(base + (Ch * 2), Cal(0x000, Ch));

    CLRSCR();
    PUTS("DA12-16 Sample1 complete.");
    } /* end main */
示例#6
0
文件: scanner.c 项目: mingpen/OpenNT
/************************************************************************
**  checknl : check for newline, skipping carriage return if there is one.
**  also increments Linenumber, so this should be used by routines which
**  will not push the newline back in such a way that rawtok() will be invoked,
**  find the newline and do another increment.
************************************************************************/
int checknl(void)
{
    REG WCHAR           c;

    for(;;) {
        c = GETCH();
        if(c > L'\r') {
            UNGETCH();
            return(FALSE);
        }
        switch(c) {
        case L'\n':
            Linenumber++;
            // must manually write '\r' with '\n' when writing 16-bit strings
            if( Prep ) {
                myfwrite(L"\r\n", 2 * sizeof(WCHAR), 1, OUTPUTFILE);
            }
            return(TRUE);
            break;
        case L'\r':
            continue;
            break;
        case EOS_CHAR:
            handle_eos();
            PREVCH() = L'\\';    /* M00HACK - needs pushback */
            continue;
            break;
        default:
            UNGETCH();
            return(FALSE);
            break;
        }
    }
}
示例#7
0
文件: scanner.c 项目: mingpen/OpenNT
/************************************************************************
**  dump_comment : while skipping a comment, output it.
************************************************************************/
void   dump_comment()
{
    if( ! Cflag ) {
        skip_1comment();
        return;
    }
    myfwrite(L"/*", 2 * sizeof(WCHAR), 1, OUTPUTFILE);
    for(;;) {
        WCHAR c;

        switch(CHARMAP(c = GETCH())) {
        case LX_STAR:
            if(checkop(L'/')) {
                myfwrite(L"*/", 2 * sizeof(WCHAR), 1, OUTPUTFILE);
                return;
            }
            break;
        case LX_EOS:
            handle_eos();
            continue;
        case LX_NL:
            Linenumber++;
            break;      /* output below */
        // must manually write '\r' with '\n' when writing 16-bit strings
        //case LX_CR:
        //    continue;
        }
        myfwrite(&c, sizeof(WCHAR), 1, OUTPUTFILE);
    }
}
示例#8
0
int tty_read(unsigned channel, char * buf, int nr)
{
	struct tty_struct * tty;
	char c, * b=buf;
	int minimum,time,flag=0;
	long oldalarm;

	if (channel>2 || nr<0) return -1;
	tty = &tty_table[channel];
	oldalarm = current->alarm;
	time = 10L*tty->termios.c_cc[VTIME];
	minimum = tty->termios.c_cc[VMIN];
	if (time && !minimum) {
		minimum=1;
		if (0 != (flag=(!oldalarm || time+jiffies<oldalarm)))
			current->alarm = time+jiffies;
	}
	if (minimum>nr)
		minimum=nr;
	while (nr>0) {
		if (flag && (current->signal & ALRMMASK)) {
			current->signal &= ~ALRMMASK;
			break;
		}
		if (current->signal)
			break;
		if (EMPTY(tty->secondary) || (L_CANON(tty) &&
		!tty->secondary.data && LEFT(tty->secondary)>20)) {
			sleep_if_empty(&tty->secondary);
			continue;
		}
		do {
			GETCH(tty->secondary,c);
			if (c==EOF_CHAR(tty) || c==10)
				tty->secondary.data--;
			if (c==EOF_CHAR(tty) && L_CANON(tty))
				return (b-buf);
			else {
				put_fs_byte(c,b++);
				if (!--nr)
					break;
			}
		} while (nr>0 && !EMPTY(tty->secondary));
		if (time && !L_CANON(tty)) {
			if (0 != (flag=(!oldalarm || time+jiffies<oldalarm)))
				current->alarm = time+jiffies;
			else
				current->alarm = oldalarm;
        }
		if (L_CANON(tty)) {
			if (b-buf)
				break;
		} else if (b-buf >= minimum)
			break;
	}
	current->alarm = oldalarm;
	if (current->signal && !(b-buf))
		return -EINTR;
	return (b-buf);
}
示例#9
0
static int scan_c_comment(Token *tok, Tokenizer *tokz)
{
    STRING_DECL_P(s, "/*");
    int c;
    int st=0;
    
    while(1){
        c=GETCH();
        
        if(c==EOF){
            STRING_FREE(s);
            return E_TOKZ_UNEXPECTED_EOF;
        }
        
        STRING_APPEND(s, c);
        
        if(c=='\n'){
            INC_LINE();
        }else if(st==0 && c=='*'){
            st=1;
        }else if(st==1){
            if(c=='/')
                break;
            st=0;
        }
    }

    STRING_FINISH(s);

    TOK_SET_COMMENT(tok, s);

    return 0;
}
示例#10
0
文件: p0macros.c 项目: mingpen/OpenNT
/************************************************************************
**do_macformal:		This function is called after a macformal marker is
**	found.  It reads the next character to find out which macformal is
**	wanted.  Then it checks to see if a paste is wanted, to find out
**	if the expanded or unexpanded actual should be used.  The return
**	value is a pointer to the text of the actual wanted, or NULL if the
**	actual asked for was not provided.
************************************************************************/
ptext_t   do_macformal(int *pre_paste)
{
    UCHAR		n;
    ptext_t	p;
    int	temp_paste;

    p = CURRENT_ACTUALS;
    n = GETCH();
    if(n > CURRENT_NACTUALS) {
	return(NULL);		/* already output warning */
    }
    temp_paste = post_paste();
    if(( ! (*pre_paste)) && ( ! temp_paste) ) {
	/*
	**	if the programmer provided x actuals, actuals x+1 to 2x are
	**	those actuals expanded
	*/
	n += CURRENT_NACTUALS;
    }
    *pre_paste = temp_paste;
    if (n != 0)
	while(--n) {
	    p = ACTUAL_NEXT(p);
	}

    return(ACTUAL_TEXT(p));
}
示例#11
0
文件: scanner.c 项目: mingpen/OpenNT
/************************************************************************
**  skip_1comment : we're called when we're already in a comment.
**  we're looking for the comment close. we also count newlines
**  and output them if we're preprocessing.
************************************************************************/
void   skip_1comment(void)
{
    UINT        c;

    for(;;) {
        c = GETCH();
        if(c == L'*') {

recheck:

            c = GETCH();
            if(c == L'/') {      /* end of comment */
                return;
            }
            else if(c == L'*') {
                /*
                **  if we get another '*' go back and check for a slash
                */
                goto recheck;
            }
            else if(c == EOS_CHAR) {
                handle_eos();
                goto recheck;
            }
        }
        /*
        **  note we fall through here. we know this baby is not a '*'
        **  we used to unget the char and continue. since we check for
        **  another '*' inside the above test, we can fall through here
        **  without ungetting/getting and checking again.
        */
        if(c <= L'\n') {
            /*
            **  hopefully, the above test is less expensive than doing two tests
            */
            if(c == L'\n') {
                Linenumber++;
                if(Prep) {
                    myfwrite(L"\r\n", 2 * sizeof(WCHAR), 1, OUTPUTFILE);
                }
            }
            else if(c == EOS_CHAR) {
                handle_eos();
            }
        }
    }
}
示例#12
0
expr 
nggen_read_rest_of_body(
    int flag
)
{
    char *cp;
    int ch;
    char in_string;
    int nest_level;
    
    cp = yytext;
    if ( flag ) {
        *cp++ = '{';                    /* already read */
    }
    in_string = 0;
    nest_level = 1;
    do {
        ch = GETCH();
        if ( ch == EOF ) {
            nggen_error("unexpected EOF");
            break;
        } else if ( ch == '\\' ) {         /* escape */
            *cp++ = ch;
            *cp++ = GETCH();
            continue;
        }
        if ( in_string != 0 && in_string == ch ) {
            in_string = 0;
        } else if ( in_string == 0 ) {      /* out string */
            
            if ( ch == '"' || ch == '\'' ) {
                in_string = ch;
            } else if ( ch == '{' ) {       /* else count nest level */
                nest_level++;
            } else if ( ch == '}' ) {
                nest_level--;
            }
        }
        *cp++ = ch;
    } while ( nest_level > 0 );
    if ( !flag ) {
        cp--;
    }
    *cp = '\0';
    return(nggen_make_enode_p(STRING_CONSTANT, nggen_save_str(yytext)));
}
示例#13
0
文件: scanner.c 项目: mingpen/OpenNT
/************************************************************************
**      str_const : gather up a string constant
************************************************************************/
void   str_const(VOID)
{
    REG WCHAR c;
    REG PWCHAR  p_buf;
    int not_warned_yet = TRUE;

    p_buf = yylval.yy_string.str_ptr = Macro_buffer;
    /*
        **      Is it possible that reading this string during a rescan will
        **      overwrite the expansion being rescanned?  No, because a macro
        **      expansion is limited to the top half of Macro_buffer.
        **      For Macro_depth > 0, this is like copying the string from
        **      somewhere in the top half of Macro_buffer to the bottom half
        **      of Macro_buffer.
        **      Note that the restriction on the size of an expanded macro is
        **      stricter than the limit on an L_STRING length.  An expanded
        **      macro is limited to around 1019 bytes, but an L_STRING is
        **      limited to 2043 bytes.
        */
    for(;;) {
        switch(CHARMAP(c = GETCH())) {
        case LX_NL:
            UNGETCH();
            strcpy (Msg_Text, GET_MSG (2001));
            error(2001);
            /*
	    **  FALLTHROUGH
	    */
        case LX_DQUOTE:
            *p_buf++ = L'\0';
            yylval.yy_string.str_len = (USHORT)(p_buf-yylval.yy_string.str_ptr);
            return;
            break;
        case LX_EOS:
            if(handle_eos() != BACKSLASH_EOS) {
                continue;
            }
            if(InInclude) {
                break;
            }
            else {
                c = (WCHAR)escape(get_non_eof());  /* process escaped char */
            }
            break;
        }
        if(p_buf - Macro_buffer > LIMIT_STRING_LENGTH) {
            if( not_warned_yet ) {
                strcpy (Msg_Text, GET_MSG (4009));
                warning(4009);          /* string too big, truncating */
                not_warned_yet = FALSE;
            }
        }
        else {
            *p_buf++ = c;
        }
    }
}
示例#14
0
static int scan_line_comment(Token *tok, Tokenizer *tokz)
{
    STRING_DECL_P(s, "#");
    int c;

    c=GETCH();
                
    while(c!='\n' && c!=EOF){
        STRING_APPEND(s, c);
        c=GETCH();
    }

    UNGETCH(c);

    STRING_FINISH(s);
    
    TOK_SET_COMMENT(tok, s);
    
    return 0;
}
示例#15
0
文件: p0macros.c 项目: mingpen/OpenNT
/************************************************************************
**post_paste:		looks ahead one character to find out if a paste has
**	been requested immediately after this identifier.  If the next
**	character can continue an identifier, or is the macformal marker,
**	a paste should be done.  This is called after a macformal is found
**	to find out if the expanded or unexpanded actual should be used.
************************************************************************/
int  post_paste(void)
{
    UCHAR	c;

    if((CHARMAP(c = GETCH()) == LX_MACFORMAL) || (LXC_IS_IDENT(c))) {
	UNGETCH();
	return(TRUE);
    }
    UNGETCH();
    return(FALSE);
}
示例#16
0
static int skip_line_comment(Tokenizer *tokz)
{
    int c;
    
    do{
        c=GETCH();
    }while(c!='\n' && c!=EOF);

    UNGETCH(c);
        
    return 0;
}
示例#17
0
int doscanf(const char *fmt, va_list ap)
{
	int ret = 0;
	int code;
	int *pvalue = NULL;
	char **sp = NULL;
	char *pc = NULL;
	char string[24] = { 0 };

	for (; ; ) {
		while (((code = *fmt) != '\0') && (code != '%')) {
			fmt++;
			ret++;
		}
		if (code == '\0')
			goto out;

		switch (code = *++fmt) {
			case 'd':
				pvalue = va_arg(ap, int*);
				get_dchars(string, 24);
				convert_d(string, pvalue);
				ret++;
				break;
				/*
			case 'o':
				value = va_arg(ap, int);
				p = otoa(string, value, 24);
				break;
			case 'x':
				value = va_arg(ap, int);
				p = xtoa(string, value, 24);
				break;
				*/
			case 's':
				sp = va_arg(ap, char **);
				get_string(sp, 1024);
				ret++;
				break;
			case 'c':
				pc = va_arg(ap, char *);
				*pc = GETCH();
				break;
			default:
				break;
		}
		fmt++;
	}

out:
	return ret;
}
示例#18
0
文件: scanner.c 项目: mingpen/OpenNT
/************************************************************************
**      char_const : gather up a character constant
**  we're called after finding the openning single quote.
************************************************************************/
token_t char_const(void)
{
    REG WCHAR c;
    value_t value;
    token_t     tok;

    tok = (token_t)(Jflag ? L_CUNSIGNED : L_CINTEGER);
first_switch:
    switch(CHARMAP(c = GETCH())) {
    case LX_BACKSLASH:
        break;
    case LX_SQUOTE:
        strcpy (Msg_Text, GET_MSG (2137));  //"empty character constant"
        error(2137);
        value.v_long = 0;
        UNGETCH();
        break;
    case LX_EOS:                /* ??? assumes i/o buffering > 1 char */
        if(handle_eos() != BACKSLASH_EOS) {
            goto first_switch;
        }
        value.v_long = escape(get_non_eof());
        if( tok == L_CUNSIGNED ) {              /* don't sign extend */
            value.v_long &= 0xff;
        }
        break;
    case LX_NL:
        /* newline in character constant */
        strcpy (Msg_Text, GET_MSG (2001));
        error (2001);
        UNGETCH();
        /*
                **  FALLTHROUGH
                */
    default:
        value.v_long = c;
        break;
    }
    if((c = get_non_eof()) != L'\'') {
        strcpy (Msg_Text, GET_MSG (2015));
        error (2015);           /* too many chars in constant */
        do {
            if(c == L'\n') {
                strcpy (Msg_Text, GET_MSG (2016));
                error(2016);            /* missing closing ' */
                    break;
            }
        } while((c = get_non_eof()) != L'\'');
    }
    yylval.yy_tree = build_const(tok, &value);
    return(tok);
}
示例#19
0
size_t
MyFRead(void *ptr, size_t size, size_t n, FILE *file)
{
    if (isterm(file)) {
	size_t i;

	for (i = 0; i < n; i++)
	    ((BYTE *)ptr)[i] = GETCH();
	TEXTMESSAGE;
	return n;
    }
    return fread(ptr, size, n, file);
}
示例#20
0
文件: p0macros.c 项目: mingpen/OpenNT
/************************************************************************
**	can_get_non_white:	tries to get the next non white character
**		using P1 rules for white space (NL included).  If the end of
**		an actual, or a rescan is found, this returns FALSE, so control
**		can drop into one of the lexers.
************************************************************************/
int	  can_get_non_white(void)
{
    int		return_value = FALSE;
    int		white_found = FALSE;

    for(;;) {
	switch(CHARMAP(GETCH())) {
	case LX_NL:
	    if(On_pound_line) {
		UNGETCH();
		goto leave_cgnw;
	    }
	    Linenumber++;
	    /*
				**	FALLTHROUGH
				*/
	case LX_WHITE:
	case LX_CR:
	    white_found = TRUE;
	    break;
	case LX_EOS:
	    {
		int	eos_res;
		if((eos_res = handle_eos()) & (ACTUAL_EOS | RESCAN_EOS)) {
		    goto leave_cgnw;
		}
		if(eos_res != BACKSLASH_EOS) {
		    break;
		}
	    }
	    /*
				**	FALLTHROUGH
				*/
	default:
	    UNGETCH();
	    return_value = TRUE;
	    goto leave_cgnw;
	    break;
	}
    }
leave_cgnw:
    if(white_found) {
	if(Exp_ptr >= ELIMIT) {
	    fatal_in_macro(10056);
	}
	if(*(Exp_ptr - 1) != ' ') {
	    *Exp_ptr++ = ' ';
	}
    }
    return(return_value);		/* could you get next non white? */
}
示例#21
0
int
nofill()
{
	int	j;
	tchar i;

	if (!pendnf) {
		over = 0;
		tbreak();
		if (trap)
			goto rtn;
		if (nlflg) {
			ch = nflush = 0;
			callsp();
			return (0);
		}
		adsp = adrem = 0;
		nwd = 10000;
	}
	while ((j = (cbits(i = GETCH()))) != '\n') {
		if (j == ohc)
			continue;
		if (j == CONT) {
			pendnf++;
			nflush = 0;
			flushi();
			ckul();
			return (0);
		}
		j = width(i);
		widthp = j;
		numtab[HP].val += j;
		storeline(i, j);
	}
	if (ce) {
		ce--;
		if ((i = quant(nel / 2, HOR)) > 0)
			un += i;
	}
	if (!nc)
		storeline((tchar)FILLER, 0);
	brflg = 2;
	tbreak();
	ckul();
rtn:
	pendnf = nflush = 0;

	return (0);
}
示例#22
0
文件: scanner.c 项目: mingpen/OpenNT
/************************************************************************
**      prep_string : outputs char/string constants when preprocessing only
************************************************************************/
void   prep_string(REG WCHAR c)
{
    REG WCHAR *p_buf;
    int term_char;

    p_buf = Reuse_W;

    term_char = c;

    *p_buf++ = c;               /*  save the open quote  */

    for(;;) {
        switch(CHARMAP(c = GETCH())) {
            case LX_DQUOTE:
            case LX_SQUOTE:
                if(c == (WCHAR)term_char) {
                    *p_buf++ = (WCHAR)term_char;/* save the terminating quote */
                    goto out_of_loop;
                }
                break;
            case LX_BACKSLASH:
                *p_buf++ = c;
                break;
            case LX_CR:
                continue;
            case LX_NL:
                UNGETCH();
                goto out_of_loop;
            case LX_EOS:
                if(c == L'\\') {
                    *p_buf++ = c;
                    c = get_non_eof();
                    break;
                }
                handle_eos();
                continue;
        }
        *p_buf++ = c;
        if(p_buf >= &Reuse_W[MED_BUFFER - 1]) {
            *p_buf = L'\0';
            myfwrite(Reuse_W, (size_t)(p_buf - Reuse_W) * sizeof(WCHAR), 1, OUTPUTFILE);
            p_buf = Reuse_W;
        }
    }

out_of_loop:
    *p_buf = L'\0';
    myfwrite(Reuse_W, (size_t)(p_buf - Reuse_W) * sizeof(WCHAR), 1, OUTPUTFILE);
}
示例#23
0
int 
nggen_read_identifier(
    char ch
)
{
    char *cp;
    SYMBOL sp;
    int rc = 0;
    
    cp = yytext;
    do {
        *cp++ = ch;
        ch = GETCH();
        if ( cp >= &yytext[lex_bufsize-1] ) {
            nggen_fatal("too long identifier");
            break;
        }
    } while ( isalnum((int)ch) || ch == '_' || ch == '$' );
    UNGETCH(ch);    /* push back */
    *cp = '\0';
    sp = nggen_find_symbol(yytext);
    
    switch ( sp->s_type ) {
        case S_KEYWORD:
            rc = sp->s_value;
        break;
        case S_TYPE:
            yylval.val = nggen_make_enode(BASIC_TYPE_NODE, sp->s_value);
            rc = TYPE;
            break;
        case S_CLASS:
            yylval.val = nggen_make_enode(MODE_SPEC_NODE, sp->s_value);
            rc = MODE;
            break;
        case S_DISTMODE:
            yylval.val = nggen_make_enode(DISTMODE_SPEC_NODE, sp->s_value);
            rc = DISTMODE;
            break;
        case S_IDENT:
            yylval.val = nggen_make_enode_p(IDENT, sp);
            rc = IDENTIFIER;
            break;
        default:
            nggen_fatal("nggen_read_identifier");
            break;
    }
    return(rc);
}
示例#24
0
char *get_string(char **sp, int lim)
{
	int i;
	char *s = priv_calloc(1, sizeof(char) * lim);
	if (s) {
		--lim;
		for (i = 0; i < lim; i++) {
			s[i] = GETCH();
			if (isspace(s[i]))
				break;
		}
	}
	s[i] = '\0';
	*sp = s;
	return s;
}
示例#25
0
文件: p0macros.c 项目: mingpen/OpenNT
/************************************************************************
**  gather_chars : collect chars until a matching one is found.
**  skip backslashed chars. moves the chars into the buffer,
**  returns a ptr past the last char copied.
************************************************************************/
ptext_t   gather_chars(REG ptext_t p, UCHAR match_c)
{
    UCHAR	c;

    *p++ = match_c;
    for(;;) {
	if(p > ELIMIT) {
	    return(ELIMIT);
	}
	switch(CHARMAP(c = GETCH())) {
	case LX_NL:
	    Msg_Temp = GET_MSG (2001);
       	    SET_MSG (Msg_Text, Msg_Temp);
	    error(2001);
	    UNGETCH();
	    c = match_c;
	    /*
			**  FALLTHROUGH
			*/
	case LX_DQUOTE:
	case LX_SQUOTE:
	    if(c == match_c) {
		*p++ = c;
		return(p);		/* only way out */
	    }
	    break;
	case LX_EOS:
	    if(handle_eos() != BACKSLASH_EOS) {
		continue;
	    }
	    else {
		/* got backslash */
		*p++ = '\\';
		c = get_non_eof();
		if((c == '\\') && (checknl())) {
		    continue;
		}
	    }
	    break;
	case LX_LEADBYTE:
	    *p++ = c;
	    c = get_non_eof();
	    break;
	}
	*p++ = c;
    }
}
示例#26
0
文件: p0macros.c 项目: mingpen/OpenNT
/************************************************************************
**	do_strformal:	returns pointer to the actual requested without
**		checking for paste (a legal token is not possible, so if a paste
**		is being done on a strformal, the behavior is undefined
************************************************************************/
ptext_t   do_strformal(void)
{
    UCHAR		n;
    ptext_t	p;

    /* use unexpanded actual */
    p = CURRENT_ACTUALS;
    n = GETCH();
    if(n > CURRENT_NACTUALS) {
	return(NULL);		/* already output warning */
    }
    if (n != 0)
	while(--n) {
	    p = ACTUAL_NEXT(p);
	}
    return(ACTUAL_TEXT(p));
}
示例#27
0
static int scan_identifier(Token *tok, Tokenizer *tokz, int c)
{
    STRING_DECL(s);
    
    do{
        STRING_APPEND(s, c);
        c=GETCH();
    }while(isalnum(c) || c=='_' || c=='$');
    
    UNGETCH(c);
    
    STRING_FINISH(s);
    
    TOK_SET_IDENT(tok, s);

    return 0;
}
示例#28
0
char *get_dchars(char *s, int lim)
{
	int i;
	int c;

	s[--lim] = '\0';
	for (i = 0; i < lim; i++) {
		if (isdigit(c = GETCH())) {
			s[i] = c;
		} else {
			UNGETCH(c);
			break;
		}
	}
	if (i < lim)
		s[i] = '\0';
	return s;
}
示例#29
0
/***************************************************************************
 * FUNCTION: intro                                                         *
 * PURPOSE: Present user with introductory screen. Get base address.       *
 **************************************************************************/
void intro(void)
   {
   CLRSCR();
   CPRINTF(
   "                        C SAMPLE #1: SAMPLE1.C                          \n\n"
   "  This sample will prompt the user for a voltage between 0 and 10 volts,  \n"
   "  then calculate the actual voltage based on the resolution of the DAC and\n"
   "  output the voltage to the desired DAC channel.                        \n\n"
   "  The following setup of the board is expected:                         \n\n"
   "        þ All DAC voltage ranges should be set to 0v-10v unipolar.        \n\n");

   PUTS("\n");
   PUTS("Press any key to continue ... ");
   GETCH();
   CLRSCR();
   base = AskForBaseAddress(0x350, "");
   CLRSCR();
   EBase = AskForBaseAddress(0x350, "Calibration ");
   } /* end of intro */
示例#30
0
文件: scanner.c 项目: mingpen/OpenNT
/************************************************************************
 * GETID - Get an identifier or keyword.
 * (we know that we're given at least 1 id char)
 * in addition, we'll hash the value using 'c'.
 ************************************************************************/
void getid(REG  UINT    c)
{
    REG WCHAR   *p;

    p = Reuse_W;
    *p++ = (WCHAR)c;
    c &= HASH_MASK;

repeat:
    while(LXC_IS_IDENT(*p = GETCH())) {    /* while it's an id char . . . */
        c += (*p & HASH_MASK);                  /* hash it */
        p++;
    }
    if(*p != EOS_CHAR) {
        if((*p == L'\\') && (checknl())) {
            goto repeat;
        }
        UNGETCH();
        if(p >= LIMIT(Reuse_W)) {
            strcpy (Msg_Text, GET_MSG (1067));
            fatal(1067);
        }
        if(     ((p - Reuse_W) > LIMIT_ID_LENGTH) && ( ! Prep )) {
            p = Reuse_W + LIMIT_ID_LENGTH;
            *p++ = L'\0';
            c = local_c_hash(Reuse_W);
            Msg_Temp = GET_MSG (4011);
            SET_MSG (Msg_Text, sizeof(Msg_Text), Msg_Temp, Reuse_W);
            warning(4011);      /* id truncated */
        }
        else {
            *p++ = L'\0';
        }
        Reuse_W_hash = (hash_t)c;
        Reuse_W_length = (UINT)(p - Reuse_W);
        return;
    }
    if(io_eob()) {                      /* end of file in middle of id */
        strcpy (Msg_Text, GET_MSG (1004));
        fatal(1004);
    }
    goto repeat;
}