"Fossies" - the Fresh Open Source Software Archive

Member "dosemu-1.4.0/src/arch/linux/dosext/sound/midid/io.c" (4 May 2007, 2288 Bytes) of package /linux/misc/old/dosemu-1.4.0.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "io.c" see the Fossies "Dox" file reference documentation.

    1 /* 
    2  * (C) Copyright 1992, ..., 2007 the "DOSEMU-Development-Team".
    3  *
    4  * for details see file COPYING.DOSEMU in the DOSEMU distribution
    5  */
    6 
    7 #include "io.h"
    8 #include "midid.h"
    9 #include <stdio.h>
   10 #include <stdlib.h>
   11 #include <string.h>
   12 #include <unistd.h>
   13 #include <sys/time.h>
   14 #include <sys/types.h>
   15 #include <errno.h>
   16 
   17 /***********************************************************************
   18   Output
   19  ***********************************************************************/
   20 
   21 void error(char *err)
   22 {
   23     fprintf(stderr, "Fatal error: %s\n", err);
   24     exit(1);
   25 }
   26 
   27 /***********************************************************************
   28   Input from stdin with 1 byte buffer
   29  ***********************************************************************/
   30 
   31 int getbyte_buffer=MAGIC_EOF;
   32 
   33 void getbyte_next(void)
   34 /* Read next symbol into buffer */
   35 {
   36         fd_set rfds;
   37         struct timeval tv;
   38         byte ch;
   39         bool is_eof;
   40 
   41         tv.tv_sec = config.timeout;
   42         tv.tv_usec = 0;
   43 again:
   44         FD_ZERO(&rfds);
   45         FD_SET(fd, &rfds);
   46     switch (select(fd + 1, &rfds, NULL, NULL, config.timeout ? &tv : NULL)) {
   47         case -1:
   48         if (tv.tv_sec + tv.tv_usec == 0) {
   49             getbyte_buffer = MAGIC_TIMEOUT;
   50             break;
   51         }
   52         if (errno == EINTR)
   53             goto again;
   54         getbyte_buffer = MAGIC_EOF;
   55         break;
   56         case 0:
   57         if (errno == EINTR && tv.tv_sec + tv.tv_usec > 0)
   58             goto again;
   59         getbyte_buffer = MAGIC_TIMEOUT;
   60         break;
   61         default:
   62         is_eof = (read(fd, &ch, 1) == 0);
   63         getbyte_buffer = ch;
   64         if (is_eof)
   65           getbyte_buffer = MAGIC_EOF;
   66         break;
   67     }
   68     if (debugall) fprintf(stderr,"getbyte_next=0x%02x (%i)\n",
   69                   getbyte_buffer,getbyte_buffer);
   70 }
   71 
   72 int getbyte(void)
   73 /* Return current contents of buffer */
   74 {
   75     return getbyte_buffer;
   76 }
   77 
   78 int getbyte_status(void)
   79 /* Tries to read a status byte (==bit 7 set) */
   80 {
   81     bool accept=(getbyte_buffer & 0x80);
   82     int ch=getbyte_buffer;
   83     if (!accept) {
   84         ch=MAGIC_INV;
   85         if (debugall) fprintf(stderr,"Status not specified, using previous\n");
   86     }
   87     return(ch);
   88 }
   89 
   90 int getbyte_data(void)
   91 /* Tries to read a data byte (==bit 7 reset) */
   92 {
   93     bool accept=(!(getbyte_buffer & 0x80));
   94     int ch=getbyte_buffer;
   95     if (!accept) {
   96         ch=MAGIC_INV;
   97         if (warning) fprintf(stderr,"Warning: got an illegal data byte=%i\n",getbyte_buffer);
   98     }
   99     return(ch);
  100 }