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 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244
|
/*
* screen.c
*
* Written By Matthew Green, based on portions of window.c
* by Michael Sandrof.
*
* Copyright(c) 1993, 1994.
*
* See the COPYRIGHT file, or do a HELP IRCII COPYRIGHT
*/
#ifndef lint
static char rcsid[] = "@(#)$Id: screen.c,v 1.70 1997/12/07 02:30:54 mrg Exp $";
#endif /* lint */
#include "irc.h"
#ifdef HAVE_SYS_UN_H
# include <sys/un.h>
#endif /* HAVE_SYS_UN_H */
#include "screen.h"
#include "menu.h"
#include "window.h"
#include "output.h"
#include "vars.h"
#include "server.h"
#include "list.h"
#include "ircterm.h"
#include "names.h"
#include "ircaux.h"
#include "input.h"
#include "log.h"
#include "hook.h"
#include "dcc.h"
#include "translat.h"
#include "exec.h"
#include "newio.h"
#ifdef lines
#undef lines
#undef columns
#endif /* lines */
Window *to_window;
Screen *current_screen;
Screen *main_screen;
Screen *last_input_screen;
extern int in_help; /* Used to suppress holding of help text */
extern char *redirect_nick;
/* Our list of screens */
Screen *screen_list = NULL;
static void display_lastlog_lines _((int, int, Window *));
static Screen * create_new_screen _((void));
static char ** split_up_line _((char *));
static void scrollback_backwards_lines _((int));
static void scrollback_forwards_lines _((int));
static char display_highlight _((int));
static char display_bold _((int));
static void display_colors _((int, int));
static void add_to_window _((Window *, char *));
static u_int create_refnum _((void));
static char *next_line_back _((Window *, int));
/*
* create_new_screen creates a new screen structure. with the help of
* this structure we maintain ircII windows that cross screen window
* boundaries.
*/
static Screen *
create_new_screen()
{
Screen *new = NULL,
**list;
static int refnumber = 0;
for (list = &screen_list; *list; list = &((*list)->next))
{
if (!(*list)->alive)
{
new = *list;
break;
}
}
if (!new)
{
new = (Screen *) malloc(sizeof(Screen));
new->screennum = ++refnumber;
new->next = screen_list;
if (screen_list)
screen_list->prev = new;
screen_list = new;
}
new->last_window_refnum = 1;
new->window_list = NULL;
new->window_list_end = NULL;
new->cursor_window = NULL;
new->current_window = NULL;
new->visible_windows = 0;
new->window_stack = NULL;
new->meta1_hit = new->meta2_hit = new->meta3_hit = new->meta4_hit = 0;
new->quote_hit = new->digraph_hit = new->inside_menu = 0;
new->buffer_pos = new->buffer_min_pos = 0;
new->input_buffer[0] = '\0';
new->fdout = 1;
new->fpout = stdout;
new->fdin = 0;
new->fpin = stdin;
new->alive = 1;
new->promptlist = NULL;
new->redirect_name = NULL;
new->redirect_token = NULL;
new->tty_name = (char *) 0;
new->li = 24;
new->co = 79;
new->redirect_server = -1;
last_input_screen = new;
return new;
}
/*
* add_wait_prompt: Given a prompt string, a function to call when
* the prompt is entered.. some other data to pass to the function,
* and the type of prompt.. either for a line, or a key, we add
* this to the prompt_list for the current screen.. and set the
* input prompt accordingly.
*/
void
add_wait_prompt(prompt, func, data, type)
char *prompt;
void (*func) _((char *, char *));
char *data;
int type;
{
WaitPrompt **AddLoc,
*New;
New = (WaitPrompt *) new_malloc(sizeof(WaitPrompt));
New->prompt = NULL;
malloc_strcpy(&New->prompt, prompt);
New->data = NULL;
malloc_strcpy(&New->data, data);
New->type = type;
New->func = func;
New->next = NULL;
for (AddLoc = ¤t_screen->promptlist; *AddLoc;
AddLoc = &(*AddLoc)->next);
*AddLoc = New;
if (AddLoc == ¤t_screen->promptlist)
change_input_prompt(1);
}
void
set_current_screen(screen)
Screen *screen;
{
if (screen->alive)
current_screen = screen;
else
current_screen = screen_list;
}
/*
* window_redirect: Setting who to non null will cause IRCII to echo all
* commands and output from that server (including output generated by IRCII)
* to who. Setting who to null disables this
*/
void
window_redirect(who, server)
char *who;
int server;
{
char buf[BIG_BUFFER_SIZE];
if (who)
sprintf(buf, "%04d%s", server, who);
else
sprintf(buf, "%04d#LAME", server);
malloc_strcpy(¤t_screen->redirect_token, buf);
malloc_strcpy(¤t_screen->redirect_name, who);
current_screen->redirect_server = server;
}
int
check_screen_redirect(nick)
char *nick;
{
Screen *screen,
*tmp_screen;
for (screen = screen_list; screen; screen = screen->next)
{
if (!screen->redirect_token)
continue;
if (!strcmp(nick, screen->redirect_token))
{
tmp_screen = current_screen;
current_screen = screen;
window_redirect(NULL, from_server);
current_screen = tmp_screen;
return 1;
}
}
return 0;
}
/* Old screens never die. They just fade away. */
#ifdef WINDOW_CREATE
void
kill_screen(screen)
Screen *screen;
{
Window *window;
if (main_screen == screen)
{
say("You may not kill the main screen");
return;
}
if (screen->fdin)
{
new_close(screen->fdout);
new_close(screen->fdin);
}
while ((window = screen->window_list))
{
screen->window_list = window->next;
add_to_invisible_list(window);
}
if (last_input_screen == screen)
last_input_screen = screen_list;
screen->alive = 0;
}
int
is_main_screen(screen)
Screen *screen;
{
return (screen == main_screen);
}
#else
static int
is_main_screen(screen)
Screen *screen;
{
return 1;
}
#endif /* WINDOW_CREATE */
/*
* scroll_window: Given a pointer to a window, this determines if that window
* should be scrolled, or the cursor moved to the top of the screen again, or
* if it should be left alone.
*/
void
scroll_window(window)
Window *window;
{
if (dumb)
return;
if (window->cursor == window->display_size)
{
if (window->scroll)
{
int scroll,
i;
if ((scroll = get_int_var(SCROLL_LINES_VAR)) <= 0)
scroll = 1;
for (i = 0; i < scroll; i++)
{
new_free (&window->top_of_display->line);
window->top_of_display =
window->top_of_display->next;
}
if (window->visible)
{
if (term_scroll(window->top + window->menu.lines, window->top + window->menu.lines + window->cursor - 1, scroll))
{
if(current_screen->visible_windows == 1)
{
int i;
Window *tmp;
/*
* this method of sim-u-scroll seems to work fairly
* well. The penalty is that you can only have one
* window, and of course you can't use the scrollback
* buffer either. Or menus. Actually, this method
* really doesn't work very well at all anymore.
*/
tmp = current_screen->cursor_window;
term_move_cursor(0, LI - 2);
if (term_clear_to_eol())
term_space_erase(0);
term_cr();
term_newline();
for (i = 0; i < scroll; i++)
{
term_cr();
term_newline();
}
update_window_status(window, 1);
update_input(UPDATE_ALL);
current_screen->cursor_window = tmp;
}
else
redraw_window(window, 1);
}
window->cursor -= scroll;
term_move_cursor(0, window->cursor + window->top + window->menu.lines);
}
else
window->cursor -= scroll;
}
else
{
window->cursor = 0;
if (window->visible)
term_move_cursor(0, window->top + window->menu.lines);
}
}
else if (window->visible && current_screen->cursor_window == window)
{
term_cr();
term_newline();
}
if (window->visible && current_screen->cursor_window)
{
if (term_clear_to_eol()) /* && !window->hold_mode && !window->hold_on_next_rite) */
{
term_space_erase(0);
term_cr();
}
term_flush();
}
}
/* display_highlight: turns off and on the display highlight. */
static char
display_highlight(flag)
int flag;
{
static int highlight = OFF;
fflush(current_screen->fpout);
if (flag == highlight)
return (flag);
switch (flag)
{
case ON:
highlight = ON;
if (get_int_var(INVERSE_VIDEO_VAR))
term_standout_on();
return (OFF);
case OFF:
highlight = OFF;
if (get_int_var(INVERSE_VIDEO_VAR))
term_standout_off();
return (ON);
case TOGGLE:
if (highlight == ON)
{
highlight = OFF;
if (get_int_var(INVERSE_VIDEO_VAR))
term_standout_off();
return (ON);
}
else
{
highlight = ON;
if (get_int_var(INVERSE_VIDEO_VAR))
term_standout_on();
return (OFF);
}
}
return flag;
}
/* display_bold: turns off and on the display bolding. */
static char
display_bold(flag)
int flag;
{
static int bold = OFF;
fflush(current_screen->fpout);
if (flag == bold)
return (flag);
switch (flag)
{
case ON:
bold = ON;
if (get_int_var(BOLD_VIDEO_VAR))
term_bold_on();
return (OFF);
case OFF:
bold = OFF;
if (get_int_var(BOLD_VIDEO_VAR))
term_bold_off();
return (ON);
case TOGGLE:
if (bold == ON)
{
bold = OFF;
if (get_int_var(BOLD_VIDEO_VAR))
term_bold_off();
return (ON);
}
else
{
bold = ON;
if (get_int_var(BOLD_VIDEO_VAR))
term_bold_on();
return (OFF);
}
}
return OFF;
}
/* display_colors sets the foreground and background colors of the display
*/
static void
display_colors(fgcolor, bgcolor)
int fgcolor;
int bgcolor;
{
if(get_int_var(COLOR_VAR))
{
/* Some people will say that I should use termcap values but since:
* 1- iso 6429 is the only used way for color in the unix realm for now
* 2- color information in termcap entries is still rare
* 3- information about color information in termcap entries is still rare too
*
* ... I'll stick with this way for now. But having only 8-9 colors is a pity.
* -- Sarayan
*/
/* mirc colors -> iso 6469 color translation tables */
static const char trans[] = "70421153326645079";
char iso[]="\033[30m\033[40m";
iso[3] = trans[fgcolor];
iso[8] = trans[bgcolor];
/* '9' means default color */
if(iso[3]!=iso[8] || iso[3]=='9')
fwrite(iso, sizeof(iso)-1, 1, current_screen->fpout);
}
}
/*
* output_line prints the given string at the current screen position,
* performing adjustments for ^_, ^B, ^V, and ^O
*/
int
output_line(str, result, startpos)
char *str;
char **result;
int startpos;
{
static int high = OFF, bold = OFF, fgcolor=16, bgcolor=16;
int rev_tog, und_tog, bld_tog, all_off;
char *ptr;
int len;
int written = 0;
char c;
char *original;
original = str;
ptr = str;
display_highlight(high);
display_bold(bold);
display_colors(fgcolor, bgcolor);
/* do processing on the string, handle inverse and bells */
while (*ptr)
{
switch (*ptr)
{
case REV_TOG:
case UND_TOG:
case BOLD_TOG:
case ALL_OFF:
len = ptr - str;
written += len;
if (startpos)
{
if (ptr - original > startpos)
{
str += len - (ptr - original - startpos);
len = ptr - original - startpos;
startpos = 0;
}
}
if (written > CO)
len = len - (written - CO);
if (!startpos)
fwrite(str, len, 1, current_screen->fpout);
rev_tog = und_tog = bld_tog = all_off = 0;
do
{
switch(*ptr)
{
case REV_TOG:
rev_tog = 1 - rev_tog;
break;
case UND_TOG:
und_tog = 1 - und_tog;
break;
case BOLD_TOG:
bld_tog = 1 - bld_tog;
break;
case ALL_OFF:
all_off = 1;
und_tog = rev_tog = bld_tog = 0;
break;
}
} while ((ptr[1] == REV_TOG || ptr[1] == UND_TOG ||
ptr[1] == BOLD_TOG || ptr[1] == ALL_OFF) && ptr++);
if (all_off)
{
if (!underline)
{
term_underline_off();
underline = 1;
}
display_highlight(OFF);
display_bold(OFF);
display_colors(16, 16);
high = 0;
bold = 0;
fgcolor = bgcolor = 16;
}
if (und_tog && get_int_var(UNDERLINE_VIDEO_VAR))
{
if ((underline = 1 - underline) != 0)
term_underline_off();
else
term_underline_on();
}
if (rev_tog)
{
high = display_highlight(TOGGLE);
high = 1 - high;
}
if (bld_tog)
{
bold = display_bold(TOGGLE);
bold = 1 - bold;
}
str = ++ptr;
break;
case COLOR_TAG:
len = ptr - str;
written += len;
if (startpos)
{
if (ptr - original > startpos)
{
str += len - (ptr - original - startpos);
len = ptr - original - startpos;
startpos = 0;
}
}
if (written > CO)
len = len - (written - CO);
if (!startpos)
fwrite(str, len, 1, current_screen->fpout);
do
{
ptr++;
fgcolor = *ptr++ - 1;
if((fgcolor == 16) || (*ptr != 16 + 1))
bgcolor = *ptr - 1;
} while (ptr[1] == COLOR_TAG && ptr++);
display_colors(fgcolor, bgcolor);
str = ++ptr;
break;
case '\007':
/*
* same as above, except after we display everything
* so far, we beep the terminal
*/
c = *ptr;
*ptr = '\0';
len = strlen(str);
written += len;
if (startpos)
{
if (ptr - original > startpos)
{
str += len - (ptr - original - startpos);
len = ptr - original - startpos;
startpos = 0;
}
}
if (written > CO)
len = len - (written - CO);
if (!startpos)
fwrite(str, len, 1, current_screen->fpout);
term_beep();
*ptr = c;
str = ++ptr;
break;
default:
ptr++;
break;
}
}
if (result)
*result = str;
return written;
}
/*
* rite: this routine displays a line to the screen adding bold facing when
* specified by ^Bs, etc. It also does handles scrolling and paging, if
* SCROLL is on, and HOLD_MODE is on, etc. This routine assumes that str
* already fits on one screen line. If show is true, str is displayed
* regardless of the hold mode state. If redraw is true, it is assumed we a
* redrawing the screen from the display_ip list, and we should not add what
* we are displaying back to the display_ip list again.
*
* Note that rite sets display_highlight() to what it was at then end of the
* last rite(). Also, before returning, it sets display_highlight() to OFF.
* This way, between susequent rites(), you can be assured that the state of
* bold face will remain the same and the it won't interfere with anything
* else (i.e. status line, input line).
*/
int
rite(window, str, show, redraw, backscroll, logged)
Window *window;
char *str;
int show,
redraw,
backscroll,
logged;
{
static int high = OFF;
int written = 0,
len;
Screen *old_current_screen = current_screen;
if (!backscroll && window->scrolled_lines)
window->new_scrolled_lines++;
#if 0
if (window->hold_mode && window->hold_on_next_rite && !redraw && !backscroll && window->line_cnt >= window->display_size)
#endif /* 0 */
if (window->hold_mode && window->hold_on_next_rite && !redraw && !backscroll)
{
/* stops output from going to the window */
window->hold_on_next_rite = 0;
hold_mode(window, ON, 1);
if (show)
return (1);
}
/*
* Don't need to worry about the current_screen if the window isn't
* visible, as hidden windows aren't attached to a screen anyway
*/
if (window->visible)
{
old_current_screen = current_screen;
set_current_screen(window->screen);
}
if (!show && (hold_output(window) || hold_queue(window)) && !in_help && !redraw && !backscroll)
/* sends window output to the hold list for that window */
add_to_hold_list(window, str, logged);
else
{
if (!redraw && !backscroll)
{
/*
* This isn't a screen refresh, so add the line to the display
* list for the window
*/
if (window->scroll)
scroll_window(window);
malloc_strcpy(&(window->display_ip->line), str);
window->display_ip->linetype = logged;
window->display_ip = window->display_ip->next;
if (!window->scroll)
new_free(&window->display_ip->line);
}
if (window->visible)
{
/* make sure the cursor is in the appropriate window */
if (current_screen->cursor_window != window &&
!redraw && !backscroll)
{
current_screen->cursor_window = window;
term_move_cursor(0, window->cursor +
window->top + window->menu.lines);
}
written = output_line(str, &str, 0);
len = strlen(str);
written += len;
if (written > CO)
len = len - (written - CO);
if (len > 0)
fwrite(str, len, 1, current_screen->fpout);
if (term_clear_to_eol())
term_space_erase(written);
}
else if (!(window->miscflags & WINDOW_NOTIFIED))
{
if ((who_level & window->notify_level)
|| ((window->notify_level & LOG_BEEP)
&& strchr (str, '\007')))
{
window->miscflags |= WINDOW_NOTIFIED;
if (window->miscflags & WINDOW_NOTIFY)
{
Window *old_to_window;
int lastlog_level;
lastlog_level =
set_lastlog_msg_level(LOG_CRAP);
old_to_window = to_window;
to_window = curr_scr_win;
say("Activity in window %d",
window->refnum);
to_window = old_to_window;
set_lastlog_msg_level(lastlog_level);
}
update_all_status();
}
}
if (!redraw && !backscroll)
{
window->cursor++;
window->line_cnt++;
if (window->scroll)
{
if (window->line_cnt >= window->display_size)
{
window->hold_on_next_rite = 1;
window->line_cnt = 0;
}
}
else
{
scroll_window(window);
if (window->cursor == (window->display_size -1))
window->hold_on_next_rite = 1;
}
}
else if (window->visible)
{
term_cr();
term_newline();
}
if (window->visible)
{
high = display_highlight(OFF);
term_flush();
}
}
if (window->visible)
set_current_screen(old_current_screen);
return (0);
}
/*
* cursor_not_in_display: This forces the cursor out of the display by
* setting the cursor window to null. This doesn't actually change the
* physical position of the cursor, but it will force rite() to reset the
* cursor upon its next call
*/
void
cursor_not_in_display()
{
current_screen->cursor_window = NULL;
}
/*
* cursor_in_display: this forces the cursor_window to be the
* current_screen->current_window.
* It is actually only used in hold.c to trick the system into thinking the
* cursor is in a window, thus letting the input updating routines move the
* cursor down to the input line. Dumb dumb dumb
*/
void
cursor_in_display()
{
current_screen->cursor_window = curr_scr_win;
}
/*
* is_cursor_in_display: returns true if the cursor is in one of the windows
* (cursor_window is not null), false otherwise
*/
int
is_cursor_in_display()
{
if (current_screen->cursor_window)
return (1);
else
return (0);
}
void
redraw_resized(window, Info, AnchorTop)
Window *window;
ShrinkInfo Info;
int AnchorTop;
{
if (!AnchorTop)
{
if (Info.bottom < 0)
term_scroll(window->top+window->menu.lines+Info.bottom,
window->top + window->menu.lines +
window->display_size - 1,
Info.bottom);
else if (Info.bottom)
term_scroll(window->top+window->menu.lines,
window->top + window->menu.lines +
window->display_size -1, Info.bottom);
}
}
/*
* resize_display: After determining that the screen has changed sizes, this
* resizes all the internal stuff. If the screen grew, this will add extra
* empty display entries to the end of the display list. If the screen
* shrank, this will remove entries from the end of the display list. By
* doing this, we try to maintain as much of the display as possible.
*
* This has now been improved so that it returns enough information for
* redraw_resized to redisplay the contents of the window without having
* to redraw too much.
*/
ShrinkInfo
resize_display(window)
Window *window;
{
int cnt,
i;
Display *tmp, *pre_ip;
int Wrapped = 0;
ShrinkInfo Result;
Result.top = Result.bottom = 0;
Result.position = window->cursor;
if (dumb)
{
return Result;
}
if (!window->top_of_display)
{
window->top_of_display = (Display *)new_malloc(sizeof(Display));
window->top_of_display->line = NULL;
window->top_of_display->linetype = LT_UNLOGGED;
window->top_of_display->next = window->top_of_display;
window->display_ip = window->top_of_display;
window->old_size = 1;
}
/* cnt = size - window->display_size; */
cnt = window->display_size - window->old_size;
if (cnt > 0)
{
Display *new = NULL;
/*
* screen got bigger: got to last display entry and link in new
* entries
*/
for (tmp = window->top_of_display, i = 0;
i < (window->old_size - 1);
i++, tmp = tmp->next);
for (i = 0; i < cnt; i++)
{
new = (Display *) new_malloc(sizeof(Display));
new->line = NULL;
new->linetype = LT_UNLOGGED;
new->next = tmp->next;
tmp->next = new;
}
if (window->display_ip == window->top_of_display &&
window->top_of_display->line)
window->display_ip = new;
Result.top = 0;
Result.bottom = cnt;
Result.position = 0;
}
else if (cnt < 0)
{
Display *ptr;
/*
* screen shrank: find last display entry we want to keep, and remove
* all after that point
*/
cnt = -cnt;
for (pre_ip = window->top_of_display;
pre_ip->next != window->display_ip;
pre_ip = pre_ip->next);
for (tmp = pre_ip->next, i =0; i < cnt; i++, tmp = ptr)
{
ptr = tmp->next;
if (tmp == window->top_of_display)
{
if (tmp->line)
Wrapped = 1;
window->top_of_display = ptr;
}
if (Wrapped)
Result.top--;
else
Result.bottom--;
new_free(&(tmp->line));
new_free(&tmp);
}
window->display_ip = pre_ip->next = tmp;
window->cursor += Result.top;
if (!window->scroll)
{
if (window->cursor == window->display_size)
window->cursor = 0;
new_free(&window->display_ip->line);
}
}
window->update |= REDRAW_DISPLAY_FULL | REDRAW_STATUS;
window->old_size = window->display_size;
return Result;
}
/*
* recalculate_windows: this is called when the terminal size changes (as
* when an xterm window size is changed). It recalculates the sized and
* positions of all the windows. Currently, all windows are rebalanced and
* window size proportionality is lost
*/
void
recalculate_windows()
{
int base_size,
size,
top,
k = 0,
extra;
Window *tmp;
if (dumb)
return;
base_size = ((LI - 1) / current_screen->visible_windows) - 1;
extra = (LI - 1) - ((base_size + 1)*current_screen->visible_windows);
top = 0;
for (tmp = current_screen->window_list; tmp; tmp = tmp->next)
{
tmp->update |= REDRAW_DISPLAY_FULL | REDRAW_STATUS;
if (extra)
{
extra--;
size = base_size + 1;
}
else
size = base_size;
#ifdef SCROLL_AFTER_DISPLAY
tmp->display_size = size - tmp->menu.lines
- tmp->double_status - 1;
#else
tmp->display_size = size - tmp->menu.lines
- tmp->double_status;
#endif /* SCROLL_AFTER_DISPLAY */
if (tmp->display_size<=0)
tmp->display_size = 1;
tmp->top = top;
tmp->bottom = top + size - tmp->double_status;
top += size + 1;
}
}
/*
* clear_window: This clears the display list for the given window, or
* current window if null is given.
*/
void
clear_window(window)
Window *window;
{
int i,
cnt;
if (dumb)
return;
if (window == NULL)
window = curr_scr_win;
erase_display(window);
term_move_cursor(0, window->top + window->menu.lines);
cnt = window->bottom - window->top - window->menu.lines;
for (i = 0; i < cnt; i++)
{
if (term_clear_to_eol())
term_space_erase(0);
term_newline();
}
term_flush();
}
/* clear_all_windows: This clears all *visible* windows */
void
clear_all_windows(unhold)
int unhold;
{
Window *tmp;
for (tmp = current_screen->window_list; tmp; tmp = tmp->next)
{
if (unhold)
hold_mode(tmp, OFF, 1);
clear_window(tmp);
}
}
/*
* redraw_window: This redraws the display list for the given window. Some
* special considerations are made if you are just redrawing one window as
* opposed to using this routine to redraw the whole screen one window at a
* time
*
* A negative value in just_one indicates not all of the window needs to
* be redrawn.
*/
void
redraw_window(window, just_one)
Window *window;
int just_one;
{
Display *tmp;
int i;
int StartPoint;
int yScr;
if (dumb || !window->visible)
return;
window = window ? window : curr_scr_win;
if (just_one < 0)
{
/* This part of the window is scrolling into view */
StartPoint = -just_one;
just_one = 0;
}
else
{
StartPoint = 0;
if (window->scrolled_lines)
display_lastlog_lines(window->scrolled_lines-window->display_size + 1, window->scrolled_lines, window);
}
if (window->menu.menu)
ShowMenuByWindow(window, just_one ? SMF_ERASE : 0);
if (window->scrolled_lines + StartPoint < window->display_size)
yScr = window->scrolled_lines + StartPoint;
else
yScr = 0;
term_move_cursor(0, window->top+window->menu.lines+yScr);
/*
* if (term_clear_to_eol())
* { term_space_erase(0); term_cr(); }
*/
for (tmp = window->top_of_display, i = 0; i < window->display_size-window->scrolled_lines; i++, tmp = tmp->next)
{
if (i < StartPoint)
continue;
if (tmp->line)
rite(window, tmp->line, 1, 1, 0, 0);
else
{
if (just_one)
{
if (term_clear_to_eol())
term_space_erase(0);
}
term_newline();
}
}
term_flush();
}
/*
* recalculate_window_positions: This runs through the window list and
* re-adjusts the top and bottom fields of the windows according to their
* current positions in the window list. This doesn't change any sizes of
* the windows
*/
void
recalculate_window_positions()
{
Window *tmp;
int top;
top = 0;
for (tmp = current_screen->window_list; tmp; tmp = tmp->next)
{
tmp->update |= REDRAW_DISPLAY_FULL | REDRAW_STATUS;
tmp->top = top;
tmp->bottom = top + tmp->display_size + tmp->menu.lines;
top += tmp->display_size + tmp->menu.lines + 1 +
tmp->double_status;
}
}
/*
* redraw_all_windows: This basically clears and redraws the entire display
* portion of the screen. All windows and status lines are draws. This does
* nothing for the input line of the screen. Only visible windows are drawn
*/
void
redraw_all_windows()
{
Window *tmp;
if (dumb)
return;
for (tmp = current_screen->window_list; tmp; tmp = tmp->next)
tmp->update |= REDRAW_STATUS | REDRAW_DISPLAY_FAST;
}
#define MAXIMUM_SPLITS 40
static char **
split_up_line(str)
char *str;
{
static char *output[MAXIMUM_SPLITS] =
{
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL
};
char buffer[BIG_BUFFER_SIZE + 1];
unsigned char *ptr;
char *cont_ptr,
*cont = NULL,
*temp = NULL,
c;
int pos = 0,
col = 0,
nd_cnt = 0,
word_break = 0,
start = 0,
i,
len,
indent = 0,
beep_cnt = 0,
beep_max,
tab_cnt = 0,
tab_max,
line = 0;
bzero(buffer, sizeof(buffer));
for (i = 0; i < MAXIMUM_SPLITS; i++)
new_free(&output[i]);
if (!*str)
malloc_strcpy(&str, " "); /* special case to make blank lines show up */
beep_max = get_int_var(BEEP_VAR) ? get_int_var(BEEP_MAX_VAR) : -1;
tab_max = get_int_var(TAB_VAR) ? get_int_var(TAB_MAX_VAR) : -1;
for (ptr = (u_char *) str; *ptr && (pos < BIG_BUFFER_SIZE - 8); ptr++)
{
if (translation)
*ptr = transToClient[*ptr];
/* 0x9b is Linux Console escape char */
if (*ptr == 0x9b || *ptr <= 32 || (*ptr >= 128 && *ptr<128+32))
{
switch (*ptr)
{
case '\007': /* bell */
if (beep_max == -1)
{
buffer[pos++] = REV_TOG;
buffer[pos++] = (*ptr & 127) | 64;
buffer[pos++] = REV_TOG;
nd_cnt += 2;
col++;
}
else if (!beep_max || (++beep_cnt <= beep_max))
{
buffer[pos++] = *ptr;
nd_cnt++;
col++;
}
break;
case '\011': /* tab */
if (tab_max && (++tab_cnt > tab_max))
{
buffer[pos++] = REV_TOG;
buffer[pos++] = (*ptr & 127) | 64;
buffer[pos++] = REV_TOG;
nd_cnt += 2;
col++;
}
else
{
if (indent == 0)
indent = -1;
len = 8 - (col % 8);
word_break = pos;
for (i = 0; i < len; i++)
buffer[pos++] = ' ';
col += len;
}
break;
case ' ': /* word break */
if (indent == 0)
indent = -1;
word_break = pos;
buffer[pos++] = *ptr;
col++;
break;
case UND_TOG:
case ALL_OFF:
case REV_TOG:
case BOLD_TOG:
buffer[pos++] = *ptr;
nd_cnt++;
break;
case COLOR_TAG:
{
int fg = -1, bg = -1;
unsigned char *p1;
int i = 0;
char minibuffer[3];
buffer[pos++] = *ptr++;
/* Colors are coded on 2 digits only */
if (isdigit(*ptr)) {
minibuffer[i++] = *ptr++;
if (isdigit(*ptr))
minibuffer[i++] = *ptr++;
minibuffer[i] = '\0';
fg = strtol((const char *)minibuffer, (char **)&p1, 10);
if(*ptr == ',') {
ptr++;
i = 0;
if (isdigit(*ptr)) {
minibuffer[i++] = *ptr++;
if (isdigit(*ptr))
minibuffer[i++] = *ptr++;
minibuffer[i] = '\0';
bg = strtol((const char *)minibuffer, (char **)&p1, 10);
}
}
}
if(fg != -1)
fg = fg & 15;
else
fg = 16;
if(bg != -1)
bg = bg & 15;
else
bg = 16;
buffer[pos++] = (char)fg+1;
buffer[pos++] = (char)bg+1;
nd_cnt += 3;
ptr--;
break;
}
default: /* Anything else, make it displayable */
if (indent == -1)
indent = pos - nd_cnt;
buffer[pos++] = REV_TOG;
buffer[pos++] = (*ptr & 127) | 64;
buffer[pos++] = REV_TOG;
nd_cnt += 2;
col++;
break;
}
}
else
{
if (indent == -1)
indent = pos - nd_cnt;
buffer[pos++] = *ptr;
col++;
}
if (pos == BIG_BUFFER_SIZE)
*ptr = '\0';
if (col >= CO)
{
/* one big long line, no word breaks */
if (word_break == 0)
word_break = pos - (col - CO);
c = buffer[word_break];
buffer[word_break] = '\0';
if (cont)
{
malloc_strcpy(&temp, cont);
malloc_strcat(&temp, &(buffer[start]));
}
else
malloc_strcpy(&temp, &(buffer[start]));
malloc_strcpy(&output[line++], temp);
buffer[word_break] = c;
start = word_break;
word_break = 0;
while (buffer[start] == ' ')
start++;
if (start > pos)
start = pos;
if (!(cont_ptr = get_string_var(CONTINUED_LINE_VAR)))
cont_ptr = empty_string;
if (get_int_var(INDENT_VAR) && (indent < CO / 3))
{
/*
* INDENT thanks to Carlo "lynx" v. Loesch
* - hehe, nice to see this is still here... -lynx 91
*/
if (!cont)
{
if ((len = strlen(cont_ptr)) > indent)
{
cont = (char *) new_malloc(len
+ 1);
strcpy(cont, cont_ptr);
}
else
{
cont = (char *)
new_malloc(indent + 1);
strcpy(cont, cont_ptr);
for (i = len; i < indent; i++)
cont[i] = ' ';
cont[indent] = '\0';
}
}
}
else
malloc_strcpy(&cont, cont_ptr);
col = strlen(cont) + (pos - start);
}
}
buffer[pos] = '\0';
if (buffer[start])
{
if (cont)
{
malloc_strcpy(&temp, cont);
malloc_strcat(&temp, &(buffer[start]));
}
else
malloc_strcpy(&temp, &(buffer[start]));
malloc_strcpy(&output[line++], temp);
}
new_free(&cont);
new_free(&temp);
return output;
}
/*
* add_to_window: adds the given string to the display. No kidding. This
* routine handles the whole ball of wax. It keeps track of what's on the
* screen, does the scrolling, everything... well, not quite everything...
* The CONTINUED_LINE idea thanks to Jan L. Peterson (jlp@hamblin.byu.edu)
*
* At least it used to. Now most of this is done by split_up_line, and this
* function just dumps it onto the screen. This is because the scrollback
* functions need to be able to figure out how to split things up too.
*/
static void
add_to_window(window, str)
Window *window;
char *str;
{
int flag;
flag = do_hook(WINDOW_LIST, "%u %s", window->refnum, str);
if (flag)
{
char **lines;
int logged;
add_to_log(window->log_fp, str);
add_to_lastlog(window, str);
display_highlight(OFF);
display_bold(OFF);
display_colors(16, 16);
strmcat(str, global_all_off, BIG_BUFFER_SIZE - 1);
logged = islogged(window);
for (lines = split_up_line(str); *lines; lines++)
{
rite(window, *lines, 0, 0, 0, logged);
if (logged == 1)
logged = 2;
}
term_flush();
}
}
/*
* XXX this is a temporary internal interface that will go
* away in the near future.
*/
int in_redirect;
/*
* add_to_screen: This adds the given null terminated buffer to the screen.
* That is, it determines which window the information should go to, which
* lastlog the information should be added to, which log the information
* should be sent to, etc
*/
void
add_to_screen(incoming)
char *incoming;
{
int flag;
Window *tmp;
/* Handles output redirection first */
if (!in_redirect && current_screen->redirect_name &&
from_server == current_screen->redirect_server)
{
int i;
in_redirect = 1;
if (*current_screen->redirect_name == '%')
{ /* redirection to a process */
if (is_number(current_screen->redirect_name + 1))
i = atoi(current_screen->redirect_name + 1);
else
i = logical_to_index(current_screen->redirect_name
+ 1);
if (is_process_running(i))
text_to_process(i, incoming, 0);
}
else if (*current_screen->redirect_name == '=')
dcc_message_transmit(current_screen->redirect_name + 1,
incoming, DCC_CHAT, 0);
/*
* shouldn't this be a NOTICE? -lynx
* agreed - phone, jan 1993
*/
else
send_to_server("PRIVMSG %s :%s",
current_screen->redirect_name, incoming);
in_redirect = 0;
}
if (dumb)
{
add_to_lastlog(curr_scr_win, incoming);
if (do_hook(WINDOW_LIST, "%u %s", curr_scr_win->refnum, incoming))
puts(incoming);
fflush(current_screen->fpout);
return;
}
if (in_window_command)
update_all_windows();
if ((who_level == LOG_CURRENT) && (curr_scr_win->server == from_server))
{
add_to_window(curr_scr_win, incoming);
return;
}
if (to_window)
{
add_to_window(to_window, incoming);
return;
}
if (who_from)
{
if (is_channel(who_from))
{
ChannelList *chan;
if ((chan = lookup_channel(who_from, from_server, CHAN_NOUNLINK)))
{
add_to_window(chan->window, incoming);
return;
}
if (who_level == LOG_DCC)
{
strcpy(buffer, "=");
strmcat(buffer, who_from, BIG_BUFFER_SIZE);
if ((chan = lookup_channel(buffer, from_server, CHAN_NOUNLINK)))
{
add_to_window(chan->window, incoming);
return;
}
}
}
else
{
flag = 1;
while ((tmp = traverse_all_windows(&flag)) != NULL)
{
if (tmp->query_nick &&
(((who_level == LOG_MSG || who_level == LOG_NOTICE)
&& !my_stricmp(who_from, tmp->query_nick) &&
from_server == tmp->server) ||
(who_level == LOG_DCC &&
(*tmp->query_nick == '=' || *tmp->query_nick == '@') &&
my_stricmp(who_from, tmp->query_nick + 1) == 0)))
{
add_to_window(tmp, incoming);
return;
}
}
flag = 1;
while ((tmp = traverse_all_windows(&flag)) != NULL)
{
if (from_server == tmp->server)
{
if (find_in_list((List **) &(tmp->nicks), who_from, !USE_WILDCARDS))
{
add_to_window(tmp, incoming);
return;
}
}
}
}
}
flag = 1;
while ((tmp = traverse_all_windows(&flag)) != NULL)
{
if (((from_server == tmp->server) || (from_server == -1)) &&
(who_level & tmp->window_level))
{
add_to_window(tmp, incoming);
return;
}
}
if (from_server == curr_scr_win->server)
tmp = curr_scr_win;
else
{
flag = 1;
while ((tmp = traverse_all_windows(&flag)) != NULL)
{
if (tmp->server == from_server)
break;
}
if (!tmp)
tmp = curr_scr_win;
}
add_to_window(tmp, incoming);
}
/*
* update_all_windows: This goes through each visible window and draws the
* necessary portions according the the update field of the window.
*/
void
update_all_windows()
{
Window *tmp;
int fast_window,
full_window,
r_status,
u_status;
for (tmp = current_screen->window_list; tmp; tmp = tmp->next)
{
if (tmp->display_size != tmp->old_size)
resize_display(tmp);
if (tmp->update)
{
fast_window = tmp->update & REDRAW_DISPLAY_FAST;
full_window = tmp->update & REDRAW_DISPLAY_FULL;
r_status = tmp->update & REDRAW_STATUS;
u_status = tmp->update & UPDATE_STATUS;
if (full_window)
redraw_window(tmp, 1);
else if (fast_window)
redraw_window(tmp, 0);
if (r_status)
update_window_status(tmp, 1);
else if (u_status)
update_window_status(tmp, 0);
}
tmp->update = 0;
}
for (tmp = invisible_list; tmp; tmp = tmp->next)
{
if (tmp->display_size != tmp->old_size)
resize_display(tmp);
tmp->update = 0;
}
update_input(UPDATE_JUST_CURSOR);
term_flush();
}
/*
* create_refnum: this generates a reference number for a new window that is
* not currently is use by another window. A refnum of 0 is reserved (and
* never returned by this routine). Using a refnum of 0 in the message_to()
* routine means no particular window (stuff goes to CRAP)
*/
static u_int
create_refnum()
{
unsigned int new_refnum = 1;
Window *tmp;
int done = 0,
flag;
while (!done)
{
done = 1;
if (new_refnum == 0)
new_refnum++;
flag = 1;
while ((tmp = traverse_all_windows(&flag)) != NULL)
{
if (tmp->refnum == new_refnum)
{
done = 0;
new_refnum++;
break;
}
}
}
return (new_refnum);
}
/*
* new_window: This creates a new window on the screen. It does so by either
* splitting the current window, or if it can't do that, it splits the
* largest window. The new window is added to the window list and made the
* current window
*/
Window *
new_window()
{
Window *new;
static int no_screens = 1;
if (no_screens)
{
set_current_screen(create_new_screen());
main_screen = current_screen;
no_screens = 0;
}
if (dumb && (current_screen->visible_windows == 1))
return NULL;
new = (Window *) new_malloc(sizeof(Window));
new->refnum = create_refnum();
if (curr_scr_win)
new->server = curr_scr_win->server;
else
new->server = primary_server;
new->prev_server = -1;
new->line_cnt = 0;
if (current_screen->visible_windows == 0)
new->window_level = LOG_DEFAULT;
else
new->window_level = LOG_NONE;
new->hold_mode = get_int_var(HOLD_MODE_VAR);
new->scroll = get_int_var(SCROLL_VAR);
new->lastlog_head = 0;
new->lastlog_tail = 0;
new->nicks = 0;
new->lastlog_level = real_lastlog_level();
new->name = 0;
new->prompt = 0;
new->lastlog_size = 0;
new->held = OFF;
new->last_held = OFF;
new->current_channel = 0;
new->query_nick = 0;
new->hold_on_next_rite = 0;
new->status_line[0] = NULL;
new->status_line[1] = NULL;
new->double_status = 0;
new->top_of_display = 0;
new->display_ip = 0;
new->display_size = 1;
new->old_size = 1;
new->hold_head = 0;
new->hold_tail = 0;
new->held_lines = 0;
new->scrolled_lines = 0;
new->new_scrolled_lines = 0;
new->next = 0;
new->prev = 0;
new->cursor = 0;
new->visible = 1;
new->screen = current_screen;
new->logfile = 0;
new->log = 0;
new->log_fp = 0;
new->miscflags = 0;
new->update = 0;
new->menu.lines = 0;
new->menu.menu = 0;
new->notify_level = real_notify_level();
new->server_group = 0;
new->sticky = 1;
resize_display(new);
if (add_to_window_list(new))
set_current_window(new);
term_flush();
return (new);
}
void
close_all_screen()
{
Screen *screen;
for (screen = screen_list; screen && screen != current_screen;
screen = screen->next)
if (screen->alive && screen->fdin != 0)
new_close(screen->fdin);
}
#ifdef WINDOW_CREATE
Window *
create_additional_screen()
{
Window *win;
Screen *oldscreen;
char *displayvar,
*termvar;
int screen_type = ST_NOTHING;
struct sockaddr_un sock,
*sockaddr = &sock,
NewSock;
int NsZ;
int s;
fd_set fd_read;
struct timeval timeout;
pid_t child;
int old_timeout;
#define IRCXTERM_MAX 10
char *ircxterm[IRCXTERM_MAX];
char *ircxterm_env;
char *xterm = (char *) 0;
int ircxterm_num;
char *p, *q;
int i;
#ifdef DAEMON_UID
if (DAEMON_UID == getuid())
{
say("you are not permitted to use WINDOW CREATE");
return (Window *) 0;
}
#endif /* DAEMON_UID */
ircxterm_num = 0;
p = ircxterm_env = getenv("IRCXTERM");
if (p)
{
q = ircxterm_env + strlen(ircxterm_env);
while (p < q)
{
while (':' == *p)
p++;
if ('\0' == *p)
break;
ircxterm[ircxterm_num++] = p;
while (':' != *p && '\0' != *p)
p++;
if (':' == *p)
{
*p = '\0';
p++;
}
}
}
else
{
ircxterm[ircxterm_num] = "xterm";
ircxterm_num++;
}
/*
* Environment variable STY has to be set for screen to work.. so it is
* the best way to check screen.. regardless of what TERM is, the
* execpl() for screen won't just open a new window if STY isn't set,
* it will open a new screen process, and run the wserv in its first
* window, not what we want... -phone
*/
if (0 != getenv("STY"))
{
screen_type = ST_SCREEN;
}
else if ((char *) 0 != (displayvar = getenv("DISPLAY")))
{
if ((char *) 0 == (termvar = getenv("TERM")))
{
say("I don't know how to create new windows for this terminal");
return (Window *) 0;
}
screen_type = ST_XTERM;
if (0 == strncmp(termvar, "sun", 3))
{
xterm = "xterm";
}
else
{
for(; *termvar; termvar++)
{
for (i = 0; i < ircxterm_num; i++)
{
if (!strncmp(termvar, ircxterm[i], strlen(ircxterm[i])))
{
screen_type = ST_XTERM;
malloc_strcpy(&xterm, ircxterm[i]);
termvar = empty_string;
break;
}
}
}
}
}
if (screen_type == ST_NOTHING)
{
say("I don't know how to create new windows for this terminal");
return (Window *) 0;
}
say("Opening new %s...",
screen_type == ST_XTERM ? "window" :
screen_type == ST_SCREEN ? "screen" :
"wound" );
sprintf(sock.sun_path, "/tmp/irc_%08d", (int) getpid());
sock.sun_family = AF_UNIX;
s = socket(AF_UNIX, SOCK_STREAM, 0);
bind(s, (struct sockaddr *) &sock, 2 + strlen(sock.sun_path));
listen(s, 1);
oldscreen = current_screen;
set_current_screen(create_new_screen());
if (0 == (child = fork()))
{
setuid(getuid());
setgid(getgid());
/*
* Unlike most other cases, it is important here to close down
* *ALL* unneeded file descriptors. Failure to do so can cause
* Things like server and DCC connections to fail to close on
* request. This isn't a problem with "screen", but is with X.
*/
new_close(s);
close_all_screen();
close_all_dcc();
close_all_exec();
close_all_server();
if (screen_type == ST_SCREEN)
{
int i = 0;
char *args[64],
*s,
*t,
*opts = NULL;
args[i++] = "screen";
if ((s = get_string_var(SCREEN_OPTIONS_VAR)) != NULL)
{
malloc_strcpy(&opts, s);
while ((t = (char *) strtok(opts," ")) != NULL)
{
args[i++] = t;
opts = NULL;
}
}
args[i++] = WSERV_PATH;
args[i++] = sockaddr->sun_path;
args[i++] = NULL;
execvp("screen", args);
}
else if (screen_type == ST_XTERM)
{
int lines,
columns,
i = 0;
char geom[20],
*args[64],
*s,
*t,
*opts = NULL;
copy_window_size(&lines, &columns);
sprintf(geom, "%dx%d", columns, lines);
args[i++] = xterm;
args[i++] = "-geom";
args[i++] = geom;
if ((s = get_string_var(XTERM_OPTIONS_VAR)) != NULL)
{
malloc_strcpy(&opts, s);
while ((t = (char *) strtok(opts," ")) != NULL)
{
args[i++] = t;
opts = NULL;
}
}
args[i++] = "-e";
args[i++] = WSERV_PATH;
args[i++] = sockaddr->sun_path;
args[i] = NULL;
execvp(xterm, args);
}
perror("execve");
exit(errno ? errno : -1);
}
NsZ = sizeof(NewSock);
FD_ZERO(&fd_read);
FD_SET(s, &fd_read);
timeout.tv_sec = (time_t) 5;
timeout.tv_usec = 0;
sleep(1);
/* using say(), yell() can be bad in this next section of code. */
switch (select(NFDBITS , &fd_read, NULL, NULL, &timeout))
{
case -1:
case 0:
errno = get_child_exit(child);
new_close(s);
kill_screen(current_screen);
kill(child, SIGKILL);
last_input_screen = oldscreen;
set_current_screen(oldscreen);
yell("child %s with %d", (errno < 1) ? "signaled" : "exited",
(errno < 1) ? -errno : errno);
return (Window *) 0;
default:
current_screen->fdin = current_screen->fdout =
accept(s, (struct sockaddr *) &NewSock, &NsZ);
if (current_screen->fdin < 0)
return (Window *) 0;
current_screen->fpin = current_screen->fpout =
fdopen(current_screen->fdin, "r+");
new_close(s);
unlink(sockaddr->sun_path);
old_timeout = dgets_timeout(5);
/*
* dgets returns 0 on EOF and -1 on timeout. both of these are
* error conditions in this case, so we bail out here.
*/
if (dgets(buffer, BIG_BUFFER_SIZE, current_screen->fdin, (char *) 0) < 1)
{
new_close(current_screen->fdin);
kill_screen(current_screen);
kill(child, SIGKILL);
last_input_screen = oldscreen;
set_current_screen(oldscreen);
(void) dgets_timeout(old_timeout);
return (Window *) 0;
}
else
malloc_strcpy(¤t_screen->tty_name, buffer);
win = new_window();
(void) refresh_screen(0, NULL);
set_current_screen(oldscreen);
(void) dgets_timeout(old_timeout);
return win;
}
/* NOTREACHED */
}
#endif /* WINDOW_CREATE */
static char *
next_line_back(window, skip)
Window *window;
int skip;
{
static int row;
static Lastlog *LogLine;
char **TheirLines;
static char *ScreenLines[MAXIMUM_SPLITS] =
{
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL
};
if (window)
{
LogLine = window->lastlog_head;
row = -1;
}
if (skip)
{
if (LogLine)
LogLine = LogLine->next;
row = -1;
return NULL;
}
if (row <= 0)
{
for (row = 0; ScreenLines[row]; row++)
new_free(&ScreenLines[row]);
if (!window && LogLine)
LogLine = LogLine->next;
if (!LogLine)
return NULL;
TheirLines = split_up_line(LogLine->msg);
for (row = 0; TheirLines[row]; row++)
{
ScreenLines[row] = TheirLines[row];
TheirLines[row] = NULL;
}
if (window)
return NULL;
}
return ScreenLines[--row];
}
static void
display_lastlog_lines(start, end, window)
int start,
end;
Window *window;
{
Display *Disp;
char *Line;
int i;
(void)next_line_back(window, 0);
for (i = window->new_scrolled_lines; i--;)
(void)next_line_back(NULL, 1);
/* WTF is this? -krys */
for (i = 0, Disp = window->top_of_display; i < window->display_size;
Disp = Disp->next, i++)
if (Disp->linetype)
(void)next_line_back(NULL, 0);
for (i = 0; i < start; i++)
(void)next_line_back(NULL, 1);
for (; i < end; i++)
{
if (!(Line = next_line_back(NULL, 0)))
break;
term_move_cursor(0, window->top + window->menu.lines +
window->scrolled_lines - i - 1);
rite(window, Line, 0, 0, 1, 0);
}
}
static void
scrollback_backwards_lines(ScrollDist)
int ScrollDist;
{
Window *window;
Debug((3, "scrollback_backwards_lines(%d)", ScrollDist));
window = curr_scr_win;
if (!window->scrolled_lines && !window->scroll)
{
term_beep();
return;
}
Debug((3, "scrolled_lines = %d", window->scrolled_lines));
window->scrolled_lines += ScrollDist;
Debug((3, "going to term_scroll(%d, %d, %d)",window->top + window->menu.lines,
window->top + window->menu.lines + window->display_size - 1, -ScrollDist));
term_scroll(window->top + window->menu.lines, window->top + window->menu.lines + window->display_size - 1, -ScrollDist);
Debug((3, "scrolled_lines = %d, new_scrolled_lines = %d, display_size = %d", window->scrolled_lines,
window->new_scrolled_lines, window->display_size));
Debug((3, "going to display_lastlog_lines(%d, %d, %s)", window->scrolled_lines - ScrollDist,
window->scrolled_lines, window->name));
display_lastlog_lines(window->scrolled_lines - ScrollDist, window->scrolled_lines, window);
cursor_not_in_display();
update_input(UPDATE_JUST_CURSOR);
}
static void
scrollback_forwards_lines(ScrollDist)
int ScrollDist;
{
Window *window;
Debug((3, "scrollback_forward_lines(%d)", ScrollDist));
window = curr_scr_win;
if (!window->scrolled_lines)
{
term_beep();
return;
}
if (ScrollDist > window->scrolled_lines)
ScrollDist = window->scrolled_lines;
Debug((3, "scrolled_lines = %d", window->scrolled_lines));
window->scrolled_lines -= ScrollDist;
Debug((3, "going to term_scroll(%d, %d, %d)", window->top + window->menu.lines,
window->top + window->menu.lines + window->display_size - 1, ScrollDist));
term_scroll(window->top + window->menu.lines, window->top + window->menu.lines + window->display_size - 1, ScrollDist);
Debug((3, "scrolled_lines = %d, new_scrolled_lines = %d, display_size = %d", window->scrolled_lines,
window->new_scrolled_lines, window->display_size));
if (window->scrolled_lines < window->display_size)
redraw_window(window, ScrollDist + window->scrolled_lines - window->display_size);
Debug((3, "going to display_lastlog_lines(%d, %d, %s)", window->scrolled_lines - window->display_size,
window->scrolled_lines - window->display_size + ScrollDist, window->name));
display_lastlog_lines(window->scrolled_lines - window->display_size,
window->scrolled_lines - window->display_size + ScrollDist, window);
cursor_not_in_display();
update_input(UPDATE_JUST_CURSOR);
if (!window->scrolled_lines)
{
window->new_scrolled_lines = 0;
if (window->hold_mode)
hold_mode(window, ON, 1);
else
hold_mode(window, OFF, 0);
}
}
void
#ifdef __STDC__
scrollback_forwards(unsigned char key, char *ptr)
#else
scrollback_forwards(key, ptr)
unsigned char key;
char * ptr;
#endif /* __STDC__ */
{
scrollback_forwards_lines(curr_scr_win->display_size/2);
}
void
#ifdef __STDC__
scrollback_backwards(unsigned char key, char *ptr)
#else
scrollback_backwards(key, ptr)
unsigned char key;
char * ptr;
#endif /* __STDC__ */
{
scrollback_backwards_lines(curr_scr_win->display_size/2);
}
void
#ifdef __STDC__
scrollback_end(unsigned char key, char *ptr)
#else
scrollback_end(key, ptr)
unsigned char key;
char * ptr;
#endif /* __STDC__ */
{
Window *window;
window = curr_scr_win;
window->new_scrolled_lines = 0;
if (!window->scrolled_lines)
{
term_beep();
return;
}
if (window->scrolled_lines < window->display_size)
scrollback_forwards_lines(window->scrolled_lines);
else
{
window->scrolled_lines = 0;
redraw_window(window, 1);
cursor_not_in_display();
update_input(UPDATE_JUST_CURSOR);
if (window->hold_mode)
hold_mode(window, ON, 1);
else
hold_mode(window, OFF, 0);
}
}
/*
* scrollback_start: moves the current screen back to the start of
* the scrollback buffer.. there are probably cases this doesn't
* quite work.. -phone, april 1993.
*/
void
#ifdef __STDC__
scrollback_start(unsigned char key, char *ptr)
#else
scrollback_start(key, ptr)
unsigned char key;
char * ptr;
#endif /* __STDC__ */
{
Window *window;
window = curr_scr_win;
if (!window->lastlog_size)
{
term_beep();
return;
}
if (window->lastlog_size < window->display_size)
scrollback_backwards_lines(window->lastlog_size);
else
{
window->scrolled_lines = window->lastlog_size;
display_lastlog_lines(window->scrolled_lines -
window->display_size, window->scrolled_lines, window);
cursor_not_in_display();
update_input(UPDATE_JUST_CURSOR);
window->new_scrolled_lines = 0;
if (window->hold_mode)
hold_mode(window, ON, 1);
else
hold_mode(window, OFF, 0);
}
}
RETSIGTYPE
sig_refresh_screen()
{
refresh_screen(0, (char *) 0);
}
|