home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / LO241SRV.ZIP / misc.c < prev    next >
C/C++ Source or Header  |  1998-08-01  |  19KB  |  984 lines

  1.  
  2. // LoraBBS Version 2.41 Free Edition
  3. // Copyright (C) 1987-98 Marco Maccaferri
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include <stdio.h>
  20. #include <ctype.h>
  21. #include <dos.h>
  22. #include <io.h>
  23. #include <share.h>
  24. #include <errno.h>
  25. #include <string.h>
  26. #include <dir.h>
  27. #include <time.h>
  28. #include <stdlib.h>
  29. #include <fcntl.h>
  30. #include <sys\stat.h>
  31.  
  32. #include <conio.h>
  33.  
  34. #define INCL_DOS
  35. #define INCL_VIO
  36. #include <os2.h>
  37.  
  38. #include <cxl\cxlvid.h>
  39. #include <cxl\cxlwin.h>
  40. #include <cxl\cxlkey.h>
  41.  
  42. #include "tc_utime.h"
  43. #include "lsetup.h"
  44. #include "sched.h"
  45. #include "msgapi.h"
  46. #include "externs.h"
  47. #include "prototyp.h"
  48.  
  49. #define isLORA       0x4E
  50. #include "version.h"
  51.  
  52. char *firstchar(char *, char *, int);
  53. extern char *emsi_data_packet;
  54.  
  55. void pokeb (unsigned segment, unsigned offset, unsigned char value);
  56. unsigned char peekb (unsigned segment, unsigned offset);
  57. void VioUpdate (void);
  58.  
  59. extern int errno = 0;
  60.  
  61. int com_online (void)
  62. {
  63.    long t;
  64.  
  65.    if (!config->dcd_timeout)
  66.       return (local_mode || (Com_(0x03) & config->carrier_mask));
  67.  
  68.    if (local_mode || (Com_(0x03) & config->carrier_mask))
  69.       return (-1);
  70.  
  71.    t = timerset (config->dcd_timeout * 100);
  72.    while (!timeup (t)) {
  73.       if (Com_(0x03) & config->carrier_mask)
  74.          return (-1);
  75.    }
  76.  
  77.    return (0);
  78. }
  79.  
  80. int esc_pressed (void)
  81. {
  82.    time_release ();
  83.    if (local_kbd == 0x1B) {
  84.       local_kbd = -1;
  85.       return (1);
  86.    }
  87.  
  88.    return (0);
  89. }
  90.  
  91. /*
  92.    if (kbhit ())
  93.       if (getch () == 0x1B)
  94.      return (1);
  95.  
  96.    return (0);
  97. }
  98. */
  99.  
  100. /* always uses modification time */
  101. int cdecl utime(char *name, struct utimbuf *times)
  102. {
  103.    int handle;
  104.    struct date d;
  105.    struct time t;
  106.    struct ftime ft;
  107.  
  108.    unixtodos(times->modtime, &d, &t);
  109.    ft.ft_tsec = t.ti_sec / 2;
  110.    ft.ft_min = t.ti_min;
  111.    ft.ft_hour = t.ti_hour;
  112.    ft.ft_day = d.da_day;
  113.    ft.ft_month = d.da_mon;
  114.    ft.ft_year = d.da_year - 1980;
  115.    if ((handle = shopen(name, O_RDONLY)) == -1)
  116.       return -1;
  117.  
  118.    setftime(handle, &ft);
  119.    close(handle);
  120.    return 0;
  121. }
  122.  
  123. char *fancy_str(s)
  124. char *s;
  125. {
  126.     int m, flag=0;
  127.  
  128.     if (s == NULL)
  129.        return (NULL);
  130.  
  131.     for(m=0;m<80;m++) {
  132.         if(s[m] == '\0')
  133.             return (s);
  134.                 if(s[m] == ' ' || s[m] == '_' || s[m] == '\'' ||
  135.                    s[m] == '(' || s[m] == '/' || s[m] == '\\')
  136.                 {
  137.             flag=0;
  138.             continue;
  139.         }
  140.         if(flag == 0) {
  141.             s[m]=toupper(s[m]);
  142.             flag=1;
  143.         }
  144.         else
  145.             s[m]=tolower(s[m]);
  146.     }
  147.  
  148.     return (s);
  149. }
  150.  
  151. int dexists (filename)
  152. char *filename;
  153. {
  154.    struct ffblk dta;
  155.  
  156.    return (!findfirst (filename, &dta, FA_DIREC));
  157. }
  158.  
  159. char *get_string(s1, s2)
  160. char *s1, *s2;
  161. {
  162.     int i=0, m=0;
  163.  
  164.     while(s1[m] == ' ')
  165.         m++;
  166.     while(s1[m] != ' ' && s1[m] != '\0')
  167.         s2[i++]=s1[m++];
  168.     s2[i]='\0';
  169.     if(i == 0)
  170.         return(NULL);
  171.     i=0;
  172.     while(s1[m] != '\0')
  173.         s1[i++]=s1[m++];
  174.     s1[i]='\0';
  175.  
  176.     return(s2);
  177. }
  178.  
  179. char *get_fancy_string(s1, s2)
  180. char *s1, *s2;
  181. {
  182.     return(fancy_str(get_string(s1, s2)));
  183. }
  184.  
  185. char *get_number(s1, s2)
  186. char *s1, *s2;
  187. {
  188.     int i=0, m=0;
  189.  
  190.     while(s1[m] == ' ')
  191.         m++;
  192.     while(isdigit(s1[m]) && s1[m] != '\0')
  193.         s2[i++]=s1[m++];
  194.     s2[i]='\0';
  195.     if(i == 0)
  196.         return(NULL);
  197.     i=0;
  198.     while(s1[m] != '\0')
  199.         s1[i++]=s1[m++];
  200.     s1[i]='\0';
  201.  
  202.     return(s2);
  203. }
  204.  
  205. int time_remain()
  206. {
  207.     int this_call, time_gone;
  208.         long t;
  209.  
  210.         this_call=(int)((time(&t) - start_time)/60);
  211.         time_gone=allowed - this_call;
  212. /*
  213.         if(time_gone > config->class[usr_class].max_time)
  214.                 time_gone=config->class[usr_class].max_time-this_call;
  215. */
  216.  
  217.     return(time_gone);
  218. }
  219.  
  220. void show_controls(i)
  221. int i;
  222. {
  223.    XON_ENABLE();
  224.    _BRK_ENABLE();
  225.  
  226.    change_attr(i);
  227.    m_print(bbstxt[B_CONTROLS]);
  228. }
  229.  
  230. word xcrc(crc,b)
  231. unsigned int crc;
  232. unsigned char b;
  233. {
  234.    register newcrc;
  235.    int i;
  236.  
  237.    newcrc = crc ^ ((int)b << 8);
  238.    for(i = 0; i < 8; ++i)
  239.       if(newcrc & 0x8000)
  240.          newcrc = (newcrc << 1) ^ 0x1021;
  241.    else
  242.       newcrc = newcrc << 1;
  243.    return(newcrc & 0xFFFF);
  244. }
  245.  
  246. int get_command_word (dest, len)
  247. char *dest;
  248. {
  249.    char tmp_buf[MAX_CMDLEN];
  250.  
  251.    if (get_string (cmd_string, tmp_buf) == NULL)
  252.       return (0);
  253.  
  254.    tmp_buf[len] = '\0';
  255.    strcpy (dest, tmp_buf);
  256.  
  257.    return (1);
  258. }
  259.  
  260. int get_entire_string (dest, len)
  261. char *dest;
  262. {
  263.    register int m = 0;
  264.    char tmp_buf[MAX_CMDLEN];
  265.  
  266.    while (cmd_string[m] == ' ')
  267.       m++;
  268.  
  269.    if (!cmd_string[m])
  270.       return (0);
  271.  
  272.    strcpy (tmp_buf, &cmd_string[m]);
  273.    tmp_buf[len] = cmd_string[0] = '\0';
  274.    strcpy (dest, tmp_buf);
  275.  
  276.    return (1);
  277. }
  278.  
  279. char get_command_letter ()
  280. {
  281.    register int m = 0;
  282.    char c;
  283.  
  284.    while (cmd_string[m] == ' ')
  285.       m++;
  286.  
  287.    if (!cmd_string[m])
  288.       return (0);
  289.  
  290.    c = cmd_string[m];
  291.    strcpy (cmd_string, &cmd_string[++m]);
  292.  
  293.    return (c);
  294. }
  295.  
  296. char *HoldAreaNameMunge (zone)
  297. int zone;
  298. {
  299.    register char *q;
  300.  
  301.    q = hold_area;
  302.  
  303.    while (*q)
  304.       q++;
  305.  
  306.    if ( *(q - 5) == '.')
  307.       q -= 5;
  308.    else
  309.       q--;
  310.  
  311.    *q = '\0';
  312.    if (zone != (int) config->alias[0].zone && zone) {
  313.       sprintf(q, ".%03x", zone);
  314.       q[4] = '\0';
  315.    }
  316.  
  317. //   mkdir (hold_area);
  318.    strcat (hold_area, "\\");
  319.  
  320.    return (hold_area);
  321. }
  322.  
  323. char *HoldAreaNameMungeCreate (zone)
  324. int zone;
  325. {
  326.    register char *q;
  327.  
  328.    q = hold_area;
  329.  
  330.    while (*q)
  331.       q++;
  332.  
  333.    if ( *(q - 5) == '.')
  334.       q -= 5;
  335.    else
  336.       q--;
  337.  
  338.    *q = '\0';
  339.    if (zone != (int) config->alias[0].zone && zone)
  340.       sprintf(q, ".%03x", zone);
  341.  
  342.    mkdir (hold_area);
  343.    strcat (hold_area, "\\");
  344.  
  345.    return (hold_area);
  346. }
  347.  
  348. char *stristr (s, p)
  349. char *s, *p;
  350. {
  351.    int i, m;
  352.  
  353.    if (s == NULL || p == NULL)
  354.       return (NULL);
  355.  
  356.    m = strlen (p);
  357.  
  358.    for (i = 0; s[i] != '\0'; i++) {
  359.       if (toupper (s[i]) != toupper (*p))
  360.          continue;
  361.       if (!strnicmp (&s[i], p, m))
  362.          break;
  363.    }
  364.  
  365.    if (s[i] != '\0')
  366.       return (&s[i]);
  367.  
  368.    return (NULL);
  369. }
  370.  
  371. void ljstring(char *dest,char *src,int len)
  372. {
  373.    int x;
  374.    char *p;
  375.  
  376.    strncpy(dest,src,len);
  377.    x = strlen(dest);
  378.    p = dest + x;
  379.    while (x < len) {
  380.       *p = ' ';
  381.       p++;
  382.       x++;
  383.    }
  384. }
  385.  
  386. void display_percentage (i, v)
  387. int i, v;
  388. {
  389.    long t;
  390.    char string[16];
  391.  
  392.    if (v)
  393.       t = (i * 100L) / v;
  394.    else
  395.       t = 100;
  396.  
  397.    sprintf (string, "\b\b\b\b%3ld%%", t);
  398.    m_print (string);
  399.  
  400.    UNBUFFER_BYTES ();
  401.    VioUpdate ();
  402. }
  403.  
  404. int is_here (z, ne, no, pp, forward, maxnodes)
  405. int z, ne, no, pp;
  406. struct _fwrd *forward;
  407. int maxnodes;
  408. {
  409.    register int i;
  410.  
  411.    for (i = 0; i < maxnodes; i++)
  412.       if (forward[i].zone == z && forward[i].net == ne && forward[i].node == no && forward[i].point == pp)
  413.          return (i);
  414.  
  415.    return (-1);
  416. }
  417.  
  418. int mail_sort_func (const void *a1, const void *b1)
  419. {
  420.    struct _fwrd *a, *b;
  421.    a = (struct _fwrd *)a1;
  422.    b = (struct _fwrd *)b1;
  423.    if (a->net != b->net)   return (a->net - b->net);
  424.    return ( (int)(a->node - b->node) );
  425. }
  426.  
  427. void parse_netnode (char *netnode, int *zo, int *ne, int *no, int *po)
  428. {
  429.    char *p;
  430.    unsigned short *zone, *net, *node, *point;
  431.  
  432.    zone = (unsigned short *)zo;
  433.    net = (unsigned short *)ne;
  434.    node = (unsigned short *)no;
  435.    point = (unsigned short *)po;
  436.  
  437.    *zone = config->alias[0].zone;
  438.    *net = config->alias[0].net;
  439.    *node = 0;
  440.    *point = 0;
  441.  
  442.    p = netnode;
  443.    while (!isdigit (*p) && *p != '.' && *p)
  444.       p++;
  445.    if (*p == '\0')
  446.       return;
  447.  
  448.    /* If we have a zone (and the caller wants the zone to be passed back).. */
  449.  
  450.    if (strchr(netnode,':') && zone) {
  451.       *zone = (unsigned short)atoi(p);
  452.       p = firstchar(p,":",2);
  453.    }
  454.  
  455.    /* If we have a net number... */
  456.  
  457.    if (p && strchr(netnode,'/') && net) {
  458.       *net=(unsigned short)atoi(p);
  459.       p=firstchar(p,"/",2);
  460.    }
  461.  
  462.    /* We *always* need a node number... */
  463.  
  464.    if (p && node)
  465.       *node=(unsigned short)atoi(p);
  466.  
  467.    /* And finally check for a point number... */
  468.  
  469.    if (p && strchr(netnode,'.') && point) {
  470.       p=firstchar(p,".",2);
  471.  
  472.       if (p)
  473.          *point=(unsigned short)atoi(p);
  474.       else
  475.          *point=0;
  476.    }
  477. }
  478.  
  479. void parse_netnode2 (char *netnode, int *zo, int *ne, int *no, int *po)
  480. {
  481.    char *p;
  482.    short *zone, *net, *node, *point;
  483.  
  484.    zone = (short *)zo;
  485.    net = (short *)ne;
  486.    node = (short *)no;
  487.    point = (short *)po;
  488.  
  489.    p = netnode;
  490.    while (!isdigit (*p) && *p != '.' && *p)
  491.       p++;
  492.    if (*p == '\0')
  493.       return;
  494.  
  495.    /* If we have a zone (and the caller wants the zone to be passed back).. */
  496.  
  497.    if (strchr (netnode, ':')) {
  498.       *zone = (unsigned short)atoi(p);
  499.       p = firstchar(p, ":", 2);
  500.    }
  501.  
  502.    /* If we have a net number... */
  503.  
  504.    if (p && strchr (p, '/')) {
  505.       *net = (unsigned short)atoi (p);
  506.       p = firstchar (p, "/", 2);
  507.    }
  508.    else if (!stricmp (p, "ALL")) {
  509.       *net = -1;
  510.       *node = -1;
  511.       *point = 0;
  512.       return;
  513.    }
  514.  
  515.    /* We *always* need a node number... */
  516.  
  517.    if (p && *p != '.')
  518.       if (!stricmp (p, "ALL"))
  519.          *node = -1;
  520.       else
  521.          *node = (unsigned short)atoi(p);
  522.    else if (p == NULL)
  523.       *node = 0;
  524.  
  525.    /* And finally check for a point number... */
  526.  
  527.    if (p && strchr (p, '.')) {
  528.       if (*p == '.')
  529.          p=firstchar (p, ".", 1);
  530.       else
  531.          p=firstchar (p, ".", 2);
  532.  
  533.       if (p) {
  534.          if (!stricmp (p, "ALL"))
  535.             *point = -1;
  536.          else
  537.             *point = (unsigned short)atoi(p);
  538.       }
  539.       else
  540.          *point = 0;
  541.    }
  542.    else
  543.       *point = 0;
  544. }
  545.  
  546.  
  547. char *firstchar(strng, delim, findword)
  548. char *strng, *delim;
  549. int findword;
  550. {
  551.    int x, isw, sl_d, sl_s, wordno=0;
  552.    char *string, *oldstring;
  553.  
  554.    /* We can't do *anything* if the string is blank... */
  555.  
  556.    if (! *strng)
  557.       return NULL;
  558.  
  559.    string=oldstring=strng;
  560.  
  561.    sl_d=strlen(delim);
  562.  
  563.    for (string=strng;*string;string++)
  564.    {
  565.       for (x=0,isw=0;x <= sl_d;x++)
  566.          if (*string==delim[x])
  567.             isw=1;
  568.  
  569.       if (isw==0) {
  570.          oldstring=string;
  571.          break;
  572.       }
  573.    }
  574.  
  575.    sl_s=strlen(string);
  576.  
  577.    for (wordno=0;(string-oldstring) < sl_s;string++)
  578.    {
  579.       for (x=0,isw=0;x <= sl_d;x++)
  580.          if (*string==delim[x])
  581.          {
  582.             isw=1;
  583.             break;
  584.          }
  585.  
  586.       if (!isw && string==oldstring)
  587.          wordno++;
  588.  
  589.       if (isw && (string != oldstring))
  590.       {
  591.          for (x=0,isw=0;x <= sl_d;x++) if (*(string+1)==delim[x])
  592.          {
  593.             isw=1;
  594.             break;
  595.          }
  596.  
  597.          if (isw==0)
  598.             wordno++;
  599.       }
  600.  
  601.       if (wordno==findword)
  602.          return((string==oldstring || string==oldstring+sl_s) ? string : string+1);
  603.    }
  604.  
  605.    return NULL;
  606. }
  607.  
  608. int scrollbox(int sy,int sx,int ey,int ex,int num,int direction)
  609. {
  610.     register unsigned i,y;
  611.     unsigned p,d,inrow;
  612.  
  613.     inrow=_vinfo.numcols*2;
  614.     d=(ex-sx+1)*2;
  615.  
  616.     if (direction==SUP)
  617.     while (num--) {
  618.         for(y=sy;y<ey;y++) {
  619.         p=((y*_vinfo.numcols)+sx)*2;
  620.         for(i=0;i<d;i++) {
  621.             pokeb(0,p,peekb(0,p+inrow));
  622.             p++;
  623.         }
  624.         }
  625.         p=((y*_vinfo.numcols)+sx)*2;
  626.         d=ex-sx+1;
  627.         for(i=0;i<d;i++) {
  628.         pokeb(0,p++,' ');
  629.         pokeb(0,p++,7);
  630.         }
  631.     }
  632.     else {
  633.     while (num--) {
  634.         for(y=ey;y>sy;y--) {
  635.         p=((y*_vinfo.numcols)+sx)*2;
  636.         for(i=0;i<d;i++) {
  637.             pokeb(0,p,peekb(0,p-inrow));
  638.             p++;
  639.         }
  640.         }
  641.         p=((y*_vinfo.numcols)+sx)*2;
  642.         d=ex-sx+1;
  643.         for(i=0;i<d;i++) {
  644.         pokeb(0,p++,' ');
  645.         pokeb(0,p++,7);
  646.         }
  647.     }
  648.     }
  649.  
  650.     VioUpdate();
  651.  
  652.    /* return with no error */
  653.    return(W_NOERROR);
  654. }
  655.  
  656. int isbundle (char *name)
  657. {
  658.    int i, n;
  659.  
  660.    if ((n = strlen (name)) < 12)
  661.       return (0);
  662.  
  663.    strupr (name);
  664.  
  665.    for (i = n - 12; i < n - 4; i++) {
  666.       if ((!isdigit (name[i])) && ((name[i] > 'F') || (name[i] < 'A')))
  667.          return (0);
  668.    }
  669.  
  670.    return ((strstr (name, ".MO") || strstr (name, ".TU") || strstr (name, ".WE") || strstr (name, ".TH") || strstr (name, ".FR") || strstr (name, ".SA") || strstr (name, ".SU")));
  671. }
  672.  
  673. void release_timeslice ()
  674. {
  675.    DosSleep (5L);
  676. }
  677.  
  678. void stripcrlf (char *linea)
  679. {
  680.    while (linea[strlen (linea) -1] == 0x0D || linea[strlen (linea) - 1] == 0x0A)
  681.       linea[strlen (linea) -1] = '\0';
  682. }
  683.  
  684. FILE *sh_fopen (char *filename, char *access, int shmode)
  685. {
  686.    FILE *fp;
  687.    long t1, t2;
  688.    long time (long *);
  689.  
  690.    t1 = time (NULL);
  691.  
  692.    while (time (NULL) < t1 + 20) {
  693.       if ((fp = _fsopen (filename, access, shmode)) != NULL || errno != EACCES)
  694.          break;
  695.       t2 = time (NULL);
  696.       while (time (NULL) < t2 + 1)
  697.      DosSleep (100L);
  698.    }
  699.  
  700.    return (fp);
  701. }
  702.  
  703. int sh_open (char *file, int shmode, int omode, int fmode)
  704. {
  705.    int i;
  706.    long t1, t2;
  707.    long time (long *);
  708.  
  709.    t1 = time (NULL);
  710.    while (time (NULL) < t1 + 20) {
  711.       if ((i = sopen (file, omode, shmode, fmode)) != -1 || errno != EACCES)
  712.          break;
  713.       t2 = time (NULL);
  714.       while (time (NULL) < t2 + 1)
  715.      DosSleep (100L);
  716.    }
  717.  
  718.    return (i);
  719. }
  720.  
  721. /*---------------------------------------------------------------------------
  722.  
  723. ---------------------------------------------------------------------------*/
  724. char *packet_fgets (dest, max, fp)
  725. char *dest;
  726. int max;
  727. FILE *fp;
  728. {
  729.    int i, c;
  730.  
  731.    i = 0;
  732.  
  733.    while (i < max) {
  734.       if ((c = fgetc (fp)) == EOF) {
  735.          if (i == 0)
  736.             return (NULL);
  737.          else
  738.             break;
  739.       }
  740.  
  741.       dest[i] = (char )c;
  742.       if ((char )c == '\0') {
  743.          if (i > 0)
  744.             ungetc (c, fp);
  745.          break;
  746.       }
  747.  
  748.       i++;
  749.       if ((char )c == 0x0D) {
  750.          if ((c = fgetc (fp)) == 0x0A)
  751.             dest[i++] = (char )c;
  752.          else
  753.             ungetc (c, fp);
  754.          break;
  755.       }
  756.    }
  757.  
  758.    dest[i] = '\0';
  759.    return (dest);
  760. }
  761.  
  762. int m_getch (void)
  763. {
  764.    int i;
  765.  
  766.    if (!local_mode) {
  767.       if (CHAR_AVAIL ())
  768.          return (TIMED_READ (1) & 0xFF);
  769.       if (local_kbd == -1)
  770.          time_release ();
  771.       else {
  772.          i = local_kbd;
  773.          local_kbd = -1;
  774.          return (i);
  775.       }
  776.    }
  777.    else {
  778.       if (local_kbd == -1)
  779.          time_release ();
  780.       else {
  781.          i = local_kbd;
  782.             local_kbd = -1;
  783.             return (i);
  784.         }
  785.     }
  786.  
  787.     return (-1);
  788. }
  789.  
  790. int get_emsi_field (char *s)
  791. {
  792.     char c;
  793.     int i = 0, start = 0, value;
  794.     long t;
  795.  
  796.     t = timerset (100);
  797.  
  798.     while (CARRIER && !timeup (t)) {
  799.         while (PEEKBYTE () == -1) {
  800.             if (!CARRIER || timeup (t))
  801.                 return (0);
  802.         }
  803.  
  804.         c = (char)TIMED_READ (1);
  805.         t = timerset (100);
  806.  
  807.         if (!start && c != '{')
  808.             continue;
  809.  
  810.         if (c == '{' && !start) {
  811.             start = 1;
  812.             continue;
  813.         }
  814.  
  815.         if (c == '}' && start) {
  816.             if (PEEKBYTE () != '}')
  817.                 break;
  818.             else
  819.                 c = (char)TIMED_READ (1);
  820.         }
  821.  
  822.         if (c == ']') {
  823.             if (PEEKBYTE () == ']')
  824.                 c = (char)TIMED_READ (1);
  825.         }
  826.  
  827.         if (c == '\\') {
  828.             if ((c = (char)TIMED_READ (1)) != '\\') {
  829.                 c = toupper (c);
  830.                 value = (c >= 'A') ? (c - 55) : (c - '0');
  831.                 value *= 16;
  832.                 c = (char)TIMED_READ (1);
  833.                 c = toupper (c);
  834.                 value += (c >= 'A') ? (c - 55) : (c - '0');
  835.                 c = (char)value;
  836.             }
  837.         }
  838.  
  839.         s[i++] = c;
  840.     }
  841.  
  842.     s[i] = '\0';
  843.     return (1);
  844. }
  845.  
  846. #define x32crc(c,crc) (cr3tab[((int) crc ^ c) & 0xff] ^ ((crc >> 8) & 0x00FFFFFFL))
  847.  
  848. unsigned long get_buffer_crc (void *buffer, int length)
  849. {
  850.     int i;
  851.     unsigned long crc = 0xFFFFFFFFL;
  852.     unsigned char *b;
  853.  
  854.     b = (unsigned char *)buffer;
  855.  
  856.    for (i = 0; i < length; i++)
  857.       crc = x32crc (*b++, crc);
  858.  
  859.    return (crc);
  860. }
  861.  
  862. int open_packet (int zone, int net, int node, int point, int ai)
  863. {
  864.    int mi;
  865.    char buff[80], *p;
  866.    struct _pkthdr2 pkthdr;
  867.  
  868.    p = HoldAreaNameMungeCreate (zone);
  869.    if (point)
  870.       sprintf (buff, "%s%04x%04x.PNT\\%08X.XPR", p, net, node, point);
  871.    else
  872.       sprintf (buff, "%s%04x%04x.XPR", p, net, node);
  873.  
  874.    mi = open (buff, O_RDWR|O_CREAT|O_BINARY, S_IREAD|S_IWRITE);
  875.    if (mi == -1 && point) {
  876.       sprintf (buff, "%s%04x%04x.PNT", p, net, node);
  877.       mkdir (buff);
  878.       sprintf (buff, "%s%04x%04x.PNT\\%08X.XPR", p, net, node, point);
  879.       mi = open (buff, O_RDWR|O_CREAT|O_BINARY, S_IREAD|S_IWRITE);
  880.    }
  881.  
  882.    if (filelength (mi) > 0L)
  883.       lseek (mi, filelength (mi) - 2, SEEK_SET);
  884.    else {
  885.       memset ((char *)&pkthdr, 0, sizeof (struct _pkthdr2));
  886.       pkthdr.ver = PKTVER;
  887.       pkthdr.product = 0x4E;
  888.       pkthdr.serial = ((MAJVERSION << 4) | MINVERSION);
  889.       pkthdr.capability = 1;
  890.       pkthdr.cwvalidation = 256;
  891.       if (config->alias[ai].point && config->alias[ai].fakenet) {
  892.          pkthdr.orig_node = config->alias[ai].point;
  893.          pkthdr.orig_net = config->alias[ai].fakenet;
  894.          pkthdr.orig_point = 0;
  895.       }
  896.       else {
  897.          pkthdr.orig_node = config->alias[ai].node;
  898.          pkthdr.orig_net = config->alias[ai].net;
  899.          pkthdr.orig_point = config->alias[ai].point;
  900.       }
  901.       pkthdr.orig_zone = config->alias[ai].zone;
  902.       pkthdr.orig_zone2 = config->alias[ai].zone;
  903.  
  904.       pkthdr.dest_point = point;
  905.       pkthdr.dest_node = node;
  906.       pkthdr.dest_net = net;
  907.       pkthdr.dest_zone = zone;
  908.       pkthdr.dest_zone2 = zone;
  909.  
  910.       add_packet_pw (&pkthdr);
  911.       write (mi, (char *)&pkthdr, sizeof (struct _pkthdr2));
  912.    }
  913.  
  914.    return (mi);
  915. }
  916.  
  917. int prep_match (char *template, char *dep)
  918. {
  919.    register int i,delim;
  920.    register char *sptr;
  921.    int start;
  922.  
  923.    memset (dep, 0, 15);
  924.    sptr = template;
  925.  
  926.    for(start=i=0; sptr[i]; i++)
  927.       if ((sptr[i]=='\\') || (sptr[i]==':'))
  928.          start = i+1;
  929.  
  930.    if(start)
  931.       sptr += start;
  932.    delim = 8;
  933.  
  934.    strupr(sptr);
  935.  
  936.    for(i=0; *sptr && i < 12; sptr++)
  937.       switch(*sptr) {
  938.          case '.':
  939.             if (i>8)
  940.                return(-1);
  941.             while(i<8)
  942.                dep[i++] = ' ';
  943.             dep[i++] = *sptr;
  944.             delim = 12;
  945.             break;
  946.          case '*':
  947.             while(i<delim)
  948.                dep[i++] = '?';
  949.             break;
  950.          default:
  951.             dep[i++] = *sptr;
  952.             break;
  953.       }
  954.  
  955.    while(i<12) {
  956.       if (i == 8)
  957.          dep[i++] = '.';
  958.       else
  959.          dep[i++] = ' ';
  960.    }
  961.    dep[i] = '\0';
  962.  
  963.    return 0;
  964. }
  965.  
  966. int match (char *s1, char *s2)
  967. {
  968.    register char *i,*j;
  969.  
  970.    i = s1;
  971.    j = s2;
  972.  
  973.    while(*i) {
  974.       if((*j != '?') && (*i != *j))
  975.          return(1);
  976.       i++;
  977.       j++;
  978.    }
  979.  
  980.    return 0;
  981. }
  982.  
  983.  
  984.