home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / MISC.C < prev    next >
C/C++ Source or Header  |  1991-10-17  |  38KB  |  1,657 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. /*                     with code from several authors                       */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*                Miscellaneous routines used by BinkleyTerm                */
  18. /*                                                                          */
  19. /*                                                                          */
  20. /*    For complete  details  of the licensing restrictions, please refer    */
  21. /*    to the License  agreement,  which  is published in its entirety in    */
  22. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.240.    */
  23. /*                                                                          */
  24. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  25. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  26. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  27. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  28. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  29. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  30. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  31. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  32. /*                                                                          */
  33. /*                                                                          */
  34. /* You can contact Bit Bucket Software Co. at any one of the following      */
  35. /* addresses:                                                               */
  36. /*                                                                          */
  37. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:132/491, 1:141/491  */
  38. /* P.O. Box 460398                AlterNet 7:491/0                          */
  39. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  40. /*                                Internet f491.n132.z1.fidonet.org         */
  41. /*                                                                          */
  42. /* Please feel free to contact us at any time to share your comments about  */
  43. /* our software and/or licensing policies.                                  */
  44. /*                                                                          */
  45. /*--------------------------------------------------------------------------*/
  46.  
  47. #include <dos.h>
  48. #include <time.h>
  49. #include <ctype.h>
  50. #include <stdio.h>
  51. #include <stdarg.h>
  52. #include <string.h>
  53. #include <conio.h>
  54. #include <process.h>
  55. #include <io.h>
  56. #include <stdlib.h>
  57. #include <fcntl.h>
  58.  
  59. #ifdef OS_2
  60. #define  INCL_DOSPROCESS
  61. #endif
  62.  
  63. #ifdef __TURBOC__
  64. #include "tc_utime.h"
  65. #include <mem.h>
  66. #else
  67. #include <sys/utime.h>
  68. #include <memory.h>
  69. #endif
  70.  
  71. #include "com.h"
  72. #include "xfer.h"
  73. #include "zmodem.h"
  74. #include "keybd.h"
  75. #include "sbuf.h"
  76. #include "sched.h"
  77. #include "vfossil.h"
  78. #include "externs.h"
  79. #include "prototyp.h"
  80. #include "defines.h"
  81.  
  82. #ifdef OS_2
  83. #ifdef Snoop
  84. #include "snserver.h"
  85. static HSNOOP hsnoop=(HSNOOP)NULL;
  86. #endif /* Snoop */
  87. #endif /* OS_2  */
  88.  
  89. static char newstring[200];
  90. static void fill_in_status (void);
  91. static int find_addr (char *, ADDR *, char *);
  92.  
  93.  
  94. extern unsigned int actual_baud;        /* CML */
  95.  
  96.  
  97.  
  98. int dexists (filename)
  99. char *filename;
  100. {
  101.    struct FILEINFO dta;
  102.  
  103.    return (!dfind (&dta, filename, 0));
  104. }
  105.  
  106. int dfind (dta, name, times)
  107. struct FILEINFO *dta;
  108. char *name;
  109. int times;
  110. {
  111. #ifndef OS_2
  112.    union REGS r;
  113.  
  114.    r.x.dx = (unsigned int) dta;
  115.    r.h.ah = 0x1a;
  116.    (void) intdos (&r, &r);
  117.    r.x.bx = 0;
  118.    r.x.cx = ~0x08;
  119.    r.x.dx = (unsigned int) name;
  120.    r.x.si = 0;
  121.    r.x.di = 0;
  122.    if (times == 0)
  123.       {
  124.       r.h.ah = 0x4e;
  125.       (void) intdos (&r, &r);
  126.       dta->nill = '\0';
  127.       if (r.x.cflag != 0)
  128.          {
  129.          dta->name[0] = '\0';
  130.          return (1);
  131.          }
  132.       return (0);
  133.       }
  134.    else
  135.       {
  136.       r.h.ah = 0x4f;
  137.       (void) intdos (&r, &r);
  138.       dta->nill = '\0';
  139.       if (r.x.cflag != 0)
  140.          {
  141.          dta->name[0] = '\0';
  142.          return (1);
  143.          }
  144.       return (0);
  145.       }
  146. #else
  147.    int retval;
  148.  
  149.    if (times == 0)
  150.    {
  151.       retval = dir_findfirst(name, 0x37, dta);
  152. /*    dta->nill = '\0'; */
  153.       if (retval)
  154.       {
  155. /*       dta->name[0] = '\0'; */
  156.          return (1);
  157.       }
  158.       else
  159.          return (0);
  160.    }
  161.    else
  162.    {
  163.       retval = dir_findnext(dta);
  164. /*    dta->nill = '\0'; */
  165.       if (retval)
  166.       {
  167. /*       dta->name[0] = '\0'; */
  168.          return (1);
  169.       }
  170.       else
  171.          return (0);
  172.    }
  173. #endif
  174. }
  175.  
  176. int set_baud (baudrate, log)
  177. unsigned baudrate;
  178. int log;
  179. {
  180.    register int i;
  181.  
  182.    if (baudrate > max_baud.rate_value)
  183.       baudrate = max_baud.rate_value;
  184.  
  185.    for (i = 0; btypes[i].rate_value; i++)
  186.       {
  187.       if (btypes[i].rate_value == baudrate)
  188.          {
  189.          if (baud != i)                          /* same as what we have?     */
  190.             {
  191.             if (log && !un_attended)
  192.                status_line (msgtxt[M_SETTING_BAUD], baudrate);
  193.             baud = i;                            /* need this for ALT-B       */
  194.             MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  195.             cur_baud = baudrate;
  196.             }
  197.  
  198.  
  199.          if (un_attended && fullscreen)
  200.             {
  201.             sb_move (settingswin, SET_PORT_ROW, SET_COL);
  202.             (void) sprintf (junk, "%-5u Com%d", baudrate, port_ptr + 1);
  203.             sb_puts (settingswin, (unsigned char *) junk);
  204.             sb_show ();
  205.             }
  206.          return (1);
  207.          }
  208.       }
  209.    return (0);
  210. }
  211.  
  212. static char *specifiers = "!*+:# >";
  213. static struct tm *tp;
  214. static time_t ltime;
  215.  
  216. void status_line (char *fmt,...)
  217. {
  218.    va_list arg_ptr;
  219.  
  220. #ifdef Snoop
  221.    char tmp[255];
  222. #define e_input tmp
  223. #endif /* Snoop */
  224.  
  225.    va_start (arg_ptr, fmt);
  226.    (void) vsprintf (e_input, fmt, arg_ptr);
  227.    (void) time (<ime);
  228.    tp = localtime (<ime);
  229.    if ((!fullscreen) || (!un_attended))
  230.       {
  231.       if ((e_input[0] != '>') || debugging_log)
  232.          {
  233.          (void) printf ("\n%c %02i %03s %02i:%02i:%02i BINK %s", e_input[0],
  234.              tp->tm_mday, mtext[tp->tm_mon], tp->tm_hour, tp->tm_min, tp->tm_sec,
  235.                   &e_input[1]);
  236.          }
  237.       }
  238.    else
  239.       {
  240.       if ((e_input[0] != '>') || debugging_log)
  241.          {
  242.          (void) sprintf (stat_line, stat_str, e_input[0],
  243.                   tp->tm_hour, tp->tm_min, tp->tm_sec, &e_input[1]);
  244.  
  245.          fill_in_status ();
  246.  
  247. #ifdef OS_2
  248. #ifdef Snoop
  249.          if(hsnoop)
  250.             SnoopWrite(hsnoop, stat_line);
  251. #endif /* Snoop */
  252. #endif /* OS_2  */
  253.          }
  254.       }
  255.    if ((status_log != NULL) &&
  256.        ((strchr (specifiers, e_input[0]) - strchr (specifiers, '!')) <= loglevel))
  257.       {
  258.       (void) fprintf (status_log, "%c %02i %s %02i:%02i:%02i BINK %s\n", e_input[0],
  259.           tp->tm_mday, mtext[tp->tm_mon], tp->tm_hour, tp->tm_min, tp->tm_sec,
  260.                &e_input[1]);
  261.       if (immed_update)
  262.          {
  263.          (void) fflush (status_log);
  264.          (void) real_flush (fileno (status_log));
  265.          need_update = 0;
  266.          }
  267.       else
  268.          {
  269.          need_update = 1;
  270.          }
  271.       }
  272.    va_end (arg_ptr);
  273. }
  274.  
  275. /*--------------------------------------------------------------------------*/
  276. /* THROUGHPUT                                                               */
  277. /* Print throughput message at end of transfer                              */
  278. /*--------------------------------------------------------------------------*/
  279. void throughput(opt, bytes)
  280. int opt;
  281. unsigned long bytes;
  282.     {
  283.     static long started = 0L;
  284.     static long elapsed;
  285.     static long cps;
  286.  
  287.     if (!opt)
  288.         started = time (NULL);
  289.     else if (started)
  290.         {
  291.         elapsed = time (NULL);
  292.         /* The next line tests for day wrap without the date rolling over */
  293.         if (elapsed < started)
  294.             elapsed += 86400L;
  295.         elapsed -= started;
  296.         if (elapsed == 0L)
  297.             elapsed = 1L;
  298.         cps = (long) (bytes / (unsigned long)elapsed);
  299.         if (lock_baud)                /* CML */
  300.             started = cps * 1000L / (long)actual_baud;
  301.         else 
  302.             started = cps * 1000L / (long)cur_baud;
  303.         status_line ((char *) msgtxt[M_CPS_MESSAGE], cps, bytes, started);
  304.         }
  305.     }                                                /* throughput */
  306.  
  307. static void fill_in_status ()
  308. {
  309.  
  310.    (void) time (<ime);
  311.    tp = localtime (<ime);
  312.    if (fullscreen)
  313.       {
  314.       sb_scrl (callwin, 1);
  315.       sb_move (callwin, SB_ROWS - 15, 2);
  316.       sb_puts (callwin, (unsigned char *) stat_line);
  317.       sb_move (settingswin, SET_TIME_ROW, SET_TIME_COL);
  318.       (void) sprintf (junk, "%s %s %02d @ %02d:%02d",
  319.                wkday[tp->tm_wday], mtext[tp->tm_mon], tp->tm_mday,
  320.                tp->tm_hour, tp->tm_min);
  321.       sb_puts (settingswin, (unsigned char *) junk);
  322.       sb_show ();
  323.       }
  324. }
  325.  
  326. void clear_statusline ()
  327. {
  328.    if (fullscreen)
  329.       sb_fillc (callwin, ' ');
  330. }
  331.  
  332. int got_error (string1, string2)
  333. char *string1, *string2;
  334. {
  335.  
  336. #ifdef __TURBOC__
  337. /*    Since TurboC doesn't handle errno correctly, zero it and ignore. */
  338.     errno = 0;
  339.    status_line ("%s, %s %s %s", msgtxt[M_ERROR], msgtxt[M_CANT], string1, string2);
  340. #else
  341.    if (errno == 0x18)
  342.       errno = 0;
  343.    if (errno != 0)
  344.       {
  345.       status_line ("%s %d, %s %s %s", msgtxt[M_ERROR], errno, msgtxt[M_CANT], string1, string2);
  346.       errno = 0;
  347.       return (1);
  348.       }
  349. #endif
  350.    return (0);
  351. }
  352.  
  353. void set_xy (string)
  354. char *string;
  355. {
  356.    WRITE_ANSI ('\r');
  357.    WRITE_ANSI ('\n');
  358.    scr_printf (string);
  359.    locate_x = wherex ();
  360.    locate_y = wherey ();
  361. }
  362.  
  363. void message (string)
  364. char *string;
  365. {
  366.    if (string != NULL)
  367.       {
  368.       status_line (" %s", string);
  369.       }
  370. }
  371.  
  372. void time_release ()
  373. {
  374.    if (need_update)
  375.       {
  376.       (void) fflush (status_log);
  377.       (void) real_flush (fileno (status_log));
  378.       need_update = 0;
  379.       }
  380.  
  381. #ifdef OS_2
  382.    DosSleep(15L);                        /* CML change 1L to 15L */
  383. #else
  384.  
  385.    dos_break_off ();                            /* Turn off ^C trapping */
  386.  
  387.    if (have_dv)
  388.       {
  389.       dv_pause ();
  390.       }
  391.     else if (have_mos)
  392.         {
  393.         mos_pause ();
  394.         }
  395.    else if (have_ddos)
  396.       {
  397.       ddos_pause ();
  398.       }
  399.    else if (have_tv)
  400.       {
  401.       tv_pause ();
  402.       }
  403.    else if (have_ml)
  404.       {
  405.       ml_pause ();
  406.       }
  407.     else
  408.         {
  409.         /* The idea for this code came from Holger Schurig */
  410.         msdos_pause ();
  411.         }
  412.  
  413. #endif /* OS_2 */
  414. }
  415.  
  416. char *fancy_str (string)
  417. char *string;
  418. {
  419.    register int flag = 0;
  420.    char *s;
  421.  
  422.    s = string;
  423.  
  424.    while (*string)
  425.       {
  426.       if (isalpha (*string))                     /* If alphabetic,     */
  427.          {
  428.          if (flag)                               /* already saw one?   */
  429.             *string = tolower (*string);         /* Yes, lowercase it  */
  430.          else
  431.             {
  432.             flag = 1;                            /* first one, flag it */
  433.             *string = toupper (*string);         /* Uppercase it       */
  434.             }
  435.          }
  436.       else /* if not alphabetic  */ flag = 0;    /* reset alpha flag   */
  437.       string++;
  438.       }
  439.  
  440.    return (s);
  441. }
  442.  
  443.  
  444.  
  445. void timer(interval)            /* CML modified to stop wasting CPU cycles */
  446. int interval;
  447.     {
  448. #ifndef OS_2
  449.     long timeout;
  450.  
  451.     timeout = timerset ((unsigned int) (interval * 10));
  452.     while (!timeup (timeout))
  453.         time_release ();
  454. #else
  455.     DosSleep((long)interval * 100L);
  456. #endif
  457.     }
  458.  
  459.  
  460.  
  461. void big_pause(secs)            /* CML modified to stop wasting CPU cycles */
  462. int secs;
  463.     {
  464.     long timeout;
  465.  
  466.     timeout = timerset ((unsigned int)(secs * 100));
  467.     while (!timeup (timeout))
  468.         {
  469.         if (CHAR_AVAIL ())
  470.             break;
  471.         time_release ();
  472.         }
  473.     }
  474.  
  475.  
  476. int com_getc(t)                /* CML modified to stop wasting CPU cycles */
  477. int t;
  478.     {
  479.     long t1;
  480.  
  481.     if (!CHAR_AVAIL ())
  482.         {
  483.         t1 = timerset ((unsigned int) (t * 100));
  484.         while (!CHAR_AVAIL ())
  485.             {
  486.             if (timeup (t1))
  487.                 return (EOF);
  488.  
  489.             time_release ();
  490.  
  491.             /** This should work because we only do TIMED_READ when we have carrier */
  492.             if (!CARRIER)
  493.                 return (EOF);
  494.             }
  495.         }
  496.     return ((int)(unsigned char)MODEM_IN());
  497.     }
  498.  
  499.  
  500.  
  501. /* Z F R E E -- Return total number of free bytes on drive specified */
  502. #ifdef OS_2
  503. long zfree (char *path)
  504. {
  505.    int drive;
  506.    FSALLOCATE dt;
  507.  
  508.    if (!path || !*path)
  509.       drive = 0;
  510.    else
  511.       drive = tolower (*path) - 'a' + 1;
  512.    DosQFSInfo (drive, 1, (char far *) &dt, sizeof (FSALLOCATE));
  513.    return ( dt.cSectorUnit * dt.cUnitAvail * dt.cbSector);
  514. }
  515.  
  516. #else /* OS_2 */
  517.  
  518. long zfree (drive)
  519. char *drive;
  520. {
  521.    union REGS r;
  522.  
  523.    unsigned char driveno;
  524.    long stat;
  525.  
  526.    if (drive[0] != '\0' && drive[1] == ':')
  527.       {
  528.       driveno = (unsigned char) (islower (*drive) ? toupper (*drive) : *drive);
  529.       driveno = (unsigned char) (driveno - 'A' + 1);
  530.       }
  531.    else driveno = 0;                             /* Default drive    */
  532.  
  533.    r.x.ax = 0x3600;                              /* get free space   */
  534.    r.h.dl = driveno;                             /* on this drive    */
  535.    (void) int86 (0x21, &r, &r);                         /* go do it      */
  536.  
  537.    if (r.x.ax == 0xffff)                         /* error return??   */
  538.       return (0);
  539.  
  540.    stat = (long) r.x.bx                          /* bx = clusters avail  */
  541.       * (long) r.x.ax                            /* ax = sectors/clust   */
  542.       * (long) r.x.cx;                           /* cx = bytes/sector    */
  543.  
  544.    return (stat);
  545.  
  546. }
  547.  
  548. #endif /* OS_2 */
  549.  
  550. void scr_printf (string)
  551. char *string;
  552. {
  553.    if (string != NULL)
  554. #ifdef OS_2
  555.       VioWrtTTY (string, (USHORT) strlen (string), (HVIO) 0L);
  556. #else
  557.       while (*string != 0)
  558.          WRITE_ANSI (*string++);
  559. #endif
  560. }
  561.  
  562. void send_can ()
  563. {
  564.    int i;
  565.  
  566.    CLEAR_OUTBOUND ();
  567.    CLEAR_INBOUND ();
  568.  
  569.    for (i = 0; i < 10; i++)
  570.       SENDBYTE (CAN);
  571.    for (i = 0; i < 10; i++)
  572.       SENDBYTE (BS);
  573. }
  574.  
  575. void invent_pkt_name (string)
  576. char string[];
  577.  
  578. {
  579.    struct tm *tp;
  580.    time_t ltime;
  581.  
  582.    (void) time (<ime);
  583.    tp = localtime (<ime);
  584.    (void) sprintf (string, "%02i%02i%02i%02i.pkt",
  585.             tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec);
  586. }
  587.  
  588. static char *suffixes[8] = {
  589.                             "SU", "MO", "TU", "WE", "TH", "FR", "SA", NULL
  590. };
  591.  
  592. int is_user (p)
  593. char *p;
  594. {
  595.    char *q, *r;
  596.    int i, j;
  597.  
  598.    if (cur_event < 0)
  599.       return (0);
  600.  
  601.    q = strchr (p, '.');
  602.    if (q != NULL)
  603.       {
  604.       ++q;
  605.       for (i = 0; i < 6; i++)
  606.          {
  607.          r = &(e_ptrs[cur_event]->err_extent[i][0]);
  608.          for (j = 0; j < 3; j++)
  609.             {
  610.             if ((tolower (q[j]) != tolower (r[j])) && (q[j] != '?'))
  611.                break;
  612.             }
  613.          if (j == 3)
  614.             user_exits[i] = 1;
  615.          }
  616.       }
  617.  
  618.    return (0);
  619. }
  620.  
  621. int is_arcmail (p, n)
  622. char *p;
  623. int n;
  624. {
  625.    int i;
  626.    char c[128];
  627.  
  628.    if (!isdigit (p[n]))
  629.       {
  630.       return (is_user (p));
  631.       }
  632.  
  633.    (void) strcpy (c, p);
  634.    (void) strupr (c);
  635.  
  636.    for (i = n - 11; i < n - 3; i++)
  637.       {
  638.       if ((!isdigit (c[i])) && ((c[i] > 'F') || (c[i] < 'A')))
  639.          return (is_user (p));
  640.       }
  641.  
  642.    for (i = 0; i < 7; i++)
  643.       {
  644.       if (strnicmp (&c[n - 2], suffixes[i], 2) == 0)
  645.          break;
  646.       }
  647.  
  648.    if (i >= 7)
  649.       {
  650.       return (is_user (p));
  651.       }
  652.  
  653.    got_arcmail = 1;
  654.    return (1);
  655. }
  656.  
  657. int get_number (target)
  658. char *target;
  659. {
  660.    ADDR gaddr;
  661.    int k;
  662.  
  663.    (void) fgets (target, 100, stdin);
  664.    k = (int) strlen (target);
  665.    if (k == 1)
  666.       return (0);
  667.    target[--k] = '\0';                           /* no '\n' */
  668.    if (!isdigit (target[0]) && target[0] != '\"')
  669.       {
  670.       fidouser (target, &gaddr);
  671.       if ((gaddr.Net != -1) && (gaddr.Node != -1) && (gaddr.Zone != -1))
  672.          {
  673.          sprintf (target, "%s", Full_Addr_Str (&gaddr));
  674.          }
  675.       else return (0);                           /* Gotta have addr */
  676.       }
  677.    return (1);
  678. }
  679.  
  680. void gong ()
  681. {
  682.    long t;
  683.    int i;
  684.  
  685.    if (!gong_allowed)
  686.       return;
  687.  
  688.    for (i = 0; i < 15; i++)
  689.       {
  690.       WRITE_ANSI ('\07');                        /* Bell code       */
  691.       t = timerset (100);                        /* 1 second        */
  692.       while (!timeup (t))
  693.          {
  694.          if (KEYPRESS ())                        /* If key pressed, */
  695.             {
  696.             (void) READKB ();                           /* Throw it away   */
  697.             return;                              /* And get out     */
  698.             }
  699.         time_release();            /* CML -- stop hogging my CPU! */
  700.          }
  701.       }
  702. }
  703.  
  704. char *skip_blanks (string)
  705. char *string;
  706. {
  707.    while (*string && isspace (*string))
  708.       ++string;
  709.    return (string);
  710. }
  711.  
  712. char *skip_to_blank (string)
  713. char *string;
  714. {
  715.    while (*string && (!isspace (*string)))
  716.       ++string;
  717.    return (string);
  718. }
  719.  
  720. #ifdef DEBUG
  721. void show_debug_name (string)
  722. char *string;
  723. {
  724.    int x, y;
  725.    static char *filler = "                           ";
  726.  
  727.    x = wherex ();
  728.    y = wherey ();
  729.    gotoxy (40, 0);
  730.    scr_printf (string);
  731.    scr_printf (&filler[strlen (string)]);
  732.    gotoxy (x, y);
  733. }
  734. #endif
  735.  
  736. int parse (input, list)
  737. char *input;
  738. struct parse_list list[];
  739.  
  740. {
  741.    int i;
  742.  
  743.    for (i = 0; list[i].p_length; i++)
  744.       {
  745.       if (strnicmp (input, list[i].p_string, (unsigned int) list[i].p_length) == 0)
  746.          return (++i);
  747.       }
  748.    return (-1);
  749. }
  750.  
  751. void change_prompt ()
  752. {
  753.    char *s;
  754.  
  755.    if (newstring[0])
  756.       {
  757.       (void) putenv (newstring);
  758.       return;
  759.       }
  760.  
  761.    (void) strcpy (newstring, "PROMPT=[");
  762.    (void) strcat (newstring, xfer_id);
  763. #ifdef OVERLAYS
  764.    (void) strcat (newstring, "-Overlay");
  765. #endif
  766.    (void) strcat (newstring, " Shell]$_");
  767.    s = getenv ("PROMPT");
  768.    if (s)
  769.       {
  770.       (void) strcat (newstring, s);
  771.       }
  772.    else
  773.       {
  774.       (void) strcat (newstring, "$P$G");
  775.       }
  776.  
  777.    (void) putenv (newstring);
  778. }
  779.  
  780. void update_files (t)
  781. int t;
  782. {
  783.    char s[10];
  784.  
  785.    if (un_attended && fullscreen)
  786.       {
  787.       if (t)
  788.          {
  789.          ++hist.files_out;
  790.          }
  791.       else
  792.          {
  793.          ++hist.files_in;
  794.          }
  795.  
  796.       sb_move (historywin, HIST_FILE_ROW, HIST_COL);
  797.       (void) sprintf (s, "%d/%d", hist.files_in, hist.files_out);
  798.       sb_puts (historywin, (unsigned char *) s);
  799.       sb_show ();
  800.       }
  801. }
  802.  
  803. static char *last_str[] = {
  804.                            "     None    ",
  805.                            "     WaZOO   ",
  806.                            "     FTS-0001",
  807.                            "     BBS     ",
  808.                            "     Ext Mail"
  809. };
  810.  
  811. void last_type (n, taddr)
  812. int n;
  813. ADDR *taddr;
  814. {
  815.    int i;
  816.    char *p;
  817.    char j[20];
  818.  
  819.    if (fullscreen)
  820.       sb_move (historywin, HIST_LAST_ROW, HIST_COL2);
  821.  
  822.    if ((n == 1) || (n == 2))
  823.       {
  824.       if ((taddr->Zone != -1000) && (taddr->Net > 0))
  825.          {
  826.          (void) sprintf (j, "%s", Full_Addr_Str (taddr));
  827. if ((p = strchr (j, '@')) != NULL)
  828. *p = '\0';
  829.          for (i = (int) strlen (j); i < 13; i++)
  830.             j[i] = ' ';
  831.          j[i] = '\0';
  832.          hist.last_zone = taddr->Zone;
  833.          hist.last_net = taddr->Net;
  834.          hist.last_node = taddr->Node;
  835.          }
  836.       else
  837.          {
  838.          (void) strcpy (j, "     FTS-0001");
  839.          }
  840.       if (fullscreen)
  841.          sb_puts (historywin, (unsigned char *) j);
  842.       }
  843.    else
  844.       {
  845.       if ((n < 0) || (n > 4))
  846.          n = 0;
  847.  
  848.       if (fullscreen)
  849.          sb_puts (historywin, (unsigned char *) last_str[n]);
  850.       }
  851.  
  852.    hist.last_caller = n;
  853. }
  854.  
  855.  
  856. /*--------------------------------------------------------------------------*/
  857. /* CHECK_NETFILE -- find out if the file we've got is a netfile.            */
  858. /*--------------------------------------------------------------------------*/
  859.  
  860. char *check_netfile (fname)
  861. char *fname;
  862. {
  863.    register char *p;
  864.    register int n;
  865.  
  866.    p = fname;
  867.    n = (int) strlen (p) - 1;
  868.  
  869.    if ((p[n] == 't') && (p[n - 1] == 'k') && (p[n - 2] == 'p') && (p[n - 3] == '.'))
  870.       {
  871.       got_packet = 1;
  872.       got_mail = 1;
  873.       p = msgtxt[M_MAIL_PACKET];
  874.       }
  875.    else if (is_arcmail (p, n))
  876.       {
  877.       got_mail = 1;
  878.       p = msgtxt[M_COMPRESSED_MAIL];
  879.       }
  880.    else
  881.       {
  882.       /* Don't set 'got_mail' if it's a .REQ file */
  883.       if ((p[n] != 'q') || (p[n - 1] != 'e') || (p[n - 2] != 'r') || (p[n - 3] != '.'))
  884.          got_mail = 1;
  885.       p = msgtxt[M_NET_FILE];
  886.       }
  887.  
  888.    return (p);
  889. }
  890.  
  891. /*--------------------------------------------------------------------------*/
  892. /* UNIQUE_NAME                                                              */
  893. /* Increments the suffix of a filename as necessary to make the name unique */
  894. /*--------------------------------------------------------------------------*/
  895. void unique_name (fname)
  896. char *fname;
  897. {
  898.    static char suffix[] = ".001";
  899.    register char *p;
  900.    register int n;
  901.  
  902.    if (dexists (fname))
  903.       {                                          /* If file already exists...      */
  904.       p = fname;
  905.       while (*p && *p != '.')
  906.          p++;                                    /* ...find the extension, if
  907.                                                   * any  */
  908.       for (n = 0; n < 4; n++)                    /* ...fill it out if
  909.                                                   * neccessary   */
  910.          if (!*p)
  911.             {
  912.             *p = suffix[n];
  913.             *(++p) = '\0';
  914.             }
  915.          else p++;
  916.  
  917.       while (dexists (fname))                    /* ...If 'file.ext' exists
  918.                                                   * suffix++ */
  919.          {
  920.          p = fname + strlen (fname) - 1;
  921.          for (n = 3; n--;)
  922.             {
  923.             if (!isdigit (*p))
  924.                *p = '0';
  925.             if (++(*p) <= '9')
  926.                break;
  927.             else *p-- = '0';
  928.             }                                    /* for */
  929.          }                                       /* while */
  930.       }                                          /* if exist */
  931. }                                                /* unique_name */
  932.  
  933. int got_ESC ()
  934. {
  935.    while (KEYPRESS ())
  936.       {
  937.       screen_blank = 0;
  938.       if (fullscreen && un_attended)
  939.          sb_show ();
  940.       if (READKB () == 27)     /* ESC pressed?        */
  941.          {
  942.          while (KEYPRESS ())
  943.             (void) READKB ();
  944.          return (1);
  945.          }
  946.       }
  947.    return (0);
  948. }
  949.  
  950. long cost_of_call (s, e)
  951. long s, e;
  952. {
  953.    long a;
  954.  
  955.    a = e - s;
  956.    a = (a + 59) / 60;
  957.    return (a * newnodedes.RealCost);
  958. }
  959.  
  960. void screen_clear ()
  961. {
  962.    register int r;
  963.    unsigned int far *q;
  964.  
  965.    if (!vfossil_installed)
  966.       scr_printf ("\033[H\033[2J");
  967.    else
  968.       {
  969.       for (r = 0; r <= SB_ROWS; r++)
  970.          {
  971.          q = (unsigned int far *) blanks;
  972. #ifndef OS_2
  973.          (void) VioWrtCellStr (q, SB_COLS * 2, r, 0, 0);
  974. #else
  975.          (void) VioWrtCellStr ((PCH) q, (USHORT) (SB_COLS * 2), (USHORT) r, (USHORT) 0, (HVIO) 0L);
  976. #endif
  977.          }
  978.  
  979.       gotoxy (0, 0);
  980.       }
  981. }
  982.  
  983. void clear_eol ()
  984. {
  985.    int x, y;
  986.    unsigned int far *q;
  987.    if (!vfossil_installed)
  988.       (void) printf ("\033[K");
  989.    else
  990.       {
  991.       x = wherex();
  992.       y = wherey();
  993.  
  994.       q = (unsigned int far *) blanks;
  995. #ifndef OS_2
  996.       (void) VioWrtCellStr (q, (SB_COLS - (unsigned) x) * 2, y, x, 0);
  997. #else
  998.       (void) VioWrtCellStr ((PCH) q, (USHORT) ((SB_COLS - x) * 2), (USHORT) y, (USHORT) x, (HVIO) 0L);
  999. #endif
  1000.       }
  1001. }
  1002.  
  1003. void log_product (product, version, subversion)
  1004. int product;
  1005. int version;
  1006. int subversion;
  1007. {
  1008.    switch (product)
  1009.       {
  1010.       case isBITBRAIN :
  1011.       case isFIDO     :
  1012.       case isSPARK    :
  1013.       case isSEA      :
  1014.       case isSlick    :
  1015.       case isHENK     :
  1016.       case isTABBIE   :
  1017.       case isWOLF     :
  1018.       case isQMM      :
  1019.       case isFD       :
  1020.       case isGSPOINT  :
  1021.       case isBGMAIL   :
  1022.       case isCROSSBOW :
  1023.       case isDBRIDGE  :
  1024.       case isDAISY    :
  1025.       case isPOLAR    :
  1026.       case isTHEBOX   :
  1027.       case isWARLOCK  :
  1028.       case isTCOMM    :
  1029.       case isBANANNA  :
  1030.       case isAPPLE    :
  1031.       case isCHAMELEON:
  1032.       case isMAJIK    :
  1033.       case isDOMAIN   :
  1034.       case isLESROBOT :
  1035.       case isROSE     :
  1036.       case isPARAGON  :
  1037.       case isBINKST   :
  1038.       case isSTARNET  :
  1039.       case isQUICKBBS :
  1040.       case isPBBS     :
  1041.       case isTRAPDOOR :
  1042.       case isWELMAT   :
  1043.       case isTIMS     :
  1044.       case isISIS     :
  1045.          status_line ("%s %s %s %d.%02d", msgtxt[M_REMOTE_USES],
  1046.              prodcode[product], msgtxt[M_VERSION], version, subversion);
  1047.          break;
  1048.  
  1049.       case isOPUS:
  1050.          status_line ("%s Opus %s %d.%02d", msgtxt[M_REMOTE_USES],
  1051.                       msgtxt[M_VERSION], version,
  1052.                       (subversion == 48) ? 0 : subversion);
  1053.          break;
  1054.  
  1055.       default:
  1056.          status_line ("%s %s '%02x' %s %d.%02d", msgtxt[M_REMOTE_USES],
  1057.                       msgtxt[M_PROGRAM], product,
  1058.                       msgtxt[M_VERSION], version, subversion);
  1059.          break;
  1060.       }
  1061. return;
  1062. }
  1063.  
  1064. int next_minute ()
  1065. {
  1066.    int hours, mins, secs, ths;
  1067.  
  1068.    /* Get the DOS time */
  1069.    dostime (&hours, &mins, &secs, &ths);
  1070.  
  1071.    return ((60 - (secs % 60)) * 100 + 1);
  1072. }
  1073.  
  1074. void can_Janus (p)
  1075. char *p;
  1076. {
  1077.    J_TYPESP j;
  1078.  
  1079.    janus_OK = 0;
  1080.    for (j = j_top; j != NULL; j = j->next)
  1081.       {
  1082.       if (strnicmp (p, j->j_match, strlen (j->j_match)) == 0)
  1083.          {
  1084.          janus_OK = 1;
  1085.          break;
  1086.          }
  1087.       }
  1088. }
  1089.  
  1090. int check_failed (fname, theirname, info, ourname)
  1091. char *fname, *theirname, *info, *ourname;
  1092. {
  1093.    FILE *abortlog;
  1094.    char linebuf[64];
  1095.     char *p, *badname;
  1096.     int ret;
  1097.  
  1098.     ret = 0;
  1099.    if ((abortlog = fopen (fname, read_ascii)) == NULL)
  1100.       {
  1101.       (void) got_error (msgtxt[M_OPEN_MSG], fname);
  1102.       }
  1103.    else
  1104.       {
  1105.       while (!feof (abortlog))
  1106.          {
  1107.          linebuf[0] = '\0';
  1108.          if (!fgets ((p = linebuf), 64, abortlog))
  1109.             break;
  1110.          while (*p >= ' ')
  1111.             ++p;
  1112.          *p = '\0';
  1113.          p = strchr (linebuf, ' ');
  1114.          *p = '\0';
  1115.          if (!stricmp (linebuf, theirname))
  1116.             {
  1117.             p = strchr ((badname = ++p), ' ');
  1118.             *p = '\0';
  1119.             if (!stricmp (++p, info))
  1120.                {
  1121.                strcpy (ourname, badname);
  1122.                     ret = 1;
  1123.                break;
  1124.                }
  1125.             }
  1126.          }
  1127.       fclose (abortlog);
  1128.       }
  1129.  
  1130.     return (ret);
  1131. }
  1132.  
  1133. void add_abort (fname, rname, cname, cpath, info)
  1134. char *fname, *rname, *cname, *cpath, *info;
  1135. {
  1136.     FILE *abortlog;
  1137.     char namebuf[100];
  1138.  
  1139.    strcpy (namebuf, cpath);
  1140.    strcat (namebuf, "BadWaZOO.001");
  1141.    unique_name (namebuf);
  1142.    rename (cname, namebuf);
  1143.    if ((abortlog = fopen (fname, "at")) == NULL)
  1144.       {
  1145.       (void) got_error (msgtxt[M_OPEN_MSG], fname);
  1146.       unlink (namebuf);
  1147.       }
  1148.    else
  1149.       {
  1150.       fprintf (abortlog, "%s %s %s\n", rname, namebuf + strlen (cpath), info);
  1151.       fclose (abortlog);
  1152.       }
  1153. }
  1154.  
  1155. void remove_abort (fname, rname)
  1156. char *fname, *rname;
  1157. {
  1158.     FILE *abortlog, *newlog;
  1159.     char namebuf[100];
  1160.     char linebuf[100];
  1161.     char *p;
  1162.     int c;
  1163.  
  1164.     if (!dexists (fname))
  1165.         return;
  1166.  
  1167.    if ((abortlog = fopen (fname, read_ascii)) == NULL)
  1168.       {
  1169.       (void) got_error (msgtxt[M_OPEN_MSG], fname);
  1170.       }
  1171.    else
  1172.       {
  1173.       strcpy (namebuf, fname);
  1174.       strcpy (namebuf + strlen (namebuf) - 1, "TMP");
  1175.       c = 0;
  1176.       if ((newlog = fopen (namebuf, write_ascii)) == NULL)
  1177.          {
  1178.          (void) got_error (msgtxt[M_OPEN_MSG], namebuf);
  1179.          fclose (abortlog);
  1180.          }
  1181.       else
  1182.          {
  1183.          while (!feof (abortlog))
  1184.             {
  1185.             linebuf[0] = '\0';
  1186.             if (!fgets (linebuf, 64, abortlog))
  1187.                break;
  1188.             p = linebuf;
  1189.             while (*p > ' ')
  1190.                ++p;
  1191.             *p = '\0';
  1192.             if (stricmp (linebuf, rname))
  1193.                {
  1194.                *p = ' ';
  1195.                fputs (linebuf, newlog);
  1196.                ++c;
  1197.                }
  1198.             }
  1199.          fclose (abortlog);
  1200.          fclose (newlog);
  1201.          unlink (fname);
  1202.          if (c)
  1203.             rename (namebuf, fname);
  1204.          else unlink (namebuf);
  1205.          }
  1206.       }
  1207. }
  1208.  
  1209. /*
  1210.  * The next routine is used in the count down timer during file
  1211.  * transfers, and were provided by Jon Sabol, along with the other code that
  1212.  * calls these routines.
  1213.  */
  1214.  
  1215. void elapse_time ()
  1216. {
  1217.    time_t ltime;
  1218.    long eh;
  1219.    long em;
  1220.    long es;
  1221.  
  1222.  
  1223.    if (fullscreen && (un_attended || doing_poll))
  1224.       {
  1225.       time (<ime);
  1226.  
  1227.       if (ltime < etm)
  1228.          ltime += 86400L;
  1229.  
  1230.       eh = (ltime - etm) / 3600L;
  1231.       em = ((ltime - etm) / 60L) - (eh * 60L);
  1232.       es = (ltime - etm) - (eh * 3600L) - (em * 60L);
  1233.  
  1234.       sb_move (settingswin, SET_TASK_ROW, SET_TIME_COL);
  1235.       sprintf (junk, "%s:  %02ld:%02ld:%02ld", msgtxt[M_ELAPSED], eh, em, es);
  1236.       sb_puts (settingswin, junk);
  1237.       sb_show ();
  1238.       }
  1239. }
  1240.  
  1241. static int find_addr (node, addr, d)
  1242. char *node;
  1243. ADDR *addr;
  1244. char *d;
  1245. {
  1246.    int ret;
  1247.  
  1248.     ret = 1;
  1249.    if (alias[0].Node == -1)
  1250.       addr->Zone = 0;
  1251.    else
  1252.       addr->Zone = alias[0].Zone;
  1253.    addr->Net = 0;
  1254.    addr->Node = 0;
  1255.    addr->Point = 0;
  1256.    addr->Domain = NULL;
  1257.    d[0] = '\0';
  1258.    if ((ret = sscanf (node, "%d:%d/%d.%d@%s",
  1259.       &(addr->Zone), &(addr->Net), &(addr->Node), &(addr->Point), d)) < 3)
  1260.       {
  1261.       if (alias[0].Node == -1)
  1262.          addr->Zone = 0;
  1263.       else
  1264.          addr->Zone = alias[0].Zone;
  1265.       if ((ret = sscanf (node, "%d/%d.%d@%s",
  1266.          &(addr->Net), &(addr->Node), &(addr->Point), d)) < 2)
  1267.          {
  1268.          addr->Net = alias[0].Net;
  1269.          if (sscanf (node, "%d.%d@%s",
  1270.             &(addr->Node), &(addr->Point), d) < 1)
  1271.             {
  1272.             ret = 0;
  1273.             }
  1274.          else if (ret == 1)
  1275.             {
  1276.             (void) sscanf (node, "%d@%s",
  1277.                &(addr->Node), d);
  1278.             }
  1279.          }
  1280.       else if (ret == 2)
  1281.          {
  1282.          (void) sscanf (node, "%d/%d@%s",
  1283.             &(addr->Net), &(addr->Node), d);
  1284.          }
  1285.       }
  1286.    else if (ret == 3)
  1287.       {
  1288.       (void) sscanf (node, "%d:%d/%d@%s",
  1289.          &(addr->Zone), &(addr->Net), &(addr->Node), d);
  1290.       }
  1291.  
  1292.    return (ret);
  1293. }
  1294.  
  1295. int parse_address (node, addr)
  1296. char *node;
  1297. ADDR *addr;
  1298. {
  1299.     int ret;
  1300.    char d[100];
  1301.  
  1302.    ret = find_addr (node, addr, d);
  1303.  
  1304.    if (d[0] != '\0')
  1305.       {
  1306.       addr->Domain = add_domain (d);
  1307.       }
  1308.  
  1309.     return (ret);
  1310. }
  1311.  
  1312. int find_address (node, addr)
  1313. char *node;
  1314. ADDR *addr;
  1315. {
  1316.    int ret;
  1317.    char d[100];
  1318.    char *p;
  1319.  
  1320.    d[0] = '\0';
  1321.    p = skip_blanks (node);
  1322.    if (!isdigit (*p))
  1323.       {
  1324.       fidouser (p, addr);
  1325.       if ((addr->Net == -1) || (addr->Node == -1) || (addr->Zone == -1))
  1326.          {
  1327.          ret = 0;
  1328.          }
  1329.       else
  1330.          {
  1331.          ret = 1;
  1332.          }
  1333.       }
  1334.    else
  1335.       {
  1336.       ret = find_addr (p, addr, d);
  1337.       }
  1338.  
  1339.    if (d[0] != '\0')
  1340.       {
  1341.       addr->Domain = find_domain (d);
  1342.       }
  1343.  
  1344.    return (ret);
  1345. }
  1346.  
  1347. char *add_domain (d)
  1348. char *d;
  1349. {
  1350.    char *p;
  1351.    int i;
  1352.  
  1353.    for (i = 0; (p = domain_name[i]) != NULL; i++)
  1354.       {
  1355.       if (strnicmp (d, p, strlen (p)) == 0)
  1356.          return (p);
  1357.       }
  1358.  
  1359.    if (i >= 49)
  1360.       return (NULL);
  1361.  
  1362.    domain_name[i] = strdup (d);
  1363.    return (domain_name[i]);
  1364. }
  1365.  
  1366. char *find_domain (d)
  1367. char *d;
  1368. {
  1369.    char *p, *q, *s;
  1370.    char c;
  1371.    int i, j, k;
  1372.  
  1373.    j = strlen (d);
  1374.    /* First see if we can find the whole domain name at the right */
  1375.    for (i = 0; (p = domain_name[i]) != NULL; i++)
  1376.       {
  1377.       k = strlen (p);
  1378.       if (k > j)
  1379.          continue;
  1380.  
  1381.       q = &(d[j - k]);
  1382.       if (strnicmp (q, p, k) == 0)
  1383.          {
  1384.          return (p);
  1385.          }
  1386.       }
  1387.  
  1388.    /* Ok, now see if we can find the abbreviated name at the right */
  1389.    for (i = 0; (p = domain_abbrev[i]) != NULL; i++)
  1390.       {
  1391.       k = strlen (p);
  1392.       if (k > j)
  1393.          continue;
  1394.  
  1395.       q = &(d[j - k]);
  1396.       if (strnicmp (q, p, k) == 0)
  1397.          {
  1398.          return (domain_name[i]);
  1399.          }
  1400.       }
  1401.  
  1402.    /* If there is a period in it, see if we can match the abbreviated name
  1403.       just before the period */
  1404.    if ((s = strrchr (d, '.')) != NULL)
  1405.       {
  1406.       c = *s;
  1407.       *s = '\0';
  1408.       j = strlen (d);
  1409.       for (i = 0; (p = domain_abbrev[i]) != NULL; i++)
  1410.          {
  1411.          k = strlen (p);
  1412.          if (k > j)
  1413.             continue;
  1414.  
  1415.          q = &(d[j - k]);
  1416.          if (strnicmp (q, p, k) == 0)
  1417.             {
  1418.             *s = c;
  1419.             return (domain_name[i]);
  1420.             }
  1421.          }
  1422.       *s = c;
  1423.       }
  1424.  
  1425.    return (NULL);
  1426. }
  1427.  
  1428. char addr_str[100];
  1429.  
  1430. char *Hex_Addr_Str (a)
  1431. ADDR *a;
  1432. {
  1433.    sprintf (addr_str, "%04x%04x", a->Net, a->Node);
  1434.    return (addr_str);
  1435. }
  1436.  
  1437. char *Full_Addr_Str (a)
  1438. ADDR *a;
  1439. {
  1440.    char t1[10];
  1441.    char t2[30];
  1442.    char t3[10];
  1443.    char t4[50];
  1444.  
  1445.    if (a->Zone && !no_zones)
  1446.       sprintf (t1, "%u:", a->Zone);
  1447.    else
  1448.       t1[0] = '\0';
  1449.  
  1450.    sprintf (t2, "%u/%u", a->Net, a->Node);
  1451.  
  1452.    if (a->Point)
  1453.       sprintf (t3, ".%u", a->Point);
  1454.    else
  1455.       t3[0] = '\0';
  1456.  
  1457.    if (a->Domain != NULL)
  1458.       sprintf (t4, "@%s", a->Domain);
  1459.    else
  1460.       t4[0] = '\0';
  1461.  
  1462.    strcpy (addr_str, t1);
  1463.    strcat (addr_str, t2);
  1464.    strcat (addr_str, t3);
  1465.    strcat (addr_str, t4);
  1466.    return (addr_str);
  1467. }
  1468.  
  1469. unsigned int crc_block(ptr, count)
  1470. unsigned char *ptr;
  1471. int count;
  1472. {
  1473.     unsigned int crc;
  1474.     int i;
  1475.  
  1476.    for (crc = 0, i = 0; i < count; i++, ptr++)
  1477.       {
  1478.       crc = xcrc (crc, (byte) *ptr);
  1479.         }
  1480.     return (crc & 0xFFFF);
  1481.     }
  1482.  
  1483. void Data_Check (xtmp, mode)
  1484. XMDATAP xtmp;
  1485. int mode;
  1486. {
  1487.     int i;
  1488.     unsigned char cs;
  1489.     unsigned char *cp;
  1490.     unsigned int cs1;
  1491.  
  1492.     /* If we are in checksum mode, just do it */
  1493.     if (mode == CHECKSUM)
  1494.         {
  1495.         cp = xtmp->data_bytes;
  1496.         cs = 0;
  1497.         for (i = 0; i < 128; i++)
  1498.             {
  1499.             cs += *cp++;
  1500.             }
  1501.         xtmp->data_check[0] = cs;
  1502.         }
  1503.     /* If we are in CRC mode, run the characters through the CRC calculator */
  1504.     else
  1505.         {
  1506.         cs1 = crc_block (xtmp->data_bytes, 128);
  1507.         xtmp->data_check[0] = (unsigned char) (cs1 >> 8);
  1508.         xtmp->data_check[1] = (unsigned char) (cs1 & 0xff);
  1509.         }
  1510.     }
  1511.  
  1512. static int buff_bytes = 0;
  1513.  
  1514. FILE *buff_fopen (fname, fmode)
  1515. char *fname;
  1516. char *fmode;
  1517. {
  1518.     buff_bytes = 0;
  1519.     return (fopen (fname, fmode));
  1520. }
  1521.  
  1522. int buff_fwrite (buff, size1, size2, fp)
  1523. char *buff;
  1524. int size1;
  1525. int size2;
  1526. FILE *fp;
  1527. {
  1528.     if ((buff_bytes + (size1 * size2)) > WAZOOMAX)
  1529.         {
  1530.         (void) fwrite (Secbuf, 1, buff_bytes, fp);
  1531.         buff_bytes = 0;
  1532.         }
  1533.  
  1534.     memcpy (Secbuf + buff_bytes, buff, size1 * size2);
  1535.     buff_bytes += size1 * size2;
  1536.     return (size1 * size2);
  1537. }
  1538.  
  1539. int buff_fclose (fp)
  1540. FILE *fp;
  1541. {
  1542.     (void) fwrite (Secbuf, 1, buff_bytes, fp);
  1543.     buff_bytes = 0;
  1544.     return (fclose (fp));
  1545. }
  1546.  
  1547. long buff_fseek (fp, a, b)
  1548. FILE *fp;
  1549. long a;
  1550. int b;
  1551. {
  1552.     (void) fwrite (Secbuf, 1, buff_bytes, fp);
  1553.     buff_bytes = 0;
  1554.     return (fseek (fp, a, b));
  1555. }
  1556.  
  1557. #ifdef OS_2
  1558. void set_prior (int pclass)
  1559.     {
  1560.     static USHORT regular = 0;
  1561.     static USHORT janus = 0;
  1562.     static USHORT modem = 0;
  1563.     USHORT priority;
  1564.     PIDINFO pids;
  1565.     char *s;
  1566.  
  1567.     switch (pclass)
  1568.         {
  1569.         case 2:
  1570.             if (regular)
  1571.                priority = regular;
  1572.             else
  1573.                {
  1574.                s = getenv("REGULARPRIORITY");
  1575.                if (s)
  1576.                   priority = regular = atoi(s);
  1577.  
  1578.                 if (!s || priority > 4 || priority < 0)        /* CML added logic to trap errors */
  1579.                     priority = regular = 2;
  1580.                }
  1581.            break;
  1582.  
  1583.         case 3:
  1584.             if (janus)
  1585.                priority = janus;
  1586.             else
  1587.                {
  1588.                s = getenv("JANUSPRIORITY");
  1589.                if (s)
  1590.                   priority = janus = atoi(s);
  1591.  
  1592.                 if (!s || priority > 4 || priority < 0)        /* CML added logic to trap errors */
  1593.                     priority = janus = 3;
  1594.                }
  1595.            break;
  1596.  
  1597.         case 4:
  1598.             if (modem)
  1599.                priority = modem;
  1600.             else
  1601.                {
  1602.                s = getenv("MODEMPRIORITY");
  1603.                if (s)
  1604.                   priority = modem = atoi(s);
  1605.  
  1606.                 if (!s || priority > 4 || priority < 0)        /* CML added logic to trap errors */
  1607.                     priority = modem = 4;
  1608.                }
  1609.             break;
  1610.  
  1611.         default:
  1612.             priority = 2;
  1613.             break;
  1614.         }
  1615.  
  1616.     DosGetPID(&pids);
  1617.     DosSetPrty(PRTYS_THREAD,priority,PRTYD_MINIMUM,pids.tid);
  1618.     }
  1619.  
  1620.  
  1621. #ifdef Snoop
  1622. #pragma check_stack(off)
  1623. static int far pascal _loadds mesgfunc(int error, char far *mesg)
  1624. {
  1625.     if(!error)
  1626.         status_line(":%Fs", mesg);
  1627.     else
  1628.         status_line("!SYS%04u : %Fs", error, mesg);
  1629.     return(0);
  1630. }
  1631. #pragma check_stack()
  1632.  
  1633. void snoop_open(char *pipename)
  1634. {
  1635.    static char *pipe = NULL;
  1636.    if(pipe)
  1637.       free(pipe);
  1638.    if(pipename)
  1639.       pipe = strdup(pipename);
  1640.    SnoopOpen(pipe, &hsnoop, xfer_id, (PFNSN)mesgfunc);
  1641. }
  1642.  
  1643. void snoop_close(void)
  1644. {
  1645.     if(hsnoop)
  1646.         SnoopClose(hsnoop);
  1647.     hsnoop = (HSNOOP)NULL;
  1648. }
  1649. #endif /* Snoop */
  1650. #else /* OS_2 */
  1651. void set_prior (int pclass)
  1652. {
  1653.    return;
  1654.    pclass = 5;
  1655. }
  1656. #endif /* OS_2 */
  1657.