Rename SpecJsonError -> SpecParseError.

pull/9/head
Joshua Potter 2023-11-24 09:01:33 -07:00
parent 9074792cfc
commit b43b1e8122
4 changed files with 14 additions and 14 deletions

View File

@ -4,11 +4,11 @@
#include "cJSON.h" #include "cJSON.h"
#include "config.h" #include "config.h"
enum SpecJsonError { enum SpecParseError {
// The `spec.json` file exists but cannot be open. // The `spec.json` file exists but cannot be open.
SJE_JSON_CANNOT_OPEN = 1, SPE_PARSE_CANNOT_OPEN = 1,
// The JSON of the corresponding file is not syntactically valid JSON. // The JSON of the corresponding file is not syntactically valid JSON.
SJE_JSON_INVALID, SPE_PARSE_INVALID,
}; };
/* /*
@ -17,9 +17,9 @@ Reads in the `spec.json` file relative to the paths of the provided @Config.
A spec directory does not necessarily contain a `spec.json` file. If this file A spec directory does not necessarily contain a `spec.json` file. If this file
cannot be found, the @parsed pointer is set to NULL with a success return code. cannot be found, the @parsed pointer is set to NULL with a success return code.
@return: 0 on success and a @SpecJsonError otherwise. @return: 0 on success and a @SpecParseError otherwise.
*/ */
enum SpecJsonError enum SpecParseError
read_spec_json(const struct Config *const config, cJSON **parsed); read_spec_json(const struct Config *const config, cJSON **parsed);
#endif /* _BOOTSTRAP_LOADER_H */ #endif /* _BOOTSTRAP_LOADER_H */

4
main.c
View File

@ -43,11 +43,11 @@ int main(int argc, char **argv) {
cJSON *parsed = 0; cJSON *parsed = 0;
switch (read_spec_json(config, &parsed)) { switch (read_spec_json(config, &parsed)) {
case SJE_JSON_CANNOT_OPEN: case SPE_PARSE_CANNOT_OPEN:
fprintf(stderr, "Found `spec.json` but could not open."); fprintf(stderr, "Found `spec.json` but could not open.");
retval = EXIT_FAILURE; retval = EXIT_FAILURE;
goto config_cleanup; goto config_cleanup;
case SJE_JSON_INVALID: case SPE_PARSE_INVALID:
fprintf(stderr, "`spec.json` does not conform to bootstrap format."); fprintf(stderr, "`spec.json` does not conform to bootstrap format.");
retval = EXIT_FAILURE; retval = EXIT_FAILURE;
goto config_cleanup; goto config_cleanup;

View File

@ -27,13 +27,13 @@ static int find_spec_json(const struct Config *const config, FILE **handle) {
return retval; return retval;
} }
enum SpecJsonError enum SpecParseError
read_spec_json(const struct Config *const config, cJSON **parsed) { read_spec_json(const struct Config *const config, cJSON **parsed) {
FILE *handle = 0; FILE *handle = 0;
int retval = find_spec_json(config, &handle); int retval = find_spec_json(config, &handle);
if (retval != 0) { if (retval != 0) {
return SJE_JSON_CANNOT_OPEN; return SPE_PARSE_CANNOT_OPEN;
} }
// The `spec.json` file does not exist. // The `spec.json` file does not exist.
@ -57,7 +57,7 @@ read_spec_json(const struct Config *const config, cJSON **parsed) {
// Can use `cJSON_GetErrorPtr()` to get the actual error message. // Can use `cJSON_GetErrorPtr()` to get the actual error message.
if (!*parsed) { if (!*parsed) {
return SJE_JSON_INVALID; return SPE_PARSE_INVALID;
} }
return 0; return 0;

View File

@ -26,7 +26,7 @@ static void test_read_spec_json_missing() {
}; };
cJSON *parsed = 0; cJSON *parsed = 0;
enum SpecJsonError retval = read_spec_json(&config, &parsed); enum SpecParseError retval = read_spec_json(&config, &parsed);
sput_fail_unless(retval == 0, "no spec.json, success"); sput_fail_unless(retval == 0, "no spec.json, success");
sput_fail_unless(parsed == 0, "no spec.json, no parsed"); sput_fail_unless(parsed == 0, "no spec.json, no parsed");
@ -47,7 +47,7 @@ static void test_read_spec_json_minimal() {
}; };
cJSON *parsed = 0; cJSON *parsed = 0;
enum SpecJsonError retval = read_spec_json(&config, &parsed); enum SpecParseError retval = read_spec_json(&config, &parsed);
sput_fail_unless(retval == 0, "minimal spec.json, success"); sput_fail_unless(retval == 0, "minimal spec.json, success");
sput_fail_unless(parsed != 0, "minimal spec.json, parsed"); sput_fail_unless(parsed != 0, "minimal spec.json, parsed");
@ -68,8 +68,8 @@ static void test_read_spec_json_invalid() {
}; };
cJSON *parsed = 0; cJSON *parsed = 0;
enum SpecJsonError retval = read_spec_json(&config, &parsed); enum SpecParseError retval = read_spec_json(&config, &parsed);
sput_fail_unless(retval == SJE_JSON_INVALID, "invalid spec.json, JSON_INVALID"); sput_fail_unless(retval == SPE_PARSE_INVALID, "invalid spec.json, JSON_INVALID");
sput_fail_unless(parsed == 0, "invalid spec.json, not parsed"); sput_fail_unless(parsed == 0, "invalid spec.json, not parsed");
free(cwd); free(cwd);