void json_free_value(struct json_val *value) { int i; if (!value) return; switch (value->type) { case JSON_OBJECT: for (i = 0; i < value->length; i++) { json_free_value(value->object[i].key); json_free_value(value->object[i].value); } free(value->object); break; case JSON_ARRAY: for (i = 0; i < value->length; i++) { json_free_value(value->array[i]); } free(value->array); break; case JSON_STRING: free(value->string); break; case JSON_NUMBER: case JSON_TRUE: case JSON_FALSE: case JSON_NULL: default: break; } free(value); }
void BulletAndWeaponInitialize( BulletClasses *b, GunClasses *g, const char *bpath, const char *gpath) { BulletInitialize(b); FILE *bf = NULL; FILE *gf = NULL; json_t *broot = NULL; json_t *groot = NULL; enum json_error e; // 2-pass bullet loading will free root for us bool freeBRoot = true; bf = fopen(bpath, "r"); if (bf == NULL) { printf("Error: cannot load bullets file %s\n", bpath); goto bail; } e = json_stream_parse(bf, &broot); if (e != JSON_OK) { printf("Error parsing bullets file %s [error %d]\n", bpath, (int)e); goto bail; } BulletLoadJSON(b, &b->Classes, broot); WeaponInitialize(g); gf = fopen(gpath, "r"); if (gf == NULL) { printf("Error: cannot load guns file %s\n", gpath); goto bail; } e = json_stream_parse(gf, &groot); if (e != JSON_OK) { printf("Error parsing guns file %s [error %d]\n", gpath, (int)e); goto bail; } WeaponLoadJSON(g, &g->Guns, groot); BulletLoadWeapons(b); freeBRoot = false; bail: if (bf) { fclose(bf); } if (gf) { fclose(gf); } if (freeBRoot) { json_free_value(&broot); } json_free_value(&groot); }
int MapArchiveSave(const char *filename, CampaignSetting *c) { int res = 1; json_t *root = NULL; char relbuf[CDOGS_PATH_MAX]; if (strcmp(StrGetFileExt(filename), "cdogscpn") == 0 || strcmp(StrGetFileExt(filename), "CDOGSCPN") == 0) { strcpy(relbuf, filename); } else { sprintf(relbuf, "%s.cdogscpn", filename); } char buf[CDOGS_PATH_MAX]; RealPath(relbuf, buf); // Make dir but ignore error, as we may be saving over an existing dir mkdir_deep(buf); // Campaign root = json_new_object(); AddIntPair(root, "Version", MAP_VERSION); AddStringPair(root, "Title", c->Title); AddStringPair(root, "Author", c->Author); AddStringPair(root, "Description", c->Description); AddIntPair(root, "Missions", c->Missions.size); char buf2[CDOGS_PATH_MAX]; sprintf(buf2, "%s/campaign.json", buf); if (!TrySaveJSONFile(root, buf2)) { res = 0; goto bail; } json_free_value(&root); root = json_new_object(); json_insert_pair_into_object(root, "Missions", SaveMissions(&c->Missions)); sprintf(buf2, "%s/missions.json", buf); if (!TrySaveJSONFile(root, buf2)) { res = 0; goto bail; } json_free_value(&root); root = json_new_object(); json_insert_pair_into_object( root, "Characters", SaveCharacters(&c->characters)); sprintf(buf2, "%s/characters.json", buf); if (!TrySaveJSONFile(root, buf2)) { res = 0; goto bail; } bail: json_free_value(&root); return res; }
void ConfigSaveJSON(const Config *config, const char *filename) { FILE *f = fopen(filename, "w"); char *text = NULL; json_t *root; if (f == NULL) { printf("Error saving config '%s'\n", filename); return; } setlocale(LC_ALL, ""); root = json_new_object(); json_insert_pair_into_object(root, "Version", json_new_number(VERSION)); ConfigSaveVisit(config, root); json_tree_to_string(root, &text); char *formatText = json_format_string(text); fputs(formatText, f); // clean up CFREE(formatText); CFREE(text); json_free_value(&root); fclose(f); }
int entryTest(void) { printf("%s", "====== Entry Test Starts =======\n"); setlocale (LC_ALL, ""); json_t *root, *subtree; // creates the root node root = json_new_object(); // creates the desired MJSON document subtree subtree = new_entry("Andrew", "555 123 456"); // inserts the subtree into the root object json_insert_child(root, subtree); // print the result char *text; json_tree_to_string(root, &text); printf("%s\n", text); // clean up free(text); json_free_value(&root); printf("%s", "====== Entry Test Ends =======\n"); return EXIT_SUCCESS; }
void AutosaveSave(Autosave *autosave, const char *filename) { FILE *f = fopen(filename, "w"); char *text = NULL; json_t *root; if (f == NULL) { printf("Error saving autosave '%s'\n", filename); return; } setlocale(LC_ALL, ""); root = json_new_object(); json_insert_pair_into_object(root, "Version", json_new_number("2")); json_insert_pair_into_object( root, "LastMission", CreateMissionNode(&autosave->LastMission)); AddMissionNodes(autosave, root, "Missions"); json_tree_to_string(root, &text); char *formatText = json_format_string(text); fputs(formatText, f); // clean up free(formatText); free(text); json_free_value(&root); fclose(f); }
void AmmoInitialize(AmmoClasses *ammo, const char *path) { memset(ammo, 0, sizeof *ammo); CArrayInit(&ammo->Ammo, sizeof(Ammo)); CArrayInit(&ammo->CustomAmmo, sizeof(Ammo)); json_t *root = NULL; enum json_error e; FILE *f = fopen(path, "r"); if (f == NULL) { printf("Error: cannot load ammo file %s\n", path); goto bail; } e = json_stream_parse(f, &root); if (e != JSON_OK) { printf("Error parsing ammo file %s [error %d]\n", path, (int)e); goto bail; } AmmoLoadJSON(&ammo->Ammo, root); bail: if (f) { fclose(f); } json_free_value(&root); }
void AmmoInitialize(AmmoClasses *ammo, const char *path) { memset(ammo, 0, sizeof *ammo); CArrayInit(&ammo->Ammo, sizeof(Ammo)); CArrayInit(&ammo->CustomAmmo, sizeof(Ammo)); json_t *root = NULL; enum json_error e; char buf[CDOGS_PATH_MAX]; GetDataFilePath(buf, path); FILE *f = fopen(buf, "r"); if (f == NULL) { LOG(LM_MAIN, LL_ERROR, "Error: cannot load ammo file %s", buf); goto bail; } e = json_stream_parse(f, &root); if (e != JSON_OK) { LOG(LM_MAIN, LL_ERROR, "Error parsing ammo file %s [error %d]", buf, (int)e); goto bail; } AmmoLoadJSON(&ammo->Ammo, root); bail: if (f) { fclose(f); } json_free_value(&root); }
void ConfigLoadJSON(Config *config, const char *filename) { FILE *f = fopen(filename, "r"); json_t *root = NULL; int version; if (f == NULL) { printf("Error loading config '%s'\n", filename); goto bail; } if (json_stream_parse(f, &root) != JSON_OK) { printf("Error parsing config '%s'\n", filename); goto bail; } LoadInt(&version, root, "Version"); LoadGameConfigNode(&config->Game, json_find_first_label(root, "Game")); LoadGraphicsConfigNode(&config->Graphics, json_find_first_label(root, "Graphics")); LoadInputConfigNode(&config->Input, json_find_first_label(root, "Input")); LoadInterfaceConfigNode( &config->Interface, json_find_first_label(root, "Interface"), version); LoadSoundConfigNode(&config->Sound, json_find_first_label(root, "Sound")); LoadQuickPlayConfigNode(&config->QuickPlay, json_find_first_label(root, "QuickPlay")); bail: json_free_value(&root); if (f != NULL) { fclose(f); } }
void ConfigSaveJSON(Config *config, const char *filename) { FILE *f = fopen(filename, "w"); char *text = NULL; json_t *root; if (f == NULL) { printf("Error saving config '%s'\n", filename); return; } setlocale(LC_ALL, ""); root = json_new_object(); json_insert_pair_into_object(root, "Version", json_new_number(VERSION)); AddGameConfigNode(&config->Game, root); AddGraphicsConfigNode(&config->Graphics, root); AddInputConfigNode(&config->Input, root); AddInterfaceConfigNode(&config->Interface, root); AddSoundConfigNode(&config->Sound, root); AddQuickPlayConfigNode(&config->QuickPlay, root); json_tree_to_string(root, &text); char *formatText = json_format_string(text); fputs(formatText, f); // clean up CFREE(formatText); CFREE(text); json_free_value(&root); fclose(f); }
void MapObjectsInit(MapObjects *classes, const char *filename) { CArrayInit(&classes->Classes, sizeof(MapObject)); CArrayInit(&classes->CustomClasses, sizeof(MapObject)); CArrayInit(&classes->Destructibles, sizeof(char *)); CArrayInit(&classes->Bloods, sizeof(char *)); FILE *f = fopen(filename, "r"); json_t *root = NULL; if (f == NULL) { printf("Error: cannot load map objects file %s\n", filename); goto bail; } enum json_error e = json_stream_parse(f, &root); if (e != JSON_OK) { printf("Error parsing map objects file %s\n", filename); goto bail; } MapObjectsLoadJSON(&classes->Classes, root); bail: if (f != NULL) { fclose(f); } json_free_value(&root); }
void AutosaveLoad(Autosave *autosave, const char *filename) { FILE *f = fopen(filename, "r"); json_t *root = NULL; if (f == NULL) { printf("Error loading autosave '%s'\n", filename); goto bail; } if (json_stream_parse(f, &root) != JSON_OK) { printf("Error parsing autosave '%s'\n", filename); goto bail; } // Note: need to load missions before LastMission because the former // will overwrite the latter, since AutosaveAddMission also // writes to LastMission LoadMissionNodes(autosave, root, "Missions"); if (json_find_first_label(root, "LastMission")) { LoadMissionNode( &autosave->LastMission, json_find_first_label(root, "LastMission")->child); } bail: json_free_value(&root); if (f != NULL) { fclose(f); } }
int treeTest1(void) { int err; printf("%s", "====== Tree Test 1 Starts =======\n"); setlocale (LC_ALL, ""); //char *document = "{\"entry\":{\"name\":\"Andew\",\"phone\":\"555 123 456\"}}"; int fd = open("./param_list.json", O_RDONLY); if (-1 == fd) { printf("open file failed\n"); return 1; } struct stat fs; if (fstat(fd, &fs)) { printf("failed to get file stat\n"); close(fd); return 1; } size_t fileLen = (size_t)fs.st_size; char *document = malloc(fileLen); bzero(document, fileLen); size_t count = read(fd, document, fileLen); if (count != fileLen) { printf("failed to read file\n"); free(document); close(fd); return 1; } json_t *root = NULL; //json_t *root = json_new_object(); if (NULL == root) { printf("%s\n", "new json object failed"); } printf("Parsing the document...\n"); err = json_parse_document(&root, document); if (err != JSON_OK) { printf("%s, err=%d\n", "parse error", err); goto cleanup; } printf("Printing the document tree...\n"); json_tree_to_string(root, &document); printf("%s\n", document); // clean up cleanup: json_free_value(&root); free(document); close(fd); printf("%s", "====== Tree Test 1 Ends =======\n"); return EXIT_SUCCESS; }
void BatDown::testJson() { char *fn = "script/2.json"; QFile testFile(fn); if(!testFile.open(QIODevice::ReadOnly | QIODevice::Text) ) return; QByteArray ba = testFile.readAll(); char* json = ba.data(); json_t* root = NULL; json_t* item; assert (JSON_OK == json_parse_document (&root, json)); assert (root->child); item = json_find_first_label (root, "title"); QString ss = QString::fromLocal8Bit(item->child->text); yDEBUG(ss.toLocal8Bit().data()); json_free_value (&item); json_free_value (&root); }
static int set_online_status_back(LwqqHttpRequest* req) { int err = LWQQ_EC_OK; int ret; char* response; char* value; json_t * json = NULL; LwqqClient* lc = req->lc; if(!lwqq_client_valid(lc)){ err = LWQQ_EC_ERROR; goto done; } if (req->http_code != 200) { err = LWQQ_EC_HTTP_ERROR; goto done; } /** * Here, we got a json object like this: * {"retcode":0,"result":{"uin":1421032531,"cip":2013211875,"index":1060,"port":43415,"status":"online","vfwebqq":"e7ce7913336ad0d28de9cdb9b46a57e4a6127161e35b87d09486001870226ec1fca4c2ba31c025c7","psessionid":"8368046764001e636f6e6e7365727665725f77656271714031302e3133332e34312e32303200006b2900001544016e0400533cb3546d0000000a4046674d4652585136496d00000028e7ce7913336ad0d28de9cdb9b46a57e4a6127161e35b87d09486001870226ec1fca4c2ba31c025c7","user_state":0,"f":0}} * */ response = req->response; lwqq_verbose(3,"%s\n",response); ret = json_parse_document(&json, response); if (ret != JSON_OK) { err = LWQQ_EC_ERROR; goto done; } if (!(value = json_parse_simple_value(json, "retcode"))) { err = LWQQ_EC_ERROR; goto done; } /** * Do we need parse "seskey? from kernelhcy's code, we need it, * but from the response we got like above, we dont need * */ lwqq__override(lc->seskey,lwqq__json_get_value(json,"seskey")); lwqq__override(lc->cip,lwqq__json_get_value(json,"cip")); lwqq__override(lc->myself->uin,lwqq__json_get_value(json,"uin")); lwqq__override(lc->index,lwqq__json_get_value(json,"index")); lwqq__override(lc->port,lwqq__json_get_value(json,"port")); lwqq__override(lc->vfwebqq,lwqq__json_get_value(json,"vfwebqq")); lwqq__override(lc->psessionid,lwqq__json_get_value(json,"psessionid")); lc->stat = lwqq_status_from_str( json_parse_simple_value(json, "status")); err = LWQQ_EC_OK; done: if (json) json_free_value(&json); lwqq_http_request_free(req); return err; }
string Benchmark::init() throw(std::runtime_error) { raw_buffer inputBuffer = input(); string inputStr(inputBuffer.m_str, inputBuffer.m_len); json_t *parsed = json_parse_document(inputStr.c_str()); if (!parsed) throw runtime_error("Failed to parse json input"); json_free_value(&parsed); return inputStr; }
struct json_val *json_parse_object(struct read_state *state) { struct json_val *value; char ch; int i; value = malloc(sizeof(*value)); value->type = JSON_OBJECT; value->length = 0; value->object = 0; if (*state->read++ != '{') { json_error_print(state, "Internal error parsing object\n"); goto fail; } if (!eat_whitespace(state)) { json_error_print(state, "Unexpected end of file parsing object\n"); goto fail; } ch = *state->read++; if (ch == '}') { //pass } else if(ch == '\"'){ do { read_state_put_back(state); value->length++; value->object = realloc(value->object, value->length * sizeof(*value->object)); value->object[value->length-1] = json_parse_object_field(state); if (value->object[value->length-1].key == 0 || value->object[value->length-1].value == 0) goto fail; if (!eat_whitespace(state)) { json_error_print(state, "Unexpected end of file parsing object\n"); goto fail; } ch = *state->read++; if (ch != '}' && ch != ',') { json_error_print(state, "Unexpected character reading object\n"); goto fail; } if (!eat_whitespace(state) && ch != '}') { json_error_print(state, "Unexpected end of file parsing object\n"); goto fail; } } while(ch == ','); } return value; fail: json_free_value(value); return 0; }
struct json_val *json_parse_array(struct read_state *state) { struct json_val *value; char ch; int i; value = malloc(sizeof(*value)); value->type = JSON_ARRAY; value->length = 0; value->array = 0; if (*state->read++ != '[') { json_error_print(state, "Internal error parsing array\n"); goto fail; } if(!eat_whitespace(state)) { json_error_print(state, "Unexpected end of file parsing array\n"); goto fail; } ch = *state->read++; if (ch == ']') { //pass } else { read_state_put_back(state); do { value->length++; value->array = realloc(value->object, value->length * sizeof(*value->object)); value->array[value->length-1] = json_parse_value(state); if (value->array[value->length-1] == 0) goto fail; if (!eat_whitespace(state)) { json_error_print(state, "Unexpected end of file parsing array\n"); goto fail; } ch = *state->read++; if (ch != ']' && ch != ',') { json_error_print(state, "Unexpected character found parsing array\n"); goto fail; } if (!eat_whitespace(state) && ch != ']') { json_error_print(state, "Unexpected end of file parsing array\n"); goto fail; } } while (ch == ','); } return value; fail: json_free_value(value); return 0; }
static int json_on_metadata_tag(flv_tag * tag, amf_data * name, amf_data * data, flv_parser * parser) { json_t * root; printf("\"scriptDataObject\":{\"name\":\"%s\",\"metadata\":", amf_string_get_bytes(name)); root = NULL; /* dump AMF into JSON */ amf_to_json(data, &root); /* print data */ json_stream_output(stdout, root); /* cleanup */ json_free_value(&root); printf("}"); return OK; }
static void test_remove_items (void) { char* json = "[{\"first\" : 1, \"second\" : 2}]"; json_t* root = NULL; json_t* item; assert (JSON_OK == json_parse_document (&root, json)); json_free_value (&root); assert (JSON_OK == json_parse_document (&root, json)); assert (root->child); item = json_find_first_label (root->child, "first"); json_free_value (&item); json_free_value (&root); assert (JSON_OK == json_parse_document (&root, json)); assert (root->child); item = json_find_first_label (root->child, "second"); json_free_value (&item); json_free_value (&root); printf ("Made It"); }
bool jps_method(LSHandle* lshandle, LSMessage *message, void *ctx) { bool returnVal = true; char line[MAXLINELEN]; // %%% MAGIC NUMBERS ALERT %%% char name[128]; LSError lserror; LSErrorInit(&lserror); char *jsonResponse = 0; int len = 0; json_t *response = json_new_object(); FILE *fp = popen("/usr/bin/jps", "r"); if (fp) { json_t *array = json_new_array(); // Skip the first line (void)fgets( line, sizeof line, fp); while ( fgets( line, sizeof line, fp)) { if (sscanf(line, "%*d %*d %*d %*d %*d %*d %*d %127c", (char*)&name) == 1) { // %%% HACK ALERT %%% *strchr(name,'\n') = 0; json_t *object = json_new_object(); // %%% IGNORING RETURN ALERT %%% json_insert_pair_into_object(object, "name", json_new_string(name)); json_insert_child(array, object); } } if (!pclose(fp)) { // %%% IGNORING RETURN ALERT %%% json_insert_pair_into_object(response, "returnValue", json_new_true()); json_insert_pair_into_object(response, "threads", array); json_tree_to_string(response, &jsonResponse); } } if (jsonResponse) { LSMessageReply(lshandle, message, jsonResponse, &lserror); free(jsonResponse); } else LSMessageReply(lshandle, message, "{\"returnValue\":false,\"errorCode\":-1,\"errorText\":\"Generic error\"}", &lserror); json_free_value(&response); LSErrorFree(&lserror); return returnVal; }
double Benchmark::execute(size_t numIterations) throw(std::runtime_error) { Timer start, end; json_t *parsed; string inputStr = init(); start.reset(); while (numIterations--) { parsed = json_parse_document(inputStr.c_str()); json_free_value(&parsed); } end.reset(); return end - start; }
int dump_json_amf_data(const amf_data * data) { json_t * root; root = NULL; /* dump AMF into JSON */ amf_to_json(data, &root); /* print data */ json_stream_output(stdout, root); /* cleanup */ json_free_value(&root); printf("\n"); return OK; }
size_t Benchmark::execute(double runtime) throw(std::runtime_error) { string inputStr = init(); Timer end; double start = Timer::now(); size_t numIterations = 0; json_t *parsed; for (; end - start < runtime; end.reset()) { parsed = json_parse_document(inputStr.c_str()); json_free_value(&parsed); numIterations++; } return numIterations; }
void LoadPlayerTemplates( CArray *templates, const CharacterClasses *classes, const char *filename) { // Note: not used, but included in function to express dependency CASSERT(classes->Classes.size > 0, "cannot load player templates without character classes"); json_t *root = NULL; int version = 1; // initialise templates CArrayInit(templates, sizeof(PlayerTemplate)); FILE *f = fopen(GetConfigFilePath(filename), "r"); if (!f) { printf("Error loading player templates '%s'\n", filename); goto bail; } if (json_stream_parse(f, &root) != JSON_OK) { printf("Error parsing player templates '%s'\n", filename); goto bail; } LoadInt(&version, root, "Version"); if (json_find_first_label(root, "PlayerTemplates") == NULL) { printf("Error: unknown player templates format\n"); goto bail; } json_t *child = json_find_first_label(root, "PlayerTemplates")->child->child; while (child != NULL) { PlayerTemplate t; LoadPlayerTemplate(&t, child, version); child = child->next; CArrayPushBack(templates, &t); } bail: json_free_value(&root); if (f != NULL) { fclose(f); } }
static void lrec_reader_stdio_json_free(lrec_reader_t* preader) { lrec_reader_stdio_json_state_t* pstate = preader->pvstate; for (sllve_t* pe = pstate->ptop_level_json_objects->phead; pe != NULL; pe = pe->pnext) { json_value_t* top_level_json_object = pe->pvvalue; json_free_value(top_level_json_object); } sllv_free(pstate->ptop_level_json_objects); for (sllve_t* pf = pstate->precords->phead; pf != NULL; pf = pf->pnext) { lrec_t* prec = pf->pvvalue; lrec_free(prec); } sllv_free(pstate->precords); pstate->precords = NULL; free(pstate); free(preader); }
int basicTest() { printf("%s", "====== basic JSon Test Starts =======\n"); char *text; json_t *root, *entry, *label, *value; setlocale (LC_ALL, ""); // creates the root node root = json_new_object(); // create an entry node entry = json_new_object(); // insert the first label-value pair label = json_new_string("name"); value = json_new_string("Andew"); json_insert_child(label, value); json_insert_child(entry, label); // insert the second label-value pair label = json_new_string("phone"); value = json_new_string("555 123 456"); json_insert_child(label, value); json_insert_child(entry, label); // inserts that object as a value in a label-value pair label = json_new_string("entry"); json_insert_child(label, entry); // inserts that label-value pair into the root object json_insert_child(root, label); // print the result json_tree_to_string(root, &text); printf("%s\n",text); // clean up free(text); json_free_value(&root); printf("%s", "====== basic JSon Test Ends =======\n"); return EXIT_SUCCESS; }
void ScriptDialog::setScript(const QString &filename) { json_t *root = BatDownUtils::readJsonFromFile(filename); json_t *idNode = json_find_first_label(root, "id"); json_t *titleNode = json_find_first_label(root, "title"); json_t *urlNode = json_find_first_label(root, "url"); json_t *stepsNode = json_find_first_label(root, "steps"); json_t *seqNode = json_find_first_label(stepsNode->child, "seq"); m_id = QString(idNode->child->text); m_title = QString::fromLocal8Bit(titleNode->child->text); m_url = QString::fromLocal8Bit(urlNode->child->text); json_t *item = item=seqNode->child->child; m_stepSeq.clear(); while( item ){ m_stepSeq.append(item->text); item = item->next; } item = seqNode->next; m_steps.clear(); while( item ){ json_t *testNode = item->child->child; json_t *scriptNode = testNode->next; char *t = json_unescape(testNode->child->text); char *c = json_unescape(scriptNode->child->text); m_steps.insert( item->text, QString::fromLocal8Bit(c) ); m_stepTests.insert( item->text, QString::fromLocal8Bit(t) ); m_stepFuncs.append( QString::fromLocal8Bit("Yew.%1=function(){%2};") .arg(item->text) .arg( QString::fromLocal8Bit(item->child->text) ) ); item = item->next; } json_free_value(&root); m_pSeqEdit->setText(m_stepSeq.join(",")); m_pStepsEdit->addItems(m_stepSeq); setWindowTitle(m_title); }
int streamParse(void) { char buffer[BUFFER_SIZE]; char *temp = NULL; unsigned int error = JSON_INCOMPLETE_DOCUMENT; struct json_parsing_info state; json_jpi_init(&state); while ((error == JSON_WAITING_FOR_EOF) || (error == JSON_INCOMPLETE_DOCUMENT)) { if(fgets (buffer, BUFFER_SIZE, stdin) != NULL) { switch(error = json_parse_fragment( &state, buffer)) { case JSON_OK: printf("complete\n"); json_tree_to_string(state.cursor, &temp); printf("%s\n",temp); break; case JSON_WAITING_FOR_EOF: case JSON_INCOMPLETE_DOCUMENT: break; default: printf("Some error occurred: %d\n", error); } } else { if(error == JSON_WAITING_FOR_EOF) error = JSON_OK; else error = JSON_UNKNOWN_PROBLEM; } } if(error == JSON_OK) { json_render_tree(state.cursor); } else { printf("Document wasn't valid.\n"); } /* perform cleanup */ json_free_value(&state.cursor); return 0; }
int MapNewScanArchive( const char *filename, char **title, int *numMissions) { int err = 0; json_t *root = ReadArchiveJSON(filename, "campaign.json"); if (root == NULL) { err = -1; goto bail; } err = MapNewScanJSON(root, title, numMissions); if (err < 0) { goto bail; } bail: json_free_value(&root); return err; }