home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / B_PROTO.C < prev    next >
Text File  |  1991-09-15  |  7KB  |  149 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 External Protocol Handler 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. #ifdef Snoop
  51. #include "snserver.h"
  52. extern HSNOOP hsnoop;
  53. #endif
  54.  
  55. void do_extern (char *cmd, int prot, char *name)
  56. {
  57.    int j;
  58.    struct baud_str *i;
  59.    char junk[100];
  60.    char *c, *p, *m;
  61.    FILE *ctlfile;
  62.  
  63.    for (j = 0; j < 100; j++)                     /* Make sure it's all  */
  64.       junk[j] = '\0';                            /* zeroes...           */
  65.  
  66.    for (j = 0; j < 5; j++)
  67.       {
  68.       if (protos[j].first_char == (char) prot)
  69.          break;
  70.       }
  71.    j = protos[j].entry;
  72.    c = m = protocols[j];
  73.    p = NULL;
  74.    while (*m)                                    /* Until end of string */
  75.       {
  76.       if ((*m == '\\') || (*m == ':'))           /* Look for last path  */
  77.          p = m;                                  /* Delimiter           */
  78.       m++;
  79.       }
  80.    m = &junk[0];
  81.    /* It doesn't pay to be too smart here. Dots can appear in dir names   */
  82.    while (c != p)                                /* Copy to last '\'    */
  83.       *m++ = *c++;
  84.    while (*c != '.')                             /* Then to the dot     */
  85.       *m++ = *c++;
  86.    (void) strcat (&junk[0], ".ctl");                    /* Then add extension  */
  87.  
  88.    /*
  89.     * At this point we have the Control File name in (junk), Now let's open
  90.     * the file and put our good stuff in there.
  91.     */
  92.  
  93.    (void) unlink (junk);                                /* Delete old copies   */
  94.    if ((ctlfile = fopen (junk, "at")) == NULL)   /* Try to open it      */
  95.       {
  96.       status_line (MSG_TXT(M_NO_CTL_FILE), junk);
  97.       return;
  98.       }
  99.  
  100.    (void) fprintf (ctlfile, "Port %d\n", (port_ptr + 1));      /* Port n              */
  101.    if (lock_baud && (cur_baud.rate_value >= (unsigned)lock_baud))
  102.       i = &max_baud;
  103.    else i = &btypes[baud];
  104.  
  105.    (void) fprintf (ctlfile, "Modem %x %x %x %x %x\n",   /* All modem params    */
  106.          hfComHandle, i->rate_value, handshake_mask, carrier_mask, i->rate_mask);
  107.    (void) fprintf (ctlfile, "Baud %u\n", i->rate_value);/* Baud Rate           */
  108.    (void) fprintf (ctlfile, "%s %s\n", cmd, name);      /* Actual command      */
  109.    (void) fclose (ctlfile);
  110.    /* The file is now written. Turn off everything. */
  111.  
  112.    if (!share)
  113.       MDM_DISABLE ();                            /* Turn off FOSSIL     */
  114.  
  115. #ifdef Snoop
  116.    if (hsnoop != (HSNOOP)NULL)
  117.       snoop_close();
  118. #endif /* Snoop */
  119.  
  120.    if (status_log != NULL)
  121.       (void) fclose (status_log);                       /* Close status log    */
  122.  
  123.    /* We're all set. Build the command and execute it. */
  124.  
  125.    c = protocols[j];
  126.    (void) sprintf (e_input, "%s %s -p%d -b%u %s", c, c, (port_ptr + 1), i->rate_value, junk);
  127.    b_spawn (e_input);                            /* Execute command     */
  128.  
  129.    /* Back from external protocol. Turn it all back on. */
  130.  
  131.    if (Cominit (port_ptr, buftmo) != 0x1954)     /* FOSSIL back on      */
  132.       {
  133.       (void) printf ("\n%s\n", MSG_TXT(M_FOSSIL_GONE));
  134.       exit (1);
  135.       }
  136.  
  137.    if (status_log != NULL)                       /* Reopen status log   */
  138.       {
  139.       if ((status_log = share_fopen (log_name, "at", DENY_WRITE)) == NULL)
  140.          {
  141.          (void) printf ("\n%s\n", MSG_TXT(M_NO_LOGFILE));
  142.          }
  143.       }
  144.  
  145.    program_baud ();
  146.    XON_ENABLE ();                                /* and reenable XON/XOF */
  147. }
  148. 
  149.