COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
json2tab.cpp File Reference
Include dependency graph for json2tab.cpp:

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)
6 {
7  char buf[1000];
8  FILE *fpi = nullptr;
9  FILE *fpo = nullptr;
10 
11  if (argc != 3)
12  {
13  printf("Usage: json2tab [-|filename.json] [-|filename.tab]\n");
14  exit(GENERAL_ERROR_ARGS);
15  }
16 
17  if (argv[1][0] == '-')
18  {
19  fpi = stdin;
20  }
21  else
22  {
23  fpi = fopen(argv[1], "r");
24  }
25 
26  if (argv[2][0] == '-')
27  {
28  fpo = stdout;
29  }
30  else
31  {
32  fpo = fopen(argv[2], "w");
33  }
34 
35  if (fpi == nullptr || fpo == nullptr)
36  {
37  printf("Usage: json2tab [-|filename.json] [-|filename.tab]\n");
38  exit(GENERAL_ERROR_ARGS);
39  }
40 
41  if (fgets(buf, 1000, fpi) == nullptr)
42  {
43  exit(-errno);
44  }
45  Json jobject(buf);
46  for (const auto& member : jobject.ObjectContents)
47  {
48  if (member.first.find("event_") == 0)
49  {
50  fprintf(fpo, "%s\t", member.first.c_str());
51  }
52  }
53 // for (uint16_t i=0; i<jobject.Members.size(); ++i)
54 // {
55 // if (jobject.Members[i].value.name.find("event_") == 0)
56 // {
57 // fprintf(fpo, "%s\t", jobject.Members[i].value.name.c_str());
58 // }
59 // }
60  fprintf(fpo, "\n");
61  for (const auto& member : jobject.ObjectContents)
62 // for (uint16_t i=0; i<jobject.Members.size(); ++i)
63  {
64  if (member.first.find("event_utc") == 0)
65  {
66  fprintf(fpo, "%f\t", member.second.nvalue);
67  }
68  else if (member.first.find("event_name") == 0)
69  {
70  fprintf(fpo, "%s\t", member.second.svalue.c_str());
71  }
72  else if (member.first.find("event_type") == 0)
73  {
74  fprintf(fpo, "%u\t", static_cast<uint32_t>(member.second.nvalue));
75  }
76  else if (member.first.find("event_flag") == 0)
77  {
78  fprintf(fpo, "%u\t", static_cast<uint32_t>(member.second.nvalue));
79  }
80  else if (member.first.find("event_data") == 0)
81  {
82  fprintf(fpo, "%s\t", member.second.svalue.c_str());
83  }
84  else if (member.first.find("event_condition") == 0)
85  {
86  fprintf(fpo, "%s\t", member.second.svalue.c_str());
87  }
88  }
89  fprintf(fpo, "\n");
90 
91  while (fgets(buf, 1000, fpi) != nullptr)
92  {
93  Json jobject(buf);
94  for (const auto& member : jobject.ObjectContents)
95 // for (uint16_t i=0; i<jobject.Members.size(); ++i)
96  {
97  if (member.first.find("event_utc") == 0)
98  {
99  fprintf(fpo, "%f\t", member.second.nvalue);
100  }
101  else if (member.first.find("event_name") == 0)
102  {
103  fprintf(fpo, "%s\t", member.second.svalue.c_str());
104  }
105  else if (member.first.find("event_type") == 0)
106  {
107  fprintf(fpo, "%u\t", static_cast<uint32_t>(member.second.nvalue));
108  }
109  else if (member.first.find("event_flag") == 0)
110  {
111  fprintf(fpo, "%u\t", static_cast<uint32_t>(member.second.nvalue));
112  }
113  else if (member.first.find("event_data") == 0)
114  {
115  fprintf(fpo, "%s\t", member.second.svalue.c_str());
116  }
117  else if (member.first.find("event_condition") == 0)
118  {
119  fprintf(fpo, "%s\t", member.second.svalue.c_str());
120  }
121  }
122  fprintf(fpo, "\n");
123  }
124 }
#define GENERAL_ERROR_ARGS
Definition: cosmos-errno.h:305
Definition: jsonclass.h:11
char buf[128]
Definition: rw_test.cpp:40