From: Karel Zak Date: Mon, 2 Oct 2023 17:41:26 +0000 (+0200) Subject: libsmartcols: accept apostrophe as quote for strings in filter X-Git-Tag: v2.40-rc1~151^2~44 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=01d24f7387fe01971130a075c3188ffd1c33ab88;p=thirdparty%2Futil-linux.git libsmartcols: accept apostrophe as quote for strings in filter lsfd supports "abc" as well as 'abc'. Signed-off-by: Karel Zak --- diff --git a/libsmartcols/src/filter-param.c b/libsmartcols/src/filter-param.c index b05eb808e1..659206ac6d 100644 --- a/libsmartcols/src/filter-param.c +++ b/libsmartcols/src/filter-param.c @@ -39,6 +39,16 @@ static inline const char *datatype2str(int type) }; return types[type]; } + +static char *rem_quotation(const char *p, int c) +{ + size_t len = strlen(p); + + if (*(p + (len - 1)) == c) + len -= 2; + return strndup(p + 1, len); +} + static int param_set_data(struct filter_param *n, int type, const void *data) { const char *p; @@ -48,14 +58,9 @@ static int param_set_data(struct filter_param *n, int type, const void *data) switch (type) { case SCOLS_DATA_STRING: p = data; - if (p && *p == '"') { - /* remove quotation marks */ - size_t len = strlen(p); - - if (*(p + (len - 1)) == '"') - len -= 2; - n->val.str = strndup(p + 1, len); - } else if (data) + if (p && (*p == '"' || *p == '\'')) + n->val.str = rem_quotation(p, *p); + else if (data) n->val.str = strdup((char *) data); if (data && !n->val.str) return -ENOMEM; diff --git a/libsmartcols/src/filter-scanner.h b/libsmartcols/src/filter-scanner.h index c15ba4d7bd..c80c4662a2 100644 --- a/libsmartcols/src/filter-scanner.h +++ b/libsmartcols/src/filter-scanner.h @@ -498,7 +498,7 @@ extern int yylex \ #undef yyTABLES_NAME #endif -#line 61 "libsmartcols/src/filter-scanner.l" +#line 62 "libsmartcols/src/filter-scanner.l" #line 503 "libsmartcols/src/filter-scanner.h" #undef yyIN_HEADER diff --git a/libsmartcols/src/filter-scanner.l b/libsmartcols/src/filter-scanner.l index c8b610e41c..70db492621 100644 --- a/libsmartcols/src/filter-scanner.l +++ b/libsmartcols/src/filter-scanner.l @@ -7,7 +7,8 @@ id [a-zA-Z][a-zA-Z_0-9]* int [0-9]+ blank [ \t] -string \"[^\"\n]*\" +str_qu \"[^\"\n]*\" +str_ap \'[^\'\n]*\' %% @@ -52,7 +53,7 @@ true|TRUE return T_TRUE; return T_NAME; } -{string} { +{str_ap}|{str_qu} { yylval->param_string = yytext; return T_STRING; }