コード例 #1
0
ファイル: xlio.c プロジェクト: jhbadger/xlispstat
/* xlgetc - get a character from a file or stream */
int xlgetc P1C(LVAL, fptr)
{
    LVAL lptr,cptr=NULL;
    FILEP fp;
    int ch;

    /* check for input from nil */
    if (fptr == NIL)
	ch = EOF;

    /* otherwise, check for input from a stream */
    else if (ustreamp(fptr)) {
	if ((lptr = gethead(fptr)) == NIL)
	    ch = EOF;
	else {
	    if (!consp(lptr) || (cptr = car(lptr)) == NIL || !charp(cptr))
		xlfail("bad stream");
	    sethead(fptr,lptr = cdr(lptr));
	    if (lptr == NIL)
		settail(fptr,NIL);
	    ch = getchcode(cptr);
	}
    }

    /* otherwise, check for a buffered character */
    else if ((ch = getsavech(fptr)) != 0)
	setsavech(fptr,'\0');

    /* otherwise, check for terminal input or file input */
    else {
	fp = getfile(fptr);
        if (fp == CLOSED)   /* TAA MOD -- give error */
            xlfail("can't read closed stream");
	else if (fp == CONSOLE)
            /* TAA MOD -- revamped for redirecting */
	    ch = ostgetc();
        else {
	  if ((fptr->n_sflags & S_FORREADING) == 0)
	    xlerror("can't read write-only file stream", fptr);
	  if ((fptr->n_sflags & S_READING) == 0) {
	    /* possible direction change*/
	    if (fptr->n_sflags & S_WRITING) {
	      OSSEEKCUR(fp,0L);
	    }
	    fptr->n_sflags |= S_READING;
	    fptr->n_sflags &= ~S_WRITING;
	  }
#ifdef OSAGETC
	  ch = (fptr->n_sflags & S_BINARY) ? OSGETC(fp) : OSAGETC(fp);
#else
	  ch = OSGETC(fp);
#endif
	}
    }

    /* return the character */
    return (ch);
}
コード例 #2
0
ファイル: xlio.c プロジェクト: SteveDaulton/audacity
/* xlgetc - get a character from a file or stream */
int xlgetc(LVAL fptr)
{
    LVAL lptr, cptr=NULL;
    FILE *fp;
    int ch;

    /* check for input from nil */
    if (fptr == NIL)
        ch = EOF;

    /* otherwise, check for input from a stream */
    else if (ustreamp(fptr)) {
        if ((lptr = gethead(fptr)) == NIL)
            ch = EOF;
        else {
            if (!consp(lptr) || (cptr = car(lptr)) == NIL || !charp(cptr))
                xlfail("bad stream");
            sethead(fptr,lptr = cdr(lptr));
            if (lptr == NIL)
                settail(fptr,NIL);
            ch = getchcode(cptr);
        }
    }

    /* otherwise, check for a buffered character */
    else if ((ch = getsavech(fptr)))
        setsavech(fptr,'\0');

    /* otherwise, check for terminal input or file input */
    else {
        fp = getfile(fptr);
        if (fp == stdin || fp == STDERR)
            ch = ostgetc();
        else
            ch = osagetc(fp);
#ifdef DEBUG_INPUT
        if (read_by_xlisp && ch != -1) {
			putc(ch, read_by_xlisp);
		}
#endif
    }

    /* return the character */
    return (ch);
}