From 4fcecb856a04d94bf82d0183e734430fb24295b8 Mon Sep 17 00:00:00 2001 From: Sebastian Geerken Date: Sun, 8 May 2016 13:26:14 +0200 Subject: RTFL. --- dw/textblock.cc | 22 ++++++----------- dw/widget.cc | 71 ++++++++++++++++++------------------------------------ lout/debug_rtfl.hh | 64 ++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 87 insertions(+), 70 deletions(-) diff --git a/dw/textblock.cc b/dw/textblock.cc index 13df376c..391e660a 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -794,8 +794,7 @@ int Textblock::getAvailWidthOfChild (Widget *child, bool forceValue) } } - DBG_OBJ_MSGF ("resize", 1, "=> %d", width); - DBG_OBJ_LEAVE (); + DBG_OBJ_LEAVE_VAL ("%d", width); return width; } @@ -838,8 +837,7 @@ bool Textblock::affectsSizeChangeContainerChild (Widget *child) else ret = Widget::affectsSizeChangeContainerChild (child); - DBG_OBJ_MSGF ("resize", 1, "=> %s", ret ? "true" : "false"); - DBG_OBJ_LEAVE (); + DBG_OBJ_LEAVE_VAL ("%s", boolToStr(ret)); return ret; } @@ -1158,8 +1156,7 @@ bool Textblock::sendSelectionEvent (core::SelectionState::EventType eventType, r = selectionHandleEvent (eventType, it, charPos, link, event); it->unref (); - DBG_OBJ_MSGF ("events", 1, "=> %s", r ? "true" : "false"); - DBG_OBJ_LEAVE (); + DBG_OBJ_LEAVE_VAL ("%s", boolToStr(r)); return r; } @@ -1620,9 +1617,7 @@ int Textblock::findLineIndex (int y, int ascent) * That function has now been inlined into Dw_page_motion_notify() --JV */ - DBG_OBJ_MSGF ("events", 1, "=> %d", low); - DBG_OBJ_LEAVE (); - + DBG_OBJ_LEAVE_VAL ("%d", low); return low; } @@ -2508,8 +2503,7 @@ bool Textblock::addAnchor (const char *name, core::style::Style *style) result = true; } - DBG_OBJ_MSGF ("construct.word", 0, "=> %s", result ? "true" : "false"); - DBG_OBJ_LEAVE (); + DBG_OBJ_LEAVE_VAL ("%s", boolToStr(result)); return result; } @@ -2857,8 +2851,7 @@ core::Widget *Textblock::getWidgetAtPointLevel (int x, int y, int level, break; } - DBG_OBJ_MSGF ("events", 1, "=> %p", widgetAtPoint); - DBG_OBJ_LEAVE (); + DBG_OBJ_LEAVE_VAL ("%p", widgetAtPoint); return widgetAtPoint; } @@ -3165,8 +3158,7 @@ RegardingBorder *Textblock::getWidgetRegardingBorderForLine (int firstWord, } } - DBG_OBJ_MSGF ("resize", 1, "=> %p", widgetRegardingBorder); - DBG_OBJ_LEAVE (); + DBG_OBJ_LEAVE_VAL ("%p", widgetRegardingBorder); return widgetRegardingBorder; } diff --git a/dw/widget.cc b/dw/widget.cc index 324c1687..abd84340 100644 --- a/dw/widget.cc +++ b/dw/widget.cc @@ -24,6 +24,7 @@ using namespace lout; using namespace lout::object; +using namespace lout::misc; namespace dw { namespace core { @@ -184,13 +185,12 @@ bool Widget::intersects (Widget *refWidget, Rectangle *area, } if (r) - DBG_OBJ_MSGF ("draw", 1, "=> true: %d, %d, %d * %d", - intersection->x, intersection->y, - intersection->width, intersection->height); + DBG_OBJ_LEAVE_VAL ("true: %d, %d, %d * %d", + intersection->x, intersection->y, + intersection->width, intersection->height); else - DBG_OBJ_MSG ("draw", 1, "=> false"); + DBG_OBJ_LEAVE_VAL0 ("false"); - DBG_OBJ_LEAVE (); return r; } @@ -450,8 +450,7 @@ bool Widget::affectedByContainerSizeChange () } else ret = container->affectsSizeChangeContainerChild (this); - DBG_OBJ_MSGF ("resize", 1, "=> %s", ret ? "true" : "false"); - DBG_OBJ_LEAVE (); + DBG_OBJ_LEAVE_VAL ("%s", boolToStr(ret)); return ret; } @@ -481,8 +480,7 @@ bool Widget::affectsSizeChangeContainerChild (Widget *child) (child->getStyle()->height == style::LENGTH_AUTO ? child->usesAvailHeight () : false); - DBG_OBJ_MSGF ("resize", 1, "=> %s", ret ? "true" : "false"); - DBG_OBJ_LEAVE (); + DBG_OBJ_LEAVE_VAL ("%s", boolToStr(ret)); return ret; } @@ -619,9 +617,7 @@ int Widget::getMinWidth (Extremes *extremes, bool forceValue) } else minWidth = 0; - DBG_OBJ_MSGF ("resize", 1, "=> %d", minWidth); - DBG_OBJ_LEAVE (); - + DBG_OBJ_LEAVE_VAL ("%d", minWidth); return minWidth; } @@ -663,9 +659,7 @@ int Widget::getAvailWidth (bool forceValue) DBG_OBJ_MSG_END (); } - DBG_OBJ_MSGF ("resize", 1, "=> %d", width); - DBG_OBJ_LEAVE (); - + DBG_OBJ_LEAVE_VAL ("%d", width); return width; } @@ -722,9 +716,7 @@ int Widget::getAvailHeight (bool forceValue) DBG_OBJ_MSG_END (); } - DBG_OBJ_MSGF ("resize", 1, "=> %d", height); - DBG_OBJ_LEAVE (); - + DBG_OBJ_LEAVE_VAL ("%d", height); return height; } @@ -801,10 +793,8 @@ void Widget::correctRequisition (Requisition *requisition, DBG_OBJ_MSG_END (); } - DBG_OBJ_MSGF ("resize", 1, "=> %d * (%d + %d)", - requisition->width, requisition->ascent, - requisition->descent); - DBG_OBJ_LEAVE (); + DBG_OBJ_LEAVE_VAL ("%d * (%d + %d)", requisition->width, requisition->ascent, + requisition->descent); } void Widget::correctExtremes (Extremes *extremes, bool useAdjustmentWidth) @@ -856,9 +846,7 @@ void Widget::correctExtremes (Extremes *extremes, bool useAdjustmentWidth) if (extremes->maxWidth < extremes->minWidth) extremes->maxWidth = extremes->minWidth; - DBG_OBJ_MSGF ("resize", 1, "=> %d / %d", - extremes->minWidth, extremes->maxWidth); - DBG_OBJ_LEAVE (); + DBG_OBJ_LEAVE_VAL ("%d / %d", extremes->minWidth, extremes->maxWidth); } int Widget::calcWidth (style::Length cssValue, int refWidth, Widget *refWidget, @@ -896,8 +884,7 @@ int Widget::calcWidth (style::Length cssValue, int refWidth, Widget *refWidget, width = -1; } - DBG_OBJ_MSGF ("resize", 1, "=> %d", width); - DBG_OBJ_LEAVE (); + DBG_OBJ_LEAVE_VAL ("%d", width); return width; } @@ -926,8 +913,7 @@ void Widget::calcFinalWidth (style::Style *style, int refWidth, if (maxWidth != -1 && *finalWidth == -1 && *finalWidth > maxWidth) *finalWidth = maxWidth; - DBG_OBJ_MSGF ("resize", 1, "=> %d", *finalWidth); - DBG_OBJ_LEAVE (); + DBG_OBJ_LEAVE_VAL ("%d", *finalWidth); } int Widget::calcHeight (style::Length cssValue, bool usePercentage, @@ -972,8 +958,7 @@ int Widget::calcHeight (style::Length cssValue, bool usePercentage, height = -1; } - DBG_OBJ_MSGF ("resize", 1, "=> %d", height); - DBG_OBJ_LEAVE (); + DBG_OBJ_LEAVE_VAL ("%d", height); return height; } @@ -1678,9 +1663,7 @@ int Widget::getAvailWidthOfChild (Widget *child, bool forceValue) } } - DBG_OBJ_MSGF ("resize", 1, "=> %d", width); - DBG_OBJ_LEAVE (); - + DBG_OBJ_LEAVE_VAL ("%d", width); return width; } @@ -1737,9 +1720,7 @@ int Widget::getAvailHeightOfChild (Widget *child, bool forceValue) } } - DBG_OBJ_MSGF ("resize", 1, "=> %d", height); - DBG_OBJ_LEAVE (); - + DBG_OBJ_LEAVE_VAL ("%d", height); return height; } @@ -1796,10 +1777,8 @@ void Widget::correctReqWidthOfChild (Widget *child, Requisition *requisition, child->calcFinalWidth (child->getStyle(), -1, this, limitMinWidth, false, &requisition->width); - DBG_OBJ_MSGF ("resize", 1, "=> %d * (%d + %d)", - requisition->width, requisition->ascent, - requisition->descent); - DBG_OBJ_LEAVE (); + DBG_OBJ_LEAVE_VAL ("%d * (%d + %d)", requisition->width, requisition->ascent, + requisition->descent); } void Widget::correctReqHeightOfChild (Widget *child, Requisition *requisition, @@ -1842,10 +1821,8 @@ void Widget::correctReqHeightOfChild (Widget *child, Requisition *requisition, splitHeightFun (maxHeight, &requisition->ascent, &requisition->descent); - DBG_OBJ_MSGF ("resize", 1, "=> %d * (%d + %d)", - requisition->width, requisition->ascent, - requisition->descent); - DBG_OBJ_LEAVE (); + DBG_OBJ_LEAVE_VAL ("%d * (%d + %d)", requisition->width, requisition->ascent, + requisition->descent); } void Widget::correctExtremesOfChild (Widget *child, Extremes *extremes, @@ -1890,9 +1867,7 @@ void Widget::correctExtremesOfChild (Widget *child, Extremes *extremes, } - DBG_OBJ_MSGF ("resize", 1, "=> %d / %d", - extremes->minWidth, extremes->maxWidth); - DBG_OBJ_LEAVE (); + DBG_OBJ_LEAVE_VAL ("%d / %d", extremes->minWidth, extremes->maxWidth); } /** diff --git a/lout/debug_rtfl.hh b/lout/debug_rtfl.hh index 616424c2..0b2b4322 100644 --- a/lout/debug_rtfl.hh +++ b/lout/debug_rtfl.hh @@ -26,9 +26,14 @@ #ifdef DBG_RTFL +// ======================================= +// Used by all modules +// ======================================= + #include #include #include +#include #define DBG_IF_RTFL if(1) @@ -37,10 +42,11 @@ // Prints an RTFL message to stdout. "fmt" contains simple format // characters how to deal with the additional arguments (no "%" -// preceeding, as in printf), or "c" (short for "#%06x" and used for -// colors), or other characters, which are simply printed. No quoting: -// this function cannot be used to print the characters "d", "p", and -// "s" directly. +// preceeding, as in printf) or "q" (which additionally +// (double-)quotes quotation marks) or "c" (short for "#%06x" and used +// for colors), or other characters, which are simply printed. No +// quoting: this function cannot be used to print the characters "d", +// "p", "s" and "q" directly. inline void rtfl_print (const char *module, const char *version, const char *file, int line, const char *fmt, ...) @@ -77,6 +83,17 @@ inline void rtfl_print (const char *module, const char *version, } break; + case 'q': + s = va_arg (args, char*); + for (int j = 0; s[j]; j++) { + if (s[j] == ':' || s[j] == '\\') + putchar ('\\'); + else if (s[j] == '\"') + printf ("\\\\"); // a quoted quoting character + putchar (s[j]); + } + break; + case 'c': n = va_arg(args, int); printf ("#%06x", n); @@ -98,6 +115,30 @@ inline void rtfl_print (const char *module, const char *version, rtfl_print (module, version, CUR_WORKING_DIR "/" __FILE__, __LINE__, \ "s:" fmt, cmd, __VA_ARGS__) + +// ================================== +// General module +// ================================== + +#define RTFL_GEN_VERSION "1.0" + +#define RTFL_GEN_PRINT(cmd, fmt, ...) \ + RTFL_PRINT ("gen", RTFL_GEN_VERSION, cmd, fmt, __VA_ARGS__) + +#define DBG_GEN_TIME() \ + STMT_START { \ + struct timeval tv; \ + gettimeofday(&tv, NULL); \ + char buf[32]; \ + snprintf (buf, sizeof (buf), "%ld%06ld", tv.tv_sec, tv.tv_usec); \ + RTFL_GEN_PRINT ("time", "s", buf); \ + } STMT_END + + +// ================================== +// Objects module +// ================================== + #define RTFL_OBJ_VERSION "1.0" #define RTFL_OBJ_PRINT(cmd, fmt, ...) \ @@ -197,6 +238,12 @@ inline void rtfl_print (const char *module, const char *version, RTFL_OBJ_PRINT ("leave", "p:s", obj, vals); \ } STMT_END +#define DBG_OBJ_LEAVE_VAL0(val) \ + DBG_OBJ_LEAVE_VAL0_O (this, val) + +#define DBG_OBJ_LEAVE_VAL0_O(obj, val) \ + RTFL_OBJ_PRINT ("leave", "p:s:", obj, val) + #define DBG_OBJ_CREATE(klass) \ DBG_OBJ_CREATE_O (this, klass) @@ -243,7 +290,7 @@ inline void rtfl_print (const char *module, const char *version, DBG_OBJ_SET_STR_O (this, var, val) #define DBG_OBJ_SET_STR_O(obj, var, val) \ - RTFL_OBJ_PRINT ("set", "p:s:\"s\"", obj, var, val) + RTFL_OBJ_PRINT ("set", "p:s:\"q\"", obj, var, val) #define DBG_OBJ_SET_PTR(var, val) \ DBG_OBJ_SET_PTR_O (this, var, val) @@ -279,7 +326,7 @@ inline void rtfl_print (const char *module, const char *version, DBG_OBJ_ARRSET_STR_O (this, var, ind, val) #define DBG_OBJ_ARRSET_STR_O(obj, var, ind, val) \ - RTFL_OBJ_PRINT ("set", "p:s.d:\"s\"", obj, var, ind, val) + RTFL_OBJ_PRINT ("set", "p:s.d:\"q\"", obj, var, ind, val) #define DBG_OBJ_ARRSET_PTR(var, ind, val) \ DBG_OBJ_ARRSET_PTR_O (this, var, ind, val) @@ -316,7 +363,7 @@ inline void rtfl_print (const char *module, const char *version, DBG_OBJ_ARRATTRSET_STR_O (this, var, ind, attr, val) #define DBG_OBJ_ARRATTRSET_STR_O(obj, var, ind, attr, val) \ - RTFL_OBJ_PRINT ("set", "p:s.d.s:\"s\"", obj, var, ind, attr, val) + RTFL_OBJ_PRINT ("set", "p:s.d.s:\"q\"", obj, var, ind, attr, val) #define DBG_OBJ_ARRATTRSET_PTR(var, ind, attr, val) \ DBG_OBJ_ARRATTRSET_PTR_O (this, var, ind, attr, val) @@ -339,6 +386,7 @@ inline void rtfl_print (const char *module, const char *version, #define DBG_IF_RTFL if(0) +#define DBG_GEN_TIME() STMT_NOP #define DBG_OBJ_MSG(aspect, prio, msg) STMT_NOP #define DBG_OBJ_MSG_O(aspect, prio, obj, msg) STMT_NOP #define DBG_OBJ_MSGF(aspect, prio, fmt, ...) STMT_NOP @@ -359,6 +407,8 @@ inline void rtfl_print (const char *module, const char *version, #define DBG_OBJ_LEAVE_O(obj) STMT_NOP #define DBG_OBJ_LEAVE_VAL(fmt, ...) STMT_NOP #define DBG_OBJ_LEAVE_VAL_O(obj, fmt, ...) STMT_NOP +#define DBG_OBJ_LEAVE_VAL0(val) STMT_NOP +#define DBG_OBJ_LEAVE_VAL0_O(obj, val) STMT_NOP #define DBG_OBJ_CREATE(klass) STMT_NOP #define DBG_OBJ_CREATE_O(obj, klass) STMT_NOP #define DBG_OBJ_DELETE() STMT_NOP -- cgit v1.2.3