1 #ifndef __CGDBRC_H__
2 #define __CGDBRC_H__
3 
4 #if HAVE_CONFIG_H
5 #include "config.h"
6 #endif /* HAVE_CONFIG_H */
7 
8 #if HAVE_STDIO_H
9 #include <stdio.h>
10 #endif /* HAVE_STDIO_H */
11 
12 /* TODO: Remove this include. It is simply used to get
13  * enum tokenizer_language_support.
14  */
15 #include "tokenizer.h"
16 
17 /**
18  * \file
19  * cgdbrc.h
20  *
21  * \brief
22  * An interface for dealing with config parameters. A client can determine
23  * the value of a configuration option by calling cgdbrc_get. A client can
24  * also ask to be notified when a particular option is changed. This gives
25  * them two benefits. They can determine if the new value the user is trying
26  * to set the option to is valid, and they can be kept up to date when
27  * the option is changed.
28  *
29  * This package is currently not context driven. That is because at this
30  * point there is only need for one cgdbrc package. Feel free to make
31  * a 'struct cgdbrc' if it's needed in the future.
32  *
33  * Also, the higlight_group package is really part of the configuration too.
34  * Feel free to integrate the two files somehow.
35  */
36 
37 /* Initialization {{{ */
38 
39 /**
40  * Initialize the cgdbrc interface.
41  *
42  * TODO: This interface should become instance driven instead of having
43  * a global context.
44  *
45  * \return
46  * 0 on success, otherwise error.
47  */
48 void cgdbrc_init(void);
49 
50 /* }}} */
51 
52 /* Parse options {{{ */
53 
54 /**
55  * Parse a string of command data and execute the commands that it represents.
56  *
57  * \param buffer
58  * A line of command data to parse (representing a single command).
59  *
60  * \return
61  * 0 on success, otherwise error.
62  */
63 int command_parse_string(const char *buffer);
64 
65 /**
66  * Parse a configuration file, and execute the commands that it contains.
67  * The commands will be executed in order.
68  *
69  * \param fp
70  * The file to parse.
71  *
72  * \return
73  * Currently only returns 0.
74  */
75 int command_parse_file(const char *config_file);
76 
77 /* }}} */
78 
79 /* Options types {{{ */
80 
81 /**
82  * The different ways to display a line in the CGDB window.
83  */
84 enum LineDisplayStyle {
85     LINE_DISPLAY_SHORT_ARROW,
86     LINE_DISPLAY_LONG_ARROW,
87     LINE_DISPLAY_HIGHLIGHT,
88     LINE_DISPLAY_BLOCK
89 };
90 
91 /** window split type enumeration*/
92 typedef enum { WIN_SPLIT_FREE = -3, /* split point not on quarter mark */
93 
94     WIN_SPLIT_GDB_FULL = -2,    /* src window is 0%   of screen */
95     WIN_SPLIT_GDB_BIG = -1,     /* src window is 25%  of screen */
96     WIN_SPLIT_EVEN = 0,         /* src window is 50%  of screen */
97     WIN_SPLIT_SRC_BIG = 1,      /* src window is 75%  of screen */
98     WIN_SPLIT_SRC_FULL = 2      /* src window is 100% of screen */
99 } WIN_SPLIT_TYPE;
100 
101 /** window split orientation type enumeration
102  *
103  *  SPLIT_VERTICAL and SPLIT_HORIZONTAL refer to the orientation
104  *  of the split between the source and GDB windows.
105  */
106 typedef enum {
107     WSO_HORIZONTAL, /* source above and GDB below (default) */
108     WSO_VERTICAL    /* source left and GDB right            */
109 } WIN_SPLIT_ORIENTATION_TYPE;
110 
111 /** All of the different configuration options */
112 enum cgdbrc_option_kind {
113     /* Arrow style is deprecated, use CGDBRC_EXECUTING_LINE_DISPLAY instead */
114     CGDBRC_ARROWSTYLE,
115     CGDBRC_AUTOSOURCERELOAD,
116     CGDBRC_CGDB_MODE_KEY,
117     CGDBRC_COLOR,
118     CGDBRC_DEBUGWINCOLOR,
119     CGDBRC_DISASM,
120     CGDBRC_EXECUTING_LINE_DISPLAY,
121     CGDBRC_HLSEARCH,
122     CGDBRC_IGNORECASE,
123     CGDBRC_SCROLLBACK_BUFFER_SIZE,
124     CGDBRC_SELECTED_LINE_DISPLAY,
125     CGDBRC_SHOWMARKS,
126     CGDBRC_SYNTAX,
127     CGDBRC_TABSTOP,
128     CGDBRC_TIMEOUT,
129     CGDBRC_TIMEOUT_LEN,
130     CGDBRC_TTIMEOUT,
131     CGDBRC_TTIMEOUT_LEN,
132     CGDBRC_WINMINHEIGHT,
133     CGDBRC_WINMINWIDTH,
134     CGDBRC_WINSPLIT,
135     CGDBRC_WINSPLITORIENTATION,
136     CGDBRC_WRAPSCAN
137 };
138 
139 /** This represents a single configuration option. */
140 struct cgdbrc_config_option {
141     enum cgdbrc_option_kind option_kind;
142     union {
143         /* option_kind == CGDBRC_ARROWSTYLE */
144         /* option_kind == CGDBRC_EXECUTING_LINE_DISPLAY */
145         /* option_kind == CGDBRC_SELECTED_LINE_DISPLAY */
146         enum LineDisplayStyle line_display_style;
147         /* option_kind == CGDBRC_AUTOSOURCERELOAD */
148         /* option_kind == CGDBRC_CGDB_MODE_KEY */
149         /* option_kind == CGDBRC_COLOR */
150         /* option_kind == CGDBRC_DEBUGWINCOLOR */
151         /* option_kind == CGDBRC_DISASM */
152         /* option_kind == CGDBRC_HLSEARCH */
153         /* option_kind == CGDBRC_IGNORECASE */
154         /* option_kind == CGDBRC_SCROLLBACK_BUFFER_SIZE */
155         /* option_kind == CGDBRC_SHOWMARKS */
156         /* option_kind == CGDBRC_TABSTOP */
157         /* option_kind == CGDBRC_TIMEOUT */
158         /* option_kind == CGDBRC_TIMEOUTLEN */
159         /* option_kind == CGDBRC_TTIMEOUT */
160         /* option_kind == CGDBRC_TTIMEOUTLEN */
161         /* option_kind == CGDBRC_WINMINHEIGHT */
162         /* option_kind == CGDBRC_WINMINWIDTH */
163         /* option_kind == CGDBRC_WRAPSCAN */
164         int int_val;
165         /* option_kind == CGDBRC_SYNTAX */
166         enum tokenizer_language_support language_support_val;
167         /* option_kind == CGDBRC_WINSPLIT */
168         WIN_SPLIT_TYPE win_split_val;
169         /* option_kind == CGDBRC_WINSPLITORIENTATION */
170         WIN_SPLIT_ORIENTATION_TYPE win_split_orientation_val;
171     } variant;
172 };
173 
174 /* }}} */
175 
176 /* Attach/Detach options {{{ */
177 
178 typedef struct cgdbrc_config_option *cgdbrc_config_option_ptr;
179 
180 /**
181  * If the notify function fails, this tells the configuration package
182  * that the option was not acceptable. The option will not be kept.
183  * This allows a mechanism for the configuration package to allow other
184  * packages to validate if a particular config option value is OK. So,
185  * a client might use this even if they are not interested in getting the
186  * new values, but want to validate the values, in order to not tightly
187  * couple the config reader with the other parts of CGDB.
188  */
189 typedef int (*cgdbrc_notify) (cgdbrc_config_option_ptr option);
190 
191 /**
192  * This will attach a new callback function for a particular option.
193  * The client will be notified when the value is changed.
194  *
195  * \param option
196  * The new option to attach a callback to.
197  *
198  * \param notify
199  * The callback function to call when the state of the data changes.
200  *
201  * \return
202  * 0 on success or -1 on error
203  */
204 int cgdbrc_attach(enum cgdbrc_option_kind option, cgdbrc_notify notify);
205 
206 /* }}} */
207 
208 /* Get options {{{ */
209 
210 /**
211  * Get a configuration option.
212  *
213  * \param option
214  * The option to get
215  *
216  * \return
217  * This will never return NULL. It is returned as a pointer simply to not
218  * pass the entire structure back. The configuration option corresponding
219  * to the option asked for is returned.
220  */
221 cgdbrc_config_option_ptr cgdbrc_get(enum cgdbrc_option_kind option);
222 int cgdbrc_get_int(enum cgdbrc_option_kind option);
223 enum LineDisplayStyle cgdbrc_get_displaystyle(enum cgdbrc_option_kind option);
224 
225 /**
226  * A convience function for determining the timeout that should be used to
227  * allow a key code sequence to complete. This function can not fail.
228  *
229  * \return
230  * The number of milliseconds to delay before timing out. If 0, then do not
231  * timeout.
232  */
233 int cgdbrc_get_key_code_timeoutlen(void);
234 
235 /**
236  * A convience function for determining the timeout that should be used to
237  * allow a mapped key sequence to complete. This function can not fail.
238  *
239  * \return
240  * The number of milliseconds to delay before timing out. If 0, then do not
241  * timeout.
242  */
243 int cgdbrc_get_mapped_key_timeoutlen(void);
244 
245 /* }}} */
246 
247 #endif /* __CGDBRC_H__ */
248