summaryrefslogtreecommitdiffstats
path: root/smenu.c
diff options
context:
space:
mode:
authorpgen <p.gen.progs@gmail.com>2023-05-10 20:09:20 +0200
committerpgen <p.gen.progs@gmail.com>2023-05-10 21:13:09 +0200
commitb74233bcc840808904dadc9a2aa898f99652dc0a (patch)
tree96705a2a4d2a6953119a5d7fcb8e52a37b030973 /smenu.c
parent32ba80a72f86110f296aa140d191471fc8006f61 (diff)
Fix alignments in case of ambiguous directives
Diffstat (limited to 'smenu.c')
-rw-r--r--smenu.c53
1 files changed, 44 insertions, 9 deletions
diff --git a/smenu.c b/smenu.c
index 9262781..875e439 100644
--- a/smenu.c
+++ b/smenu.c
@@ -10639,18 +10639,49 @@ main(int argc, char * argv[])
if (regexec(&re, word_a[wi].str + daccess.flength, (int)0, NULL, 0)
== 0)
{
+ int already_aligned = 0;
+
/* We have a match. */
/* '''''''''''''''' */
interval = xmalloc(sizeof(interval_t));
interval->low = interval->high = col_index;
- /* Append a new interval containing the current column number */
- /* in the interval list matching the regex list. */
- /* '''''''''''''''''''''''''''''''''''''''''''''''''''''''''' */
- if (*interval_list_a[i] == NULL)
- *interval_list_a[i] = ll_new();
+ /* Look if the column has already been inserted in another */
+ /* interval list. */
+ /* ''''''''''''''''''''''''''''''''''''''''''''''''''''''' */
+ for (int j = 0; j < 3; j++)
+ {
+ interval_t inter;
+ ll_node_t * n;
+
+ /* Quick continuation. */
+ /* ''''''''''''''''''' */
+ if (i == j || *interval_list_a[j] == NULL)
+ continue;
- ll_append(*interval_list_a[i], interval);
+ n = (*interval_list_a[j])->head;
+ while (n)
+ {
+ inter = *(interval_t *)(n->data);
+ if (col_index >= inter.low && col_index <= inter.high)
+ {
+ already_aligned = 1; /* This column is already aligned. */
+ break;
+ }
+ n = n->next;
+ }
+ }
+
+ if (!already_aligned)
+ {
+ /* Append a new interval containing the current column number */
+ /* in the interval list matching the regex list. */
+ /* '''''''''''''''''''''''''''''''''''''''''''''''''''''''''' */
+ if (*interval_list_a[i] == NULL)
+ *interval_list_a[i] = ll_new();
+
+ ll_append(*interval_list_a[i], interval);
+ }
}
node = node->next;
}
@@ -10951,13 +10982,15 @@ main(int argc, char * argv[])
/* modified to point to the next one of the list is the */
/* current column is greater than the max column in the */
/* pointed interval. */
+ /* An already aligned column will not be realigned. */
/* """"""""""""""""""""""""""""""""""""""""""""""""""""""""" */
for (int i = 0; i < 3; i++)
{
if (cur_col_node_a[i] != NULL)
{
interval = *(interval_t *)(cur_col_node_a[i]->data);
- if (col_index >= interval.low && col_index <= interval.high)
+ if (aligned_a[col_index] == 'N' && col_index >= interval.low
+ && col_index <= interval.high)
{
/* Tell that the word is already aligned when column */
/* alignments have precedence over row alignments. */
@@ -10983,7 +11016,8 @@ main(int argc, char * argv[])
if (cur_row_interval_node_a[i] != NULL)
{
interval = *(interval_t *)(cur_row_interval_node_a[i]->data);
- if (row_index >= interval.low && row_index <= interval.high)
+ if (row_alignment == AL_NONE && row_index >= interval.low
+ && row_index <= interval.high)
{
row_alignment = alignment_a[i];
if (aligned_a[col_index] == 'N')
@@ -11003,7 +11037,8 @@ main(int argc, char * argv[])
re = (regex_t *)(cur_row_regex_node_a[i]->data);
- if (regexec(re, tstr, (int)0, NULL, 0) == 0)
+ if (row_alignment == AL_NONE
+ && regexec(re, tstr, (int)0, NULL, 0) == 0)
{
row_alignment = alignment_a[i];
if (aligned_a[col_index] == 'N')