From 7c810dc344c28d1876c5ee158cb0806289d0f813 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Wed, 30 May 2018 13:20:02 -0400 Subject: Make command block implementation generic --- include/sway/commands.h | 29 +++++++++++++++++------------ include/sway/config.h | 2 -- 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/sway/commands.h b/include/sway/commands.h index b2255c4b..6e2395bd 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -3,6 +3,13 @@ #include "config.h" +typedef struct cmd_results *sway_cmd(int argc, char **argv); + +struct cmd_handler { + char *command; + sway_cmd *handle; +}; + /** * Indicates the result of a command's execution. */ @@ -11,16 +18,9 @@ enum cmd_status { CMD_FAILURE, /**< The command resulted in an error */ CMD_INVALID, /**< Unknown command or parser error */ CMD_DEFER, /**< Command execution deferred */ - // Config Blocks - CMD_BLOCK_END, - CMD_BLOCK_MODE, - CMD_BLOCK_BAR, - CMD_BLOCK_BAR_COLORS, - CMD_BLOCK_INPUT, - CMD_BLOCK_SEAT, + CMD_BLOCK, CMD_BLOCK_COMMANDS, - CMD_BLOCK_IPC, - CMD_BLOCK_IPC_EVENTS, + CMD_BLOCK_END }; /** @@ -45,6 +45,8 @@ enum expected_args { struct cmd_results *checkarg(int argc, const char *name, enum expected_args type, int val); +struct cmd_handler *find_handler(char *line, struct cmd_handler *cmd_handlers, + int handlers_size); /** * Parse and executes a command. */ @@ -54,7 +56,12 @@ struct cmd_results *execute_command(char *command, struct sway_seat *seat); * * Do not use this under normal conditions. */ -struct cmd_results *config_command(char *command, enum cmd_status block); +struct cmd_results *config_command(char *command); +/** + * Parse and handle a sub command + */ +struct cmd_results *subcommand(char **argv, int argc, + struct cmd_handler *handlers, int handlers_size); /* * Parses a command policy rule. */ @@ -77,8 +84,6 @@ const char *cmd_results_to_json(struct cmd_results *results); struct cmd_results *add_color(const char *name, char *buffer, const char *color); -typedef struct cmd_results *sway_cmd(int argc, char **argv); - sway_cmd cmd_assign; sway_cmd cmd_bar; sway_cmd cmd_bindcode; diff --git a/include/sway/config.h b/include/sway/config.h index de651ea4..b597da75 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -403,8 +403,6 @@ bool read_config(FILE *file, struct sway_config *config); */ void free_config(struct sway_config *config); -void config_clear_handler_context(struct sway_config *config); - void free_sway_variable(struct sway_variable *var); /** -- cgit v1.2.3 From 51bb9d8573efce7c46703d070ad963ba7d8dee76 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Wed, 30 May 2018 15:06:25 -0400 Subject: Support braces on next line for config blocks --- include/readline.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/readline.h b/include/readline.h index b3e06d4b..3f63e917 100644 --- a/include/readline.h +++ b/include/readline.h @@ -4,6 +4,7 @@ #include char *read_line(FILE *file); +char *peek_line(FILE *file, int offset); char *read_line_buffer(FILE *file, char *string, size_t string_len); #endif -- cgit v1.2.3 From 8bfa2def8876bb507aa0174e6b159a0a226889b4 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Wed, 30 May 2018 22:23:11 -0400 Subject: Address first round of review for generic blocks --- include/readline.h | 2 +- include/sway/commands.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/readline.h b/include/readline.h index 3f63e917..e1ae2302 100644 --- a/include/readline.h +++ b/include/readline.h @@ -4,7 +4,7 @@ #include char *read_line(FILE *file); -char *peek_line(FILE *file, int offset); +char *peek_line(FILE *file, int offset, long *position); char *read_line_buffer(FILE *file, char *string, size_t string_len); #endif diff --git a/include/sway/commands.h b/include/sway/commands.h index 6e2395bd..593ae0f1 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -60,8 +60,8 @@ struct cmd_results *config_command(char *command); /** * Parse and handle a sub command */ -struct cmd_results *subcommand(char **argv, int argc, - struct cmd_handler *handlers, int handlers_size); +struct cmd_results *config_subcommand(char **argv, int argc, + struct cmd_handler *handlers, size_t handlers_size); /* * Parses a command policy rule. */ -- cgit v1.2.3 From af87c7a1af8d790b819afe782fcff2830e959d58 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Fri, 1 Jun 2018 18:35:16 -0400 Subject: Address emersion's feedback on peek_line --- include/readline.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/readline.h b/include/readline.h index e1ae2302..ee2eba5d 100644 --- a/include/readline.h +++ b/include/readline.h @@ -4,7 +4,7 @@ #include char *read_line(FILE *file); -char *peek_line(FILE *file, int offset, long *position); +char *peek_line(FILE *file, int line_offset, long *position); char *read_line_buffer(FILE *file, char *string, size_t string_len); #endif -- cgit v1.2.3