aboutsummaryrefslogtreecommitdiff
path: root/docs/examples/xmlstream.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2016-02-11 09:42:38 +0100
committerDaniel Stenberg <daniel@haxx.se>2016-02-11 09:44:45 +0100
commit3a6563d668406df1703edb4202afc038fcf9d30e (patch)
tree0fbb9438d99c13049f72b10c966583e582e4e238 /docs/examples/xmlstream.c
parent936d8f07dfbf2ac22ffd216f5363152bcecc2651 (diff)
examples: adhere to curl code style
All plain C examples now (mostly) adhere to the curl code style. While they are only examples, they had diverted so much and contained all sorts of different mixed code styles by now. Having them use a unified style helps users and readability. Also, as they get copy-and-pasted widely by users, making sure they're clean and nice is a good idea. 573 checksrc warnings were addressed.
Diffstat (limited to 'docs/examples/xmlstream.c')
-rw-r--r--docs/examples/xmlstream.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/docs/examples/xmlstream.c b/docs/examples/xmlstream.c
index 3ed5c1985..8066828f2 100644
--- a/docs/examples/xmlstream.c
+++ b/docs/examples/xmlstream.c
@@ -51,7 +51,8 @@ struct ParserStruct {
struct MemoryStruct characters;
};
-static void startElement(void *userData, const XML_Char *name, const XML_Char **atts)
+static void startElement(void *userData, const XML_Char *name,
+ const XML_Char **atts)
{
struct ParserStruct *state = (struct ParserStruct *) userData;
state->tags++;
@@ -89,16 +90,18 @@ static void endElement(void *userData, const XML_Char *name)
printf("%5lu %10lu %s\n", state->depth, state->characters.size, name);
}
-static size_t parseStreamCallback(void *contents, size_t length, size_t nmemb, void *userp)
+static size_t parseStreamCallback(void *contents, size_t length, size_t nmemb,
+ void *userp)
{
XML_Parser parser = (XML_Parser) userp;
size_t real_size = length * nmemb;
struct ParserStruct *state = (struct ParserStruct *) XML_GetUserData(parser);
/* Only parse if we're not already in a failure state. */
- if (state->ok && XML_Parse(parser, contents, real_size, 0) == 0) {
+ if(state->ok && XML_Parse(parser, contents, real_size, 0) == 0) {
int error_code = XML_GetErrorCode(parser);
- fprintf(stderr, "Parsing response buffer of length %lu failed with error code %d (%s).\n",
+ fprintf(stderr, "Parsing response buffer of length %lu failed"
+ " with error code %d (%s).\n",
real_size, error_code, XML_ErrorString(error_code));
state->ok = 0;
}
@@ -126,7 +129,8 @@ int main(void)
/* Initialize a libcurl handle. */
curl_global_init(CURL_GLOBAL_ALL ^ CURL_GLOBAL_SSL);
curl_handle = curl_easy_init();
- curl_easy_setopt(curl_handle, CURLOPT_URL, "http://www.w3schools.com/xml/simple.xml");
+ curl_easy_setopt(curl_handle, CURLOPT_URL,
+ "http://www.w3schools.com/xml/simple.xml");
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, parseStreamCallback);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)parser);
@@ -138,9 +142,9 @@ int main(void)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
}
- else if (state.ok) {
+ else if(state.ok) {
/* Expat requires one final call to finalize parsing. */
- if (XML_Parse(parser, NULL, 0, 1) == 0) {
+ if(XML_Parse(parser, NULL, 0, 1) == 0) {
int error_code = XML_GetErrorCode(parser);
fprintf(stderr, "Finalizing parsing failed with error code %d (%s).\n",
error_code, XML_ErrorString(error_code));