home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / bts310b5 / bt.c < prev    next >
Text File  |  1993-08-04  |  19KB  |  549 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. #include <stdio.h>
  184. #include <signal.h>
  185. #include <ctype.h>
  186. #include <string.h>
  187.  
  188. #ifdef LATTICE
  189. #include <dos.h>
  190. #else
  191. #include <process.h>
  192. #endif
  193.  
  194. #include <stdlib.h>
  195.  
  196. #ifdef __TURBOC__
  197. #ifndef __TOS__
  198. #include <alloc.h>
  199. #endif
  200. #else
  201. #ifndef LATTICE
  202. #include <malloc.h>
  203. #endif
  204. #endif
  205.  
  206. #include "bink.h"
  207. #include "msgs.h"
  208. #include "sbuf.h"
  209. #include "vfossil.h"
  210. #include "com.h"
  211. #ifdef NEW
  212. #include "session.h"
  213. #endif
  214.  
  215. static void handler (int);
  216.  
  217. static struct parse_list DOS_commands[] = {
  218.     {  7, "noforce"        },
  219.     {  4, "mail"        },
  220.     {  5, "share"        },
  221.     {  5, "dynam"        },
  222.     { 10, "unattended"    },
  223.     {  6, "config"        },
  224.     {  4, "poll"        },
  225. #ifdef NEW
  226.     {  5, "batch"        },
  227.     {  7, "connect"     },
  228.     { 12, "nofullscreen"},
  229. #endif
  230.     {  0, NULL            }
  231. };
  232.  
  233. enum {
  234.     P_NONE,
  235.     P_NOFORCE,
  236.     P_MAIL,
  237.     P_SHARE,
  238.     P_DYNAM,
  239.     P_UNATTENDED,
  240.     P_CONFIG,
  241.     P_POLL,
  242.     P_BATCH,
  243.     P_CONNECT,
  244.     P_NOFULLSCREEN,
  245.     P_LAST
  246. } PARAMETERS;
  247.  
  248.  
  249. void main (int argc, char *argv[])
  250. {
  251.    int done;
  252.    char *envptr;
  253.    int mail_only = 0;                             /* if 1, do mail and exit       */
  254.    ADDR baddr;
  255.    long init_timer;
  256. #ifdef NEW
  257.        char *connectString = NULL;
  258. #endif
  259.  
  260.     load_language ();
  261.  
  262.     if (signalhandler)
  263.     {
  264.         if (signal(SIGINT, handler) == SIG_ERR)
  265.         {
  266.             fprintf(stderr, msgtxt[M_NO_SIGINT]);
  267.             return;
  268.         }
  269.         signal(SIGINT, SIG_IGN);
  270.     }
  271.     
  272.    (void) printf (ANNOUNCE);
  273.    (void) printf ("\n(C) Copyright 1987-90, Bit Bucket Software, Co. ALL RIGHTS RESERVED.\n\n");
  274. #ifdef ATARIST
  275.     printf("Atari ST conversion by STeVeN Green FidoNet 2:255/355, NeST 90:1004/1004\n");
  276.     printf("Features since 3.02a/Beta-8 by Joerg Spilker FidoNet 2:243/6207, NeST 90:4/0\n");
  277.     printf("Optimized RS232-Routines by Uwe Zerbe FidoNet 2:246/1414, NeST 90:400/203\n");
  278.     printf("Optimized ZModem and Janus-Routines by Stephan Slabihoud FidoNet 2:2401/103.6\n");
  279.     printf("Fax support by Helmut Neumann FidoNet 2:2405/6.9\n");
  280.     printf("ST/TT/Falcon support by Michael Ziegler FidoNet 2:246/170.5\n");
  281.     printf("RSVE support by Wolfgang Zweygart, 2:246/1104\n");
  282.  
  283. #endif
  284. #if defined(LATTICE)
  285.     printf("Compiled with Lattice C5\n");
  286. #elif defined(__PUREC__)
  287.     printf("Compiled with Pure C V1.10\n");
  288. #elif defined(__TURBOC__)
  289.     printf("Compiled with Turbo C V%x.%02x\n",
  290.         __TURBOC__ / 0x100, __TURBOC__ & 0xff);
  291. #endif
  292. #ifdef DEBUG
  293.     printf("Debug Version, ");
  294. #endif
  295.     printf(ver_stuff);
  296.    (void) printf (msgtxt[M_SYSTEM_INITIALIZING]);
  297.    init_timer = timerset (200);
  298.  
  299.    b_initvars ();
  300.  
  301.    while (--argc > 0)
  302.       {
  303.       ++argv;
  304.  
  305.       switch (parse (argv[0], DOS_commands))
  306.          {
  307.          case P_NOFORCE:                                /* Noforce      */
  308.             noforce = 1;
  309.             break;
  310.  
  311.          case P_MAIL:                                /* Mail       */
  312.             ++mail_only;
  313.             break;
  314.  
  315.          case P_SHARE:                                /* Share      */
  316.             ++share;
  317.             break;
  318.  
  319.          case P_DYNAM:                                /* Dynam      */
  320.             ++redo_dynam;
  321.             break;
  322.  
  323.          case P_UNATTENDED:                                /* Unattended */
  324.             un_attended = 1;
  325.             command_line_un = 1;
  326.             break;
  327.  
  328.          case P_CONFIG:                                /* Config      */
  329.             config_name = argv[1];
  330.             --argc;
  331.             ++argv;
  332.             break;
  333.  
  334.          case P_POLL:                                /* Poll       */
  335.             if (parse_address(argv[1], &baddr))
  336.                {
  337.                doing_poll = 1;
  338.                }
  339.             --argc;
  340.             ++argv;
  341.             break;
  342.         
  343. #ifdef NEW
  344.          case P_BATCH:
  345.              ++batch_mode;
  346.              break;
  347.          case P_CONNECT:
  348.              if(argc > 1)
  349.              {
  350.                  connectString = argv[1];
  351.                  argv++;
  352.                  argc--;
  353.             }
  354.              break;
  355.          case P_NOFULLSCREEN:
  356.              fullscreen = 0;
  357.              break;
  358. #endif
  359.  
  360.          default:                                /* Not there  */
  361.             (void) printf (msgtxt[M_UNRECOGNIZED_OPTION], argv[0]);
  362.             exit_port();
  363.             exit (1);
  364.          }
  365.       }
  366.  
  367.    envptr = getenv ("BINKLEY");                  /* get path from environment */
  368.    if ((envptr != NULL)                          /* If there was one, and      */
  369.        && (!dexists (config_name)))              /* No BINKLEY.CFG locally,   */
  370.       {
  371.       BINKpath = malloc (strlen (envptr) + 2);     /* make room for new */
  372.       (void) strcpy (BINKpath, envptr);                 /* use BINKLEY as our path     */
  373.       (void) add_backslash (BINKpath);
  374.       }
  375.  
  376.    read_sched ();
  377.  
  378.     if (init_driver()<0x0102)
  379.         {    fprintf(stderr,"\n Wrong devicedriver. Try a newer one...\n");
  380.             return;
  381.         }
  382.  
  383.    parse_config ("Binkley.Evt");
  384.    parse_config (config_name);
  385.  
  386.     if (set_driver()<0x0102)
  387.         {    fprintf(stderr,"\n Wrong devicedriver. Try a newer one...\n");
  388.             return;
  389.         }
  390.  
  391.  
  392.    b_defaultvars ();
  393.  
  394.  
  395.    (void) LoadScanList (0,0);                        /* Get default scan list */
  396.  
  397.    /* We expect this to fail right away, but in order to keep the copyright
  398.       notice displayed long enough, we check anyway */
  399.  
  400.    while (!timeup (init_timer))
  401.         ;
  402.  
  403.    done = 0;
  404.  
  405.    vfossil_init();    
  406.    if (fullscreen)
  407.       b_sbinit ();
  408.  
  409.    if (mail_only)
  410.       {
  411.       doing_poll = 1;
  412. #ifdef MULTIPOINT
  413.         baddr = alias[0].ad;    /* Make up our Boss's address */
  414.         baddr.Point = 0;
  415. #else
  416.       baddr = boss_addr.ad;
  417. #endif        
  418.       }
  419.  
  420. #ifdef NEW
  421.  
  422. /*
  423.  * Batch Mode operation
  424.  *
  425.  * Carrier should be present when it is called
  426.  * It will do an inbound mail session and the exit with an errorlevel
  427.  *
  428.  *  0 = nomail
  429.  * -1 or 255 = Carrier was lost
  430.  *  Other values depend on what is set in the event file
  431.  */
  432.  
  433.     if (batch_mode)
  434.     {
  435.         FILE *tfile;
  436.         
  437.         un_attended = 1;
  438.           opening_banner ();
  439.           mailer_banner ();
  440.           if (fullscreen)
  441.         {
  442.             sb_fill (holdwin, ' ', colors.hold);
  443.              sb_move (holdwin, 2, 4);
  444.              sb_puts (holdwin, "Incoming Batch Mode");
  445.              sb_show ();
  446.         }
  447.  
  448.         if ((tfile = fopen ("BINKLEY.BAN", read_binary)) != NULL)
  449.         {
  450.             fread (BBSwelcome, 1, 1000, tfile);
  451.             fclose (tfile);
  452.         }
  453.         else
  454.             BBSwelcome[0] = '\0';
  455.  
  456.         find_event();
  457.  
  458.         if(connectString)
  459.             setModemValues(connectString);
  460.  
  461.           set_prior(4);                                    /* Always High */
  462.           if (!CARRIER)
  463.           {
  464.               status_line(":Batch Mode: No Carrier, exitting with level -1");
  465.               errl_exit(-1);                            /* No carrier */
  466.           }
  467.         b_session (0);                                     /* do a mail session      */
  468.         mdm_hangup ();                                     /* Make sure to hang up   */
  469.  
  470.         /*
  471.          * Exit with errorlevels depending on what happened
  472.          *  0 = No mail was received
  473.          * otherwise it will depend on the events errorlevel
  474.          */
  475.  
  476.         if (got_arcmail || got_packet || got_mail)
  477.             receive_exit ();
  478.         else
  479.             errl_exit(0);
  480.     }
  481.     else
  482. #endif
  483.  
  484.    if (doing_poll)
  485.       {
  486. #ifndef NEW    /* Let something else expand it later */
  487.       if (baddr.Zone == 0)
  488.          baddr.Zone = (int) alias[0].ad.Zone;
  489. #endif
  490.       un_attended = 1;
  491.       opening_banner ();
  492.       mailer_banner ();
  493.       if (fullscreen)
  494.          {
  495.          sb_fill (holdwin, ' ', colors.hold);
  496.          sb_move (holdwin, 2, 12);
  497.          sb_puts (holdwin, msgtxt[M_POLLING_COLON]);
  498.          (void) sprintf (junk, "%s", Pretty_Addr_Str (&baddr));
  499.          junk[28] = '\0';
  500.          sb_move (holdwin, 4, 16 - (int)strlen(junk) / 2);
  501.          sb_puts (holdwin, (unsigned char *) junk);
  502.          sb_show ();
  503.          }
  504.       set_prior(4);                                    /* Always High */
  505.       if (!CARRIER)
  506.          mdm_hangup ();
  507.       (void) do_mail (&baddr, 1);
  508.       set_prior(2);                                    /* Regular */
  509.       done = 1;
  510.       }
  511.    else if (!un_attended)
  512.       {
  513.       opening_banner ();
  514.       }
  515.  
  516.    while (!done)
  517.       {
  518.       if (un_attended)
  519.          {
  520.          done = unattended ();
  521.          un_attended = 0;
  522.          }
  523.       else
  524.          {
  525.          done = b_term ();
  526.          un_attended = 1;
  527.          }
  528.       }         
  529.  
  530.    b_exitproc ();
  531.      exit_port();
  532.    exit (1);
  533. }
  534.  
  535. static void handler(int sig)    /* Function called at system interrupt */
  536. {
  537.     signal(SIGINT, SIG_IGN);     /* Disallow CTRL + C during handler   */
  538.  
  539.     ctrlc_ctr++;
  540.  
  541.     signal(SIGINT, handler);     /* This is necessary so that the
  542.                                 ** next CTRL+C interrupt will call
  543.                                 ** "handler", since the DOS 3.x
  544.                                 ** operating system resets the
  545.                                 ** interrupt handler to the
  546.                                 ** system default after the
  547.                                 ** user-defined handler is called
  548.                                 */
  549. }