-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig_parser.c
More file actions
338 lines (252 loc) · 9.74 KB
/
Config_parser.c
File metadata and controls
338 lines (252 loc) · 9.74 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#include "Config_parser.h"
int filledDsplByLines = 0;
VMUINT8 *buffer;
VMCHAR myHost[100] = {};
VMINT myPort = 0;
VMCHAR myPort1[100] = {};
VMCHAR myLogin[100] = {};
VMCHAR myPassword[100] = {};
VMCHAR myCommand[100] = {};
VMBOOL missingConfigFile = VM_FALSE;
VMWCHAR file_pathw[100];
VMWCHAR fullPath1[100];
VMINT hnd;
VMCHAR test9[100] = "Flight mode OF";
char *stringSrc; //char *test2;
char *test2;
VMCHAR test3[100] = {};
VMINT test; // = 0;
//stringSrc = test9;
struct vm_fileinfo_ext fileInfo;
//struct vm_fileinfo_t;
void vm_main(void) {
layer_hdl[0] = -1;
vm_reg_sysevt_callback(handle_sysevt);
vm_reg_keyboard_callback(handle_keyevt);
vm_font_set_font_size(VM_SMALL_FONT);
checkFileExist();
}
void handle_sysevt(VMINT message, VMINT param) {
switch (message) {
case VM_MSG_CREATE:
case VM_MSG_ACTIVE:
layer_hdl[0] =
vm_graphic_create_layer(0, 0, vm_graphic_get_screen_width(),
vm_graphic_get_screen_height(), -1);
vm_graphic_set_clip(0, 0, vm_graphic_get_screen_width(),
vm_graphic_get_screen_height());
buffer = vm_graphic_get_layer_buffer(layer_hdl[0]);
vm_switch_power_saving_mode(turn_off_mode);
break;
case VM_MSG_PAINT:
vm_switch_power_saving_mode(turn_off_mode);
showResult();
break;
case VM_MSG_INACTIVE:
vm_switch_power_saving_mode(turn_on_mode);
if (layer_hdl[0] != -1) vm_graphic_delete_layer(layer_hdl[0]);
break;
case VM_MSG_QUIT:
if (layer_hdl[0] != -1) vm_graphic_delete_layer(layer_hdl[0]);
break;
}
}
void handle_keyevt(VMINT event, VMINT keycode) {
if (event == VM_KEY_EVENT_UP && keycode == VM_KEY_RIGHT_SOFTKEY) {
if (layer_hdl[0] != -1) {
vm_graphic_delete_layer(layer_hdl[0]);
layer_hdl[0] = -1;
}
vm_exit_app();
}
if (event == VM_KEY_EVENT_UP && keycode == VM_KEY_LEFT_SOFTKEY) {
showResult();
}
}
void mre_draw_black_rectangle(void) {
buffer = vm_graphic_get_layer_buffer(layer_hdl[0]);
vm_graphic_fill_rect(buffer, 0, 0, vm_graphic_get_screen_width(), vm_graphic_get_screen_height(), VM_COLOR_WHITE, VM_COLOR_WHITE);
vm_graphic_flush_layer(layer_hdl, 1);
filledDsplByLines = 0;
}
void vertical_scrolling_ucs2_text(VMWSTR ucs2_string) {
int max_height;
int font_height = 16;
int i;
int abc = 0;
if (filledDsplByLines == 0) {
abc = 2;
mre_draw_black_rectangle();
}
max_height = vm_graphic_get_screen_height();
vm_graphic_clear_layer_bg(layer_hdl[0]);
vm_graphic_textout_by_baseline(buffer, 0, filledDsplByLines + abc, ucs2_string, vm_wstrlen(ucs2_string), VM_COLOR_BLACK, 12);
vm_graphic_flush_layer(layer_hdl, 1);
filledDsplByLines += font_height;
}
void create_app_txt_path(VMWSTR text, VMSTR extt) {
VMWCHAR fullPath[100];
VMWCHAR wfile_extension[4];
vm_get_exec_filename(fullPath);
vm_get_path(fullPath, fullPath1);
vm_ascii_to_ucs2(wfile_extension, 8, extt);
vm_wstrncpy(text, fullPath, vm_wstrlen(fullPath) - 3);
vm_wstrcat(text, wfile_extension);
}
void checkFileExist(void) {
VMFILE f_read;
VMUINT nread;
//VMWCHAR file_pathw[100];
VMCHAR new_data[500];
create_app_txt_path(file_pathw, "txt");
f_read = vm_file_open(file_pathw, MODE_READ, FALSE);
if (f_read < 0) {
vm_file_close(f_read);
missingConfigFile = VM_TRUE;
} else {
vm_file_read(f_read, new_data, 500, &nread);
new_data[nread] = '\0';
vm_file_close(f_read);
if (strlen(new_data) > 1) {
parseText(new_data);
} else {
missingConfigFile = VM_TRUE;
}
}
}
VMINT parseText(VMSTR text) {
VMCHAR vns_simbl[2] = {};
VMCHAR nauj_strng[100] = {};
VMINT counter = 0;
VMINT counter1 = 0;
VMCHAR *ptr;
ptr = text;
while (*ptr != '\0' || counter1 == 5) {
if (*ptr == '\r') {ptr++;}
if (*ptr == '\n') {
counter = counter + 1;
if (counter == 1) {strcpy(myHost, nauj_strng);}
if (counter == 2) {
myPort = strtoi(nauj_strng);
strcpy(myPort1, nauj_strng);
}
if (counter == 3) {strcpy(myLogin, nauj_strng);}
if (counter == 4) {strcpy(myPassword, nauj_strng);}
if (counter == 5) {strcpy(myCommand, nauj_strng);}
counter1 = counter;
strcpy(nauj_strng, "");
ptr++;
}
sprintf(vns_simbl, "%c", *ptr);
strcat(nauj_strng, vns_simbl);
ptr++;
}
if (counter == 0) {strcpy(myHost, nauj_strng);} //counter1 ???????????????
if (counter == 1) {
myPort = strtoi(nauj_strng);
strcpy(myPort1, nauj_strng);
}
if (counter == 2) {strcpy(myLogin, nauj_strng);}
if (counter == 3) {strcpy(myPassword, nauj_strng);}
if (counter == 4) {strcpy(myCommand, nauj_strng);}
//if (strlen(myHost) < 1 || myPort < 0) { missingConfigFile = VM_TRUE;}
return 0;
}
void showResult(void) {
VMCHAR cmyHost[100];
VMWCHAR cmyHostX[100];
VMCHAR cmyPort[100];
VMWCHAR cmyPortX[100];
VMCHAR cmyLogin[100];
VMWCHAR cmyLoginX[100];
VMCHAR cmyPassword[100];
VMWCHAR cmyPasswordX[100];
VMCHAR cmyCommand[100];
VMWCHAR cmyCommandX[100];
VMCHAR cmyEmpty[100] = " ";
VMWCHAR cmyEmptyX[100];
VMCHAR cmyPort1[100];
VMWCHAR cmyPort1X[100];
VMCHAR cmyTest[100];
VMWCHAR cmyTestX[100];
VMCHAR cmyTest2[100];
VMWCHAR cmyTest2X[100];
VMCHAR cmyTest3[100];
VMWCHAR cmyTest3X[100];
VMCHAR cmyTest4[100];
VMWCHAR cmyTest4X[100];
//test = strlen(myPort1);
//test = strtoi("a");
//test = vm_sim_card_count();
//if (vm_sim_card_count() == 99) { strcpy(test9, "Flight mode ON");}
hnd = vm_find_first_ext(fullPath1, &fileInfo);
//test = vm_find_first_ext(fullPath1, &fileInfo);
vertical_scrolling_ucs2_text(fileInfo.filefullname);
test = vm_find_next_ext(hnd, &fileInfo);
vertical_scrolling_ucs2_text(fileInfo.filefullname);
//vertical_scrolling_ucs2_text(fileInfo.filefullname);
//VMINT hnd = vm_find_first_ext(fullPath1, &vm_fileinfo_ext * direntry);
//VMINT vm_find_first_ext(VMWSTR pathname, vm_fileinfo_ext * direntry);
//vm_find_close_ext(hnd);
// hnd = vm_find_first_ext(fullPath1, &fileInfo);
// VMINT last_hnd = vm_find_next_ext(hnd, &fileInfo);
stringSrc = myHost;
test2 = strsubstr(stringSrc , 2, strlen(myLogin)); // mid function
strncpy(test3, myHost, strlen(myLogin)); // right function
if (missingConfigFile == VM_FALSE) {
sprintf(cmyHost, "myHost: %s", myHost);
vm_ascii_to_ucs2(cmyHostX, (strlen(cmyHost) + 1) * 2, cmyHost);
vertical_scrolling_ucs2_text(cmyHostX);
sprintf(cmyPort, "myPort: %d", myPort);
vm_ascii_to_ucs2(cmyPortX, (strlen(cmyPort) + 1) * 2, cmyPort);
vertical_scrolling_ucs2_text(cmyPortX);
sprintf(cmyLogin, "myLogin: %s", myLogin);
vm_ascii_to_ucs2(cmyLoginX, (strlen(cmyLogin) + 1) * 2, cmyLogin);
vertical_scrolling_ucs2_text(cmyLoginX);
sprintf(cmyPassword, "myPassword: %s", myPassword);
vm_ascii_to_ucs2(cmyPasswordX, (strlen(cmyPassword) + 1) * 2, cmyPassword);
vertical_scrolling_ucs2_text(cmyPasswordX);
sprintf(cmyCommand, "myCommand: %s", myCommand);
vm_ascii_to_ucs2(cmyCommandX, (strlen(cmyCommand) + 1) * 2, cmyCommand);
vertical_scrolling_ucs2_text(cmyCommandX);
vm_ascii_to_ucs2(cmyEmptyX, (strlen(cmyEmpty) + 1) * 2, cmyEmpty);
vertical_scrolling_ucs2_text(cmyEmptyX);
sprintf(cmyPort1, "myPort[char]: %s", myPort1);
vm_ascii_to_ucs2(cmyPort1X, (strlen(cmyPort1) + 1) * 2, cmyPort1);
vertical_scrolling_ucs2_text(cmyPort1X);
sprintf(cmyTest, "%s", test9);
vm_ascii_to_ucs2(cmyTestX, (strlen(cmyTest) + 1) * 2, cmyTest);
vertical_scrolling_ucs2_text(cmyTestX);
sprintf(cmyTest2, "MID%d,%d:myHost=%s", strlen(myPort1), strlen(myLogin), test2);
vm_ascii_to_ucs2(cmyTest2X, (strlen(cmyTest2) + 1) * 2, cmyTest2);
vertical_scrolling_ucs2_text(cmyTest2X);
sprintf(cmyTest3, "LEFT%d:myHost=%s", strlen(myLogin), test3);
vm_ascii_to_ucs2(cmyTest3X, (strlen(cmyTest3) + 1) * 2, cmyTest3);
vertical_scrolling_ucs2_text(cmyTest3X);
sprintf(cmyTest4, "%d", hnd);
vm_ascii_to_ucs2(cmyTest4X, (strlen(cmyTest4) + 1) * 2, cmyTest4);
vertical_scrolling_ucs2_text(cmyTest4X);
} else {
sprintf(cmyHost, "%s", "Missing or incorrect config file:");
vm_ascii_to_ucs2(cmyHostX, (strlen(cmyHost) + 1) * 2, cmyHost);
vertical_scrolling_ucs2_text(cmyHostX);
vertical_scrolling_ucs2_text(file_pathw);
}
filledDsplByLines = 0;
}
char * strsubstr(char * str , int from, int count) {
char * result;
if(str == NULL) return NULL;
result = vm_malloc((count+1) * sizeof(char));
if(result == NULL) return NULL;
strncpy(result, str+from, count);
result[count] = '\0';
vm_free(result);
return result;
}
// test2 = strsubstr(stringSrc , 0, 5);
// hnd = vm_find_first_ext(fullPath1, &fileInfo);
// VMINT last_hnd = vm_find_next_ext(hnd, &fileInfo);
//vm_find_close_ext(hnd);
//vm_find_close_ext(last_hnd);
//(vm_file_get_attributes(str)&VM_FS_ATTR_DIR)