ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/init.C
(Generate patch)

Comparing rxvt-unicode/src/init.C (file contents):
Revision 1.306 by sf-exg, Tue Dec 6 11:39:30 2011 UTC vs.
Revision 1.320 by sf-exg, Thu Jan 19 15:08:55 2012 UTC

38#include "init.h" 38#include "init.h"
39#include "keyboard.h" 39#include "keyboard.h"
40 40
41#include <limits> 41#include <limits>
42 42
43#include <csignal> 43#include <signal.h>
44 44
45#include <fcntl.h> 45#include <fcntl.h>
46 46
47#ifdef HAVE_XSETLOCALE 47#ifdef HAVE_XSETLOCALE
48# define X_LOCALE 48# define X_LOCALE
49# include <X11/Xlocale.h> 49# include <X11/Xlocale.h>
50#else 50#else
51# ifdef HAVE_SETLOCALE
52# include <clocale> 51# include <locale.h>
53# endif
54#endif 52#endif
55 53
56#ifdef HAVE_NL_LANGINFO 54#ifdef HAVE_NL_LANGINFO
57# include <langinfo.h> 55# include <langinfo.h>
58#endif 56#endif
567 565
568/*----------------------------------------------------------------------*/ 566/*----------------------------------------------------------------------*/
569const char ** 567const char **
570rxvt_term::init_resources (int argc, const char *const *argv) 568rxvt_term::init_resources (int argc, const char *const *argv)
571{ 569{
572 int i, r_argc; 570 int i;
573 const char **cmd_argv; 571 const char **cmd_argv;
574
575 /*
576 * Look for -e option. Find => split and make cmd_argv[] of command args
577 */
578 for (r_argc = 0; r_argc < argc; r_argc++)
579 if (!strcmp (argv[r_argc], "-e"))
580 break;
581
582 if (r_argc == argc)
583 cmd_argv = NULL;
584 else if (!argv[r_argc + 1])
585 rxvt_fatal ("option '-e' requires an argument, aborting.\n");
586 else
587 cmd_argv = (const char **)argv + r_argc + 1;
588 572
589 rs[Rs_name] = rxvt_basename (argv[0]); 573 rs[Rs_name] = rxvt_basename (argv[0]);
590 574
591 /* 575 /*
592 * Open display, get options/resources and create the window 576 * Open display, get options/resources and create the window
593 */ 577 */
594 578
595 if ((rs[Rs_display_name] = getenv ("DISPLAY")) == NULL) 579 if ((rs[Rs_display_name] = getenv ("DISPLAY")) == NULL)
596 rs[Rs_display_name] = ":0"; 580 rs[Rs_display_name] = ":0";
597 581
598 get_options (r_argc, argv); 582 cmd_argv = get_options (argc, argv);
599 583
600 if (!(display = displays.get (rs[Rs_display_name]))) 584 if (!(display = displays.get (rs[Rs_display_name])))
601 rxvt_fatal ("can't open display %s, aborting.\n", rs[Rs_display_name]); 585 rxvt_fatal ("can't open display %s, aborting.\n", rs[Rs_display_name]);
602 586
603 // using a local pointer decreases code size a lot 587 // using a local pointer decreases code size a lot
747 return cmd_argv; 731 return cmd_argv;
748} 732}
749 733
750/*----------------------------------------------------------------------*/ 734/*----------------------------------------------------------------------*/
751void 735void
736rxvt_term::init (stringvec *argv, stringvec *envv)
737{
738 argv->push_back (0);
739 envv->push_back (0);
740
741 this->argv = argv;
742 this->envv = envv;
743
744 init2 (argv->size () - 1, argv->begin ());
745}
746
747void
748rxvt_term::init (int argc, const char *const *argv, const char *const *envv)
749{
750#if ENABLE_PERL
751 // perl might want to access the stringvecs later, so we need to copy them
752 stringvec *args = new stringvec;
753 for (int i = 0; i < argc; i++)
754 args->push_back (strdup (argv [i]));
755
756 stringvec *envs = new stringvec;
757 for (const char *const *var = envv; *var; var++)
758 envs->push_back (strdup (*var));
759
760 init (args, envs);
761#else
762 init2 (argc, argv);
763#endif
764}
765
766void
752rxvt_term::init (int argc, const char *const *argv) 767rxvt_term::init2 (int argc, const char *const *argv)
753{ 768{
754 SET_R (this); 769 SET_R (this);
755 set_locale (""); 770 set_locale ("");
756 set_environ (envv); // a few things in X do not call setlocale :( 771 set_environ (envv); // a few things in X do not call setlocale :(
757 772
824 } 839 }
825#endif 840#endif
826 841
827#ifdef BG_IMAGE_FROM_FILE 842#ifdef BG_IMAGE_FROM_FILE
828 if (rs[Rs_backgroundPixmap]) 843 if (rs[Rs_backgroundPixmap])
829 {
830 if (bg_set_file (rs[Rs_backgroundPixmap])) 844 if (bg_set_file (rs[Rs_backgroundPixmap]))
831 if (!bg_window_position_sensitive ()) 845 if (!bg_window_position_sensitive ())
832 update_background (); 846 update_background ();
833 }
834#endif 847#endif
835 } 848 }
836#endif 849#endif
837 850
838#if ENABLE_PERL 851#if ENABLE_PERL
839 rootwin_ev.start (display, display->root); 852 rootwin_ev.start (display, display->root);
840#endif 853#endif
841 854
842 set_colorfgbg (); 855 init_done = 1;
843 856
844 init_command (cmd_argv); 857 init_command (cmd_argv);
845 858
846 if (pty->pty >= 0) 859 if (pty->pty >= 0)
847 pty_ev.start (pty->pty, ev::READ); 860 pty_ev.start (pty->pty, ev::READ);
891/*----------------------------------------------------------------------*/ 904/*----------------------------------------------------------------------*/
892void 905void
893rxvt_term::init_env () 906rxvt_term::init_env ()
894{ 907{
895 char *val; 908 char *val;
909 char *env_display;
910 char *env_windowid;
911 char *env_colorfgbg;
912 char *env_term;
896 913
897#ifdef DISPLAY_IS_IP 914#ifdef DISPLAY_IS_IP
898 /* Fixup display_name for export over pty to any interested terminal 915 /* Fixup display_name for export over pty to any interested terminal
899 * clients via "ESC[7n" (e.g. shells). Note we use the pure IP number 916 * clients via "ESC[7n" (e.g. shells). Note we use the pure IP number
900 * (for the first non-loopback interface) that we get from 917 * (for the first non-loopback interface) that we get from
917 934
918 env_display = (char *)rxvt_malloc (strlen (val) + 9); 935 env_display = (char *)rxvt_malloc (strlen (val) + 9);
919 936
920 sprintf (env_display, "DISPLAY=%s", val); 937 sprintf (env_display, "DISPLAY=%s", val);
921 938
939 env_windowid = (char *)rxvt_malloc (21);
922 sprintf (env_windowid, "WINDOWID=%lu", (unsigned long)parent); 940 sprintf (env_windowid, "WINDOWID=%lu", (unsigned long)parent);
923 941
924 /* add entries to the environment: 942 /* add entries to the environment:
925 * @ DISPLAY: in case we started with -display 943 * @ DISPLAY: in case we started with -display
926 * @ WINDOWID: X window id number of the window 944 * @ WINDOWID: X window id number of the window
930 * @ COLORFGBG: fg;bg color codes 948 * @ COLORFGBG: fg;bg color codes
931 */ 949 */
932 putenv (env_display); 950 putenv (env_display);
933 putenv (env_windowid); 951 putenv (env_windowid);
934 952
935 if (env_colorfgbg) 953 env_colorfgbg = get_colorfgbg ();
936 putenv (env_colorfgbg); 954 putenv (env_colorfgbg);
937 955
938#ifdef RXVT_TERMINFO 956#ifdef RXVT_TERMINFO
939 putenv ("TERMINFO=" RXVT_TERMINFO); 957 putenv ("TERMINFO=" RXVT_TERMINFO);
940#endif 958#endif
941 959
960 unsetenv ("TERMCAP"); /* terminfo should be okay */ 978 unsetenv ("TERMCAP"); /* terminfo should be okay */
961#endif /* HAVE_UNSETENV */ 979#endif /* HAVE_UNSETENV */
962} 980}
963 981
964/*----------------------------------------------------------------------*/ 982/*----------------------------------------------------------------------*/
965/*
966 * This is more or less stolen straight from XFree86 xterm.
967 * This should support all European type languages.
968 */
969void 983void
970rxvt_term::set_locale (const char *locale) 984rxvt_term::set_locale (const char *locale)
971{ 985{
972 set_environ (envv); 986 set_environ (envv);
973 987
974#if HAVE_XSETLOCALE || HAVE_SETLOCALE
975 free (this->locale); 988 free (this->locale);
976 this->locale = setlocale (LC_CTYPE, locale); 989 this->locale = setlocale (LC_CTYPE, locale);
977 990
978 if (!this->locale) 991 if (!this->locale)
979 { 992 {
990 1003
991 1004
992 this->locale = strdup (this->locale); 1005 this->locale = strdup (this->locale);
993 SET_LOCALE (this->locale); 1006 SET_LOCALE (this->locale);
994 mbstate.reset (); 1007 mbstate.reset ();
995#endif
996 1008
997#if HAVE_NL_LANGINFO 1009#if HAVE_NL_LANGINFO
998 char *codeset = strdup (nl_langinfo (CODESET)); 1010 char *codeset = nl_langinfo (CODESET);
999 // /^UTF.?8/i 1011 // /^UTF.?8/i
1000 enc_utf8 = (codeset[0] == 'U' || codeset[0] == 'u') 1012 enc_utf8 = (codeset[0] == 'U' || codeset[0] == 'u')
1001 && (codeset[1] == 'T' || codeset[1] == 't') 1013 && (codeset[1] == 'T' || codeset[1] == 't')
1002 && (codeset[2] == 'F' || codeset[2] == 'f') 1014 && (codeset[2] == 'F' || codeset[2] == 'f')
1003 && (codeset[3] == '8' || codeset[4] == '8'); 1015 && (codeset[3] == '8' || codeset[4] == '8');
1004 free (codeset);
1005#else 1016#else
1006 enc_utf8 = 0; 1017 enc_utf8 = 0;
1007#endif 1018#endif
1008} 1019}
1009 1020
1012{ 1023{
1013 set_environ (envv); 1024 set_environ (envv);
1014 1025
1015#ifdef USE_XIM 1026#ifdef USE_XIM
1016 if (!locale) 1027 if (!locale)
1017 rxvt_warn ("setting locale failed, working without locale support.\n"); 1028 rxvt_warn ("setting locale failed, continuing without locale support.\n");
1018 else 1029 else
1019 { 1030 {
1020 set_string_property (xa[XA_WM_LOCALE_NAME], locale); 1031 set_string_property (xa[XA_WM_LOCALE_NAME], locale);
1021 1032
1022 if (!XSupportsLocale ()) 1033 if (!XSupportsLocale ())
1023 { 1034 {
1024 rxvt_warn ("the locale is not supported by Xlib, working without locale support.\n"); 1035 rxvt_warn ("the locale is not supported by Xlib, continuing without locale support.\n");
1025 return; 1036 return;
1026 } 1037 }
1027 1038
1028 im_ev.start (display); 1039 im_ev.start (display);
1029 1040
1178/*----------------------------------------------------------------------*/ 1189/*----------------------------------------------------------------------*/
1179/* color aliases, fg/bg bright-bold */ 1190/* color aliases, fg/bg bright-bold */
1180void 1191void
1181rxvt_term::color_aliases (int idx) 1192rxvt_term::color_aliases (int idx)
1182{ 1193{
1183 if (rs[Rs_color + idx] && isdigit (* (rs[Rs_color + idx]))) 1194 if (rs[Rs_color + idx] && isdigit (*rs[Rs_color + idx]))
1184 { 1195 {
1185 int i = atoi (rs[Rs_color + idx]); 1196 int i = atoi (rs[Rs_color + idx]);
1186 1197
1187 if (i >= 8 && i <= 15) 1198 if (i >= 8 && i <= 15)
1188 /* bright colors */ 1199 /* bright colors */
1464 CWColormap | CWBackPixel | CWBorderPixel | CWOverrideRedirect, 1475 CWColormap | CWBackPixel | CWBorderPixel | CWOverrideRedirect,
1465 &attributes); 1476 &attributes);
1466 1477
1467 this->parent = top; 1478 this->parent = top;
1468 1479
1469 old_width = szHint.width;
1470 old_height = szHint.height;
1471
1472 set_title (rs [Rs_title]); 1480 set_title (rs [Rs_title]);
1473 set_icon_name (rs [Rs_iconName]); 1481 set_icon_name (rs [Rs_iconName]);
1474 1482
1475 classHint.res_name = (char *)rs[Rs_name]; 1483 classHint.res_name = (char *)rs[Rs_name];
1476 classHint.res_class = (char *)RESCLASS; 1484 classHint.res_class = (char *)RESCLASS;
1538 TermWin_cursor = XCreateFontCursor (dpy, XC_xterm); 1546 TermWin_cursor = XCreateFontCursor (dpy, XC_xterm);
1539 1547
1540 /* the vt window */ 1548 /* the vt window */
1541 vt = XCreateSimpleWindow (dpy, top, 1549 vt = XCreateSimpleWindow (dpy, top,
1542 window_vt_x, window_vt_y, 1550 window_vt_x, window_vt_y,
1543 width, height, 1551 vt_width, vt_height,
1544 0, 1552 0,
1545 pix_colors_focused[Color_fg], 1553 pix_colors_focused[Color_fg],
1546 pix_colors_focused[Color_bg]); 1554 pix_colors_focused[Color_bg]);
1547 1555
1548 attributes.bit_gravity = NorthWestGravity; 1556 attributes.bit_gravity = NorthWestGravity;
1597 if (pty->pty >= 0) 1605 if (pty->pty >= 0)
1598 { 1606 {
1599 if (getfd_hook) 1607 if (getfd_hook)
1600 pty->pty = (*getfd_hook) (pty->pty); 1608 pty->pty = (*getfd_hook) (pty->pty);
1601 1609
1602 if (pty->pty < 0 || fcntl (pty->pty, F_SETFL, O_NONBLOCK)) 1610 if (pty->pty < 0)
1603 rxvt_fatal ("unusable pty-fd filehandle, aborting.\n"); 1611 rxvt_fatal ("unusable pty-fd filehandle, aborting.\n");
1604 } 1612 }
1605 } 1613 }
1606 else 1614 else
1607#endif 1615#endif
1608 if (!pty->get ()) 1616 if (!pty->get ())
1609 rxvt_fatal ("can't initialize pseudo-tty, aborting.\n"); 1617 rxvt_fatal ("can't initialize pseudo-tty, aborting.\n");
1618
1619 fcntl (pty->pty, F_SETFL, O_NONBLOCK);
1610 1620
1611 struct termios tio = def_tio; 1621 struct termios tio = def_tio;
1612 1622
1613#ifndef NO_BACKSPACE_KEY 1623#ifndef NO_BACKSPACE_KEY
1614 if (rs[Rs_backspace_key][0] && !rs[Rs_backspace_key][1]) 1624 if (rs[Rs_backspace_key][0] && !rs[Rs_backspace_key][1])
1664 1674
1665 _exit (EXIT_FAILURE); 1675 _exit (EXIT_FAILURE);
1666 1676
1667 default: 1677 default:
1668 if (!option (Opt_utmpInhibit)) 1678 if (!option (Opt_utmpInhibit))
1679 {
1680#ifdef LOG_ONLY_ON_LOGIN
1681 bool login_shell = option (Opt_loginShell);
1682#else
1683 bool login_shell = true;
1684#endif
1669 pty->login (cmd_pid, option (Opt_loginShell), rs[Rs_display_name]); 1685 pty->login (cmd_pid, login_shell, rs[Rs_display_name]);
1686 }
1670 1687
1671 pty->close_tty (); 1688 pty->close_tty ();
1672 1689
1673 child_ev.start (cmd_pid); 1690 child_ev.start (cmd_pid);
1674 1691
1699#elif defined (SRIOCSREDIR) 1716#elif defined (SRIOCSREDIR)
1700 int fd; 1717 int fd;
1701 1718
1702 fd = open (CONSOLE, O_WRONLY, 0); 1719 fd = open (CONSOLE, O_WRONLY, 0);
1703 if (fd >= 0) 1720 if (fd >= 0)
1704 if (ioctl (fd, SRIOCSREDIR, NULL) < 0) 1721 {
1722 ioctl (fd, SRIOCSREDIR, STDIN_FILENO);
1705 close (fd); 1723 close (fd);
1724 }
1706#endif /* SRIOCSREDIR */ 1725#endif /* SRIOCSREDIR */
1707 } 1726 }
1708 1727
1709 /* reset signals and spin off the command interpreter */ 1728 /* reset signals and spin off the command interpreter */
1710 signal (SIGINT, SIG_DFL); 1729 signal (SIGINT, SIG_DFL);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines