1
0
mirror of https://github.com/kgabis/parson.git synced 2025-01-14 06:12:54 +08:00

Small code cleanup, narrower example code in tests and readme.

This commit is contained in:
Krzysztof Gabis 2012-11-24 20:59:16 +01:00
parent 5eb66d2b31
commit 457fa1100f
3 changed files with 10 additions and 11 deletions

View File

@ -31,14 +31,15 @@ void print_commits_info(const char *username, const char *repo) {
char output_filename[] = "commits.json";
/* it ain't pretty, but it's not a libcurl tutorial */
sprintf(curl_command, "curl -s \"https://api.github.com/repos/%s/%s/commits\"\
> %s", username, repo, output_filename);
sprintf(curl_command,
"curl -s \"https://api.github.com/repos/%s/%s/commits\" > %s",
username, repo, output_filename);
sprintf(cleanup_command, "rm -f %s", output_filename);
system(curl_command);
/* parsing json and validating output */
root_value = json_parse_file(output_filename);
if (root_value == NULL || json_value_get_type(root_value) != JSONArray) {
if (json_value_get_type(root_value) != JSONArray) {
system(cleanup_command);
return;
}

View File

@ -511,11 +511,8 @@ JSON_Value * json_parse_file(const char *filename) {
}
JSON_Value * json_parse_string(const char *string) {
if (string && (*string == '{' || *string == '[')) {
return parse_value((const char**)&string, 0);
} else {
return NULL;
}
if (!string || (*string != '{' && *string != '[')) { return NULL; }
return parse_value((const char**)&string, 0);
}
/* JSON Object API */

View File

@ -180,14 +180,15 @@ void print_commits_info(const char *username, const char *repo) {
char output_filename[] = "commits.json";
/* it ain't pretty, but it's not a libcurl tutorial */
sprintf(curl_command, "curl -s \"https://api.github.com/repos/%s/%s/commits\"\
> %s", username, repo, output_filename);
sprintf(curl_command,
"curl -s \"https://api.github.com/repos/%s/%s/commits\" > %s",
username, repo, output_filename);
sprintf(cleanup_command, "rm -f %s", output_filename);
system(curl_command);
/* parsing json and validating output */
root_value = json_parse_file(output_filename);
if (root_value == NULL || json_value_get_type(root_value) != JSONArray) {
if (json_value_get_type(root_value) != JSONArray) {
system(cleanup_command);
return;
}