1 /**
2  * @file
3  * NeoMutt commands API
4  *
5  * @authors
6  * Copyright (C) 2021 Richard Russon <rich@flatcap.org>
7  *
8  * @copyright
9  * This program is free software: you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License as published by the Free Software
11  * Foundation, either version 2 of the License, or (at your option) any later
12  * version.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License along with
20  * this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef MUTT_CORE_COMMAND_H
24 #define MUTT_CORE_COMMAND_H
25 
26 #include <stdint.h>
27 
28 struct Buffer;
29 
30 /**
31  * enum CommandResult - Error codes for command_t parse functions
32  */
33 enum CommandResult
34 {
35   MUTT_CMD_ERROR   = -1, ///< Error: Can't help the user
36   MUTT_CMD_WARNING = -2, ///< Warning: Help given to the user
37   MUTT_CMD_SUCCESS =  0, ///< Success: Command worked
38   MUTT_CMD_FINISH  =  1  ///< Finish: Stop processing this file
39 };
40 
41 /**
42  * @defgroup command_api Command API
43  *
44  * A user-callable command
45  */
46 struct Command
47 {
48   const char *name; ///< Name of the command
49 
50   /**
51    * @defgroup command_parse parse()
52    * @ingroup command_api
53    *
54    * parse - Function to parse a command
55    * @param buf  Temporary Buffer space
56    * @param s    Buffer containing string to be parsed
57    * @param data Flags associated with the command
58    * @param err  Buffer for error messages
59    * @retval #CommandResult Result e.g. #MUTT_CMD_SUCCESS
60    */
61   enum CommandResult (*parse)(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
62 
63   intptr_t data; ///< Data or flags to pass to the command
64 };
65 
66 #endif /* MUTT_CORE_COMMAND_H */
67