chiark
/
gitweb
/
~mdw
/
mLib
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
3fd896a
)
New custom trace output interface.
author
mdw
<mdw>
Sat, 3 Feb 2001 16:23:55 +0000
(16:23 +0000)
committer
mdw
<mdw>
Sat, 3 Feb 2001 16:23:55 +0000
(16:23 +0000)
trace.c
patch
|
blob
|
blame
|
history
trace.h
patch
|
blob
|
blame
|
history
diff --git
a/trace.c
b/trace.c
index 9e1cf0f11fc3b08dd248fd4bc27140f7dd568850..749b4ab75fe8678a7b7181c8fc0d546d2cf6b44e 100644
(file)
--- a/
trace.c
+++ b/
trace.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: trace.c,v 1.
5 1999/10/22 22:39:52
mdw Exp $
+ * $Id: trace.c,v 1.
6 2001/02/03 16:23:55
mdw Exp $
*
* Tracing functions for debugging
*
*
* Tracing functions for debugging
*
@@
-30,6
+30,9
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: trace.c,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: trace.c,v $
+ * Revision 1.6 2001/02/03 16:23:55 mdw
+ * New custom trace output interface.
+ *
* Revision 1.5 1999/10/22 22:39:52 mdw
* New documented interface for tracing.
*
* Revision 1.5 1999/10/22 22:39:52 mdw
* New documented interface for tracing.
*
@@
-59,16
+62,37
@@
/* --- Local headers --- */
/* --- Local headers --- */
+#include "dstr.h"
#include "quis.h"
#include "trace.h"
/*----- Private state information -----------------------------------------*/
#include "quis.h"
#include "trace.h"
/*----- Private state information -----------------------------------------*/
-static FILE *tracefp = 0; /* Where does debugging go? */
+static void (*tracefunc)(const char *buf, size_t sz, void *v) = 0;
+static void *tracearg;
static unsigned tracelvl = 0; /* How much tracing gets done? */
/*----- Functions provided ------------------------------------------------*/
static unsigned tracelvl = 0; /* How much tracing gets done? */
/*----- Functions provided ------------------------------------------------*/
+/* --- @t_file@ --- *
+ *
+ * Arguments: @const char *buf@ = buffer to print
+ * @size_t sz@ = buffer size
+ * @void *v@ = file handle
+ *
+ * Returns: ---
+ *
+ * Use: Dumps tracing information to a file.
+ */
+
+static void t_file(const char *buf, size_t sz, void *v)
+{
+ FILE *fp = v;
+ fprintf(fp, "+ %s: ", QUIS);
+ fwrite(buf, 1, sz, fp);
+ fputc('\n', fp);
+}
+
/* --- @trace@ --- *
*
* Arguments: @unsigned l@ = trace level for output
/* --- @trace@ --- *
*
* Arguments: @unsigned l@ = trace level for output
@@
-83,14
+107,14
@@
static unsigned tracelvl = 0; /* How much tracing gets done? */
void trace(unsigned l, const char *f, ...)
{
va_list ap;
void trace(unsigned l, const char *f, ...)
{
va_list ap;
+ dstr d = DSTR_INIT;
if ((l & tracing()) == 0)
return;
va_start(ap, f);
if ((l & tracing()) == 0)
return;
va_start(ap, f);
- fprintf(tracefp, "*** %s: ", QUIS);
- vfprintf(tracefp, f, ap);
+ dstr_vputf(&d, f, ap);
va_end(ap);
va_end(ap);
-
putc('\n', tracefp
);
-
fflush(tracefp
);
+
tracefunc(d.buf, d.len, tracearg
);
+
dstr_destroy(&d
);
}
/* --- @trace_block@ --- *
}
/* --- @trace_block@ --- *
@@
-110,6
+134,7
@@
void trace_block(unsigned l, const char *s, const void *b, size_t sz)
const unsigned char *p = b;
size_t i;
unsigned long o = 0;
const unsigned char *p = b;
size_t i;
unsigned long o = 0;
+ dstr d = DSTR_INIT;
size_t c;
/* --- Skip if the trace level is too high --- */
size_t c;
/* --- Skip if the trace level is too high --- */
@@
-119,28
+144,29
@@
void trace_block(unsigned l, const char *s, const void *b, size_t sz)
/* --- Now start work --- */
/* --- Now start work --- */
- fprintf(tracefp, "*** %s: %s\n", QUIS, s);
-
+ tracefunc(s, strlen(s), tracearg);
while (sz) {
while (sz) {
- fprintf(tracefp, "*** %s: %08lx : ", QUIS, o);
+ dstr_reset(&d);
+ dstr_putf(&d, " %08lx : ", o);
for (i = 0; i < 8; i++) {
if (i < sz)
for (i = 0; i < 8; i++) {
if (i < sz)
-
fprintf(tracefp
, "%02x ", p[i]);
+
dstr_putf(&d
, "%02x ", p[i]);
else
else
-
fputs("** ", tracefp
);
+
dstr_puts(&d, "** "
);
}
}
-
fputs(": ", tracefp
);
+
dstr_puts(&d, ": "
);
for (i = 0; i < 8; i++) {
if (i < sz)
for (i = 0; i < 8; i++) {
if (i < sz)
-
fputc(isprint(p[i]) ? p[i] : '.', tracefp
);
+
dstr_putc(&d, isprint(p[i]) ? p[i] : '.'
);
else
else
-
fputc('*', tracefp
);
+
dstr_putc(&d, '*'
);
}
}
- fputc('\n', tracefp);
+ dstr_putz(&d);
+ tracefunc(d.buf, d.len, tracearg);
c = (sz >= 8) ? 8 : sz;
sz -= c, p += c, o += c;
}
c = (sz >= 8) ? 8 : sz;
sz -= c, p += c, o += c;
}
-
fflush(tracefp
);
+
dstr_destroy(&d
);
}
/* --- @trace_on@ --- *
}
/* --- @trace_on@ --- *
@@
-155,12
+181,32
@@
void trace_block(unsigned l, const char *s, const void *b, size_t sz)
void trace_on(FILE *fp, unsigned l)
{
void trace_on(FILE *fp, unsigned l)
{
- tracefp = fp;
+ tracefunc = t_file;
+ tracearg = fp;
if (!tracelvl)
tracelvl = l;
}
if (!tracelvl)
tracelvl = l;
}
-/* --- @trace_setLevel@ --- *
+/* --- @trace_custom@ --- *
+ *
+ * Arguments: @void (*func)(const char *buf, size_t sz, void *v)@ =
+ * output function
+ * @void *v@ = magic handle to give to function
+ *
+ * Returns: ---
+ *
+ * Use: Sets up a custom trace handler.
+ */
+
+void trace_custom(void (*func)(const char */*buf*/,
+ size_t /*sz*/, void */*v*/),
+ void *v)
+{
+ tracefunc = func;
+ tracearg = v;
+}
+
+/* --- @trace_level@ --- *
*
* Arguments: @unsigned l@ = trace level to set
*
*
* Arguments: @unsigned l@ = trace level to set
*
@@
-169,7
+215,7
@@
void trace_on(FILE *fp, unsigned l)
* Use: Sets the tracing level.
*/
* Use: Sets the tracing level.
*/
-void trace_
setL
evel(unsigned l)
+void trace_
l
evel(unsigned l)
{
tracelvl = l;
}
{
tracelvl = l;
}
@@
-185,7
+231,7
@@
void trace_setLevel(unsigned l)
unsigned tracing(void)
{
unsigned tracing(void)
{
- return (tracef
p
? tracelvl : 0u);
+ return (tracef
unc
? tracelvl : 0u);
}
/*----- That's all, folks -------------------------------------------------*/
}
/*----- That's all, folks -------------------------------------------------*/
diff --git
a/trace.h
b/trace.h
index 6ebc0648d8136c301cb95e04b76d81b785a62df6..c78ba8ff06396b129967eed6e564e2c303623c6a 100644
(file)
--- a/
trace.h
+++ b/
trace.h
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: trace.h,v 1.
5 1999/12/10 23:42:04
mdw Exp $
+ * $Id: trace.h,v 1.
6 2001/02/03 16:23:55
mdw Exp $
*
* Tracing functions for debugging
*
*
* Tracing functions for debugging
*
@@
-30,6
+30,9
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: trace.h,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: trace.h,v $
+ * Revision 1.6 2001/02/03 16:23:55 mdw
+ * New custom trace output interface.
+ *
* Revision 1.5 1999/12/10 23:42:04 mdw
* Change header file guard names.
*
* Revision 1.5 1999/12/10 23:42:04 mdw
* Change header file guard names.
*
@@
-108,6
+111,21
@@
extern void trace_block(unsigned /*l*/, const char */*s*/,
extern void trace_on(FILE */*fp*/, unsigned /*l*/);
extern void trace_on(FILE */*fp*/, unsigned /*l*/);
+/* --- @trace_custom@ --- *
+ *
+ * Arguments: @void (*func)(const char *buf, size_t sz, void *v)@ =
+ * output function
+ * @void *v@ = magic handle to give to function
+ *
+ * Returns: ---
+ *
+ * Use: Sets up a custom trace handler.
+ */
+
+extern void trace_custom(void (*/*func*/)(const char */*buf*/,
+ size_t /*sz*/, void */*v*/),
+ void */*v*/);
+
/* --- @trace_level@ --- *
*
* Arguments: @unsigned l@ = trace level to set
/* --- @trace_level@ --- *
*
* Arguments: @unsigned l@ = trace level to set
@@
-132,7
+150,7
@@
extern unsigned tracing(void);
/* --- @traceopt@ --- *
*
/* --- @traceopt@ --- *
*
- * Arguments: @trace_opt *t@ = pointer to trace options table
+ * Arguments: @
const
trace_opt *t@ = pointer to trace options table
* @const char *p@ = option string supplied by user
* @unsigned f@ = initial tracing flags
* @unsigned bad@ = forbidden tracing flags
* @const char *p@ = option string supplied by user
* @unsigned f@ = initial tracing flags
* @unsigned bad@ = forbidden tracing flags
@@
-144,7
+162,7
@@
extern unsigned tracing(void);
* `?' character, a help message is displayed.
*/
* `?' character, a help message is displayed.
*/
-extern unsigned traceopt(trace_opt */*t*/, const char */*p*/,
+extern unsigned traceopt(
const
trace_opt */*t*/, const char */*p*/,
unsigned /*f*/, unsigned /*bad*/);
/*----- Tracing macros ----------------------------------------------------*/
unsigned /*f*/, unsigned /*bad*/);
/*----- Tracing macros ----------------------------------------------------*/