home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / OS2 / BSRCP240.ZIP / B_BBS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-22  |  8.4 KB  |  300 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 BBS / UUCP Session Initiator                    */
  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. #define WAZOO_SECTION
  56. #define MATRIX_SECTION
  57.  
  58. #include "com.h"
  59. #include "xfer.h"
  60. #include "zmodem.h"
  61. #include "keybd.h"
  62. #include "sbuf.h"
  63. #include "sched.h"
  64. #include "externs.h"
  65. #include "prototyp.h"
  66.  
  67. void BBSexit ()
  68. {
  69.    int retval;
  70.    int xit = 0;
  71.    unsigned int baudrate;
  72.    char command[80];
  73.    FILE *bbsbatch;
  74.    long t1, t2;
  75.  
  76.    if (BBSnote != NULL)
  77.       {
  78.       (void) SendBanner ("\r\n");                /* Start with newline    */
  79.       (void) SendBanner (BBSnote);                 /* Tell user we're going */
  80.       (void) SendBanner ("\r\n");                /* End it with a newline */
  81.       }
  82.  
  83.    t1 = timerset (50);
  84.    t2 = timerset (400);
  85.  
  86.    /* Wait for output complete, 4 seconds, or carrier loss */
  87.  
  88.    while (!OUT_EMPTY () && !timeup (t2) && CARRIER)
  89.       ;
  90.  
  91.    /* Make sure we waited at least 1/2 second */
  92.    while (CARRIER && !timeup (t1))
  93.       ;
  94.  
  95.    /* Now if there is no carrier bag it */
  96.    if (!CARRIER)
  97.       {
  98.       status_line (msgtxt[M_NO_CARRIER]);
  99.       return;
  100.       }
  101.  
  102.    ++hist.bbs_calls;
  103.    if (un_attended && fullscreen)
  104.       {
  105.       sb_move (historywin, HIST_BBS_ROW, HIST_COL);
  106.       (void) sprintf (junk, "%d/%d", hist.bbs_calls, hist.mail_calls);
  107.       sb_puts (historywin, (unsigned char *) junk);
  108.         }
  109.  
  110. #ifndef OS_2
  111.    if (lock_baud && (cur_baud >= lock_baud))
  112.       baudrate = max_baud.rate_value;
  113.    else baudrate = btypes[baud].rate_value;
  114. #else
  115.    baudrate = btypes[baud].rate_value;
  116. #endif
  117.  
  118.    if (strnicmp (BBSopt, "batch", 5) == 0)       /* if BBS flag is "batch" */
  119.       {
  120. #ifndef OS_2
  121.       (void) strcpy (command, "BBSBATCH.BAT");          /* Batch file name        */
  122. #else
  123.       (void) strcpy (command, "BBSBATCH.CMD");          /* Batch file name        */
  124. #endif
  125.       (void) unlink (command);                            /* Delete old copies      */
  126.       if ((bbsbatch = fopen (command, "wt")) == NULL)   /* Try to open it  */
  127.          {
  128.          (void) got_error (msgtxt[M_OPEN_MSG], command);
  129.          return;
  130.          }
  131.       errno = 0;
  132. #ifndef OS_2
  133.       (void) fprintf (bbsbatch, "SPAWNBBS %u %d %d %s\n",
  134.                baudrate, port_ptr + 1, time_to_next (1), mdm_reliable);
  135. #else
  136.       (void) fprintf (bbsbatch, "SPAWNBBS %u %d %d %s\n",
  137.                baudrate, hfComHandle, time_to_next (1), mdm_reliable);
  138. #endif
  139.       (void) fclose (bbsbatch);
  140.       xit = 1;
  141.       }
  142.  
  143.    if ((strnicmp (BBSopt, "exit", 4) == 0) || (xit))    /* "exit" or "batch" ??   */
  144.       {
  145.       retval = (int) (baudrate / 100);
  146.       status_line (msgtxt[M_BBS_EXIT], retval);
  147.       if (vfossil_installed)
  148.          vfossil_close ();
  149.  
  150.       if (!share)                                 /* Turn off FOSSIL,       */
  151.          MDM_DISABLE ();                         /* if need be               */
  152.       write_sched ();
  153.       exit (retval);                             /* and exit with error    */
  154.       }
  155.  
  156.    if (strnicmp (BBSopt, "spawn", 5) == 0)       /* if BBS flag is "spawn" */
  157.       {
  158.       status_line (msgtxt[M_BBS_SPAWN]);
  159.       gotoxy (0, SB_ROWS);
  160. #ifndef OS_2
  161.       (void) sprintf (command, "SPAWNBBS %u %d %d %s",
  162.                baudrate, port_ptr + 1, time_to_next (1), mdm_reliable);
  163. #else
  164.       (void) sprintf (command, "SPAWNBBS %u %d %d %s",
  165.                baudrate, hfComHandle, time_to_next (1), mdm_reliable);
  166. #endif
  167.       close_up ();
  168.  
  169.       /* Run the BBS */
  170.       b_spawn (command);
  171.  
  172.       come_back ();
  173.       status_line (msgtxt[M_BBS_RETURN]);
  174.       }
  175. }
  176.  
  177. void close_up ()
  178. {
  179.    if (!share)
  180.        MDM_DISABLE ();
  181.  
  182.    vfossil_close ();
  183.  
  184.    /* Close the log file */
  185.    if (status_log != NULL)
  186.       (void) fclose (status_log);
  187. #ifdef OS_2
  188. #ifdef Snoop
  189.    snoop_close();
  190. #endif /* Snoop */
  191. #endif /* OS_2    */
  192. }
  193.  
  194. void come_back ()
  195. {
  196. #ifdef OS_2
  197. #ifdef Snoop
  198.    snoop_open(NULL);
  199. #endif /* Snoop */
  200. #endif /* OS_2    */
  201.  
  202.    /* Re-enable ourselves */
  203.    if (Cominit (port_ptr) != 0x1954)
  204.       {
  205.       (void) printf ("\n%s\n", msgtxt[M_FOSSIL_GONE]);
  206.       exit (1);
  207.       }
  208.  
  209.    if (status_log != NULL)
  210.       {
  211.       if ((status_log = fopen (log_name, "at")) == NULL)
  212.          {
  213.          (void) printf ("\n%s\n", msgtxt[M_NO_LOGFILE]);
  214.          }
  215.       }
  216.  
  217.    MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  218.    vfossil_init ();
  219.    if (fullscreen && un_attended)
  220.       {
  221.       screen_clear ();
  222.       sb_dirty ();
  223.       opening_banner ();
  224.       mailer_banner ();
  225.       sb_show ();
  226.       }
  227. }
  228.  
  229.  
  230. void UUCPexit (n)
  231. int n;           /* UUCP Errorlevel value */
  232. {
  233.    unsigned int baudrate;
  234.    char command[80];
  235.    FILE *mailbatch;
  236.    long t1, t2, timerset ();
  237.  
  238.    if (MAILnote != NULL)
  239.       {
  240.       (void) SendBanner ("\r\n");                /* Start with newline */
  241.       (void) SendBanner (MAILnote);              /* Say it's mail time */
  242.       (void) SendBanner ("\r\n");                /* End with a newline */
  243.       }
  244.  
  245.    t1 = timerset (50);
  246.    t2 = timerset (400);
  247.  
  248.    /* Wait for output complete, 4 seconds, or carrier loss */
  249.  
  250.    while (!OUT_EMPTY () && !timeup (t2) && CARRIER)
  251.       ;
  252.  
  253.    /* Make sure we waited at least 1/2 second */
  254.    while (CARRIER && !timeup (t1))
  255.       ;
  256.  
  257.    /* Now if there is no carrier bag it */
  258.    if (!CARRIER)
  259.       {
  260.       status_line (msgtxt[M_NO_CARRIER]);
  261.       return;
  262.       }
  263.  
  264.  
  265.    if (lock_baud && (cur_baud >= lock_baud))
  266.       baudrate = max_baud.rate_value;
  267.    else baudrate = btypes[baud].rate_value;
  268.  
  269. #ifndef OS_2
  270.   (void) strcpy (command, "MAILBAT.BAT");              /* Batch file name   */
  271. #else
  272.   (void) strcpy (command, "MAILBAT.CMD");              /* Batch file name   */
  273. #endif
  274.    (void) unlink (command);                             /* Delete old copies */
  275.    if ((mailbatch = fopen (command, "at")) == NULL) /* Try to open it */
  276.       {
  277.       (void) got_error (msgtxt[M_OPEN_MSG], command);
  278.       return;
  279.       }
  280. #ifndef OS_2
  281.    (void) fprintf (mailbatch, "EXTMAIL %u %d %d %d %s\n",
  282.             baudrate, port_ptr + 1, time_to_next (1), n, mdm_reliable);
  283. #else
  284.    (void) fprintf (mailbatch, "EXTMAIL %u %d %d %d %s\n",
  285.             baudrate, hfComHandle, time_to_next (1), n, mdm_reliable);
  286. #endif
  287.    (void) fclose (mailbatch);
  288.  
  289.    status_line (msgtxt[M_EXT_MAIL], n);
  290.  
  291.    if (vfossil_installed)
  292.       vfossil_close ();
  293.  
  294.    if (!share)                                     /* Turn off FOSSIL,          */
  295.       MDM_DISABLE ();                             /* if need be                  */
  296.  
  297.    write_sched ();                                 /* Save scheduler info       */
  298.    exit (n);                                     /* and exit with UUCP error  */
  299. }
  300.