summaryrefslogtreecommitdiff
path: root/src/options.h
blob: f324601481265f9a444c9a1baef643db4ab6ccbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*  options.h -- Eterm options module header file
 *            -- 25 July 1997, mej
 *
 * This file is original work by Michael Jennings <mej@eterm.org> and
 * Tuomo Venalainen <vendu@cc.hut.fi>.  This file, and any other file
 * bearing this same message or a similar one, is distributed under
 * the GNU Public License (GPL) as outlined in the COPYING file.
 *
 * Copyright (C) 1997-1999, Michael Jennings and Tuomo Venalainen
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * 
 */

#ifndef _OPTIONS_H_
#define _OPTIONS_H_

#include <X11/Xfuncproto.h>
#include <X11/Intrinsic.h>	/* Xlib, Xutil, Xresource, Xfuncproto */

/************ Macros and Definitions ************/
#define OPT_BOOLEAN          0x0001
#define OPT_INTEGER          0x0002
#define OPT_STRING           0x0004
#define OPT_ARGUMENT         0x0008

#define OPT_STR(s, l, d, p)         { s, l, "(str)  " d, OPT_STRING,   (const char **)  p, 0, 0 }
#define OPT_INT(s, l, d, p)         { s, l, "(int)  " d, OPT_INTEGER,  (const int *)    p, 0, 0 }
#define OPT_BOOL(s, l, d, v, m)     { s, l, "(bool) " d, OPT_BOOLEAN,                NULL, v, m }
#define OPT_LONG(l, d, p)           { 0, l, "(str)  " d, OPT_STRING,   (const char **)  p, 0, 0 }
#define OPT_ARGS(s, l, d, p)        { s, l, "(str)  " d, OPT_ARGUMENT, (const char ***) p, 0, 0 }
#define OPT_BLONG(l, d, v, m)       { 0, l, "(bool) " d, OPT_BOOLEAN,                NULL, v, m }
#define OPT_ILONG(l, d, p)          { 0, l, "(int)  " d, OPT_INTEGER,  (const int *)    p, 0, 0 }
#define optList_numoptions()        (sizeof(optList)/sizeof(optList[0]))

#if PATH_MAX < 1024
#  undef PATH_MAX
#  define PATH_MAX 1024
#endif

# define Opt_console			(1LU <<  0)
# define Opt_loginShell			(1LU <<  1)
# define Opt_iconic			(1LU <<  2)
# define Opt_visualBell			(1LU <<  3)
# define Opt_mapAlert			(1LU <<  4)
# define Opt_reverseVideo		(1LU <<  5)
# define Opt_utmpLogging		(1LU <<  6)
# define Opt_scrollBar			(1LU <<  7)
# define Opt_meta8			(1LU <<  8)
# define Opt_exec			(1LU <<  9)
# define Opt_homeOnEcho			(1LU << 10)
# define Opt_homeOnRefresh		(1LU << 11)
# define Opt_scrollBar_right		(1LU << 12)
# define Opt_borderless			(1LU << 13)
# define Opt_backing_store		(1LU << 14)
# define Opt_noCursor			(1LU << 15)
# define Opt_pause			(1LU << 16)
# define Opt_homeOnInput		(1LU << 17)
# define Opt_report_as_keysyms		(1LU << 18)
# define Opt_xterm_select		(1LU << 19)
# define Opt_select_whole_line		(1LU << 20)
# define Opt_scrollbar_popup		(1LU << 21)
# define Opt_select_trailing_spaces	(1LU << 22)
# define Opt_install                	(1LU << 23)
# define Opt_scrollBar_floating		(1LU << 24)

# define IMOPT_TRANS                    (1U << 0)
# define IMOPT_VIEWPORT                 (1U << 1)

#define BOOL_OPT_ISTRUE(s)  (!strcasecmp((s), true_vals[0]) || !strcasecmp((s), true_vals[1]) \
                             || !strcasecmp((s), true_vals[2]) || !strcasecmp((s), true_vals[3]))
#define BOOL_OPT_ISFALSE(s) (!strcasecmp((s), false_vals[0]) || !strcasecmp((s), false_vals[1]) \
                             || !strcasecmp((s), false_vals[2]) || !strcasecmp((s), false_vals[3]))

/* This defines how many mistakes to allow before giving up
   and printing the usage                          -- mej   */
#define BAD_THRESHOLD 3
#define CHECK_BAD()  do { \
	               if (++bad_opts >= BAD_THRESHOLD) { \
			 print_error("error threshold exceeded, giving up"); \
			 usage(); \
		       } else { \
			 print_error("attempting to continue, but performance may be unpredictable"); \
		       } \
                     } while(0)

/* Max length of a line in the config file */
#define CONFIG_BUFF 20480

/* The context identifier.  This tells us what section of the config file
   we're in, for syntax checking purposes and the like.            -- mej */

enum {
  CTX_NULL,
  CTX_MAIN,
  CTX_COLOR,
  CTX_ATTRIBUTES,
  CTX_TOGGLES,
  CTX_KEYBOARD,
  CTX_MISC,
  CTX_IMAGECLASSES,
  CTX_IMAGE,
  CTX_ACTIONS,
  CTX_MENU,
  CTX_MENUITEM,
  CTX_XIM,
  CTX_MULTI_CHARSET,
  CTX_MAX = CTX_MULTI_CHARSET,
  CTX_UNDEF
};

#define ctx_name_to_id(the_id, n, i) do { \
                                       for ((i)=0; (i) <= CTX_MAX; (i)++) { \
                                         if (!strcasecmp((n), contexts[(i)].description)) { \
		                           (the_id) = contexts[(i)].id; \
					   break; \
					 } \
			               } \
                                       if ((i) > CTX_MAX) (the_id) = CTX_UNDEF; \
                                     } while (0)

#define ctx_id_to_name(id) (contexts[(id)].description)
#define ctx_id_to_func(id) (contexts[(id)].ctx_handler)

/* The context stack.  This keeps track of the current context and each
   previous one.  You MUST define MAX_CTX_DEPTH to the absolute maximum
   number of context levels deep your contexts go, or the results can be
   Very Bad.  I recommend erring on the side of caution.          -- mej */

#define MAX_CTX_DEPTH 10
#define ctx_push(ctx) id_stack[++cur_ctx] = (ctx)
#define ctx_pop()  (id_stack[cur_ctx--])
#define ctx_peek() (id_stack[cur_ctx])
#define ctx_poke(c) (id_stack[cur_ctx] = (c))
#define ctx_peek_last() (id_stack[(cur_ctx?cur_ctx-1:0)])
#define ctx_get_depth() (cur_ctx)
#define MAX_FILE_DEPTH 10
#define FILE_SKIP_TO_END	(0x01)
#define FILE_PREPROC		(0x02)
#define file_push(fs) do { \
                        cur_file++; \
                        file_stack[cur_file].fp = (fs).fp; \
                        file_stack[cur_file].path = (fs).path; \
                        file_stack[cur_file].line = (fs).line; \
			file_stack[cur_file].flags = (fs).flags; \
                      } while (0)

#define file_pop()    (cur_file--)
#define file_peek(fs) do { \
                        (fs).fp = file_stack[cur_file].fp; \
                        (fs).path = file_stack[cur_file].path; \
                        (fs).line = file_stack[cur_file].line; \
			(fs).flags = file_stack[cur_file].flags; \
                      } while (0)
#define file_peek_fp()      (file_stack[cur_file].fp)
#define file_peek_path()    (file_stack[cur_file].path)
#define file_peek_outfile() (file_stack[cur_file].outfile)
#define file_peek_line()    (file_stack[cur_file].line)
#define file_peek_skip()    (file_stack[cur_file].flags & FILE_SKIP_TO_END)
#define file_peek_preproc() (file_stack[cur_file].flags & FILE_PREPROC)

#define file_poke_fp(f)      ((file_stack[cur_file].fp) = (f))
#define file_poke_path(p)    ((file_stack[cur_file].path) = (p))
#define file_poke_outfile(p) ((file_stack[cur_file].outfile) = (p))
#define file_poke_line(l)    ((file_stack[cur_file].line) = (l))
#define file_poke_skip(s)    do {if (s) {file_stack[cur_file].flags |= FILE_SKIP_TO_END;} else {file_stack[cur_file].flags &= ~(FILE_SKIP_TO_END);} } while (0)
#define file_poke_preproc(s) do {if (s) {file_stack[cur_file].flags |= FILE_PREPROC;} else {file_stack[cur_file].flags &= ~(FILE_PREPROC);} } while (0)

#define file_inc_line()     (file_stack[cur_file].line++)

#define to_keysym(p,s) do { KeySym sym; \
                            if (s && ((sym = XStringToKeysym(s)) != 0)) *p = sym; \
                           } while (0)

#define RESET_AND_ASSIGN(var, val)  do {if ((var) != NULL) FREE(var);  (var) = (val);} while (0)

/************ Structures ************/
/* The file state stack.  This keeps track of the file currently being
   parsed.  This allows for %include directives.                  -- mej */
typedef struct file_state_struct {
  FILE *fp;
  char *path, *outfile;
  unsigned long line;
  unsigned char flags;
} file_state;
typedef char *(*eterm_function_ptr) (char *);
typedef struct eterm_function_struct {

  char *name;
  eterm_function_ptr ptr;
  int params;

} eterm_func;

/************ Variables ************/
extern unsigned long Options, image_toggles;
extern char *theme_dir, *user_dir;
extern       char **rs_execArgs;        /* Args to exec (-e or --exec) */
extern       char  *rs_title;		/* Window title */
extern       char  *rs_iconName;	/* Icon name */
extern       char  *rs_geometry;	/* Geometry string */
extern        int   rs_desktop;         /* Startup desktop */
extern        int   rs_saveLines;	/* Lines in the scrollback buffer */
extern unsigned short rs_min_anchor_size; /* Minimum size, in pixels, of the scrollbar anchor */
extern       char  *rs_term_name;
extern const char  *rs_menubar;
extern const char  *rs_menu;
extern       char  *rs_icon;
extern       char  *rs_scrollbar_type;
extern unsigned long rs_scrollbar_width;
extern       char  *rs_scrollbar_type;
extern       char  *rs_anim_pixmap_list;
extern       char **rs_anim_pixmaps;
extern     time_t   rs_anim_delay;
extern char *rs_path;
extern char *rs_noCursor;
#ifdef USE_XIM
extern char *rs_inputMethod;
extern char *rs_preeditType;
#endif
extern char *rs_name;
extern char *rs_config_file;
extern unsigned int rs_line_space;
#ifndef NO_BOLDFONT
extern char *rs_boldFont;
#endif
#ifdef PRINTPIPE
extern char *rs_print_pipe;
#endif
extern char *rs_cutchars;
#ifdef CUTCHAR_OPTION
extern       char  *rs_cutchars;
#endif
extern const char *true_vals[];
extern const char *false_vals[];
#ifdef KEYSYM_ATTRIBUTE
extern unsigned char *KeySym_map[256];
#endif
#if defined (HOTKEY_CTRL) || defined (HOTKEY_META)
extern KeySym ks_bigfont;
extern KeySym ks_smallfont;
#endif

/************ Function Prototypes ************/
_XFUNCPROTOBEGIN

unsigned long NumWords(const char *str);
extern void get_initial_options(int, char **);
extern void get_options(int, char **);
extern char *chomp(char *);
extern char *shell_expand(char *);
extern char *find_theme(char *, char *, char *);
extern unsigned char open_config_file(char *);
extern void read_config(char *);
extern void init_defaults(void);
extern void post_parse(void);
unsigned char save_config(char *);

_XFUNCPROTOEND

#endif	/* _OPTIONS_H_ */