Add streq() helper to use instead of strcmp() == 0
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 25 May 2015 22:46:05 +0000 (08:46 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Mon, 25 May 2015 22:46:05 +0000 (08:46 +1000)
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/evdev.c
src/libinput-util.h
src/path.c
src/udev-seat.c
test/litest.c
test/udev.c
tools/libinput-list-devices.c
tools/ptraccel-debug.c
tools/shared.c

index 1a71e4c0f669799eee82dd85537537e259b533f1..8e25e45d9debee13a686789fe5bcb870eb254832 100644 (file)
@@ -1970,7 +1970,7 @@ evdev_device_compare_syspath(struct udev_device *udev_device, int fd)
        if (!udev_device_new)
                goto out;
 
-       rc = strcmp(udev_device_get_syspath(udev_device_new),
+       rc = !streq(udev_device_get_syspath(udev_device_new),
                    udev_device_get_syspath(udev_device));
 out:
        if (udev_device_new)
index 74226b962cfcebfd265e78de0cff44aadaf5140c..1673551ee34e4b48334a4c98780e990d3f2518b3 100644 (file)
@@ -83,6 +83,8 @@ int list_empty(const struct list *list);
 
 #define min(a, b) (((a) < (b)) ? (a) : (b))
 #define max(a, b) (((a) > (b)) ? (a) : (b))
+#define streq(s1, s2) (strcmp((s1), (s2)) == 0)
+#define strneq(s1, s2, n) (strncmp((s1), (s2), (n)) == 0)
 
 #define LIBINPUT_EXPORT __attribute__ ((visibility("default")))
 
index f9b1a6c2333d8879a428261b0467cdaa0b1a8011..ab5587bfe96223ba649caa91af7a1c6bcc5879ec 100644 (file)
@@ -101,8 +101,8 @@ path_seat_get_named(struct path_input *input,
        struct path_seat *seat;
 
        list_for_each(seat, &input->base.seat_list, base.link) {
-               if (strcmp(seat->base.physical_name, seat_name_physical) == 0 &&
-                   strcmp(seat->base.logical_name, seat_name_logical) == 0)
+               if (streq(seat->base.physical_name, seat_name_physical) &&
+                   streq(seat->base.logical_name, seat_name_logical))
                        return seat;
        }
 
index 6615f208daddea3c4079c35efb9419ca85118bb9..8dc0c23651bdac3b9379c46fee8a67c98d2389cc 100644 (file)
@@ -57,7 +57,7 @@ device_added(struct udev_device *udev_device,
        if (!device_seat)
                device_seat = default_seat;
 
-       if (strcmp(device_seat, input->seat_id))
+       if (!streq(device_seat, input->seat_id))
                return 0;
 
        devnode = udev_device_get_devnode(udev_device);
@@ -131,8 +131,8 @@ device_removed(struct udev_device *udev_device, struct udev_input *input)
        list_for_each(seat, &input->base.seat_list, base.link) {
                list_for_each_safe(device, next,
                                   &seat->base.devices_list, base.link) {
-                       if (!strcmp(syspath,
-                                   udev_device_get_syspath(device->udev_device))) {
+                       if (streq(syspath,
+                                 udev_device_get_syspath(device->udev_device))) {
                                log_info(&input->base,
                                         "input device %s, %s removed\n",
                                         device->devname,
@@ -198,9 +198,9 @@ evdev_udev_handler(void *data)
        if (strncmp("event", udev_device_get_sysname(udev_device), 5) != 0)
                goto out;
 
-       if (!strcmp(action, "add"))
+       if (streq(action, "add"))
                device_added(udev_device, input, NULL);
-       else if (!strcmp(action, "remove"))
+       else if (streq(action, "remove"))
                device_removed(udev_device, input);
 
 out:
@@ -328,7 +328,7 @@ udev_seat_get_named(struct udev_input *input, const char *seat_name)
        struct udev_seat *seat;
 
        list_for_each(seat, &input->base.seat_list, base.link) {
-               if (strcmp(seat->base.logical_name, seat_name) == 0)
+               if (streq(seat->base.logical_name, seat_name))
                        return seat;
        }
 
index 040bfb4ae90774f38cf0d770be96d0b02fb53754..8221a7a2a34434cba8e3a6a14b405f002f5579d2 100644 (file)
@@ -432,7 +432,7 @@ litest_add_tcase_for_device(struct suite *suite,
        const char *test_name = dev->shortname;
 
        list_for_each(t, &suite->tests, node) {
-               if (strcmp(t->name, test_name) != 0)
+               if (!streq(t->name, test_name))
                        continue;
 
                if (range)
@@ -476,7 +476,7 @@ litest_add_tcase_no_device(struct suite *suite,
                return;
 
        list_for_each(t, &suite->tests, node) {
-               if (strcmp(t->name, test_name) != 0)
+               if (!streq(t->name, test_name))
                        continue;
 
                if (range)
@@ -504,7 +504,7 @@ get_suite(const char *name)
                list_init(&all_tests);
 
        list_for_each(s, &all_tests, node) {
-               if (strcmp(s->name, name) == 0)
+               if (streq(s->name, name))
                        return s;
        }
 
index 4ec956bc9696276a1032293ad3769f2d8f38a7db..f01acc7eab531c4081eed5b86ab585766a905bec 100644 (file)
@@ -26,6 +26,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <libinput.h>
+#include <libinput-util.h>
 #include <libudev.h>
 #include <unistd.h>
 
@@ -184,7 +185,7 @@ START_TEST(udev_added_seat_default)
                ck_assert(seat != NULL);
 
                seat_name = libinput_seat_get_logical_name(seat);
-               default_seat_found = !strcmp(seat_name, "default");
+               default_seat_found = streq(seat_name, "default");
                libinput_event_destroy(event);
        }
 
index 825969d50fd38782e9c6d8285b846bca7bd4d7dd..662517312bf980ff770c86f1868f8c390f521b34 100644 (file)
@@ -30,6 +30,7 @@
 #include <libudev.h>
 
 #include <libinput.h>
+#include <libinput-util.h>
 #include <libinput-version.h>
 
 #include "shared.h"
@@ -279,10 +280,10 @@ main(int argc, char **argv)
        struct libinput_event *ev;
 
        if (argc > 1) {
-               if (strcmp(argv[1], "--help") == 0) {
+               if (streq(argv[1], "--help")) {
                        usage();
                        return 0;
-               } else if (strcmp(argv[1], "--version") == 0) {
+               } else if (streq(argv[1], "--version")) {
                        printf("%s\n", LIBINPUT_VERSION);
                        return 0;
                } else {
index fdd8490e7a23a7dfa2a3208930b31fe194d0e9db..7d72225789a28cb5d13c6b6f7b737975b3156c53 100644 (file)
@@ -220,13 +220,13 @@ main(int argc, char **argv)
 
                switch (c) {
                case OPT_MODE:
-                       if (strcmp(optarg, "accel") == 0)
+                       if (streq(optarg, "accel"))
                                print_accel = true;
-                       else if (strcmp(optarg, "motion") == 0)
+                       else if (streq(optarg, "motion"))
                                print_motion = true;
-                       else if (strcmp(optarg, "delta") == 0)
+                       else if (streq(optarg, "delta"))
                                print_delta = true;
-                       else if (strcmp(optarg, "sequence") == 0)
+                       else if (streq(optarg, "sequence"))
                                print_sequence = true;
                        else {
                                usage();
index 9ccd5dda1c8821f908399322cc7d264831665369..c5f7f20e50e4e83bd6da41f0e540e4e1816aee11 100644 (file)
@@ -31,6 +31,7 @@
 #include <libudev.h>
 
 #include <libevdev/libevdev.h>
+#include <libinput-util.h>
 
 #include "shared.h"
 
@@ -189,13 +190,13 @@ tools_parse_args(int argc, char **argv, struct tools_options *options)
                                        tools_usage();
                                        return 1;
                                }
-                               if (strcmp(optarg, "none") == 0) {
+                               if (streq(optarg, "none")) {
                                        options->click_method =
                                                LIBINPUT_CONFIG_CLICK_METHOD_NONE;
-                               } else if (strcmp(optarg, "clickfinger") == 0) {
+                               } else if (streq(optarg, "clickfinger")) {
                                        options->click_method =
                                                LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
-                               } else if (strcmp(optarg, "buttonareas") == 0) {
+                               } else if (streq(optarg, "buttonareas")) {
                                        options->click_method =
                                                LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
                                } else {
@@ -208,16 +209,16 @@ tools_parse_args(int argc, char **argv, struct tools_options *options)
                                        tools_usage();
                                        return 1;
                                }
-                               if (strcmp(optarg, "none") == 0) {
+                               if (streq(optarg, "none")) {
                                        options->scroll_method =
                                                LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
-                               } else if (strcmp(optarg, "twofinger") == 0) {
+                               } else if (streq(optarg, "twofinger")) {
                                        options->scroll_method =
                                                LIBINPUT_CONFIG_SCROLL_2FG;
-                               } else if (strcmp(optarg, "edge") == 0) {
+                               } else if (streq(optarg, "edge")) {
                                        options->scroll_method =
                                                LIBINPUT_CONFIG_SCROLL_EDGE;
-                               } else if (strcmp(optarg, "button") == 0) {
+                               } else if (streq(optarg, "button")) {
                                        options->scroll_method =
                                                LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
                                } else {