]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: accept apostrophe as quote for strings in filter
authorKarel Zak <kzak@redhat.com>
Mon, 2 Oct 2023 17:41:26 +0000 (19:41 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 20 Nov 2023 21:25:46 +0000 (22:25 +0100)
lsfd supports "abc" as well as 'abc'.

Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/filter-param.c
libsmartcols/src/filter-scanner.h
libsmartcols/src/filter-scanner.l

index b05eb808e11d5fdd4b35dfc404159b50c25c5716..659206ac6df31b88962e08bc831dae3553730852 100644 (file)
@@ -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;
index c15ba4d7bd11c7335fa596636694802870e9312f..c80c4662a2b0cbe9a5f72b2b8998a11e350fd695 100644 (file)
@@ -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
index c8b610e41c15dbc760cd7ba16522aaabff3453b5..70db492621e7d19ef674646d4456b0fd9f9dc331 100644 (file)
@@ -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;
 }