From 5c036a3eac89e3dec71484fe9c22704b120254b1 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 19 Dec 2017 05:26:55 -0500 Subject: [PATCH] error on not enough input/seat args for cmd --- sway/commands/input.c | 88 +++++++++++++++++++++---------------------- sway/commands/seat.c | 32 ++++++++-------- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/sway/commands/input.c b/sway/commands/input.c index dac028a7..ccb1d276 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c @@ -16,50 +16,50 @@ struct cmd_results *cmd_input(int argc, char **argv) { return cmd_results_new(CMD_BLOCK_INPUT, NULL, NULL); } - if (argc > 2) { - int argc_new = argc-2; - char **argv_new = argv+2; - - struct cmd_results *res; - current_input_config = new_input_config(argv[0]); - if (strcasecmp("accel_profile", argv[1]) == 0) { - res = input_cmd_accel_profile(argc_new, argv_new); - } else if (strcasecmp("click_method", argv[1]) == 0) { - res = input_cmd_click_method(argc_new, argv_new); - } else if (strcasecmp("drag_lock", argv[1]) == 0) { - res = input_cmd_drag_lock(argc_new, argv_new); - } else if (strcasecmp("dwt", argv[1]) == 0) { - res = input_cmd_dwt(argc_new, argv_new); - } else if (strcasecmp("events", argv[1]) == 0) { - res = input_cmd_events(argc_new, argv_new); - } else if (strcasecmp("left_handed", argv[1]) == 0) { - res = input_cmd_left_handed(argc_new, argv_new); - } else if (strcasecmp("middle_emulation", argv[1]) == 0) { - res = input_cmd_middle_emulation(argc_new, argv_new); - } else if (strcasecmp("natural_scroll", argv[1]) == 0) { - res = input_cmd_natural_scroll(argc_new, argv_new); - } else if (strcasecmp("pointer_accel", argv[1]) == 0) { - res = input_cmd_pointer_accel(argc_new, argv_new); - } else if (strcasecmp("scroll_method", argv[1]) == 0) { - res = input_cmd_scroll_method(argc_new, argv_new); - } else if (strcasecmp("tap", argv[1]) == 0) { - res = input_cmd_tap(argc_new, argv_new); - } else if (strcasecmp("xkb_layout", argv[1]) == 0) { - res = input_cmd_xkb_layout(argc_new, argv_new); - } else if (strcasecmp("xkb_model", argv[1]) == 0) { - res = input_cmd_xkb_model(argc_new, argv_new); - } else if (strcasecmp("xkb_options", argv[1]) == 0) { - res = input_cmd_xkb_options(argc_new, argv_new); - } else if (strcasecmp("xkb_rules", argv[1]) == 0) { - res = input_cmd_xkb_rules(argc_new, argv_new); - } else if (strcasecmp("xkb_variant", argv[1]) == 0) { - res = input_cmd_xkb_variant(argc_new, argv_new); - } else { - res = cmd_results_new(CMD_INVALID, "input ", "Unknown command %s", argv[1]); - } - current_input_config = NULL; - return res; + if ((error = checkarg(argc, "input", EXPECTED_AT_LEAST, 3))) { + return error; } - return cmd_results_new(CMD_BLOCK_INPUT, NULL, NULL); + int argc_new = argc-2; + char **argv_new = argv+2; + + struct cmd_results *res; + current_input_config = new_input_config(argv[0]); + if (strcasecmp("accel_profile", argv[1]) == 0) { + res = input_cmd_accel_profile(argc_new, argv_new); + } else if (strcasecmp("click_method", argv[1]) == 0) { + res = input_cmd_click_method(argc_new, argv_new); + } else if (strcasecmp("drag_lock", argv[1]) == 0) { + res = input_cmd_drag_lock(argc_new, argv_new); + } else if (strcasecmp("dwt", argv[1]) == 0) { + res = input_cmd_dwt(argc_new, argv_new); + } else if (strcasecmp("events", argv[1]) == 0) { + res = input_cmd_events(argc_new, argv_new); + } else if (strcasecmp("left_handed", argv[1]) == 0) { + res = input_cmd_left_handed(argc_new, argv_new); + } else if (strcasecmp("middle_emulation", argv[1]) == 0) { + res = input_cmd_middle_emulation(argc_new, argv_new); + } else if (strcasecmp("natural_scroll", argv[1]) == 0) { + res = input_cmd_natural_scroll(argc_new, argv_new); + } else if (strcasecmp("pointer_accel", argv[1]) == 0) { + res = input_cmd_pointer_accel(argc_new, argv_new); + } else if (strcasecmp("scroll_method", argv[1]) == 0) { + res = input_cmd_scroll_method(argc_new, argv_new); + } else if (strcasecmp("tap", argv[1]) == 0) { + res = input_cmd_tap(argc_new, argv_new); + } else if (strcasecmp("xkb_layout", argv[1]) == 0) { + res = input_cmd_xkb_layout(argc_new, argv_new); + } else if (strcasecmp("xkb_model", argv[1]) == 0) { + res = input_cmd_xkb_model(argc_new, argv_new); + } else if (strcasecmp("xkb_options", argv[1]) == 0) { + res = input_cmd_xkb_options(argc_new, argv_new); + } else if (strcasecmp("xkb_rules", argv[1]) == 0) { + res = input_cmd_xkb_rules(argc_new, argv_new); + } else if (strcasecmp("xkb_variant", argv[1]) == 0) { + res = input_cmd_xkb_variant(argc_new, argv_new); + } else { + res = cmd_results_new(CMD_INVALID, "input ", "Unknown command %s", argv[1]); + } + current_input_config = NULL; + return res; } diff --git a/sway/commands/seat.c b/sway/commands/seat.c index 0149762a..155bc510 100644 --- a/sway/commands/seat.c +++ b/sway/commands/seat.c @@ -16,22 +16,22 @@ struct cmd_results *cmd_seat(int argc, char **argv) { return cmd_results_new(CMD_BLOCK_SEAT, NULL, NULL); } - if (argc > 2) { - int argc_new = argc-2; - char **argv_new = argv+2; - - struct cmd_results *res; - current_seat_config = new_seat_config(argv[0]); - if (strcasecmp("attach", argv[1]) == 0) { - res = seat_cmd_attach(argc_new, argv_new); - } else if (strcasecmp("fallback", argv[1]) == 0) { - res = seat_cmd_fallback(argc_new, argv_new); - } else { - res = cmd_results_new(CMD_INVALID, "seat ", "Unknown command %s", argv[1]); - } - current_seat_config = NULL; - return res; + if ((error = checkarg(argc, "seat", EXPECTED_AT_LEAST, 3))) { + return error; } - return cmd_results_new(CMD_BLOCK_SEAT, NULL, NULL); + int argc_new = argc-2; + char **argv_new = argv+2; + + struct cmd_results *res; + current_seat_config = new_seat_config(argv[0]); + if (strcasecmp("attach", argv[1]) == 0) { + res = seat_cmd_attach(argc_new, argv_new); + } else if (strcasecmp("fallback", argv[1]) == 0) { + res = seat_cmd_fallback(argc_new, argv_new); + } else { + res = cmd_results_new(CMD_INVALID, "seat ", "Unknown command %s", argv[1]); + } + current_seat_config = NULL; + return res; }