Update to new rjp api
This commit is contained in:
parent
2e0ee84ca7
commit
9c4425ff54
@ -93,8 +93,10 @@ static RJP_value* restore_file_handle(void){
|
||||
}
|
||||
|
||||
RJP_value* find_matching_json_device(const char* name, RJP_value* root){
|
||||
for(RJP_value* curr = rjp_get_member(root);curr;curr = rjp_next_member(curr)){
|
||||
if(!strcmp(rjp_member_name(curr), name)){
|
||||
RJP_object_iterator it;
|
||||
rjp_init_object_iterator(&it, root);
|
||||
for(RJP_value* curr = rjp_object_iterator_current(&it);curr;curr = rjp_object_iterator_next(&it)){
|
||||
if(!strcmp(rjp_member_key(curr)->value, name)){
|
||||
return curr;
|
||||
}
|
||||
}
|
||||
@ -114,7 +116,7 @@ int restore_to_delta(struct arg_values* curr){
|
||||
return 0;
|
||||
}
|
||||
curr->operation = OP_SET;
|
||||
curr->delta = rjp_value_dfloat(match);
|
||||
curr->delta = rjp_get_float(match);
|
||||
return 1;
|
||||
}
|
||||
void prep_restore(struct arg_values* a){
|
||||
@ -124,10 +126,12 @@ void prep_restore(struct arg_values* a){
|
||||
}
|
||||
|
||||
void save_restore_file(struct string_array* devices, struct arg_values* args){
|
||||
RJP_object_iterator it;
|
||||
RJP_value* rf = restore_file_handle();
|
||||
if(!rf)
|
||||
rf = rjp_init_json();
|
||||
for(RJP_value* mem = rjp_get_member(rf);mem;mem = rjp_next_member(mem)){
|
||||
rf = rjp_new_object();
|
||||
rjp_init_object_iterator(&it, rf);
|
||||
for(RJP_value* mem = rjp_object_iterator_current(&it);mem;mem = rjp_object_iterator_next(&it)){
|
||||
for(struct arg_values* curr = args->next, *prev = args;curr;prev = curr, curr = curr->next){
|
||||
if(curr->operation != OP_SET || curr->flags & ARG_FLAG_NO_SAVE){
|
||||
prev->next = curr->next;
|
||||
@ -135,8 +139,8 @@ void save_restore_file(struct string_array* devices, struct arg_values* args){
|
||||
curr = prev;
|
||||
continue;
|
||||
}
|
||||
if(!strcmp(rjp_member_name(mem), curr->device)){
|
||||
rjp_set_value(mem, rjp_dfloat(curr->delta));
|
||||
if(!strcmp(rjp_member_key(mem)->value, curr->device)){
|
||||
rjp_set_float(mem, curr->delta);
|
||||
prev->next = curr->next;
|
||||
free(curr);
|
||||
break;
|
||||
@ -144,18 +148,14 @@ void save_restore_file(struct string_array* devices, struct arg_values* args){
|
||||
}
|
||||
}
|
||||
for(struct arg_values* curr = args->next;curr;curr = curr->next){
|
||||
if(curr->operation == OP_SET)
|
||||
rjp_add_member(rf, curr->device, 0, rjp_dfloat(curr->delta));
|
||||
if(curr->operation == OP_SET){
|
||||
RJP_value* newmem = rjp_add_member_key_copy(rf, curr->device, 0);
|
||||
rjp_set_float(newmem, curr->delta);
|
||||
}
|
||||
}
|
||||
free_cmd_args(args);
|
||||
|
||||
#ifdef RJP_FORMAT_NONE
|
||||
//new rjp api
|
||||
char* tmp = rjp_to_json(rf, RJP_FORMAT_NONE);
|
||||
#else
|
||||
//old rjp api
|
||||
char* tmp = rjp_to_json(rf);
|
||||
#endif
|
||||
char* rfil = restore_file();
|
||||
FILE* restf = fopen(rfil, "w");
|
||||
if(!restf){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user