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