summaryrefslogtreecommitdiffstats
path: root/tmux.h
diff options
context:
space:
mode:
authornicm <nicm>2019-05-23 11:13:30 +0000
committernicm <nicm>2019-05-23 11:13:30 +0000
commit723010ba72e337832402f8e44981c02caa30b476 (patch)
treea7fa1089f4d5dc368a44702489cf176afbcfec55 /tmux.h
parent5571d7a21c5dc920eb9d25336b5bb7b04d72fc9d (diff)
Replace the split parser code (cfg.c and cmd-string.c) with a single
parser using yacc(1). This is a major change but is clearer and simpler and allows some edge cases to be made more consistent, as well as tidying up how aliases are handled. It will also allow some further improvements later. Entirely the same parser is now used for parsing the configuration file and for string commands. This means that constructs previously only available in .tmux.conf, such as %if, can now be used in string commands (for example, those given to if-shell - not commands invoked from the shell, they are still parsed by the shell itself). The only syntax change I am aware of is that #{} outside quotes or a comment is now considered a format and not a comment, so #{ is now a syntax error (notably, if it is at the start of a line). This also adds two new sections to the man page documenting the syntax and outlining how parsing and command execution works. Thanks to everyone who sent me test configs (they still all parse without errors - but this doesn't mean they still work as intended!). Thanks to Avi Halachmi for testing and man page improvements, also to jmc@ for reviewing the man page changes.
Diffstat (limited to 'tmux.h')
-rw-r--r--tmux.h64
1 files changed, 52 insertions, 12 deletions
diff --git a/tmux.h b/tmux.h
index 2979a6e3..f996b1f4 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1279,18 +1279,25 @@ struct cmd_find_state {
/* Command and list of commands. */
struct cmd {
- const struct cmd_entry *entry;
- struct args *args;
+ const struct cmd_entry *entry;
+ struct args *args;
+ u_int group;
- char *file;
- u_int line;
+ char *file;
+ u_int line;
+
+ char *alias;
+ int argc;
+ char **argv;
- TAILQ_ENTRY(cmd) qentry;
+ TAILQ_ENTRY(cmd) qentry;
};
+TAILQ_HEAD(cmds, cmd);
struct cmd_list {
- int references;
- TAILQ_HEAD(, cmd) list;
+ int references;
+ u_int group;
+ struct cmds list;
};
/* Command return values. */
@@ -1301,6 +1308,31 @@ enum cmd_retval {
CMD_RETURN_STOP
};
+/* Command parse result. */
+enum cmd_parse_status {
+ CMD_PARSE_EMPTY,
+ CMD_PARSE_ERROR,
+ CMD_PARSE_SUCCESS
+};
+struct cmd_parse_result {
+ enum cmd_parse_status status;
+ struct cmd_list *cmdlist;
+ char *error;
+};
+struct cmd_parse_input {
+ int flags;
+#define CMD_PARSE_QUIET 0x1
+#define CMD_PARSE_PARSEONLY 0x2
+#define CMD_PARSE_NOALIAS 0x4
+
+ const char *file;
+ u_int line;
+
+ struct cmdq_item *item;
+ struct client *c;
+ struct cmd_find_state fs;
+};
+
/* Command queue item type. */
enum cmdq_type {
CMDQ_COMMAND,
@@ -1671,7 +1703,6 @@ void proc_toggle_log(struct tmuxproc *);
/* cfg.c */
extern int cfg_finished;
extern struct client *cfg_client;
-#define CFG_QUIET 0x1
void start_cfg(void);
int load_cfg(const char *, struct client *, struct cmdq_item *, int,
struct cmdq_item **);
@@ -1956,12 +1987,16 @@ int cmd_find_from_nothing(struct cmd_find_state *, int);
/* cmd.c */
void cmd_log_argv(int, char **, const char *);
+void cmd_prepend_argv(int *, char ***, char *);
+void cmd_append_argv(int *, char ***, char *);
int cmd_pack_argv(int, char **, char *, size_t);
int cmd_unpack_argv(char *, size_t, int, char ***);
char **cmd_copy_argv(int, char **);
void cmd_free_argv(int, char **);
char *cmd_stringify_argv(int, char **);
+char *cmd_get_alias(const char *);
struct cmd *cmd_parse(int, char **, const char *, u_int, char **);
+void cmd_free(struct cmd *);
char *cmd_print(struct cmd *);
int cmd_mouse_at(struct window_pane *, struct mouse_event *,
u_int *, u_int *, int);
@@ -1975,7 +2010,16 @@ extern const struct cmd_entry *cmd_table[];
enum cmd_retval cmd_attach_session(struct cmdq_item *, const char *, int, int,
const char *, int);
+/* cmd-parse.c */
+void cmd_parse_empty(struct cmd_parse_input *);
+struct cmd_parse_result *cmd_parse_from_file(FILE *, struct cmd_parse_input *);
+struct cmd_parse_result *cmd_parse_from_string(const char *,
+ struct cmd_parse_input *);
+
/* cmd-list.c */
+struct cmd_list *cmd_list_new(void);
+void cmd_list_append(struct cmd_list *, struct cmd *);
+void cmd_list_move(struct cmd_list *, struct cmd_list *);
struct cmd_list *cmd_list_parse(int, char **, const char *, u_int, char **);
void cmd_list_free(struct cmd_list *);
char *cmd_list_print(struct cmd_list *);
@@ -1997,10 +2041,6 @@ void cmdq_guard(struct cmdq_item *, const char *, int);
void printflike(2, 3) cmdq_print(struct cmdq_item *, const char *, ...);
void printflike(2, 3) cmdq_error(struct cmdq_item *, const char *, ...);
-/* cmd-string.c */
-int cmd_string_split(const char *, int *, char ***);
-struct cmd_list *cmd_string_parse(const char *, const char *, u_int, char **);
-
/* cmd-wait-for.c */
void cmd_wait_for_flush(void);