add json printing and parsing (of strings)
This commit is contained in:
parent
563b1b0c5a
commit
a13c6ecb3a
6 changed files with 277 additions and 81 deletions
|
@ -4,9 +4,11 @@
|
|||
|
||||
#include "arraylist.h"
|
||||
#include "sortedmap.h"
|
||||
#include "json.h"
|
||||
|
||||
#define BUF 20
|
||||
|
||||
/*
|
||||
struct LIST {
|
||||
ArrayList * (*init)();
|
||||
void (*add)(ArrayList *, void *);
|
||||
|
@ -14,6 +16,7 @@ struct LIST {
|
|||
void (*freeitems)(ArrayList *);
|
||||
void (*free)(ArrayList *);
|
||||
} LIST = { list, add_list, get_list, free_listitems, free_list };
|
||||
*/
|
||||
|
||||
typedef struct planet {
|
||||
int ship_count;
|
||||
|
@ -59,7 +62,7 @@ int read_planet(ArrayList *planets) {
|
|||
sscanf(owner, "%d", &planet->owner);
|
||||
}
|
||||
print_planet(planet);
|
||||
LIST.add(planets, planet);
|
||||
add_list(planets, planet);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -107,6 +110,7 @@ void free_gamestate(Gamestate *this) {
|
|||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
Json * json = json_parse(stdin);
|
||||
Gamestate *gamestate;
|
||||
SortedMap *test;
|
||||
|
||||
|
@ -121,5 +125,7 @@ int main(int argc, char **argv) {
|
|||
printf("%s\n", (char *) get_map(test, "awer"));
|
||||
print_map(test);
|
||||
free_map(test);
|
||||
json_print(json, stdout);
|
||||
json_free(json);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue