home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff262.lzh / Lotto / data.c < prev    next >
C/C++ Source or Header  |  1989-10-31  |  1KB  |  61 lines

  1. /*************************************/
  2. /*                                   */
  3. /* AUoH Progressive Door Prize Lotto */
  4. /*                                   */
  5. /*     DataBase extract routine      */
  6. /*                                   */
  7. /*  Michael D. Groshart - 16 Aug 89  */
  8. /*                                   */
  9. /*************************************/
  10.  
  11. #include <fcntl.h>
  12.  
  13. typedef struct sb_block
  14. {
  15.     long id;
  16.     char user[4];
  17.     char fill1[13];
  18.     char code;
  19.     char fill2;
  20.     char data[105];
  21. } SBblock;
  22.  
  23. #define NUMBLOCKS 8
  24. #define BLOCKSIZE (sizeof(SBblock))
  25. #define BUFFERLEN (NUMBLOCKS*BLOCKSIZE)
  26.  
  27. SBblock buffer[NUMBLOCKS];
  28.  
  29. #define DATABLOCK 0x80000000    /* Bit mask to determine block type */
  30.  
  31. read_db(name,add)
  32. char *name;
  33. void (*add)();
  34. {
  35.     register int fd, bytes, i, nent;
  36.  
  37.     if ((fd = open(name,O_RDONLY)) < 0) return 0;
  38.  
  39.     while ((bytes = read(fd,buffer,BUFFERLEN)) > 0)
  40.     {
  41.         for (i = 0; i < (bytes / BLOCKSIZE); i++)
  42.         {
  43.             if (buffer[i].id & DATABLOCK)
  44.             {
  45.                 switch(buffer[i].code)
  46.                 {
  47.                     case 'N':
  48.                     case 'R':
  49.                         add(buffer[i].user,buffer[i].data);
  50.                     default:
  51.                         break;
  52.                 }
  53.             }
  54.         }
  55.     }
  56.  
  57.     close(fd);
  58.  
  59.     return 1;
  60. }
  61.