home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / sharedmem / part01 / src / cm_util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-17  |  2.0 KB  |  108 lines

  1. /* utilities */
  2.  
  3. #include <stdio.h>
  4. #include <strings.h>
  5. #include <ctype.h>
  6. #include <varargs.h>
  7.  
  8. /* uh-oh, looks like Lisp has a bcopy too! */
  9. /* and it doesn't do the same thing as the C bcopy!  */
  10. /* Now who wants to know how long this took me to find? */
  11. static bcopy(s1,s2,length)
  12. char *s1, *s2;
  13. int length;
  14. {
  15.     while (0 < length--) *s2++ = *s1++;
  16. }
  17.  
  18. void
  19. safebcopy(b1,b2,length)
  20. char *b1, *b2;
  21. int length;
  22. {
  23.     eprintf(9,"safebcopy(%x,%x,%d)\n",b1,b2,length);
  24.     if (!b1) {
  25.     printf("error: bcopy dest is null ptr\n");
  26.     abort();
  27.     } else if (!b2) {
  28.     printf("error: bcopy src is null ptr\n");
  29.     abort();
  30.     } else bcopy(b1,b2,length);
  31. }
  32.  
  33. /* dump first 20 bytes starting at s in hex */
  34. hex20(s)
  35. char *s;
  36. {
  37.     int i;
  38.     for (i=0;i<20;i++) printf("%2x",0xff & s[i]);
  39.     putchar('\n');
  40. }
  41.  
  42. /* dump length bytes worth of s in ascii */
  43. ascii_dump(s,length)
  44. char *s;
  45. int length;
  46. {
  47.     int i;
  48.     for (i=0;i<length;i++) {
  49.         if (isascii(s[i]) && isprint(s[i])) {
  50.             printf(" %c",s[i]);
  51.         } else {
  52.             printf(" %02x",0xff & s[i]);
  53.         }
  54.     }
  55.     putchar('/n');
  56. }
  57.  
  58. int cm_debug_level;       /* controls how many debugging statements are
  59.                 /* printed.  0 means none, higher numbers mean
  60.                 /* more. */
  61. /* levels are:
  62. 0    nothing
  63. 1
  64. 2    msgs send/received
  65. 3    msgs init, aborted
  66. 4
  67. 5    slots composed, decomposed
  68. 6    slots broken out
  69. 7
  70. 8
  71. 9    bcopy, strcpy, malloc
  72. */
  73. set_cm_debug_level(level)
  74. int level;
  75. {
  76.     cm_debug_level = level;
  77.     eprintf(1,"cm debug level is %d\n",cm_debug_level);
  78. }
  79.  
  80.  
  81. /* Debugging function, use like printf, but the global var debug_level */
  82. /* controls how much is printed */
  83. #if 0
  84. /* Yes, I know its gross */
  85. /*VARARGS2*/
  86. eprintf(level,fmt,v1,v2,v3,v4,v5,v6,v7,v8,v9)
  87. int level;
  88. char *fmt;
  89. int v1, v2, v3, v4, v5, v6, v7, v8, v9;
  90. {
  91.     if (cm_debug_level >= level) printf(fmt,v1,v2,v3,v4,v5,v6,v7,v8,v9);
  92. }
  93. #endif
  94.  
  95. /*VARARGS2*/
  96. eprintf(level,fmt,va_alist)
  97. int level;
  98. char *fmt;
  99. va_dcl
  100. {
  101.     va_list pvar;
  102.  
  103.     va_start(pvar);
  104.     /* & may be incorrect in following statement */
  105.     if (cm_debug_level >= level) _doprnt(fmt,pvar,stderr);
  106.     va_end(pvar);
  107. }
  108.