home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / BT.C < prev    next >
Text File  |  1991-10-17  |  21KB  |  434 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 originally written by Bob Hartman              */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*           BinkleyTerm "Main" Module: Terminal Emulation and              */
  17. /*                       File Transfer dispatching                          */
  18. /*                                                                          */
  19. /*                                                                          */
  20. /*                       BinkleyTerm Licensing Terms                        */
  21. /*                                                                          */
  22. /*                                                                          */
  23. /* (C) Copyright 1987-90 Bit Bucket Software Co., a Delaware Corporation.   */
  24. /* ALL RIGHTS RESERVED. COMMERCIAL DISTRIBUTION AND/OR USE PROHIBITED       */
  25. /* WITHOUT WRITTEN PERMISSION FROM BIT BUCKET SOFTWARE CO.                  */
  26. /*                                                                          */
  27. /* Non-Commercial distribution and/or use is permitted under the following  */
  28. /* terms:                                                                   */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* 1. You may copy and distribute verbatim copies of BinkleyTerm source,    */
  32. /* documentation, and executable code as you receive it, in any medium,     */
  33. /* provided that you conspicuously and appropriately publish on each copy a */
  34. /* valid copyright notice "(C) Copyright 1987-90, Bit Bucket Software Co."; */
  35. /* keep intact the notices on all files that refer to this License          */
  36. /* Agreement and to the absence of any warranty;  PROVIDE UNMODIFIED COPIES */
  37. /* OF THE DOCUMENTATION AS PROVIDED WITH THE PROGRAM; and give any other    */
  38. /* recipients of the BinkleyTerm program a copy of this License Agreement   */
  39. /* along with the program.  You may charge a distribution fee for the       */
  40. /* physical act of transferring a copy, but no more than is necessary to    */
  41. /* recover your actual costs incurred in the transfer. Under no             */
  42. /* circumstances is BinkleyTerm to be distributed in such a way as to be    */
  43. /* construed as "value added" in a sales transaction, such as, but not      */
  44. /* limited to, software bundled with a modem or CD-ROM software             */
  45. /* collections.                                                             */
  46. /*                                                                          */
  47. /* 2. You may modify your copy or copies of BinkleyTerm or any portion of   */
  48. /* it, and copy and distribute such modifications under the terms of        */
  49. /* Paragraph 1 above, provided that you also do the following:              */
  50. /*                                                                          */
  51. /*     a) cause the modified files to carry prominent notices stating       */
  52. /*     that you changed the files and the date of any change;               */
  53. /*                                                                          */
  54. /*     b) cause the executable code of such modified version to clearly     */
  55. /*     identify itself as such in the course of its normal operation;       */
  56. /*                                                                          */
  57. /*     c) if the modified version is not a "port", but operates in the      */
  58. /*     same hardware and/or software environment as the original            */
  59. /*     distribution, make the original version equally available,           */
  60. /*     clearly identifying same as the original, unmodified version;        */
  61. /*                                                                          */
  62. /*     d) cause the whole of any work that you distribute or publish,       */
  63. /*     that in whole or in part contains or is a derivative of              */
  64. /*     BinkleyTerm or any part thereof, to be licensed at no charge to      */
  65. /*     all third parties on terms identical to those contained in this      */
  66. /*     License Agreement (except that you may choose to grant more          */
  67. /*     extensive warranty protection to some or all third parties, at       */
  68. /*     your option); and                                                    */
  69. /*                                                                          */
  70. /*     e) send the complete source code modifications to Bit Bucket         */
  71. /*     Software Co. at one of the addresses listed below,  for the          */
  72. /*     purpose of evaluation for inclusion in future releases of            */
  73. /*     BinkleyTerm.  Should your source code be included in BinkleyTerm,    */
  74. /*     Bit Bucket Software Co. retains all rights for redistribution of     */
  75. /*     the code as part of BinkleyTerm and all derivative works, with       */
  76. /*     appropriate credit given to the author of the modification.          */
  77. /*                                                                          */
  78. /*     f) You may charge a distribution fee for the physical act of         */
  79. /*     transferring a copy, but no more than is necessary to recover        */
  80. /*     your actual costs incurred in the transfer, and you may at your      */
  81. /*     option offer warranty protection in exchange for a fee.              */
  82. /*                                                                          */
  83. /* 3. Mere aggregation of another unrelated program with this program and   */
  84. /* documentation (or derivative works) on a volume of a storage or          */
  85. /* distribution medium does not bring the other program under the scope of  */
  86. /* these terms.                                                             */
  87. /*                                                                          */
  88. /* 4. You may copy and distribute BinkleyTerm and its associated            */
  89. /* documentation (or a portion or derivative of it, under Paragraph 2) in   */
  90. /* object code or executable form under the terms of Paragraphs 1 and 2     */
  91. /* above provided that you also do one of the following:                    */
  92. /*                                                                          */
  93. /*     a) accompany it with the complete corresponding machine-readable     */
  94. /*     source code, which must be distributed under the terms of            */
  95. /*     Paragraphs 1 and 2 above; or,                                        */
  96. /*                                                                          */
  97. /*     b) accompany it with a written offer, valid for at least three       */
  98. /*     years, to give any third party free (except for a nominal            */
  99. /*     shipping charge) a complete machine-readable copy of the             */
  100. /*     corresponding source code, to be distributed under the terms of      */
  101. /*     Paragraphs 1 and 2 above; or,                                        */
  102. /*                                                                          */
  103. /*     c) accompany it with the information you received as to where        */
  104. /*     the corresponding source code may be obtained.  (This                */
  105. /*     alternative is allowed only for noncommercial distribution and       */
  106. /*     only if you received the program in object code or executable        */
  107. /*     form alone.)                                                         */
  108. /*                                                                          */
  109. /* For an executable file, complete source code means all the source code   */
  110. /* for all modules it contains; but, as a special exception, it need not    */
  111. /* include source code for modules which are standard libraries that        */
  112. /* accompany the operating system on which the executable file runs.        */
  113. /*                                                                          */
  114. /* 5. You may not copy, sublicense, distribute or transfer BinkleyTerm and  */
  115. /* its associated documentation  except as expressly provided under this    */
  116. /* License Agreement.  Any attempt otherwise to copy, sublicense,           */
  117. /* distribute or transfer BinkleyTerm is void and your rights to use the    */
  118. /* program under this License agreement shall be automatically terminated.  */
  119. /* However, parties who have received computer software programs from you   */
  120. /* with this License Agreement will not have their licenses terminated so   */
  121. /* long as such parties remain in full compliance, and notify Bit Bucket    */
  122. /* Software Co. of their intention to comply with this Agreement.           */
  123. /*                                                                          */
  124. /* 6. If you wish to incorporate parts of BinkleyTerm into other free       */
  125. /* programs whose distribution conditions are different, please contact     */
  126. /* Bit Bucket Software Co. at one of the addresses listed below.  We have   */
  127. /* not yet worked out a simple rule that can be stated here, but we will    */
  128. /* usually permit this.  We will be guided by the two goals of preserving   */
  129. /* the free status of all derivatives of our free software (as it pertains  */
  130. /* to Non-Commercial use as provided by this Agreement) and of promoting    */
  131. /* the sharing and reuse of software.                                       */
  132. /*                                                                          */
  133. /* 7. For the purposes of this document, "COMMERCIAL USE" is defined as     */
  134. /* operation of the software on four or more computers or data lines owned  */
  135. /* by the same for-profit organization. Any organization may operate this   */
  136. /* software under the terms of this Non-Commercial Agreement if operation   */
  137. /* is limited to three or less computers or data lines.                     */
  138. /*                                                                          */
  139. /*                                                                          */
  140. /*                                NO WARRANTY                               */
  141. /*                                                                          */
  142. /* BECAUSE BINKLEYTERM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY NO */
  143. /* WARRANTY.  EXCEPT WHEN OTHERWISE STATED IN WRITING, BIT BUCKET SOFTWARE  */
  144. /* CO. AND/OR OTHER PARTIES PROVIDE BINKLEYTERM "AS IS" WITHOUT WARRANTY OF */
  145. /* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,    */
  146. /* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR   */
  147. /* PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF           */
  148. /* BINKLEYTERM, AND THE ACCURACY OF ITS ASSOCIATED DOCUMENTATION, IS WITH   */
  149. /* YOU.  SHOULD BINKLEYTERM OR ITS ASSOCIATED DOCUMENTATION PROVE           */
  150. /* DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR     */
  151. /* CORRECTION.                                                              */
  152. /*                                                                          */
  153. /* IN NO EVENT WILL BIT BUCKET SOFTWARE CO. BE RESPONSIBLE IN ANY WAY FOR   */
  154. /* THE BEHAVIOR OF MODIFIED VERSIONS OF BINKLEYTERM. IN NO EVENT WILL       */
  155. /* BIT BUCKET SOFTWARE CO. AND/OR ANY OTHER PARTY WHO MAY MODIFY AND        */
  156. /* REDISTRIBUTE BINKLEYTERM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR        */
  157. /* DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL,      */
  158. /* INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY  */
  159. /* TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED */
  160. /* INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A FAILURE OF THE      */
  161. /* PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) BINKLEYTERM, EVEN IF YOU     */
  162. /* HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM   */
  163. /* BY ANY OTHER PARTY.                                                      */
  164. /*                                                                          */
  165. /*                                                                          */
  166. /* You can contact Bit Bucket Software Co. at any one of the following      */
  167. /* addresses:                                                               */
  168. /*                                                                          */
  169. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:132/491, 1:141/491  */
  170. /* P.O. Box 460398                AlterNet 7:491/0                          */
  171. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  172. /*                                Internet f491.n132.z1.fidonet.org         */
  173. /*                                                                          */
  174. /*                                                                          */
  175. /* Please feel free to contact us at any time to share your comments about  */
  176. /* our software and/or licensing policies.                                  */
  177. /*                                                                          */
  178. /* Our thanks to Richard Stallman and the Free Software Foundation, Inc.,   */
  179. /* for most of the wording of this License.                                 */
  180. /*                                                                          */
  181. /*--------------------------------------------------------------------------*/
  182.  
  183.  
  184. #include <stdio.h>
  185. #include <signal.h>
  186. #include <ctype.h>
  187. #include <conio.h>
  188. #include <string.h>
  189. #include <process.h>
  190. #include <stdlib.h>
  191. #ifdef OS_2
  192.     #define INCL_DOSSIGNALS
  193.     #include <os2.h>
  194. #endif
  195.  
  196. #ifdef __TURBOC__
  197.     #include <alloc.h>
  198. #else
  199.     #include <malloc.h>
  200. #endif
  201.  
  202. #include "com.h"
  203. #include "xfer.h"
  204. #include "zmodem.h"
  205. #include "keybd.h"
  206. #include "sbuf.h"
  207. #include "sched.h"
  208. #include "externs.h"
  209. #include "prototyp.h"
  210.  
  211. void handler(void);
  212. extern int start_timer(void);            /* CML starts timer thread */
  213. extern int leave_port;                    /* CML */
  214.  
  215.  
  216.  
  217. void main (argc, argv)
  218. int argc;
  219. char *argv[];
  220. {
  221.    int done;
  222.    char *envptr;
  223.    int mail_only = 0;                            /* if 1, do mail and exit     */
  224.    ADDR baddr;
  225.    long init_timer;
  226. #ifdef OS_2
  227.     PFNSIGHANDLER prev_ctrlc;
  228.     USHORT prev_action;
  229. #endif
  230.  
  231.  
  232.     load_language ();
  233.  
  234. #if !defined(__TURBOC__) && !defined(OS_2)
  235.     if (signal(SIGINT,handler) == SIG_ERR)
  236.        {
  237.        fprintf(stderr,msgtxt[M_NO_SIGINT]);
  238.        exit(1);
  239.        }
  240.    (void) signal (SIGINT, SIG_IGN);
  241. #endif
  242.  
  243. #ifdef OS_2
  244.     DosSetSigHandler(NULL,&prev_ctrlc,&prev_action,SIGA_IGNORE,SIG_CTRLC);
  245.     DosSetSigHandler(NULL,&prev_ctrlc,&prev_action,SIGA_IGNORE,SIG_CTRLBREAK);
  246. #endif
  247.  
  248.     fprintf(stderr,ANNOUNCE);
  249.     fprintf(stderr,"\nCopyright (c) 1987-90, Bit Bucket Software, Co. ALL RIGHTS RESERVED.\n");
  250.     fprintf(stderr,"    Subversion modifications by Chris Laforet Software.\n");
  251.     fprintf(stderr,"    Changes copyright (c) 1991 and released into the public domain.\n\n");
  252.     fprintf(stderr,msgtxt[M_SYSTEM_INITIALIZING]);
  253.  
  254.    b_initvars ();
  255.  
  256. #ifdef OS_2
  257.     if (_osmajor == 10 && _osminor < 20)        /* if OS/2 version less than 1.20 make it timecritical */
  258.         {
  259.         fprintf(stderr,"Sorry: This version of Binkleyterm-OS/2 requires OS/2 v 1.2 or later!\n\n");
  260.         exit(1);
  261.         }
  262.  
  263.     fprintf(stderr,"Starting timer thread....\n");
  264.     if (!start_timer())
  265.         {
  266.         fprintf(stderr,"Fatal Error: Unable to start timer thread!\n\n");        /* CML -- this is mine */
  267.         exit(1);
  268.         }
  269.  
  270.     fprintf(stderr,"Starting communications threads....\n");
  271.     if (!start_ringthread())
  272.         {
  273.         fprintf(stderr,"Fatal Error: Unable to start communications threads!\n\n");        /* CML -- this is mine */
  274.         exit(1);
  275.         }
  276. #endif
  277.  
  278.    init_timer = timerset(200);            /* CML -- this must follow start_timer()! */
  279.  
  280.    while (--argc)
  281.       {
  282.       ++argv;
  283.  
  284.       switch (parse(argv[0],DOS_commands))
  285.          {
  286.          case 1:                                /* Noforce    */
  287.             noforce = 1;
  288.             break;
  289.  
  290.          case 2:                                /* Mail       */
  291.             ++mail_only;
  292.             break;
  293.  
  294.          case 3:                                /* Share      */
  295.             ++share;
  296.             break;
  297.  
  298.          case 4:                                /* Dynam      */
  299.             ++redo_dynam;
  300.             break;
  301.  
  302.          case 5:                                /* Unattended */
  303.             un_attended = 1;
  304.             command_line_un = 1;
  305.             break;
  306.  
  307.          case 6:                                /* Config     */
  308.             config_name = argv[1];
  309.             --argc;
  310.             ++argv;
  311.             break;
  312.  
  313.          case 7:                                /* Poll       */
  314.             if (parse_address (argv[1], &baddr))
  315.                {
  316.                doing_poll = 1;
  317.                }
  318.             --argc;
  319.             ++argv;
  320.             break;
  321.  
  322. #ifdef OS_2
  323.         case 8:                                    /* LeavePort */
  324.             ++leave_port;
  325.             break;
  326. #endif
  327.  
  328.          default:                               /* Not there  */
  329.             (void) printf (msgtxt[M_UNRECOGNIZED_OPTION], argv[0]);
  330.             exit (1);
  331.          }
  332.       }
  333.  
  334.    envptr = getenv ("BINKLEY");                  /* get path from environment */
  335.    if ((envptr != NULL)                          /* If there was one, and     */
  336.        && (!dexists (config_name)))              /* No BINKLEY.CFG locally,   */
  337.       {
  338.       BINKpath = malloc (strlen (envptr) + 2);   /* make room for new */
  339.       (void) strcpy (BINKpath, envptr);                 /* use BINKLEY as our path   */
  340.       (void) add_backslash (BINKpath);
  341.       }
  342.  
  343.    read_sched ();
  344.    parse_config ("Binkley.Evt");
  345.    parse_config (config_name);
  346.    b_defaultvars ();
  347.    (void) LoadScanList (0,0);                       /* Get default scan list */
  348.  
  349.    /* We expect this to fail right away, but in order to keep the copyright
  350.       notice displayed long enough, we check anyway */
  351.  
  352.    while (!timeup (init_timer))
  353.         time_release();                /* CML -- avoid blank polling loop */
  354.  
  355.    done = 0;
  356.  
  357.    if (fullscreen)
  358.       b_sbinit ();
  359.  
  360.    if (mail_only)
  361.       {
  362.       doing_poll = 1;
  363.       baddr = boss_addr;
  364.       }
  365.  
  366.    if (doing_poll)
  367.       {
  368.       if (baddr.Zone == 0)
  369.          baddr.Zone = (int) alias[0].Zone;
  370.       un_attended = 1;
  371.       opening_banner ();
  372.       mailer_banner ();
  373.       if (fullscreen)
  374.          {
  375.          sb_fill (holdwin, ' ', colors.hold);
  376.          sb_move (holdwin, 2, 12);
  377.          sb_puts (holdwin, msgtxt[M_POLLING_COLON]);
  378.          (void) sprintf (junk, "%s", Full_Addr_Str (&baddr));
  379.          junk[28] = '\0';
  380.          sb_move (holdwin, 4, 16 - strlen (junk) / 2);
  381.          sb_puts (holdwin, (unsigned char *) junk);
  382.          sb_show ();
  383.          }
  384.       set_prior(4);                                    /* Always High */
  385.       if (!CARRIER)
  386.          mdm_hangup ();
  387.       (void) do_mail (&baddr, 1);
  388.       set_prior(2);                                    /* Regular */
  389.       done = 1;
  390.       }
  391.    else if (!un_attended)
  392.       {
  393.       opening_banner ();
  394.       }
  395.  
  396.    while (!done)
  397.       {
  398.       if (un_attended)
  399.          {
  400.          done = unattended ();
  401.          un_attended = 0;
  402.          }
  403.       else
  404.          {
  405.          done = b_term ();
  406.          un_attended = 1;
  407.          }
  408.       }         
  409.  
  410.    b_exitproc ();
  411.  
  412.     exit(1);
  413.     }
  414.  
  415.  
  416. #if !defined(__TURBOC__) && !defined(OS_2)
  417. void handler(void)     /* Function called at system interrupt */
  418. {
  419.  
  420.     signal(SIGINT, SIG_IGN); /* Disallow CTRL + C during handler   */
  421.     ctrlc_ctr++;
  422.     signal(SIGINT,handler);     /* This is necessary so that the
  423.                                 ** next CTRL+C interrupt will call
  424.                                 ** "handler", since the DOS 3.x
  425.                                 ** operating system resets the
  426.                                 ** interrupt handler to the
  427.                                 ** system default after the
  428.                                 ** user-defined handler is called
  429.                                 */
  430.     return(0);
  431. }
  432. #endif
  433.  
  434.