home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / trn_12.zip / src / threads.c < prev    next >
C/C++ Source or Header  |  1993-12-04  |  3KB  |  152 lines

  1. /* $Id: threads.c,v 2.3 1992/12/14 00:14:08 davison Trn $
  2. */
  3.  
  4. #include "EXTERN.h"
  5. #include "common.h"
  6. #include "INTERN.h"
  7. #include "threads.h"
  8.  
  9. #ifdef USETHREADS
  10.  
  11. extern char *threaddir;
  12.  
  13. /* Change a newsgroup name into the name of the thread data file.  We
  14. ** subsitute any '.'s in the group name into '/'s (unless LONG_THREAD_NAMES
  15. ** is defined), prepend the path, and append the '/.thread' (or '.th') on to
  16. ** the end.
  17. */
  18. char *
  19. thread_name(group)
  20. char *group;
  21. {
  22.     static char name_buff[MAXFILENAME];
  23. #ifndef LONG_THREAD_NAMES
  24.     char group_buff[512];
  25.     register char *ptr;
  26.  
  27.     strcpy(group_buff, group);
  28.     ptr = group = group_buff;
  29.     while ((ptr = index(ptr, '.'))) {
  30.     *ptr = '/';
  31.     }
  32. #endif
  33. #ifdef SUFFIX
  34.     sprintf(name_buff, "%s/%s%s", threaddir, group, SUFFIX);
  35. #else
  36.     sprintf(name_buff, "%s/%s", threaddir, group);
  37. #endif
  38.  
  39.     return name_buff;
  40. }
  41.  
  42. /* Determine this machine's byte map for WORDs and LONGs.  A byte map is an
  43. ** array of BYTEs (sizeof (WORD) or sizeof (LONG) of them) with the 0th BYTE
  44. ** being the byte number of the high-order byte in my <type>, and so forth.
  45. */
  46. void
  47. mybytemap(map)
  48. BMAP *map;
  49. {
  50.     union {
  51.     BYTE b[sizeof (LONG)];
  52.     WORD w;
  53.     LONG l;
  54.     } u;
  55.     register BYTE *mp;
  56.     register int i, j;
  57.  
  58.     mp = &map->w[sizeof (WORD)];
  59.     u.w = 1;
  60.     for (i = sizeof (WORD); i > 0; i--) {
  61.     for (j = 0; j < sizeof (WORD); j++) {
  62.         if (u.b[j] != 0) {
  63.         break;
  64.         }
  65.     }
  66.     if (j == sizeof (WORD)) {
  67.         goto bad_news;
  68.     }
  69.     *--mp = j;
  70.     while (u.b[j] != 0 && u.w) {
  71.         u.w <<= 1;
  72.     }
  73.     }
  74.  
  75.     mp = &map->l[sizeof (LONG)];
  76.     u.l = 1;
  77.     for (i = sizeof (LONG); i > 0; i--) {
  78.     for (j = 0; j < sizeof (LONG); j++) {
  79.         if (u.b[j] != 0) {
  80.         break;
  81.         }
  82.     }
  83.     if (j == sizeof (LONG)) {
  84.       bad_news:
  85.         /* trouble -- set both to *something* consistent */
  86.         for (j = 0; j < sizeof (WORD); j++) {
  87.         map->w[j] = j;
  88.         }
  89.         for (j = 0; j < sizeof (LONG); j++) {
  90.         map->l[j] = j;
  91.         }
  92.         return;
  93.     }
  94.     *--mp = j;
  95.     while (u.b[j] != 0 && u.l) {
  96.         u.l <<= 1;
  97.     }
  98.     }
  99. }
  100.  
  101. /* Transform each WORD's byte-ordering in a buffer of the designated length.
  102. */
  103. void
  104. wp_bmap(buf, len)
  105. WORD *buf;
  106. int len;
  107. {
  108.     union {
  109.     BYTE b[sizeof (WORD)];
  110.     WORD w;
  111.     } in, out;
  112.     register int i;
  113.  
  114.     if (word_same) {
  115.     return;
  116.     }
  117.     while (len--) {
  118.     in.w = *buf;
  119.     for (i = 0; i < sizeof (WORD); i++) {
  120.         out.b[my_bmap.w[i]] = in.b[mt_bmap.w[i]];
  121.     }
  122.     *buf++ = out.w;
  123.     }
  124. }
  125.  
  126. /* Transform each LONG's byte-ordering in a buffer of the designated length.
  127. */
  128. void
  129. lp_bmap(buf, len)
  130. LONG *buf;
  131. int len;
  132. {
  133.     union {
  134.     BYTE b[sizeof (LONG)];
  135.     LONG l;
  136.     } in, out;
  137.     register int i;
  138.  
  139.     if (long_same) {
  140.     return;
  141.     }
  142.     while (len--) {
  143.     in.l = *buf;
  144.     for (i = 0; i < sizeof (LONG); i++) {
  145.         out.b[my_bmap.l[i]] = in.b[mt_bmap.l[i]];
  146.     }
  147.     *buf++ = out.l;
  148.     }
  149. }
  150.  
  151. #endif /* USETHREADS */
  152.