bin/csh/dol.c
/*
 * Get a word.  This routine is analogous to the routine
 * word() in sh.lex.c for the main lexical input.  One difference
 * here is that we don't get a newline to terminate our expansion.
 * Rather, DgetC will return a DEOF when we hit the end-of-input.
 */
Get a word.  This routine is analogous to the routine
word() in sh.lex.c for the main lexical input.  One difference
here is that we don't get a newline to terminate our expansion.
Rather, DgetC will return a DEOF when we hit the end-of-input.
Get a word . This routine is analogous to the routine word () in sh . lex . c for the main lexical input . One difference here is that we don ' t get a newline to terminate our expansion . Rather DgetC will return a DEOF when we hit the end - of - input .
static int
Dword()
{
    register int c, c1;
    Char    wbuf[BUFSIZ];
    register Char *wp = wbuf;
    register int i = MAXWLEN;
    register bool dolflg;
    bool    sofar = 0, done = 0;
    while (!done) {
	done = 1;
	c = DgetC(DODOL);
	switch (c) {
	case DEOF:
	    if (sofar == 0)
		return (0);
	    unDredc(c);
	case '\n':
	    *wp = 0;
	    Gcat(STRNULL, wbuf);
	    return (1);
	case ' ':
	case '\t':
	    done = 0;
	    break;
	case '`':
	    *wp++ = c, --i;
	case '\'':
	case '"':
	    c1 = c;
	    dolflg = c1 == '"' ? DODOL : 0;
	    for (;;) {
		c = DgetC(dolflg);
		if (c == c1)
		    break;
		if (c == '\n' || c == DEOF)
		    stderror(ERR_UNMATCHED, c1);
		if ((c & (QUOTE | TRIM)) == ('\n' | QUOTE))
		    --wp, ++i;
		if (--i <= 0)
		    stderror(ERR_WTOOLONG);
		switch (c1) {
		case '"':
		    *wp++ = c == '`' ? '`' : c | QUOTE;
		    break;
		case '\'':
		    *wp++ = c | QUOTE;
		    break;
		case '`':
		    *wp++ = c;
		    break;
		default:
		    break;
		}
	    }
	    if (c1 == '`')
		*wp++ = '`' ;
	    sofar = 1;
	    if ((wp = Dpack(wbuf, wp)) == NULL)
		return (1);
	    else {
		i = MAXWLEN - (wp - wbuf);
		done = 0;
	    }
	    break;
	case '\\':
	    c = DgetC(0);	
	    if (c == '\n' || c == DEOF) {
		done = 0;
		break;
	    }
	    c |= QUOTE;
	    break;
	default:
	    break;
	}
	if (done) {
	    unDgetC(c);
	    sofar = 1;
	    if ((wp = Dpack(wbuf, wp)) == NULL)
		return (1);
	    else {
		i = MAXWLEN - (wp - wbuf);
		done = 0;
	    }
	}
    }
    return (0);
}
static int Dword ( ) { register int c , c1 ; Char wbuf [ BUFSIZ ] ; register Char * wp = wbuf ; register int i = MAXWLEN ; register bool dolflg ; bool sofar = 0 , done = 0 ; while ( ! done ) { done = 1 ; c = DgetC ( DODOL ) ; switch ( c ) { case DEOF : if ( sofar == 0 ) return ( 0 ) ; unDredc ( c ) ; case ' \n ' : * wp = 0 ; Gcat ( STRNULL , wbuf ) ; return ( 1 ) ; case ' ' : case ' \t ' : done = 0 ; break ; case ' ' : * wp ++ = c , -- i ; case ' \' ' : case ' ' : c1 = c ; dolflg = c1 == ' ' ? DODOL : 0 ; for ( ; ; ) { c = DgetC ( dolflg ) ; if ( c == c1 ) break ; if ( c == ' \n ' || c == DEOF ) stderror ( ERR_UNMATCHED , c1 ) ; if ( ( c & ( QUOTE | TRIM ) ) == ( ' \n ' | QUOTE ) ) -- wp , ++ i ; if ( -- i <= 0 ) stderror ( ERR_WTOOLONG ) ; switch ( c1 ) { case ' ' : * wp ++ = c == ' ' ? ' ' : c | QUOTE ; break ; case ' \' ' : * wp ++ = c | QUOTE ; break ; case ' ' : * wp ++ = c ; break ; default : break ; } } if ( c1 == ' ' ) * wp ++ = ' ' ; sofar = 1 ; if ( ( wp = Dpack ( wbuf , wp ) ) == NULL ) return ( 1 ) ; else { i = MAXWLEN - ( wp - wbuf ) ; done = 0 ; } break ; case ' \\ ' : c = DgetC ( 0 ) ; if ( c == ' \n ' || c == DEOF ) { done = 0 ; break ; } c |= QUOTE ; break ; default : break ; } if ( done ) { unDgetC ( c ) ; sofar = 1 ; if ( ( wp = Dpack ( wbuf , wp ) ) == NULL ) return ( 1 ) ; else { i = MAXWLEN - ( wp - wbuf ) ; done = 0 ; } } } return ( 0 ) ; }
Get a word.
Get a word .
/* finish this word and catch the code above the next time */ /* fall into ... */ /* We preserve ` quotations which are done yet later */ /*
	     * Note that DgetC never returns a QUOTES character from an
	     * expansion, so only true input quotes will get us here or out.
	     */ /*
		     * Leave any `s alone for later. Other chars are all
		     * quoted, thus `...` can tell it was within "...".
		     */ /* Prevent all further interpretation */ /* Leave all text alone for later */ /* i--; eliminated */ /* No $ subst! */ /* Really NOTREACHED */