Revision: 1154 Author: mwhapples@xxxxxxxxx Date: Mon Apr 28 09:25:53 2014 UTC Log: Some logging callback updates and way for logging widechar buffers http://code.google.com/p/liblouis/source/detail?r=1154 Modified: /trunk/liblouis/compileTranslationTable.c /trunk/liblouis/liblouis.h.in /trunk/liblouis/lou_translateString.c /trunk/liblouis/louis.h /trunk/windows/include/liblouis.h ======================================= --- /trunk/liblouis/compileTranslationTable.c Fri Apr 11 14:00:30 2014 UTC +++ /trunk/liblouis/compileTranslationTable.c Mon Apr 28 09:25:53 2014 UTC @@ -5163,7 +5163,12 @@ printf ("%s\n", hook); } -static logcallback logCallbackFunction; +static void defaultLogCallback(int level, const char *message) +{ + lou_logPrint(message); +} + +static logcallback logCallbackFunction = defaultLogCallback; void EXPORT_CALL lou_registerLogCallback(logcallback callback) { logCallbackFunction = callback; @@ -5199,3 +5204,30 @@ } } } + +void EXPORT_CALL lou_setDefaultLogCallback() +{ + logCallbackFunction = defaultLogCallback; +} + +void logWidecharBuf(int level, const char *msg, widechar *wbuf, int wlen) +{ + int logBufSize = (wlen * ((sizeof(widechar) * 2) + 3)) + 1 + strlen(msg); + char *logMessage = malloc(logBufSize); + char *p = logMessage; + char *formatString; + if (sizeof(widechar) == 2) + formatString = "0x%04X "; + else + formatString = "0x%08X "; + for (int i = 0; i < strlen(msg); i++) + logMessage[i] = msg[i]; + p += strlen(msg); + for (int i = 0; i < wlen; i++) + { + p += sprintf(p, formatString, wbuf[i]); + } + p = '\0'; + lou_log(level, logMessage); + free(logMessage); +} ======================================= --- /trunk/liblouis/liblouis.h.in Mon Apr 21 09:19:39 2014 UTC +++ /trunk/liblouis/liblouis.h.in Mon Apr 28 09:25:53 2014 UTC @@ -168,6 +168,7 @@ LOG_OFF = 2147483647 } logLevels; void EXPORT_CALL lou_setLogLevel(int level); + void EXPORT_CALL lou_setDefaultCallback(); void EXPORT_CALL lou_log(int level, const char *format, ...); /* General log function for callback logging */ ======================================= --- /trunk/liblouis/lou_translateString.c Tue Apr 22 13:43:03 2014 UTC +++ /trunk/liblouis/lou_translateString.c Mon Apr 28 09:25:53 2014 UTC @@ -78,6 +78,8 @@ if (tableList == NULL || inbufx == NULL || inlen == NULL || outbuf == NULL || outlen == NULL) return 0;+ lou_log(LOG_INFO, "Performing translation: tableList=%s, inlen=%d", tableList, *inlen);
+ logWidecharBuf(LOG_INFO, "Inbuf=", inbufx, *inlen); if ((modex & otherTrans)) return other_translate (tableList, inbufx, inlen, outbuf, outlen, @@ -271,6 +273,8 @@ } if (rulesLen != NULL) *rulesLen = appliedRulesCount; + lou_log(LOG_INFO, "Translation complete: outlen=%d", *outlen); + logWidecharBuf(LOG_INFO, "Outbuf=", outbuf, *outlen); return goodTrans; } ======================================= --- /trunk/liblouis/louis.h Wed Oct 23 15:12:24 2013 UTC +++ /trunk/liblouis/louis.h Mon Apr 28 09:25:53 2014 UTC @@ -565,6 +565,9 @@ void outOfMemory (); /* Priknts an out-of-memory message and exits*/ +void logWidecharBuf(int level, const char *msg, widechar *wbuf, int wlen); +/* Helper for logging a widechar buffer */ + #ifdef __cplusplus } #endif /* __cplusplus */ ======================================= --- /trunk/windows/include/liblouis.h Mon Apr 21 09:19:39 2014 UTC +++ /trunk/windows/include/liblouis.h Mon Apr 28 09:25:53 2014 UTC @@ -147,6 +147,7 @@ LOG_OFF = 2147483647 } logLevels; void EXPORT_CALL lou_setLogLevel(int level); + void EXPORT_CALL lou_setDefaultLogCallback(); void EXPORT_CALL lou_log(int level, const char *format, ...); /* General log function for callback logging */ For a description of the software, to download it and links to project pages go to http://www.abilitiessoft.com