From 49ee322d152bfd02d21f6f88cd2cf696ff5e140c Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 18 Dec 2023 13:15:49 +0000 Subject: [PATCH] refactor: Use `enum-from-int` rule from tokstyle. These functions are a bit clearer and don't need to change if enum values change. See https://github.com/TokTok/hs-tokstyle/pull/212 for the relevant linter implementation. --- .../docker/tox-bootstrapd.sha256 | 2 +- toxcore/Messenger.c | 8 +++--- toxcore/group_pack.c | 10 +++---- toxcore/tox_unpack.c | 26 +++++++++---------- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index efc3f0a052c..5d349ae8b93 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -849ec5686eeaea448f4ef99650b016c883e6ea13d5fa2e7b2a344c9275a10431 /usr/local/bin/tox-bootstrapd +603c0892e737eb7b2bb6e6a7ba6407a847c90dad34ab1e3919f5259069c35540 /usr/local/bin/tox-bootstrapd diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index cd1e53d9bee..05bebebde41 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -760,12 +760,14 @@ int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length) static Userstatus userstatus_from_int(uint8_t status) { switch (status) { - case 0: + case USERSTATUS_NONE: return USERSTATUS_NONE; - case 1: + case USERSTATUS_AWAY: return USERSTATUS_AWAY; - case 2: + case USERSTATUS_BUSY: return USERSTATUS_BUSY; + case USERSTATUS_INVALID: + return USERSTATUS_INVALID; default: return USERSTATUS_INVALID; } diff --git a/toxcore/group_pack.c b/toxcore/group_pack.c index c63a46afa90..9743813e9ce 100644 --- a/toxcore/group_pack.c +++ b/toxcore/group_pack.c @@ -21,9 +21,9 @@ Group_Privacy_State group_privacy_state_from_int(uint8_t value) { switch (value) { - case 0: + case GI_PUBLIC: return GI_PUBLIC; - case 1: + case GI_PRIVATE: return GI_PRIVATE; default: return GI_PUBLIC; @@ -33,11 +33,11 @@ Group_Privacy_State group_privacy_state_from_int(uint8_t value) Group_Voice_State group_voice_state_from_int(uint8_t value) { switch (value) { - case 0: + case GV_ALL: return GV_ALL; - case 1: + case GV_MODS: return GV_MODS; - case 2: + case GV_FOUNDER: return GV_FOUNDER; default: return GV_ALL; diff --git a/toxcore/tox_unpack.c b/toxcore/tox_unpack.c index e3a461d6e16..004aba3be01 100644 --- a/toxcore/tox_unpack.c +++ b/toxcore/tox_unpack.c @@ -12,9 +12,9 @@ static Tox_Conference_Type tox_conference_type_from_int(uint32_t value) { switch (value) { - case 0: + case TOX_CONFERENCE_TYPE_TEXT: return TOX_CONFERENCE_TYPE_TEXT; - case 1: + case TOX_CONFERENCE_TYPE_AV: return TOX_CONFERENCE_TYPE_AV; default: return TOX_CONFERENCE_TYPE_TEXT; @@ -35,11 +35,11 @@ bool tox_unpack_conference_type(Bin_Unpack *bu, Tox_Conference_Type *val) static Tox_Connection tox_connection_from_int(uint32_t value) { switch (value) { - case 0: + case TOX_CONNECTION_NONE: return TOX_CONNECTION_NONE; - case 1: + case TOX_CONNECTION_TCP: return TOX_CONNECTION_TCP; - case 2: + case TOX_CONNECTION_UDP: return TOX_CONNECTION_UDP; default: return TOX_CONNECTION_NONE; @@ -60,11 +60,11 @@ bool tox_unpack_connection(Bin_Unpack *bu, Tox_Connection *val) static Tox_File_Control tox_file_control_from_int(uint32_t value) { switch (value) { - case 0: + case TOX_FILE_CONTROL_RESUME: return TOX_FILE_CONTROL_RESUME; - case 1: + case TOX_FILE_CONTROL_PAUSE: return TOX_FILE_CONTROL_PAUSE; - case 2: + case TOX_FILE_CONTROL_CANCEL: return TOX_FILE_CONTROL_CANCEL; default: return TOX_FILE_CONTROL_RESUME; @@ -85,9 +85,9 @@ bool tox_unpack_file_control(Bin_Unpack *bu, Tox_File_Control *val) static Tox_Message_Type tox_message_type_from_int(uint32_t value) { switch (value) { - case 0: + case TOX_MESSAGE_TYPE_NORMAL: return TOX_MESSAGE_TYPE_NORMAL; - case 1: + case TOX_MESSAGE_TYPE_ACTION: return TOX_MESSAGE_TYPE_ACTION; default: return TOX_MESSAGE_TYPE_NORMAL; @@ -108,11 +108,11 @@ bool tox_unpack_message_type(Bin_Unpack *bu, Tox_Message_Type *val) static Tox_User_Status tox_user_status_from_int(uint32_t value) { switch (value) { - case 0: + case TOX_USER_STATUS_NONE: return TOX_USER_STATUS_NONE; - case 1: + case TOX_USER_STATUS_AWAY: return TOX_USER_STATUS_AWAY; - case 2: + case TOX_USER_STATUS_BUSY: return TOX_USER_STATUS_BUSY; default: return TOX_USER_STATUS_NONE;