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