[PATCH v2] coding-style: Use the same style in the 'struct option'

Jiang Jiacheng posted 1 patch 1 week, 5 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20221122015001.2303883-1-jiangjiacheng@huawei.com
examples/c/domain/domtop.c      | 10 +++++-----
examples/c/domain/suspend.c     | 10 +++++-----
src/locking/lock_daemon.c       | 12 ++++++------
src/logging/log_daemon.c        | 12 ++++++------
src/remote/remote_daemon.c      | 14 +++++++-------
src/security/virt-aa-helper.c   | 22 +++++++++++-----------
tools/virsh.c                   | 24 ++++++++++++------------
tools/virt-admin.c              | 14 +++++++-------
tools/virt-host-validate.c      |  8 ++++----
tools/virt-login-shell-helper.c |  6 +++---
tools/virt-pki-query-dn.c       |  6 +++---
11 files changed, 69 insertions(+), 69 deletions(-)
[PATCH v2] coding-style: Use the same style in the 'struct option'
Posted by Jiang Jiacheng 1 week, 5 days ago
Use same style in the 'struct option' as:
    struct option opt[] = {
        { a, b },
        { a, b },
        ...
        { a, b },
    };

diff to v1:
* use the same style in all the 'struct option'

Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
---
 examples/c/domain/domtop.c      | 10 +++++-----
 examples/c/domain/suspend.c     | 10 +++++-----
 src/locking/lock_daemon.c       | 12 ++++++------
 src/logging/log_daemon.c        | 12 ++++++------
 src/remote/remote_daemon.c      | 14 +++++++-------
 src/security/virt-aa-helper.c   | 22 +++++++++++-----------
 tools/virsh.c                   | 24 ++++++++++++------------
 tools/virt-admin.c              | 14 +++++++-------
 tools/virt-host-validate.c      |  8 ++++----
 tools/virt-login-shell-helper.c |  6 +++---
 tools/virt-pki-query-dn.c       |  6 +++---
 11 files changed, 69 insertions(+), 69 deletions(-)

diff --git a/examples/c/domain/domtop.c b/examples/c/domain/domtop.c
index 5228445b7c..dd35ec8661 100644
--- a/examples/c/domain/domtop.c
+++ b/examples/c/domain/domtop.c
@@ -86,11 +86,11 @@ parse_argv(int argc, char *argv[],
     unsigned long val;
     char *p;
     struct option opt[] = {
-        {"debug", no_argument, NULL, 'd'},
-        {"help", no_argument, NULL, 'h'},
-        {"connect", required_argument, NULL, 'c'},
-        {"delay", required_argument, NULL, 'D'},
-        {NULL, 0, NULL, 0}
+        { "debug", no_argument, NULL, 'd' },
+        { "help", no_argument, NULL, 'h' },
+        { "connect", required_argument, NULL, 'c' },
+        { "delay", required_argument, NULL, 'D' },
+        { NULL, 0, NULL, 0 },
     };
 
     while ((arg = getopt_long(argc, argv, "+:dhc:D:", opt, NULL)) != -1) {
diff --git a/examples/c/domain/suspend.c b/examples/c/domain/suspend.c
index 3ff24f6861..6e0bbd5597 100644
--- a/examples/c/domain/suspend.c
+++ b/examples/c/domain/suspend.c
@@ -76,11 +76,11 @@ parse_argv(int argc, char *argv[],
     unsigned long val;
     char *p;
     struct option opt[] = {
-        {"debug", no_argument, NULL, 'd'},
-        {"help", no_argument, NULL, 'h'},
-        {"connect", required_argument, NULL, 'c'},
-        {"seconds", required_argument, NULL, 's'},
-        {NULL, 0, NULL, 0}
+        { "debug", no_argument, NULL, 'd' },
+        { "help", no_argument, NULL, 'h' },
+        { "connect", required_argument, NULL, 'c' },
+        { "seconds", required_argument, NULL, 's' },
+        { NULL, 0, NULL, 0 },
     };
 
     while ((arg = getopt_long(argc, argv, "+:dhc:s:", opt, NULL)) != -1) {
diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index c997d327c4..5eed6b7c26 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -809,14 +809,14 @@ int main(int argc, char **argv) {
     int rv;
 
     struct option opts[] = {
-        { "verbose", no_argument, &verbose, 'v'},
-        { "daemon", no_argument, &godaemon, 'd'},
-        { "config", required_argument, NULL, 'f'},
-        { "timeout", required_argument, NULL, 't'},
-        { "pid-file", required_argument, NULL, 'p'},
+        { "verbose", no_argument, &verbose, 'v' },
+        { "daemon", no_argument, &godaemon, 'd' },
+        { "config", required_argument, NULL, 'f' },
+        { "timeout", required_argument, NULL, 't' },
+        { "pid-file", required_argument, NULL, 'p' },
         { "version", no_argument, NULL, 'V' },
         { "help", no_argument, NULL, 'h' },
-        {0, 0, 0, 0}
+        { 0, 0, 0, 0 },
     };
 
     privileged = geteuid() == 0;
diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c
index 00fc4148fd..9b70ffad2f 100644
--- a/src/logging/log_daemon.c
+++ b/src/logging/log_daemon.c
@@ -613,14 +613,14 @@ int main(int argc, char **argv) {
     int rv;
 
     struct option opts[] = {
-        { "verbose", no_argument, &verbose, 'v'},
-        { "daemon", no_argument, &godaemon, 'd'},
-        { "config", required_argument, NULL, 'f'},
-        { "timeout", required_argument, NULL, 't'},
-        { "pid-file", required_argument, NULL, 'p'},
+        { "verbose", no_argument, &verbose, 'v' },
+        { "daemon", no_argument, &godaemon, 'd' },
+        { "config", required_argument, NULL, 'f' },
+        { "timeout", required_argument, NULL, 't' },
+        { "pid-file", required_argument, NULL, 'p' },
         { "version", no_argument, NULL, 'V' },
         { "help", no_argument, NULL, 'h' },
-        {0, 0, 0, 0}
+        { 0, 0, 0, 0 },
     };
 
     privileged = geteuid() == 0;
diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c
index f369d09d35..dd9344168b 100644
--- a/src/remote/remote_daemon.c
+++ b/src/remote/remote_daemon.c
@@ -807,17 +807,17 @@ int main(int argc, char **argv) {
     mode_t old_umask;
 
     struct option opts[] = {
-        { "verbose", no_argument, &verbose, 'v'},
-        { "daemon", no_argument, &godaemon, 'd'},
+        { "verbose", no_argument, &verbose, 'v' },
+        { "daemon", no_argument, &godaemon, 'd' },
 #if defined(WITH_IP) && defined(LIBVIRTD)
-        { "listen", no_argument, &ipsock, 'l'},
+        { "listen", no_argument, &ipsock, 'l' },
 #endif /* !(WITH_IP && LIBVIRTD) */
-        { "config", required_argument, NULL, 'f'},
-        { "timeout", required_argument, NULL, 't'},
-        { "pid-file", required_argument, NULL, 'p'},
+        { "config", required_argument, NULL, 'f' },
+        { "timeout", required_argument, NULL, 't' },
+        { "pid-file", required_argument, NULL, 'p' },
         { "version", no_argument, NULL, 'V' },
         { "help", no_argument, NULL, 'h' },
-        {0, 0, 0, 0}
+        { 0, 0, 0, 0 },
     };
 
     if (virGettextInitialize() < 0 ||
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index a15971b9bb..53a1cd1048 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -1337,17 +1337,17 @@ vahParseArgv(vahControl * ctl, int argc, char **argv)
 {
     int arg, idx = 0;
     struct option opt[] = {
-        {"add", 0, 0, 'a'},
-        {"create", 0, 0, 'c'},
-        {"dryrun", 0, 0, 'd'},
-        {"delete", 0, 0, 'D'},
-        {"add-file", 0, 0, 'f'},
-        {"append-file", 0, 0, 'F'},
-        {"help", 0, 0, 'h'},
-        {"replace", 0, 0, 'r'},
-        {"remove", 0, 0, 'R'},
-        {"uuid", 1, 0, 'u'},
-        {0, 0, 0, 0}
+        { "add", 0, 0, 'a' },
+        { "create", 0, 0, 'c' },
+        { "dryrun", 0, 0, 'd' },
+        { "delete", 0, 0, 'D' },
+        { "add-file", 0, 0, 'f' },
+        { "append-file", 0, 0, 'F' },
+        { "help", 0, 0, 'h' },
+        { "replace", 0, 0, 'r' },
+        { "remove", 0, 0, 'R' },
+        { "uuid", 1, 0, 'u' },
+        { 0, 0, 0, 0 },
     };
 
     while ((arg = getopt_long(argc, argv, "acdDhrRH:b:u:p:f:F:", opt,
diff --git a/tools/virsh.c b/tools/virsh.c
index b37d2ce12f..5696941550 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -638,18 +638,18 @@ virshParseArgv(vshControl *ctl, int argc, char **argv)
     int longindex = -1;
     virshControl *priv = ctl->privData;
     struct option opt[] = {
-        {"connect", required_argument, NULL, 'c'},
-        {"debug", required_argument, NULL, 'd'},
-        {"escape", required_argument, NULL, 'e'},
-        {"help", no_argument, NULL, 'h'},
-        {"keepalive-interval", required_argument, NULL, 'k'},
-        {"keepalive-count", required_argument, NULL, 'K'},
-        {"log", required_argument, NULL, 'l'},
-        {"quiet", no_argument, NULL, 'q'},
-        {"readonly", no_argument, NULL, 'r'},
-        {"timing", no_argument, NULL, 't'},
-        {"version", optional_argument, NULL, 'v'},
-        {NULL, 0, NULL, 0}
+        { "connect", required_argument, NULL, 'c' },
+        { "debug", required_argument, NULL, 'd' },
+        { "escape", required_argument, NULL, 'e' },
+        { "help", no_argument, NULL, 'h' },
+        { "keepalive-interval", required_argument, NULL, 'k' },
+        { "keepalive-count", required_argument, NULL, 'K' },
+        { "log", required_argument, NULL, 'l' },
+        { "quiet", no_argument, NULL, 'q' },
+        { "readonly", no_argument, NULL, 'r' },
+        { "timing", no_argument, NULL, 't' },
+        { "version", optional_argument, NULL, 'v' },
+        { NULL, 0, NULL, 0 },
     };
 
     /* Standard (non-command) options. The leading + ensures that no
diff --git a/tools/virt-admin.c b/tools/virt-admin.c
index 11ba242742..85b010b95f 100644
--- a/tools/virt-admin.c
+++ b/tools/virt-admin.c
@@ -1318,13 +1318,13 @@ vshAdmParseArgv(vshControl *ctl, int argc, char **argv)
     size_t i;
     int longindex = -1;
     struct option opt[] = {
-        {"connect", required_argument, NULL, 'c'},
-        {"debug", required_argument, NULL, 'd'},
-        {"help", no_argument, NULL, 'h'},
-        {"log", required_argument, NULL, 'l'},
-        {"quiet", no_argument, NULL, 'q'},
-        {"version", optional_argument, NULL, 'v'},
-        {NULL, 0, NULL, 0}
+        { "connect", required_argument, NULL, 'c' },
+        { "debug", required_argument, NULL, 'd' },
+        { "help", no_argument, NULL, 'h' },
+        { "log", required_argument, NULL, 'l' },
+        { "quiet", no_argument, NULL, 'q' },
+        { "version", optional_argument, NULL, 'v' },
+        { NULL, 0, NULL, 0 },
     };
 
     /* Standard (non-command) options. The leading + ensures that no
diff --git a/tools/virt-host-validate.c b/tools/virt-host-validate.c
index 4dae97910a..52ca729f85 100644
--- a/tools/virt-host-validate.c
+++ b/tools/virt-host-validate.c
@@ -73,10 +73,10 @@ show_version(FILE *out, const char *argv0)
 }
 
 static const struct option argOptions[] = {
-    { "help", 0, NULL, 'h', },
-    { "version", 0, NULL, 'v', },
-    { "quiet", 0, NULL, 'q', },
-    { NULL, 0, NULL, '\0', }
+    { "help", 0, NULL, 'h' },
+    { "version", 0, NULL, 'v' },
+    { "quiet", 0, NULL, 'q' },
+    { NULL, 0, NULL, '\0' },
 };
 
 int
diff --git a/tools/virt-login-shell-helper.c b/tools/virt-login-shell-helper.c
index 3f8757e496..8feeb8f0fe 100644
--- a/tools/virt-login-shell-helper.c
+++ b/tools/virt-login-shell-helper.c
@@ -179,9 +179,9 @@ main(int argc, char **argv)
     bool autoshell = false;
 
     struct option opt[] = {
-        {"help", no_argument, NULL, 'h'},
-        {"version", optional_argument, NULL, 'V'},
-        {NULL, 0, NULL, 0}
+        { "help", no_argument, NULL, 'h' },
+        { "version", optional_argument, NULL, 'V' },
+        { NULL, 0, NULL, 0 },
     };
     if (virInitialize() < 0) {
         fprintf(stderr, _("Failed to initialize libvirt error handling"));
diff --git a/tools/virt-pki-query-dn.c b/tools/virt-pki-query-dn.c
index ee3783c1b2..2d7849feb7 100644
--- a/tools/virt-pki-query-dn.c
+++ b/tools/virt-pki-query-dn.c
@@ -61,9 +61,9 @@ main(int argc,
     int rv = 0;
 
     struct option opt[] = {
-        {"help", no_argument, NULL, 'h'},
-        {"version", optional_argument, NULL, 'v'},
-        {NULL, 0, NULL, 0}
+        { "help", no_argument, NULL, 'h' },
+        { "version", optional_argument, NULL, 'v' },
+        { NULL, 0, NULL, 0 },
     };
 
     if (virGettextInitialize() < 0)
-- 
2.33.0
Re: [PATCH v2] coding-style: Use the same style in the 'struct option'
Posted by Michal Prívozník 1 week, 5 days ago
On 11/22/22 02:50, Jiang Jiacheng wrote:
> Use same style in the 'struct option' as:
>     struct option opt[] = {
>         { a, b },
>         { a, b },
>         ...
>         { a, b },
>     };
> 
> diff to v1:
> * use the same style in all the 'struct option'

We usually put this ...

> 
> Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
> ---

... here. We don't really need it to be part of the commit message.

>  examples/c/domain/domtop.c      | 10 +++++-----
>  examples/c/domain/suspend.c     | 10 +++++-----
>  src/locking/lock_daemon.c       | 12 ++++++------
>  src/logging/log_daemon.c        | 12 ++++++------
>  src/remote/remote_daemon.c      | 14 +++++++-------
>  src/security/virt-aa-helper.c   | 22 +++++++++++-----------
>  tools/virsh.c                   | 24 ++++++++++++------------
>  tools/virt-admin.c              | 14 +++++++-------
>  tools/virt-host-validate.c      |  8 ++++----
>  tools/virt-login-shell-helper.c |  6 +++---
>  tools/virt-pki-query-dn.c       |  6 +++---
>  11 files changed, 69 insertions(+), 69 deletions(-)

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

and pushed.

Michal