Debian Codegraph @

src/hics/hics203.cxx

raw
1 // ----------------------------------------------------------------------------
2 // Copyright (C) 2014
3 // David Freese, W1HKJ
4 //
5 // This file is part of flmsg
6 //
7 // flrig is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // flrig is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 // ----------------------------------------------------------------------------
20
21 #include <stdlib.h>
22 #include <iostream>
23 #include <fstream>
24 #include <cstring>
25 #include <ctime>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <stdio.h>
29 #include <errno.h>
30
31 #include <FL/Fl.H>
32 #include <FL/Enumerations.H>
33 #include <FL/Fl_Window.H>
34 #include <FL/Fl_Button.H>
35 #include <FL/Fl_Group.H>
36 #include <FL/Fl_Sys_Menu_Bar.H>
37 #include <FL/x.H>
38 #include <FL/Fl_Help_Dialog.H>
39 #include <FL/Fl_Menu_Item.H>
40 #include <FL/Fl_File_Icon.H>
41
42 #include "config.h"
43 #include "flmsg_config.h"
44
45 #include "flmsg.h"
46 #include "templates.h"
47 #include "debug.h"
48 #include "util.h"
49 #include "gettext.h"
50 #include "flmsg_dialog.h"
51 #include "flinput2.h"
52 #include "date.h"
53 #include "calendar.h"
54 #include "icons.h"
55 #include "fileselect.h"
56 #include "wrap.h"
57 #include "status.h"
58 #include "parse_xml.h"
59
60 #ifdef WIN32
61 # include "flmsgrc.h"
62 # include "compat.h"
63 # define dirent fl_dirent_no_thanks
64 #endif
65
66 #include <FL/filename.H>
67 #include "dirent-check.h"
68
69 #include <FL/x.H>
70 #include <FL/Fl_Pixmap.H>
71 #include <FL/Fl_Image.H>
72
73 // ---------------------------------------------------------------------
74 // hics 203 field variables and template variables
75 // ---------------------------------------------------------------------
76
77 std::string hics203_tag_incident = ":inc:";
78 std::string hics203_tag_date = ":dat:";
79 std::string hics203_tag_time = ":tim:";
80 std::string hics203_tag_op_period = ":opp:";
81 std::string hics203_tag_incident_commander = ":icc:";
82 std::string hics203_tag_incident_safety_officer = ":ics:";
83 std::string hics203_tag_incident_info_officer = ":ici:";
84 std::string hics203_tag_liaison_officer = ":icl:";
85 std::string hics203_tag_prepared_by = ":pre:";
86 std::string hics203_tag_facility = ":facility:";
87
88 std::string hics203_tag_tech_spc = ":tech_spc[n]:"; // 6
89
90 std::string hics203_tag_ops_chief = ":ops_chief:";
91 std::string hics203_tag_bus_brch = ":bus_brch:";
92 std::string hics203_tag_stg_mgr = ":stg_mgr:";
93 std::string hics203_tag_med_care_brch = ":med_care_brch:";
94 std::string hics203_tag_infr_brch = ":infr_brch:";
95 std::string hics203_tag_sec_brch = ":sec_brch:";
96 std::string hics203_tag_hazmat_brch = ":hazmat_brch:";
97 std::string hics203_tag_ops_other = ":ops_other:";
98
99 std::string hics203_tag_fin_chief = ":fin_chief:";
100 std::string hics203_tag_cost_unit = ":cost_unit:";
101 std::string hics203_tag_proc_unit = ":proc_unit:";
102 std::string hics203_tag_comp_unit = ":comp_unit:";
103 std::string hics203_tag_time_unit = ":time_unit:";
104 std::string hics203_tag_fin_other = ":fin_other:";
105
106 std::string hics203_tag_planning_chief = ":planning_chief:";
107 std::string hics203_tag_res_unit = ":res_unit:";
108 std::string hics203_tag_sit_unit = ":sit_unit:";
109 std::string hics203_tag_doc_unit = ":doc_unit:";
110 std::string hics203_tag_dem_unit = ":dem_unit:";
111 std::string hics203_tag_planning_other = ":planning_other:";
112
113 std::string hics203_tag_log_chief = ":log_chief:";
114 std::string hics203_tag_sup_brch = ":sup_brch:";
115 std::string hics203_tag_svc_brch = ":svc_brch:";
116 std::string hics203_tag_log_other = ":log_other:";
117
118 std::string hics203_tag_hcc_agency = ":hcc_agency:";
119 std::string hics203_tag_hcc_rep = ":hcc_rep:";
120 std::string hics203_tag_ext_loc = ":ext_loc:";
121 std::string hics203_tag_ext_rep = ":ext_rep:";
122
123 std::string hics203_incident;
124 std::string hics203_date;
125 std::string hics203_time;
126 std::string hics203_op_period;
127 std::string hics203_incident_commander;
128 std::string hics203_incident_safety_officer;
129 std::string hics203_incident_info_officer;
130 std::string hics203_liaison_officer;
131 std::string hics203_prepared_by;
132 std::string hics203_facility;
133
134 std::string hics203_fin_chief;
135 std::string hics203_fin_other;
136 std::string hics203_time_unit;
137 std::string hics203_proc_unit;
138 std::string hics203_comp_unit;
139 std::string hics203_cost_unit;
140
141 std::string hics203_tech_spc[6];
142
143 std::string hics203_planning_chief;
144 std::string hics203_planning_other;
145 std::string hics203_res_unit;
146 std::string hics203_sit_unit;
147 std::string hics203_doc_unit;
148 std::string hics203_dem_unit;
149 std::string hics203_log_chief;
150 std::string hics203_log_other;
151 std::string hics203_log_sup_brch;
152 std::string hics203_bus_brch;
153 std::string hics203_stg_mgr;
154 std::string hics203_med_care_brch;
155 std::string hics203_infr_brch;
156 std::string hics203_sec_brch;
157 std::string hics203_hazmat_brch;
158 std::string hics203_hcc_agency;
159 std::string hics203_svc_brch;
160 std::string hics203_hcc_rep;
161 std::string hics203_ext_loc;
162 std::string hics203_ext_rep;
163 std::string hics203_ops_chief;
164 std::string hics203_ops_other;
165
166 // =====================================================================
167
168 std::string hics_buff203;
169 std::string def_hics203_filename = "";
170 std::string base_hics203_filename = "";
171 std::string def_hics203_TemplateName = "";
172 bool using_hics203_template = false;
173
174 void cb_hics203_set_date()
175 {
176 txt_hics203_date->value(szDate(progStatus.dtformat));
177 }
178
179 void cb_hics203_set_time()
180 {
181 txt_hics203_time->value(szTime(progStatus.UTC));
182 }
183
184 void clear_hics203fields()
185 {
186 hics203_incident.clear();
187 hics203_date.clear();
188 hics203_time.clear();
189 hics203_op_period.clear();
190 hics203_incident_commander.clear();
191 hics203_incident_safety_officer.clear();
192 hics203_incident_info_officer.clear();
193 hics203_liaison_officer.clear();
194 hics203_prepared_by.clear();
195 hics203_facility.clear();
196 hics203_planning_chief.clear();
197 hics203_planning_other.clear();
198 hics203_res_unit.clear();
199 hics203_sit_unit.clear();
200 hics203_doc_unit.clear();
201 hics203_dem_unit.clear();
202 hics203_log_chief.clear();
203 hics203_log_other.clear();
204 hics203_log_sup_brch.clear();
205 hics203_bus_brch.clear();
206 hics203_stg_mgr.clear();
207 hics203_med_care_brch.clear();
208 hics203_infr_brch.clear();
209 hics203_sec_brch.clear();
210 hics203_hazmat_brch.clear();
211 hics203_hcc_agency.clear();
212 hics203_svc_brch.clear();
213 hics203_hcc_rep.clear();
214 hics203_ext_loc.clear();
215 hics203_ext_rep.clear();
216 hics203_ops_chief.clear();
217 hics203_ops_other.clear();
218 hics203_fin_chief.clear();
219 hics203_fin_other.clear();
220 hics203_time_unit.clear();
221 hics203_proc_unit.clear();
222 hics203_comp_unit.clear();
223 hics203_cost_unit.clear();
224
225 for (int i = 0; i < 6; i++) {
226 hics203_tech_spc[i].clear();
227 }
228 }
229
230 bool check_hics203fields()
231 {
232 if (hics203_incident != txt_hics203_incident->value())
233 return true;
234 if (hics203_date != txt_hics203_date->value())
235 return true;
236 if (hics203_time != txt_hics203_time->value())
237 return true;
238 if (hics203_op_period != txt_hics203_op_period->value())
239 return true;
240 if (hics203_incident_commander != txt_hics203_incident_commander->value())
241 return true;
242 if (hics203_incident_safety_officer != txt_hics203_incident_safety_officer->value())
243 return true;
244 if (hics203_incident_info_officer != txt_hics203_incident_info_officer->value())
245 return true;
246 if (hics203_liaison_officer != txt_hics203_liaison_officer->value())
247 return true;
248 if (hics203_prepared_by != txt_hics203_prepared_by->value())
249 return true;
250 if (hics203_facility != txt_hics203_facility->value())
251 return true;
252 if (hics203_planning_chief != txt_hics203_planning_chief->value())
253 return true;
254 if (hics203_planning_other != txt_hics203_planning_other->value())
255 return true;
256 if (hics203_res_unit != txt_hics203_res_unit->value())
257 return true;
258 if (hics203_sit_unit != txt_hics203_sit_unit->value())
259 return true;
260 if (hics203_doc_unit != txt_hics203_doc_unit->value())
261 return true;
262 if (hics203_dem_unit != txt_hics203_dem_unit->value())
263 return true;
264 if (hics203_log_chief != txt_hics203_log_chief->value())
265 return true;
266 if (hics203_log_other != txt_hics203_log_other->value())
267 return true;
268 if (hics203_log_sup_brch != txt_hics203_log_sup_brch->value())
269 return true;
270 if (hics203_bus_brch != txt_hics203_bus_brch->value())
271 return true;
272 if (hics203_stg_mgr != txt_hics203_stg_mgr->value())
273 return true;
274 if (hics203_med_care_brch != txt_hics203_med_care_brch->value())
275 return true;
276 if (hics203_infr_brch != txt_hics203_infr_brch->value())
277 return true;
278 if (hics203_sec_brch != txt_hics203_sec_brch->value())
279 return true;
280 if (hics203_hazmat_brch != txt_hics203_hazmat_brch->value())
281 return true;
282 if (hics203_hcc_agency != txt_hics203_hcc_agency->value())
283 return true;
284 if (hics203_svc_brch != txt_hics203_svc_brch->value())
285 return true;
286 if (hics203_hcc_rep != txt_hics203_hcc_rep->value())
287 return true;
288 if (hics203_ext_loc != txt_hics203_ext_loc->value())
289 return true;
290 if (hics203_ext_rep != txt_hics203_ext_rep->value())
291 return true;
292 if (hics203_ops_chief != txt_hics203_ops_chief->value())
293 return true;
294 if (hics203_ops_other != txt_hics203_ops_other->value())
295 return true;
296 if (hics203_fin_chief != txt_hics203_fin_chief->value())
297 return true;
298 if (hics203_fin_other != txt_hics203_fin_other->value())
299 return true;
300 if (hics203_time_unit != txt_hics203_time_unit->value())
301 return true;
302 if (hics203_proc_unit != txt_hics203_proc_unit->value())
303 return true;
304 if (hics203_comp_unit != txt_hics203_comp_unit->value())
305 return true;
306 if (hics203_cost_unit != txt_hics203_cost_unit->value())
307 return true;
308
309 for (int i = 0; i < 6; i++) {
310 if (hics203_tech_spc[i] != txt_hics203_tech_spc[i]->value())
311 return true;
312 }
313 return false;
314 }
315
316 void update_hics203fields()
317 {
318 hics203_incident = txt_hics203_incident->value();
319 hics203_date = txt_hics203_date->value();
320 hics203_time = txt_hics203_time->value();
321 hics203_op_period = txt_hics203_op_period->value();
322 hics203_incident_commander = txt_hics203_incident_commander->value();
323 hics203_incident_safety_officer = txt_hics203_incident_safety_officer->value();
324 hics203_incident_info_officer = txt_hics203_incident_info_officer->value();
325 hics203_liaison_officer = txt_hics203_liaison_officer->value();
326 hics203_prepared_by = txt_hics203_prepared_by->value();
327 hics203_facility = txt_hics203_facility->value();
328 hics203_planning_chief = txt_hics203_planning_chief->value();
329 hics203_planning_other = txt_hics203_planning_other->value();
330 hics203_res_unit = txt_hics203_res_unit->value();
331 hics203_sit_unit = txt_hics203_sit_unit->value();
332 hics203_doc_unit = txt_hics203_doc_unit->value();
333 hics203_dem_unit = txt_hics203_dem_unit->value();
334 hics203_log_chief = txt_hics203_log_chief->value();
335 hics203_log_other = txt_hics203_log_other->value();
336 hics203_log_sup_brch = txt_hics203_log_sup_brch->value();
337 hics203_bus_brch = txt_hics203_bus_brch->value();
338 hics203_stg_mgr = txt_hics203_stg_mgr->value();
339 hics203_med_care_brch = txt_hics203_med_care_brch->value();
340 hics203_infr_brch = txt_hics203_infr_brch->value();
341 hics203_sec_brch = txt_hics203_sec_brch->value();
342 hics203_hazmat_brch = txt_hics203_hazmat_brch->value();
343 hics203_hcc_agency = txt_hics203_hcc_agency->value();
344 hics203_svc_brch = txt_hics203_svc_brch->value();
345 hics203_hcc_rep = txt_hics203_hcc_rep->value();
346 hics203_ext_loc = txt_hics203_ext_loc->value();
347 hics203_ext_rep = txt_hics203_ext_rep->value();
348 hics203_ops_chief = txt_hics203_ops_chief->value();
349 hics203_ops_other = txt_hics203_ops_other->value();
350 hics203_fin_chief = txt_hics203_fin_chief->value();
351 hics203_fin_other = txt_hics203_fin_other->value();
352 hics203_time_unit = txt_hics203_time_unit->value();
353 hics203_proc_unit = txt_hics203_proc_unit->value();
354 hics203_comp_unit = txt_hics203_comp_unit->value();
355 hics203_cost_unit = txt_hics203_cost_unit->value();
356
357 for (int i = 0; i < 6; i++) {
358 hics203_tech_spc[i] = txt_hics203_tech_spc[i]->value();
359 }
360 }
361
362 void update_hics203form()
363 {
364 txt_hics203_incident->value(hics203_incident.c_str());
365 txt_hics203_date->value(hics203_date.c_str());
366 txt_hics203_time->value(hics203_time.c_str());
367 txt_hics203_op_period->value(hics203_op_period.c_str());
368 txt_hics203_incident_commander->value(hics203_incident_commander.c_str());
369 txt_hics203_incident_safety_officer->value(hics203_incident_safety_officer.c_str());
370 txt_hics203_incident_info_officer->value(hics203_incident_info_officer.c_str());
371 txt_hics203_liaison_officer->value(hics203_liaison_officer.c_str());
372 txt_hics203_prepared_by->value(hics203_prepared_by.c_str());
373 txt_hics203_facility->value(hics203_facility.c_str());
374 txt_hics203_planning_chief->value(hics203_planning_chief.c_str());
375 txt_hics203_planning_other->value(hics203_planning_other.c_str());
376 txt_hics203_res_unit->value(hics203_res_unit.c_str());
377 txt_hics203_sit_unit->value(hics203_sit_unit.c_str());
378 txt_hics203_doc_unit->value(hics203_doc_unit.c_str());
379 txt_hics203_dem_unit->value(hics203_dem_unit.c_str());
380 txt_hics203_log_chief->value(hics203_log_chief.c_str());
381 txt_hics203_log_other->value(hics203_log_other.c_str());
382 txt_hics203_log_sup_brch->value(hics203_log_sup_brch.c_str());
383 txt_hics203_bus_brch->value(hics203_bus_brch.c_str());
384 txt_hics203_stg_mgr->value(hics203_stg_mgr.c_str());
385 txt_hics203_med_care_brch->value(hics203_med_care_brch.c_str());
386 txt_hics203_infr_brch->value(hics203_infr_brch.c_str());
387 txt_hics203_sec_brch->value(hics203_sec_brch.c_str());
388 txt_hics203_hazmat_brch->value(hics203_hazmat_brch.c_str());
389 txt_hics203_hcc_agency->value(hics203_hcc_agency.c_str());
390 txt_hics203_svc_brch->value(hics203_svc_brch.c_str());
391 txt_hics203_hcc_rep->value(hics203_hcc_rep.c_str());
392 txt_hics203_ext_loc->value(hics203_ext_loc.c_str());
393 txt_hics203_ext_rep->value(hics203_ext_rep.c_str());
394 txt_hics203_ops_chief->value(hics203_ops_chief.c_str());
395 txt_hics203_ops_other->value(hics203_ops_other.c_str());
396 txt_hics203_fin_chief->value(hics203_fin_chief.c_str());
397 txt_hics203_fin_other->value(hics203_fin_other.c_str());
398 txt_hics203_time_unit->value(hics203_time_unit.c_str());
399 txt_hics203_proc_unit->value(hics203_proc_unit.c_str());
400 txt_hics203_comp_unit->value(hics203_comp_unit.c_str());
401 txt_hics203_cost_unit->value(hics203_cost_unit.c_str());
402
403 for (int i = 0; i < 6; i++) {
404 txt_hics203_tech_spc[i]->value(hics203_tech_spc[i].c_str());
405 }
406 }
407
408 void clear_hics203_form()
409 {
410 clear_hics203fields();
411
412 txt_hics203_incident->value("");
413 txt_hics203_date->value("");
414 txt_hics203_time->value("");
415 txt_hics203_op_period->value("");
416 txt_hics203_incident_commander->value("");
417 txt_hics203_incident_safety_officer->value("");
418 txt_hics203_incident_info_officer->value("");
419 txt_hics203_liaison_officer->value("");
420 txt_hics203_prepared_by->value("");
421 txt_hics203_facility->value("");
422 txt_hics203_planning_chief->value("");
423 txt_hics203_planning_other->value("");
424 txt_hics203_res_unit->value("");
425 txt_hics203_sit_unit->value("");
426 txt_hics203_doc_unit->value("");
427 txt_hics203_dem_unit->value("");
428 txt_hics203_log_chief->value("");
429 txt_hics203_log_other->value("");
430 txt_hics203_log_sup_brch->value("");
431 txt_hics203_bus_brch->value("");
432 txt_hics203_stg_mgr->value("");
433 txt_hics203_med_care_brch->value("");
434 txt_hics203_infr_brch->value("");
435 txt_hics203_sec_brch->value("");
436 txt_hics203_hazmat_brch->value("");
437 txt_hics203_hcc_agency->value("");
438 txt_hics203_svc_brch->value("");
439 txt_hics203_hcc_rep->value("");
440 txt_hics203_ext_loc->value("");
441 txt_hics203_ext_rep->value("");
442 txt_hics203_ops_chief->value("");
443 txt_hics203_ops_other->value("");
444 txt_hics203_fin_chief->value("");
445 txt_hics203_fin_other->value("");
446 txt_hics203_time_unit->value("");
447 txt_hics203_proc_unit->value("");
448 txt_hics203_comp_unit->value("");
449 txt_hics203_cost_unit->value("");
450
451 for (int i = 0; i < 6; i++) {
452 txt_hics203_tech_spc[i]->value("");
453 }
454 }
455
456 std::string &hics_n(std::string & subst, int n)
457 {
458 static std::string garbage = "#$^*!";
459 size_t pos = subst.find("[");
460 if (pos == std::string::npos) return garbage;
461 pos++;
462 subst[pos] = '0' + n;
463 return subst;
464 }
465
466 void make_hics_buff203(bool compress = false)
467 {
468 std::string mbuff;
469 mbuff.assign( lineout( hics203_tag_incident, hics203_incident ) );
470 mbuff.append( lineout( hics203_tag_date, hics203_date ) );
471 mbuff.append( lineout( hics203_tag_time, hics203_time ) );
472 mbuff.append( lineout( hics203_tag_op_period, hics203_op_period ) );
473 mbuff.append( lineout( hics203_tag_incident_commander, hics203_incident_commander ) );
474 mbuff.append( lineout( hics203_tag_incident_safety_officer, hics203_incident_safety_officer ) );
475 mbuff.append( lineout( hics203_tag_incident_info_officer, hics203_incident_info_officer ) );
476 mbuff.append( lineout( hics203_tag_liaison_officer, hics203_liaison_officer ) );
477 mbuff.append( lineout( hics203_tag_prepared_by, hics203_prepared_by ) );
478 mbuff.append( lineout( hics203_tag_facility, hics203_facility ) );
479 mbuff.append( lineout( hics203_tag_planning_chief, hics203_planning_chief ) );
480 mbuff.append( lineout( hics203_tag_planning_other, hics203_planning_other ) );
481 mbuff.append( lineout( hics203_tag_res_unit, hics203_res_unit ) );
482 mbuff.append( lineout( hics203_tag_sit_unit, hics203_sit_unit ) );
483 mbuff.append( lineout( hics203_tag_doc_unit, hics203_doc_unit ) );
484 mbuff.append( lineout( hics203_tag_dem_unit, hics203_dem_unit ) );
485 mbuff.append( lineout( hics203_tag_log_chief, hics203_log_chief ) );
486 mbuff.append( lineout( hics203_tag_log_other, hics203_log_other ) );
487 mbuff.append( lineout( hics203_tag_sup_brch, hics203_log_sup_brch ) );
488 mbuff.append( lineout( hics203_tag_bus_brch, hics203_bus_brch ) );
489 mbuff.append( lineout( hics203_tag_stg_mgr, hics203_stg_mgr ) );
490 mbuff.append( lineout( hics203_tag_med_care_brch, hics203_med_care_brch ) );
491 mbuff.append( lineout( hics203_tag_infr_brch, hics203_infr_brch ) );
492 mbuff.append( lineout( hics203_tag_sec_brch, hics203_sec_brch ) );
493 mbuff.append( lineout( hics203_tag_hazmat_brch, hics203_hazmat_brch ) );
494 mbuff.append( lineout( hics203_tag_hcc_agency, hics203_hcc_agency ) );
495 mbuff.append( lineout( hics203_tag_svc_brch, hics203_svc_brch ) );
496 mbuff.append( lineout( hics203_tag_hcc_rep, hics203_hcc_rep ) );
497 mbuff.append( lineout( hics203_tag_ext_loc, hics203_ext_loc ) );
498 mbuff.append( lineout( hics203_tag_ext_rep, hics203_ext_rep ) );
499 mbuff.append( lineout( hics203_tag_ops_chief, hics203_ops_chief ) );
500 mbuff.append( lineout( hics203_tag_ops_other, hics203_ops_other ) );
501 mbuff.append( lineout( hics203_tag_fin_chief, hics203_fin_chief ) );
502 mbuff.append( lineout( hics203_tag_fin_other, hics203_fin_other ) );
503 mbuff.append( lineout( hics203_tag_time_unit, hics203_time_unit ) );
504 mbuff.append( lineout( hics203_tag_proc_unit, hics203_proc_unit ) );
505 mbuff.append( lineout( hics203_tag_comp_unit, hics203_comp_unit ) );
506 mbuff.append( lineout( hics203_tag_cost_unit, hics203_cost_unit ) );
507
508 for (int i = 0; i < 6; i++) {
509 mbuff.append( lineout( hics_n( hics203_tag_tech_spc, i ), hics203_tech_spc[i] ) );
510 }
511 if (compress) compress_maybe(mbuff);
512 hics_buff203.append(mbuff);
513 }
514
515 void read_hics203_buffer(std::string data)
516 {
517 clear_hics203fields();
518 read_header(data);
519
520 hics203_incident = findstr(data, hics203_tag_incident);
521 hics203_date = findstr(data, hics203_tag_date);
522 hics203_time = findstr(data, hics203_tag_time);
523 hics203_op_period = findstr(data, hics203_tag_op_period);
524 hics203_incident_commander = findstr(data, hics203_tag_incident_commander);
525 hics203_incident_safety_officer = findstr(data, hics203_tag_incident_safety_officer);
526 hics203_incident_info_officer = findstr(data, hics203_tag_incident_info_officer);
527 hics203_liaison_officer = findstr(data, hics203_tag_liaison_officer);
528 hics203_prepared_by = findstr(data, hics203_tag_prepared_by);
529 hics203_facility = findstr(data, hics203_tag_facility);
530 hics203_planning_chief = findstr(data, hics203_tag_planning_chief);
531 hics203_planning_other = findstr(data, hics203_tag_planning_other);
532 hics203_res_unit = findstr(data, hics203_tag_res_unit);
533 hics203_sit_unit = findstr(data, hics203_tag_sit_unit);
534 hics203_doc_unit = findstr(data, hics203_tag_doc_unit);
535 hics203_dem_unit = findstr(data, hics203_tag_dem_unit);
536 hics203_log_chief = findstr(data, hics203_tag_log_chief);
537 hics203_log_other = findstr(data, hics203_tag_log_other);
538 hics203_log_sup_brch = findstr(data, hics203_tag_sup_brch);
539 hics203_bus_brch = findstr(data, hics203_tag_bus_brch);
540 hics203_stg_mgr = findstr(data, hics203_tag_stg_mgr);
541 hics203_med_care_brch = findstr(data, hics203_tag_med_care_brch);
542 hics203_infr_brch = findstr(data, hics203_tag_infr_brch);
543 hics203_sec_brch = findstr(data, hics203_tag_sec_brch);
544 hics203_hazmat_brch = findstr(data, hics203_tag_hazmat_brch);
545 hics203_hcc_agency = findstr(data, hics203_tag_hcc_agency);
546 hics203_svc_brch = findstr(data, hics203_tag_svc_brch);
547 hics203_hcc_rep = findstr(data, hics203_tag_hcc_rep);
548 hics203_ext_loc = findstr(data, hics203_tag_ext_loc);
549 hics203_ext_rep = findstr(data, hics203_tag_ext_rep);
550 hics203_ops_chief = findstr(data, hics203_tag_ops_chief);
551 hics203_ops_other = findstr(data, hics203_tag_ops_other);
552 hics203_fin_chief = findstr(data, hics203_tag_fin_chief);
553 hics203_fin_other = findstr(data, hics203_tag_fin_other);
554 hics203_time_unit = findstr(data, hics203_tag_time_unit);
555 hics203_proc_unit = findstr(data, hics203_tag_proc_unit);
556 hics203_comp_unit = findstr(data, hics203_tag_comp_unit);
557 hics203_cost_unit = findstr(data, hics203_tag_cost_unit);
558
559 for (int i = 0; i < 6; i++) {
560 hics203_tech_spc[i] = findstr(data, hics_n( hics203_tag_tech_spc, i) );
561 }
562 update_hics203form();
563 }
564
565 void cb_hics203_new()
566 {
567 if (check_hics203fields()) {
568 if (fl_choice2("Form modified, save?", "No", "Yes", NULL) == 1) {
569 update_header(CHANGED);
570 cb_hics203_save();
571 }
572 }
573 clear_hics203_form();
574 clear_header();
575 def_hics203_filename = ICS_msg_dir;
576 def_hics203_filename.append("new").append(HF203_EXT);
577 show_filename(def_hics203_filename);
578 using_hics203_template = false;
579 }
580
581 void cb_hics203_import()
582 {
583 fl_alert2("Not implemented");
584 }
585
586 void cb_hics203_export()
587 {
588 fl_alert2("Not implemented");
589 }
590
591 void cb_hics203_wrap_import(std::string wrapfilename, std::string inpbuffer)
592 {
593 clear_hics203_form();
594 read_hics203_buffer(inpbuffer);
595 def_hics203_filename = ICS_msg_dir;
596 def_hics203_filename.append(wrapfilename);
597 show_filename(def_hics203_filename);
598 using_hics203_template = false;
599 }
600
601 int eval_hics203_fsize()
602 {
603 Ccrc16 chksum;
604 evalstr.assign("[WRAP:beg][WRAP:lf][WRAP:fn ");
605 evalstr.append(base_hics203_filename).append("]");
606 update_hics203fields();
607 update_header(FROM);
608 evalstr.append(header("<hics203>"));
609 hics_buff203.clear();
610 make_hics_buff203(true);
611 if (hics_buff203.empty()) return 0;
612 compress_maybe( hics_buff203 );
613 evalstr.append( hics_buff203 );
614 evalstr.append("[WRAP:chksum ").append(chksum.scrc16(evalstr)).append("][WRAP:end]");
615 return evalstr.length();
616 }
617
618 void cb_hics203_wrap_export()
619 {
620 if (check_hics203fields()) {
621 if (fl_choice2("Form modified, save?", "No", "Yes", NULL) == 0)
622 return;
623 update_header(CHANGED);
624 }
625 update_hics203fields();
626
627 if (base_hics203_filename == std::string("new").append(HF203_EXT) ||
628 base_hics203_filename == std::string("default").append(HF203_EXT) )
629 if (!cb_hics203_save_as()) return;
630
631 std::string wrapfilename = WRAP_send_dir;
632 wrapfilename.append(base_hics203_filename);
633 wrapfilename.append(".wrap");
634 const char *p = FSEL::saveas(
635 "Save as wrap file",
636 "Wrap file\t*.{wrap,WRAP}",
637 wrapfilename.c_str());
638 if (p) {
639 std::string pext = fl_filename_ext(p);
640 wrapfilename = p;
641 update_header(FROM);
642 hics_buff203.assign(header("<hics203>"));
643 make_hics_buff203(true);
644 export_wrapfile(base_hics203_filename, wrapfilename, hics_buff203, pext != ".wrap");
645
646 hics_buff203.assign(header("<hics203>"));
647 make_hics_buff203(false);
648 write_hics203(def_hics203_filename);
649 }
650 }
651
652 void cb_hics203_wrap_autosend()
653 {
654 if (check_hics203fields()) {
655 if (fl_choice2("Form modified, save?", "No", "Yes", NULL) == 0)
656 return;
657 update_header(CHANGED);
658 }
659 update_hics203fields();
660
661 if (base_hics203_filename == std::string("new").append(HF203_EXT) ||
662 base_hics203_filename == std::string("default").append(HF203_EXT) )
663 cb_hics203_save_as();
664
665 update_header(FROM);
666 hics_buff203.assign(header("<hics203>"));
667 make_hics_buff203(true);
668 xfr_via_socket(base_hics203_filename, hics_buff203);
669
670 hics_buff203.assign(header("<hics203>"));
671 make_hics_buff203(false);
672 write_hics203(def_hics203_filename);
673 }
674
675 void cb_hics203_load_template()
676 {
677 std::string def_hics203_filename = def_hics203_TemplateName;
678 const char *p = FSEL::select(
679 "Open template file",
680 std::string("Template file\t*").append(HT203_EXT).c_str(),
681 def_hics203_filename.c_str());
682 if (p) {
683 clear_hics203_form();
684 read_data_file(p);
685 def_hics203_TemplateName = p;
686 show_filename(def_hics203_TemplateName);
687 using_hics203_template = true;
688 }
689 }
690
691 void cb_hics203_save_template()
692 {
693 if (!using_hics203_template) {
694 cb_hics203_save_as_template();
695 return;
696 }
697 std::string def_hics203_filename = def_hics203_TemplateName;
698 const char *p = FSEL::saveas(
699 "Save template file",
700 std::string("Template file\t*").append(HT203_EXT).c_str(),
701 def_hics203_filename.c_str());
702 if (p) {
703 update_header(CHANGED);
704 update_203fields();
705 hics_buff203.assign(header("<hics203>"));
706 make_hics_buff203();
707 write_hics203(p);
708 }
709 }
710
711 void cb_hics203_save_as_template()
712 {
713 std::string def_hics203_filename = def_hics203_TemplateName;
714 const char *p = FSEL::saveas(
715 "Save as template file",
716 std::string("Template file\t*").append(HT203_EXT).c_str(),
717 def_hics203_filename.c_str());
718 if (p) {
719 const char *pext = fl_filename_ext(p);
720 def_hics203_TemplateName = p;
721 if (strlen(pext) == 0) def_hics203_TemplateName.append(HT203_EXT);
722 remove_spaces_from_filename(def_hics203_TemplateName);
723 clear_header();
724 update_header(CHANGED);
725 update_203fields();
726 hics_buff203.assign(header("<hics203>"));
727 make_hics_buff203();
728 write_hics203(def_hics203_TemplateName);
729 show_filename(def_hics203_TemplateName);
730 using_hics203_template = true;
731 }
732 }
733
734 void cb_hics203_open()
735 {
736 const char *p = FSEL::select(
737 _("Open data file"),
738 std::string("HICS-203\t*").append(HF203_EXT).c_str(),
739 def_hics203_filename.c_str());
740 if (!p) return;
741 if (strlen(p) == 0) return;
742 clear_hics203_form();
743 read_data_file(p);
744 using_hics203_template = false;
745 def_hics203_filename = p;
746 show_filename(def_hics203_filename);
747 }
748
749 void write_hics203(std::string s)
750 {
751 FILE *file203 = fopen(s.c_str(), "w");
752 if (!file203) return;
753
754 fwrite(hics_buff203.c_str(), hics_buff203.length(), 1, file203);
755 fclose(file203);
756 }
757
758 bool cb_hics203_save_as()
759 {
760 const char *p;
761 std::string newfilename;
762
763 std::string name = named_file();
764 if (!name.empty()) {
765 name.append(F203_EXT);
766 newfilename = ICS_msg_dir;
767 newfilename.append(name);
768 } else
769 newfilename = def_hics203_filename;
770
771 p = FSEL::saveas(
772 _("Save data file"),
773 std::string("HICS-203\t*").append(HF203_EXT).c_str(),
774 newfilename.c_str());
775
776 if (!p) return false;
777 if (strlen(p) == 0) return false;
778
779 if (progStatus.sernbr_fname) update_sernbr();
780
781 const char *pext = fl_filename_ext(p);
782 def_hics203_filename = p;
783 if (strlen(pext) == 0) def_hics203_filename.append(HF203_EXT);
784
785 remove_spaces_from_filename(def_hics203_filename);
786 update_hics203fields();
787 update_header(NEW);
788 hics_buff203.assign(header("<hics203>"));
789 make_hics_buff203();
790 write_hics203(def_hics203_filename);
791
792 using_hics203_template = false;
793 show_filename(def_hics203_filename);
794 return true;
795 }
796
797 void cb_hics203_save()
798 {
799 if (base_hics203_filename == std::string("new").append(HF203_EXT) ||
800 base_hics203_filename == std::string("default").append(HF203_EXT) ||
801 using_hics203_template == true) {
802 cb_hics203_save_as();
803 return;
804 }
805 if (check_hics203fields()) update_header(CHANGED);
806 update_hics203fields();
807 hics_buff203.assign(header("<hics203>"));
808 make_hics_buff203();
809 write_hics203(def_hics203_filename);
810 using_hics203_template = false;
811 }
812
813 void cb_hics203_html()
814 {
815 std::string fname_name = fl_filename_name(def_hics203_filename.c_str());
816 size_t p = fname_name.rfind('.');
817 if (p != std::string::npos) fname_name.erase(p);
818
819 std::string hics203_fname = ICS_dir;
820 hics203_fname.append(fname_name);
821 hics203_fname.append(".html");
822
823 std::string html_text = "";
824
825 update_hics203fields();
826 std::string form203 = hics203_html_template;
827 replacestr(form203, TITLE, fname_name);
828
829 replacestr(form203, hics203_tag_incident, hics203_incident );
830 replacestr(form203, hics203_tag_date, hics203_date );
831 replacestr(form203, hics203_tag_time, hics203_time );
832 replacestr(form203, hics203_tag_op_period, hics203_op_period );
833 replacestr(form203, hics203_tag_incident_commander, hics203_incident_commander );
834 replacestr(form203, hics203_tag_incident_safety_officer, hics203_incident_safety_officer );
835 replacestr(form203, hics203_tag_incident_info_officer, hics203_incident_info_officer );
836 replacestr(form203, hics203_tag_liaison_officer, hics203_liaison_officer );
837 replacestr(form203, hics203_tag_prepared_by, hics203_prepared_by );
838 replacestr(form203, hics203_tag_facility, hics203_facility );
839 replacestr(form203, hics203_tag_planning_chief, hics203_planning_chief );
840 replacestr(form203, hics203_tag_planning_other, hics203_planning_other );
841 replacestr(form203, hics203_tag_res_unit, hics203_res_unit );
842 replacestr(form203, hics203_tag_sit_unit, hics203_sit_unit );
843 replacestr(form203, hics203_tag_doc_unit, hics203_doc_unit );
844 replacestr(form203, hics203_tag_dem_unit, hics203_dem_unit );
845 replacestr(form203, hics203_tag_log_chief, hics203_log_chief );
846 replacestr(form203, hics203_tag_log_other, hics203_log_other );
847 replacestr(form203, hics203_tag_sup_brch, hics203_log_sup_brch );
848 replacestr(form203, hics203_tag_bus_brch, hics203_bus_brch );
849 replacestr(form203, hics203_tag_stg_mgr, hics203_stg_mgr);
850 replacestr(form203, hics203_tag_med_care_brch, hics203_med_care_brch);
851 replacestr(form203, hics203_tag_infr_brch, hics203_infr_brch);
852 replacestr(form203, hics203_tag_sec_brch, hics203_sec_brch);
853 replacestr(form203, hics203_tag_hazmat_brch, hics203_hazmat_brch );
854 replacestr(form203, hics203_tag_hcc_agency, hics203_hcc_agency );
855 replacestr(form203, hics203_tag_svc_brch, hics203_svc_brch );
856 replacestr(form203, hics203_tag_hcc_rep, hics203_hcc_rep );
857 replacestr(form203, hics203_tag_ext_loc, hics203_ext_loc );
858 replacestr(form203, hics203_tag_ext_rep, hics203_ext_rep );
859 replacestr(form203, hics203_tag_ops_chief, hics203_ops_chief );
860 replacestr(form203, hics203_tag_ops_other, hics203_ops_other );
861 replacestr(form203, hics203_tag_fin_chief, hics203_fin_chief );
862 replacestr(form203, hics203_tag_fin_other, hics203_fin_other );
863 replacestr(form203, hics203_tag_time_unit, hics203_time_unit );
864 replacestr(form203, hics203_tag_proc_unit, hics203_proc_unit );
865 replacestr(form203, hics203_tag_comp_unit, hics203_comp_unit );
866 replacestr(form203, hics203_tag_cost_unit, hics203_cost_unit );
867
868 for (int i = 0; i < 6; i++) {
869 replacestr(form203, hics_n( hics203_tag_tech_spc, i ), hics203_tech_spc[i] );
870 }
871
872 FILE *file203 = fopen(hics203_fname.c_str(), "w");
873 fprintf(file203,"%s", form203.c_str());
874 fclose(file203);
875
876 open_url(hics203_fname.c_str());
877 }
878
879 void cb_hics203_msg_type()
880 {
881 if (tabs_msg_type->value() == tab_hics203 ) {
882 tab_hics203_type->value(tab_hics203_1);
883 show_filename(def_hics203_filename);
884 }
885 }
886
887 void cb_hics203_textout()
888 {
889 std::string hics203_fname = ICS_dir;
890 hics203_fname.append("hics203.txt");
891
892 update_hics203fields();
893 std::string form203 = hics203_text_template;
894
895 replacestr(form203, hics203_tag_incident, hics203_incident );
896 replacestr(form203, hics203_tag_date, hics203_date );
897 replacestr(form203, hics203_tag_time, hics203_time );
898 replacestr(form203, hics203_tag_op_period, hics203_op_period );
899 replacestr(form203, hics203_tag_incident_commander, hics203_incident_commander );
900 replacestr(form203, hics203_tag_incident_safety_officer, hics203_incident_safety_officer );
901 replacestr(form203, hics203_tag_incident_info_officer, hics203_incident_info_officer );
902 replacestr(form203, hics203_tag_liaison_officer, hics203_liaison_officer );
903 replacestr(form203, hics203_tag_prepared_by, hics203_prepared_by );
904 replacestr(form203, hics203_tag_facility, hics203_facility );
905 replacestr(form203, hics203_tag_planning_chief, hics203_planning_chief );
906 replacestr(form203, hics203_tag_planning_other, hics203_planning_other );
907 replacestr(form203, hics203_tag_res_unit, hics203_res_unit );
908 replacestr(form203, hics203_tag_sit_unit, hics203_sit_unit );
909 replacestr(form203, hics203_tag_doc_unit, hics203_doc_unit );
910 replacestr(form203, hics203_tag_dem_unit, hics203_dem_unit );
911 replacestr(form203, hics203_tag_log_chief, hics203_log_chief );
912 replacestr(form203, hics203_tag_log_other, hics203_log_other );
913 replacestr(form203, hics203_tag_sup_brch, hics203_log_sup_brch );
914 replacestr(form203, hics203_tag_bus_brch, hics203_bus_brch );
915 replacestr(form203, hics203_tag_stg_mgr, hics203_stg_mgr);
916 replacestr(form203, hics203_tag_med_care_brch, hics203_med_care_brch);
917 replacestr(form203, hics203_tag_infr_brch, hics203_infr_brch);
918 replacestr(form203, hics203_tag_sec_brch, hics203_sec_brch);
919 replacestr(form203, hics203_tag_hazmat_brch, hics203_hazmat_brch );
920 replacestr(form203, hics203_tag_hcc_agency, hics203_hcc_agency );
921 replacestr(form203, hics203_tag_svc_brch, hics203_svc_brch );
922 replacestr(form203, hics203_tag_hcc_rep, hics203_hcc_rep );
923 replacestr(form203, hics203_tag_ext_loc, hics203_ext_loc );
924 replacestr(form203, hics203_tag_ext_rep, hics203_ext_rep );
925 replacestr(form203, hics203_tag_ops_chief, hics203_ops_chief );
926 replacestr(form203, hics203_tag_ops_other, hics203_ops_other );
927 replacestr(form203, hics203_tag_fin_chief, hics203_fin_chief );
928 replacestr(form203, hics203_tag_fin_other, hics203_fin_other );
929 replacestr(form203, hics203_tag_time_unit, hics203_time_unit );
930 replacestr(form203, hics203_tag_proc_unit, hics203_proc_unit );
931 replacestr(form203, hics203_tag_comp_unit, hics203_comp_unit );
932 replacestr(form203, hics203_tag_cost_unit, hics203_cost_unit );
933
934 for (int i = 0; i < 6; i++) {
935 replacestr(form203, hics_n( hics203_tag_tech_spc, i ), hics203_tech_spc[i] );
936 }
937
938 FILE *file203 = fopen(hics203_fname.c_str(), "w");
939 fprintf(file203,"%s", form203.c_str());
940 fclose(file203);
941
942 open_url(hics203_fname.c_str());
943 }