ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/xdefaults.C
Revision: 1.170
Committed: Thu Jun 7 16:04:45 2012 UTC (11 years, 11 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.169: +2 -1 lines
Log Message:
visual selection

File Contents

# Content
1 /*----------------------------------------------------------------------*
2 * File: xdefaults.C
3 *----------------------------------------------------------------------*
4 *
5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com>
7 * - original version
8 * Copyright (c) 1997,1998 mj olesen <olesen@me.queensu.ca>
9 * Copyright (c) 2003-2006 Marc Lehmann <schmorp@schmorp.de>
10 * Copyright (c) 2007 Emanuele Giaquinta <e.giaquinta@glauco.it>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *----------------------------------------------------------------------*/
26
27 #include "../config.h"
28 #include "rxvt.h"
29 #include "version.h"
30
31 #ifdef KEYSYM_RESOURCE
32 # include "keyboard.h"
33 #endif
34
35 /* place holders used for parsing command-line options */
36 #define Optflag_Reverse 1
37 #define Optflag_Boolean 2
38 #define Optflag_Switch 4
39 #define Optflag_Info 8
40
41 /* monolithic option/resource structure: */
42 /*
43 * `string' options MUST have a usage argument
44 * `switch' and `boolean' options have no argument
45 * if there's no desc (ription), it won't appear in rxvt_usage ()
46 */
47
48 /* INFO () - descriptive information only */
49 #define INFO(opt, arg, desc) \
50 {0, Optflag_Info, -1, NULL, (opt), (arg), (desc)}
51
52 #define RINFO(kw, arg) \
53 {0, Optflag_Info, -1, (kw), NULL, (arg), NULL}
54
55 /* STRG () - command-line option, with/without resource */
56 #define STRG(rsp, kw, opt, arg, desc) \
57 {0, 0, (rsp), (kw), (opt), (arg), (desc)}
58
59 /* RSTRG () - resource/long-option */
60 #define RSTRG(rsp, kw, arg) \
61 {0, 0, (rsp), (kw), NULL, (arg), NULL}
62
63 /* BOOL () - regular boolean `-/+' flag */
64 #define BOOL(rsp, kw, opt, option, flag, desc) \
65 { (option), (Optflag_Boolean | (flag)), (rsp), (kw), (opt), NULL, (desc)}
66
67 /* SWCH () - `-' flag */
68 #define SWCH(opt, option, flag, desc) \
69 { (option), (Optflag_Switch | (flag)), -1, NULL, (opt), NULL, (desc)}
70
71 /* convenient macros */
72 #define optList_isString(i) \
73 (optList[i].flag == 0)
74 #define optList_isBool(i) \
75 (optList[i].flag & Optflag_Boolean)
76 #define optList_isReverse(i) \
77 (optList[i].flag & Optflag_Reverse)
78 #define optList_isInfo(i) \
79 (optList[i].flag & Optflag_Info)
80
81 static const struct
82 {
83 const uint8_t index; /* Option index */
84 const uint8_t flag; /* Option flag */
85 const int16_t doff; /* resource value index or -1 */
86 const char *kw; /* keyword */
87 const char *opt; /* option */
88 const char *arg; /* argument */
89 const char *desc; /* description */
90 }
91 optList[] = {
92 STRG (Rs_display_name, NULL, "d", NULL, NULL), /* short form */
93 STRG (Rs_display_name, NULL, "display", "string", "X server to contact"),
94 STRG (Rs_term_name, "termName", "tn", "string", "value of the TERM environment variable"),
95 STRG (Rs_geometry, NULL, "g", NULL, NULL), /* short form */
96 STRG (Rs_geometry, "geometry", "geometry", "geometry", "size (in characters) and position"),
97 SWCH ("C", Opt_console, 0, "intercept console messages"),
98 SWCH ("iconic", Opt_iconic, 0, "start iconic"),
99 SWCH ("ic", Opt_iconic, 0, NULL), /* short form */
100 STRG (Rs_chdir, "chdir", "cd", "string", "start shell in this directory"),
101 BOOL (Rs_reverseVideo, "reverseVideo", "rv", Opt_reverseVideo, 0, "reverse video"),
102 BOOL (Rs_loginShell, "loginShell", "ls", Opt_loginShell, 0, "login shell"),
103 BOOL (Rs_jumpScroll, "jumpScroll", "j", Opt_jumpScroll, 0, "jump scrolling"),
104 BOOL (Rs_skipScroll, "skipScroll", "ss", Opt_skipScroll, 0, "skip scrolling"),
105 BOOL (Rs_pastableTabs, "pastableTabs", "ptab", Opt_pastableTabs, 0, "tab characters are pastable"),
106 RSTRG (Rs_scrollstyle, "scrollstyle", "mode"),
107 BOOL (Rs_scrollBar, "scrollBar", "sb", Opt_scrollBar, 0, "scrollbar"),
108 BOOL (Rs_scrollBar_right, "scrollBar_right", "sr", Opt_scrollBar_right, 0, "scrollbar right"),
109 BOOL (Rs_scrollBar_floating, "scrollBar_floating", "st", Opt_scrollBar_floating, 0, "scrollbar without a trough"),
110 RSTRG (Rs_scrollBar_align, "scrollBar_align", "mode"),
111 STRG (Rs_scrollBar_thickness, "thickness", "sbt", "number", "scrollbar thickness/width in pixels"),
112 BOOL (Rs_scrollTtyOutput, "scrollTtyOutput", NULL, Opt_scrollTtyOutput, 0, NULL),
113 BOOL (Rs_scrollTtyOutput, NULL, "si", Opt_scrollTtyOutput, Optflag_Reverse, "scroll-on-tty-output inhibit"),
114 BOOL (Rs_scrollTtyKeypress, "scrollTtyKeypress", "sk", Opt_scrollTtyKeypress, 0, "scroll-on-keypress"),
115 BOOL (Rs_scrollWithBuffer, "scrollWithBuffer", "sw", Opt_scrollWithBuffer, 0, "scroll-with-buffer"),
116 #if ENABLE_TRANSPARENCY
117 BOOL (Rs_transparent, "inheritPixmap", "ip", Opt_transparent, 0, "inherit parent pixmap"),
118 BOOL (Rs_transparent, "transparent", "tr", Opt_transparent, 0, "inherit parent pixmap"),
119 STRG (Rs_color + Color_tint, "tintColor", "tint", "color", "tint color"),
120 STRG (Rs_shade, "shading", "sh", "number", "shade background by number %."),
121 STRG (Rs_blurradius, "blurRadius", "blr", "HxV", "gaussian blur radii to apply to the root background"),
122 #endif
123 #if OFF_FOCUS_FADING
124 STRG (Rs_fade, "fading", "fade", "number", "fade colors by number % when losing focus"),
125 STRG (Rs_color + Color_fade, "fadeColor", "fadecolor", "color", "target color for off-focus fading"),
126 #endif
127 BOOL (Rs_utmpInhibit, "utmpInhibit", "ut", Opt_utmpInhibit, 0, "utmp inhibit"),
128 #ifndef NO_BELL
129 # if ENABLE_FRILLS
130 BOOL (Rs_urgentOnBell, "urgentOnBell", NULL, Opt_urgentOnBell, 0, NULL),
131 # endif
132 BOOL (Rs_visualBell, "visualBell", "vb", Opt_visualBell, 0, "visual bell"),
133 # if ! defined(NO_MAPALERT) && defined(MAPALERT_OPTION)
134 BOOL (Rs_mapAlert, "mapAlert", NULL, Opt_mapAlert, 0, NULL),
135 # endif
136 #endif
137 #ifdef META8_OPTION
138 BOOL (Rs_meta8, "meta8", NULL, Opt_meta8, 0, NULL),
139 #endif
140 #ifdef MOUSE_WHEEL
141 BOOL (Rs_mouseWheelScrollPage, "mouseWheelScrollPage", NULL, Opt_mouseWheelScrollPage, 0, NULL),
142 #endif
143 #if ENABLE_FRILLS
144 BOOL (Rs_tripleclickwords, "tripleclickwords", "tcw", Opt_tripleclickwords, 0, "triple click word selection"),
145 BOOL (Rs_insecure, "insecure", "insecure", Opt_insecure, 0, "enable possibly insecure escape sequences"),
146 BOOL (Rs_cursorUnderline, "cursorUnderline", "uc", Opt_cursorUnderline, 0, "underline cursor"),
147 #endif
148 #if CURSOR_BLINK
149 BOOL (Rs_cursorBlink, "cursorBlink", "bc", Opt_cursorBlink, 0, "blinking cursor"),
150 #endif
151 #ifdef POINTER_BLANK
152 BOOL (Rs_pointerBlank, "pointerBlank", "pb", Opt_pointerBlank, 0, "switch off pointer after delay"),
153 #endif
154 STRG (Rs_color + Color_bg, "background", "bg", "color", "background color"),
155 STRG (Rs_color + Color_fg, "foreground", "fg", "color", "foreground color"),
156 RSTRG (Rs_color + minCOLOR + 0, "color0", "color"),
157 RSTRG (Rs_color + minCOLOR + 1, "color1", "color"),
158 RSTRG (Rs_color + minCOLOR + 2, "color2", "color"),
159 RSTRG (Rs_color + minCOLOR + 3, "color3", "color"),
160 RSTRG (Rs_color + minCOLOR + 4, "color4", "color"),
161 RSTRG (Rs_color + minCOLOR + 5, "color5", "color"),
162 RSTRG (Rs_color + minCOLOR + 6, "color6", "color"),
163 RSTRG (Rs_color + minCOLOR + 7, "color7", "color"),
164 RSTRG (Rs_color + minBrightCOLOR + 0, "color8", "color"),
165 RSTRG (Rs_color + minBrightCOLOR + 1, "color9", "color"),
166 RSTRG (Rs_color + minBrightCOLOR + 2, "color10", "color"),
167 RSTRG (Rs_color + minBrightCOLOR + 3, "color11", "color"),
168 RSTRG (Rs_color + minBrightCOLOR + 4, "color12", "color"),
169 RSTRG (Rs_color + minBrightCOLOR + 5, "color13", "color"),
170 RSTRG (Rs_color + minBrightCOLOR + 6, "color14", "color"),
171 RSTRG (Rs_color + minBrightCOLOR + 7, "color15", "color"),
172 #ifndef NO_BOLD_UNDERLINE_REVERSE
173 RSTRG (Rs_color + Color_BD, "colorBD", "color"),
174 RSTRG (Rs_color + Color_IT, "colorIT", "color"),
175 RSTRG (Rs_color + Color_UL, "colorUL", "color"),
176 RSTRG (Rs_color + Color_RV, "colorRV", "color"),
177 #endif /* ! NO_BOLD_UNDERLINE_REVERSE */
178 #if ENABLE_FRILLS
179 RSTRG (Rs_color + Color_underline, "underlineColor", "color"),
180 #endif
181 RSTRG (Rs_color + Color_scroll, "scrollColor", "color"),
182 #ifdef RXVT_SCROLLBAR
183 RSTRG (Rs_color + Color_trough, "troughColor", "color"),
184 #endif
185 #ifdef OPTION_HC
186 STRG (Rs_color + Color_HC, "highlightColor", "hc", "color", "highlight color"),
187 RSTRG (Rs_color + Color_HTC, "highlightTextColor", "color"),
188 #endif
189 #ifndef NO_CURSORCOLOR
190 STRG (Rs_color + Color_cursor, "cursorColor", "cr", "color", "cursor color"),
191 /* command-line option = resource name */
192 RSTRG (Rs_color + Color_cursor2, "cursorColor2", "color"),
193 #endif /* NO_CURSORCOLOR */
194 STRG (Rs_color + Color_pointer_fg, "pointerColor", "pr", "color", "pointer color"),
195 STRG (Rs_color + Color_pointer_bg, "pointerColor2", "pr2", "color", "pointer bg color"),
196 STRG (Rs_color + Color_border, "borderColor", "bd", "color", "border color"),
197 #if BG_IMAGE_FROM_FILE
198 RSTRG (Rs_path, "path", "search path"),
199 STRG (Rs_backgroundPixmap, "backgroundPixmap", "pixmap", "file[;geom]", "background pixmap"),
200 # if ENABLE_EWMH
201 STRG (Rs_iconfile, "iconFile", "icon", "file", "path to application icon image"),
202 # endif
203 #endif
204 /* fonts: command-line option = resource name */
205 STRG (Rs_font, "font", "fn", "fontname", "normal text font"),
206 #if ENABLE_STYLES
207 STRG (Rs_boldFont, "boldFont", "fb", "fontname", "bold font"),
208 STRG (Rs_italicFont, "italicFont", "fi", "fontname", "italic font"),
209 STRG (Rs_boldItalicFont, "boldItalicFont", "fbi", "fontname", "bold italic font"),
210 BOOL (Rs_intensityStyles, "intensityStyles", "is", Opt_intensityStyles, 0, "font styles imply intensity changes"),
211 #endif
212 #if USE_XIM
213 STRG (Rs_inputMethod, "inputMethod", "im", "name", "name of input method"),
214 STRG (Rs_preeditType, "preeditType", "pt", "style", "input style: style = OverTheSpot|OffTheSpot|Root"),
215 STRG (Rs_imLocale, "imLocale", "imlocale", "string", "locale to use for input method"),
216 STRG (Rs_imFont, "imFont", "imfont", "fontname", "fontset for styles OverTheSpot and OffTheSpot"),
217 #endif /* USE_XIM */
218 STRG (Rs_name, NULL, "name", "string", "client instance, icon, and title strings"),
219 STRG (Rs_title, "title", "title", "string", "title name for window"),
220 STRG (Rs_title, NULL, "T", NULL, NULL), /* short form */
221 STRG (Rs_iconName, "iconName", "n", "string", "icon name for window"),
222 STRG (Rs_saveLines, "saveLines", "sl", "number", "number of scrolled lines to save"),
223 #if ENABLE_XEMBED
224 STRG (Rs_embed, NULL, "embed", "windowid", "window id to embed terminal in"),
225 #endif
226 #if XFT
227 BOOL (Rs_buffered, "buffered", NULL, Opt_buffered, 0, NULL),
228 #endif
229 #if ENABLE_FRILLS
230 STRG (Rs_depth, "depth", "depth", "number", "depth of visual to request"),
231 STRG (Rs_visual, "visual", "visual", "number", "visual id to request"),
232 RSTRG (Rs_transient_for, "transient-for", "windowid"),
233 BOOL (Rs_override_redirect, "override-redirect", "override-redirect", Opt_override_redirect, 0, "set override-redirect on the terminal window"),
234 STRG (Rs_pty_fd, NULL, "pty-fd", "fileno", "file descriptor of pty to use"),
235 BOOL (Rs_hold, "hold", "hold", Opt_hold, 0, "retain window after shell exit"),
236 STRG (Rs_ext_bwidth, "externalBorder", "w", "number", "external border in pixels"),
237 STRG (Rs_ext_bwidth, NULL, "bw", NULL, NULL),
238 STRG (Rs_ext_bwidth, NULL, "borderwidth", NULL, NULL),
239 STRG (Rs_int_bwidth, "internalBorder", "b", "number", "internal border in pixels"),
240 BOOL (Rs_borderLess, "borderLess", "bl", Opt_borderLess, 0, "borderless window"),
241 STRG (Rs_lineSpace, "lineSpace", "lsp", "number", "number of extra pixels between rows"),
242 STRG (Rs_letterSpace, "letterSpace", "letsp", "number", "letter spacing adjustment"),
243 #endif
244 #ifdef BUILTIN_GLYPHS
245 BOOL (Rs_skipBuiltinGlyphs, "skipBuiltinGlyphs", "sbg", Opt_skipBuiltinGlyphs, 0, "do not use internal glyphs"),
246 #endif
247 #ifdef POINTER_BLANK
248 RSTRG (Rs_pointerBlankDelay, "pointerBlankDelay", "number"),
249 #endif
250 #ifndef NO_BACKSPACE_KEY
251 RSTRG (Rs_backspace_key, "backspacekey", "string"),
252 #endif
253 #ifndef NO_DELETE_KEY
254 RSTRG (Rs_delete_key, "deletekey", "string"),
255 #endif
256 #ifdef PRINTPIPE
257 RSTRG (Rs_print_pipe, "print-pipe", "string"),
258 #endif
259 STRG (Rs_modifier, "modifier", "mod", "modifier", "meta modifier = alt|meta|hyper|super|mod1|...|mod5"),
260 RSTRG (Rs_cutchars, "cutchars", "string"),
261 RSTRG (Rs_answerbackstring, "answerbackString", "string"),
262 #ifndef NO_SECONDARY_SCREEN
263 BOOL (Rs_secondaryScreen, "secondaryScreen", "ssc", Opt_secondaryScreen, 0, "enable secondary screen"),
264 BOOL (Rs_secondaryScroll, "secondaryScroll", "ssr", Opt_secondaryScroll, 0, "enable secondary screen scroll"),
265 #endif
266 #if ENABLE_PERL
267 RSTRG (Rs_perl_lib, "perl-lib", "string"), //, "colon-separated directories with extension scripts"),TODO
268 RSTRG (Rs_perl_eval, "perl-eval", "perl-eval"), // "string", "code to be evaluated after all extensions have been loaded"),TODO
269 RSTRG (Rs_perl_ext_1, "perl-ext-common", "string"), //, "colon-separated list of perl extensions to enable"),TODO
270 STRG (Rs_perl_ext_2, "perl-ext", "pe", "string", "colon-separated list of perl extensions to enable for this instance"),
271 #endif
272 #if ISO_14755
273 BOOL (Rs_iso14755, "iso14755", NULL, Opt_iso14755, 0, NULL),
274 BOOL (Rs_iso14755_52, "iso14755_52", NULL, Opt_iso14755_52, 0, NULL),
275 #endif
276 #ifndef NO_RESOURCES
277 RINFO ("xrm", "string"),
278 #endif
279 #ifdef KEYSYM_RESOURCE
280 RINFO ("keysym.sym", "keysym"),
281 #endif
282 INFO ("e", "command arg ...", "command to execute")
283 };
284
285 #undef INFO
286 #undef RINFO
287 #undef STRG
288 #undef RSTRG
289 #undef SWCH
290 #undef BOOL
291
292 static const char releasestring[] = "rxvt-unicode (" RXVTNAME ") v" VERSION " - released: " DATE "\n";
293 static const char optionsstring[] = "options: "
294 #if ENABLE_PERL
295 "perl,"
296 #endif
297 #if XFT
298 "xft,"
299 #endif
300 #if ENABLE_STYLES
301 "styles,"
302 #endif
303 #if ENABLE_COMBINING
304 "combining,"
305 #endif
306 #if TEXT_BLINK
307 "blink,"
308 #endif
309 #if ISO_14755
310 "iso14755,"
311 #endif
312 #if UNICODE_3
313 "unicode3,"
314 #endif
315 "encodings=eu+vn"
316 #if ENCODING_JP
317 "+jp"
318 #endif
319 #if ENCODING_JP_EXT
320 "+jp-ext"
321 #endif
322 #if ENCODING_KR
323 "+kr"
324 #endif
325 #if ENCODING_ZH
326 "+zh"
327 #endif
328 #if ENCODING_ZH_EXT
329 "+zh-ext"
330 #endif
331 ","
332 #if OFF_FOCUS_FADING
333 "fade,"
334 #endif
335 #if defined(ENABLE_TRANSPARENCY)
336 "transparent,"
337 "tint,"
338 #endif
339 #if HAVE_PIXBUF
340 "pixbuf,"
341 #endif
342 #if defined(USE_XIM)
343 "XIM,"
344 #endif
345 #if defined(NO_BACKSPACE_KEY)
346 "no_backspace,"
347 #endif
348 #if defined(NO_DELETE_KEY)
349 "no_delete,"
350 #endif
351 #if EIGHT_BIT_CONTROLS
352 "8bitctrls,"
353 #endif
354 #if defined(ENABLE_FRILLS)
355 "frills,"
356 #endif
357 #if defined(SELECTION_SCROLLING)
358 "selectionscrolling,"
359 #endif
360 #if MOUSE_WHEEL
361 "wheel,"
362 #endif
363 #if MOUSE_SLIP_WHEELING
364 "slipwheel,"
365 #endif
366 #if defined(SMART_RESIZE)
367 "smart-resize,"
368 #endif
369 #if defined(CURSOR_BLINK)
370 "cursorBlink,"
371 #endif
372 #if defined(POINTER_BLANK)
373 "pointerBlank,"
374 #endif
375 #if defined(NO_RESOURCES)
376 "NoResources,"
377 #endif
378 "scrollbars=plain"
379 #if defined(RXVT_SCROLLBAR)
380 "+rxvt"
381 #endif
382 #if defined(NEXT_SCROLLBAR)
383 "+NeXT"
384 #endif
385 #if defined(XTERM_SCROLLBAR)
386 "+xterm"
387 #endif
388 "\nUsage: "; /* Usage */
389
390 #define INDENT 28
391
392 const char rxvt_term::resval_undef [] = "<undef>";
393 const char rxvt_term::resval_on [] = "on";
394 const char rxvt_term::resval_off [] = "off";
395
396 /*{{{ usage: */
397 /*----------------------------------------------------------------------*/
398 void
399 rxvt_term::rxvt_usage (int type)
400 {
401 unsigned int i, col;
402
403 rxvt_log ("%s%s%s", releasestring, optionsstring, RESNAME);
404
405 switch (type)
406 {
407 case 0: /* brief listing */
408 rxvt_log (" [-help] [--help]\n");
409
410 for (col = 1, i = 0; i < ecb_array_length (optList); i++)
411 if (optList[i].desc != NULL)
412 {
413 int len = 0;
414
415 if (optList[i].arg)
416 len = strlen (optList[i].arg) + 1;
417
418 assert (optList[i].opt != NULL);
419 len += 4 + strlen (optList[i].opt) + (optList_isBool (i) ? 2 : 0);
420 col += len;
421
422 if (col > 79)
423 {
424 /* assume regular width */
425 rxvt_log ("\n");
426 col = 1 + len;
427 }
428
429 rxvt_log (" [-%s%s", (optList_isBool (i) ? "/+" : ""), optList[i].opt);
430
431 if (optList[i].arg)
432 rxvt_log (" %s]", optList[i].arg);
433 else
434 rxvt_log ("]");
435 }
436 break;
437
438 case 1: /* full command-line listing */
439 rxvt_log (" [options] [-e command args]\n\nwhere options include:\n");
440
441 for (i = 0; i < ecb_array_length (optList); i++)
442 if (optList[i].desc != NULL)
443 {
444 assert (optList[i].opt != NULL);
445 rxvt_log (" %s%s %-*s%s%s\n",
446 (optList_isBool (i) ? "-/+" : "-"), optList[i].opt,
447 (INDENT - strlen (optList[i].opt)
448 + (optList_isBool (i) ? 0 : 2)),
449 (optList[i].arg ? optList[i].arg : ""),
450 (optList_isBool (i) ? "turn on/off " : ""),
451 optList[i].desc);
452 }
453
454 #if ENABLE_PERL
455 rxvt_perl.init (this);
456 rxvt_perl.usage (this, 1);
457 #endif
458
459 rxvt_log ("\n --help to list long-options");
460 break;
461
462 case 2: /* full resource listing */
463 rxvt_log (" [options] [-e command args]\n\n"
464 "where resources (long-options) include:\n");
465
466 for (i = 0; i < ecb_array_length (optList); i++)
467 if (optList[i].kw != NULL)
468 rxvt_log (" %s: %*s%s\n",
469 optList[i].kw,
470 (INDENT + 2 - strlen (optList[i].kw)), "", /* XXX */
471 (optList_isBool (i) ? "boolean" : optList[i].arg));
472
473 #if ENABLE_PERL
474 rxvt_perl.init (this);
475 rxvt_perl.usage (this, 2);
476 #endif
477
478 rxvt_log ("\n -help to list options");
479 break;
480 }
481
482 rxvt_log ("\n\n");
483 rxvt_exit_failure ();
484 }
485
486 /*}}} */
487
488 /*{{{ get command-line options before getting resources */
489 const char **
490 rxvt_term::get_options (int argc, const char *const *argv)
491 {
492 int i, bad_option = 0;
493
494 for (i = 1; i < argc; i++)
495 {
496 unsigned int entry, longopt = 0;
497 const char *opt;
498 int flag;
499
500 opt = argv[i];
501
502 if (*opt == '-')
503 {
504 flag = 1;
505
506 if (*++opt == '-')
507 longopt = *opt++; /* long option */
508 }
509 else if (*opt == '+')
510 {
511 flag = 0;
512
513 if (*++opt == '+')
514 longopt = *opt++; /* long option */
515 }
516 else
517 {
518 bad_option = 1;
519 rxvt_warn ("\"%s\": malformed option.\n", opt);
520 continue;
521 }
522
523 if (!strcmp (opt, "help"))
524 rxvt_usage (longopt ? 2 : 1);
525
526 if (!strcmp (opt, "h"))
527 rxvt_usage (0);
528
529 /* feature: always try to match long-options */
530 for (entry = 0; entry < ecb_array_length (optList); entry++)
531 if ((optList[entry].kw && !strcmp (opt, optList[entry].kw))
532 || (!longopt
533 && optList[entry].opt && !strcmp (opt, optList[entry].opt)))
534 break;
535
536 if (entry < ecb_array_length (optList)
537 && !optList_isInfo (entry))
538 {
539 if (optList_isReverse (entry))
540 flag = !flag;
541
542 if (optList_isString (entry))
543 {
544 /*
545 * special cases are handled in init_resources () to allow
546 * X resources to set these values before we settle for
547 * default values
548 */
549
550 if (optList[entry].doff != -1)
551 {
552 if (flag && i + 1 == argc)
553 rxvt_fatal ("option '%s' requires an argument, aborting.\n", argv [i]);
554
555 rs[optList[entry].doff] = flag ? argv[++i] : resval_undef;
556 }
557 }
558 else
559 {
560 /* boolean value */
561 set_option (optList[entry].index, flag);
562
563 if (optList[entry].doff != -1)
564 rs[optList[entry].doff] = flag ? resval_on : resval_off;
565 }
566 }
567 #ifndef NO_RESOURCES
568 else if (!strcmp (opt, "xrm"))
569 {
570 if (i + 1 < argc)
571 XrmPutLineResource (&option_db, argv[++i]);
572 }
573 #endif
574 #ifdef KEYSYM_RESOURCE
575 else if (!strncmp (opt, "keysym.", sizeof ("keysym.") - 1))
576 {
577 if (i + 1 < argc)
578 {
579 char *res = rxvt_temp_buf<char> (strlen (opt) + strlen (argv[++i]) + 6);
580 sprintf (res, "*.%s: %s\n", opt, argv[i]);
581 XrmPutLineResource (&option_db, res);
582 }
583 }
584 #endif
585 else if (!strcmp (opt, "e"))
586 {
587 if (i + 1 < argc)
588 return (const char **)argv + i + 1;
589
590 rxvt_warn ("option '-e' requires an argument, aborting.\n");
591 bad_option = 1;
592 }
593 else
594 {
595 #if ENABLE_PERL
596 rxvt_perl.init (this);
597
598 if (int flags = rxvt_perl.parse_resource (this, opt, true, longopt, flag, argv [i + 1]))
599 {
600 if (flags & rxvt_perl.RESOURCE_ARG)
601 {
602 if (i + 1 == argc)
603 {
604 rxvt_warn ("option '%s' requires an argument.\n", argv [i]);
605 bad_option = 1;
606 }
607 else
608 ++i;
609 }
610 }
611 else
612 #endif
613 {
614 rxvt_warn ("\"%s\": unknown or malformed option.\n", opt);
615 bad_option = 1;
616 }
617 }
618 }
619
620 if (bad_option)
621 rxvt_usage (0);
622
623 return 0;
624 }
625
626 /*}}} */
627
628 #ifndef NO_RESOURCES
629 /*----------------------------------------------------------------------*/
630
631 # ifdef KEYSYM_RESOURCE
632 /*
633 * Define key from XrmEnumerateDatabase.
634 * quarks will be something like
635 * "rxvt" "keysym" "0xFF01"
636 * value will be a string
637 */
638 static int
639 rxvt_define_key (XrmDatabase *database ecb_unused,
640 XrmBindingList bindings ecb_unused,
641 XrmQuarkList quarks,
642 XrmRepresentation *type ecb_unused,
643 XrmValue *value,
644 XPointer closure ecb_unused)
645 {
646 int last;
647
648 for (last = 0; quarks[last] != NULLQUARK; last++) /* look for last quark in list */
649 ;
650
651 last--;
652 GET_R->parse_keysym (XrmQuarkToString (quarks[last]), (char *)value->addr);//D//TODO
653 return False;
654 }
655
656 /*
657 * look for something like this (XK_Delete)
658 * rxvt*keysym.0xFFFF: "\177"
659 */
660
661 struct keysym_vocabulary_t
662 {
663 const char *name;
664 unsigned short len;
665 unsigned short value;
666 };
667 static const keysym_vocabulary_t keysym_vocabulary[] =
668 {
669 { "ISOLevel3", 9, Level3Mask },
670 { "AppKeypad", 9, AppKeypadMask },
671 { "Control", 7, ControlMask },
672 { "NumLock", 7, NumLockMask },
673 { "Shift", 5, ShiftMask },
674 { "Meta", 4, MetaMask },
675 { "Lock", 4, LockMask },
676 { "Mod1", 4, Mod1Mask },
677 { "Mod2", 4, Mod2Mask },
678 { "Mod3", 4, Mod3Mask },
679 { "Mod4", 4, Mod4Mask },
680 { "Mod5", 4, Mod5Mask },
681 { "I", 1, Level3Mask },
682 { "K", 1, AppKeypadMask },
683 { "C", 1, ControlMask },
684 { "N", 1, NumLockMask },
685 { "S", 1, ShiftMask },
686 { "M", 1, MetaMask },
687 { "A", 1, MetaMask },
688 { "L", 1, LockMask },
689 { "1", 1, Mod1Mask },
690 { "2", 1, Mod2Mask },
691 { "3", 1, Mod3Mask },
692 { "4", 1, Mod4Mask },
693 { "5", 1, Mod5Mask },
694 };
695
696 int
697 rxvt_term::parse_keysym (const char *str, const char *arg)
698 {
699 int sym;
700 unsigned int state = 0;
701 const char *key = strrchr (str, '-');
702
703 if (!key)
704 key = str;
705 else
706 key++;
707
708 // string or key is empty
709 if (*arg == '\0' || *key == '\0')
710 return -1;
711
712 // parse modifiers
713 while (str < key)
714 {
715 unsigned int i;
716
717 for (i = 0; i < ecb_array_length (keysym_vocabulary); ++i)
718 {
719 if (strncmp (str, keysym_vocabulary [i].name, keysym_vocabulary [i].len) == 0)
720 {
721 state |= keysym_vocabulary[i].value;
722 str += keysym_vocabulary[i].len;
723 break;
724 }
725 }
726
727 if (i >= ecb_array_length (keysym_vocabulary))
728 return -1;
729
730 if (*str == '-')
731 ++str;
732 }
733
734 // convert keysym name to keysym number
735 if ((sym = XStringToKeysym (str)) == None)
736 {
737 // fallback on hexadecimal parsing
738 char *end;
739 sym = strtol (str, &end, 16);
740 if (*end)
741 return -1;
742 }
743
744 wchar_t *ws = rxvt_mbstowcs (arg);
745 if (!HOOK_INVOKE ((this, HOOK_REGISTER_COMMAND, DT_INT, sym, DT_INT, state, DT_WCS_LEN, ws, wcslen (ws), DT_END)))
746 keyboard->register_user_translation (sym, state, ws);
747 free (ws);
748 return 1;
749 }
750
751 # endif /* KEYSYM_RESOURCE */
752 #endif /* NO_RESOURCES */
753
754 static char *
755 get_res (XrmDatabase database, const char *program, const char *option)
756 {
757 char resource[512];
758 char *type;
759 XrmValue result;
760
761 snprintf (resource, sizeof (resource), "%s.%s", program, option);
762 XrmGetResource (database, resource, resource, &type, &result);
763
764 return result.addr;
765 }
766
767 const char *
768 rxvt_term::x_resource (const char *name)
769 {
770 XrmDatabase database = XrmGetDatabase (dpy);
771
772 const char *p = get_res (database, rs[Rs_name], name);
773 const char *p0 = get_res (database, "!INVALIDPROGRAMMENAMEDONTMATCH!", name);
774
775 if (p == NULL || (p0 && strcmp (p, p0) == 0))
776 {
777 p = get_res (database, RESCLASS, name);
778 #ifdef RESFALLBACK
779 if (p == NULL || (p0 && strcmp (p, p0) == 0))
780 p = get_res (database, RESFALLBACK, name);
781 #endif
782 }
783
784 if (p == NULL && p0)
785 p = p0;
786
787 return p;
788 }
789
790 void
791 rxvt_term::extract_resources ()
792 {
793 #ifndef NO_RESOURCES
794 XrmDatabase database = XrmGetDatabase (dpy);
795 XrmMergeDatabases (option_db, &database);
796 option_db = NULL;
797 /*
798 * Query resources for options that affect us
799 */
800 for (int entry = 0; entry < ecb_array_length (optList); entry++)
801 {
802 const char *kw = optList[entry].kw;
803
804 if (kw == NULL || rs[optList[entry].doff] != NULL)
805 continue; // previously set
806
807 const char *p = x_resource (kw);
808
809 if (p)
810 {
811 p = strdup (p);
812 allocated.push_back ((void *)p);
813 rs[optList[entry].doff] = p;
814
815 if (optList_isBool (entry))
816 {
817 bool s = parse_bool_resource (p);
818
819 if (optList_isReverse (entry))
820 s = !s;
821
822 set_option (optList[entry].index, s);
823 }
824 }
825 }
826 #endif /* NO_RESOURCES */
827 }
828
829 void
830 rxvt_term::extract_keysym_resources ()
831 {
832 #if !defined NO_RESOURCES && defined KEYSYM_RESOURCE
833 find_resources ("keysym", "Keysym", XrmEnumOneLevel, rxvt_define_key);
834 #endif
835 }
836
837 #if !defined NO_RESOURCES && defined KEYSYM_RESOURCE
838 void
839 rxvt_term::find_resources (const char *n_prefix, const char *c_prefix, int mode,
840 Bool (*proc)(XrmDatabase *, XrmBindingList, XrmQuarkList, XrmRepresentation *, XrmValue *, XPointer))
841 {
842 /*
843 * [R5 or later]: enumerate the resource database
844 */
845 XrmDatabase database = XrmGetDatabase (dpy);
846 XrmName name_prefix[3];
847 XrmClass class_prefix[3];
848
849 name_prefix[0] = XrmStringToName (rs[Rs_name]);
850 name_prefix[1] = XrmStringToName (n_prefix);
851 name_prefix[2] = NULLQUARK;
852 class_prefix[0] = XrmStringToName (RESCLASS);
853 class_prefix[1] = XrmStringToName (c_prefix);
854 class_prefix[2] = NULLQUARK;
855 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */
856 XrmEnumerateDatabase (database, name_prefix, class_prefix,
857 mode, proc, NULL);
858 # ifdef RESFALLBACK
859 name_prefix[0] = class_prefix[0] = XrmStringToName (RESFALLBACK);
860 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */
861 XrmEnumerateDatabase (database, name_prefix, class_prefix,
862 mode, proc, NULL);
863 # endif
864 }
865 #endif
866
867 /*----------------------- end-of-file (C source) -----------------------*/