home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRCP250.LZH / MISC.C < prev   
Text File  |  1991-09-17  |  32KB  |  1,274 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 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.250.    */
  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:343/491             */
  38. /* P.O. Box 460398                AlterNet 7:491/0                          */
  39. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  40. /*                                Internet f491.n343.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 this file before any other includes or defines! */
  48.  
  49. #include "includes.h"
  50.  
  51. #define EVENT_ENABLE
  52.  
  53. #ifdef Snoop
  54. #include "snserver.h"
  55. extern HSNOOP hsnoop;
  56. #endif /* Snoop */
  57.  
  58. static char newstring[200];
  59. void fill_in_status (char *);
  60. int find_addr (char *, ADDR *, char *);
  61.  
  62.  
  63. int set_baud (unsigned baudrate, int log)
  64. {
  65.    register int i;
  66.    unsigned search_rate;
  67.  
  68.    search_rate = (baudrate > max_baud.rate_value) ? max_baud.rate_value : baudrate;
  69.  
  70.    for (i = 0; btypes[i].rate_value; i++)
  71.       {
  72.       if (btypes[i].rate_value >= search_rate)
  73.          {
  74.          if ((btypes[i].rate_value != search_rate) && (search_rate < 9600))
  75.             break;
  76.  
  77.          if (baud != i)                          /* same as what we have?     */
  78.             {
  79.             if (log && !un_attended)
  80.                status_line (MSG_TXT(M_SETTING_BAUD), baudrate);
  81.             baud = i;                            /* need this for ALT-B       */
  82.             program_baud ();
  83.             cur_baud = btypes[i];
  84.             }
  85.  
  86.          cur_baud.rate_value = baudrate;
  87.  
  88.  
  89.          if (un_attended && fullscreen)
  90.             {
  91.             (void) sprintf (junk, "%-5u Com%d", baudrate, port_ptr + 1);
  92.             sb_move (settings_hWnd, SET_PORT_ROW, SET_COL);
  93.             sb_puts( settings_Port, junk );
  94.             sb_show ();
  95.             }
  96.          return (1);
  97.          }
  98.       }
  99.    return (0);
  100. }
  101.  
  102. void program_baud ()
  103. {
  104.    register unsigned int rate_mask;
  105.  
  106.    set_prior(4);                                           /* Always High    */
  107.  
  108.    if ((lock_baud && (btypes[baud].rate_value >= (unsigned)lock_baud))
  109.    || (ARQ_lock != 0))
  110.       rate_mask = max_baud.rate_mask;
  111.    else
  112.       rate_mask = btypes[baud].rate_mask;
  113.  
  114.    MDM_ENABLE (rate_mask);
  115.  
  116.    set_prior(2);                                           /* Regular        */
  117.  
  118. }
  119.  
  120. static char *specifiers = "!*+:# >";
  121. static struct tm *tp;
  122. static time_t ltime;
  123.  
  124. void status_line (char *fmt,...)
  125. {
  126.    va_list arg_ptr;
  127.  
  128.    char tmp[255];
  129.  
  130.    va_start (arg_ptr, fmt);
  131.    if (fmt == NULL)
  132.       return;
  133.    (void) vsprintf (e_input, fmt, arg_ptr);
  134.    (void) time (<ime);
  135.    tp = localtime (<ime);
  136.    if ((!fullscreen) || (!un_attended))
  137.       {
  138.       if ((e_input[0] != '>') || debugging_log)
  139.          {
  140.          (void) sprintf (tmp,"\r\n%c %02i %03s %02i:%02i:%02i " PRDCT_SHRT " %s", e_input[0],
  141.              tp->tm_mday, mtext[tp->tm_mon], tp->tm_hour, tp->tm_min, tp->tm_sec,
  142.                   &e_input[1]);
  143.          scr_printf (tmp);
  144.          }
  145.       }
  146.    else
  147.       {
  148.       if ((e_input[0] != '>') || debugging_log)
  149.          {
  150.          (void) sprintf (tmp, stat_str, e_input[0],
  151.                   tp->tm_hour, tp->tm_min, tp->tm_sec, &e_input[1]);
  152.  
  153.          fill_in_status (tmp);
  154.  
  155. #ifdef Snoop
  156.          if(hsnoop != (HSNOOP)NULL)
  157.             SnoopWrite(hsnoop, tmp);
  158. #endif /* Snoop */
  159.          }
  160.       }
  161.    if ((status_log != NULL) &&
  162.        ((strchr (specifiers, e_input[0]) - strchr (specifiers, '!')) <= loglevel))
  163.       {
  164.       (void) fprintf (status_log, "%c %02i %s %02i:%02i:%02i BINK %s\n", e_input[0],
  165.           tp->tm_mday, mtext[tp->tm_mon], tp->tm_hour, tp->tm_min, tp->tm_sec,
  166.                &e_input[1]);
  167.       if (immed_update)
  168.          {
  169.          (void) fflush (status_log);
  170.          (void) real_flush (fileno (status_log));
  171.          need_update = 0;
  172.          }
  173.       else
  174.          {
  175.          need_update = 1;
  176.          }
  177.       }
  178.    va_end (arg_ptr);
  179. }
  180.  
  181. /*--------------------------------------------------------------------------*/
  182. /* THROUGHPUT                                                               */
  183. /* Print throughput message at end of transfer                              */
  184. /*--------------------------------------------------------------------------*/
  185. void throughput (int opt, unsigned long bytes)
  186. {
  187.    static long started = 0L;
  188.    static long elapsed;
  189.    static long cps;
  190.  
  191.    if (!opt)
  192.       started = time (NULL);
  193.    else if (started)
  194.       {
  195.       elapsed = time (NULL);
  196.       /* The next line tests for day wrap without the date rolling over */
  197.       if (elapsed < started)
  198.          elapsed += 86400L;
  199.       elapsed -= started;
  200.       if (elapsed == 0L)
  201.          elapsed = 1L;
  202.       cps = (long) (bytes / (unsigned long) elapsed);
  203.       started = (cps * 1000L) / ((long) cur_baud.rate_value);
  204.       status_line ((char *) MSG_TXT(M_CPS_MESSAGE), cps, bytes, started);
  205.       }
  206. }                                                /* throughput */
  207.  
  208. void fill_in_status (char *stat_line)
  209. {
  210. #ifdef MILQ
  211.    RECT                 Rect;
  212. #endif
  213.  
  214.    (void) time (<ime);
  215.    tp = localtime (<ime);
  216.    if (fullscreen)
  217.       {
  218.       sb_scrl (call_hWnd, 1);
  219.  
  220.      /* This is crazy (as are all the the computations based on SB_ROWS
  221.       * and SB_COLS).  These should be computed somewhere, and left alone.
  222.       */
  223.  
  224. #ifdef MILQ
  225.       GetClientRect( call_hWnd, &Rect );
  226.       SB_ROW_STATUS = ++Rect.bottom;
  227. #endif
  228.  
  229. #ifndef CALL_LISTBOX
  230.       sb_move (call_hWnd, SB_ROW_STATUS, 2);
  231.       sb_puts (call_hWnd, stat_line);
  232. #else
  233.       SendMessage( call_hWnd, LB_ADDSTRING, 0, (long)stat_line );
  234. #endif
  235.  
  236.       (void) sprintf (junk, "%s %s %02d @ %02d:%02d",
  237.                wkday[tp->tm_wday], mtext[tp->tm_mon], tp->tm_mday,
  238.                tp->tm_hour, tp->tm_min);
  239.       sb_move (settings_hWnd, SET_TIME_ROW, SET_TIME_COL);
  240.       sb_puts( settings_DtTm, junk );
  241.       sb_show ();
  242.       }
  243. }
  244.  
  245. void clear_statusline ()
  246. {
  247.    if (fullscreen)
  248.       sb_fillc (call_hWnd, ' ');
  249. }
  250.  
  251. #ifndef MILQ
  252. void set_xy (char *string)
  253. {
  254.    WRITE_ANSI ('\r');
  255.    WRITE_ANSI ('\n');
  256.    scr_printf (string);
  257.    locate_x = wherex ();
  258.    locate_y = wherey ();
  259. }
  260. #endif
  261.  
  262. void _cdecl time_release ()
  263. {
  264.    EventSub();
  265.    if (need_update)
  266.       {
  267.       if (status_log != NULL)                                 /*WRA*/
  268.          {
  269.          (void) fflush (status_log);
  270.          (void) real_flush (fileno (status_log));
  271.          }
  272.       need_update = 0;
  273.       }
  274.  
  275.    dos_break_off ();                            /* Turn off ^C trapping */
  276.  
  277.    (*mtask_idle) ();
  278.  
  279. }
  280.  
  281. char *fancy_str (char *string)
  282. {
  283.    register int flag = 0;
  284.    char *s;
  285.  
  286.    s = string;
  287.  
  288.    while (*string)
  289.       {
  290.       if (isalpha (*string))                     /* If alphabetic,     */
  291.          {
  292.          if (flag)                               /* already saw one?   */
  293.             *string = (char) tolower (*string);  /* Yes, lowercase it  */
  294.          else
  295.             {
  296.             flag = 1;                            /* first one, flag it */
  297.             *string = (char) toupper (*string);  /* Uppercase it       */
  298.             }
  299.          }
  300.       else /* if not alphabetic  */ flag = 0;    /* reset alpha flag   */
  301.       string++;
  302.       }
  303.  
  304.    return (s);
  305. }
  306.  
  307. void timer (int interval)
  308. {
  309.    long timeout;
  310.  
  311.    timeout = timerset ((unsigned int) (interval * 10));
  312.    while (!timeup (timeout))
  313.       time_release ();
  314. }
  315.  
  316. void big_pause (int secs)
  317. {
  318.    long timeout;
  319.  
  320.    timeout = timerset ((unsigned int) (secs * 100));
  321.    while (!timeup (timeout))
  322.       {
  323.       if (CHAR_AVAIL ())
  324.          break;
  325.       time_release ();
  326.       }
  327. }
  328.  
  329. int com_getc (int t)
  330. {
  331.    long t1;
  332.  
  333.    if (!CHAR_AVAIL ())
  334.       {
  335.       t1 = timerset ((unsigned int) (t * 100));
  336.       while (!CHAR_AVAIL ())
  337.          {
  338.          if (timeup (t1))
  339.             {
  340.             return (EOF);
  341.             }
  342.  
  343.          /*
  344.           * This should work because we only do TIMED_READ when we have
  345.           * carrier
  346.           */
  347.          if (!CARRIER)
  348.             {
  349.             return (EOF);
  350.             }
  351.          time_release ();
  352.          }
  353.       }
  354.    return ((unsigned int)(MODEM_IN ()) & 0x00ff);
  355. }
  356.  
  357. void scr_printf (char *string)
  358. {
  359.    if (string != NULL)
  360.       if (vfossil_installed)
  361.          (void) VioWrtTTY (string, (USHORT) strlen (string), (HVIO) 0L);
  362.       else while (*string != 0)
  363.          WRITE_ANSI (*string++);
  364. }
  365.  
  366. void send_can ()
  367. {
  368.    int i;
  369.  
  370.    CLEAR_OUTBOUND ();
  371.    CLEAR_INBOUND ();
  372.  
  373.    for (i = 0; i < 10; i++)
  374.       SENDBYTE (CAN);
  375.    for (i = 0; i < 10; i++)
  376.       SENDBYTE (BS);
  377. }
  378.  
  379. void invent_pkt_name (char string[])
  380. {
  381.    struct tm *tp;
  382.    time_t ltime;
  383.  
  384.    (void) time (<ime);
  385.    tp = localtime (<ime);
  386.    (void) sprintf (string, "%02i%02i%02i%02i.pkt",
  387.             tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec);
  388. }
  389.  
  390. static char *suffixes[8] = {
  391.                             "SU", "MO", "TU", "WE", "TH", "FR", "SA", NULL
  392. };
  393.  
  394. int is_user (char *p)
  395. {
  396.    char *q;
  397.    char far *r;
  398.    int i, j;
  399.  
  400.    if (cur_event < 0)
  401.       return (0);
  402.  
  403.    q = strchr (p, '.');
  404.    if (q != NULL)
  405.       {
  406.       ++q;
  407.       for (i = 0; i < 6; i++)
  408.          {
  409.          r = &(e_ptrs[cur_event].err_extent[i][0]);
  410.          for (j = 0; j < 3; j++)
  411.             {
  412.             if ((tolower (q[j]) != tolower (r[j])) && (q[j] != '?'))
  413.                break;
  414.             }
  415.          if (j == 3)
  416.             user_exits[i] = 1;
  417.          }
  418.       }
  419.  
  420.    return (0);
  421. }
  422.  
  423. int is_arcmail (char *p, int n)
  424. {
  425.    int i;
  426.    char c[128];
  427.  
  428.    if (!isdigit (p[n]))
  429.       {
  430.       return (is_user (p));
  431.       }
  432.  
  433.    (void) strcpy (c, p);
  434.    (void) strupr (c);
  435.  
  436.    for (i = n - 11; i < n - 3; i++)
  437.       {
  438.       if ((!isdigit (c[i])) && ((c[i] > 'F') || (c[i] < 'A')))
  439.          return (is_user (p));
  440.       }
  441.  
  442.    for (i = 0; i < 7; i++)
  443.       {
  444.       if (strnicmp (&c[n - 2], suffixes[i], 2) == 0)
  445.          break;
  446.       }
  447.  
  448.    if (i >= 7)
  449.       {
  450.       return (is_user (p));
  451.       }
  452.  
  453.    got_arcmail = 1;
  454.    return (1);
  455. }
  456.  
  457. int get_number (char *target)
  458. {
  459.    ADDR gaddr;
  460.    int k;
  461.  
  462. #ifndef MILQ
  463.    (void) fgets (target, 100, stdin);
  464. #endif
  465.  
  466.    k = (int) strlen (target);
  467.  
  468. #ifndef MILQ
  469.    if (k == 1)
  470.       return (0);
  471.    target[--k] = '\0';                           /* no '\n' */
  472. #endif
  473.  
  474.    if (!isdigit (target[0]) && target[0] != '\"')
  475.       {
  476.       (*userfunc) (target, &gaddr);
  477.       if ((gaddr.Net != 0xffff) && (gaddr.Node != 0xffff) && (gaddr.Zone != 0xffff))
  478.          {
  479.          (void) sprintf (target, "%s", Full_Addr_Str (&gaddr));
  480.          }
  481.       else return (0);                           /* Gotta have addr */
  482.       }
  483.    return (1);
  484. }
  485.  
  486. void gong ()
  487. {
  488.    long t;
  489.    int i;
  490.  
  491.    if (!gong_allowed)
  492.       return;
  493.  
  494.    for (i = 0; i < 15; i++)
  495.       {
  496.       WRITE_ANSI ('\07');                        /* Bell code       */
  497.       t = timerset (100);                        /* 1 second        */
  498.       while (!timeup (t))
  499.          {
  500.          if (KEYPRESS ())                        /* If key pressed, */
  501.             {
  502.             (void) READKB ();                    /* Throw it away   */
  503.             return;                              /* And get out     */
  504.             }
  505.          }
  506.       }
  507. }
  508.  
  509. char *skip_blanks (char *string)
  510. {
  511.    while (*string && isspace (*string))
  512.       ++string;
  513.    return (string);
  514. }
  515.  
  516. char *skip_to_blank (char *string)
  517. {
  518.    while (*string && (!isspace (*string)))
  519.       ++string;
  520.    return (string);
  521. }
  522.  
  523. #ifdef DEBUG
  524. void show_debug_name (char *string)
  525. {
  526.    int x, y;
  527.    static char *filler = "                           ";
  528.  
  529.    x = wherex ();
  530.    y = wherey ();
  531.    gotoxy (40, 0);
  532.    scr_printf (string);
  533.    scr_printf (&filler[strlen (string)]);
  534.    gotoxy (x, y);
  535. }
  536. #endif
  537.  
  538. int parse (char *input, struct parse_list far list[])
  539. {
  540.    int i, j;
  541.    char *p;
  542.    char far *q;
  543.  
  544.    for (i = 0; list[i].p_length; i++)
  545.       {
  546.       p = input;
  547.       q = list[i].p_string;
  548.       for (j = list[i].p_length; j > 0; j--, p++, q++)
  549.          {
  550.          if (tolower(*p) != tolower (*q))
  551.             break;
  552.          }
  553.       if (j == 0)
  554.          return (++i);
  555.       }
  556.    return (-1);
  557. }
  558.  
  559. void change_prompt ()
  560. {
  561.    char *s;
  562.  
  563.    if (newstring[0])
  564.       {
  565.       (void) putenv (newstring);
  566.       return;
  567.       }
  568.  
  569.    (void) strcpy (newstring, "PROMPT=[");
  570.    (void) strcat (newstring, xfer_id);
  571.    (void) strcat (newstring, COMPILER_NAME);
  572.    (void) strcat (newstring, " Shell]$_");
  573.    s = getenv ("PROMPT");
  574.    if (s)
  575.       {
  576.       (void) strcat (newstring, s);
  577.       }
  578.    else
  579.       {
  580.       (void) strcat (newstring, "$P$G");
  581.       }
  582.  
  583.    (void) putenv (newstring);
  584. }
  585.  
  586. void update_files (int t)
  587. {
  588.    char s[10];
  589.  
  590.    if (un_attended && fullscreen)
  591.       {
  592.       if (t)
  593.          {
  594.          ++hist.files_out;
  595.          }
  596.       else
  597.          {
  598.          ++hist.files_in;
  599.          }
  600.  
  601.       (void) sprintf (s, "%d/%d", hist.files_in, hist.files_out);
  602.       sb_move (history_hWnd, HIST_FILE_ROW, HIST_COL);
  603.       sb_puts( history_Fl, s );
  604.       sb_show ();
  605.       }
  606. }
  607.  
  608. static char *last_str[] = {
  609.                            "     None    ",
  610.                            "     WaZOO   ",
  611.                            "     FTS-0001",
  612.                            "     BBS     ",
  613.                            "     Ext Mail"
  614. };
  615.  
  616. void last_type (int n, ADDRP taddr)
  617. {
  618.    int i;
  619.    char *p;
  620.    char j[90];
  621.  
  622.    if (fullscreen)
  623.       sb_move (history_hWnd, HIST_LAST_ROW, HIST_COL2);
  624.  
  625.    if ((n == 1) || (n == 2))
  626.       {
  627.       if (((int)taddr->Zone != -1000) && ((int)taddr->Net > 0))
  628.          {
  629.          (void) sprintf (j, "%s", Full_Addr_Str (taddr));
  630.          if ((p = strchr (j, '@')) != NULL)
  631.             *p = '\0';
  632.          for (i = (int) strlen (j); i < 13; i++)
  633.             j[i] = ' ';
  634.          j[i] = '\0';
  635.          hist.last_addr = *taddr;
  636.          SendMessage( node_hWnd, WM_COMMAND, GD_CRNT, (long)&hist.last_addr );
  637.          }
  638.       else
  639.          {
  640.          (void) strcpy (j, "     FTS-0001");
  641.          }
  642.       if (fullscreen) {
  643.          sb_puts( history_Last, j );
  644.          }
  645.       }
  646.    else
  647.       {
  648.       if ((n < 0) || (n > 4))
  649.          n = 0;
  650.  
  651.       if (fullscreen)
  652.          sb_puts (history_Last, last_str[n]);
  653.       }
  654.  
  655.    hist.last_caller = n;
  656. }
  657.  
  658.  
  659. /*--------------------------------------------------------------------------*/
  660. /* CHECK_NETFILE -- find out if the file we've got is a netfile.            */
  661. /*--------------------------------------------------------------------------*/
  662.  
  663. char *check_netfile (char *fname)
  664. {
  665.    register char *p;
  666.    register int n;
  667.  
  668.    p = fname;
  669.    n = (int) strlen (p) - 1;
  670.  
  671.    if ((p[n] == 't') && (p[n - 1] == 'k') && (p[n - 2] == 'p') && (p[n - 3] == '.'))
  672.       {
  673.       got_packet = 1;
  674.       got_mail = 1;
  675.       p = MSG_TXT(M_MAIL_PACKET);
  676.       }
  677.    else if (is_arcmail (p, n))
  678.       {
  679.       got_mail = 1;
  680.       p = MSG_TXT(M_COMPRESSED_MAIL);
  681.       }
  682.    else
  683.       {
  684.       /* Don't set 'got_mail' if it's a .REQ file */
  685.       if ((p[n] != 'q') || (p[n - 1] != 'e') || (p[n - 2] != 'r') || (p[n - 3] != '.'))
  686.          got_mail = 1;
  687.       p = MSG_TXT(M_NET_FILE);
  688.       }
  689.  
  690.    return (p);
  691. }
  692.  
  693. /*--------------------------------------------------------------------------*/
  694. /* UNIQUE_NAME                                                              */
  695. /* Increments the suffix of a filename as necessary to make the name unique */
  696. /*--------------------------------------------------------------------------*/
  697. void unique_name (char *fname)
  698. {
  699.    static char suffix[] = ".001";
  700.    register char *p;
  701.    register int n;
  702.  
  703.    if (dexists (fname))
  704.       {                                          /* If file already exists...      */
  705.       p = fname;
  706.       while (*p && *p != '.')
  707.          p++;                                    /* ...find the extension, if
  708.                                                   * any  */
  709.       for (n = 0; n < 4; n++)                    /* ...fill it out if
  710.                                                   * neccessary   */
  711.          if (!*p)
  712.             {
  713.             *p = suffix[n];
  714.             *(++p) = '\0';
  715.             }
  716.          else p++;
  717.  
  718.       while (dexists (fname))                    /* ...If 'file.ext' exists
  719.                                                   * suffix++ */
  720.          {
  721.          p = fname + strlen (fname) - 1;
  722.          for (n = 3; n--;)
  723.             {
  724.             if (!isdigit (*p))
  725.                *p = '0';
  726.             if (++(*p) <= '9')
  727.                break;
  728.             else *p-- = '0';
  729.             }                                    /* for */
  730.          }                                       /* while */
  731.       }                                          /* if exist */
  732. }                                                /* unique_name */
  733.  
  734. int got_ESC ()
  735. {
  736.    while (KEYPRESS ())
  737.       {
  738.       screen_blank = 0;
  739.       if (fullscreen && un_attended)
  740.          sb_show ();
  741.       if (READKB () == 27)     /* ESC pressed?        */
  742.          {
  743.          while (KEYPRESS ())
  744.             (void) READKB ();
  745.          return (1);
  746.          }
  747.       }
  748.    return (0);
  749. }
  750.  
  751. long cost_of_call (long s, long e)
  752. {
  753.    long a;
  754.  
  755.    a = e - s;
  756.    a = (a + 59) / 60;
  757.    return (a * newnodedes.RealCost);
  758. }
  759.  
  760. void screen_clear ()
  761. {
  762. #ifndef MILQ
  763.    unsigned int r;
  764.    PCH q;
  765.  
  766.    if (!vfossil_installed)
  767.       scr_printf ("\033[H\033[2J");
  768.    else
  769.       {
  770.       for (r = 0; (int) r <= (int) SB_ROWS; r++)
  771.          {
  772.          q = (PCH) blanks;
  773.          (void) VioWrtCellStr ((PCH) q, (USHORT) (SB_COLS * 2), (USHORT) r, (USHORT) 0, (HVIO) 0L);
  774.          }
  775.  
  776.       gotoxy (0, 0);
  777.       }
  778. #endif
  779. }
  780.  
  781. void clear_eol ()
  782. {
  783.    unsigned int x, y;
  784.    PCH q;
  785.  
  786.    if (!vfossil_installed)
  787.       (void) printf ("\033[K");
  788.    else
  789.       {
  790.       x = (unsigned int) wherex();
  791.       y = (unsigned int) wherey();
  792.  
  793.       q = (PCH) blanks;
  794.       (void) VioWrtCellStr ((PCH) q, (USHORT) ((SB_COLS - x) * 2), (USHORT) y, (USHORT) x, (HVIO) 0L);
  795.       }
  796. }
  797.  
  798. void log_product (int product, int version, int subversion)
  799. {
  800.    switch (product)
  801.       {
  802.  
  803. /*  Special case Opus.
  804.  */
  805.       case isOPUS:
  806.          status_line ("%s Opus %s %d.%02d", MSG_TXT(M_REMOTE_USES),
  807.                       MSG_TXT(M_VERSION), version,
  808.                       (subversion == 48) ? 0 : subversion);
  809.          break;
  810.  
  811.       default:
  812.          status_line ("%s %s %s %d.%02d", MSG_TXT(M_REMOTE_USES),
  813.                  PRDCT_NM(product), MSG_TXT(M_VERSION), version, subversion);
  814.          break;
  815.       }
  816. return;
  817. }
  818.  
  819. int next_minute ()
  820. {
  821.    time_t long_time;
  822.    struct tm *tm;
  823.  
  824.    /* Get the current time into a structure */
  825.  
  826.    (void) time (&long_time);
  827.    tm = localtime (&long_time);
  828.  
  829.    return ((60 - (tm->tm_sec % 60)) * 100 + 1);
  830. }
  831.  
  832. void can_Janus (char *p)
  833. {
  834.    J_TYPESP j;
  835.  
  836.    janus_OK = 0;
  837.    for (j = j_top; j != NULL; j = j->next)
  838.       {
  839.       if (strnicmp (p, j->j_match, strlen (j->j_match)) == 0)
  840.          {
  841.          janus_OK = 1;
  842.          break;
  843.          }
  844.       }
  845. }
  846.  
  847. int check_failed (char *fname, char *theirname, char *info, char *ourname)
  848. {
  849.    FILE *abortlog;
  850.    char linebuf[64];
  851.    char *p, *badname;
  852.    int ret;
  853.  
  854.    ret = 0;
  855.    if ((abortlog = fopen (fname, read_ascii)) == NULL)
  856.       {
  857.       (void) got_error (MSG_TXT(M_OPEN_MSG), fname);
  858.       }
  859.    else
  860.       {
  861.       while (!feof (abortlog))
  862.          {
  863.          linebuf[0] = '\0';
  864.          if (!fgets ((p = linebuf), 64, abortlog))
  865.             break;
  866.          while (*p >= ' ')
  867.             ++p;
  868.          *p = '\0';
  869.          p = strchr (linebuf, ' ');
  870.          *p = '\0';
  871.          if (!stricmp (linebuf, theirname))
  872.             {
  873.             p = strchr ((badname = ++p), ' ');
  874.             *p = '\0';
  875.             if (!stricmp (++p, info))
  876.                {
  877.                (void) strcpy (ourname, badname);
  878.                ret = 1;
  879.                break;
  880.                }
  881.             }
  882.          }
  883.       (void) fclose (abortlog);
  884.       }
  885.  
  886.   return (ret);
  887. }
  888.  
  889. void add_abort (char *fname, char *rname, char *cname,
  890.                 char *cpath, char *info)
  891. {
  892.    FILE *abortlog;
  893.    char namebuf[100];
  894.  
  895.    (void) strcpy (namebuf, cpath);
  896.    (void) strcat (namebuf, "BadWaZOO.001");
  897.    unique_name (namebuf);
  898.    (void) rename (cname, namebuf);
  899.    if ((abortlog = fopen (fname, "at")) == NULL)
  900.       {
  901.       (void) got_error (MSG_TXT(M_OPEN_MSG), fname);
  902.       (void) unlink (namebuf);
  903.       }
  904.    else
  905.       {
  906.       (void) fprintf (abortlog, "%s %s %s\n", rname, namebuf + strlen (cpath), info);
  907.       (void) fclose (abortlog);
  908.       }
  909. }
  910.  
  911. void remove_abort (char *fname, char *rname)
  912. {
  913.   FILE *abortlog, *newlog;
  914.   char namebuf[100];
  915.   char linebuf[100];
  916.   char *p;
  917.   int c;
  918.  
  919.   if (!dexists (fname))
  920.     return;
  921.  
  922.    if ((abortlog = fopen (fname, read_ascii)) == NULL)
  923.       {
  924.       (void) got_error (MSG_TXT(M_OPEN_MSG), fname);
  925.       }
  926.    else
  927.       {
  928.       (void) strcpy (namebuf, fname);
  929.       (void) strcpy (namebuf + strlen (namebuf) - 1, "TMP");
  930.       c = 0;
  931.       if ((newlog = fopen (namebuf, write_ascii)) == NULL)
  932.          {
  933.          (void) got_error (MSG_TXT(M_OPEN_MSG), namebuf);
  934.          (void) fclose (abortlog);
  935.          }
  936.       else
  937.          {
  938.          while (!feof (abortlog))
  939.             {
  940.             linebuf[0] = '\0';
  941.             if (!fgets (linebuf, 64, abortlog))
  942.                break;
  943.             p = linebuf;
  944.             while (*p > ' ')
  945.                ++p;
  946.             *p = '\0';
  947.             if (stricmp (linebuf, rname))
  948.                {
  949.                *p = ' ';
  950.                (void) fputs (linebuf, newlog);
  951.                ++c;
  952.                }
  953.             }
  954.          (void) fclose (abortlog);
  955.          (void) fclose (newlog);
  956.          (void) unlink (fname);
  957.          if (c)
  958.             (void) rename (namebuf, fname);
  959.          else (void) unlink (namebuf);
  960.          }
  961.       }
  962. }
  963.  
  964. /*
  965.  * The next routine is used in the count down timer during file
  966.  * transfers, and were provided by Jon Sabol, along with the other code that
  967.  * calls these routines.
  968.  */
  969.  
  970. void elapse_time ()
  971. {
  972.    time_t ltime;
  973.    time_t etime;
  974.    long eh;
  975.    long em;
  976.    long es;
  977.  
  978.  
  979.    if (fullscreen && (un_attended || doing_poll))
  980.       {
  981.       (void) time (<ime);
  982.  
  983.       if (ltime < etm)
  984.          ltime += 86400L;
  985.       etime = ltime - etm;
  986.       eh = etime / 3600L;
  987.       em = (etime / 60L) - (eh * 60L);
  988.       es = etime - (eh * 3600L) - (em * 60L);
  989.  
  990. #ifndef MILQ
  991.       (void) sprintf ( junk,
  992.                        "%s:  %02ld:%02ld:%02ld",
  993.                         MSG_TXT(M_ELAPSED),
  994.                         eh, em, es);
  995.       sb_move (settings_hWnd, SET_TASK_ROW, SET_TIME_COL);
  996.       sb_puts (settings_hWnd, junk);
  997. #else
  998.       (void) sprintf ( last_Elapsed_Str,
  999.                        "%02ld:%02ld:%02ld",
  1000.                          eh, em, es);
  1001.       if (etime)
  1002.         sb_puts( node_Elapsed, last_Elapsed_Str );
  1003. #endif
  1004.       sb_show ();
  1005.       }
  1006. }
  1007.  
  1008. int find_addr (char *node, ADDRP addr, char *d)
  1009. {
  1010.    int ret;
  1011.  
  1012.    ret = 1;
  1013.    if (alias[0].Node == 0xffff)
  1014.       addr->Zone = 0;
  1015.    else
  1016.       addr->Zone = alias[0].Zone;
  1017.    addr->Net = 0;
  1018.    addr->Node = 0;
  1019.    addr->Point = 0;
  1020.    addr->Domain = NULL;
  1021.    d[0] = '\0';
  1022.    if ((ret = sscanf (node, "%d:%d/%d.%d@%s",
  1023.       &(addr->Zone), &(addr->Net), &(addr->Node), &(addr->Point), d)) < 3)
  1024.       {
  1025.       if (alias[0].Node == 0xffff)
  1026.          addr->Zone = 0;
  1027.       else
  1028.          addr->Zone = alias[0].Zone;
  1029.       d[0] = '\0';
  1030.       if ((ret = sscanf (node, "%d/%d.%d@%s",
  1031.          &(addr->Net), &(addr->Node), &(addr->Point), d)) < 2)
  1032.          {
  1033.          addr->Net = alias[0].Net;
  1034.          d[0] = '\0';
  1035.          if (sscanf (node, "%d.%d@%s",
  1036.             &(addr->Node), &(addr->Point), d) < 1)
  1037.             {
  1038.             ret = 0;
  1039.             }
  1040.          else if (ret == 1)
  1041.             {
  1042.             d[0] = '\0';
  1043.             (void) sscanf (node, "%d@%s",
  1044.                &(addr->Node), d);
  1045.             }
  1046.          }
  1047.       else if (ret == 2)
  1048.          {
  1049.          d[0] = '\0';
  1050.          (void) sscanf (node, "%d/%d@%s",
  1051.             &(addr->Net), &(addr->Node), d);
  1052.          }
  1053.       }
  1054.    else if (ret == 3)
  1055.       {
  1056.       d[0] = '\0';
  1057.       (void) sscanf (node, "%d:%d/%d@%s",
  1058.          &(addr->Zone), &(addr->Net), &(addr->Node), d);
  1059.       }
  1060.  
  1061.    return (ret);
  1062. }
  1063.  
  1064. int parse_address (char *node, ADDRP addr)
  1065. {
  1066.    int ret;
  1067.    char d[100];
  1068.  
  1069.    ret = find_addr (node, addr, d);
  1070.  
  1071.    if (d[0] != '\0')
  1072.       {
  1073.       addr->Domain = add_domain (d);
  1074.       }
  1075.    else addr->Domain = NULL;
  1076.  
  1077.    return (ret);
  1078. }
  1079.  
  1080. int find_address (char *node, ADDRP addr)
  1081. {
  1082.    int ret;
  1083.    char d[100];
  1084.    char *p;
  1085.  
  1086.    d[0] = '\0';
  1087.    p = skip_blanks (node);
  1088.    if (!isdigit (*p))
  1089.       {
  1090.       (*userfunc) (p, addr);
  1091.       if ((addr->Net == 0xffff) || (addr->Node == 0xffff) || (addr->Zone == 0xffff))
  1092.          {
  1093.          ret = 0;
  1094.          }
  1095.       else
  1096.          {
  1097.          ret = 1;
  1098.          }
  1099.       }
  1100.    else
  1101.       {
  1102.       ret = find_addr (p, addr, d);
  1103.       }
  1104.  
  1105.    if (d[0] != '\0')
  1106.       {
  1107.       addr->Domain = find_domain (d);
  1108.       }
  1109.  
  1110.    return (ret);
  1111. }
  1112.  
  1113. char *add_domain (char *d)
  1114. {
  1115.    char *p;
  1116.    int i;
  1117.  
  1118.    for (i = 0; (p = domain_name[i]) != NULL; i++)
  1119.       {
  1120.       if (strnicmp (d, p, strlen (p)) == 0)
  1121.          return (p);
  1122.       }
  1123.  
  1124.    if (i >= 49)
  1125.       return (NULL);
  1126.  
  1127.    domain_name[i] = strdup (d);
  1128.    return (domain_name[i]);
  1129. }
  1130.  
  1131. char *find_domain (char *d)
  1132. {
  1133.    char *p, *q, *s;
  1134.    char c;
  1135.    int i, j, k;
  1136.  
  1137.    j = strlen (d);
  1138.    /* First see if we can find the whole domain name at the right */
  1139.    for (i = 0; (p = domain_name[i]) != NULL; i++)
  1140.       {
  1141.       k = strlen (p);
  1142.       if (k > j)
  1143.          continue;
  1144.  
  1145.       q = &(d[j - k]);
  1146.       if (strnicmp (q, p, k) == 0)
  1147.          {
  1148.          return (p);
  1149.          }
  1150.       }
  1151.  
  1152.    /* Ok, now see if we can find the abbreviated name at the right */
  1153.    for (i = 0; (p = domain_abbrev[i]) != NULL; i++)
  1154.       {
  1155.       k = strlen (p);
  1156.       if (k > j)
  1157.          continue;
  1158.  
  1159.       q = &(d[j - k]);
  1160.       if (strnicmp (q, p, k) == 0)
  1161.          {
  1162.          return (domain_name[i]);
  1163.          }
  1164.       }
  1165.  
  1166.    /* If there is a period in it, see if we can match the abbreviated name
  1167.       just before the period */
  1168.    if ((s = strrchr (d, '.')) != NULL)
  1169.       {
  1170.       c = *s;
  1171.       *s = '\0';
  1172.       j = strlen (d);
  1173.       for (i = 0; (p = domain_abbrev[i]) != NULL; i++)
  1174.          {
  1175.          k = strlen (p);
  1176.          if (k > j)
  1177.             continue;
  1178.  
  1179.          q = &(d[j - k]);
  1180.          if (strnicmp (q, p, k) == 0)
  1181.             {
  1182.             *s = c;
  1183.             return (domain_name[i]);
  1184.             }
  1185.          }
  1186.       *s = c;
  1187.       }
  1188.  
  1189.    return (NULL);
  1190. }
  1191.  
  1192. char addr_str[100];
  1193.  
  1194. char *Hex_Addr_Str (ADDRP a)
  1195. {
  1196.    if (a->Point != 0)
  1197.       {
  1198.       (void) sprintf (addr_str, "%04x%04x.PNT\\%08x", a->Net, a->Node, a->Point);
  1199.       }
  1200.    else (void) sprintf (addr_str, "%04x%04x", a->Net, a->Node);
  1201.    return (addr_str);
  1202. }
  1203.  
  1204. char *Full_Addr_Str (ADDRP a)
  1205. {
  1206.    char t1[10];
  1207.    char t2[30];
  1208.    char t3[10];
  1209.    char t4[50];
  1210.  
  1211.    if (a->Zone && !no_zones)
  1212.       (void) sprintf (t1, "%u:", a->Zone);
  1213.    else
  1214.       t1[0] = '\0';
  1215.  
  1216.    (void) sprintf (t2, "%u/%u", a->Net, a->Node);
  1217.  
  1218.    if (a->Point)
  1219.       (void) sprintf (t3, ".%u", a->Point);
  1220.    else
  1221.       t3[0] = '\0';
  1222.  
  1223.    if (a->Domain != NULL)
  1224.       (void) sprintf (t4, "@%s", a->Domain);
  1225.    else
  1226.       t4[0] = '\0';
  1227.  
  1228.    (void) strcpy (addr_str, t1);
  1229.    (void) strcat (addr_str, t2);
  1230.    (void) strcat (addr_str, t3);
  1231.    (void) strcat (addr_str, t4);
  1232.    return (addr_str);
  1233. }
  1234.  
  1235. unsigned int crc_block(unsigned char *ptr, int count)
  1236. {
  1237.    unsigned int crc;
  1238.    int i;
  1239.  
  1240.    for (crc = 0, i = 0; i < count; i++, ptr++)
  1241.       {
  1242.       crc = xcrc (crc, (byte) *ptr);
  1243.       }
  1244.    return (crc & 0xFFFF);
  1245. }
  1246.  
  1247. void Data_Check (XMDATAP xtmp, int mode)
  1248. {
  1249.   int i;
  1250.   unsigned char cs;
  1251.   unsigned char *cp;
  1252.   unsigned int cs1;
  1253.  
  1254.   /* If we are in checksum mode, just do it */
  1255.   if (mode == CHECKSUM)
  1256.     {
  1257.     cp = xtmp->data_bytes;
  1258.     cs = 0;
  1259.     for (i = 0; i < 128; i++)
  1260.       {
  1261.       cs += *cp++;
  1262.       }
  1263.     xtmp->data_check[0] = cs;
  1264.     }
  1265.   /* If we are in CRC mode, run the characters through the CRC calculator */
  1266.   else
  1267.     {
  1268.     cs1 = crc_block (xtmp->data_bytes, 128);
  1269.     xtmp->data_check[0] = (unsigned char) (cs1 >> 8);
  1270.     xtmp->data_check[1] = (unsigned char) (cs1 & 0xff);
  1271.     }
  1272. }
  1273.  
  1274.