home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / B_FUSER.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  7KB  |  141 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                 This module was written by Bob Hartman                   */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                 BinkleyTerm Fidolist processing module                   */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  29. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /* You can contact Bit Bucket Software Co. at any one of the following      */
  34. /* addresses:                                                               */
  35. /*                                                                          */
  36. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n343.z1.fidonet.org         */
  40. /*                                                                          */
  41. /* Please feel free to contact us at any time to share your comments about  */
  42. /* our software and/or licensing policies.                                  */
  43. /*                                                                          */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46. /* Include this file before any other includes or defines! */
  47.  
  48. #include "includes.h"
  49.  
  50. static int reclength = -1;
  51. static int nrecs = -1;
  52.  
  53. void ovl_fidouser (char *name, ADDRP faddr)
  54. {
  55.    int low, high, mid, f, cond, namelen;
  56.    char midname[80];
  57.    char last_name_first[80];
  58.    char *c, *p, *m;
  59.    struct stat buffer;
  60.  
  61.    faddr->Zone = faddr->Net = faddr->Node = faddr->Point = (unsigned int) -1;
  62.    faddr->Domain = NULL;
  63.  
  64.    c = midname;                                  /* Start of temp name buff   */
  65.    p = name;                                     /* Point to start of name    */
  66.    m = NULL;                                     /* Init pointer to space     */
  67.  
  68.    *c = *p++;
  69.    while (*c)                                    /* Go entire length of name  */
  70.       {
  71.       if (*c == ' ')                             /* Look for space            */
  72.          m = c;                                  /* Save location             */
  73.       c++;
  74.       *c = *p++;
  75.       }
  76.  
  77.    if (m != NULL)                                /* If we have a pointer,     */
  78.       {
  79.       *m++ = '\0';                               /* Terminate the first half  */
  80.       (void) strcpy (last_name_first, m);               /* Now copy the last name    */
  81.       (void) strcat (last_name_first, ", ");            /* Insert a comma and space  */
  82.       (void) strcat (last_name_first, midname);         /* Finally copy first half   */
  83.       }
  84.    else (void) strcpy (last_name_first, midname);       /* Use whole name otherwise  */
  85.  
  86.    (void) fancy_str (last_name_first);                  /* Get caps in where needed  */
  87.    namelen = (int) strlen (last_name_first);           /* Calc length now           */
  88.  
  89.    midname[0] = '\0';                            /* "null-terminated string"  */
  90.    (void) strcpy (midname, net_info);                   /* take nodelist path        */
  91.    (void) strcat (midname, "FIDOUSER.LST");             /* add in the file name      */
  92.    if ((f = share_open (midname, O_RDONLY | O_BINARY, DENY_WRITE)) == -1)
  93.       {
  94.       reclength = -1;                            /* Reset all on open failure */
  95.       return;
  96.       }
  97.  
  98.    /* Find out if we have done this before */
  99.    if (reclength == -1)
  100.       {
  101.       /* If not, then determine file size and record length */
  102.  
  103.       (void) fstat (f, &buffer);                        /* Get file stats in buffer  */
  104.       (void) read (f, midname, 80);                     /* Read 1 record             */
  105.       reclength = (int) (strchr (midname, '\n') - midname) + 1;   /* FindEnd */
  106.       nrecs = (int) (buffer.st_size / reclength);/* Now get num of records */
  107.       }
  108.  
  109.    /* Binary search algorithm */
  110.    low = 0;
  111.    high = nrecs - 1;
  112.    while (low <= high)
  113.       {
  114.       mid = low + (high - low) / 2;
  115.       (void) lseek (f, (long) ((long) mid * (long) reclength), SEEK_SET);
  116.       (void) read (f, midname, (unsigned int) reclength);
  117.       if ((cond = strnicmp (last_name_first, midname, (unsigned int) namelen)) < 0)
  118.          high = mid - 1;
  119.       else
  120.          {
  121.          if (cond > 0)
  122.             low = mid + 1;
  123.          else
  124.             {
  125.             /* Return the address information */
  126.             (void) close (f);
  127.             /* The offset of 40 is just a number that should work properly */
  128.             faddr->Point = 0;
  129.             if (!find_address (&midname[40], faddr))
  130.                {
  131.                faddr->Zone = faddr->Net = faddr->Node = faddr->Point = (unsigned int) -1;
  132.                }
  133.             return;
  134.             }
  135.          }
  136.       }
  137.    faddr->Zone = faddr->Net = faddr->Node = faddr->Point = (unsigned int) -1;
  138.    faddr->Domain = NULL;
  139.    (void) close (f);
  140. }
  141.