commit 468067a8fdf246671997930166c26957b052d8cf
parent f21abfb2d751e7d2c228cae1a6c40e69609a7174
Author: lumidify <nobody@lumidify.org>
Date: Sat, 4 Apr 2020 18:36:26 +0200
Fix writing replacement words when revert is set
Diffstat:
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/transliterate.pl b/transliterate.pl
@@ -653,6 +653,10 @@ sub interpret_config {
# the "replacement id" is just the number of the replacement group,
# starting at 0 with the first group in the config
$config{"table_paths"} = {};
+ # reverted_tables stores a hash of the paths of all tables that are
+ # reverted so that replacements added from the GUI are added in the
+ # right order
+ $config{"reverted_tables"} = {};
# these are the paths of the tables that are displayed in the GUI
$config{"display_tables"} = {};
# a mapping between the table ids and tables for all tables used as
@@ -717,6 +721,9 @@ sub interpret_config {
return if !$table;
$path_to_table{$table_path} = $table;
}
+ if ($table_args{"revert"}) {
+ $config{"reverted_tables"}->{$table_path} = 1;
+ }
my $table_id = $cmd->[1]->{"value"};
$tables{$table_id} = $table;
$table_id_to_path{$table_id} = $table_path;
@@ -909,12 +916,17 @@ sub handle_unknown_word_action {
my $table_path = $action->[3];
my $word = $action->[1];
my $replace_word = $action->[2];
+ # make sure to write the words in the correct order if the
+ # tables were reverted while loading
+ my $reverted = exists $config->{"reverted_tables"}->{$table_path};
+ my $word_abs = $reverted ? $action->[2] : $action->[1];
+ my $replace_word_abs = $reverted ? $action->[1] : $action->[2];
my $fh;
if (!open($fh, ">>", $table_path)) {
warn "ERROR: Can't open table file \"$table_path\" for appending.\n";
return 1;
}
- print($fh $word . $config->{tablesep} . $replace_word . "\n");
+ print($fh $word_abs . $config->{tablesep} . $replace_word_abs . "\n");
close($fh);
# loop over all table ids that are impacted by this file
foreach my $replacement (@{$config->{"table_paths"}->{$table_path}}) {
@@ -1775,6 +1787,15 @@ set and the new one doesn't. This is technically a problem, but I don't know of
any real-world case where it would be a problem, so I'm too lazy to change it.
Tell me if it actually becomes a problem for you.
+WARNING: Don't load the same table file both with and without B<revert> in the same
+config! When a replacement word is added through the GUI, the program has to know
+which way to write the words. Currently, whenever a table file is loaded with
+B<revert> anywhere in the config (even if it is loaded without B<revert> in a
+different place), words will automatically be written as if B<revert> was on. I
+cannot currently think of any reason why someone would want to load a file both
+with and without B<revert> in the same config, but I still wanted to add this
+warning just in case.
+
=item B<expand> <table identifier> <word ending table> [noroot]
Expand the table C<< <table identifier> >>, i.e. generate all the word forms using