1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
/* This file is part of the debugging module DEBUG.
Written by Dick Grune, Vrije Universiteit, Amsterdam.
$Id: debug.c,v 1.8 2017-12-08 18:07:16 Gebruiker Exp $
*/
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include "debug.h"
/*Library module source prelude */
#undef _MODULE_CODE_
#ifndef lint
#define _MODULE_CODE_
#endif
#ifdef LIB
#define _MODULE_CODE_
#endif
#ifdef _MODULE_CODE_
/* Library module source code */
#ifdef DEBUG
static void
wr_char(char ch) {
write(2, &ch, 1);
}
static void
wr_str(const char *s) {
while (*s) {
wr_char(*s++);
}
}
static void
wr_num(int b,int v) {
if (v >= b) {
wr_num(b, v/b);
}
wr_char("0123456789ABCDEF"[v%b]);
}
void
wr_info(const char *s, int v) {
/* print the string */
if (s) {
int cnt = 0;
while (*s) {
int ch = *s++ &0377;
/* cut short a possibly corrupted string */
if (cnt++ > 50) {
wr_str("...");
break;
}
/* put not thy faith in chars, signed or unsigned */
if (isprint(ch)) {
wr_char(ch);
}
else {
switch (ch) {
case '\n': wr_str("\\n"); break;
case '\t': wr_str("\\t"); break;
case '\r': wr_str("\\r"); break;
case '\f': wr_str("\\f"); break;
default:
wr_char('\\');
wr_char(ch / 0100 % 010 + '0');
wr_char(ch / 010 % 010 + '0');
wr_char(ch / 01 % 010 + '0');
break;
}
}
}
}
else {
wr_str("<wr_info: NO STRING>");
}
/* print the value */
wr_char(' ');
if (v < 0) {
wr_char('-');
v = -v;
}
wr_num(10, v);
wr_char('\n');
}
#else
/*ARGSUSED*/
void
wr_info(const char *s, int v) {
}
#endif /* DEBUG */
/* End library module source code */
#endif /* _MODULE_CODE_ */
#ifdef lint
static void
satisfy_lint(void *x) {
wr_info((char *)x, 0);
satisfy_lint(x);
}
#endif /* lint */
|