-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapCpoint.c
More file actions
120 lines (107 loc) · 2.9 KB
/
mapCpoint.c
File metadata and controls
120 lines (107 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "mapCpoint.h"
obj_mapCpoint*
OBJF(obj_mapCpoint,finalize)(obj_mapCpoint* this){
this->mapCpointx=0;
this->mapCpointy=0;
/* solar system radius 143730642000000.0 m */
this->mapCpointName=calloc(SSTRLENG,sizeof(char));
TEMPLATE3(arr,Finalize,obj_ship)(&this->ships);
return(this);}
void
OBJF(obj_mapCpoint,clean)(obj_mapCpoint* this){
TEMPLATE3(arr,Clean,obj_ship)(&this->ships);
free(this->mapCpointName);
return;}
void
OBJF(obj_mapCpoint,copy)(obj_mapCpoint* this, obj_mapCpoint* dest){
NULL_P_CHECK(this);
NULL_P_CHECK(dest);
strncpy(dest->mapCpointName,this->mapCpointName,SSTRLENG);
TEMPLATE3(arr,Copyto_memcpy,obj_ship)(&this->ships,&dest->ships);
STRUCTCOPPIER(dest,this,mapCpointx);
STRUCTCOPPIER(dest,this,mapCpointy);
return;}
obj_mapCpoint*
OBJF(obj_mapCpoint,print)(obj_mapCpoint* this){
NULL_P_CHECK(this);
fprintf(stderr,"\ndumping obj_mapCpoint\n");
DUMP_STRUCT_string(this,mapCpointName);
DUMP_STRUCT_int64(this,mapCpointx);
DUMP_STRUCT_int64(this,mapCpointy);
TEMPLATE3(arr,dump,obj_ship)(&this->ships);
return(NULL);}
int
mapCpointParse(obj_mapCpoint* this, json_stream* js){
NULL_P_CHECK(this);
NULL_P_CHECK(js);
enum json_type type;
const char* str=json_get_string(js,NULL);
//bool arrloop=true;
printf("FIRST %s STRING %s\n",__func__,str);
bool var=false,arrloop=true;
obj_ship* obj_ship=NULL;
while(true){
type=json_next(js);
switch(type){
case JSON_ERROR:
PARSE_EMSG(js,json_typename[type]);
fprintf(stderr,"JSON ERR %s\n",\
json_get_error(js));
break;
case JSON_NULL:
case JSON_TRUE:
case JSON_FALSE:
case JSON_NUMBER:
break;
case JSON_STRING:
var=true;
break;
case JSON_ARRAY:
case JSON_OBJECT:
case JSON_DONE:
PARSE_EMSG(js,json_typename[type]);
break;
case JSON_ARRAY_END:
PARSE_EMSG(js,json_typename[type]);
return(1);
case JSON_OBJECT_END:
fprintf(stderr,"SHIP END l=%ld\n",json_get_lineno(js));
return(0);}
if(var){
parseVarSTR(js,mapCpointName);
parseVarint64_t(js,mapCpointx);
parseVarint64_t(js,mapCpointx);
parseARRobj(js,ships,obj_ship,shipParse,&this->ships)
/* temp solution
* (Z,Y,X,W,U) if(strcmp("ships",str)==0){
** if((type=json_next(js))!=JSON_ARRAY)continue;
** while(arrloop){
** type=json_next(js);
** var=false;
** switch(type){
** case JSON_ERROR:
** PARSE_EMSG(js,json_typename[type]);
** fprintf(stderr,"json ERR %s\n",
** json_get_error(js));
** break;
** case JSON_OBJECT:
** var=true;
** break;
** case JSON_DONE:
** case JSON_ARRAY_END:
** arrloop=false;
** continue;
** default:
** fprintf(stderr,"arr parse err\n");
** PARSE_EMSG(js,json_typename[type]);
** break;
** }
** if(var){
** obj_ship=TEMPLATE3(arr,append,obj_ship)(&this->ships);
** if(!obj_ship)return(2);
** shipParse(obj_ship,js);}}
** continue;}
*/
}
}
return(1);}