home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / trn / part02 / threads.c < prev   
Encoding:
C/C++ Source or Header  |  1991-12-02  |  2.9 KB  |  157 lines

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