#include #include #include #include #include #include #include #include "ba8400.h" /////////////////////////////////////////////////////////// // TFormer_mask /////////////////////////////////////////////////////////// class TFormer_mask : public TAutomask { bool _doc; protected: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); void parse_field_line(const TString& line, TReport_field& rf) const; void import_section(TScanner& scan, TReport_section& rs) const; void import_sections(TScanner& scan, TReport& rep) const; void import_use(TScanner& scan, TReport& rep) const; void import(); public: TFormer_mask(); }; void TFormer_mask::import_use(TScanner& scan, TReport& rep) const { TString use; int parse_use = 0; while (scan.ok()) { const TString& line = scan.line(); if (line.empty()) break; if (parse_use == 0 && line.starts_with("US")) parse_use = 1; if (parse_use == 1) { if (line.starts_with("EN")) { parse_use = 2; break; } else use << line << '\n'; } } if (!use.blank()) { if (_doc) { int pos = use.find(" 33"); if (pos >= 0 && pos < 10) use.overwrite("4", pos+2); pos = use.find("JOIN 34"); if (pos >= 0) use.overwrite("3", pos+6); } rep.set_recordset(use); } } void TFormer_mask::parse_field_line(const TString& line, TReport_field& rf) const { TToken_string head(line, ' '); head.trim(); head.strip_d_spaces(); if (head.starts_with("FI")) { TString fld = head.get(1); if (_doc) { if (fld.find("->") < 0) fld.insert("33->"); } rf.set_field(fld); } else if (head.starts_with("FL")) { const TString& flags = head.get(1); for (int i = 0; flags[i]; i++) { switch (flags[i]) { case 'D': rf.hide(); rf.deactivate(); break; case 'H': rf.hide(); break; case 'U': if (rf.type() == 'V') rf.set_type('P'); // Trasforma da Valuta a Prezzo break; default: break; } } } else if (head.starts_with("ME")) { head.add("MESSAGE", 0); TString me = rf.prescript(); me << head << '\n'; rf.set_prescript(head); } else if (head.starts_with("PR")) { const int x = 100*(head.get_int(1)-1); const int y = 100*(head.get_int()-1); rf.set_pos(x, y); if (rf.type() == 'I') rf.set_field(head.get()); } } void TFormer_mask::import_section(TScanner& scan, TReport_section& rs) const { TToken_string head(256, ' '); int in_field = 0; TReport_field* cur_field = NULL; while (scan.ok()) { TString& line = scan.line(); if (line.empty()) break; if (line.starts_with("BE")) { in_field++; if (in_field == 1) { head.trim(); head.strip_d_spaces(); const TString16 str_type = head.get(0); char type = ' '; if (str_type.starts_with("FI")) type = 'I'; else type = str_type[0]; if (type > ' ') { const int id = head.get_int(1); const int width = 100*head.get_int(); const int height = 100*head.get_int(); cur_field = new TReport_field(&rs); cur_field->set_type(type); if (id > 0) cur_field->set_id(id); if (width > 0) cur_field->set_width(width); if (height > 0) { if (_doc && type == 'S' && height >= 5 && rs.type() == 'B') cur_field->set_height(0); else cur_field->set_height(height); } if (strchr("NVP", type) != NULL) cur_field->set_horizontal_alignment('R'); rs.add(cur_field); } } } else if (line.starts_with("EN")) { if (in_field >= 0) { in_field--; // END of field cur_field = NULL; } if (in_field < 0) break; // END of section } else if (cur_field != NULL) { parse_field_line(line, *cur_field); } head = line; } } void TFormer_mask::import_sections(TScanner& scan, TReport& rep) const { while (scan.ok()) { TString& line = scan.line(); if (line.empty()) break; if (line.starts_with("SE")) { line.trim(); line.strip_d_spaces(); TToken_string head(line, ' '); const TString16 str_name = head.get(1); const TString16 str_type = head.get(); int height = 100*head.get_int(); char type = ' '; int level = 0; if (str_name.starts_with("BO")) { if (str_type.starts_with("OD")) { type = 'B'; level = 1; height = 0; } } if (str_name.starts_with("FO")) { if (str_type.starts_with("LA")) { type = 'F'; level = 1; } if (str_type.starts_with("OD")) { type = 'F'; level = 0; } } else if (str_name.starts_with("GR")) { if (str_type.starts_with("OD")) { type = 'B'; level = 0; } } else if (str_name.starts_with("HE")) { if (str_type.starts_with("FI")) { type = 'H'; level = 1; } if (str_type.starts_with("OD")) { type = 'H'; level = 0; } } if (type > ' ') { TReport_section& cur_sec = rep.section(type, level); if (height >= 0) cur_sec.set_height(height); else { if (type == 'F') { const TPoint abolute_footer_pos(0, -height); cur_sec.set_pos(abolute_footer_pos); } } import_section(scan, cur_sec); } } } const char* hf = "HF"; for (int i = 0; hf[i]; i++) { TReport_section* sec = rep.find_section(hf[i], 0); if (sec != NULL) { const bool yes = rep.find_section(hf[i], 1) != NULL; sec->hide_if_needed(yes); } } } void TFormer_mask::import() { _doc = get_bool(F_DOC); TScanner scan(get(F_FORM)); TReport rep; import_use(scan, rep); import_sections(scan, rep); if (_doc) rep.set_libraries("ve1100.alx"); rep.save(get(F_REPORT)); } bool TFormer_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) { case F_FORM: if (e == fe_modify) { TFilename output = get(F_REPORT); TFilename path = output.path(); if (path.empty()) { path = firm2dir(-1); path.add("custom"); } const TFilename input = o.get(); output = path; output.add(input.name()); output.ext("rep"); output.lower(); set(F_REPORT, output); enable(DLG_ELABORA, input.exist()); } break; case F_REPORT: if (e == fe_modify) { const TFilename output = get(F_REPORT); enable(DLG_PRINT, output.exist()); } break; case DLG_ELABORA: if (e == fe_button) { const TFilename output = get(F_REPORT); if (output.exist()) { if (!yesno_box(TR("Il file %s esiste gia':\nSi desidera sovrascriverlo?"), (const char*)output)) return false; } import(); enable(DLG_PRINT, output.exist()); } break; case DLG_PRINT: if (e == fe_button) { const TFilename output = get(F_REPORT); if (output.exist()) { TString cmd; cmd << "ba8 -2 " << output; TExternal_app app(cmd); app.run(); return false; // Altrimenti esce dalla maschera } else return error_box(TR("Il file %s non esiste"), (const char*)output); } break; default: break; } return true; } TFormer_mask::TFormer_mask() : TAutomask("ba8400a") { } /////////////////////////////////////////////////////////// // TFormer_app /////////////////////////////////////////////////////////// class TFormer_app : public TSkeleton_application { protected: virtual void main_loop(); }; void TFormer_app::main_loop() { TFormer_mask m; m.run(); } int ba8400(int argc, char* argv[]) { TFormer_app app; app.run(argc, argv, TR("Form Converter")); return 0; }