1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: xdefaults.C |
2 | * File: xdefaults.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> |
6 | * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> |
… | |
… | |
21 | * You should have received a copy of the GNU General Public License |
21 | * You should have received a copy of the GNU General Public License |
22 | * along with this program; if not, write to the Free Software |
22 | * along with this program; if not, write to the Free Software |
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
24 | *----------------------------------------------------------------------*/ |
24 | *----------------------------------------------------------------------*/ |
25 | |
25 | |
26 | #include "../config.h" /* NECESSARY */ |
26 | #include "../config.h" |
27 | #include "rxvt.h" /* NECESSARY */ |
27 | #include "rxvt.h" |
28 | #include "version.h" |
28 | #include "version.h" |
29 | |
29 | |
30 | #ifdef KEYSYM_RESOURCE |
30 | #ifdef KEYSYM_RESOURCE |
31 | #include "keyboard.h" |
31 | # include "keyboard.h" |
32 | #endif |
32 | #endif |
33 | |
33 | |
34 | /* place holders used for parsing command-line options */ |
34 | /* place holders used for parsing command-line options */ |
35 | #define Optflag_Reverse 0x40000000UL |
35 | #define Optflag_Reverse 0x40000000UL |
36 | #define Optflag_Boolean 0x80000000UL |
36 | #define Optflag_Boolean 0x80000000UL |
37 | #define Optflag_mask 0x3fffffffUL |
37 | #define Optflag_mask 0x3fffffffUL |
38 | |
38 | |
39 | /*{{{ monolithic option/resource structure: */ |
39 | /* monolithic option/resource structure: */ |
40 | /* |
40 | /* |
41 | * `string' options MUST have a usage argument |
41 | * `string' options MUST have a usage argument |
42 | * `switch' and `boolean' options have no argument |
42 | * `switch' and `boolean' options have no argument |
43 | * if there's no desc (ription), it won't appear in rxvt_usage () |
43 | * if there's no desc (ription), it won't appear in rxvt_usage () |
44 | */ |
44 | */ |
… | |
… | |
266 | #undef INFO |
266 | #undef INFO |
267 | #undef STRG |
267 | #undef STRG |
268 | #undef RSTRG |
268 | #undef RSTRG |
269 | #undef SWCH |
269 | #undef SWCH |
270 | #undef BOOL |
270 | #undef BOOL |
271 | /*}}} */ |
|
|
272 | |
271 | |
273 | static const char releasestring[] = "rxvt-unicode (" RXVTNAME ") v" VERSION " - released: " DATE "\n"; |
272 | static const char releasestring[] = "rxvt-unicode (" RXVTNAME ") v" VERSION " - released: " DATE "\n"; |
274 | static const char optionsstring[] = "options: " |
273 | static const char optionsstring[] = "options: " |
275 | #if ENABLE_PERL |
274 | #if ENABLE_PERL |
276 | "perl," |
275 | "perl," |
… | |
… | |
386 | #endif |
385 | #endif |
387 | "\nUsage: "; /* Usage */ |
386 | "\nUsage: "; /* Usage */ |
388 | |
387 | |
389 | #define INDENT 18 |
388 | #define INDENT 18 |
390 | |
389 | |
|
|
390 | const char rxvt_term::resval_undef [] = "<undef>"; |
|
|
391 | const char rxvt_term::resval_on [] = "on"; |
|
|
392 | const char rxvt_term::resval_off [] = "off"; |
|
|
393 | |
391 | /*{{{ usage: */ |
394 | /*{{{ usage: */ |
392 | /*----------------------------------------------------------------------*/ |
395 | /*----------------------------------------------------------------------*/ |
393 | static void |
396 | static void |
394 | rxvt_usage (int type) |
397 | rxvt_usage (int type) |
395 | { |
398 | { |
… | |
… | |
403 | rxvt_log (" [-help] [--help]\n"); |
406 | rxvt_log (" [-help] [--help]\n"); |
404 | |
407 | |
405 | for (col = 1, i = 0; i < optList_size; i++) |
408 | for (col = 1, i = 0; i < optList_size; i++) |
406 | if (optList[i].desc != NULL) |
409 | if (optList[i].desc != NULL) |
407 | { |
410 | { |
408 | int len = 0; |
411 | int len = 0; |
409 | |
412 | |
410 | if (!optList_isBool (i)) |
413 | if (!optList_isBool (i)) |
411 | { |
414 | { |
412 | len = optList_strlen (i); |
415 | len = optList_strlen (i); |
413 | if (len > 0) |
416 | if (len > 0) |
… | |
… | |
480 | |
483 | |
481 | /*{{{ get command-line options before getting resources */ |
484 | /*{{{ get command-line options before getting resources */ |
482 | void |
485 | void |
483 | rxvt_term::get_options (int argc, const char *const *argv) |
486 | rxvt_term::get_options (int argc, const char *const *argv) |
484 | { |
487 | { |
485 | int i, bad_option = 0; |
488 | int i, bad_option = 0; |
486 | static const char On[3] = "ON", Off[4] = "OFF"; |
|
|
487 | |
489 | |
488 | for (i = 1; i < argc; i++) |
490 | for (i = 1; i < argc; i++) |
489 | { |
491 | { |
490 | unsigned int entry, longopt = 0; |
492 | unsigned int entry, longopt = 0; |
491 | const char *flag, *opt; |
493 | const char *flag, *opt; |
492 | |
494 | |
493 | opt = argv[i]; |
495 | opt = argv[i]; |
494 | |
496 | |
495 | if (*opt == '-') |
497 | if (*opt == '-') |
496 | { |
498 | { |
497 | flag = On; |
499 | flag = resval_on; |
|
|
500 | |
498 | if (*++opt == '-') |
501 | if (*++opt == '-') |
499 | longopt = *opt++; /* long option */ |
502 | longopt = *opt++; /* long option */ |
500 | } |
503 | } |
501 | else if (*opt == '+') |
504 | else if (*opt == '+') |
502 | { |
505 | { |
503 | flag = Off; |
506 | flag = resval_off; |
|
|
507 | |
504 | if (*++opt == '+') |
508 | if (*++opt == '+') |
505 | longopt = *opt++; /* long option */ |
509 | longopt = *opt++; /* long option */ |
506 | } |
510 | } |
507 | else |
511 | else |
508 | { |
512 | { |
… | |
… | |
511 | continue; |
515 | continue; |
512 | } |
516 | } |
513 | |
517 | |
514 | if (!strcmp (opt, "help")) |
518 | if (!strcmp (opt, "help")) |
515 | rxvt_usage (longopt ? 2 : 1); |
519 | rxvt_usage (longopt ? 2 : 1); |
|
|
520 | |
516 | if (!strcmp (opt, "h")) |
521 | if (!strcmp (opt, "h")) |
517 | rxvt_usage (0); |
522 | rxvt_usage (0); |
518 | |
523 | |
519 | /* feature: always try to match long-options */ |
524 | /* feature: always try to match long-options */ |
520 | for (entry = 0; entry < optList_size; entry++) |
525 | for (entry = 0; entry < optList_size; entry++) |
… | |
… | |
524 | break; |
529 | break; |
525 | |
530 | |
526 | if (entry < optList_size) |
531 | if (entry < optList_size) |
527 | { |
532 | { |
528 | if (optList_isReverse (entry)) |
533 | if (optList_isReverse (entry)) |
529 | flag = flag == On ? Off : On; |
534 | flag = flag == resval_on ? resval_off : resval_on; |
530 | |
535 | |
531 | if (optList_strlen (entry)) |
536 | if (optList_strlen (entry)) |
532 | { |
537 | { |
533 | /* |
538 | /* |
534 | * special cases are handled in main.c:main () to allow |
539 | * special cases are handled in main.c:main () to allow |
535 | * X resources to set these values before we settle for |
540 | * X resources to set these values before we settle for |
536 | * default values |
541 | * default values |
537 | */ |
542 | */ |
538 | |
543 | |
539 | if (optList[entry].doff != -1) |
544 | if (optList[entry].doff != -1) |
|
|
545 | { |
|
|
546 | if (flag == resval_on && !argv [i+1]) |
|
|
547 | rxvt_fatal ("option '%s' needs an argument, aborting.\n", argv [i]); |
|
|
548 | |
540 | rs[optList[entry].doff] = flag == On && argv[i+1] |
549 | rs[optList[entry].doff] = flag == resval_on ? argv[++i] : resval_undef; |
541 | ? argv[++i] : 0; |
550 | } |
542 | } |
551 | } |
543 | else |
552 | else |
544 | { /* boolean value */ |
553 | { /* boolean value */ |
545 | set_option (optList[entry].flag & Optflag_mask, flag == On); |
554 | set_option (optList[entry].flag & Optflag_mask, flag == resval_on); |
546 | |
555 | |
547 | if (optList[entry].doff != -1) |
556 | if (optList[entry].doff != -1) |
548 | rs[optList[entry].doff] = flag; |
557 | rs[optList[entry].doff] = flag; |
549 | } |
558 | } |
550 | } |
559 | } |
… | |
… | |
765 | } |
774 | } |
766 | |
775 | |
767 | const char * |
776 | const char * |
768 | rxvt_term::x_resource (const char *name) |
777 | rxvt_term::x_resource (const char *name) |
769 | { |
778 | { |
770 | XrmDatabase database = XrmGetDatabase (xdisp); |
779 | XrmDatabase database = XrmGetDatabase (dpy); |
771 | |
780 | |
772 | const char *p = get_res (database, rs[Rs_name], name); |
781 | const char *p = get_res (database, rs[Rs_name], name); |
773 | const char *p0 = get_res (database, "!INVALIDPROGRAMMENAMEDONTMATCH!", name); |
782 | const char *p0 = get_res (database, "!INVALIDPROGRAMMENAMEDONTMATCH!", name); |
774 | |
783 | |
775 | if (p == NULL || (p0 && strcmp (p, p0) == 0)) |
784 | if (p == NULL || (p0 && strcmp (p, p0) == 0)) |
… | |
… | |
827 | |
836 | |
828 | /* |
837 | /* |
829 | * [R5 or later]: enumerate the resource database |
838 | * [R5 or later]: enumerate the resource database |
830 | */ |
839 | */ |
831 | # ifdef KEYSYM_RESOURCE |
840 | # ifdef KEYSYM_RESOURCE |
832 | XrmDatabase database = XrmGetDatabase (xdisp); |
841 | XrmDatabase database = XrmGetDatabase (dpy); |
833 | XrmName name_prefix[3]; |
842 | XrmName name_prefix[3]; |
834 | XrmClass class_prefix[3]; |
843 | XrmClass class_prefix[3]; |
835 | |
844 | |
836 | name_prefix[0] = XrmStringToName (rs[Rs_name]); |
845 | name_prefix[0] = XrmStringToName (rs[Rs_name]); |
837 | name_prefix[1] = XrmStringToName ("keysym"); |
846 | name_prefix[1] = XrmStringToName ("keysym"); |