home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / B_PROTO.C < prev    next >
C/C++ Source or Header  |  1991-08-15  |  8KB  |  168 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 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.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. #include <stdio.h>
  47. #include <signal.h>
  48. #include <ctype.h>
  49. #include <conio.h>
  50. #include <string.h>
  51. #include <process.h>
  52. #include <stdlib.h>
  53. #include <errno.h>
  54.  
  55. #ifdef __TURBOC__
  56. #include <alloc.h>
  57. #else
  58. #include <malloc.h>
  59. #endif
  60.  
  61. #include "com.h"
  62. #include "xfer.h"
  63. #include "zmodem.h"
  64. #include "keybd.h"
  65. #include "sbuf.h"
  66. #include "sched.h"
  67. #include "externs.h"
  68. #include "prototyp.h"
  69.  
  70. void do_extern (cmd, prot, name)
  71. char *cmd;                                       /* "Get" or "Send"     */
  72. int  prot;                                       /* 1st letter of proto */
  73. char *name;                                      /* Name of file        */
  74. {
  75.    int j;
  76.    struct baud_str *i;
  77.    char junk[100];
  78.    char *c, *p, *m;
  79.    FILE *ctlfile;
  80.  
  81.    for (j = 0; j < 100; j++)                     /* Make sure it's all  */
  82.       junk[j] = '\0';                            /* zeroes...           */
  83.  
  84.    for (j = 0; j < 5; j++)
  85.       {
  86.       if (protos[j].first_char == (char) prot)
  87.          break;
  88.       }
  89.    j = protos[j].entry;
  90.    c = m = protocols[j];
  91.    p = NULL;
  92.    while (*m)                                    /* Until end of string */
  93.       {
  94.       if ((*m == '\\') || (*m == ':'))           /* Look for last path  */
  95.          p = m;                                  /* Delimiter           */
  96.       m++;
  97.       }
  98.    m = &junk[0];
  99.    /* It doesn't pay to be too smart here. Dots can appear in dir names   */
  100.    while (c != p)                                /* Copy to last '\'    */
  101.       *m++ = *c++;
  102.    while (*c != '.')                             /* Then to the dot     */
  103.       *m++ = *c++;
  104.    (void) strcat (&junk[0], ".ctl");                    /* Then add extension  */
  105.  
  106.    /*
  107.     * At this point we have the Control File name in (junk), Now let's open
  108.     * the file and put our good stuff in there. 
  109.     */
  110.  
  111.    (void) unlink (junk);                                /* Delete old copies   */
  112.    if ((ctlfile = fopen (junk, "at")) == NULL)   /* Try to open it      */
  113.       {
  114.       status_line (msgtxt[M_NO_CTL_FILE], junk);
  115.       return;
  116.       }
  117.  
  118.    (void) fprintf (ctlfile, "Port %d\n", (port_ptr + 1));      /* Port n              */
  119.    if (lock_baud && (cur_baud >= lock_baud))
  120.       i = &max_baud;
  121.    else i = &btypes[baud];
  122.  
  123.    (void) fprintf (ctlfile, "Modem %x %x %x %x %x\n",   /* All modem params    */
  124.          (port_ptr + 1), i->rate_value, handshake_mask, carrier_mask, i->rate_mask);
  125.    (void) fprintf (ctlfile, "Baud %u\n", i->rate_value);/* Baud Rate           */
  126.    (void) fprintf (ctlfile, "%s %s\n", cmd, name);      /* Actual command      */
  127.    (void) fclose (ctlfile);
  128.    /* The file is now written. Turn off everything. */
  129.  
  130.    if (!share)
  131.       MDM_DISABLE ();                            /* Turn off FOSSIL     */
  132.  
  133. #ifdef OS_2
  134. #ifdef Snoop
  135.    snoop_close();
  136. #endif /* Snoop */
  137. #endif /* OS_2  */
  138.  
  139.    if (status_log != NULL)
  140.       (void) fclose (status_log);                       /* Close status log    */
  141.  
  142.    /* We're all set. Build the command and execute it. */
  143.  
  144.    c = protocols[j];
  145.    (void) sprintf (e_input, "%s %s -p%d -b%u %s", c, c, (port_ptr + 1), i->rate_value, junk);
  146.    b_spawn (e_input);                            /* Execute command     */
  147.  
  148.    /* Back from external protocol. Turn it all back on. */
  149.  
  150.    if (Cominit (port_ptr) != 0x1954)             /* FOSSIL back on      */
  151.       {
  152.       (void) printf ("\n%s\n", msgtxt[M_FOSSIL_GONE]);
  153.       exit (1);
  154.       }
  155.  
  156.     come_back();            /* CML */
  157.  
  158.     /******* Code commented out by CML *******/
  159. //   if (status_log != NULL)                       /* Reopen status log   */
  160. //      {
  161. //      if ((status_log = fopen (log_name, "at")) == NULL)
  162. //         (void) printf ("\n%s\n", msgtxt[M_NO_LOGFILE]);
  163. //      }
  164.  
  165. //   MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  166. //   XON_ENABLE ();                                /* and reenable XON/XOF */
  167. }
  168.