mangohudctl: rework argv handling, always send valid data
Currently, if the user sets attribute we send dummy data to mangohud.
Avoid that by pulling the attrib handling into main and avoiding the
duplicate attribute name checking.
Kill off the no-longer relevant TODO while we're here.
#include "mangoapp.h"
void help_and_quit() {
- // TODO! document attributes and values
fprintf(stderr, "Usage: mangohudctl [set|toggle] attribute [value]\n");
fprintf(stderr, "Attributes:\n");
fprintf(stderr, " no_display hides or shows hud\n");
@@ -28,34 +27,6 @@ bool str_to_bool(const char *value)
exit(1);
}
-bool set_attribute(struct mangoapp_ctrl_msgid1_v1 *ctrl_msg,
- const char *attribute, const char* value)
-{
- if (strcmp(attribute, "no_display") == 0) {
- ctrl_msg->no_display = str_to_bool(value) ? 1 : 2;
- return true;
- } else if (strcmp(attribute, "log_session") == 0) {
- ctrl_msg->log_session = str_to_bool(value) ? 1 : 2;
- return true;
- }
-
- return false;
-}
-
-bool toggle_attribute(struct mangoapp_ctrl_msgid1_v1 *ctrl_msg,
- const char *attribute)
-{
- if (strcmp(attribute, "no_display") == 0) {
- ctrl_msg->no_display = 3;
- return true;
- } else if (strcmp(attribute, "log_session") == 0) {
- ctrl_msg->log_session = 3;
- return true;
- }
-
- return false;
-}
-
int main(int argc, char *argv[])
{
/* Set up message queue */
@@ -66,6 +37,7 @@ int main(int argc, char *argv[])
ctrl_msg.hdr.msg_type = 2;
ctrl_msg.hdr.ctrl_msg_type = 1;
ctrl_msg.hdr.version = 1;
+ uint8_t value;
if (argc <= 2)
help_and_quit();
@@ -74,13 +46,21 @@ int main(int argc, char *argv[])
if (argc != 4)
help_and_quit();
- set_attribute(&ctrl_msg, argv[2], argv[3]);
+ value = str_to_bool(argv[3]) ? 1 : 2;
} else if (strcmp(argv[1], "toggle") == 0) {
if (argc != 3)
help_and_quit();
- toggle_attribute(&ctrl_msg, argv[2]);
- } else
+ value = 3;
+ } else {
+ help_and_quit();
+ }
+
+ if (strcmp(argv[2], "no_display") == 0)
+ ctrl_msg.no_display = value;
+ else if (strcmp(argv[2], "log_session") == 0)
+ ctrl_msg.log_session = value;
+ else
help_and_quit();
msgsnd(msgid, &ctrl_msg, sizeof(mangoapp_ctrl_msgid1_v1), IPC_NOWAIT);
