1
/* $XTermId: os2main.c,v 1.247 2007/03/19 23:48:32 tom Exp $ */
1
/* $XTermId: os2main.c,v 1.249 2007/06/09 13:42:04 tom Exp $ */
3
3
/* removed all foreign stuff to get the code more clear (hv)
4
4
* and did some rewrite for the obscure OS/2 environment
128
128
static SIGNAL_T reapchild(int n);
129
129
static int spawnXTerm(XtermWidget /* xw */ );
130
static void resize_termcap(XTermWidget xw, char *oldtc, char *newtc);
130
static void resize_termcap(XtermWidget xw, char *newtc);
131
131
static void set_owner(char *device, uid_t uid, gid_t gid, mode_t mode);
133
133
static Bool added_utmp_entry = False;
192
192
#define CWERASE CONTROL('W')
195
#define TERMIO_STRUCT struct termio
196
198
* SYSV has the termio.c_cc[V] and ltchars; BSD has tchars and ltchars;
197
199
* SVR4 has only termio.c_cc, but it includes everything from ltchars.
1474
1476
if (why != ENOENT
1475
1477
&& save_ruid == 0) {
1476
1478
fprintf(stderr, "Cannot chown %s to %ld,%ld: %s\n",
1477
device, (long) uid, (long) gid, strerror(why));
1481
/* EMX can chmod files only, not devices */
1482
if (chmod(device, mode) < 0) {
1484
if (why != ENOENT) {
1486
if (stat(device, &sb) < 0) {
1487
fprintf(stderr, "Cannot chmod %s to %03o: %s\n",
1488
device, mode, strerror(why));
1491
"Cannot chmod %s to %03o currently %03o: %s\n",
1492
device, mode, (sb.st_mode & S_IFMT), strerror(why));
1479
device, (long) uid, (long) gid,
1499
1485
#define THE_PARENT 1
1538
1524
int Xsocket = ConnectionNumber(screen->display);
1540
1526
int ttyfd = -1;
1544
char newtc[TERMCAP_SIZE];
1545
1532
char *TermName = NULL;
1546
1533
char *ptr, *shname, buf[64];
1547
int i, no_dev_tty = False, envsize;
1534
int i, no_dev_tty = False;
1548
1535
char *dev_tty_name = (char *) 0;
1549
1536
TTYSIZE_STRUCT ts;
1550
1537
int pgrp = getpid();
1656
1643
* entry is not found.
1658
1645
ok_termcap = True;
1659
if (!get_termcap(TermName = resource.term_name, ptr)) {
1646
if (!get_termcap(TermName = resource.term_name, newtc)) {
1660
1647
char *last = NULL;
1661
1648
TermName = *envnew;
1662
1649
ok_termcap = False;
1663
1650
while (*envnew != NULL) {
1664
1651
if ((last == NULL || strcmp(last, *envnew))
1665
&& get_termcap(*envnew, ptr)) {
1652
&& get_termcap(*envnew, newtc)) {
1666
1653
TermName = *envnew;
1667
1654
ok_termcap = True;
1771
1758
if (ioctl(ttyfd, TIOCCONS, (char *) &on) == -1)
1772
fprintf(stderr, "%s: cannot open console\n", xterm_name);
1759
fprintf(stderr, "%s: cannot open console: %s\n",
1760
xterm_name, strerror(errno));
1781
1769
signal(SIGQUIT, SIG_DFL);
1782
1770
signal(SIGTERM, SIG_DFL);
1784
/* copy the environment before Setenv'ing */
1785
for (i = 0; gblenvp[i] != NULL; i++) ;
1787
/* compute number of xtermSetenv() calls below */
1788
envsize = 1; /* (NULL terminating entry) */
1789
envsize += 5; /* TERM, WINDOWID, DISPLAY, _SHELL, _VERSION */
1790
envsize += 2; /* COLUMNS, LINES */
1792
envnew = TypeCallocN(char *, (unsigned) i + envsize);
1793
memmove((char *) envnew, (char *) gblenvp, i * sizeof(char *));
1795
xtermSetenv("TERM=", TermName);
1772
xtermCopyEnv(gblenvp);
1774
xtermSetenv("TERM", TermName);
1799
1778
sprintf(buf, "%lu",
1800
1779
((unsigned long) XtWindow(SHELL_OF(CURRENT_EMU()))));
1801
xtermSetenv("WINDOWID=", buf);
1780
xtermSetenv("WINDOWID", buf);
1803
1782
/* put the display into the environment of the shell */
1804
xtermSetenv("DISPLAY=", XDisplayString(screen->display));
1783
xtermSetenv("DISPLAY", XDisplayString(screen->display));
1806
xtermSetenv("XTERM_VERSION=", xtermVersion());
1785
xtermSetenv("XTERM_VERSION", xtermVersion());
1808
1787
signal(SIGTERM, SIG_DFL);
1835
1814
sprintf(numbuf, "%d", MaxCols(screen));
1836
xtermSetenv("COLUMNS=", numbuf);
1815
xtermSetenv("COLUMNS", numbuf);
1837
1816
sprintf(numbuf, "%d", MaxRows(screen));
1838
xtermSetenv("LINES=", numbuf);
1817
xtermSetenv("LINES", numbuf);
1840
/* reconstruct dead environ variable */
1843
1821
/* need to reset after all the ioctl bashing we did above */
1844
1822
ptioctl(0, TIOCSWINSZ, (char *) &ts);
1862
1840
* to command that the user gave anyway.
1864
1842
if (command_to_exec_with_luit) {
1865
xtermSetenv("XTERM_SHELL=",
1843
xtermSetenv("XTERM_SHELL",
1866
1844
xtermFindShell(*command_to_exec_with_luit, False));
1867
1845
TRACE(("spawning command \"%s\"\n", *command_to_exec_with_luit));
1868
1846
execvp(*command_to_exec_with_luit, command_to_exec_with_luit);
1876
1854
if (command_to_exec) {
1877
xtermSetenv("XTERM_SHELL=",
1855
xtermSetenv("XTERM_SHELL",
1878
1856
xtermFindShell(*command_to_exec, False));
1879
1857
TRACE(("spawning command \"%s\"\n", *command_to_exec));
1880
1858
execvpe(*command_to_exec, command_to_exec, gblenvp);
1887
1865
/* use a layered mechanism to find a shell */
1888
ptr = getenv("X11SHELL");
1890
ptr = getenv("SHELL");
1892
ptr = getenv("OS2_SHELL");
1866
ptr = x_getenv("X11SHELL");
1868
ptr = x_getenv("SHELL");
1870
ptr = x_getenv("OS2_SHELL");
1894
1872
ptr = "SORRY_NO_SHELL_FOUND";
1895
xtermSetenv("XTERM_SHELL=", ptr);
1873
xtermSetenv("XTERM_SHELL", ptr);
1897
1875
shname = x_basename(ptr);
1898
1876
if (command_to_exec) {
2033
2011
TRACE(("parse_tty_modes\n"));
2035
2015
while (*s && isascii(CharOf(*s)) && isspace(CharOf(*s)))
2020
for (len = 0; isalnum(CharOf(s[len])); ++len) ;
2040
2021
for (mp = modelist; mp->name; mp++) {
2041
if (strncmp(s, mp->name, mp->len) == 0)
2023
&& strncmp(s, mp->name, mp->len) == 0)