add small 'sample' API use, optional build

This commit is contained in:
Geoff McLane 2015-02-07 15:33:13 +01:00
parent 53dda446d4
commit 4bb9418c7c
2 changed files with 56 additions and 0 deletions

View File

@ -19,6 +19,7 @@ list(GET VERSION_LIST 2 TIDY_POINT_VERSION)
set( LIB_TYPE STATIC ) # set default static
option( BUILD_SHARED_LIB "Set ON to build Shared (DLL) Library" OFF )
option( BUILD_TAB2SPACE "Set ON to build utility app, tab2space" OFF )
option( BUILD_SAMPLE_CODE "Set ON to build the sample code" OFF )
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
message(STATUS "*** Have SIZEOF void * = 8, so 64-bit")
@ -157,5 +158,16 @@ if (BUILD_TAB2SPACE)
# no INSTALL of this 'local' tool
endif ()
if (BUILD_SAMPLE_CODE)
set(name test71)
set(dir console)
add_executable( ${name} ${dir}/${name}.cxx )
if (MSVC)
set_target_properties( ${name} PROPERTIES DEBUG_POSTFIX d )
endif ()
target_link_libraries( ${name} ${add_LIBS} )
# no INSTALL of this 'local' sample
endif ()
# eof

44
console/test71.cxx Normal file
View File

@ -0,0 +1,44 @@
/*\
* 20150206 - Test app for Issue #71
*
* A simple API example of getting the body text, first as html,
* and then as a raw stream.
*
* Note: This simple test app has no error checking
*
\*/
#include <stdio.h>
#include "buffio.h"
#include "tidy.h"
static const char *sample =
"<!DOCTYPE html>\n"
"<head>\n"
"<meta charset=utf-8>\n"
"<title>Test app for Issue #71</title>\n"
"<body>something &amp; escaped</body>\n"
"</html>";
int main() {
printf("\nSimple example of HTML Tidy API use.\n");
TidyDoc tdoc = tidyCreate();
TidyBuffer buff;
tidyBufInit(&buff);
tidyBufAppend(&buff, (void *)sample, strlen(sample));
tidyParseBuffer(tdoc, &buff);
TidyNode body = tidyGetBody(tdoc);
TidyNode text_node = tidyGetChild(body);
TidyBuffer buff2;
tidyBufInit(&buff2);
printf("This is the 'escaped' text, from tidyNodeGetText(...), suitable for html use...\n");
tidyNodeGetText(tdoc, text_node, &buff2);
fwrite(buff2.bp, buff2.size, 1, stdout);
printf("This is the 'raw' lexer values, from tidyNodeGetValue(...).\n");
tidyNodeGetValue(tdoc, text_node, &buff2);
fwrite(buff2.bp, buff2.size, 1, stdout);
printf("\n");
return 0;
}
// eof