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