All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>, Wei Liu <wl@xen.org>,
	Konrad Wilk <konrad.wilk@oracle.com>,
	George Dunlap <George.Dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Ian Jackson <ian.jackson@citrix.com>
Subject: [Xen-devel] [PATCH] cmdline: treat hyphens and underscores the same
Date: Thu, 5 Dec 2019 16:33:29 +0100	[thread overview]
Message-ID: <aa92bd0c-f35c-2bf3-d665-4977f83bb0d5@suse.com> (raw)

In order to avoid permanently having to ask that no new command line
options using underscores be introduced (albeit I'm likely to still make
remarks), and in order to also allow extending the use of hyphens to
pre-existing ones, introduce custom comparison functions treating both
characters as matching.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/docs/misc/xen-command-line.pandoc
+++ b/docs/misc/xen-command-line.pandoc
@@ -72,6 +72,11 @@ Some options take a comma separated list
 Some parameters act as combinations of the above, most commonly a mix
 of Boolean and String.  These are noted in the relevant sections.
 
+### Spelling
+
+Parameter names may include hyphens or underscores.  These are
+generally being treated as matching one another by the parsing logic.
+
 ## Parameter details
 
 ### acpi
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -23,6 +23,49 @@ enum system_state system_state = SYS_STA
 xen_commandline_t saved_cmdline;
 static const char __initconst opt_builtin_cmdline[] = CONFIG_CMDLINE;
 
+static int cdiff(unsigned char c1, unsigned char c2)
+{
+    int res = c1 - c2;
+
+    if ( res && (c1 ^ c2) == ('-' ^ '_') &&
+         (c1 == '-' || c1 == '_') )
+        res = 0;
+
+    return res;
+}
+
+/*
+ * String comparison functions mostly matching strcmp() / strncmp(),
+ * except that they treat '-' and '_' as matching one another.
+ */
+static int _strcmp(const char *s1, const char *s2)
+{
+    int res;
+
+    for ( ; ; ++s1, ++s2 )
+    {
+        res = cdiff(*s1, *s2);
+        if ( res || !*s1 )
+            break;
+    }
+
+    return res;
+}
+
+static int _strncmp(const char *s1, const char *s2, size_t n)
+{
+    int res = 0;
+
+    for ( ; n--; ++s1, ++s2 )
+    {
+        res = cdiff(*s1, *s2);
+        if ( res || !*s1 )
+            break;
+    }
+
+    return res;
+}
+
 static int assign_integer_param(const struct kernel_param *param, uint64_t val)
 {
     switch ( param->len )
@@ -94,7 +137,7 @@ static int parse_params(const char *cmdl
 
         /* Boolean parameters can be inverted with 'no-' prefix. */
         key = optkey;
-        bool_assert = !!strncmp("no-", optkey, 3);
+        bool_assert = !!_strncmp("no-", optkey, 3);
         if ( !bool_assert )
             optkey += 3;
 
@@ -105,11 +148,11 @@ static int parse_params(const char *cmdl
             int rctmp;
             const char *s;
 
-            if ( strcmp(param->name, optkey) )
+            if ( _strcmp(param->name, optkey) )
             {
                 if ( param->type == OPT_CUSTOM && q &&
                      strlen(param->name) == q + 1 - opt &&
-                     !strncmp(param->name, opt, q + 1 - opt) )
+                     !_strncmp(param->name, opt, q + 1 - opt) )
                 {
                     found = true;
                     optval[-1] = '=';
@@ -275,7 +318,7 @@ int parse_bool(const char *s, const char
 int parse_boolean(const char *name, const char *s, const char *e)
 {
     size_t slen, nlen;
-    int val = !!strncmp(s, "no-", 3);
+    int val = !!_strncmp(s, "no-", 3);
 
     if ( !val )
         s += 3;
@@ -284,7 +327,7 @@ int parse_boolean(const char *name, cons
     nlen = strlen(name);
 
     /* Does s now start with name? */
-    if ( slen < nlen || strncmp(s, name, nlen) )
+    if ( slen < nlen || _strncmp(s, name, nlen) )
         return -1;
 
     /* Exact, unadorned name?  Result depends on the 'no-' prefix. */
@@ -304,7 +347,7 @@ int cmdline_strcmp(const char *frag, con
     for ( ; ; frag++, name++ )
     {
         unsigned char f = *frag, n = *name;
-        int res = f - n;
+        int res = cdiff(f, n);
 
         if ( res || n == '\0' )
         {

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

             reply	other threads:[~2019-12-05 15:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-05 15:33 Jan Beulich [this message]
2019-12-05 16:27 ` [Xen-devel] [PATCH] cmdline: treat hyphens and underscores the same Julien Grall
2019-12-05 16:50   ` Jan Beulich
2019-12-06 14:46     ` Julien Grall
2019-12-06 15:18       ` George Dunlap
2019-12-06 16:06       ` Jan Beulich
2019-12-06 16:20         ` Julien Grall
2019-12-06 16:42           ` Jan Beulich
2019-12-06 16:45             ` Julien Grall
2019-12-09 14:06             ` George Dunlap
2019-12-09 14:11               ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aa92bd0c-f35c-2bf3-d665-4977f83bb0d5@suse.com \
    --to=jbeulich@suse.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.jackson@citrix.com \
    --cc=julien@xen.org \
    --cc=konrad.wilk@oracle.com \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.