home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / B_FUSER.C < prev    next >
C/C++ Source or Header  |  1990-06-28  |  7KB  |  155 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-90, 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.240.    */
  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:132/491, 1:141/491  */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n132.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 <stdio.h>
  47. #include <sys\types.h>
  48. #include <sys\stat.h>
  49. #include <fcntl.h>
  50. #include <string.h>
  51. #include <io.h>
  52.  
  53. #include "com.h"
  54. #include "xfer.h"
  55. #include "zmodem.h"
  56. #include "keybd.h"
  57. #include "sbuf.h"
  58. #include "sched.h"
  59. #include "externs.h"
  60. #include "prototyp.h"
  61.  
  62. static int reclength = -1;
  63. static int nrecs = -1;
  64.  
  65. void fidouser (name, faddr)
  66. char *name;
  67. ADDR *faddr;
  68. {
  69.    int low, high, mid, f, cond, namelen;
  70.    char midname[80];
  71.    char last_name_first[80];
  72.    char *c, *p, *m;
  73.    struct stat buffer;
  74.  
  75.    faddr->Zone = faddr->Net = faddr->Node = faddr->Point = -1;
  76.    faddr->Domain = NULL;
  77.  
  78.    c = midname;                                  /* Start of temp name buff   */
  79.    p = name;                                     /* Point to start of name    */
  80.    m = NULL;                                     /* Init pointer to space     */
  81.  
  82.    *c = *p++;
  83.    while (*c)                                    /* Go entire length of name  */
  84.       {
  85.       if (*c == ' ')                             /* Look for space            */
  86.          m = c;                                  /* Save location             */
  87.       c++;
  88.       *c = *p++;
  89.       }
  90.  
  91.    if (m != NULL)                                /* If we have a pointer,     */
  92.       {
  93.       *m++ = '\0';                               /* Terminate the first half  */
  94.       (void) strcpy (last_name_first, m);               /* Now copy the last name    */
  95.       (void) strcat (last_name_first, ", ");            /* Insert a comma and space  */
  96.       (void) strcat (last_name_first, midname);         /* Finally copy first half   */
  97.       }
  98.    else (void) strcpy (last_name_first, midname);       /* Use whole name otherwise  */
  99.  
  100.    (void) fancy_str (last_name_first);                  /* Get caps in where needed  */
  101.    namelen = (int) strlen (last_name_first);           /* Calc length now           */
  102.  
  103.    midname[0] = '\0';                            /* "null-terminated string"  */
  104.    (void) strcpy (midname, net_info);                   /* take nodelist path        */
  105.    (void) strcat (midname, "FIDOUSER.LST");             /* add in the file name      */
  106.    if ((f = open (midname, O_RDONLY | O_BINARY)) == -1)
  107.       {
  108.       reclength = -1;                            /* Reset all on open failure */
  109.       return;
  110.       }
  111.  
  112.    /* Find out if we have done this before */
  113.    if (reclength == -1)
  114.       {
  115.       /* If not, then determine file size and record length */
  116.  
  117.       (void) fstat (f, &buffer);                        /* Get file stats in buffer  */
  118.       (void) read (f, midname, 80);                     /* Read 1 record             */
  119.       reclength = ((int) strchr (midname, '\n') - (int) midname) + 1;   /* FindEnd */
  120.       nrecs = (int) (buffer.st_size / reclength);/* Now get num of records */
  121.       }
  122.  
  123.    /* Binary search algorithm */
  124.    low = 0;
  125.    high = nrecs - 1;
  126.    while (low <= high)
  127.       {
  128.       mid = low + (high - low) / 2;
  129.       (void) lseek (f, (long) ((long) mid * (long) reclength), SEEK_SET);
  130.       (void) read (f, midname, (unsigned int) reclength);
  131.       if ((cond = strnicmp (last_name_first, midname, (unsigned int) namelen)) < 0)
  132.          high = mid - 1;
  133.       else
  134.          {
  135.          if (cond > 0)
  136.             low = mid + 1;
  137.          else
  138.             {
  139.             /* Return the address information */
  140.             (void) close (f);
  141.             /* The offset of 40 is just a number that should work properly */
  142.             faddr->Point = 0;
  143.             if (!find_address (&midname[40], faddr))
  144.                {
  145.                faddr->Zone = faddr->Net = faddr->Node = faddr->Point = -1;
  146.                }
  147.             return;
  148.             }
  149.          }
  150.       }
  151.    faddr->Zone = faddr->Net = faddr->Node = faddr->Point = -1;
  152.    faddr->Domain = NULL;
  153.    (void) close (f);
  154. }
  155.