Skip to content

Commit

Permalink
Add a -Q|-ignore_quotes option to ignore quotes
Browse files Browse the repository at this point in the history
With this option " and ' will lose their grouping function and be
considered normal characters.
  • Loading branch information
p-gen committed Oct 3, 2020
1 parent 608fe40 commit 7304e15
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 16 deletions.
9 changes: 9 additions & 0 deletions smenu.1
Expand Up @@ -57,6 +57,7 @@ and outputs the selection to stdout.
\fIdelay\fP]
[\fB-r\fP|\fB-auto_validate\fP]
[\fB-v\fP|\fB-vb\fP|\fB-visual_bell\fP]
[\fB-Q\fP|\fB-ignore_quotes\fP]


selectors ::= \fIcol1\fP[-\fIcol2\fP],...|\fIrow1\fP[-\fIrow2\fP],...|\
Expand Down Expand Up @@ -1487,6 +1488,14 @@ By default, when searching, an alarm is produced by the terminal when
the user enters a character or makes a move which lead to no result or
to an error condition.
This argument make this beep visual by briefly showing the cursor.
.IP "\fB-Q\fP|\fB-ignore_quotes\fP"
(Allowed in all contexts.)

Using this option will remove the word grouping feature from single and
double quotes which will be considered normal characters.
For example: \f(CB"a b"\fP will be considered by smenu as two words
\fB"a\fP and \fBb"\fP and no more as a single word: \fBa b\fP.

.SH NOTES
If tabulators (\fI\\t\fP) are embedded in the input, there is no way
to replace them with the original number of spaces.
Expand Down
53 changes: 37 additions & 16 deletions smenu.c
Expand Up @@ -2616,15 +2616,18 @@ get_word(FILE * input, ll_t * word_delims_list, ll_t * record_delims_list,
}
else
{
/* Manage double quotes */
/* """""""""""""""""""" */
if (byte == '"' && !is_squote)
is_dquote = !is_dquote;

/* Manage single quotes */
/* """""""""""""""""""" */
if (byte == '\'' && !is_dquote)
is_squote = !is_squote;
if (!misc->ignore_quotes)
{
/* Manage double quotes */
/* """""""""""""""""""" */
if (byte == '"' && !is_squote)
is_dquote = !is_dquote;

/* Manage single quotes */
/* """""""""""""""""""" */
if (byte == '\'' && !is_dquote)
is_squote = !is_squote;
}
}

/* Only consider delimiters when outside quotations */
Expand All @@ -2633,13 +2636,16 @@ get_word(FILE * input, ll_t * word_delims_list, ll_t * record_delims_list,
&& ll_find(word_delims_list, utf8_buffer, buffer_cmp) != NULL)
break;

/* We no dot count the significant quotes */
/* """""""""""""""""""""""""""""""""""""" */
if (!is_special
&& ((byte == '"' && !is_squote) || (byte == '\'' && !is_dquote)))
if (!misc->ignore_quotes)
{
is_special = 0;
goto next;
/* We no dot count the significant quotes */
/* """""""""""""""""""""""""""""""""""""" */
if (!is_special
&& ((byte == '"' && !is_squote) || (byte == '\'' && !is_dquote)))
{
is_special = 0;
goto next;
}
}

/* Feed temp with the content of utf8_buffer */
Expand Down Expand Up @@ -5745,6 +5751,16 @@ da_options_action(char * ctx_name, char * opt_name, char * param, int nb_values,
}
}

void
ignore_quotes_action(char * ctx_name, char * opt_name, char * param,
int nb_values, char ** values, int nb_opt_data,
void ** opt_data, int nb_ctx_data, void ** ctx_data)
{
misc_t * misc = opt_data[0];

misc->ignore_quotes = 1;
}

/* ================ */
/* Main entry point */
/* ================ */
Expand Down Expand Up @@ -6151,6 +6167,7 @@ main(int argc, char * argv[])
/* misc default values */
/* """"""""""""""""""" */
misc.default_search_method = NONE;
misc.ignore_quotes = 0;

/* direct access variable initialization */
/* """"""""""""""""""""""""""""""""""""" */
Expand Down Expand Up @@ -6326,7 +6343,8 @@ main(int argc, char * argv[])
"[timeout #...] "
"[hidden_timeout #...] "
"[validate_in_search_mode] "
"[visual_bell] "; /* Do not remove the last space. */
"[visual_bell] "
"[ignore_quotes] "; /* Do not remove the last space. */

main_spec_options = "[*version] "
"[*long_help] "
Expand Down Expand Up @@ -6470,6 +6488,7 @@ main(int argc, char * argv[])
ctxopt_add_opt_settings(parameters, "validate_in_search_mode",
"-r -auto_validate");
ctxopt_add_opt_settings(parameters, "visual_bell", "-v -vb -visual_bell");
ctxopt_add_opt_settings(parameters, "ignore_quotes", "-Q -ignore_quotes");

/* ctxopt options incompatibilities */
/* """"""""""""""""""""""""""""""""" */
Expand Down Expand Up @@ -6596,6 +6615,8 @@ main(int argc, char * argv[])
(char *)0);
ctxopt_add_opt_settings(actions, "da_options", da_options_action, &langinfo,
&daccess_index, &misc, (char *)0);
ctxopt_add_opt_settings(actions, "ignore_quotes", ignore_quotes_action, &misc,
(char *)0);

/* ctxopt constraints */
/* """""""""""""""""" */
Expand Down
1 change: 1 addition & 0 deletions smenu.h
Expand Up @@ -188,6 +188,7 @@ struct misc_s
{
search_mode_t default_search_method;
char invalid_char_substitute;
int ignore_quotes;
};

/* Terminal setting variables */
Expand Down
2 changes: 2 additions & 0 deletions usage.c
Expand Up @@ -74,6 +74,8 @@ common_help(void)
printf(" enables ENTER to validate the selection even in search mode.\n");
printf("-v|-vb|-visual_bell\n");
printf(" makes the bell visual (fuzzy search with error).\n");
printf("-Q|-ignore_quotes\n");
printf(" treats single and double quotes as normal characters.\n");
}

void
Expand Down

0 comments on commit 7304e15

Please sign in to comment.