examples/complicated: fix warnings, bump deprecated callback, tidy up

Also: make them C89, add consts.

Closes #15785
This commit is contained in:
Viktor Szakats 2024-12-20 02:00:22 +01:00
parent fa0ccd9f1f
commit 37fb50a858
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
15 changed files with 199 additions and 132 deletions

View file

@ -43,7 +43,7 @@
// Case-insensitive string comparison
//
#ifdef _MSC_VER
#ifdef _WIN32
#define COMPARE(a, b) (!_stricmp((a), (b)))
#else
#define COMPARE(a, b) (!strcasecmp((a), (b)))
@ -71,8 +71,8 @@ static std::string buffer;
// libcurl write callback function
//
static int writer(char *data, size_t size, size_t nmemb,
std::string *writerData)
static size_t writer(char *data, size_t size, size_t nmemb,
std::string *writerData)
{
if(writerData == NULL)
return 0;
@ -86,7 +86,7 @@ static int writer(char *data, size_t size, size_t nmemb,
// libcurl connection initialization
//
static bool init(CURL *&conn, char *url)
static bool init(CURL *&conn, const char *url)
{
CURLcode code;
@ -140,7 +140,7 @@ static void StartElement(void *voidContext,
{
Context *context = static_cast<Context *>(voidContext);
if(COMPARE(reinterpret_cast<char *>(name), "TITLE")) {
if(COMPARE(reinterpret_cast<const char *>(name), "TITLE")) {
context->title = "";
context->addTitle = true;
}
@ -156,7 +156,7 @@ static void EndElement(void *voidContext,
{
Context *context = static_cast<Context *>(voidContext);
if(COMPARE(reinterpret_cast<char *>(name), "TITLE"))
if(COMPARE(reinterpret_cast<const char *>(name), "TITLE"))
context->addTitle = false;
}
@ -169,7 +169,8 @@ static void handleCharacters(Context *context,
int length)
{
if(context->addTitle)
context->title.append(reinterpret_cast<char *>(chars), length);
context->title.append(reinterpret_cast<const char *>(chars),
(unsigned long)length);
}
//
@ -230,6 +231,11 @@ static htmlSAXHandler saxHandler =
NULL,
NULL,
cdata,
NULL,
0,
0,
0,
0,
NULL
};
@ -246,7 +252,7 @@ static void parseHtml(const std::string &html,
ctxt = htmlCreatePushParserCtxt(&saxHandler, &context, "", 0, "",
XML_CHAR_ENCODING_NONE);
htmlParseChunk(ctxt, html.c_str(), html.size(), 0);
htmlParseChunk(ctxt, html.c_str(), (int)html.size(), 0);
htmlParseChunk(ctxt, "", 0, 1);
htmlFreeParserCtxt(ctxt);