Add some debug prints to the C side
This commit is contained in:
parent
541f2e1769
commit
1792ddc8ae
53
src/event.c
53
src/event.c
|
@ -5,6 +5,8 @@
|
|||
* functions to lookup and execute events.
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "unroff.h"
|
||||
|
||||
#define NUM_VEC_EVENTS 6
|
||||
|
@ -42,6 +44,28 @@ static char *event_names[] = {
|
|||
"character event",
|
||||
};
|
||||
|
||||
int debug_flag = 0;
|
||||
|
||||
void debug_printf(const char *format, ...) {
|
||||
va_list ap;
|
||||
|
||||
if (!debug_flag) return;
|
||||
va_start(ap, format);
|
||||
vfprintf(stderr, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void debug_string(const char *bytes, int nbytes) {
|
||||
char *string;
|
||||
|
||||
if (!debug_flag) return;
|
||||
string = safe_malloc(nbytes + 1);
|
||||
memcpy(string, bytes, nbytes);
|
||||
string[nbytes] = '\0';
|
||||
debug_printf("%s", string);
|
||||
free(string);
|
||||
}
|
||||
|
||||
static Object make_event_object(Object x) {
|
||||
switch (TYPE(x)) {
|
||||
case T_Null:
|
||||
|
@ -64,6 +88,9 @@ static Object store_event(Table *tp, char *key, int size, Object obj,
|
|||
Elem *oldp;
|
||||
Object ret = False;
|
||||
|
||||
debug_printf("store_event ");
|
||||
debug_string(key, size);
|
||||
debug_printf("\n");
|
||||
if ((oldp = table_lookup(tp, key, size)) != 0)
|
||||
ret = get_object(oldp->obj);
|
||||
if (!Nullp(obj)) {
|
||||
|
@ -184,9 +211,35 @@ Object p_chardef(Object key) {
|
|||
return def_char_event(chars, key, Null);
|
||||
}
|
||||
|
||||
const char *event_name(Event e) {
|
||||
switch (e) {
|
||||
#define ENAME(x) case x: return #x;
|
||||
ENAME(EV_REQUEST);
|
||||
ENAME(EV_MACRO);
|
||||
ENAME(EV_STRING);
|
||||
ENAME(EV_NUMREG);
|
||||
ENAME(EV_SPECIAL);
|
||||
ENAME(EV_ESCAPE);
|
||||
ENAME(EV_CHAR);
|
||||
ENAME(EV_EQUATION);
|
||||
ENAME(EV_SENTENCE);
|
||||
ENAME(EV_LINE);
|
||||
ENAME(EV_PROLOG);
|
||||
ENAME(EV_EPILOG);
|
||||
ENAME(EV_OPTION);
|
||||
ENAME(EV_START);
|
||||
ENAME(EV_EXIT);
|
||||
#undef ENAME
|
||||
}
|
||||
return "???";
|
||||
}
|
||||
|
||||
Elem *event_lookup(Event e, char *key, int size) {
|
||||
Elem *p;
|
||||
|
||||
debug_printf("event_lookup %s ", event_name(e));
|
||||
debug_string(key, size);
|
||||
debug_printf("\n");
|
||||
if (key && size == 0) {
|
||||
switch(e) {
|
||||
case EV_REQUEST:
|
||||
|
|
Loading…
Reference in New Issue