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:
parent
5eb66d2b31
commit
457fa1100f
@ -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;
|
||||
}
|
||||
|
7
parson.c
7
parson.c
@ -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 */
|
||||
|
7
tests.c
7
tests.c
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user