help w/pipe read

root root at ozdaltx.UUCP
Tue May 29 11:21:17 AEST 1990


Situation:
  Read characters from a pipe (one at a time) and at the same time scan
the keyboard for a command without disrupting the pipe input.

Conditions:
  Stdin and stdout have been closed, ttfp has been opened
for reading and writing (fopen w/r+). CBREAK (only) is in effect.

What happens:
  The pipe is read successfully, but the program waits until some key
is struck on the keyboard before it prints anything else from the
pipe.

I have tried fgetc, fscanf and just about everything else I can think
of.... What am I missing (see below)?

Thanks in advance...
Scotty
-----
AIDS INFORMATION EXCHANGE BBS      (214) 247-2367/247-5609
               "Education is the best weapon"
{mic,void,egsner}!ozdaltx!sysop || {uunet,smu,ames}!sulaco!ozdaltx!sysop 
----------------------------------------------------------------------
int pread()
{   /* reads the pipe and displays one char at a time
    ** while checking the keyboard for input
    */

    FILE  *fd;  /* fd is the PIPE pointer created earlier */
    int q;
    int rc;
    char rcmd[1][3];
    int c;

    rcmd[0][0]='\0';
    q = 0;
    if((fd = fopen(PIPE, "r+")) == 0){
        return(0);
    }
    setbuf(fd, 0);
    while(1) {
       rc = getc(fd);
       putc(rc,ttfp);   /* put a char from the pipe to the tty*/
       q=0;
       if(isspace(rc)){
           fflush(fd);
           fread(rcmd,1,1,ttfp);  /* ttfp is opened [r+] in main() as the tty */
           fflush(ttfp);
           c='\0';
           c = (int)rcmd[0][0];
           if(c == ':'){
               fprintf(ttfp,"\nCommand: ");
               c=getc(ttfp);
                 switch(c){
                    case 'Q':
                    case 'q':
                              fclose(fd);
                              return(0);
                 }
           }
           c='\0';
       }
    }
    fclose(fd);
    return(0);
}



More information about the Comp.unix.xenix mailing list