home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1996 October / PCO_10.ISO / filesbbs / bsrc_260.arj / SRC.ZIP / b_search.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-20  |  10.6 KB  |  382 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-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*               This module was written by Vince Perriello                 */
  13. /*                                                                          */
  14. /*                   BinkleyTerm Phone list Search Module                   */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. /* Include this file before any other includes or defines! */
  45.  
  46. #include "includes.h"
  47.  
  48. int SaveScanList (int);
  49. void wait_for_keypress (void);
  50.  
  51. int 
  52. list_search ()
  53. {
  54.     int saved_baud;
  55.     long t1;
  56.     int i, k, l;
  57.     int dirty;
  58.     ADDR ls_addr;
  59.     unsigned int kbd_input;
  60.  
  61.     static unsigned int save_chars[] =
  62.     {
  63.         SHF1, SHF2, SHF3, SHF4, SHF5,
  64.         SHF6, SHF7, SHF8, SHF9, SHF10
  65.     };
  66.  
  67.     static unsigned int load_chars[] =
  68.     {
  69.         ALTF1, ALTF2, ALTF3, ALTF4, ALTF5,
  70.         ALTF6, ALTF7, ALTF8, ALTF9, ALTF10
  71.     };
  72.  
  73.     static unsigned int command_chars[] =
  74.     {
  75.         PF1, PF2, PF3, PF4, PF5,
  76.         PF6, PF7, PF8, PF9, PF10
  77.     };
  78.  
  79.     /*
  80.     * *     Input the phone numbers we want to scan *
  81.     *
  82.     */
  83.  
  84.     dirty = 1;
  85.  
  86. /*
  87.  * Print out a null string in a nice way for unforgiving OS.
  88.  */
  89.  
  90. #define NICE_TEXT(n) (((n) == NULL) ? "(none)" : n)
  91.  
  92.     for (;;)
  93.     {
  94.         if (dirty)
  95.         {
  96.             screen_clear ();
  97.             (void) printf (MSG_TXT (M_PHONE_HELP));
  98.             (void) printf (MSG_TXT (M_PHONE_HELP2));
  99.             if (set_loaded)
  100.                 (void) printf (MSG_TXT (M_LAST_SET), set_loaded);
  101.             (void) printf (MSG_TXT (M_CURRENT_PHONES));
  102.             for (k = 0; k < 10; k += 2)
  103.             {
  104.                 (void) printf ("%2d: %35s %2d: %35s\n",
  105.                     k + 1,
  106.                     NICE_TEXT (scan_list[k]),
  107.                     k + 2,
  108.                     NICE_TEXT (scan_list[k + 1]));
  109.             }
  110.             (void) printf (MSG_TXT (M_INPUT_COMMAND));
  111.             dirty = 0;
  112.         }
  113.  
  114.         while (!KEYPRESS ())
  115.             time_release ();
  116.         kbd_input = FOSSIL_CHAR ();
  117.  
  118.         if (((kbd_input & 0xff) == '\n') || ((kbd_input & 0xff) == '\r'))
  119.             break;
  120.  
  121.         if ((kbd_input & 0xff) == ESC)
  122.             return (0);
  123.  
  124.         for (k = 0; k < 10; k++)
  125.         {
  126.             if (kbd_input == save_chars[k])            /* Save into a set?     */
  127.             {
  128.                 (void) SaveScanList (k);            /* Yes, do it           */
  129.                 dirty = 1;                            /* Force redisplay      */
  130.                 k = 10;                                /* Then fool the logic  */
  131.                 break;
  132.             }
  133.  
  134.             if (kbd_input == load_chars[k])            /* Load from a set?     */
  135.             {
  136.                 (void) LoadScanList (k, 1);            /* Yes, do it           */
  137.                 dirty = 1;                            /* Force redisplay      */
  138.                 k = 10;                                /* Then fool the logic  */
  139.                 break;
  140.             }
  141.  
  142.             if (kbd_input == command_chars[k])        /* Plain old Fkey?      */
  143.                 break;                                /* Yup, get out now     */
  144.         }
  145.  
  146.         if (k == 10)                                /* Not a function key   */
  147.         {
  148.             k = (kbd_input & 0xff) - '0';            /* Convert from digit   */
  149.             if ((k < 0) || (k > 9))                    /* Was it a digit?      */
  150.                 continue;                            /* No, throw char out   */
  151.             if (!k)                                    /* Is it a zero?        */
  152.                 k = 9;                                /* That's 9 to us       */
  153.             else
  154.                 --k;                                /* Else make zero-rel   */
  155.         }
  156.  
  157.         (void) printf (MSG_TXT (M_ELEMENT_CHOSEN), k + 1);
  158.         if (scan_list[k] != NULL)
  159.         {
  160.             (void) printf (MSG_TXT (M_CURRENTLY_CONTAINS), scan_list[k]);
  161.             (void) printf (MSG_TXT (M_PHONE_HELP3));
  162.         }
  163.         else
  164.         {
  165.             (void) printf (MSG_TXT (M_PHONE_HELP4));
  166.         }
  167.         (void) gets (junk);                            /* Get user's input     */
  168.         ++dirty;                                    /* Always redisplay     */
  169.         if ((l = (int) strlen (junk)) == 0)            /* If nothing there,    */
  170.             continue;                                /* move along           */
  171.  
  172.         if (l == 1 && *junk == ' ')                    /* If just a space...   */
  173.         {
  174.             if (scan_list[k] != NULL)                /* Delete old number    */
  175.                 free (scan_list[k]);
  176.             scan_list[k] = NULL;                    /* Clean up the ref     */
  177.             continue;                                /* End this iteration   */
  178.         }
  179.  
  180.         /* Get rid of old num if any */
  181.  
  182.         if (scan_list[k] != NULL)
  183.         {
  184.             free (scan_list[k]);
  185.         }
  186.     
  187.         /* Allocate space for new num */
  188.  
  189.         if ((scan_list[k] = calloc (1, (unsigned int) (++l))) == NULL)
  190.         {
  191.             (void) printf (MSG_TXT (M_MEM_ERROR));
  192.             return (0);                                /* Get out for error    */
  193.         }
  194.         (void) strcpy (scan_list[k], junk);            /* Save new number      */
  195.     }
  196.  
  197.    /*
  198.     * Actual Search logic *
  199.     *
  200.     */
  201.  
  202.     status_line (MSG_TXT (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.                 (*userfunc) (junk, &ls_addr);
  214.                 if ((ls_addr.Net != 0xffff) && (ls_addr.Node != 0xffff) && (ls_addr.Zone != 0xffff))
  215.                 {
  216.                     (void) sprintf (junk, "%s", Full_Addr_Str (&ls_addr));
  217.                 }
  218.                 else
  219.                     continue;
  220.             }
  221.             if (strchr (junk, '/') != NULL)
  222.             {
  223.                 if (!nodeproc (junk))
  224.                     break;
  225.                 (void) strcpy (junk, (char *) (newnodedes.PhoneNumber));
  226.             }
  227.             saved_baud = baud;
  228.             if (try_1_connect (junk))                /* Attempt to connect   */
  229.             {
  230.                 status_line (MSG_TXT (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.             program_baud ();
  239.             cur_baud = pbtypes[baud];
  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 (MSG_TXT (M_CONNECT_ABORTED));
  249.                         return (0);
  250.                     }
  251.                 }
  252.                 time_release ();
  253.             }
  254.         }
  255.         if (!l)
  256.             break;
  257.     }
  258.  
  259.     return (0);
  260. }
  261.  
  262. int 
  263. LoadScanList (int number, int report_errors)
  264. {
  265.     int k, l;
  266.     FILE *ScanFile;
  267.  
  268.     (void) sprintf (junk, "%sBinkScan.LS%c", BINKpath, number + '0');
  269.     if ((ScanFile = fopen (junk, read_binary)) == NULL)
  270.     {
  271.         if (report_errors)
  272.         {
  273.             (void) printf (MSG_TXT (M_UNABLE_TO_OPEN), junk);
  274.             (void) printf ("\n");
  275.             wait_for_keypress ();
  276.         }
  277.         return (0);
  278.     }
  279.     for (k = 0; k < 10; k++)
  280.     {
  281.         if (fread (junk, 36, 1, ScanFile) != 1)
  282.         {
  283.             if (report_errors)
  284.             {
  285.                 (void) printf (MSG_TXT (M_SET_READ_ERROR), number + 1);
  286.                 wait_for_keypress ();
  287.             }
  288.             (void) fclose (ScanFile);
  289.             return (0);
  290.         }
  291.  
  292.         if (scan_list[k] != NULL)
  293.         {
  294.             free (scan_list[k]);
  295.             scan_list[k] = NULL;
  296.         }
  297.  
  298.         l = (int) strlen (junk);
  299.         if (l)
  300.         {
  301.             if ((scan_list[k] = calloc (1, (unsigned int) (++l))) == NULL)    /* Allocate space    */
  302.             {
  303.                 if (report_errors)
  304.                 {
  305.                     (void) printf (MSG_TXT (M_MEM_ERROR));
  306.                     wait_for_keypress ();
  307.                 }
  308.                 (void) fclose (ScanFile);
  309.                 return (0);
  310.             }
  311.  
  312.             (void) strcpy (scan_list[k], junk);    /* Save new number   */
  313.         }
  314.     }
  315.     l = fclose (ScanFile);
  316.     if (report_errors)
  317.     {
  318.         if (l)
  319.             (void) printf (MSG_TXT (M_SET_CLOSE_ERR), number + 1);
  320.         else
  321.         {
  322.             (void) printf (MSG_TXT (M_SET_LOADED), number + 1);
  323.             set_loaded = number + 1;
  324.         }
  325.         wait_for_keypress ();
  326.     }
  327.     return (l);
  328. }
  329.  
  330. int 
  331. SaveScanList (int number)
  332. {
  333.     int k, l;
  334.     FILE *ScanFile;
  335.  
  336.     (void) sprintf (junk, "%sBinkScan.LS%c", BINKpath, number + '0');
  337.     if ((ScanFile = fopen (junk, write_binary)) == NULL)
  338.     {
  339.         (void) printf (MSG_TXT (M_UNABLE_TO_OPEN), junk);
  340.         (void) printf ("\n");
  341.         wait_for_keypress ();
  342.         return (0);
  343.     }
  344.     for (k = 0; k < 10; k++)
  345.     {
  346.         for (l = 0; l < 36; l++)
  347.             junk[l] = '\0';
  348.  
  349.         if (scan_list[k] != NULL)
  350.             (void) strcpy (junk, scan_list[k]);
  351.  
  352.         if (fwrite (junk, 36, 1, ScanFile) != 1)
  353.         {
  354.             (void) printf (MSG_TXT (M_SET_WRITE_ERROR), number + 1);
  355.             wait_for_keypress ();
  356.             (void) fclose (ScanFile);
  357.             return (0);
  358.         }
  359.     }
  360.  
  361.     l = fclose (ScanFile);
  362.     if (l)
  363.         (void) printf (MSG_TXT (M_SET_CLOSE_ERR), number + 1);
  364.     else
  365.     {
  366.         (void) printf (MSG_TXT (M_SET_SAVED), number + 1);
  367.         set_loaded = number + 1;
  368.     }
  369.     wait_for_keypress ();
  370.     return (l);
  371. }
  372.  
  373. void 
  374. wait_for_keypress (void)
  375. {
  376.     (void) printf ("%s\n", MSG_TXT (M_PRESS_ENTER));
  377.     while (!KEYPRESS ())
  378.         time_release ();
  379.     (void) FOSSIL_CHAR ();
  380. }
  381.  
  382.