From 5d3df694c17a8783c288ddbc3a13f885b2caf546 Mon Sep 17 00:00:00 2001 From: Jim Derry Date: Fri, 12 May 2017 13:05:50 -0400 Subject: [PATCH] WIP --- console/tidy.c | 4 +-- src/messageobj.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++-- src/tidy-int.h | 4 +-- 3 files changed, 72 insertions(+), 7 deletions(-) diff --git a/console/tidy.c b/console/tidy.c index 4a9fe0ae9..ca0296d44 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -1836,13 +1836,13 @@ static void xml_strings( void ) */ static Bool TIDY_CALL reportCallback(TidyMessage tmessage) { -#if 0 +#if 1 TidyIterator pos; TidyMessageArgument arg; TidyFormatParameterType messageType; ctmbstr messageFormat; - printf("FILTER: %s, %s\n", tidyGetMessageKey( tmessage ), tidyGetMessageOutput( tmessage )); + printf("FILTER: %s:\n%s\n", tidyGetMessageKey( tmessage ), tidyGetMessageOutput( tmessage )); /* loop through the arguments, if any, and print their details */ pos = tidyGetMessageArguments( tmessage ); diff --git a/src/messageobj.c b/src/messageobj.c index 31563568e..e232f4bbf 100644 --- a/src/messageobj.c +++ b/src/messageobj.c @@ -53,6 +53,13 @@ struct printfArg { static struct printfArg *BuildArgArray( TidyDocImpl *doc, ctmbstr fmt, va_list ap, int *rv ); +/********************************************************************* + * Other Static functions + *********************************************************************/ +static Bool paragraphizeText( tmbstr dest, size_t size, ctmbstr text ); + + + /********************************************************************* * Tidy Message Object Support *********************************************************************/ @@ -106,9 +113,12 @@ static TidyMessageImpl *tidyMessageCreateInitV( TidyDocImpl *doc, result->messageKey = TY_(tidyErrorCodeAsKey)(code); - result->messageFormatDefault = tidyDefaultString(code); - result->messageFormat = tidyLocalizedString(code); - + result->messageFormatDefault = TidyDocAlloc(doc, sizeMessageBuf); + paragraphizeText( result->messageFormatDefault, sizeMessageBuf, tidyDefaultString(code)); + + result->messageFormat = TidyDocAlloc(doc, sizeMessageBuf); + paragraphizeText( result->messageFormat, sizeMessageBuf, tidyLocalizedString(code)); + result->messageDefault = TidyDocAlloc(doc, sizeMessageBuf); va_copy(args_copy, args); TY_(tmbvsnprintf)(result->messageDefault, sizeMessageBuf, result->messageFormatDefault, args_copy); @@ -250,6 +260,8 @@ void TY_(tidyMessageRelease)( TidyMessageImpl *message ) if ( !message ) return; TidyDocFree( tidyDocToImpl(message->tidyDoc), message->arguments ); + TidyDocFree( tidyDocToImpl(message->tidyDoc), message->messageFormatDefault ); + TidyDocFree( tidyDocToImpl(message->tidyDoc), message->messageFormat ); TidyDocFree( tidyDocToImpl(message->tidyDoc), message->messageDefault ); TidyDocFree( tidyDocToImpl(message->tidyDoc), message->message ); TidyDocFree( tidyDocToImpl(message->tidyDoc), message->messagePosDefault ); @@ -628,3 +640,56 @@ static struct printfArg* BuildArgArray( TidyDocImpl *doc, ctmbstr fmt, va_list a return nas; } + +/********************************************************************* + * Other Static functions + *********************************************************************/ + +/** Filles a provided buffer with with proper paragraph text from the source text. + ** For some reason Tidy refuses to work with paragraphs and instead believes that + ** 80 characters is good enough for everyone in the world regardless of modern + ** monitor sizes, *and* it implements a private API for formatting. This function + ** will respect Tidy's private API and turn dialogue output text back into + ** paragraphs. + ** + ** The internal, private API seems to be such: + */ +static Bool paragraphizeText( tmbstr dest, size_t size, ctmbstr text ) +{ + const char* p = text; + char c; + uint ix = 0; + + while( ( c = *p++ ) != 0 ) + { + if ( c == '\n' && ( c = *p++ ) == '\n' ) + { + dest[ix] = '\n'; + ix++; + continue; + } + + dest[ix] = c; + ix++; + } + + dest[ix] = '\0'; + + return yes; + + +// { +// if( c != '%' ) +// continue; +// +// if( ( c = *p++ ) == '%' ) /* skip %% case */ +// continue; +// else +// number++; +// } + +} + + + + diff --git a/src/tidy-int.h b/src/tidy-int.h index 7973c74d6..99d5f30ec 100755 --- a/src/tidy-int.h +++ b/src/tidy-int.h @@ -116,8 +116,8 @@ struct _TidyMessageImpl ctmbstr messageKey; /* the message code as a key string */ - ctmbstr messageFormatDefault; /* the built-in format string */ - ctmbstr messageFormat; /* the localized format string */ + tmbstr messageFormatDefault; /* the built-in format string */ + tmbstr messageFormat; /* the localized format string */ tmbstr messageDefault; /* the message, formatted, default language */ tmbstr message; /* the message, formatted, localized */