home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / B_INITVA.C < prev    next >
Text File  |  1991-09-15  |  15KB  |  444 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 originally written by Vince Perriello           */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                   BinkleyTerm Variable Initialization                    */
  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. void compile_externs (void);
  51. void fillin_defaults (struct secure *, struct secure *);
  52.  
  53. /**
  54.  ** b_initvars -- called before parse_config. Sets defaults that we want
  55.  ** to have set FIRST.
  56.  **/
  57.  
  58.  
  59. void b_initvars ()
  60. {
  61.     int k;
  62.     char *envp;
  63.     BINK_EVENT far *p;
  64.     BINK_EVENT foo;
  65.  
  66.     if ((envp = getenv ("TZ")) != NULL)
  67.         {
  68.         if ((saved_TZ = calloc( 1, 4 + strlen (envp))) != NULL)
  69.             {
  70.             (void) strcpy (saved_TZ, "TZ=");
  71.             (void) strcat (saved_TZ, envp);
  72.             }
  73.         }
  74.  
  75.     (void) putenv ("TZ=GMT0");
  76.     tzset ();
  77.  
  78.  
  79.     p = (BINK_EVENT far *) _fmalloc( 256 * sizeof (BINK_EVENT));
  80.     if (p == (BINK_EVENT far *) NULLGLOBALPTR)
  81.         {
  82.         (void) printf (MSG_TXT(M_BAD_EVENT_ALLOC));
  83.         exit (252);
  84.         }
  85.  
  86.     (void) memset ((char *)&foo, 0 , sizeof (foo));
  87.  
  88.     e_ptrs = p;
  89.  
  90.     for (k = 0; k < 256; k++)
  91.         {
  92.         *p++ = foo;
  93.         }
  94.  
  95.     (void) memset ((char *)&DEFAULT, 0 , sizeof (DEFAULT));
  96.  
  97.     KNOWN = DEFAULT;                            /* Does some of the work      */
  98.     KNOWN.rq_Limit = -1;
  99.     KNOWN.byte_Limit = -1L;
  100.     KNOWN.time_Limit = -1;
  101.     KNOWN.rq_Cum_Limit = -1;
  102.     KNOWN.byte_Cum_Limit = -1L;
  103.     KNOWN.time_Cum_Limit = -1L;
  104.  
  105.     PROT = KNOWN;                               /* Initially the same default */
  106.  
  107.     for (k = 0; k < 10; k++)                    /* Zero the phone scan list   */
  108.         {
  109.         scan_list[k] = NULL;
  110.         }
  111.  
  112.     for (k = 0; k < MAX_EXTERN; k++)            /* And the external protocols */
  113.         {
  114.         protocols[k] = NULL;
  115.         }
  116.  
  117.     for (k = 1; k < ALIAS_CNT; k++)             /* And the alias list         */
  118.         {
  119.         alias[k].Zone = alias[k].Net = alias[k].Node = alias[k].Point = 0;
  120.         alias[k].Domain = NULL;
  121.         }
  122.  
  123.     alias[0].Zone = 1;                          /* Make sure we have a zone   */
  124.     alias[0].Net = alias[0].Node = (unsigned) -1;  /* Default Fidonet address */
  125.     alias[0].Point = 0;
  126.     alias[0].Domain = NULL;
  127.  
  128. #ifdef Snoop
  129.     pipename[0] = '\0';                         /* Make sure we have no name  */
  130.     if (getenv("SNOOPPIPE") != NULL)
  131.        {
  132.        strcpy (pipename, getenv("SNOOPPIPE"));
  133.        snoop_open(pipename);
  134.        }
  135. #endif
  136.  
  137.     b_init ();
  138.  
  139.     baud = 2;
  140.     cur_baud = btypes[baud];
  141.     command_line_un = 0;
  142.  
  143.     (void) memset (&dta_str, 0, sizeof (dta_str));
  144.  
  145. }
  146.  
  147. /**
  148.  ** b_defaultvars -- called after all parse_config passes complete.
  149.  ** sets anything not handled by parse_config to default if we know it.
  150.  **/
  151.  
  152.  
  153. void b_defaultvars ()
  154. {
  155.     int i;
  156.     char *p;
  157.  
  158.     if (!fullscreen)
  159.         do_screen_blank = 0;
  160.  
  161.     if (version7)
  162.         nodelist_name = "NODEX";
  163.     else
  164.         nodelist_name = "NODELIST";
  165.  
  166.     if (modem_init == NULL)
  167.         modem_init = ctl_string ("|AT|");
  168.     if (modem_busy == NULL)
  169.         modem_busy = ctl_string ("|AT|");
  170.  
  171.     if (net_info == NULL)
  172.         net_info = ctl_string (".\\");
  173.  
  174.  
  175.     /* Set up "boss" and "point" addresses correctly if we can */
  176.  
  177.     if (boss_addr.Zone == 0)
  178.         boss_addr.Zone = alias[0].Zone;
  179.  
  180.     if (boss_addr.Net == 0)
  181.         {
  182.         boss_addr = alias[0];
  183.         boss_addr.Point = 0;
  184.         }
  185.  
  186.     if ((pvtnet >= 0) && (alias[0].Point != 0))
  187.         {
  188.         my_addr = boss_addr;
  189.         my_addr.Point  = alias[0].Point;
  190.         alias[0].Net   = (unsigned) pvtnet;
  191.         alias[0].Node  = alias[0].Point;
  192.         alias[0].Point = 0;
  193.         }
  194.     else
  195.         my_addr = alias[0];
  196.  
  197.     /* If we have the minimum information to do netmail, set the flag */
  198.  
  199.     if ((alias[0].Zone      != 0)
  200.     &&  (alias[0].Net       != 0)
  201.     &&  (system_name        != NULL)
  202.     &&  (sysop              != NULL)
  203.     &&  (hold_area          != NULL)
  204.     &&  (DEFAULT.sc_Inbound != NULL))
  205.         {
  206.         net_params = 1;
  207.         (void) flag_file (INITIALIZE, &alias[0], 0);
  208.         }
  209.  
  210.     if (system_name == NULL)
  211.         system_name = "";
  212.  
  213.     if (hold_area == NULL)
  214.         hold_area = ctl_string (".\\");
  215.  
  216.     if (DEFAULT.sc_Inbound == NULL)
  217.         DEFAULT.sc_Inbound = ctl_string (".\\");
  218.  
  219.     /* Make the "higher class" requests at least as well off as the
  220.         "lowest class"... */
  221.  
  222.     fillin_defaults (&KNOWN, &DEFAULT);
  223.     fillin_defaults (&PROT, &KNOWN);
  224.  
  225.     if (extern_index)
  226.         compile_externs ();                     /* generate extern_protocols  */
  227.  
  228.     if (!colors.calling && colors.hold)
  229.         colors.calling = (unsigned char)(((colors.hold & 0x70) >> 4) | ((colors.hold & 0x7) << 4) | (colors.hold & 0x8));
  230.  
  231.     if ((!colors.popup) && colors.call)
  232.         colors.popup = colors.call;
  233.  
  234.     first_block = 0;
  235.  
  236.     /* Make our domain first in the list */
  237.     if (my_addr.Domain != NULL)
  238.         {
  239.         for (i = 0; domain_name[i] != NULL; i++)
  240.             {
  241.             if (domain_name[i] == my_addr.Domain)
  242.                 break;
  243.             }
  244.  
  245.         if ((i > 0) && (domain_name[i] == my_addr.Domain))
  246.             {
  247.             p = domain_name[0];
  248.             domain_name[0] = domain_name[i];
  249.             domain_name[i] = p;
  250.             p = domain_nodelist[0];
  251.             domain_nodelist[0] = domain_nodelist[i];
  252.             domain_nodelist[i] = p;
  253.             p = domain_abbrev[0];
  254.             domain_abbrev[0] = domain_abbrev[i];
  255.             domain_abbrev[i] = p;
  256.             }
  257.         }
  258.  
  259.     set_prior(4);                                           /* Always High    */
  260.  
  261.     if (Cominit (port_ptr, buftmo) != 0x1954)
  262.         {
  263.         (void) printf (MSG_TXT(M_DRIVER_DEAD_1));
  264.         (void) printf (MSG_TXT(M_DRIVER_DEAD_2));
  265.         (void) printf (MSG_TXT(M_DRIVER_DEAD_3));
  266.         set_prior(2);                                       /* Regular        */
  267.         exit (1);
  268.         }
  269.  
  270.     i = un_attended;
  271.     un_attended = 0;
  272.  
  273.     (void) set_baud (max_baud.rate_value, 0);
  274.     un_attended = i;
  275.  
  276.     MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= (unsigned)lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  277.     RAISE_DTR ();
  278.     XON_ENABLE ();
  279.  
  280.     set_prior(2);                                           /* Regular        */
  281.  
  282.     Txbuf = Secbuf = (byte *) calloc( 1, WAZOOMAX + 16);
  283.     if (!Txbuf)
  284.         {
  285.         status_line (MSG_TXT(M_MEM_ERROR));
  286.         exit (2);
  287.         }
  288.  
  289. /*
  290.  * Pointing it to the middle of the buffer allows us to pop up
  291.  * file transfer windows if we choose to do so.
  292.  */
  293.  
  294.     popbuf = Secbuf + 1500;
  295.  
  296. /*
  297.  * Do a couple of system-related things.
  298.  * Maybe they shouldn't be here -- but better here than in BT.C.
  299.  *
  300.  * Because of some config verbs that affect its behavior, mtask_find
  301.  * MUST follow parse_config!
  302.  */
  303.  
  304.     fossil_ver ();
  305.     mtask_find ();
  306. }
  307.  
  308. void compile_externs ()
  309. {
  310.     register char *c;
  311.     register i;
  312.     char junk[100];
  313.     int j, k, l;
  314.     char *p;
  315.     char x;
  316.  
  317.     i = l = 0;                                      /* start at beginning     */
  318.     junk [0] = '\0';
  319.  
  320.     for (k = 0; protocols[k] != NULL; k++)          /* Total no. of protos    */
  321.         {
  322.         c = protocols[k];                           /* Point at filename      */
  323.         if (!dexists (c))                           /* Is it there?           */
  324.             {
  325.             (void) printf ("%s %s\n", MSG_TXT(M_NO_PROTOCOL), c);
  326.             continue;
  327.             }
  328.         p = NULL;
  329.         while (*c)                                  /* Until end of string    */
  330.             {
  331.             if ((*c == '\\') || (*c == ':'))        /* Look for last path     */
  332.                 p = c;                              /* Delimiter              */
  333.             c++;
  334.             }
  335.         if (strlen (p) < 3)                         /* If no name,            */
  336.             continue;                               /* No protocol...        */
  337.  
  338.         p++;                                        /* Point to the          */
  339.         x = (char) toupper (*p);                    /* First character      */
  340.         if (strchr (junk, x) != NULL)
  341.             {
  342.             (void) printf ("%s %s\n", MSG_TXT(M_DUP_PROTOCOL), c);
  343.             continue;
  344.             }
  345.  
  346.         protos[l].first_char = x;                   /* Makes lookup fast      */
  347.         protos[l++].entry = k;                      /* Now we know where      */
  348.  
  349.         junk[i++] = x;                              /* Store first char       */
  350.         junk[i++] = ')';                            /* Then a ')'             */
  351.         c = ++p;                                    /* Point to 2nd char      */
  352.         for (j = 0; j < 9; j++)                     /* Up to 9 chars more     */
  353.             {
  354.             if (*c != '.')                          /* If no comma yet,       */
  355.                 {
  356.                 junk[i++] = (char) tolower (*c);    /* store the char and     */
  357.                 ++c;                                /* bump the pointer       */
  358.                 }
  359.             else junk[i++] = ' ';                   /* otherwise pad it       */
  360.             }
  361.         junk[i++] = ' ';                            /* And one more space     */
  362.         junk[i] = '\0';                             /* Need for testing       */
  363.         }
  364.  
  365.     if (!i)                                         /* If we got none,        */
  366.         return;                                     /* Return now.            */
  367.  
  368.     i += 2;                                         /* Total for malloc       */
  369.     if ((extern_protocols = calloc( 1, (unsigned) i)) == NULL) /* Allocate string*/
  370.         return;                                     /* Return on failure      */
  371.     (void) strcpy (extern_protocols, junk);         /* Copy the string        */
  372.     return;                                         /* Back to caller         */
  373. }
  374.  
  375. void fillin_defaults (struct secure *higher, struct secure *lower)
  376. {
  377.     if (higher->time_Limit == -1)
  378.         higher->time_Limit = lower->time_Limit;
  379.     if (higher->byte_Limit == -1L)
  380.         higher->byte_Limit = lower->byte_Limit;
  381.     if (higher->rq_Limit == -1)
  382.         higher->rq_Limit = lower->rq_Limit;
  383.  
  384.     if (higher->time_Cum_Limit == -1)
  385.         higher->time_Cum_Limit = lower->time_Cum_Limit;
  386.     if (higher->byte_Cum_Limit == -1L)
  387.         higher->byte_Cum_Limit = lower->byte_Cum_Limit;
  388.     if (higher->rq_Cum_Limit == -1)
  389.         higher->rq_Cum_Limit = lower->rq_Cum_Limit;
  390.  
  391.     if (higher->rq_FILES == NULL)
  392.         higher->rq_FILES = lower->rq_FILES;
  393.     if (higher->rq_OKFile == NULL)
  394.         higher->rq_OKFile = lower->rq_OKFile;
  395.     if (higher->rq_About == NULL)
  396.         higher->rq_About = lower->rq_About;
  397.     if (higher->rq_Template == NULL)
  398.         higher->rq_Template = lower->rq_Template;
  399.     if (higher->sc_Inbound == NULL)
  400.         higher->sc_Inbound = lower->sc_Inbound;
  401. }
  402.  
  403.  
  404. /**
  405.  ** b_exitproc -- called by mainline to do exit processing.
  406.  **/
  407.  
  408. void b_exitproc ()
  409. {
  410.     if (command_line_un)
  411.         {
  412.         mdm_init (modem_busy);
  413.         exit_DTR ();
  414.         }
  415.  
  416.     vfossil_cursor (1);
  417.  
  418.     while (KEYPRESS ())
  419.         {
  420.         (void) FOSSIL_CHAR ();
  421.         }
  422.  
  423. #ifdef MILQ
  424.     SB_ROWS = 24;
  425. #endif
  426.  
  427.     gotoxy (0, SB_ROWS);
  428.     clear_eol ();
  429.     (void) printf (MSG_TXT(M_THANKS), ANNOUNCE);
  430.     clear_eol ();
  431.     (void) printf (MSG_TXT(M_ANOTHER_FINE_PRODUCT));
  432.  
  433.     if (vfossil_installed)
  434.         vfossil_close ();
  435.  
  436.     if (!share) {
  437.         set_prior(4);                                                /* Always High */
  438.         MDM_DISABLE ();
  439.         set_prior(2);                                                /* Regular */
  440.     }
  441. }
  442.  
  443. 
  444.