36 #define AWARBASE_XFERSET_TMP "tmp/fts/"
37 #define AWARBASE_XFERRULE_TMP AWARBASE_XFERSET_TMP "rule/"
39 #define AWAR_XFERSET_SELECTED AWARBASE_XFERSET_TMP "focus" // Note: FTS clients like importer or exporter react if this awar gets touched
40 #define AWAR_XFERSET_COMMENT AWARBASE_XFERSET_TMP "comment"
41 #define AWAR_XFERSET_UNDEFINED AWARBASE_XFERSET_TMP "undefined"
44 #define AWAR_XFERSET_FTSBASE AWARBASE_XFERSET_TMP "file"
45 #define AWAR_XFERSET_FTSNAME AWAR_XFERSET_FTSBASE "/file_name"
46 #define AWAR_XFERSET_FTSFILTER AWAR_XFERSET_FTSBASE "/filter"
47 #define AWAR_XFERSET_FTSDIR AWAR_XFERSET_FTSBASE "/directory"
49 #define AWAR_XFERRULE_SELECTED AWARBASE_XFERRULE_TMP "focus"
50 #define AWAR_XFERRULE_TARGETFIELD AWARBASE_XFERRULE_TMP "rule"
51 #define AWAR_XFERRULE_ACI AWARBASE_XFERRULE_TMP "aci"
52 #define AWAR_XFERRULE_SEP AWARBASE_XFERRULE_TMP "sep"
53 #define AWAR_XFERRULE_TYPE AWARBASE_XFERRULE_TMP "type"
54 #define AWAR_XFERRULE_LOSS AWARBASE_XFERRULE_TMP "loss"
55 #define AWAR_XFERRULE_INPUT_FIELDS AWARBASE_XFERRULE_TMP "input/fields" // contains list of fieldnames separated by ';'
56 #define AWAR_XFERRULE_INPUT_SELECTED AWARBASE_XFERRULE_TMP "input/focus" // field selected in AWAR_XFERRULE_INPUT_FIELDS (duplicate entries contain suffix! better not use content of this awar)
57 #define AWAR_XFERRULE_AVAIL_SELECTED AWARBASE_XFERRULE_TMP "avail" // selected available field
58 #define AWAR_XFERRULE_AVAIL_CATEGORY AWARBASE_XFERRULE_TMP "acat" // shown available fields
59 #define AWAR_XFERRULE_FIELD AWARBASE_XFERRULE_TMP "field" // content of fieldname textbox
63 #define NO_XFERSET_SELECTED ""
68 inline bool is_info(
const char *field) {
return field[0] ==
'<'; }
72 bool operator()(
const string& s1,
const string& s2)
const {
74 if (!cmp) cmp = s1.compare(s2);
84 typedef set<string, lt_field>
StrSet;
103 return result.c_str();
118 char *nameOnly =
NULp;
132 failReason =
"load error";
139 failReason =
"no transfer set";
151 idx = atoi(rule_id+4)-1;
161 return ruleset->validIdx(idx) ?
NULp :
"rule index out-of-bounds";
169 const char *ruleId = idx>=0 && idx<ruleCount ?
ruleSelId(idx) :
"";
180 failReason =
"no rule";
184 if (ruleset.
isSet()) {
186 if (!failReason) rule = ruleset->getPtr(idx);
200 error =
"no ruleset selected";
203 error = ruleset->saveTo(fts.c_str());
218 typedef map<string, int> StrMap;
220 bool testsAllRules = onlyLintRuleWithIdx < 0;
221 int warningsPrinted = 0;
222 StrMap targetFieldCount;
225 for (
size_t r = 0; r<ruleset->size(); ++r) {
226 const Rule& rule = ruleset->get(r);
229 StrMap::iterator found = targetFieldCount.find(dest);
230 if (found == targetFieldCount.end()) {
231 targetFieldCount[dest] = 1;
238 bool lintThisRule = testsAllRules || (onlyLintRuleWithIdx ==
int(r));
240 if (dest ==
"name") {
241 aw_message(
"Warning: potentially dangerous target field 'name' detected");
244 if (targetFieldCount[dest] == 2) {
250 else if (!testsAllRules) {
256 if (!checkDupOf.empty()) {
257 if (targetFieldCount[checkDupOf]>2) {
265 if (warningsPrinted) {
275 static string last_linted_fts;
278 if (last_linted_fts.empty()) {
281 else if (fts != last_linted_fts) {
284 else if (onlyLintRuleWithIdx>=0) {
290 last_linted_fts = fts;
299 error =
"no rule selected. update impossible.";
303 if (ruleset.
isSet()) {
306 ruleset->replace(idx, newRule);
321 error =
"no name specified";
326 fts_nameOnly ? fts_nameOnly : fullfts);
338 const char *failReason;
342 const bool haveRule = rule.
isSet();
349 if (haveRule && rule->forcesType()) forcedType = rule->getTargetType();
364 newRule = aci[0] ? Rule::makeAciConverter(src, sep, aci, dest) : Rule::makeSimple(src, sep, dest);
369 if (type !=
GB_NONE) newRule->setTargetType(type);
370 if (permitLoss) newRule->permitPrecisionLoss();
381 const char *failReason;
386 printf(
"rebuild_rule_from_awars_cb:\n");
388 if (selRule.
isSet()) printf(
" selRule config: %s\n", selRule->getConfig().c_str());
389 if (newRule.
isSet()) printf(
" newRule config: %s\n", newRule->getConfig().c_str());
393 string selCfg = selRule->getConfig();
394 string newCfg = newRule->getConfig();
395 if (selCfg != newCfg) {
397 fputs(
"Rule has changed!\n", stdout);
418 bool isPart = part[0];
426 int shownFieldCount = 0;
428 const char *field = f->c_str();
434 if (!isPart || strcasestr(field, part)) {
435 avail->
insert(field, field);
443 const char *
info =
"";
445 if (fieldCount == 0) info =
"<no fields detected>";
468 for (
unsigned i = 0; i<source.size(); ++i) {
474 for (
unsigned i = 0; i<unwanted.size(); ++i) {
523 if (rulesetPtr.
isSet()) {
536 if (fieldScanner == currentFieldScanner) {
560 for (
int i = 0; field[i]; ++i) {
561 const char *disp = field[i];
577 const char *defaultText;
586 for (
size_t r = 0; r<ruleset->size(); ++r) {
587 const Rule& rule = ruleset->get(r);
590 defaultText =
"no rule";
622 if (ruleset.
isSet()) {
632 toAdd = Rule::makeSimple(
"",
"",
"");
635 int newIdx = ruleset->insertBefore(idx, toAdd);
651 error =
"no rule selected. nothing deleted.";
655 if (ruleset.
isSet()) {
670 const bool fromStack = !toStack;
672 if (fromStack && stack.empty()) {
673 error =
"nothing copied. cannot paste.";
678 if (idx<0 && toStack) {
679 error =
"no rule selected. nothing copied.";
683 if (ruleset.
isSet()) {
687 stack.push_back(ruleset->getPtr(idx));
694 int newIdx = ruleset->insertBefore(idx, rule);
706 else if (fromStack) {
707 error =
"did not paste to nowhere (no ruleset selected)";
717 free(new_input_fields);
725 aw_message(
"Please select an available field or\n"
726 "enter a custom field name in the textbox below.");
735 const char *used_input_fields = awar_input_fields->
read_char_pntr();
738 if (used_input_fields[0]) {
761 const char *used_input_fields = awar_input_fields->
read_char_pntr();
763 if (used_input_fields[0]) {
769 int maxIdx = ifield.
size()-1;
770 bool needUpdate =
false;
779 ifield.
move(selIdx, selIdx+1);
786 ifield.
move(selIdx, selIdx-1);
804 AW_window_simple *aws =
new AW_window_simple;
805 aws->init(awr,
"DEFINE_RULE",
"Define rules for field transfer");
806 aws->load_xfig(
"fts_ruledef.fig");
808 aws->button_length(8);
812 aws->create_button(
"CLOSE",
"CLOSE",
"C");
816 aws->create_button(
"HELP",
"HELP",
"H");
830 aws->label(
"Transfer undefined fields?");
842 aws->update_option_menu();
853 aws->insert_option (
"Ascii text",
"s",
GB_STRING);
854 aws->insert_option (
"Rounded numerical",
"i",
GB_INT);
855 aws->insert_option (
"Floating-point n.",
"F",
GB_FLOAT);
856 aws->insert_option (
"Bitmask (0/1)",
"B",
GB_BITS);
857 aws->insert_default_option(
"Automatic",
"A",
GB_NONE);
858 aws->update_option_menu();
864 aws->button_length(6);
865 aws->auto_space(5, 5);
868 aws->callback(
add_rule_cb); aws->create_button(
"ADD_RULE",
"ADD");
869 aws->callback(
del_rule_cb); aws->create_button(
"DEL_RULE",
"DEL");
870 aws->callback(makeWindowCallback(
rule_stack_cb,
true)); aws->create_button(
"COPY_RULE",
"COPY");
871 aws->callback(makeWindowCallback(
rule_stack_cb,
false)); aws->create_button(
"PASTE_RULE",
"PASTE");
874 aws->callback(makeWindowCallback(
move_field_cb,
MV_OFF, input)); aws->create_button(
"INPUT_DROP",
"DROP");
875 aws->callback(makeWindowCallback(
move_field_cb,
MV_UP, input)); aws->create_button(
"INPUT_UP",
"UP");
876 aws->callback(makeWindowCallback(
move_field_cb,
MV_DOWN, input)); aws->create_button(
"INPUT_DOWN",
"DOWN");
879 aws->callback(makeWindowCallback(
add_field_cb, input)); aws->create_button(
"INPUT_ADD",
"FROM");
881 aws->callback(makeWindowCallback(
clear_field_cb)); aws->create_button(
"CLEAR",
"CLEAR");
909 static bool recursion =
false;
930 static bool recursion =
false;
938 bool transferUndef =
false;
970 string saved = ruleset->getComment();
972 if (strcmp(saved.c_str(), changed) != 0) {
973 ruleset->setComment(changed);
979 if (transferUndef != ruleset->shallTransferUndefFields()) {
980 ruleset->set_transferUndefFields(transferUndef);
996 aw_message(
"Please select an existing FTS, then try again to change this setting.");
1014 error = empty.
saveTo(fullfts.c_str());
1033 string fullTargetFts;
1070 const char *prompt =
NULp;
1071 const char *butTxt =
NULp;
1074 title =
"Copy ruleset";
1075 prompt =
"Enter the name of the new ruleset:";
1079 title =
"Rename ruleset";
1080 prompt =
"Enter the new name for the ruleset:";
1153 AW_window_simple *aws =
new AW_window_simple;
1154 aws->init(awr,
"SELECT_FTS",
"Select field transfer set (FTS)");
1155 aws->load_xfig(
"fts_select.fig");
1157 aws->button_length(8);
1161 aws->create_button(
"CLOSE",
"CLOSE",
"C");
1165 aws->create_button(
"HELP",
"HELP",
"H");
1177 aws->create_button(
"CREATE",
"CREATE",
"N");
1181 aws->create_button(
"EDIT",
"EDIT",
"E");
1185 aws->create_button(
"COPY",
"COPY",
"Y");
1189 aws->create_button(
"DELETE",
"DELETE",
"D");
1193 aws->create_button(
"RENAME",
"RENAME",
"R");
1197 aws->create_button(
"NONE",
"NONE",
"O");
1213 if (fieldScanner != currentFieldScanner) {
static StrSet knownFields
#define AWAR_XFERSET_COMMENT
set< string, lt_field > StrSet
GB_CSTR GB_path_in_arbprop(const char *relative_path)
void AW_set_selected_fullname(AW_root *awr, const char *awar_prefix, const char *to_fullname)
static StrArray knownFieldsRulesetInput
GB_ERROR GB_safe_copy_file(const char *oldpath, const char *newpath)
void XFER_select_RuleSet(AW_window *aww, const char *awar_selected_fts, const AvailableFieldScanner *fieldScanner)
#define AWAR_XFERRULE_INPUT_SELECTED
static void refresh_inputfield_selbox_cb(AW_root *awr, AW_selection_list *input)
void select_element_at(int wanted_index)
void insert_default(const char *displayed, const AW_scalar &value)
char * getNameOnly(const char *fullpath)
static const char * get_selected_FTS()
static void noRuleset_cb()
static void initXferAwars(AW_root *awr)
static void selected_fts_changed_cb(AW_root *awr)
string getShortDescription() const
static bool ignoreRuleDetailChange
static const AvailableFieldScanner * currentFieldScanner
StrSet::iterator StrSetIter
const char * GBS_global_string(const char *templat,...)
static ExportFieldScanner fieldScanner
char * AW_get_selected_fullname(AW_root *awr, const char *awar_prefix)
void AW_POPDOWN(AW_window *window)
#define AWAR_XFERRULE_SEP
int get_index_of_selected()
int GB_unlink(const char *path)
static GB_ERROR check_valid_target_fts(const char *fullfts)
#define AWAR_XFERRULE_FIELD
#define NO_XFERSET_SELECTED
__ATTR__USERESULT GB_ERROR saveTo(const char *filename) const
static RulePtr build_rule_from_awars(AW_root *awr)
AW_awar * add_callback(const RootCallback &cb)
static RuleSetPtr getSelectedRuleset(const char *&failReason)
#define AWAR_XFERRULE_TARGETFIELD
void mergeToKnownFields(const StrArray &source)
#define AWAR_XFERRULE_INPUT_FIELDS
void insert(const char *displayed, const AW_scalar &value)
GB_ERROR GB_safe_rename_file(const char *oldpath, const char *newpath)
static void createRuleset_cb(AW_window *aww)
GB_ERROR GB_check_hkey(const char *key) __ATTR__USERESULT
const char * read_char_pntr() const
GB_ERROR GB_await_error()
static AW_root * SINGLETON
WindowCallback makeHelpCallback(const char *helpfile)
GB_ERROR check_valid_existing_fts(const char *fullfts)
static bool warnAboutDuplicateTargets
int getSelectedRuleIndex()
static RulePtr getSelectedRule(const char *&failReason)
const char * awarname(const char *awarname_template, int idx)
bool isSet() const
test if SmartPtr is not NULp
static void move_field_cb(AW_window *aww, FieldMoveDest dest, AW_selection_list *inputSel)
static void popup_rule_definition_window(AW_root *awr)
static void refresh_rule_selection_box_cb(AW_root *awr, AW_selection_list *rules)
AW_awar * awar_selected_FTS()
static void deleteRuleset_cb()
const string & targetField() const
static void selected_rule_changed_cb(AW_root *awr)
bool operator()(const string &s1, const string &s2) const
bool shallTransferUndefFields() const
static StrArray knownFieldsClientInput
static void error(const char *msg)
#define AWAR_XFERSET_FTSNAME
void AW_create_fileselection_awars(AW_root *awr, const char *awar_base, const char *directories, const char *filter, const char *file_name)
const string & getComment() const
static void clear_field_cb(AW_window *aww)
static void lintRuleset(RuleSetPtr ruleset)
static void del_rule_cb(AW_window *)
#define AWAR_XFERRULE_ACI
static void rule_stack_cb(AW_window *, bool toStack)
bool is_info(const char *field)
char * read_string() const
void put_before(int insert_before, const char *elem)
AW_awar * awar(const char *awar)
const char * ruleSelId(int idx)
const char * XFER_getFullFTS(const char *name)
#define AWAR_XFERSET_UNDEFINED
void AW_refresh_fileselection(AW_root *awr, const char *awar_prefix)
static char * cat(char *toBuf, const char *s1, const char *s2)
static void selectRule(int idx, int ruleCount)
static void editRuleset_cb(AW_window *aww)
GB_CSTR GB_append_suffix(const char *name, const char *suffix)
static void init_rule_definition_awars(AW_root *awr)
char * GBT_join_strings(const CharPtrArray &strings, char separator)
fputs(TRACE_PREFIX, stderr)
#define AWAR_XFERRULE_AVAIL_SELECTED
GB_CSTR GB_concat_path(GB_CSTR anypath_left, GB_CSTR anypath_right)
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
static bool ignoreRulesetAwarChange
GB_ERROR saveChangedRuleset(RuleSetPtr ruleset)
static void fts_filesel_changed_cb(AW_root *awr)
#define AWAR_XFERRULE_LOSS
static void askCopyMoveRuleset_cb(AW_window *, copyMoveMode mode)
bool GB_is_directory(const char *path)
void set_selected_FTS(const char *name)
static void add_rule_cb(AW_window *aww)
static StrArray knownFieldsClientOutput
AW_awar * map(const char *awarn)
void move(int from, int to)
GB_ERROR checkValidIndex(RuleSetPtr ruleset, int idx)
static void deselectRule()
static void overwriteSelectedRule(RulePtr newRule)
void aw_message(const char *msg)
static void selected_fts_file_changed(const char *, ChangeReason reason)
#define AWAR_XFERRULE_TYPE
void GB_split_full_path(const char *fullpath, char **res_dir, char **res_fullname, char **res_name_only, char **res_suffix)
static void add_field_cb(AW_window *aww, AW_selection_list *inputSel)
static void refresh_availfield_selbox_cb(AW_root *awr, AW_selection_list *avail)
bool GB_is_readablefile(const char *filename)
#define AWAR_XFERSET_SELECTED
static void refresh_available_fields_from_ruleset(AW_root *awr, RuleSetPtr rulesetPtr)
void AW_create_fileselection(AW_window *aws, const char *awar_prefix, const char *at_prefix, const char *pwd, DirDisplay disp_dirs, bool allow_wildcards)
GB_ERROR write_string(const char *aw_string)
void GBT_split_string(ConstStrArray &dest, const char *namelist, const char *separator, SplitMode mode)
static int onlyLintRuleWithIdx
bool ARB_strBeginsWith(const char *str, const char *with)
#define AWAR_XFERRULE_SELECTED
ARB_ERROR getError() const
#define AWAR_XFERRULE_AVAIL_CATEGORY
static void mergeKnownFields(AW_root *awr)
void updateChangedInputFields(const ConstStrArray &ifield, AW_awar *awar_input_fields)
size_t removeFromKnownFields(const StrArray &unwanted)
const char * make_unique_key(const char *key)
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
void XFER_refresh_available_fields(AW_root *awr, const AvailableFieldScanner *fieldScanner, FieldsToScan whatToScan)
static void availfield_selected_cb(AW_root *awr)
static void ruleset_awar_changed_cb(AW_root *awr, const char *awarname)
static GB_ERROR copyMoveRuleset_cb(const char *new_name, copyMoveMode mode)
static int info[maxsites+1]
void GBT_splitNdestroy_string(ConstStrArray &names, char *&namelist, const char *separator, SplitMode mode)
void refresh_fts_selbox()
static void rebuild_rule_from_awars_cb(AW_root *awr)
static StrArray knownFieldsRulesetOutput
#define AWAR_XFERSET_FTSBASE
GB_ERROR write_int(long aw_int)
virtual void scanFields(StrArray &fields, FieldsToScan whatToScan) const =0
static void popup_ruleset_admin_window(AW_root *awr)
void aw_message_if(GB_ERROR error)
static void lintRulesetOnce(RuleSetPtr ruleset)
std::vector< RulePtr > RuleContainer
void AWT_activate_prompt(const char *title, const char *prompt, const char *defaultResult, const char *button, const ResultHandler &handle_result, const char *helpfile, const char *srt)