home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / B_SEARCH.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  13KB  |  367 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 Vince Perriello                 */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                   BinkleyTerm Phone list Search 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. int SaveScanList (int);
  51. void wait_for_keypress(void);
  52.  
  53. int list_search ()
  54. {
  55.    int saved_baud;
  56.    long t1;
  57.    int i, k, l;
  58.    int dirty;
  59.    ADDR ls_addr;
  60.    unsigned int kbd_input;
  61.  
  62.    static unsigned int save_chars[] = {
  63.       SHF1, SHF2, SHF3, SHF4, SHF5,
  64.       SHF6, SHF7, SHF8, SHF9, SHF10
  65.    };
  66.  
  67.    static unsigned int load_chars[] =  {
  68.       ALTF1, ALTF2, ALTF3, ALTF4, ALTF5,
  69.       ALTF6, ALTF7, ALTF8, ALTF9, ALTF10
  70.    };
  71.  
  72.    static unsigned int command_chars[] = {
  73.       PF1, PF2, PF3, PF4, PF5,
  74.       PF6, PF7, PF8, PF9, PF10
  75.    };
  76.  
  77.    /*
  78.     * *     Input the phone numbers we want to scan *
  79.     *
  80.     */
  81.  
  82.    dirty = 1;
  83.  
  84. /*
  85.  * Print out a null string nicely for OS/2
  86.  */
  87.  
  88. #define NICE_TEXT(n) (((n) == NULL) ? "(none)" : n)
  89.  
  90.    for (;;)
  91.       {
  92.       if (dirty)
  93.          {
  94.          screen_clear ();
  95.          (void) printf (MSG_TXT(M_PHONE_HELP));
  96.          (void) printf (MSG_TXT(M_PHONE_HELP2));
  97.          if (set_loaded)
  98.             (void) printf (MSG_TXT(M_LAST_SET),set_loaded);
  99.          (void) printf (MSG_TXT(M_CURRENT_PHONES));
  100.          for (k = 0; k < 10; k += 2)
  101.             {
  102.             (void) printf ("%2d: %35s %2d: %35s\n",
  103.                      k + 1,
  104.                      NICE_TEXT (scan_list[k]),
  105.                      k + 2,
  106.                      NICE_TEXT (scan_list[k + 1]));
  107.             }
  108.          (void) printf (MSG_TXT(M_INPUT_COMMAND));
  109.          dirty = 0;
  110.          }
  111.  
  112.       while (!KEYPRESS ())
  113.          time_release ();
  114.       kbd_input = FOSSIL_CHAR ();
  115.  
  116.       if (((kbd_input & 0xff) == '\n') || ((kbd_input & 0xff) == '\r'))
  117.          break;
  118.  
  119.       if ((kbd_input & 0xff) == ESC)
  120.          return (0);
  121.  
  122.       for (k = 0; k < 10; k++)
  123.          {
  124.          if (kbd_input == save_chars[k])         /* Save into a set?   */
  125.             {
  126.             (void) SaveScanList(k);                     /* Yes, do it         */
  127.             dirty = 1;                           /* Force redisplay    */
  128.             k = 10;                              /* Then fool the logic*/
  129.             break;
  130.             }
  131.  
  132.          if (kbd_input == load_chars[k])         /* Load from a set?   */
  133.             {
  134.             (void) LoadScanList(k,1);                   /* Yes, do it         */
  135.             dirty = 1;                           /* Force redisplay    */
  136.             k = 10;                              /* Then fool the logic*/
  137.             break;
  138.             }
  139.  
  140.          if (kbd_input == command_chars[k])      /* Plain old Fkey?    */
  141.             break;                               /* Yup, get out now   */
  142.          }
  143.  
  144.       if (k == 10)                               /* Not a function key */
  145.          {
  146.          k = (kbd_input & 0xff) - '0';           /* Convert from digit */
  147.          if ((k < 0) || (k > 9))                 /* Was it a digit?    */
  148.             continue;                            /* No, throw char out */
  149.          if (!k)                                 /* Is it a zero?      */
  150.             k = 9;                               /* That's 9 to us     */
  151.          else --k;                               /* Else make zero-rel */
  152.          }
  153.  
  154.       (void) printf (MSG_TXT(M_ELEMENT_CHOSEN), k + 1);
  155.       if (scan_list[k] != NULL)
  156.          {
  157.          (void) printf (MSG_TXT(M_CURRENTLY_CONTAINS), scan_list[k]);
  158.          (void) printf (MSG_TXT(M_PHONE_HELP3));
  159.          }
  160.       else
  161.          {
  162.          (void) printf (MSG_TXT(M_PHONE_HELP4));
  163.          }
  164.       (void) gets (junk);                               /* Get the user's input */
  165.       ++dirty;                                   /* Always redisplay     */
  166.       if ((l = (int) strlen (junk)) == 0)              /* If nothing there,    */
  167.          continue;                               /* move along           */
  168.  
  169.       if (l == 1 && *junk == ' ')                /* If just a space...   */
  170.          {
  171.          if (scan_list[k] != NULL)               /* Delete old number    */
  172.             free(scan_list[k]);
  173.          scan_list[k] = NULL;                    /* Clean up the ref     */
  174.          continue;                               /* End this iteration   */
  175.          }
  176.  
  177.       if (scan_list[k] != NULL) {                /* Get rid of old num   */
  178.          free(scan_list[k]);
  179.          }
  180.       if ((scan_list[k] = calloc( 1, (unsigned int) (++l))) == NULL) /* Allocate space       */
  181.          {
  182.          (void) printf (MSG_TXT(M_MEM_ERROR));
  183.          return (0);                             /* Get out for error    */
  184.          }
  185.       (void) strcpy (scan_list[k], junk);               /* Save new number      */
  186.       }
  187.  
  188.    /*
  189.     * *     Actual Search logic *
  190.     *
  191.     */
  192.    status_line (MSG_TXT(M_STARTING_SCAN));
  193.    for (;;)
  194.       {
  195.       l = 0;
  196.       for (k = 0; k < 10; k++)
  197.          {
  198.          if (scan_list[k] == NULL)
  199.             continue;
  200.          (void) strcpy (junk, scan_list[k]);
  201.          if (!isdigit (junk[0]) && junk[0] != '\"')
  202.             {
  203.             (*userfunc) (junk, &ls_addr);
  204.             if ((ls_addr.Net != 0xffff) && (ls_addr.Node != 0xffff) && (ls_addr.Zone != 0xffff))
  205.                {
  206.                (void) sprintf (junk, "%s", Full_Addr_Str (&ls_addr));
  207.                }
  208.             else continue;
  209.             }
  210.          if (strchr (junk, '/') != NULL)
  211.             {
  212.             if (!nodeproc (junk))
  213.                break;
  214.             (void) strcpy (junk, (char *) (newnodedes.PhoneNumber));
  215.             }
  216.          saved_baud = baud;
  217.          if (try_1_connect (junk))               /* Attempt to connect     */
  218.             {
  219.             status_line (MSG_TXT(M_CONNECTED_TO_ITEM), k + 1);
  220.             free(scan_list[k]);
  221.             scan_list[k] = NULL;
  222.             gong ();
  223.             return (1);
  224.             }
  225.          ++l;
  226.          baud = saved_baud;
  227.          program_baud ();
  228.          cur_baud = btypes[baud];
  229.          t1 = timerset (200);
  230.          while (!timeup (t1))                    /* pause for 2 seconds */
  231.             {
  232.             if (KEYPRESS ())
  233.                {
  234.                i = FOSSIL_CHAR () & 0xff;
  235.                if (i == ESC)                     /* Abort for ESCape    */
  236.                   {
  237.                   status_line (MSG_TXT(M_CONNECT_ABORTED));
  238.                   return (0);
  239.                   }
  240.                }
  241.             time_release ();
  242.             }
  243.          }
  244.       if (!l)
  245.          break;
  246.       }
  247.  
  248.    return (0);
  249. }
  250.  
  251. int LoadScanList (int number,int report_errors)
  252. {
  253.     int k, l;
  254.     FILE *ScanFile;
  255.  
  256.     (void) sprintf(junk,"%sBinkScan.LS%c",BINKpath, number + '0');
  257.     if ((ScanFile = fopen(junk, "rb")) == NULL)
  258.         {
  259.         if (report_errors)
  260.             {
  261.             (void) printf(MSG_TXT(M_UNABLE_TO_OPEN), junk);
  262.             (void) printf ("\n");
  263.             wait_for_keypress();
  264.             }
  265.         return(0);
  266.         }
  267.     for (k = 0; k < 10; k++)
  268.         {
  269.         if (fread(junk, 36, 1, ScanFile) != 1)
  270.             {
  271.             if (report_errors)
  272.                 {
  273.                 (void) printf(MSG_TXT(M_SET_READ_ERROR), number + 1);
  274.                 wait_for_keypress();
  275.                 }
  276.             (void) fclose(ScanFile);
  277.             return(0);
  278.             }
  279.  
  280.         if (scan_list[k] != NULL)
  281.             {
  282.             free(scan_list[k]);
  283.             scan_list[k] = NULL;
  284.             }
  285.  
  286.          l = (int) strlen (junk);
  287.          if (l)
  288.             {
  289.             if ((scan_list[k] = calloc( 1, (unsigned int) (++l))) == NULL) /* Allocate space    */
  290.                 {
  291.                 if (report_errors)
  292.                     {
  293.                     (void) printf(MSG_TXT(M_MEM_ERROR));
  294.                     wait_for_keypress();
  295.                     }
  296.                 (void) fclose(ScanFile);
  297.                 return(0);
  298.                 }
  299.  
  300.             (void) strcpy (scan_list[k], junk);               /* Save new number   */
  301.             }
  302.         }
  303.     l = fclose (ScanFile);
  304.     if (report_errors)
  305.         {
  306.         if (l)
  307.             (void) printf(MSG_TXT(M_SET_CLOSE_ERR), number + 1);
  308.         else
  309.             {
  310.             (void) printf(MSG_TXT(M_SET_LOADED), number + 1);
  311.             set_loaded = number + 1;
  312.             }
  313.         wait_for_keypress();
  314.         }
  315.     return(l);
  316. }
  317.  
  318. int SaveScanList(int number)
  319. {
  320.     int k, l;
  321.     FILE *ScanFile;
  322.  
  323.     (void) sprintf(junk,"%sBinkScan.LS%c",BINKpath, number + '0');
  324.     if ((ScanFile = fopen(junk, "wb")) == NULL)
  325.         {
  326.         (void) printf(MSG_TXT(M_UNABLE_TO_OPEN),junk);
  327.         (void) printf ("\n");
  328.         wait_for_keypress();
  329.         return(0);
  330.         }
  331.     for (k = 0; k < 10; k++)
  332.         {
  333.         for (l = 0; l < 36; l++)
  334.             junk[l] = '\0';
  335.  
  336.         if (scan_list[k] != NULL)
  337.             (void) strcpy(junk,scan_list[k]);
  338.  
  339.         if (fwrite(junk, 36, 1, ScanFile) != 1)
  340.             {
  341.             (void) printf(MSG_TXT(M_SET_WRITE_ERROR), number + 1);
  342.             wait_for_keypress();
  343.             (void) fclose(ScanFile);
  344.             return(0);
  345.             }
  346.         }
  347.  
  348.     l = fclose (ScanFile);
  349.     if (l)
  350.         (void) printf(MSG_TXT(M_SET_CLOSE_ERR), number + 1);
  351.     else
  352.         {
  353.         (void) printf(MSG_TXT(M_SET_SAVED), number + 1);
  354.         set_loaded = number + 1;
  355.         }
  356.     wait_for_keypress();
  357.     return(l);
  358. }
  359.  
  360. void wait_for_keypress(void)
  361. {
  362.     (void) printf("%s\n", MSG_TXT(M_PRESS_ENTER));
  363.     while (!KEYPRESS ())
  364.         time_release ();
  365.     (void) FOSSIL_CHAR ();
  366. }
  367.