aboutsummaryrefslogtreecommitdiffstats
path: root/src/mds-kkbd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mds-kkbd.c')
-rw-r--r--src/mds-kkbd.c74
1 files changed, 37 insertions, 37 deletions
diff --git a/src/mds-kkbd.c b/src/mds-kkbd.c
index 31915bd..24fee29 100644
--- a/src/mds-kkbd.c
+++ b/src/mds-kkbd.c
@@ -1,6 +1,6 @@
/**
* mds — A micro-display server
- * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (maandree@kth.se)
+ * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (m@maandree.se)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -240,23 +240,23 @@ parse_cmdline(void)
/* Parse command line arguments. */
for (i = 1; i < argc; i++) {
arg = argv[i];
- if ((v = strequals(arg, "--initial-spawn")) || /* Initial spawn? */
- strequals(arg, "--respawn")) { /* Respawning after crash? */
+ if ((v = streq(arg, "--initial-spawn")) || /* Initial spawn? */
+ streq(arg, "--respawn")) { /* Respawning after crash? */
exit_if (is_respawn == v,
eprintf("conflicting arguments %s and %s cannot be combined.",
"--initial-spawn", "--respawn"););
is_respawn = !v;
- } else if (strequals(arg, "--re-exec")) { /* Re-exec state-marshal. */
+ } else if (streq(arg, "--re-exec")) { /* Re-exec state-marshal. */
is_reexec = 1;
- } else if (startswith(arg, "--alarm=")) { /* Schedule an alarm signal for forced abort. */
- alarm(min(atou(arg + strlen("--alarm=")), 60)); /* At most 1 minute. */
- } else if (strequals(arg, "--on-init-fork")) { /* Fork process when initialised. */
+ } else if (strstarts(arg, "--alarm=")) { /* Schedule an alarm signal for forced abort. */
+ alarm(MIN(atou(arg + strlen("--alarm=")), 60)); /* At most 1 minute. */
+ } else if (streq(arg, "--on-init-fork")) { /* Fork process when initialised. */
on_init_fork = 1;
- } else if (startswith(arg, "--on-init-sh=")) { /* Run a command when initialised. */
+ } else if (strstarts(arg, "--on-init-sh=")) { /* Run a command when initialised. */
on_init_sh = arg + strlen("--on-init-sh=");
- } else if (strequals(arg, "--immortal")) { /* I return to serve. */
+ } else if (streq(arg, "--immortal")) { /* I return to serve. */
is_immortal = 1;
- } else if (startswith(arg, "--led=")) { /* Remap LED:s. */
+ } else if (strstarts(arg, "--led=")) { /* Remap LED:s. */
if (remap_led_cmdline(arg + strlen("--led=")) < 0)
return -1;
}
@@ -598,7 +598,7 @@ handle_message(void)
size_t i;
#define __get_header(storage, header)\
- (startswith(received.headers[i], header))\
+ (strstarts(received.headers[i], header))\
storage = received.headers[i] + strlen(header)
for (i = 0; i < received.header_count; i++) {
@@ -621,20 +621,20 @@ handle_message(void)
return 0; /* How did that get here, no matter, just ignore it? */
#define t(expr) do { fail_if (expr); return 0; } while (0)
- if (strequals(recv_command, "enumerate-keyboards"))
+ if (streq(recv_command, "enumerate-keyboards"))
t (handle_enumerate_keyboards(recv_client_id, recv_message_id, recv_modify_id));
- if (strequals(recv_command, "keyboard-enumeration"))
+ if (streq(recv_command, "keyboard-enumeration"))
t (handle_keyboard_enumeration(recv_modify_id));
- if (strequals(recv_command, "keycode-map"))
+ if (streq(recv_command, "keycode-map"))
t (handle_keycode_map(recv_client_id, recv_message_id, recv_action, recv_keyboard));
/* The following do not need to be inside a mutex, because this server
only interprets on message at the time, thus there can not be any
conflicts and access to LED:s are automatically atomic. */
- if (strequals(recv_command, "set-keyboard-leds"))
+ if (streq(recv_command, "set-keyboard-leds"))
t (handle_set_keyboard_leds(recv_active, recv_mask, recv_keyboard));
- if (strequals(recv_command, "get-keyboard-leds"))
+ if (streq(recv_command, "get-keyboard-leds"))
t (handle_get_keyboard_leds(recv_client_id, recv_message_id, recv_keyboard));
- if (strequals(recv_command, "map-keyboard-leds"))
+ if (streq(recv_command, "map-keyboard-leds"))
t (handle_map_keyboard_leds(recv_keyboard));
#undef t
@@ -688,7 +688,7 @@ handle_enumerate_keyboards(const char *recv_client_id, const char *recv_message_
return eprint("did not get a modify ID, ignoring."), 0;
- if (strequals(recv_client_id, "0:0")) {
+ if (streq(recv_client_id, "0:0")) {
eprint("received information request from an anonymous client, sending non-modifying response.");
with_mutex (send_mutex,
@@ -813,7 +813,7 @@ handle_keyboard_enumeration(const char *recv_modify_id)
n = off;
for (i = 0; i < received.header_count; i++) {
header = received.headers[i];
- if (!have_len && startswith(header, "Length: ")) {
+ if (!have_len && strstarts(header, "Length: ")) {
have_len = 1;
sprintf(send_buffer + n,
"Length: %zu\n",
@@ -896,7 +896,7 @@ handle_set_keyboard_leds(const char *recv_active, const char *recv_mask, const c
const char *begin;
const char *end;
- if ((recv_keyboard) && !strequals(recv_keyboard, KEYBOARD_ID))
+ if ((recv_keyboard) && !streq(recv_keyboard, KEYBOARD_ID))
return 0;
if (!recv_active)
@@ -911,7 +911,7 @@ handle_set_keyboard_leds(const char *recv_active, const char *recv_mask, const c
return 0; /* Not fatal */
}
-#define __test(have, want) (startswith(have, want " ") || strequals(have, want))
+#define __test(have, want) (strstarts(have, want " ") || streq(have, want))
for (begin = end = recv_active; end;) {
end = strchr(begin, ' ');
@@ -963,13 +963,13 @@ handle_get_keyboard_leds(const char *recv_client_id, const char *recv_message_id
size_t n;
int r, leds, error;
- if (recv_keyboard && !strequals(recv_keyboard, KEYBOARD_ID))
+ if (recv_keyboard && !streq(recv_keyboard, KEYBOARD_ID))
return 0;
if (!recv_keyboard)
return eprint("received LED reading request but no specified keyboard, ignoring."), 0;
- if (strequals(recv_client_id, "0:0"))
+ if (streq(recv_client_id, "0:0"))
return eprint("received information request from an anonymous client, ignoring."), 0;
leds = get_leds();
@@ -1027,11 +1027,11 @@ fail:
__attribute__((nonnull))
static int parse_led(const char* name)
{
- if (strequals(name, "num")) return LED_NUM_LOCK;
- if (strequals(name, "caps")) return LED_CAPS_LOCK;
- if (strequals(name, "scrl")) return LED_SCRL_LOCK;
+ if (streq(name, "num")) return LED_NUM_LOCK;
+ if (streq(name, "caps")) return LED_CAPS_LOCK;
+ if (streq(name, "scrl")) return LED_SCRL_LOCK;
#ifdef LED_COMPOSE
- if (strequals(name, "compose")) return LED_COMPOSE;
+ if (streq(name, "compose")) return LED_COMPOSE;
#endif
return -1;
}
@@ -1127,7 +1127,7 @@ handle_map_keyboard_leds(const char *recv_keyboard)
size_t i, len;
char *pos_;
- if (recv_keyboard && !strequals(recv_keyboard, KEYBOARD_ID))
+ if (recv_keyboard && !streq(recv_keyboard, KEYBOARD_ID))
return 0;
/* Parse the payload. `led` and `pos` are set just when thier first
@@ -1268,8 +1268,8 @@ remap(char *table, size_t n)
goto next;
}
- if (in != out) greatest_remap = max(greatest_remap, in);
- else greatest_reset = max(greatest_reset, in);
+ if (in != out) greatest_remap = MAX(greatest_remap, in);
+ else greatest_reset = MAX(greatest_reset, in);
fail_if (add_mapping(in, out) < 0);
@@ -1310,7 +1310,7 @@ mapping_query(const char *recv_client_id, const char *recv_message_id)
with the highest value. */
for (i = 0; i < mapping_size; i++) {
if (mapping[i] != (int)i) {
- greatest = max(greatest, mapping[i]);
+ greatest = MAX(greatest, mapping[i]);
n++;
}
}
@@ -1318,7 +1318,7 @@ mapping_query(const char *recv_client_id, const char *recv_message_id)
highest targt, that source value will
be highest integer that will be included
the mapping-table. */
- greatest = max(greatest, (int)mapping_size);
+ greatest = MAX(greatest, (int)mapping_size);
/* Calculate an upper bound for the payload. */
n *= 2 + 2 * (size_t)(greatest > 0x00FF ? 5 : 3);
@@ -1388,12 +1388,12 @@ handle_keycode_map(const char *recv_client_id, const char *recv_message_id,
const char *recv_action, const char *recv_keyboard)
{
int r;
- if (recv_keyboard && !strequals(recv_keyboard, KEYBOARD_ID))
+ if (recv_keyboard && !streq(recv_keyboard, KEYBOARD_ID))
return 0;
if (!recv_action) {
eprint("received keycode map request but without any action, ignoring.");
- } else if (strequals(recv_action, "remap")) {
+ } else if (streq(recv_action, "remap")) {
if (!received.payload_size)
return eprint("received keycode remap request without a payload, ignoring."), 0;
with_mutex (mapping_mutex,
@@ -1401,13 +1401,13 @@ handle_keycode_map(const char *recv_client_id, const char *recv_message_id,
if (r) r = errno ? errno : -1;
);
fail_if (errno = (r == -1 ? 0 : r), r);
- } else if (strequals(recv_action, "reset")) {
+ } else if (streq(recv_action, "reset")) {
with_mutex (mapping_mutex,
free(mapping);
mapping_size = 0;
);
- } else if (strequals(recv_action, "query")) {
- if (strequals(recv_client_id, "0:0"))
+ } else if (streq(recv_action, "query")) {
+ if (streq(recv_client_id, "0:0"))
return eprint("received information request from an anonymous client, ignoring."), 0;
fail_if (mapping_query(recv_client_id, recv_message_id));
} else {