home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / com / bbs / lora / lora234s.exe / READUSR.C < prev    next >
C/C++ Source or Header  |  1993-10-17  |  2KB  |  78 lines

  1. /*
  2.  
  3.                       LoraBBS (DOS / OS2) Ver. 2.33
  4.  
  5.     Copyright (c) 1989, 1990, 1991, 1992, 1993 by Marco Maccaferri.
  6.                           All rights reserved.
  7.  
  8.  
  9.                           Source code examples
  10.                        User record read routines
  11.  
  12.  
  13.   You may use this structures at your own risk. The author cannot guarantee
  14.   that this structures are maintained in all future versions of the program.
  15.   You can freely (and you are encouraged on that) distribute this file
  16.   without limitations.
  17.  
  18.   You can contact the autor at one of the following address:
  19.  
  20.   Marco Maccaferri
  21.   BBS: 39-51-6331730 (2:332/402)
  22.  
  23. */
  24. #include <stdio.h>
  25. #include <io.h>
  26. #include <time.h>
  27. #include <fcntl.h>
  28. #include <string.h>
  29.  
  30. #include "lora.h"
  31. #include "crc32.h"
  32.  
  33. #define MAX_INDEX   500
  34.  
  35. void read_user_record (name)
  36. char *name;
  37. {
  38.    int fd, fflag, m, i, posit;
  39.    long crc;
  40.    struct _usr usr;
  41.    struct _usridx usridx[MAX_INDEX];
  42.  
  43.    crc = 0xFFFFFFFFL;
  44.    for (i=0; i < strlen(name); i++)
  45.       crc = Z_32UpdateCRC (((unsigned short) name[i]), crc);
  46.  
  47.    fd = open ("USERS.BBS", O_RDWR|O_BINARY);
  48.  
  49.    fflag = 0;
  50.    posit = 0;
  51.  
  52.    do {
  53.       i = read(fd,(char *)&usridx,sizeof(struct _usridx) * MAX_INDEX);
  54.       m = i / sizeof (struct _usridx);
  55.  
  56.       for (i=0; i < m; i++)
  57.          if (usridx[i].id == crc)
  58.          {
  59.             posit += i;
  60.             fflag = 1;
  61.             break;
  62.          }
  63.  
  64.       if (!fflag)
  65.          posit += m;
  66.    } while (m == MAX_INDEX && !fflag);
  67.  
  68.    close (fd);
  69.  
  70.    fd = open ("USERS.BBS", O_RDWR|O_BINARY);
  71.  
  72.    lseek (fd, (long)posit * sizeof (struct _usr), SEEK_SET);
  73.    read(fd, (char *)&usr, sizeof(struct _usr));
  74.  
  75.    close(fd);
  76. }
  77.  
  78.