summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 02:20:21 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 02:20:21 +0000
commit4f64827f3a395072f300b86ef17f730805b47048 (patch)
treec16297f7d68903dc80c86e3003b8e3ab5f030f7d
parentInitial commit. (diff)
downloadscreen-4f64827f3a395072f300b86ef17f730805b47048.tar.xz
screen-4f64827f3a395072f300b86ef17f730805b47048.zip
Adding upstream version 4.6.2.upstream/4.6.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
-rw-r--r--.gitignore21
-rw-r--r--.iscreenrc169
-rw-r--r--COPYING674
-rw-r--r--ChangeLog595
l---------FAQ1
-rw-r--r--HACKING39
-rw-r--r--INSTALL114
-rw-r--r--Makefile.in356
-rw-r--r--NEWS28
-rw-r--r--NEWS.3.5119
-rw-r--r--NEWS.3.648
-rw-r--r--NEWS.3.739
-rw-r--r--NEWS.3.9205
-rw-r--r--README102
-rw-r--r--TODO7
-rw-r--r--acconfig.h579
-rw-r--r--acls.c1147
-rw-r--r--acls.h98
-rw-r--r--ansi.c3193
-rw-r--r--ansi.h175
-rw-r--r--attacher.c1113
-rwxr-xr-xautogen.sh2
-rw-r--r--braille.c945
-rw-r--r--braille.h83
-rw-r--r--braille_tsi.c319
-rw-r--r--canvas.c918
-rw-r--r--canvas.h101
-rw-r--r--comm.c348
-rw-r--r--comm.sh96
-rw-r--r--config.h.in720
-rwxr-xr-xconfigure8034
-rw-r--r--configure.ac1302
-rw-r--r--display.c3820
-rw-r--r--display.h327
-rw-r--r--doc/.gitignore2
-rw-r--r--doc/FAQ253
-rw-r--r--doc/Makefile.in62
-rw-r--r--doc/README.DOTSCREEN151
-rw-r--r--doc/fdpat.ps6501
l---------doc/install.sh1
-rw-r--r--doc/make.help51
-rw-r--r--doc/screen.15273
-rw-r--r--doc/screen.texinfo6097
-rw-r--r--doc/window_to_display.ps2959
-rw-r--r--encoding.c2134
-rwxr-xr-xetc/ccdefs46
-rw-r--r--etc/completer.zsh53
-rwxr-xr-xetc/countmail67
-rw-r--r--etc/etcscreenrc94
-rw-r--r--etc/gr-braille.tbl260
-rw-r--r--etc/gs-braille.tbl261
-rwxr-xr-xetc/mkinstalldirs35
-rwxr-xr-xetc/newsyntax64
-rwxr-xr-xetc/newsyntax3871
-rw-r--r--etc/screenrc153
-rwxr-xr-xetc/toolcheck44
-rw-r--r--etc/us-braille.tbl260
-rw-r--r--extern.h511
-rw-r--r--fileio.c773
-rw-r--r--help.c934
-rw-r--r--image.h189
-rw-r--r--input.c528
-rwxr-xr-xinstall.sh119
-rw-r--r--layer.c1230
-rw-r--r--layer.h163
-rw-r--r--layout.c350
-rw-r--r--layout.h63
-rw-r--r--list_display.c245
-rw-r--r--list_generic.c486
-rw-r--r--list_generic.h73
-rw-r--r--list_window.c708
-rw-r--r--loadav.c396
-rw-r--r--logfile.c251
-rw-r--r--logfile.h87
-rw-r--r--mark.c1537
-rw-r--r--mark.h58
-rw-r--r--misc.c771
-rw-r--r--nethack.c138
-rw-r--r--os.h529
-rw-r--r--osdef.h.in202
-rw-r--r--osdef.sh69
-rw-r--r--patchlevel.h538
-rw-r--r--process.c7414
-rw-r--r--pty.c415
-rw-r--r--putenv.c216
-rw-r--r--resize.c1136
-rw-r--r--sched.c290
-rw-r--r--sched.h48
-rw-r--r--screen.c3416
-rw-r--r--screen.h316
-rw-r--r--search.c399
-rw-r--r--socket.c1930
-rw-r--r--teln.c578
-rw-r--r--term.c297
-rw-r--r--term.sh169
-rw-r--r--termcap.c1514
-rw-r--r--terminfo/8bits17
-rw-r--r--terminfo/README20
-rw-r--r--terminfo/checktc.c204
-rw-r--r--terminfo/screencap23
-rw-r--r--terminfo/screeninfo.src80
-rw-r--r--terminfo/test.txt603
-rw-r--r--terminfo/tetris.c20
-rw-r--r--tty.sh1604
-rw-r--r--utf8encodings/01bin0 -> 29808 bytes
-rw-r--r--utf8encodings/02bin0 -> 27550 bytes
-rw-r--r--utf8encodings/03bin0 -> 32926 bytes
-rw-r--r--utf8encodings/04bin0 -> 24302 bytes
-rw-r--r--utf8encodings/18bin0 -> 54862 bytes
-rw-r--r--utf8encodings/19bin0 -> 95776 bytes
-rw-r--r--utf8encodings/a1bin0 -> 536 bytes
-rw-r--r--utf8encodings/bfbin0 -> 232 bytes
-rw-r--r--utf8encodings/c2bin0 -> 256 bytes
-rw-r--r--utf8encodings/c3bin0 -> 140 bytes
-rw-r--r--utf8encodings/c4bin0 -> 228 bytes
-rw-r--r--utf8encodings/c6bin0 -> 68 bytes
-rw-r--r--utf8encodings/c7bin0 -> 52 bytes
-rw-r--r--utf8encodings/c8bin0 -> 40 bytes
-rw-r--r--utf8encodings/ccbin0 -> 68 bytes
-rw-r--r--utf8encodings/cdbin0 -> 52 bytes
-rw-r--r--utf8encodings/d6bin0 -> 212 bytes
-rw-r--r--utmp.c893
-rw-r--r--viewport.c129
-rw-r--r--viewport.h51
-rw-r--r--window.c2357
-rw-r--r--window.h355
126 files changed, 86171 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..529960c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,21 @@
+*.o
+.*.swp
+\#*\#
+*~
+Makefile
+autom4te.cache
+cscope.out
+TAGS
+tags
+comm.h
+config.h
+config.h.in
+config.log
+config.status
+configure
+kmapdef.c
+osdef.h
+term.h
+screen
+stamp-h.in
+tty.c
diff --git a/.iscreenrc b/.iscreenrc
new file mode 100644
index 0000000..802afbd
--- /dev/null
+++ b/.iscreenrc
@@ -0,0 +1,169 @@
+#
+# A sample .screenrc which I use for everyday work.
+#
+# some of the commands commented out here, have been moved to
+# /local/etc/screenrc
+#
+# we want no password, right?
+#password # This will ask us for a password.
+password none # Same as not even mentioning it.
+#password 12Bz/9hNlPLZk # "1234"
+#password YahtrWblnJw # ypmatch jnweiger passwd. Well, ... :-)
+
+scrollback 200 # we have a 200 lines history buffer
+markkeys "@=\177:@=^C" # our mad facit-twist terminal buffer overflow...
+markkeys "h=^B:l=^F:\$=^E" # some missing emacs style bindings in copymode
+
+echo -n "booting screen"
+
+# let it flash, not horn!
+#vbell on # "vbell" don't work any longer, sorry.
+#vbell_msg " Wuff, Wuff!! " # this is the default message
+#bell "Bimmmel No. %" # sounds the bell and shows a message
+
+# we want to login all windows we create.
+#login on # "login", "nologin" don't work any longer, sorry 2.
+
+echo -n "."
+# we have no termcap entry for screen on the target machine? Well then
+# we tell a lie.
+term screen # would be the obvious default here.
+#term vt100 # screen will understand vt100 for 99%.
+
+# we want to survive hangups
+# note that the default setting is off now!
+autodetach on
+
+# when we open a window, where shall its CWD be?
+chdir # without argument it's my $HOME
+
+echo -n "."
+# I hate nonexisting status lines! Force screen to believe me.
+#hardstatus off
+
+# now some Terminal setup:
+# Printing in the leftmost column is not save. We express that fact as :LP@:
+#
+# Emacs tends to smear it's highlighted status bar across the screen, producing
+# ugly areas of bright background, if termcap is'nt perfectly sober.
+# Give a little :ms@: in the termcap, this may help.
+#
+# And who invented the initialisation for facit terminals? We tell him that
+# we non't like smooth scroll, by specifying :ti=\E[?l:.
+# \E[?3l 80 Zeichen
+# \E[?3h 132 Zeichen
+# LP Last column Printable
+# \E[A cursor up
+# \E[B cursor down
+# \E[?4h smooth scroll
+# \E[?4l jump scroll
+# \E[%dL insert %d lines
+# \E[K clear to end of line
+# cs \E[%i%d;%dr for twist and xterm
+# ms@ Move in Standout mode is NOT save.
+# WS our private variable, it declares that the terminal can
+# be resized by an escape-sequence
+# The termcap statement takes 2 or three parameters. First parameter lists
+# which TERMCAPs are affected by this statement. Second we specify changes
+# in screen's view of that terminals. Third we may specify some capabilities
+# that user-programs want to see in the $TERMCAP environment variable or in
+# screen's termcap entry.
+termcap vt* cl=\E[H\E[J\E[?1h:vi=\E[?35h:ve=\E[35l:ti=\E[?4l[vt100]
+termcap facit ti=\E[?4l[facit]
+termcap xterm* is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l:Z0=\E[?3h:Z1=\E[?3l
+
+echo -n "."
+# "\E(B", "\E(0", "\E(1", "\E(2", ... to switch between charsets.
+# screen internally emulates G1: "\E)..", G2: "\E*..", G3: "\E+.."
+# you can switch between them, with:
+#
+# code | switch to
+# ------+------
+# ^O | G0
+# ^N | G1
+# \En | G2
+# \Eo | G3
+#termcap facit|vt100|xterm* G0
+
+# how do we resize windows? under sunview, this is standard, but xterm
+# needs to be a specially hacked xterm, to make this work.
+termcap xterm* WS=\E[8;%d;%dt
+
+# ICL 6402 testing:
+termcap icl* G0:S0=\E$[start]:E0=\E%[end]:C0=j9k<l6m3n?q\:t7u=v;w>x5 GS=\E(0^O:GE=\E(B^O:G1=k:G2=l:G3=m:G4=j:GV=x:GH=q:GR=u:GL=t:GU=w:GD=v:GC=n
+
+# Flowcontrol produces trouble. ^S und ^Q will never reach screen, as our
+# terminals catch them locally. Who can explain that to me?:
+#flow on|off|auto [interrupt]
+
+# Long Lines get wrapped around (the back of your terminal). This is the
+# default for vt100. But now programs make different asumptions about your
+# terminal. You may find two linefeeds where you'd expect one, or you may
+# be confronted with a truncated line. Currently there is no fix, but pressing
+# C-A r and doing a redraw.
+#wrap on
+
+# the autoaka allows you to see the currently executing shell command in the
+# window name field. To use that, your shell prompt must contain ^[k^[\ or
+# you will see the string "(init)" as a name.
+# in my .cshrc I may use this for a wonderfull tcsh-prompt:
+# set prompt="%{^[k^[\\%}%h %c2(%m)%# "
+#
+# defining a shellaka that contains a pipe-symbol (|) activites the
+# autoaka feature. To the left of that | you specify a constant part of
+# your prompt as a trigger, to the right you may place a default string
+# as in
+shellaka '> |tc'
+# but beware! specifying a window name with the -t option has priority over
+# the autoaka mechanism. Although specifying -t "> |foo" will work.
+# shellaka tc
+
+# ... now a little bit of key bindings
+# In case we don't have write permission for /etc/utmp (no s-bit)
+# we create even local windows via rlogin. -> Et voila: a utmp-slot
+# utmp-slots are strongly recomended to keep sccs and talk happy.
+# (thus we have ^A# or. ^Ac for windowcreation with or without utmp-slot.)
+# but if we run suid-root, we produce all the rlogins with -ln,
+# as nobody shall refer to these pty's.
+bind '!' screen -ln -k faui41 rlogin faui41
+bind '@' screen -ln -k vme2 rlogin faui4_vme2
+#bind '#' screen -k faui43
+bind '#' screen -ln -k faui43 rlogin faui43
+bind '$' screen -ln -k faui44 rlogin faui44
+bind '%' screen -ln -k faui45 rlogin faui45
+bind '\^' screen -ln -k sup1 rlogin fausup1
+bind '&' screen -ln -k sup2 rlogin fausup2
+bind '*' screen -ln -k faui48 rlogin faui48
+bind '(' screen -ln -k faui09 rlogin faui09
+bind ')' screen -ln -k faui10 rlogin faui10
+bind 'J' screen -ln -k 4j rlogin faui4j
+bind 'P' screen -ln -k 4p rlogin faui4p
+bind '^C' screen -ln -k 45c rlogin faui45c
+bind '^D' screen -ln -k 45d rlogin faui45d
+bind '^E' screen -ln -k 45e rlogin faui45e
+bind '^I' screen -ln -k 45i rlogin faui45i
+
+# these two are logIn and logOut. As a toggle is too stupid.
+#bind 'I' set login on
+#bind 'O' set login off
+bind 'L'
+
+# What happens, when you 'think emacs' and want to erase a whole
+# line? You type ^A^K right? Under screen it should be ^Aa^K. But...
+# killing the window would be a real punishment for a little mistyping.
+bind k #wow! I even amange to type ^Ak by accident.
+#bind ^k
+#bind K kill
+
+echo -n "."
+#screen 1:faui43 # My good old <nr>:<alias> syntax
+#screen -k faui43 # The way Wayne Davison thinks about it.
+#screen -ln -k faui43 # this one not logged in.
+#screen -ln 2:faui09 rlogin faui09 -l jnweiger
+
+# Finally another bonus feature for people using strange terminal settings like
+# different baud rate, etc. The next user will get standard settings
+# as ^[c is a reset sequence.
+#pow_detach_msg "" # is the default
+pow_detach_msg "c"
+echo "done."
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..94a9ed0
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/ChangeLog b/ChangeLog
new file mode 100644
index 0000000..78280c1
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1,595 @@
+Version 4.6.2 (23/10/2017):
+ * Fixes:
+ - revert changes to cursor position restore behavour (bug #51832)
+ - set freed pointer to NULL (bug #52133)
+ - documentation fixes
+ - fix windowlist crashes (bug #43054 & #51500)
+
+Version 4.6.1 (10/07/2017):
+ * Fixes:
+ - problems with starting session in some cases
+ - parallel make install
+ - segfault when querying info on nonUTF locale (bug #51402)
+
+Version 4.6.0 (28/06/2017):
+ * Update Unicode wide tables to 9.0 (bug #50044)
+ * Support more serial speeds
+ * Improved namespaces support
+ * Migrate from fifos to sockets
+ * Start viewing scrollback at first line of output (bug #49377)
+
+Version 4.5.1 (25/02/2017):
+ * Fixes:
+ - logfile permissions problem (CVE-2017-5618)
+ - SunOS build problem (bug #50089)
+ - FreeBSD core dumps (bug #50143)
+
+Version 4.5.0 (10/12/2016):
+ * Allow specifying logfile's name via command line parameter '-L'
+ * Fixes:
+ - broken handling of "bind u digraph U+" (bug #48691)
+ - crash with long $TERM (bug #48983)
+ - crash when bumping blank window
+ - build for AIX (bug #49149)
+ - %x improperly separating arguments
+ - install with custom DESTDIR (bug #48370)
+
+Version 4.4.0 (19/06/2016):
+ * Support up to 24 function keys
+ * Fix runtime issues
+ * 'logfile' command, starts logging into new file upon changing
+
+Version 4.3.1 (28/06/2015):
+ * Fix resize bug
+
+Version 4.3.0 (13/06/2015):
+ * Introduce Xx string escape showing the executed command of a window
+ * Implement dead/zombie window polling, allowing for auto reconnecting
+ * Allow setting hardstatus on first line
+
+ New Commands:
+ * 'sort' command sorting windows by title
+ * 'bumpleft', 'bumpright' - manually move windows on window list
+ * 'collapse' removing numbering 'gaps' between windows, by renumbering
+ * 'windows' command now accepts arguments for use with querying
+
+Version 4.2.1 (28/04/2014):
+ * allow for terminal with long $TERM (up to 32 characters)
+ * allow to use long logins
+ * documentation fixes
+ * runtime fixes
+
+Version 4.2.0 (17/04/2014):
+ New Commands:
+ * 'unbindall' to unbind all commands
+ * 'up', 'down', 'left', 'right' sub-commands for 'focus'
+ * 'rendition' to specify rendition to use in caption/hardstatus for
+ window-names that have bell/monitor/silence/so turned on.
+ * 'layout', with the following sub-commands
+ - 'title'
+ - 'number'
+ - 'autosave' ('autosave on' or 'autosave off')
+ - 'new'
+ - 'save' ('save <name>')
+ - 'select'
+ - 'next'
+ - 'prev'
+ - 'attach'
+ - 'show'
+ - 'remove'
+ - 'dump'
+ * 'group' for moving window(s) into a group.
+ * 'defmousetrack' and 'mousetrack', to turn on/off mouse-tracking for
+ displays. It's turned off by default. With mouse-tracking turned on, it's
+ possible to switch to a region ('focus') using mouse clicks. It's also
+ possible to select a text region in copy-mode using a mouse click to place
+ a mark and the scroll wheel to scroll through the buffer. Additional
+ features might be to allow clicking on window-titles in the caption to
+ switch to that window.
+ * All commands prefixed '@' are treated as 'quiet', i.e. '@'-prefixed commands
+ do not trigger any display messages.
+
+ Changed Commands:
+ * '-v' parameter to 'split' command for vertical splits.
+ * 'sorendition' deprecated in favour of 'rendition so'.
+ * 'digraph' can take a second parameter to specify custom digraphs. For
+ example,
+ 'digraph >= ≥' or 'digraph >= U+2265'
+ Using '0' as the second parameter will remove the digraph.
+ * 'stuff' will prompt for input if there's nothing to stuff.
+ * The argument to ":number" can be prefixed with '+' or '-' to use it as a
+ relative argument.
+ * '-g' parameter to 'windowlist' to show nested list of windows.
+ * '//group' parameter to 'screen' to create a grouped window.
+ * 'blankerprg' shows the currently set command on no argument.
+ * 'maxwin' can now be used to increase the number of maximum windows.
+
+ .screenrc:
+ * $PID expands to the PID of the screen session.
+ * $PWD expands to the current working directory of the session.
+ * $STY expands to the session name.
+ * Tilde-expansion in pathnames (e.g. for the 'source' command)
+ * C-style escapes can be used (e.g. "\n" to get a newline with 'stuff')
+ * '%p' in caption/hardstatus string expands to the PID of the backend, and
+ '%+p' expands to the PID of the frontend (display).
+ * '%S' in caption/hardstatus string expands to the session name.
+ * '%P' in the caption string evaluates to true if the region is in copy mode.
+ * '%E' in the caption string evaluates to true if the escape character has
+ currently been pressed.
+
+ Window List:
+ * Nested views when there are window groups (with 'windowlist -g').
+ * Press 'm' to toggle the most-recent view.
+ * Press 'g' to toggle nestedness.
+ * Press 'a' to view all windows in the list.
+ * Press '/' to search in the list.
+ * Press ',' and '.' to re-order windows in the list.
+ * Press 'K' to kill a window (requires confirmation).
+
+ Display List:
+ * Press 'd' to detach a display, 'D' to power-detach.
+
+ Others:
+ * Start using 'ChangeLog' for logging changes again.
+ * Terminfo update for 256-color support.
+ * Multiple input history (partially from Romain Francoise).
+ * vi-like fFtT;, searching in copy mode.
+ * In copy mode, search in reverse direction when 'N' is pressed.
+ * Tab-completion for command input.
+ * Some more readline-like bindings in input mode (e.g. ^W, ^D, ^P, ^N etc.)
+ * Fix displaying unicode characters in the caption/hardstatus on UTF8 locale.
+ * A revamped displays list (for 'displays' command)
+ * Increased default maximum number of windows from 40 to 100.
+ * Increased number color/attribute changes in caption/hardstatus string from 16 to 256.
+ * Some commands can be remotely queried using the -Q command-line flag.
+
+ In-Progress:
+ * Scripting support (thanks to Google Summer of Code 2009 project by Rui Guo)
+
+ Developers:
+ * Alexander Naumov <alexander_naumov@opensuse.org>
+ * Amadeusz Sławiński <amade@asmblr.net>
+ * Juergen Weigert <jw@suse.de>
+ * Michael Schroeder <mls@suse.de>
+ * Micah Cowan <micah@cowan.name>
+ * Sadrul Habib Chowdhury <sadrul@users.sourceforge.net>
+
+ Contributors:
+ * Clavelito <maromomo@hotmail.com>
+ * Dick <dick@mrns.nl>
+ * Gabriel <g2p.code@gmail.com>
+ * Benjamin Andresen <bandresen@gmail.com>
+ * Takeshi Banse <takebi@laafc.net>
+ * Maarten Billemont <lhunath@gmail.com>
+ * Curtis Brown <mrbrown8@juno.com>
+ * Cyril Brulebois <kibi@debian.org>
+ * Trent W Buck <trentbuck@gmail.com>
+ * Stephane Chazelas <stephane_chazelas@yahoo.fr>
+ * Kees Cook <kees@ubuntu.com>
+ * Thomas Dickey <tom@invisible-island.net>
+ * Christian Ebert <blacktrash@gmx.net>
+ * Geraint Edwards <gedge-lists-screen@yadn.org>
+ * Romain Francoise <romain@orebokech.com>
+ * Alexander Gattin <xrgtn@yandex.ru>
+ * Emanuele Giaquinta <e.giaquinta@glauco.it>
+ * Yi-Hsuan Hsin <mhsin@mhsin.org>
+ * Kipling Inscore <kinscore@synaptics.com>
+ * Chris Jones <cjns1989@gmail.com>
+ * Max Kalashnikov <mmt@maxkalashnikov.com>
+ * Steve Kemp <steve@steve.org.uk>
+ * Ryan Niebur <ryan@debian.org>
+ * Jan Christoph Nordholz <hesso@pool.math.tu-berlin.de>
+ * William Pursell <bill.pursell@gmail.com>
+ * Michael Scherer <misc@mandriva.org>
+ * Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+ * Peter Teichman <peter@teichman.org>
+
+30.10.94
+
+This is a quick overview of screen's life story. But it is not up
+to date. You'll find more details about the revision history in
+patchlevel.h and newer changes are only documented there.
+
+31.7.93 -- 3.5.1
+================
+
+* writelock, number, paste with arg, at, zombie and wall commands added.
+
+* Access Control Lists and more multi-user support added.
+
+* select and setenv commands enhanced.
+
+* socket.c: motorola bugfix.
+
+* configure.in: --srcdir support.
+
+* configure.in: recognize alpha and SUNOS3 correctly.
+
+* doc/screen.texinfo: Documentation by Jason Merrill.
+
+13.05.93 -- 3.3.3
+=================
+
+* defautonuke, silence commands added.
+
+* exec command added.
+
+* hardcopydir, logdir commands added.
+
+* Made a superb configure script.
+
+* BROKEN_PIPE, SOCK_NOT_IN_FS added for braindamaged systems.
+
+* multi display, multi user support.
+
+* process command. CS, CE switch cursorkeycap in application mode.
+
+* lockprg pow_detaches on SIGHUP
+
+* ins_reg copy_reg commands.
+
+* new screenrc syntax.
+
+* split up screen.c and ansi.c
+
+21.10.92 -- 3.2.9
+================
+
+* ChangeLog: replaces CHANGES and is in GNUish format.
+
+* Makefile (CFLAGS, M_CFLAGS, LIBS, OPTIONS): moved user config here,
+ merged all Makefiles, GNUified
+
+* socket.c (FindSocket): ignoring bad files in $SCREENDIR
+
+* config/config.linux: ported.
+
+* utmp.c, exec.c, loadav.c: split apart from screen.c/fileio.c
+
+15.07.92 -- 3.2.8
+=================
+
+* ansi.c (WriteString): automatic character set switching for 8bit support
+
+3.2.3-3.2.7
+===========
+
+* concept changes: Display structure, Multi attacher
+
+...
+
+3.2.2
+=====
+
+* screen.c (main): -m option, "_M_ake always new session", ignore $STY
+
+* screen.c (main): -Ssessionname
+* fileio.c (RcLine): ^A:sessionname give your session a nicer name.
+
+* screen.c (main): supporting detached startup via screen -d -m -Ssockname
+
+* fileio.c (stripdev): moved, could not compile
+
+* overlay.h: "stackable overlay concept"
+
+* search.c: vi-like / and ? search AND emacs-like ^S and ^R incremental search
+ in scrollback
+
+* mark.c: I meant BSDI not BSD
+
+* concept change: struct display and struct newwin introduced.
+
+* screen.c (main): -v option prints version.
+
+* screen.c (MakeWindow): ^A:screen /dev/ttya opens a character device
+ instead of forking ShellProg with a pty pair.
+
+3.2.0
+=====
+
+Ultrix port
+
+Irix 3.3 SGI port
+
+shadow password suite supported
+
+data loss on stdin overflow fixed
+
+"refresh off" keyword added.
+
+3.1.1
+------
+
+Screen is now under the GNU copyleft license. See file COPYING.
+
+command line option -A. $LINES, $COLUMNS improved.
+
+C-A : vbellwait <sec>
+
+XENIX support (Ronald Khoo)
+
+SYSV has uname() instead of gethostname().
+
+hpux has setresuid.
+
+ClearScreen now saves image to scrollback buffer.
+
+mips has setenv.
+
+numerous bugfixes.
+
+3.1 finally released version.
+=============================
+
+3.0.99: last minute changes:
+----------------------------
+
+MIPS support (J{rvinen Markku)
+
+SVR4 support (Marc Boucher)
+
+secopen() secfopen() calls replace stat/access/open.
+C-a : echo improved.
+'register int'
+
+Changes up to Screen 3.0 Patchlevel 7
+=====================================
+
+Better terminfo support: Screen now checks if a termcap/info
+entry which the name "screen.$TERM" does exist. Look in the
+"VIRTUAL TERMINAL" section of the manual for more details.
+
+Many security improvements.
+
+ScrollRegion() bug fixed which caused slow scrolling if AL
+or DL was used.
+
+Pyramid and Ultrix support added. (Tim and Larry)
+
+ENVIRONMENT support.
+ /local/etc/screenrc checks for $SYSSCREENRC
+ $HOME/.screenrc checks for $ISCREENRC and $SCREENRC
+ /local/screens checks for $ISCREENDIR and $SCREENDIR
+ .screenrc understands ${VAR} and $VAR .
+
+screen 3.0 Patchlevel 6
+=======================
+
+.screenrc:
+ screen now only opens the windows you explicitly ask for. if you
+ specify none, you still get one window, of course.
+
+screen 3.0. Patchlevel 5
+========================
+
+Ansi prototyping by Christos.
+
+copy mode: CTRL-U / CTRL-D exchanged. code cleanup.
+
+changes to screen 3.0 patchlevel 4
+==================================
+
+markkeys "string"
+ allows to rebind the keys used in copy/history mode.
+ string is made up of pairs "<oldchar>=<newchar>" which are separated
+ by a colon. Oldchar and newchar are either single ascii characters,
+ or the two character sequence ^x, where x is an ascii character, or
+ a 3 digit octal value prepended with '\'. the string "\040=.:^M=q"
+ rebinds '.' to set marks, and the return rey will abort copy mode.
+
+set scrollback 100
+ resizes the scrollback history buffer to 100 lines. a default of 50
+ is installed.
+
+A Howard Chu like scrollback history is installed. Many vi-like keys
+ are added to the copy mode. The '?' key reports on cursor position.
+
+screen 3.0 Patchlevel 3
+=======================
+
+WriteString fixed, it did kill the display variable.
+
+Yet another LP bugfix.
+
+non vt100 semi-graphics character support.
+
+waynes patch fixed
+
+screen 3.0 Patchlevel 2
+=======================
+
+wayne patches cursor motion outside scrollregions.
+
+.screenrc
+ monitor on|off
+
+changes in Screen 3.0 Patchlevel 1
+==================================
+
+screen -wipe
+
+^A : set vbell_msg "Wuff Wuff"
+
+Thousand enhancements: help resizible, copy'n'paste in main
+ socket loop, and no more '\0' hackin'. :WS=\E8;%d;%dt:
+
+screen can now resize windows under sunview.
+
+^A : set crlf on|off
+ effects markroutine join.
+
+screen learned about sized windows under X
+
+screen -ls (-d) -q
+ quiet option. We count the number of detached (attached) sessions and set
+ a return value of 10+n. The -q option inhibits all startup
+ warnings/messages. i.e. screen -R -q may return with code 12 or higher
+ or start a new/old session.
+
+pow_detach_msg "text string"
+ new command, allows messages, terminal reset, etc. on logout caused
+ by pow_detach.
+
+^A : learned a new keyword "set":
+ commands like "login on" , "vbell off", ... affect the default for
+ windows to be created. But commands like "set login off" affect
+ the actual setting of this window. and not the default.
+ such commands may be bound to keys. example:
+ bind 'O' set login off
+ is valid in your .screenrc as well as typed at the ':' prompt.
+ a bonus is ":set all" which is synonym to ":help".
+ At the Colon prompt also KeyNames can be entered, alothough that makes
+ not always sense.
+
+^A x uses a builtin lockprg, if
+ a) we don't find our lockprg, or
+ b) user supplies us with the environmet variable LOCKPRG set to "builtin"
+ the builtin locks until your login password is typed. on systems using
+ "shadow password files" you are prompted for a password.
+
+markroutine can append joined.
+
+screen removes the "controlling tty" from utmp while ptys are attached.
+
+markroutine performs CR+NL when '\n' is pressed
+
+screen may die quietly, when no TERMCAP entry for "screen" is
+found, and screen is run under X-windows
+
+_SEQUENT_ marks sequent386_ptx
+
+screen runs now under SunOS4.1.1 (we need setsid()!).
+
+bug in SetForeWindow fixed.
+
+rare markroutine bug fixed.
+
+we dont open every file the attacher tells us.
+
+we have now our wonderful "Wuff, Wuff" visual_bell
+
+we have now the interprocess-communication-buffer. secure version.
+
+'^A =' removes the interprocess-communication-buffer.
+
+markroutine as in 2.1
+
+markroutine: 'a' toggles append mode,
+ '>' like ' ', but immediately WriteFile(DUMP_EXCHANGE) then.
+ 'A' like ' ', but first switch to append mode.
+
+.screenrc understands "screen 2:faui09 rlogin faui09 -l jnweiger"
+ and "password none"
+ and "vbell [on|off]"
+
+'^A :' allows .screenrc commands "online".
+
+screen now receives new $TERM from attacher, when it is reattached
+
+MakeClientSocket() fifo version does now test for access.
+
+.screenrc learns "hardstatus {on|off}"
+
+termcap's VB is used for vbell if available.
+
+Attach() code rewritten:
+ screen now lists socket directory, if it does not find a suitable socket
+ screen -d [host.tty] detaches a running screen.
+
+screen -[ls|list]
+ list all sockets that we find in our sockdir
+
+when the socket has been removed, send a SIGCHLD to the poor SCREEN
+process and it will try to recover. then try a 'screen -r' again.
+all the socket stuff lives now in an extra file.
+
+Major changes in version 2.4:
+=============================
+
+* Test version that presents the erlangen extensions from 2.0 in a 2.3
+ screen.
+
+* window resize support
+
+* screen locking C-a x
+
+* support for SYSV
+
+* password protection
+
+* copy & paste across screens
+
+* remote detach and power detach
+
+Major changes in version 2.3:
+
+* Terminal emulation has been significantly enhanced and bugfixed.
+
+* We now fully update the last character on the screen for true auto-
+ margin terminals, though there may be some delay before the character
+ can be safely added to the screen. If your terminal has character
+ insert it will be used to shorten the delay.
+
+* Added the "termcap" .screenrc command to tweak your terminal's termcap
+ entry AND to customize the termcap generated for the virtual terminals.
+ See also the -L and -O command-line options, and the SCREENCAP environ-
+ ment variable.
+
+* Fixed screen's character handling when detached or suspended to NOT block
+ the child processes in their windows -- output continues to be processed
+ in the background.
+
+* Added a.k.a.s (window-name aliases) that allow you to customize the
+ window-information line, including being able to change the name on-
+ the-fly to reflect what's currently running in the window (see the
+ -k option, shellaka command, and ALSO KNOWN AS discussion in the doc).
+
+* Added the ability to log the output of a window to a file (see the
+ "C-a H" (log) command).
+
+* Flow-control can now be set for each window and switched interactively
+ (see the "flow" command, -f option, and FLOW CONTROL discussion).
+
+* Individual windows can be included or excluded from mention in the
+ /etc/utmp file (see the "login" command and -l option).
+
+* Added an activity monitor, which allows you to have a window watched for
+ the start of any output and alert you when it occurs (see the "C-a M"
+ (monitor) command).
+
+* Enhanced the information in the window-information line to keep track of
+ windows that have: logging turned on '(L)'; beeped in the background '!';
+ became active while being monitored '@' (see the "C-a w" (windows) command).
+
+* Added an on-line help display that lists all the commands and their
+ key bindings (see the "C-a ?" (help) command).
+
+* Extended handling of the beep message (and also the new activity message)
+ to allow '~' to specify a literal beep (see the "beep" and "activity"
+ .screenrc commands).
+
+* You can now set the default action on receipt of a hangup signal: detach
+ or terminate (see the "autodetach" .screenrc command).
+
+* Routing of characters to their virtual terminals has been enhanced to
+ not drop characters nor (in rare circumstances) hang up screen.
+
+* The NFS compatibility has been enhanced.
+
+Major changes in version 2.0a:
+
+* Screen allows you to `detach' the "screen" session from the physical
+ terminal and resume it at a later point in time (possibly on a
+ different terminal or in a different login session).
+
+ To get an impression of this functionality do the following:
+
+ - call "screen" and create a couple of windows
+ - type Control-A Control-D (screen terminates; you are back
+ in the shell)
+ - call "screen -r" to resume the detached screen
+
+* Screen supports multiple character sets and the ISO 2022 control
+ functions to designate and switch between character sets.
+ This allows you, for instance, to make use of the VT100 graphics
+ character set or national character sets.
diff --git a/FAQ b/FAQ
new file mode 120000
index 0000000..1ad45dd
--- /dev/null
+++ b/FAQ
@@ -0,0 +1 @@
+doc/FAQ \ No newline at end of file
diff --git a/HACKING b/HACKING
new file mode 100644
index 0000000..b78d40f
--- /dev/null
+++ b/HACKING
@@ -0,0 +1,39 @@
+WIP notes on hacking the Screen source.
+
+* Screen commands are handled by the DoAction function in process.c.
+ The local variable nr is set to an integer value representing the
+ command to be evaluated; for every command `foo', there is an
+ integer value RC_FOO for use as nr's value to represent it. Find
+ the matching case label to follow procesing of the command.
+
+ The RC_FOO values are defined in comm.h, which is automatically
+ generated by comm.sh, based on the names of the commands
+ themselves (found in comm.c).
+
+* The current display is held in the global variable "display".
+ Variable names like D_foo are shorthands for display->d_foo (where d_foo
+ is a member of "struct display").
+
+* Names like D_IS, D_TI, D_SG usually refer to the values of various
+ termcap features of the current display. These are found in term.h,
+ which is automatically generated from term.c by term.sh.
+
+* The main input-reading function for handling user input from a display,
+ is disp_readev_fn in display.c. This also handles automatic transformation
+ of mouse-tracking codes from display coordinates to screen-window
+ coordinates, and decodes characters from the display's encoding, passing
+ it on to the foreground input processor.
+
+ Input is passed through ProcessInput in process.c to handle
+ keybindings (specified by bindkey and such), and then processed by
+ layer-specific input-processing functions, which you'll find in
+ instances of struct LayFuncs. For instance, keystrokes are processed
+ by:
+
+ normal windows: WinPrGocess
+ window in copy-mode: MarkProcess
+ window list: WListProcess
+ command input line: InpProcess
+
+* Handling string escapes (in hardstatus and the like), such as %w or
+ %{= bw}, is done in screen.c, MakeWinMsgEv().
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..3ad58a1
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,114 @@
+Installation of GNU screen.
+
+
+0.) This instruction is quite lengthy
+-------------------------------------
+... and there are still important items near the end. Start here:
+Unpack. Screen comes as a compressed tar archive. You need gzip to
+uncompress. And... well, you probably already managed that step,
+when you are reading this.
+
+For general documentation on the coding and usage standards this
+distributions follows, see the GNU standards document on
+https://www.gnu.org/prep/standards/, especially the `Makefile
+Conventions', `Configuration', and `User Interfaces' sections.
+
+0.) autogen.sh
+--------------
+First, run ./autogen.sh. This will create configure file that you can use.
+This should be already done, so you can skip this step.
+
+1.) configure & config.status
+-----------------------------
+Run ./configure. This should create a reasonable Makefile and a config.h file
+suited for your machine. Rename config.status to reflect the architecture
+(hostname) where it was built. To reconfigure quickly for that architecture
+just run that config.status file.
+If this process fails, try to find out what configure did do and what it
+should have checked.
+And then please report a bug (https://savannah.gnu.org/bugs/?group=screen
+or mail screen-devel@gnu.org).
+Actually the initial Makefile that comes with the distribution just runs
+configure -- thus you can start by typing 'make' right after unpacking.
+You will be prompted to run 'make' again, which will really make screen.
+
+2.) Makefile & config.h
+-----------------------
+Look through the Makefile & user configuration section in config.h and check
+pathnames. Change them to suit your installation requirements. Usually
+sysadmins discuss the location of SOCKDIR, whether it should be in /tmp or
+not. At least it must be on a filesystem that supports sockets/fifos.
+SOCKDIR must not point into an AFS (Andrew File System) mounted directory.
+If you are uncertain about your NFS implementation, use a UFS directory for
+SOCKDIR. Personally, I favour a users home directory and recommend the the
+/tmp/ area.
+The path for ETCSCREENRC may also need to be adapted.
+
+3.) how to actually compile
+---------------------------
+Run 'make'. Screen should compile without too many warnings :)
+The creation of term.h, comm.h, tty.c or osdef.h may fail on some machines
+for some odd reason. (E.g. the sed under SCO-unix is known to be
+case-insensitive and breaks term.h.) If so, please mail a short description
+of the problem to screen-devel@gnu.org and use the files ending in .dist
+as a replacement (or in case of osdef.h retry with an empty file).
+You can then try 'make install' (if you dare).
+
+4.) where to install
+--------------------
+You may well run screen from your private binary directory and with a
+private socket directory like $HOME/.screen. But to have a full featured
+screen and (from a users point of view) more secure pty's you should
+consult a system administrator and discuss installing screen setuid-root
+in some globally accessible directory like /usr/local/bin.
+
+Consider this, when deciding whether you install screen setuid-root:
+- On some machines root privileges are required to open pty's.
+- Pty's should be owned by the user, so that she can do chmod to prevent
+ intruder attacks. The PTYs used by screen will remain world read-writable
+ if screen is not installed setuid-root.
+- Some commands only work properly when the pty is owned by the user.
+ These include mesg and biff.
+- The ^At feature may need to lseek and read the kernel file to retrieve
+ the load average.
+- On most machines utmp slots can only be created/manipulated with root
+ privileges. Users will appear to be logged on the primary terminal
+ instead of the screen windows, if screen is not installed setuid-root.
+- Multi-user screen sessions are only allowed when screen has a root-s-bit.
+- If screen sockets of multiple users are kept in one directory (e.g.
+ /tmp/screens), this directory must be world writable when screen is not
+ installed setuid-root. Any user can remove or abuse any socket then.
+
+
+5.) doc/screen.1 & doc/screen.texinfo
+-------------------------------------
+The man page doc/screen.1 should go to /usr/local/man/man1, or some similar
+directory. It should format nicely with nroff -man. If it does not, then
+try removing extra dots with: sed -e 's/^\.\././' < screen.1 | nroff -man
+The info page doc/screen.texinfo contains basically the same information as
+the man-page, we may have missed one or another thing in one of the files.
+If so, mail me.
+
+6.) etc/screenrc & etc/etcscreenrc
+----------------------------------
+The files screenrc and etc/etcscreenrc are instructive samples that
+demonstrate what can/should be done from your private .screenrc and from
+$ETCSCREENRC -- do not just copy them. Read them. Look through the
+etcscreenrc file for system wide defaults that you like to set. e.g.
+autodetach off, startup_message off, vbell on, ...
+Since version 3.2.15 the screenrc file syntax changed slightly. All rc files
+from previous versions should be run through the 'newsyntax' script that comes
+with this package.
+If and only if you want to install screen as a console multiplexer, look
+at the *.sample files and what 'make cscreen' suggests.
+
+7.) terminfo/screeninfo.src & terminfo/screencap
+------------------------------------------------
+Every now and then we update the termcap/terminfo entries for screen.
+E.g. keycodes were added in 3.6.0 -- thus you check that your termcap/terminfo
+database is up to date. See the README in the terminfo subdirectory.
+
+8.) have fun
+------------
+To get an idea what the basic screen commands are, read the file README.
+Request snail mail address for liquid and solid donations. :-)
diff --git a/Makefile.in b/Makefile.in
new file mode 100644
index 0000000..08b44d3
--- /dev/null
+++ b/Makefile.in
@@ -0,0 +1,356 @@
+#
+# Makefile template for screen
+#
+# See machine dependant config.h for more configuration options.
+#
+
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+DESTDIR =
+
+# Where to install screen.
+
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+datarootdir = @datarootdir@
+datadir = @datadir@
+
+# don't forget to change mandir and infodir in doc/Makefile.
+bindir = $(exec_prefix)/bin
+
+VERSION = @VERSION@
+SCREEN = screen-$(VERSION)
+
+GIT_REV =
+DEFS = @DEFS@ -DGIT_REV=\"$(GIT_REV)\"
+
+ETCSCREENRC = @ETCSCREENRC@
+ifeq (${ETCSCREENRC}, )
+ETCSCREENRC=$(prefix)/etc/screenrc
+endif
+SCREENENCODINGS = $(datadir)/screen/utf8encodings
+
+CC = @CC@
+CFLAGS = @CFLAGS@
+CPPFLAGS = @CPPFLAGS@ -DETCSCREENRC='"$(ETCSCREENRC)"' \
+ -DSCREENENCODINGS='"$(SCREENENCODINGS)"'
+LDFLAGS = @LDFLAGS@
+LIBS = @LIBS@
+
+CPP=@CPP@
+CPP_DEPEND=$(CC) -MM
+
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_DATA = @INSTALL_DATA@
+
+AWK = @AWK@
+
+### Chose some debug configuration options:
+# -DDEBUG
+# Turn on really heavy debug output. This is written to
+# /tmp/debug/{SCREEN,screen}.<pid>. Look at these files and quote
+# questionable sections when sending bug-reports to the author.
+# -DDUMPSHADOW
+# With shadow-pw screen would never dump core. Use this option if
+# you still want to have a core. Use only for debugging.
+OPTIONS=
+#OPTIONS= -DDEBUG
+
+SHELL=/bin/sh
+
+CFILES= screen.c ansi.c fileio.c mark.c misc.c resize.c socket.c \
+ search.c tty.c term.c window.c utmp.c loadav.c putenv.c help.c \
+ termcap.c input.c attacher.c pty.c process.c display.c comm.c \
+ kmapdef.c acls.c braille.c braille_tsi.c logfile.c layer.c \
+ sched.c teln.c nethack.c encoding.c canvas.c layout.c viewport.c \
+ list_display.c list_generic.c list_window.c
+OFILES= screen.o ansi.o fileio.o mark.o misc.o resize.o socket.o \
+ search.o tty.o term.o window.o utmp.o loadav.o putenv.o help.o \
+ termcap.o input.o attacher.o pty.o process.o display.o comm.o \
+ kmapdef.o acls.o braille.o braille_tsi.o logfile.o layer.o \
+ list_generic.o list_display.o list_window.o \
+ sched.o teln.o nethack.o encoding.o canvas.o layout.o viewport.o
+
+all: screen
+
+screen: $(OFILES)
+ $(CC) $(LDFLAGS) -o $@ $(OFILES) $(LIBS)
+
+.c.o:
+ $(CC) -c -I. -I$(srcdir) $(M_CFLAGS) $(CPPFLAGS) $(DEFS) \
+ $(OPTIONS) $(CFLAGS) $<
+
+install_bin: .version screen installdirs
+ -if [ -f $(DESTDIR)$(bindir)/$(SCREEN) ] && [ ! -f $(DESTDIR)$(bindir)/$(SCREEN).old ]; \
+ then mv $(DESTDIR)$(bindir)/$(SCREEN) $(DESTDIR)$(bindir)/$(SCREEN).old; fi
+ $(INSTALL_PROGRAM) screen $(DESTDIR)$(bindir)/$(SCREEN)
+ -chown root $(DESTDIR)$(bindir)/$(SCREEN) && chmod 4755 $(DESTDIR)$(bindir)/$(SCREEN)
+# This doesn't work if $(bindir)/screen is a symlink
+ -if [ -f $(DESTDIR)$(bindir)/screen ] && [ ! -f $(DESTDIR)$(bindir)/screen.old ]; then mv $(DESTDIR)$(bindir)/screen $(DESTDIR)$(bindir)/screen.old; fi
+ rm -f $(DESTDIR)$(bindir)/screen
+ (cd $(DESTDIR)$(bindir) && ln -f -s $(SCREEN) screen)
+ cp $(srcdir)/utf8encodings/?? $(DESTDIR)$(SCREENENCODINGS)
+
+###############################################################################
+install: installdirs install_bin
+ cd doc ; $(MAKE) install
+ -if [ -d $(DESTDIR)/usr/lib/terminfo ]; then \
+ PATH="$$PATH:/usr/5bin" tic ${srcdir}/terminfo/screeninfo.src; \
+ chmod 644 $(DESTDIR)/usr/lib/terminfo/s/screen*; \
+ fi
+# Better do this by hand. E.g. under RCS...
+# cat ${srcdir}/terminfo/screencap >> /etc/termcap
+ @echo "termcap entry (${srcdir}/terminfo/screencap) should be installed manually."
+ @echo "You may also want to install $(srcdir)/etc/etcscreenrc in" $(ETCSCREENRC)
+
+installdirs:
+# Path leading to ETCSCREENRC and Socketdirectory not checked.
+ $(srcdir)/etc/mkinstalldirs $(DESTDIR)$(bindir) $(DESTDIR)$(SCREENENCODINGS)
+ cd doc ; $(MAKE) installdirs
+
+uninstall: .version
+ rm -f $(DESTDIR)$(bindir)/$(SCREEN)
+ rm -f $(DESTDIR)$(bindir)/screen
+ -mv $(DESTDIR)$(bindir)/screen.old $(DESTDIR)$(bindir)/screen
+ rm -f $(DESTDIR)$(ETCSCREENRC)
+ cd doc; $(MAKE) uninstall
+
+shadow:
+ mkdir shadow;
+ cd shadow; ln -s ../*.[ch] ../*.in ../*.sh ../configure ../doc ../terminfo ../etc .
+ rm -f shadow/term.h shadow/tty.c shadow/comm.h shadow/osdef.h
+ echo "install all Makefiles and config:" > shadow/Makefile
+ echo " rm -f config.cache" >> shadow/Makefile
+ echo " sh ./configure" >> shadow/Makefile
+
+term.h: term.c term.sh
+ AWK=$(AWK) srcdir=$(srcdir) sh $(srcdir)/term.sh
+
+kmapdef.c: term.h
+
+tty.c: tty.sh
+ sh $(srcdir)/tty.sh tty.c
+
+comm.h: comm.c comm.sh config.h
+ AWK=$(AWK) CC="$(CC) $(CFLAGS)" srcdir=${srcdir} sh $(srcdir)/comm.sh
+
+osdef.h: osdef.sh config.h osdef.h.in
+ CPP="$(CPP) $(CPPFLAGS)" srcdir=${srcdir} sh $(srcdir)/osdef.sh
+
+docs:
+ cd doc; $(MAKE) dvi screen.info
+
+dvi info screen.info:
+ -cd doc; $(MAKE) $@
+
+mostlyclean:
+ rm -f $(OFILES) screen config.cache osdef0.c osdef1.sed osdef2.sed
+
+clean celan: mostlyclean
+ rm -f tty.c term.h comm.h osdef.h kmapdef.c core
+
+# Delete all files from the current directory that are created by
+# configuring or building the program.
+# building of term.h/comm.h requires awk. Keep it in the distribution
+# we keep config.h, as this file knows where 'make dist' finds the ETCSCREENRC.
+#distclean: mostlyclean
+# rm -f $(SCREEN).tar $(SCREEN).tar.gz
+# rm -f config.status Makefile
+# rm -f osdef.h doc/Makefile
+
+maintainer-clean:
+ @echo "This command is not even intended for maintainers to use;"
+ @echo "it deletes files that may require special tools to rebuild."
+
+
+# Delete everything from the current directory that can be
+# reconstructed with this Makefile.
+realclean: .version mostlyclean
+ rm -f $(SCREEN).tar $(SCREEN).tar.gz
+ rm -f config.status Makefile doc/Makefile
+ rm -f tty.c term.h comm.h osdef.h kmapdef.c
+ rm -f config.h
+ echo "install all Makefiles and config:" > Makefile
+ echo " sh ./configure" >> Makefile
+
+tags TAGS: $(CFILES)
+ -ctags *.sh $(CFILES) *.h
+ -etags *.sh $(CFILES) *.h
+
+dist: .version $(SCREEN).tar.gz
+
+$(SCREEN).tar: .version term.h comm.h tty.c kmapdef.c
+ -rm -rf dist
+ mkdir dist
+ mkdir dist/$(SCREEN)
+ ln acls.h ansi.h display.h extern.h logfile.h mark.h os.h \
+ layer.h patchlevel.h screen.h window.h image.h \
+ osdef.h.in term.sh tty.sh comm.sh osdef.sh braille.h \
+ sched.h \
+ $(CFILES) \
+ ChangeLog COPYING INSTALL NEWS* TODO install.sh \
+ dist/$(SCREEN)
+ cd dist/$(SCREEN); mv tty.c tty.c.dist
+ cd dist/$(SCREEN); mv kmapdef.c kmapdef.c.dist
+ ln configure.in configure dist/$(SCREEN)
+ sed -e 's@"/local/screens@"/tmp/screens@' -e 's@"/local@"/usr/local@g' < config.h.in > dist/$(SCREEN)/config.h.in
+ sed -e 's@[ ]/local@ /usr/local@g' -e 's/^CFLAGS = -g/CFLAGS = -O/' < Makefile.in > dist/$(SCREEN)/Makefile.in
+ ln term.h dist/$(SCREEN)/term.h.dist
+ ln comm.h dist/$(SCREEN)/comm.h.dist
+ ln README dist/$(SCREEN)/README
+ mkdir dist/$(SCREEN)/terminfo
+ cd terminfo; ln 8bits README checktc.c screencap \
+ screeninfo.src test.txt tetris.c \
+ ../dist/$(SCREEN)/terminfo
+ mkdir dist/$(SCREEN)/etc
+ cd etc; ln * ../dist/$(SCREEN)/etc
+ mkdir dist/$(SCREEN)/utf8encodings
+ cd utf8encodings; ln * ../dist/$(SCREEN)/utf8encodings
+ # sed -e 's/^startup/#startup/' -e 's/^autodetach/#autodetach/' < $(ETCSCREENRC) > dist/$(SCREEN)/etc/etcscreenrc
+ cp $(HOME)/.screenrc dist/$(SCREEN)/etc/screenrc
+ mkdir dist/$(SCREEN)/doc
+ sed -e 's@/local/emacs@/usr/local@g' < doc/Makefile.in > dist/$(SCREEN)/doc/Makefile.in
+ cd doc; ln FAQ README.DOTSCREEN screen.1 screen.texinfo fdpat.ps make.help window_to_display.ps \
+ ../dist/$(SCREEN)/doc
+ cd doc; if test -f screen.info; then ln screen.info* \
+ ../dist/$(SCREEN)/doc; fi
+ cd dist/$(SCREEN)/doc; ln -s ../install.sh .
+ cd dist/$(SCREEN); ln -s doc/FAQ .
+ echo "install all Makefiles and config:" > dist/$(SCREEN)/Makefile
+ echo " rm -f config.cache" >> dist/$(SCREEN)/Makefile
+ echo " sh ./configure" >> dist/$(SCREEN)/Makefile
+ cd dist; tar cf ../$(SCREEN).tar $(SCREEN)
+ rm -rf dist
+
+$(SCREEN).tar.gz: $(SCREEN).tar
+ gzip -nf $(SCREEN).tar || gzip -f $(SCREEN).tar
+
+# Perform self-tests (if any).
+check:
+
+lint:
+ lint -I. $(CFILES)
+
+saber:
+ #load $(CFLAGS) screen.c ansi.c $(LIBS)
+
+config:
+ rm -f config.cache
+ sh ./configure
+
+
+###############################################################################
+
+.version:
+ @rev=`sed < $(srcdir)/patchlevel.h -n -e '/#define REV/s/#define REV *//p'`; \
+ vers=`sed < $(srcdir)/patchlevel.h -n -e '/#define VERS/s/#define VERS *//p'`; \
+ pat=`sed < $(srcdir)/patchlevel.h -n -e '/#define PATCHLEVEL/s/#define PATCHLEVEL *//p'`; \
+ if [ "$${rev}.$${vers}.$${pat}" != "$(VERSION)" ]; then \
+ echo "This distribution is screen-$${rev}.$${vers}.$${pat}, but"; \
+ echo "the Makefile is from $(VERSION). Please update!"; exit 1; fi
+
+###############################################################################
+
+mdepend: $(CFILES) term.h
+ @rm -f DEPEND ; \
+ for i in ${CFILES} ; do \
+ echo "$$i" ; \
+ echo `echo "$$i" | sed -e 's/.c$$/.o/'`": $$i" `\
+ cc -E $$i |\
+ grep '^# .*"\./.*\.h"' |\
+ (sort -t'"' -u -k 2,2 2>/dev/null || sort -t'"' -u +1 -2) |\
+ sed -e 's/.*"\.\/\(.*\)".*/\1/'\
+ ` >> DEPEND ; \
+ done
+
+
+depend: depend.in
+ ./config.status || ./configure
+
+depend.in: $(CFILES) term.h
+ cp Makefile.in Makefile.in~
+ sed -e '/\#\#\# Dependencies/q' < Makefile.in > tmp_make
+ for i in $(CFILES); do echo $$i; $(CPP_DEPEND) $$i >> tmp_make; done
+ mv tmp_make Makefile.in
+
+###############################################################################
+
+### Dependencies:
+screen.o: layout.h viewport.h canvas.h screen.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h braille.h \
+ patchlevel.h logfile.h extern.h
+ansi.o: layout.h viewport.h canvas.h ansi.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h braille.h extern.h \
+ logfile.h
+fileio.o: layout.h viewport.h canvas.h fileio.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h
+mark.o: layout.h viewport.h canvas.h mark.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h mark.h extern.h
+misc.o: layout.h viewport.h canvas.h misc.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h
+resize.o: layout.h viewport.h canvas.h resize.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h
+socket.o: layout.h viewport.h canvas.h socket.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h
+search.o: layout.h viewport.h canvas.h search.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h mark.h extern.h
+tty.o: layout.h viewport.h canvas.h tty.c config.h screen.h os.h osdef.h ansi.h acls.h comm.h \
+ layer.h term.h image.h display.h window.h extern.h
+term.o: layout.h viewport.h canvas.h term.c term.h
+window.o: layout.h viewport.h canvas.h window.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h logfile.h
+utmp.o: layout.h viewport.h canvas.h utmp.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h
+loadav.o: layout.h viewport.h canvas.h loadav.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h
+putenv.o: layout.h viewport.h canvas.h putenv.c config.h
+help.o: layout.h viewport.h canvas.h help.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h list_generic.h
+termcap.o: layout.h viewport.h canvas.h termcap.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h
+input.o: layout.h viewport.h canvas.h input.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h
+attacher.o: layout.h viewport.h canvas.h attacher.c config.h screen.h os.h osdef.h ansi.h \
+ acls.h comm.h layer.h term.h image.h display.h window.h extern.h
+pty.o: layout.h viewport.h canvas.h pty.c config.h screen.h os.h osdef.h ansi.h acls.h comm.h \
+ layer.h term.h image.h display.h window.h extern.h
+process.o: layout.h viewport.h canvas.h process.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h logfile.h
+display.o: layout.h viewport.h canvas.h display.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h braille.h
+canvas.o: layout.h viewport.h canvas.h canvas.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h \
+ braille.h
+comm.o: layout.h viewport.h canvas.h comm.c config.h acls.h comm.h
+kmapdef.o: layout.h viewport.h canvas.h kmapdef.c config.h
+acls.o: layout.h viewport.h canvas.h acls.c config.h screen.h os.h osdef.h ansi.h acls.h comm.h \
+ layer.h term.h image.h display.h window.h extern.h
+braille.o: layout.h viewport.h canvas.h braille.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h braille.h
+braille_tsi.o: layout.h viewport.h canvas.h braille_tsi.c config.h screen.h os.h osdef.h ansi.h \
+ acls.h comm.h layer.h term.h image.h display.h window.h extern.h \
+ braille.h
+logfile.o: layout.h viewport.h canvas.h logfile.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h logfile.h
+layer.o: layout.h viewport.h canvas.h layer.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h
+sched.o: layout.h viewport.h canvas.h sched.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h logfile.h
+teln.o: layout.h viewport.h canvas.h teln.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h
+nethack.o: layout.h viewport.h canvas.h nethack.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h
+encoding.o: layout.h viewport.h canvas.h encoding.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h
+layout.o: layout.h viewport.h canvas.h layout.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h \
+ braille.h
+viewport.o: layout.h viewport.h canvas.h viewport.c config.h screen.h os.h osdef.h ansi.h acls.h \
+ comm.h layer.h term.h image.h display.h window.h extern.h \
+ braille.h
+list_generic.o: list_generic.h list_generic.c layer.h screen.h osdef.h
+list_display.o: list_generic.h list_display.c layer.h screen.h osdef.h
+list_window.o: list_generic.h list_window.c window.h layer.h screen.h osdef.h comm.h
+
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..ad502ef
--- /dev/null
+++ b/NEWS
@@ -0,0 +1,28 @@
+ ------------------------------
+ What's new in screen-4.0.3 ?
+ ------------------------------
+
+* zombie command has new option 'onerror'
+
+* buffer overflow in resize.c fixed
+
+* minor docu update
+
+* more robust startup
+
+* use setresuid; SendAttachMsg() for fd-passing added; DoCSI enhanced.
+
+ ------------------------------
+ What's new in screen-4.0.0 ?
+ ------------------------------
+
+* new screenrc parser, not 100% compatible.
+
+* screenblanker support: new 'idle', 'blanker', 'blankerprg'
+ commands.
+
+* zmodem support via the 'zmodem' command.
+
+* nonblock code rewritten, nonblock now understands a timeout.
+ new command 'defnonblock'.
+
diff --git a/NEWS.3.5 b/NEWS.3.5
new file mode 100644
index 0000000..74bb7bf
--- /dev/null
+++ b/NEWS.3.5
@@ -0,0 +1,119 @@
+
+ ----------------------------
+ What's new in screen-3.5 ?
+ ----------------------------
+
+
+* Texinfo manpage! Thanks to Jason Merrill.
+
+* Screen now has a very large 'configure' script. If you have
+ problems with the resulting configuration please send mail to
+ screen@uni-erlangen.de.
+
+* Stackable overlay planes.
+ All commands are available even if you work with an overlay. Thus
+ you can be in copy/paste mode on several windows!
+
+* Unification of key bindings and screen commands. All keys now generate
+ commands.
+
+* Screen now reads/writes only in asyncronous mode.
+
+* Ansi parser speedup code resulting in much faster output of text.
+
+* Changed the rc file syntax. Commands now directly affect the current
+ window. The default settings are changed with 'def...' commands.
+ The 'set' keyword no longer exists.
+ Please run the 'newsyntax' script on your old screenrc files!
+
+* Emacs style isearch added to copy mode. Try ^A ESC ^R screen ^R ^R
+ to locate the last three occurences of the word 'screen' in the
+ history buffer.
+
+* New command 'silence'. Alarms the user whenever there was inactivity
+ for a specified amount of time on a certain window.
+ Useful if you want to wait for a compilation to end.
+
+* Much better margin handling:
+ Screen now handles autowrapped lines correctly in the redisplay and
+ copy/paste functions.
+
+* New commands for pastebuffer management:
+ 'copy_reg' copies the pastebuffer to a register,
+ 'ins_reg' pastes a register,
+ 'register' fills a register with a string,
+ 'process' stuffs a register into strings input queue.
+
+* Autonuke feature. Flush the output buffer if the window gets
+ cleared. Enable this with 'autonuke on'.
+
+* Modifications to save memory: Empty attribute and font lines don't
+ get allocated. This is very useful if you have a lage scrollback.
+
+* Multi display support:
+ You can now attach from more than one terminal to a session with
+ the '-x' option.
+
+* New option '-S' to specify socket name.
+
+* Experimental multiuser support added:
+ You can start screen in multiuser Mode by prepending the socket
+ name with a '/' (or by the command 'multiuser on').
+ If another user wants to attach to the screen session, he can do
+ this by prepending the socketname with 'screenuser/'.
+ Of course he must be in the access control list for a successful
+ attach (see the acladd/acldel command).
+
+* Extension to the 'screen' command: You can now specify tty lines
+ instead of programs. This can be used for console management.
+ Added the command 'break' to send a break to the tty line.
+ Not really a new feature, but terminal initialisation now works
+ on suns.
+
+* Input/output filters added. This has been implemented to allow the
+ user to configure an open tty line, but got soon exended to allow
+ all sorts of filters. For more information read the explanation
+ of the 'exec' command in the man page and check the 'fdpat.ps'
+ document.
+
+* Screen can now be started detached (screen -d -m -S sockname).
+ This is useful if you want to start screen in your /etc/rc file
+ (e.g. as a console multiplexer)
+
+* Console grabbing added ('console on' command).
+
+* Windows can now be selected by akas, too. (Per default bound to the
+ >'< key.)
+
+* New terminal capabiliteise CS/CE for cursorkey control.
+
+* setenv/unsetenv commands added.
+
+* Expansion of environment variables ($VAR) and terminal capabilities
+ ($:TC:) in the screenrc files and detach messages.
+ Example: pow_detach_msg "Session of \$LOGNAME \$:cr:\$:nl:ended."
+
+* New commands:
+ 'hardcopydir' and 'logdir' to change the output directories,
+ 'partial' and 'allpartial' to make screen only refresh the line
+ containing the cursor if a window is selected (useful for slow
+ modem connections).
+
+* Cleanup of the provided termcap/terminfo file. Please install
+ the new one!
+
+* The program 'terminfo/checktc.c' does a visual check of a
+ termcap/terminfo entry. Please try it before calling screen and
+ in a screen session.
+
+* LOTS of bugfixes and code cleanup.
+
+Thanks to all the beta testers who helped porting screen to at least
+the following platforms: Ultrix, SunOS, Solaris, BSD43, linux, NEWSOS,
+Irix, OSF/1, Harris CX/UX, hpux, dynix/ptx, AIX.
+And even more thanks to the brave who attempted to use the 'exec'
+command features.
+
+ Donnate patches, bugreports, suggestions, money, beer & pizza to
+ screen@uni-erlangen.de
+
diff --git a/NEWS.3.6 b/NEWS.3.6
new file mode 100644
index 0000000..6d4360f
--- /dev/null
+++ b/NEWS.3.6
@@ -0,0 +1,48 @@
+
+ ----------------------------
+ What's new in screen-3.6 ?
+ ----------------------------
+
+* Input translation! This makes the vt100 emulation complete.
+ As an addition it is now possible to bind any command to any
+ (function-) key. See the man page for more details (bindkey
+ command).
+
+* Status line support. Each window can have a different status line.
+ Use the ANSI APC string to set the status line, i.e.:
+ <ESC>_<status string><ESC>\
+ (For convenience the xterm sequence is also accepted.)
+ You may want to add
+ termcap * '' ':hs:ts=\E_:fs=\E\\:ds=\E_\E\\:'
+ terminfo * '' ':hs:ts=\E_:fs=\E\\:ds=\E_\E\\:'
+ to your ~/.screenrc to make screen advertise the hardstatus
+ support.
+
+* Zombie feature added. Windows now may generate a message (with a
+ timestamp) if they die and stay around until the user presses
+ a key.
+
+* New paste syntax: Paste can now concatenate registers and paste
+ either on screen or in anouther register.
+ This makes the old "ins_reg", "copy_reg" commands obsolete.
+
+* More architecures supported. Screen now runs on AIX3.2.5,
+ Solaris, NeXT and some other exotic platforms.
+
+* Kanji support added. Screen understands JIS, EUC and SJIS coding.
+ This is an experimental feature.
+
+* GR charset switching (ISO 2022) implemented. Can be enabled with
+ the "gr" command.
+
+* C1 sequences implemented (see the "c1" command).
+
+* Tek support from Xiaoguang Zhang. Apply tek.patch if you want to
+ make screen pass tek sequences.
+
+* List of new commands:
+ bindkey, c1, command, defc1, defgr, defkanji, gr, kanji, mapdefault,
+ mapnotnext, maptimeout, pastefont, printcmd, readreg, stuff, zombie
+
+* Lots of other bugs fixed.
+
diff --git a/NEWS.3.7 b/NEWS.3.7
new file mode 100644
index 0000000..e398f95
--- /dev/null
+++ b/NEWS.3.7
@@ -0,0 +1,39 @@
+
+
+ ----------------------------
+ What's new in screen-3.7 ?
+ ----------------------------
+
+* Color support. Screen understands the following capabilities:
+ AF (setaf) = Set foreground color (ANSI compatible)
+ AB (setab) = Set background color (ANSI compatible)
+ AX = Does understand ANSI set default fg/bg color
+ (\E[39m / \E[49m)
+ The tweaks for the color xterm would be:
+ termcap xterm 'AF=\E[3%dm:AB=\E[4%dm'
+ terminfo xterm 'AF=\E[3%p1%dm:AB=\E[4%p1%dm'
+
+* New 'digraph' command (bound to ^A^V)
+ ^A^Va" or ^A^V0344 input an a-umlaut
+
+* activity/bell message strings can now include the window title:
+ %t - title
+ %n - number (a single % still works)
+
+* 'defhstatus' command to give everey window a default
+ hardstatus line. ^E is used as a string escape instead of %
+ (see above). Try 'defhstatus "Screen: window ^E (^Et)"'
+
+* Input parser changed to understand '^' (see ^E above).
+
+Note that the linux color xterm has a stupid bug: the characters
+get the color of the cursor, therefore if you change color and move
+the cursor around all the characters will get the new color...
+Here is a patch:
+ pub/utilities/screen/color_xterm_patch
+Btw.: rxvt works fine.
+
+* Optional Braille support. If you can read Braille and have one of
+ the devices listed in README.DOTSCREEN, please compile with
+ -DHAVE_BRAILLE and let us know if this feature is useful.
+
diff --git a/NEWS.3.9 b/NEWS.3.9
new file mode 100644
index 0000000..4dc7891
--- /dev/null
+++ b/NEWS.3.9
@@ -0,0 +1,205 @@
+ -------------------------------
+ What's new in screen-3.9.15 ?
+ -------------------------------
+
+* unicode combining character support
+
+* new encoding: chinese GBK
+
+* new 'backtick' command and string escape to embed command
+ output into e.g. the hardstatus line
+
+
+ -------------------------------
+ What's new in screen-3.9.13 ?
+ -------------------------------
+
+* altscreen support from Gurusamy Sarathy
+
+* new command "maxwin" to set a limit on the number of windows
+
+* new keys in copy&paste mode: 'B' and 'E'
+
+
+ -------------------------------
+ What's new in screen-3.9.11 ?
+ -------------------------------
+
+* windowlist, bound to ^A"
+
+* support for other encodings, e.g. big5, koi8r, cp1251
+ new commands 'encoding', 'defencoding'
+ 'register', 'readreg', 'readbuf', 'writebuf' now understand
+ an extra encoding parameter
+
+* support for double utf-8 characters
+
+* lots of new string escapes and extensions to existsing ones:
+ %LD, %LM, %Lw, %W, %-w, %+w, %H, %f, %F, %l, %=, %<, %>
+
+* new commands: 'source', 'eval', 'deflog', 'ignorecase', 'setsid'
+
+* command key classes: 'bind', 'command' and 'help' understand
+ a '-c <class>' parameter. See the man page for examples
+
+* new login state: always - don't remove slot even if screen gets
+ detached
+
+* 256 color support (experimental)
+
+* configurable time format string (for ^At)
+
+* config option to use localized month/week names
+
+* new option '-h' for hardcopy: also dump the scrollback buffer
+
+
+ ------------------------------
+ What's new in screen-3.9.9 ?
+ ------------------------------
+
+* new '-X' option to send commands to screen sessions.
+
+ screen -X echo Hi...
+
+* added a possibility to change the attributes/color in caption or
+ hardstatus strings:
+
+ caption always "%3n %{r}%t%{-}%? @%u%?%? %{g}[%h]%{-}%?"
+
+* new 'dinfo' command to show what screen thinks about your terminal.
+
+* new 'attrcolor' command to map attributes to color codes:
+ attrcolor u "-u b"
+ attrcolor b "r"
+
+* support for UTF-8: new commands 'utf8', 'defutf8' to change the
+ encoding of a window, plus a '-U' option to tell screen that
+ your terminal sends/receives UTF-8 codes.
+
+* support for 16 colors.
+
+
+ ------------------------------
+ What's new in screen-3.9.8 ?
+ ------------------------------
+
+* new command 'resize' to resize regions (aka split windows), try:
+ bind = resize =
+ bind + resize +1
+ bind - resize -1
+ bind _ resize max
+
+* new argument for 'focus': up, down, top, bottom
+
+* X11 mouse tracking support
+
+* Support for the "new color model", aka "background color erase":
+ the bce/defbce commands change the color model of the current
+ window/new windows.
+
+* experimental rxvt OSC sequence support (used to set a background
+ picture or to change the default colors), disabled by default.
+
+
+ ----------------------------
+ What's new in screen-3.9 ?
+ ----------------------------
+
+* real multiuser support
+ A window can now be displayed on more than one attached displays.
+ Screen does all the necessary clipping if the window size doesn't
+ fit the display.
+ New command:
+ ^AF - fit the window size into the display size.
+
+* split screen support
+ A display may now host multiple windows.
+ New commands:
+ ^AS - split horizontally. This add another region to the display
+ ^A<Tab> - move the focus to the next region
+ ^AX - kill the current region
+ ^AQ - kill all other regions
+
+* hardstatus emulation support
+ The last line of the display may now be used as a hardstatus
+ line if the terminal doesn't have the 'hs' capability.
+ New commands:
+ hardstatus [always]lastline
+ hardstatus [always]message
+ hardstatus [always]ignore
+
+* configurable window seperator and hardstatus strings
+ The window (region) seperator and the hardstatus can be set to an
+ arbitrary string containing screen's % escape sequences.
+ The window's hardstatus is just another escape sequence, '%h'.
+ New commands:
+ hardstatus string [string]
+ caption string [string]
+ The default strings are "%h" (hardstatus) and "%3n %t" (caption).
+
+* permanent window seperator
+ The window seperator can be set to stay on screen even if
+ the display contains only one region
+ New commands:
+ caption always
+ caption splitonly
+
+* many new escapes
+ %c - current time HH:MM (*CHANGE*: this was %w in screen-3.7)
+ %C - current time HH:MM in 24h format
+ %l - the load of the system
+ %h - hardstatus of the window
+ %w - all window names
+ %W - all window names except the current window
+ %u - all other users on this window
+ %? - the part to the next %? is displayed only if an escape
+ expands to an nonempty string.
+ %: - "else" part of %?
+ Some escapes like %c may be qualified with a '0' (like %0c)
+ to make screen use '0' instead of space as a filler.
+ Others understand a length qualifier, like %3n.
+ If escapes like the current time are used as hardstatus/caption
+ string screen will update them so that you can always have
+ the current time onscreen.
+ *CHANGE* ~ is no longer used as bell character, use ^G instead!
+
+* logfile timestamps and flush timeout
+ New commands:
+ logfile flush <secs>
+ logtstamp [on|off]
+ logtstamp string [string]
+ logtstamp after [secs]
+
+* configurable breaktype
+ You can now choose one of TIOCSBRK, TCSBRK, tcsendbreak.
+ New commands:
+ breaktype
+ defbreaktype
+
+* other new commands:
+ hstatus - set the window's hardstatus
+ defslowpaste
+ defsilence
+
+* optional builtin telnet.
+ This is useful if screen is used as frontend to a terminal
+ multiplexor. Use //telnet to access the builtin telnet program,
+ as in: 'screen //telnet host [port]'
+
+* remote detach and reattach change:
+ '-d' is now ignored if the screen is already detached and you
+ want to reattach. You can also use '-RR' to make screen use
+ the first session found if more than one session is available.
+ Thus '-d -RR' or '-x -RR' always gets you a screen.
+
+* support for history compaction
+ You can tell screen to suppress trailing blank lines when
+ scolling up text into the history buffer. (Wayne Davison)
+ New command:
+ compacthist
+
+* optional Braille support. If you can read Braille and have one of
+ the devices listed in README.DOTSCREEN, please compile with
+ -DHAVE_BRAILLE and let us know if this feature is useful.
+
diff --git a/README b/README
new file mode 100644
index 0000000..00b6908
--- /dev/null
+++ b/README
@@ -0,0 +1,102 @@
+
+ [If you just got the screen package, it pays to read the file INSTALL]
+ [This intro only describes the most common features to get you started]
+ [A full description of all features is contained in the source package]
+
+
+
+Short introduction to GNU screen.
+
+Send bugreports, fixes, enhancements, t-shirts, money, beer & pizza to
+ screen-devel@gnu.org
+
+Screen provides you with an ANSI/vt100 terminal emulator, which can multiplex
+up to 10 pseudo-terminals. On startup, it executes $SHELL in window 0.
+Then it reads $HOME/.screenrc to learn configuration, keybindings, and
+possibly open more windows.
+
+ C-a ? (help) Show all keybindings.
+
+ C-a c (screen) Create new windows.
+
+ C-a SPACE (next) Advance to next window (with wraparound).
+
+ C-a C-a (other) Toggle between the current and previously
+ displayed windows.
+
+ C-a 0 (select n) Switch to window n=0 ... 9.
+ ...
+ C-a 9
+
+ C-a w (windows) Show a list of window names in the status line.
+
+ C-a a (meta) Send a literal C-a/C-s/C-q to the
+ C-a s (xoff) process in the window.
+ C-a q (xon) For instance, emacs uses C-a and C-s.
+
+ C-a l (redisplay) Redraw this window.
+
+ C-a W (width) Toggle between 80 & 132 columns mode.
+
+ C-a L (login) Try to toggle the window's utmp-slot.
+
+ C-a z (suspend) Suspend the whole screen session.
+
+ C-a x (lockscreen) Execute /usr/bin/lock, $LOCKCMD or a
+ built-in terminal lock.
+
+ C-a H (log) Log stdout of window n to screenlog.n.
+
+ C-a C-[ (copy) Start copy mode. Move cursor with h,j,k,l.
+ Set 2 marks with SPACE or y. Abort with ESC.
+ (C-[ is ESC.) Preceeding second mark with
+ an a appends the text to the copy buffer.
+
+ C-a C-] (paste) Output copy buffer to current window's stdin.
+
+ C-a < (readbuf) Read the copy buffer from /tmp/screen-exchange.
+ C-a > (writebuf) Write the copy buffer to /tmp/screen-exchange.
+
+ C-a d (detach) Detach screen. All processes continue and may
+ spool output to their pty's, but screen
+ disconnects from your terminal.
+
+ C-a D D (pow_detach) Power detach. Disconnect like C-a d but also
+ kill the parent shell.
+
+ C-a K (kill) Kill a window and send SIGHUP to its process
+ group. Per default this would be C-a C-k,
+ but it is redefined in the demo .screenrc
+ (think of killing a whole line in emacs).
+
+ C-a : (colon) Online configuration change.
+
+See the man page or TeXinfo manual for many more keybindings and commands.
+
+screen -r [pid.tty.host|tty.host]
+ Reattach to a specific detached session. The terminal emulator
+ reconfigures according to your $TERMCAP or $TERM settings.
+ When you have multiple screens detached, you must supply the session
+ name.
+
+screen -R reattaches to a detached session or (if none) creates a new
+ session.
+
+screen -d [pid.tty.host|tty.host]
+ Detach a screen session remotely. Has the same effect as typing 'C-a d'
+ on the controlling terminal. 'screen -D' will power-detach.
+
+screen -list
+screen -ls
+screen -wipe
+ Show all available sessions and their status. Use -wipe to remove
+ DEAD sessions.
+
+ If sockets are missing, you may send a SIGCHLD to its 'SCREEN'
+ process and the process will re-establish the socket (think of
+ someone cleaning /tmp thoroughly).
+
+screen -h 200
+ Starts a new screen session and sets the number of lines in the scrollback
+ buffer to 200. The default is 100 lines.
+
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..54b2b9f
--- /dev/null
+++ b/TODO
@@ -0,0 +1,7 @@
+- display size adaption (Activate)
+- process.c cleanup via comm splitting
+- writelocks?
+- partial?
+- type into several windows at once (for cluster admins)
+- configurable digraph table
+- command line options should overwrite config files.
diff --git a/acconfig.h b/acconfig.h
new file mode 100644
index 0000000..4e5cda0
--- /dev/null
+++ b/acconfig.h
@@ -0,0 +1,579 @@
+/* Copyright (c) 1993-2000
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+
+
+
+
+/**********************************************************************
+ *
+ * User Configuration Section
+ */
+
+/*
+ * Maximum of simultaneously allowed windows per screen session.
+ */
+#ifndef MAXWIN
+# define MAXWIN 100
+#endif
+
+/*
+ * Define SOCKDIR to be the directory to contain the named sockets
+ * screen creates. This should be in a common subdirectory, such as
+ * /usr/local or /tmp. It makes things a little more secure if you
+ * choose a directory which is not writable by everyone or where the
+ * "sticky" bit is on, but this isn't required.
+ * If SOCKDIR is not defined screen will put the named sockets in
+ * the user's home directory. Notice that this can cause you problems
+ * if some user's HOME directories are AFS- or NFS-mounted. Especially
+ * AFS is unlikely to support named sockets.
+ *
+ * Screen will name the subdirectories "S-$USER" (e.g /tmp/S-davison).
+ */
+#undef SOCKDIR
+
+/*
+ * Define this if the SOCKDIR is not shared between hosts.
+ */
+#define SOCKDIR_IS_LOCAL_TO_HOST
+
+/*
+ * Screen can look for the environment variable $SYSSCREENRC and -if it
+ * exists- load the file specified in that variable as global screenrc.
+ * If you want to enable this feature, define ALLOW_SYSSCREENRC to one (1).
+ * Otherwise ETCSCREENRC is always loaded.
+ */
+#define ALLOW_SYSSCREENRC 1
+
+/*
+ * Define CHECKLOGIN to force Screen users to enter their Unix password
+ * in addition to the screen password.
+ *
+ * Define NOSYSLOG if yo do not have logging facilities. Currently
+ * syslog() will be used to trace ``su'' commands only.
+ */
+#define CHECKLOGIN 1
+#undef NOSYSLOG
+
+
+/*
+ * define PTYMODE if you do not like the default of 0622, which allows
+ * public write to your pty.
+ * define PTYGROUP to some numerical group-id if you do not want the
+ * tty to be in "your" group.
+ * Note, screen is unable to change mode or group of the pty if it
+ * is not installed with sufficient privilege. (e.g. set-uid-root)
+ * define PTYROFS if the /dev/pty devices are mounted on a read-only
+ * filesystem so screen should not even attempt to set mode or group
+ * even if running as root (e.g. on TiVo).
+ */
+#undef PTYMODE
+#undef PTYGROUP
+#undef PTYROFS
+
+/*
+ * If screen is NOT installed set-uid root, screen can provide tty
+ * security by exclusively locking the ptys. While this keeps other
+ * users from opening your ptys, it also keeps your own subprocesses
+ * from being able to open /dev/tty. Define LOCKPTY to add this
+ * exclusive locking.
+ */
+#undef LOCKPTY
+
+/*
+ * If you'd rather see the status line on the first line of your
+ * terminal rather than the last, define TOPSTAT.
+ */
+#undef TOPSTAT
+
+/*
+ * define DETACH can detach a session. An absolute 'must'.
+ */
+#define DETACH
+
+/*
+ * here come the erlangen extensions to screen:
+ * define LOCK if you want to use a lock program for a screenlock.
+ * define PASSWORD for secure reattach of your screen.
+ * define COPY_PASTE to use the famous hacker's treasure zoo.
+ * define POW_DETACH to have a detach_and_logout key (requires DETACH).
+ * define REMOTE_DETACH (-d option) to move screen between terminals.
+ * define AUTO_NUKE to enable Tim MacKenzies clear screen nuking
+ * define PSEUDOS to allow window input/output filtering
+ * define MULTI to allow multiple attaches.
+ * define MULTIUSER to allow other users attach to your session
+ * (if they are in the acl, of course)
+ * define MAPKEYS to include input keyboard translation.
+ * define FONT to support ISO2022/alternet charset support
+ * define COLOR to include ansi color support. This may expose
+ * a bug in x11r6-color-xterm.
+ * define DW_CHARS to include support for double-width character
+ * sets.
+ * define ENCODINGS to include support for encodings like euc or big5.
+ * Needs FONT to work.
+ * define UTF8 if you want support for UTF-8 encoding.
+ * Needs FONT and ENCODINGS to work.
+ * define COLORS16 if you want 16 colors.
+ * Needs COLOR to work.
+ * define BUILTIN_TELNET to add telnet support to screen.
+ * Syntax: screen //telnet host [port]
+ * define RXVT_OSC if you want support for rxvts special
+ * change fgcolor/bgcolor/bgpicture sequences
+ */
+#undef SIMPLESCREEN
+#ifndef SIMPLESCREEN
+# define LOCK
+# define PASSWORD
+# define COPY_PASTE
+# define REMOTE_DETACH
+# define POW_DETACH
+# define AUTO_NUKE
+# define PSEUDOS
+# define MULTI
+# define MULTIUSER
+# define MAPKEYS
+# define COLOR
+# define FONT
+# define DW_CHARS
+# define ENCODINGS
+# define UTF8
+# define COLORS16
+# define ZMODEM
+# define BLANKER_PRG
+#endif /* SIMPLESCREEN */
+
+#undef BUILTIN_TELNET
+#undef RXVT_OSC
+#undef COLORS256
+
+
+/*
+ * If you have a braille display you should define HAVE_BRAILLE.
+ * The code inside #ifdef HAVE_BRAILLE was contributed by Hadi Bargi
+ * Rangin (bargi@dots.physics.orst.edu).
+ * WARNING: this is more or less unsupported code, it may be full of
+ * bugs leading to security holes, enable at your own risk!
+ */
+#undef HAVE_BRAILLE
+
+
+/*
+ * As error messages are mostly meaningless to the user, we
+ * try to throw out phrases that are somewhat more familiar
+ * to ...well, at least familiar to us NetHack players.
+ */
+#ifndef NONETHACK
+# define NETHACK
+#endif /* NONETHACK */
+
+/*
+ * If screen is installed with permissions to update /etc/utmp (such
+ * as if it is installed set-uid root), define UTMPOK.
+ */
+#define UTMPOK
+
+/* Set LOGINDEFAULT to one (1)
+ * if you want entries added to /etc/utmp by default, else set it to
+ * zero (0).
+ * LOGINDEFAULT will be one (1) whenever LOGOUTOK is undefined!
+ */
+#define LOGINDEFAULT 1
+
+/* Set LOGOUTOK to one (1)
+ * if you want the user to be able to log her/his windows out.
+ * (Meaning: They are there, but not visible in /etc/utmp).
+ * Disabling this feature only makes sense if you have a secure /etc/utmp
+ * database.
+ * Negative examples: suns usually have a world writable utmp file,
+ * xterm will run perfectly without s-bit.
+ *
+ * If LOGOUTOK is undefined and UTMPOK is defined, all windows are
+ * initially and permanently logged in.
+ *
+ * Set CAREFULUTMP to one (1) if you want that users have at least one
+ * window per screen session logged in.
+ */
+#define LOGOUTOK 1
+#undef CAREFULUTMP
+
+
+/*
+ * If UTMPOK is defined and your system (incorrectly) counts logins by
+ * counting non-null entries in /etc/utmp (instead of counting non-null
+ * entries with no hostname that are not on a pseudo tty), define USRLIMIT
+ * to have screen put an upper-limit on the number of entries to write
+ * into /etc/utmp. This helps to keep you from exceeding a limited-user
+ * license.
+ */
+#undef USRLIMIT
+
+/*
+ * both must be defined if you want to favor tcsendbreak over
+ * other calls to generate a break condition on serial lines.
+ * (Do not bother, if you are not using plain tty windows.)
+ */
+#define POSIX_HAS_A_GOOD_TCSENDBREAK
+#define SUNOS4_AND_WE_TRUST_TCSENDBREAK
+
+/*
+ * to lower the interrupt load on the host machine, you may want to
+ * adjust the VMIN and VTIME settings used for plain tty windows.
+ * See the termio(4) manual page (Non-Canonical Mode Input Processing)
+ * for details.
+ * if undefined, VMIN=1, VTIME=0 is used as a default - this gives you
+ * best user responsiveness, but highest interrupt frequency.
+ * (Do not bother, if you are not using plain tty windows.)
+ */
+#define TTYVMIN 100
+#define TTYVTIME 2
+
+/*
+ * looks like the above values are ignored by setting FNDELAY.
+ * This is default for all pty/ttys, you may disable it for
+ * ttys here. After playing with it for a while, one may find out
+ * that this feature may cause screen to lock up.
+ */
+#ifdef bsdi
+# define TTY_DISABLE_FNBLOCK /* select barfs without it ... */
+#endif
+
+
+/*
+ * Some terminals, e.g. Wyse 120, use a bitfield to select attributes.
+ * This doesn't work with the standard so/ul/m? terminal entries,
+ * because they will cancel each other out.
+ * On TERMINFO machines, "sa" (sgr) may work. If you want screen
+ * to switch attributes only with sgr, define USE_SGR.
+ * This is *not* recomended, do this only if you must.
+ */
+#undef USE_SGR
+
+
+/*
+ * Define USE_LOCALE if you want screen to use the locale names
+ * for the name of the month and day of the week.
+ */
+#define USE_LOCALE
+
+/*
+ * Define USE_PAM if your system supports PAM (Pluggable Authentication
+ * Modules) and you want screen to use it instead of calling crypt().
+ * (You may also need to add -lpam to LIBS in the Makefile.)
+ */
+#undef USE_PAM
+
+/*
+ * Define CHECK_SCREEN_W if you want screen to set TERM to screen-w
+ * if the terminal width is greater than 131 columns. No longer needed
+ * on modern systems which use $COLUMNS or the tty settings instead.
+ */
+#undef CHECK_SCREEN_W
+
+/**********************************************************************
+ *
+ * End of User Configuration Section
+ *
+ * Rest of this file is modified by 'configure'
+ * Change at your own risk!
+ *
+ */
+
+/*
+ * Some defines to identify special unix variants
+ */
+#ifndef SVR4
+#undef SVR4
+#endif
+
+/* #ifndef __osf__ */
+#ifndef MIPS
+#undef MIPS
+#endif
+/* #endif */
+
+#ifndef OSX
+#undef OSX
+#endif
+
+#ifndef ISC
+#undef ISC
+#endif
+
+#ifndef sysV68
+#undef sysV68
+#endif
+
+#ifndef _POSIX_SOURCE
+#undef _POSIX_SOURCE
+#endif
+
+/*
+ * Define POSIX if your system supports IEEE Std 1003.1-1988 (POSIX).
+ */
+#undef POSIX
+
+/*
+ * Define BSDJOBS if you have BSD-style job control (both process
+ * groups and a tty that deals correctly with them).
+ */
+#undef BSDJOBS
+
+/*
+ * Define TERMIO if you have struct termio instead of struct sgttyb.
+ * This is usually the case for SVID systems, where BSD uses sgttyb.
+ * POSIX systems should define this anyway, even though they use
+ * struct termios.
+ */
+#undef TERMIO
+
+/*
+ * Define CYTERMIO if you have cyrillic termio modes.
+ */
+#undef CYTERMIO
+
+/*
+ * Define TERMINFO if your machine emulates the termcap routines
+ * with the terminfo database.
+ * Thus the .screenrc file is parsed for
+ * the command 'terminfo' and not 'termcap'.
+ */
+#undef TERMINFO
+
+/*
+ * If your library does not define ospeed, define this.
+ */
+#undef NEED_OSPEED
+
+/*
+ * Define SYSV if your machine is SYSV complient (Sys V, HPUX, A/UX)
+ */
+#ifndef SYSV
+#undef SYSV
+#endif
+
+/*
+ * Define SIGVOID if your signal handlers return void. On older
+ * systems, signal returns int, but on newer ones, it returns void.
+ */
+#undef SIGVOID
+
+/*
+ * Define USESIGSET if you have sigset for BSD 4.1 reliable signals.
+ */
+#undef USESIGSET
+
+/*
+ * Define SYSVSIGS if signal handlers must be reinstalled after
+ * they have been called.
+ */
+#undef SYSVSIGS
+
+/*
+ * Define BSDWAIT if your system defines a 'union wait' in <sys/wait.h>
+ *
+ * Only allow BSDWAIT i.e. wait3 on nonposix systems, since
+ * posix implies wait(3) and waitpid(3). vdlinden@fwi.uva.nl
+ *
+ */
+#ifndef POSIX
+#undef BSDWAIT
+#endif
+
+/*
+ * On RISCOS we prefer wait2() over wait3(). rouilj@sni-usa.com
+ */
+#ifdef BSDWAIT
+#undef USE_WAIT2
+#endif
+
+/*
+ * If your system has getutent(), pututline(), etc. to write to the
+ * utmp file, define GETUTENT.
+ */
+#undef GETUTENT
+
+/*
+ * Define UTHOST if the utmp file has a host field.
+ */
+#undef UTHOST
+
+/*
+ * Define if you have the utempter utmp helper program
+ */
+#undef HAVE_UTEMPTER
+
+/*
+ * If ttyslot() breaks getlogin() by returning indexes to utmp entries
+ * of type DEAD_PROCESS, then our getlogin() replacement should be
+ * selected by defining BUGGYGETLOGIN.
+ */
+#undef BUGGYGETLOGIN
+
+/*
+ * If your system has the calls setreuid() and setregid(),
+ * define HAVE_SETREUID. Otherwise screen will use a forked process to
+ * safely create output files without retaining any special privileges.
+ */
+#undef HAVE_SETRESUID
+#undef HAVE_SETREUID
+
+/*
+ * If your system supports BSD4.4's seteuid() and setegid(), define
+ * HAVE_SETEUID.
+ */
+#undef HAVE_SETEUID
+
+/*
+ * execvpe is now defined in some systems.
+ */
+#undef HAVE_EXECVPE
+
+/*
+ * If you want the "time" command to display the current load average
+ * define LOADAV. Maybe you must install screen with the needed
+ * privileges to read /dev/kmem.
+ * Note that NLIST_ stuff is only checked, when getloadavg() is not available.
+ */
+#undef LOADAV
+
+#undef LOADAV_NUM
+#undef LOADAV_TYPE
+#undef LOADAV_SCALE
+#undef LOADAV_GETLOADAVG
+#undef LOADAV_UNIX
+#undef LOADAV_AVENRUN
+#undef LOADAV_USE_NLIST64
+
+#undef NLIST_DECLARED
+#undef NLIST_STRUCT
+#undef NLIST_NAME_UNION
+
+/*
+ * If your system has the new format /etc/ttys (like 4.3 BSD) and the
+ * getttyent(3) library functions, define GETTTYENT.
+ */
+#undef GETTTYENT
+
+/*
+ * Define USEBCOPY if the bcopy/memcpy from your system's C library
+ * supports the overlapping of source and destination blocks. When
+ * undefined, screen uses its own (probably slower) version of bcopy().
+ *
+ * SYSV machines may have a working memcpy() -- Oh, this is
+ * quite unlikely. Tell me if you see one.
+ * "But then, memmove() should work, if at all available" he thought...
+ * Boing, never say "works everywhere" unless you checked SCO UNIX.
+ * Their memove fails the test in the configure script. Sigh. (Juergen)
+ */
+#undef USEBCOPY
+#undef USEMEMCPY
+#undef USEMEMMOVE
+
+/*
+ * If your system has vsprintf() and requires the use of the macros in
+ * "varargs.h" to use functions with variable arguments,
+ * define USEVARARGS.
+ */
+#undef USEVARARGS
+
+/*
+ * If the select return value doesn't treat a descriptor that is
+ * usable for reading and writing as two hits, define SELECT_BROKEN.
+ */
+#undef SELECT_BROKEN
+
+/*
+ * Define this if your system exits select() immediatly if a pipe is
+ * opened read-only and no writer has opened it.
+ */
+#undef BROKEN_PIPE
+
+/*
+ * Define this if the unix-domain socket implementation doesn't
+ * create a socket in the filesystem.
+ */
+#undef SOCK_NOT_IN_FS
+
+/*
+ * If your system has setenv() and unsetenv() define USESETENV
+ */
+#undef USESETENV
+
+/*
+ * If setenv() takes 3 arguments define HAVE_SETENV_3
+ */
+#undef HAVE_SETENV_3
+
+/*
+ * If setenv() takes 2 arguments define HAVE_SETENV_2
+ */
+#undef HAVE_SETENV_2
+
+/*
+ * If your system does not come with a setenv()/putenv()/getenv()
+ * functions, you may bring in our own code by defining NEEDPUTENV.
+ */
+#undef NEEDPUTENV
+
+/*
+ * If the passwords are stored in a shadow file and you want the
+ * builtin lock to work properly, define SHADOWPW.
+ */
+#undef SHADOWPW
+
+/*
+ * define HAVE_NL_LANGINFO if your system has the nl_langinfo() call
+ * and <langinfo.h> defines CODESET.
+ */
+#undef HAVE_NL_LANGINFO
+
+/*
+ * Newer versions of Solaris include fdwalk, which can greatly improve
+ * the startup time of screen; otherwise screen spends a lot of time
+ * closing file descriptors.
+ */
+#undef HAVE_FDWALK
+
+/*
+ * define HAVE_DEV_PTC if you have a /dev/ptc character special
+ * device.
+ */
+#undef HAVE_DEV_PTC
+
+/*
+ * define HAVE_SVR4_PTYS if you have a /dev/ptmx character special
+ * device and support the ptsname(), grantpt(), unlockpt() functions.
+ */
+#undef HAVE_SVR4_PTYS
+
+/*
+ * define PTYRANGE0 and or PTYRANGE1 if you want to adapt screen
+ * to unusual environments. E.g. For SunOs the defaults are "qpr" and
+ * "0123456789abcdef". For SunOs 4.1.2
+ * #define PTYRANGE0 "pqrstuvwxyzPQRST"
+ * is recommended by Dan Jacobson.
+ */
+#undef PTYRANGE0
+#undef PTYRANGE1
+
diff --git a/acls.c b/acls.c
new file mode 100644
index 0000000..514e0fc
--- /dev/null
+++ b/acls.c
@@ -0,0 +1,1147 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include "config.h"
+
+#include <sys/types.h>
+
+/* XXX: WHY IS THIS HERE?? :XXX */
+
+#ifdef CHECKLOGIN
+# ifdef _SEQUENT_
+# include <stdio.h> /* needed by <pwd.h> */
+# endif /* _SEQUENT_ */
+# include <pwd.h>
+# ifdef SHADOWPW
+# include <shadow.h>
+# endif /* SHADOWPW */
+#endif /* CHECKLOGIN */
+
+#ifndef NOSYSLOG
+# include <syslog.h>
+#endif
+
+#include "screen.h" /* includes acls.h */
+#include "extern.h"
+
+
+/************************************************************************
+ * user managing code, this does not really belong into the acl stuff *
+ ************************************************************************/
+
+extern struct comm comms[];
+extern struct win *windows, **wtab;
+extern char NullStr[];
+extern char SockPath[];
+extern struct display *display, *displays;
+struct acluser *users;
+
+#ifdef MULTIUSER
+int maxusercount = 0; /* used in process.c: RC_MONITOR, RC_SILENCE */
+
+/* record given user ids here */
+static AclBits userbits;
+
+/*
+ * rights a new unknown user will have on windows and cmds.
+ * These are changed by a "umask ?-..." command:
+ */
+static char default_w_bit[ACL_BITS_PER_WIN] =
+{
+ 1, /* EXEC */
+ 1, /* WRITE */
+ 1 /* READ */
+};
+
+static char default_c_bit[ACL_BITS_PER_CMD] =
+{
+ 0 /* EXEC */
+};
+
+/* rights of all users per newly created window */
+/*
+ * are now stored per user (umask)
+ * static AclBits default_w_userbits[ACL_BITS_PER_WIN];
+ * static AclBits default_c_userbits[ACL_BITS_PER_CMD];
+ */
+
+static int GrowBitfield __P((AclBits *, int, int, int));
+static struct aclusergroup **FindGroupPtr __P((struct aclusergroup **, struct acluser *, int));
+static int AclSetPermCmd __P((struct acluser *, char *, struct comm *));
+static int AclSetPermWin __P((struct acluser *, struct acluser *, char *, struct win *));
+static int UserAcl __P((struct acluser *, struct acluser **, int, char **));
+static int UserAclCopy __P((struct acluser **, struct acluser **));
+
+
+static int
+GrowBitfield(bfp, len, delta, defaultbit)
+AclBits *bfp;
+int len, delta, defaultbit;
+{
+ AclBits n, o = *bfp;
+ int i;
+
+ if (!(n = (AclBits)calloc(1, (unsigned long)(&ACLBYTE((char *)0, len + delta + 1)))))
+ return -1;
+ for (i = 0; i < (len + delta); i++)
+ {
+ if (((i < len) && (ACLBIT(i) & ACLBYTE(o, i))) ||
+ ((i >= len) && (defaultbit)))
+ ACLBYTE(n, i) |= ACLBIT(i);
+ }
+ if (len)
+ free((char *)o);
+ *bfp = n;
+ return 0;
+}
+
+#endif /* MULTIUSER */
+
+/*
+ * Returns an nonzero Address. Its contents is either a User-ptr,
+ * or NULL which may be replaced by a User-ptr to create the entry.
+ */
+struct acluser **
+FindUserPtr(name)
+char *name;
+{
+ struct acluser **u;
+
+ for (u = &users; *u; u = &(*u)->u_next)
+ if (!strcmp((*u)->u_name, name))
+ break;
+#ifdef MULTIUSER
+ debug3("FindUserPtr %s %sfound, id %d\n", name, (*u)?"":"not ",
+ (*u)?(*u)->u_id:-1);
+#else /* MULTIUSER */
+ debug2("FindUserPtr %s %sfound\n", name, (*u)?"":"not ");
+#endif /* MULTIUSER */
+ return u;
+}
+
+int DefaultEsc = -1; /* initialised by screen.c:main() */
+int DefaultMetaEsc = -1;
+
+/*
+ * Add a new user. His password may be NULL or "" if none. His name must not
+ * be "none", as this represents the NULL-pointer when dealing with groups.
+ * He has default rights, determined by umask.
+ */
+int
+UserAdd(name, pass, up)
+char *name, *pass;
+struct acluser **up;
+{
+#ifdef MULTIUSER
+ int j;
+#endif
+
+ if (!up)
+ up = FindUserPtr(name);
+ if (*up)
+ {
+ if (pass)
+ (*up)->u_password = SaveStr(pass);
+ return 1; /* he is already there */
+ }
+ if (strcmp("none", name)) /* "none" is a reserved word */
+ *up = (struct acluser *)calloc(1, sizeof(struct acluser));
+ if (!*up)
+ return -1; /* he still does not exist */
+#ifdef COPY_PASTE
+ (*up)->u_plop.buf = NULL;
+ (*up)->u_plop.len = 0;
+# ifdef ENCODINGS
+ (*up)->u_plop.enc = 0;
+# endif
+#endif
+ (*up)->u_Esc = DefaultEsc;
+ (*up)->u_MetaEsc = DefaultMetaEsc;
+ strncpy((*up)->u_name, name, MAXLOGINLEN);
+ (*up)->u_password = NULL;
+ if (pass)
+ (*up)->u_password = SaveStr(pass);
+ if (!(*up)->u_password)
+ (*up)->u_password = NullStr;
+ (*up)->u_detachwin = -1;
+ (*up)->u_detachotherwin = -1;
+
+#ifdef MULTIUSER
+ (*up)->u_group = NULL;
+ /* now find an unused index */
+ for ((*up)->u_id = 0; (*up)->u_id < maxusercount; (*up)->u_id++)
+ if (!(ACLBIT((*up)->u_id) & ACLBYTE(userbits, (*up)->u_id)))
+ break;
+ debug2("UserAdd %s id %d\n", name, (*up)->u_id);
+ if ((*up)->u_id == maxusercount)
+ {
+ int j;
+ struct win *w;
+ struct acluser *u;
+
+ debug2("growing all bitfields %d += %d\n", maxusercount, USER_CHUNK);
+ /* the bitfields are full, grow a chunk */
+ /* first, the used_uid_indicator: */
+ if (GrowBitfield(&userbits, maxusercount, USER_CHUNK, 0))
+ {
+ free((char *)*up); *up = NULL; return -1;
+ }
+ /* second, default command bits */
+ /* (only if we generate commands dynamically) */
+/*
+ for (j = 0; j < ACL_BITS_PER_CMD; j++)
+ if (GrowBitfield(&default_c_userbits[j], maxusercount, USER_CHUNK,
+ default_c_bit[j]))
+ {
+ free((char *)*up); *up = NULL; return -1;
+ }
+*/
+ /* third, the bits for each commands */
+ for (j = 0; j <= RC_LAST; j++)
+ {
+ int i;
+
+ for (i = 0; i < ACL_BITS_PER_CMD; i++)
+ if (GrowBitfield(&comms[j].userbits[i], maxusercount, USER_CHUNK,
+ default_c_bit[i]))
+ {
+ free((char *)*up); *up = NULL; return -1;
+ }
+ }
+ /* fourth, default window creation bits per user */
+ for (u = users; u != *up; u = u->u_next)
+ {
+ for (j = 0; j < ACL_BITS_PER_WIN; j++)
+ {
+ if (GrowBitfield(&u->u_umask_w_bits[j], maxusercount, USER_CHUNK,
+ default_w_bit[j]))
+ {
+ free((char *)*up); *up = NULL; return -1;
+ }
+ }
+ }
+
+ /* fifth, the bits for each window */
+ /* keep these in sync with NewWindowAcl() */
+ for (w = windows; w; w = w->w_next)
+ {
+ /* five a: the access control list */
+ for (j = 0; j < ACL_BITS_PER_WIN; j++)
+ if (GrowBitfield(&w->w_userbits[j], maxusercount, USER_CHUNK,
+ default_w_bit[j]))
+ {
+ free((char *)*up); *up = NULL; return -1;
+ }
+ /* five b: the activity notify list */
+ /* five c: the silence notify list */
+ if (GrowBitfield(&w->w_mon_notify, maxusercount, USER_CHUNK, 0) ||
+ GrowBitfield(&w->w_lio_notify, maxusercount, USER_CHUNK, 0))
+ {
+ free((char *)*up); *up = NULL; return -1;
+ }
+ }
+ maxusercount += USER_CHUNK;
+ }
+
+ /* mark the user-entry as "in-use" */
+ ACLBYTE(userbits, (*up)->u_id) |= ACLBIT((*up)->u_id);
+
+ /* user id 0 is the session creator, he has all rights */
+ if ((*up)->u_id == 0)
+ AclSetPerm(NULL, *up, "+a", "#?");
+
+ /* user nobody has a fixed set of rights: */
+ if (!strcmp((*up)->u_name, "nobody"))
+ {
+ AclSetPerm(NULL, *up, "-rwx", "#?");
+ AclSetPerm(NULL, *up, "+x", "su");
+ AclSetPerm(NULL, *up, "+x", "detach");
+ AclSetPerm(NULL, *up, "+x", "displays");
+ AclSetPerm(NULL, *up, "+x", "version");
+ }
+
+ /*
+ * Create his umask:
+ * Give default_w_bit's for all users,
+ * but allow himself everything on "his" windows.
+ */
+ for (j = 0; j < ACL_BITS_PER_WIN; j++)
+ {
+ if (GrowBitfield(&(*up)->u_umask_w_bits[j], 0, maxusercount,
+ default_w_bit[j]))
+ {
+ free((char *)*up); *up = NULL; return -1;
+ }
+ ACLBYTE((*up)->u_umask_w_bits[j], (*up)->u_id) |= ACLBIT((*up)->u_id);
+ }
+#else /* MULTIUSER */
+ debug1("UserAdd %s\n", name);
+#endif /* MULTIUSER */
+ return 0;
+}
+
+#if 0
+/* change user's password */
+int
+UserSetPass(name, pass, up)
+char *name, *pass;
+struct acluser **up;
+{
+ if (!up)
+ up = FindUserPtr(name);
+ if (!*up)
+ return UserAdd(name, pass, up);
+ if (!strcmp(name, "nobody")) /* he remains without password */
+ return -1;
+ strncpy((*up)->u_password, pass ? pass : "", 20);
+ (*up)->u_password[20] = '\0';
+ return 0;
+}
+#endif
+
+/*
+ * Remove a user from the list.
+ * Destroy all his permissions and completely detach him from the session.
+ */
+int
+UserDel(name, up)
+char *name;
+struct acluser **up;
+{
+ struct acluser *u;
+#ifdef MULTIUSER
+ int i;
+#endif
+ struct display *old, *next;
+
+ if (!up)
+ up = FindUserPtr(name);
+ if (!(u = *up))
+ return -1; /* he who does not exist cannot be removed */
+ old = display;
+ for (display = displays; display; display = next)
+ {
+ next = display->d_next; /* read the next ptr now, Detach may zap it. */
+ if (D_user != u)
+ continue;
+ if (display == old)
+ old = NULL;
+ Detach(D_REMOTE);
+ }
+ display = old;
+ *up = u->u_next;
+
+#ifdef MULTIUSER
+ for (up = &users; *up; up = &(*up)->u_next)
+ {
+ /* unlink all group references to this user */
+ struct aclusergroup **g = &(*up)->u_group;
+
+ while (*g)
+ {
+ if ((*g)->u == u)
+ {
+ struct aclusergroup *next = (*g)->next;
+
+ free((char *)(*g));
+ *g = next;
+ }
+ else
+ g = &(*g)->next;
+ }
+ }
+ ACLBYTE(userbits, u->u_id) &= ~ACLBIT(u->u_id);
+ /* restore the bits in his slot to default: */
+ AclSetPerm(NULL, u, default_w_bit[ACL_READ] ? "+r" : "-r", "#");
+ AclSetPerm(NULL, u, default_w_bit[ACL_WRITE]? "+w" : "-w", "#");
+ AclSetPerm(NULL, u, default_w_bit[ACL_EXEC] ? "+x" : "-x", "#");
+ AclSetPerm(NULL, u, default_c_bit[ACL_EXEC] ? "+x" : "-x", "?");
+ for (i = 0; i < ACL_BITS_PER_WIN; i++)
+ free((char *)u->u_umask_w_bits[i]);
+#endif /* MULTIUSER */
+ debug1("FREEING user structure for %s\n", u->u_name);
+#ifdef COPY_PASTE
+ UserFreeCopyBuffer(u);
+#endif
+ free((char *)u);
+ if (!users)
+ {
+ debug("Last user deleted. Feierabend.\n");
+ Finit(0); /* Destroying whole session. Noone could ever attach again. */
+ }
+ return 0;
+}
+
+
+#ifdef COPY_PASTE
+
+/*
+ * returns 0 if the copy buffer was really deleted.
+ * Also removes any references into the users copybuffer
+ */
+int
+UserFreeCopyBuffer(u)
+struct acluser *u;
+{
+ struct win *w;
+ struct paster *pa;
+
+ if (!u->u_plop.buf)
+ return 1;
+ for (w = windows; w; w = w->w_next)
+ {
+ pa = &w->w_paster;
+ if (pa->pa_pasteptr >= u->u_plop.buf &&
+ pa->pa_pasteptr - u->u_plop.buf < u->u_plop.len)
+ FreePaster(pa);
+ }
+ free((char *)u->u_plop.buf);
+ u->u_plop.len = 0;
+ u->u_plop.buf = 0;
+ return 0;
+}
+#endif /* COPY_PASTE */
+
+#ifdef MULTIUSER
+/*
+ * Traverses group nodes. It searches for a node that references user u.
+ * If recursive is true, nodes found in the users are also searched using
+ * depth first method. If none of the nodes references u, the address of
+ * the last next pointer is returned. This address will contain NULL.
+ */
+static struct aclusergroup **
+FindGroupPtr(gp, u, recursive)
+struct aclusergroup **gp;
+struct acluser *u;
+int recursive;
+{
+ struct aclusergroup **g;
+
+ ASSERT(recursive < 1000); /* Ouch, cycle detection failed */
+ while (*gp)
+ {
+ if ((*gp)->u == u)
+ return gp; /* found him here. */
+ if (recursive &&
+ *(g = FindGroupPtr(&(*gp)->u->u_group, u, recursive + 1)))
+ return g; /* found him there. */
+ gp = &(*gp)->next;
+ }
+ return gp; /* *gp is NULL */
+}
+
+static int
+PasswordMatches(pw, password)
+const char *pw, *password;
+{
+ if (!*password)
+ return 0;
+ char *buf = crypt((char *)pw, (char *)password);
+ return (buf && !strcmp(buf, password));
+}
+
+/*
+ * Returns nonzero if failed or already linked.
+ * Both users are created on demand.
+ * Cyclic links are prevented.
+ */
+int
+AclLinkUser(from, to)
+char *from, *to;
+{
+ struct acluser **u1, **u2;
+ struct aclusergroup **g;
+
+ if (!*(u1 = FindUserPtr(from)) && UserAdd(from, NULL, u1))
+ return -1;
+ if (!*(u2 = FindUserPtr(to)) && UserAdd(to, NULL, u2))
+ return -1; /* hmm, could not find both users. */
+
+ if (*FindGroupPtr(&(*u2)->u_group, *u1, 1))
+ return 1; /* cyclic link detected! */
+ if (*(g = FindGroupPtr(&(*u1)->u_group, *u2, 0)))
+ return 2; /* aha, we are already linked! */
+
+ if (!(*g = (struct aclusergroup *)malloc(sizeof(struct aclusergroup))))
+ return -1; /* Could not alloc link. Poor screen */
+ (*g)->u = (*u2);
+ (*g)->next = NULL;
+ return 0;
+}
+
+/*
+ * The user pointer stored at *up will be substituted by a pointer
+ * to the named user's structure, if passwords match.
+ * returns NULL if successfull, an static error string otherwise
+ */
+char *
+DoSu(up, name, pw1, pw2)
+struct acluser **up;
+char *name, *pw1, *pw2;
+{
+ struct acluser *u;
+ int sorry = 0;
+
+ if (!(u = *FindUserPtr(name)))
+ sorry++;
+ else
+ {
+#ifdef CHECKLOGIN
+ struct passwd *pp;
+#ifdef SHADOWPW
+ struct spwd *ss;
+ int t, c;
+#endif
+ char *pass = "";
+
+ if (!(pp = getpwnam(name)))
+ {
+ debug1("getpwnam(\"%s\") failed\n", name);
+ if (!(pw1 && *pw1 && *pw1 != '\377'))
+ {
+ debug("no unix account, no screen passwd\n");
+ sorry++;
+ }
+ }
+ else
+ pass = pp->pw_passwd;
+#ifdef SHADOWPW
+ for (t = 0; t < 13; t++)
+ {
+ c = pass[t];
+ if (!(c == '.' || c == '/' ||
+ (c >= '0' && c <= '9') ||
+ (c >= 'a' && c <= 'z') ||
+ (c >= 'A' && c <= 'Z')))
+ break;
+ }
+ if (t < 13)
+ {
+ if (!(ss = getspnam(name)))
+ {
+ debug1("getspnam(\"%s\") failed\n", name);
+ sorry++;
+ }
+ else
+ pass = ss->sp_pwdp;
+ }
+#endif /* SHADOWPW */
+
+ if (pw2 && *pw2 && *pw2 != '\377') /* provided a system password */
+ {
+ if (!PasswordMatches(pw2, pass))
+ {
+ debug("System password mismatch\n");
+ sorry++;
+ }
+ }
+ else /* no pasword provided */
+ if (*pass) /* but need one */
+ sorry++;
+#endif /* CHECKLOGIN */
+ if (pw1 && *pw1 && *pw1 != '\377') /* provided a screen password */
+ {
+ if (!PasswordMatches(pw1, u->u_password))
+ {
+ debug("screen password mismatch\n");
+ sorry++;
+ }
+ }
+ else /* no pasword provided */
+ if (*u->u_password) /* but need one */
+ sorry++;
+ }
+
+ debug2("syslog(LOG_NOTICE, \"screen %s: \"su %s\" ", SockPath, name);
+ debug2("%s for \"%s\"\n", sorry ? "failed" : "succeeded", (*up)->u_name);
+#ifndef NOSYSLOG
+# ifdef BSD_42
+ openlog("screen", LOG_PID);
+# else
+ openlog("screen", LOG_PID, LOG_AUTH);
+# endif /* BSD_42 */
+ syslog(LOG_NOTICE, "%s: \"su %s\" %s for \"%s\"", SockPath, name,
+ sorry ? "failed" : "succeeded", (*up)->u_name);
+ closelog();
+#else
+ debug("NOT LOGGED.\n");
+#endif /* NOSYSLOG */
+
+ if (sorry)
+ return "Sorry.";
+ else
+ *up = u; /* substitute user now */
+ return NULL;
+}
+#endif /* MULTIUSER */
+
+/************************************************************************
+ * end of user managing code *
+ ************************************************************************/
+
+
+#ifdef MULTIUSER
+
+/* This gives the users default rights to the new window w created by u */
+int
+NewWindowAcl(w, u)
+struct win *w;
+struct acluser *u;
+{
+ int i, j;
+
+ debug2("NewWindowAcl %s's umask_w_bits for window %d\n",
+ u ? u->u_name : "everybody", w->w_number);
+
+ /* keep these in sync with UserAdd part five. */
+ if (GrowBitfield(&w->w_mon_notify, 0, maxusercount, 0) ||
+ GrowBitfield(&w->w_lio_notify, 0, maxusercount, 0))
+ return -1;
+ for (j = 0; j < ACL_BITS_PER_WIN; j++)
+ {
+ /* we start with len 0 for the new bitfield size and add maxusercount */
+ if (GrowBitfield(&w->w_userbits[j], 0, maxusercount, 0))
+ {
+ while (--j >= 0)
+ free((char *)w->w_userbits[j]);
+ free((char *)w->w_mon_notify);
+ free((char *)w->w_lio_notify);
+ return -1;
+ }
+ for (i = 0; i < maxusercount; i++)
+ if (u ? (ACLBIT(i) & ACLBYTE(u->u_umask_w_bits[j], i)) :
+ default_w_bit[j])
+ ACLBYTE(w->w_userbits[j], i) |= ACLBIT(i);
+ }
+ return 0;
+}
+
+void
+FreeWindowAcl(w)
+struct win *w;
+{
+ int i;
+
+ for (i = 0; i < ACL_BITS_PER_WIN; i++)
+ free((char *)w->w_userbits[i]);
+ free((char *)w->w_mon_notify);
+ free((char *)w->w_lio_notify);
+}
+
+
+/* if mode starts with '-' we remove the users exec bit for cmd */
+/*
+ * NOTE: before you make this function look the same as
+ * AclSetPermWin, try to merge both functions.
+ */
+static int
+AclSetPermCmd(u, mode, cmd)
+struct acluser *u;
+char *mode;
+struct comm *cmd;
+{
+ int neg = 0;
+ char *m = mode;
+
+ while (*m)
+ {
+ switch (*m++)
+ {
+ case '-':
+ neg = 1;
+ continue;
+ case '+':
+ neg = 0;
+ continue;
+ case 'a':
+ case 'e':
+ case 'x':
+/* debug3("AclSetPermCmd %s %s %s\n", u->u_name, mode, cmd->name); */
+ if (neg)
+ ACLBYTE(cmd->userbits[ACL_EXEC], u->u_id) &= ~ACLBIT(u->u_id);
+ else
+ ACLBYTE(cmd->userbits[ACL_EXEC], u->u_id) |= ACLBIT(u->u_id);
+ break;
+ case 'r':
+ case 'w':
+ break;
+ default:
+ return -1;
+ }
+ }
+ return 0;
+}
+
+/* mode strings of the form +rwx -w+rx r -wx are parsed and evaluated */
+/*
+ * aclchg nerd -w+w 2
+ * releases a writelock on window 2 held by user nerd.
+ * Letter n allows network access on a window.
+ * uu should be NULL, except if you want to change his umask.
+ */
+static int
+AclSetPermWin(uu, u, mode, win)
+struct acluser *u, *uu;
+char *mode;
+struct win *win;
+{
+ int neg = 0;
+ int bit, bits;
+ AclBits *bitarray;
+ char *m = mode;
+
+ if (uu)
+ {
+ debug3("AclSetPermWin %s UMASK %s %s\n", uu->u_name, u->u_name, mode);
+ bitarray = uu->u_umask_w_bits;
+ }
+ else
+ {
+ ASSERT(win);
+ bitarray = win->w_userbits;
+ debug3("AclSetPermWin %s %s %d\n", u->u_name, mode, win->w_number);
+ }
+
+ while (*m)
+ {
+ switch (*m++)
+ {
+ case '-':
+ neg = 1;
+ continue;
+ case '+':
+ neg = 0;
+ continue;
+ case 'r':
+ bits = (1 << ACL_READ);
+ break;
+ case 'w':
+ bits = (1 << ACL_WRITE);
+ break;
+ case 'x':
+ bits = (1 << ACL_EXEC);
+ break;
+ case 'a':
+ bits = (1 << ACL_BITS_PER_WIN) - 1;
+ break;
+ default:
+ return -1;
+ }
+ for (bit = 0; bit < ACL_BITS_PER_WIN; bit++)
+ {
+ if (!(bits & (1 << bit)))
+ continue;
+ if (neg)
+ ACLBYTE(bitarray[bit], u->u_id) &= ~ACLBIT(u->u_id);
+ else
+ ACLBYTE(bitarray[bit], u->u_id) |= ACLBIT(u->u_id);
+ if (!uu && (win->w_wlockuser == u) && neg && (bit == ACL_WRITE))
+ {
+ debug2("%s lost writelock on win %d\n", u->u_name, win->w_number);
+ win->w_wlockuser = NULL;
+ if (win->w_wlock == WLOCK_ON)
+ win->w_wlock = WLOCK_AUTO;
+ }
+ }
+ }
+ if (uu && u->u_name[0] == '?' && u->u_name[1] == '\0')
+ {
+ /*
+ * It is Mr. '?', the unknown user. He deserves special treatment as
+ * he defines the defaults. Sorry, this is global, not per user.
+ */
+ if (win)
+ {
+ debug1("AclSetPermWin: default_w_bits '%s'.\n", mode);
+ for (bit = 0; bit < ACL_BITS_PER_WIN; bit++)
+ default_w_bit[bit] =
+ (ACLBYTE(bitarray[bit], u->u_id) & ACLBIT(u->u_id)) ? 1 : 0;
+ }
+ else
+ {
+ /*
+ * Hack. I do not want to duplicate all the above code for
+ * AclSetPermCmd. This asumes that there are not more bits
+ * per cmd than per win.
+ */
+ debug1("AclSetPermWin: default_c_bits '%s'.\n", mode);
+ for (bit = 0; bit < ACL_BITS_PER_CMD; bit++)
+ default_c_bit[bit] =
+ (ACLBYTE(bitarray[bit], u->u_id) & ACLBIT(u->u_id)) ? 1 : 0;
+ }
+ UserDel(u->u_name, NULL);
+ }
+ return 0;
+}
+
+/*
+ * String is broken down into comand and window names, mode applies
+ * A command name matches first, so do not use these as window names.
+ * uu should be NULL, except if you want to change his umask.
+ */
+int
+AclSetPerm(uu, u, mode, s)
+struct acluser *uu, *u;
+char *mode, *s;
+{
+ struct win *w;
+ int i;
+ char *p, ch;
+
+ debug3("AclSetPerm(uu, user '%s', mode '%s', object '%s')\n",
+ u->u_name, mode, s);
+ while (*s)
+ {
+ switch (*s)
+ {
+ case '*': /* all windows and all commands */
+ return AclSetPerm(uu, u, mode, "#?");
+ case '#':
+ if (uu) /* window umask or .. */
+ AclSetPermWin(uu, u, mode, (struct win *)1);
+ else /* .. or all windows */
+ for (w = windows; w; w = w->w_next)
+ AclSetPermWin((struct acluser *)0, u, mode, w);
+ s++;
+ break;
+ case '?':
+ if (uu) /* command umask or .. */
+ AclSetPermWin(uu, u, mode, (struct win *)0);
+ else /* .. or all commands */
+ for (i = 0; i <= RC_LAST; i++)
+ AclSetPermCmd(u, mode, &comms[i]);
+ s++;
+ break;
+ default:
+ for (p = s; *p && *p != ' ' && *p != '\t' && *p != ','; p++)
+ ;
+ if ((ch = *p))
+ *p++ = '\0';
+ if ((i = FindCommnr(s)) != RC_ILLEGAL)
+ AclSetPermCmd(u, mode, &comms[i]);
+ else if (((i = WindowByNoN(s)) >= 0) && wtab[i])
+ AclSetPermWin((struct acluser *)0, u, mode, wtab[i]);
+ else
+ /* checking group name */
+ return -1;
+ if (ch)
+ p[-1] = ch;
+ s = p;
+ }
+ }
+ return 0;
+}
+
+/*
+ * Generic ACL Manager:
+ *
+ * This handles acladd and aclchg identical.
+ * With 2 or 4 parameters, the second parameter is a password.
+ * With 3 or 4 parameters the last two parameters specify the permissions
+ * else user is added with full permissions.
+ * With 1 parameter the users permissions are copied from user *argv.
+ * Unlike the other cases, u->u_name should not match *argv here.
+ * uu should be NULL, except if you want to change his umask.
+ */
+static int
+UserAcl(uu, u, argc, argv)
+struct acluser *uu, **u;
+int argc;
+char **argv;
+{
+ if ((*u && !strcmp((*u)->u_name, "nobody")) ||
+ (argc > 1 && !strcmp(argv[0], "nobody")))
+ return -1; /* do not change nobody! */
+
+ switch (argc)
+ {
+ case 1+1+2:
+ debug2("UserAcl: user '%s', password '%s':", argv[0], argv[1]);
+ return (UserAdd(argv[0], argv[1], u) < 0) ||
+ AclSetPerm(uu, *u, argv[2], argv[3]);
+ case 1+2:
+ debug1("UserAcl: user '%s', no password:", argv[0]);
+ return (UserAdd(argv[0], NULL, u) < 0) ||
+ AclSetPerm(uu, *u, argv[1], argv[2]);
+ case 1+1:
+ debug2("UserAcl: user '%s', password '%s'\n", argv[0], argv[1]);
+ return UserAdd(argv[0], argv[1], u) < 0;
+ case 1:
+ debug1("UserAcl: user '%s', no password:", argv[0]);
+ return (UserAdd(argv[0], NULL, u) < 0) ||
+ AclSetPerm(uu, *u, "+a", "#?");
+ default:
+ return -1;
+ }
+}
+
+static int
+UserAclCopy(to_up, from_up)
+struct acluser **to_up, **from_up;
+{
+ struct win *w;
+ int i, j, to_id, from_id;
+
+ if (!*to_up || !*from_up)
+ return -1;
+ debug2("UserAclCopy: from user '%s' to user '%s'\n",
+ (*from_up)->u_name, (*to_up)->u_name);
+ if ((to_id = (*to_up)->u_id) == (from_id = (*from_up)->u_id))
+ return -1;
+ for (w = windows; w; w = w->w_next)
+ {
+ for (i = 0; i < ACL_BITS_PER_WIN; i++)
+ {
+ if (ACLBYTE(w->w_userbits[i], from_id) & ACLBIT(from_id))
+ ACLBYTE(w->w_userbits[i], to_id) |= ACLBIT(to_id);
+ else
+ {
+ ACLBYTE(w->w_userbits[i], to_id) &= ~ACLBIT(to_id);
+ if ((w->w_wlockuser == *to_up) && (i == ACL_WRITE))
+ {
+ debug2("%s lost wlock on win %d\n",
+ (*to_up)->u_name, w->w_number);
+ w->w_wlockuser = NULL;
+ if (w->w_wlock == WLOCK_ON)
+ w->w_wlock = WLOCK_AUTO;
+ }
+ }
+ }
+ }
+ for (j = 0; j <= RC_LAST; j++)
+ {
+ for (i = 0; i < ACL_BITS_PER_CMD; i++)
+ {
+ if (ACLBYTE(comms[j].userbits[i], from_id) & ACLBIT(from_id))
+ ACLBYTE(comms[j].userbits[i], to_id) |= ACLBIT(to_id);
+ else
+ ACLBYTE(comms[j].userbits[i], to_id) &= ~ACLBIT(to_id);
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * Syntax:
+ * user [password] [+rwx #?]
+ * * [password] [+rwx #?]
+ * user1,user2,user3 [password] [+rwx #?]
+ * user1,user2,user3=user
+ * uu should be NULL, except if you want to change his umask.
+ */
+int
+UsersAcl(uu, argc, argv)
+struct acluser *uu;
+int argc;
+char **argv;
+{
+ char *s;
+ int r;
+ struct acluser **cf_u = NULL;
+
+ if (argc == 1)
+ {
+ char *p = NULL;
+
+ s = argv[0];
+ while (*s)
+ if (*s++ == '=') p = s;
+ if (p)
+ {
+ p[-1] = '\0';
+ cf_u = FindUserPtr(p);
+ }
+ }
+
+ if (argv[0][0] == '*' && argv[0][1] == '\0')
+ {
+ struct acluser **u;
+
+ debug("all users acls.\n");
+ for (u = &users; *u; u = &(*u)->u_next)
+ if (strcmp("nobody", (*u)->u_name) &&
+ ((cf_u) ?
+ ((r = UserAclCopy(u, cf_u)) < 0) :
+ ((r = UserAcl(uu, u, argc, argv)) < 0)))
+ return -1;
+ return 0;
+ }
+
+ do
+ {
+ for (s = argv[0]; *s && *s!=' ' && *s!='\t' && *s!=',' && *s!='='; s++)
+ ;
+ *s ? (*s++ = '\0') : (*s = '\0');
+ debug2("UsersAcl(uu, \"%s\", argc=%d)\n", argv[0], argc);
+ if ((cf_u) ?
+ ((r = UserAclCopy(FindUserPtr(argv[0]), cf_u)) < 0) :
+ ((r = UserAcl(uu, FindUserPtr(argv[0]), argc, argv)) < 0))
+ return -1;
+ } while (*(argv[0] = s));
+ return 0;
+}
+
+/*
+ * Preprocess argments, so that umask can be set with UsersAcl
+ *
+ * all current users umask ±rwxn
+ * one specific user umask user1±rwxn
+ * several users umask user1,user2,...±rwxn
+ * default_w_bits umask ?±rwxn
+ * default_c_bits umask ??±rwxn
+ */
+int
+AclUmask(u, str, errp)
+struct acluser *u;
+char *str;
+char **errp;
+{
+ char mode[16];
+ char *av[3];
+ char *p, c = '\0';
+
+ /* split str into user and bits section. */
+ for (p = str; *p; p++)
+ if ((c = *p) == '+' || c == '-')
+ break;
+ if (!*p)
+ {
+ *errp = "Bad argument. Should be ``[user[,user...]{+|-}rwxn''.";
+ return -1;
+ }
+ strncpy(mode, p, 15);
+ mode[15] = '\0';
+ *p = '\0';
+
+ /* construct argument vector */
+ if (!strcmp("??", str))
+ {
+ str++;
+ av[2] = "?";
+ }
+ else
+ av[2] = "#";
+ av[1] = mode;
+ av[0] = *str ? str : "*";
+ /* call UsersAcl */
+ if (UsersAcl(u, 3, av))
+ {
+ *errp = "UsersAcl failed. Hmmm.";
+ *p = c;
+ return -1;
+ }
+ *p = c;
+ return 0;
+}
+
+void
+AclWinSwap(a, b)
+int a, b;
+{
+ debug2("AclWinSwap(%d, %d) NOP.\n", a, b);
+}
+
+struct acluser *EffectiveAclUser = NULL; /* hook for AT command permission */
+
+int
+AclCheckPermWin(u, mode, w)
+struct acluser *u;
+int mode;
+struct win *w;
+{
+ int ok;
+
+ if (mode < 0 || mode >= ACL_BITS_PER_WIN)
+ return -1;
+ if (EffectiveAclUser)
+ {
+ debug1("AclCheckPermWin: WARNING user %s overridden!\n", u->u_name);
+ u = EffectiveAclUser;
+ }
+ ok = ACLBYTE(w->w_userbits[mode], u->u_id) & ACLBIT(u->u_id);
+ debug3("AclCheckPermWin(%s, %d, %d) = ", u->u_name, mode, w->w_number);
+
+ if (!ok)
+ {
+ struct aclusergroup **g = &u->u_group;
+ struct acluser *saved_eff = EffectiveAclUser;
+
+ EffectiveAclUser = NULL;
+ while (*g)
+ {
+ if (!AclCheckPermWin((*g)->u, mode, w))
+ break;
+ g = &(*g)->next;
+ }
+ EffectiveAclUser = saved_eff;
+ if (*g)
+ ok = 1;
+ }
+ debug1("%d\n", !ok);
+ return !ok;
+}
+
+int
+AclCheckPermCmd(u, mode, c)
+struct acluser *u;
+int mode;
+struct comm *c;
+{
+ int ok;
+
+ if (mode < 0 || mode >= ACL_BITS_PER_CMD)
+ return -1;
+ if (EffectiveAclUser)
+ {
+ debug1("AclCheckPermCmd: WARNING user %s overridden!\n", u->u_name);
+ u = EffectiveAclUser;
+ }
+ ok = ACLBYTE(c->userbits[mode], u->u_id) & ACLBIT(u->u_id);
+ debug3("AclCheckPermCmd(%s %d %s) = ", u->u_name, mode, c->name);
+ if (!ok)
+ {
+ struct aclusergroup **g = &u->u_group;
+ struct acluser *saved_eff = EffectiveAclUser;
+
+ EffectiveAclUser = NULL;
+ while (*g)
+ {
+ if (!AclCheckPermCmd((*g)->u, mode, c))
+ break;
+ g = &(*g)->next;
+ }
+ EffectiveAclUser = saved_eff;
+ if (*g)
+ ok = 1;
+ }
+ debug1("%d\n", !ok);
+ return !ok;
+}
+
+#endif /* MULTIUSER */
diff --git a/acls.h b/acls.h
new file mode 100644
index 0000000..42c7c18
--- /dev/null
+++ b/acls.h
@@ -0,0 +1,98 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#ifdef MULTIUSER
+
+/* three known bits: */
+#define ACL_EXEC 0
+#define ACL_WRITE 1
+#define ACL_READ 2
+
+#define ACL_BITS_PER_CMD 1 /* for comm.h */
+#define ACL_BITS_PER_WIN 3 /* for window.h */
+
+#define USER_CHUNK 8
+
+#define ACLBYTE(data, w) ((data)[(w) >> 3])
+#define ACLBIT(w) (0x80 >> ((w) & 7))
+
+typedef unsigned char * AclBits;
+
+/*
+ * How a user joins a group.
+ * Here is the node to construct one list per user.
+ */
+struct aclusergroup
+{
+ struct acluser *u; /* the user who borrows us his rights */
+ struct aclusergroup *next;
+};
+#endif /* MULTIUSER */
+
+/***************
+ * ==> user.h
+ */
+
+/*
+ * a copy buffer
+ */
+struct plop
+{
+ char *buf;
+ int len;
+#ifdef ENCODINGS
+ int enc;
+#endif
+};
+
+/*
+ * A User has a list of groups, and points to other users.
+ * users is the User entry of the session owner (creator)
+ * and anchors all other users. Add/Delete users there.
+ */
+typedef struct acluser
+{
+ struct acluser *u_next; /* continue the main user list */
+ char u_name[MAXLOGINLEN + 1]; /* login name how he showed up */
+ char *u_password; /* his password (may be NullStr). */
+ int u_checkpassword; /* nonzero if this u_password is valid */
+ int u_detachwin; /* the window where he last detached */
+ int u_detachotherwin; /* window that was "other" when he detached */
+ int u_Esc, u_MetaEsc; /* the users screen escape character */
+#ifdef COPY_PASTE
+ struct plop u_plop;
+#endif
+#ifdef MULTIUSER
+ int u_id; /* a uniq index in the bitfields. */
+ AclBits u_umask_w_bits[ACL_BITS_PER_WIN]; /* his window create umask */
+ struct aclusergroup *u_group; /* linked list of pointers to other users */
+#endif
+} User;
+
+extern int DefaultEsc, DefaultMetaEsc;
+
diff --git a/ansi.c b/ansi.c
new file mode 100644
index 0000000..6636d10
--- /dev/null
+++ b/ansi.c
@@ -0,0 +1,3193 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+#include <fcntl.h>
+#ifndef sun /* we want to know about TIOCPKT. */
+# include <sys/ioctl.h>
+#endif
+
+#include "config.h"
+#include "screen.h"
+#include "braille.h"
+#include "extern.h"
+#include "logfile.h"
+
+extern struct display *display, *displays;
+extern struct win *fore; /* for 83 escape */
+extern struct layer *flayer; /* for 83 escape */
+
+extern struct NewWindow nwin_default; /* for ResetWindow() */
+extern int nversion; /* numerical version of screen */
+extern int log_flush, logtstamp_on, logtstamp_after;
+extern char *logtstamp_string;
+extern char *captionstring;
+extern char *hstatusstring;
+extern char *wliststr;
+#ifdef COPY_PASTE
+extern int compacthist;
+#endif
+#ifdef MULTIUSER
+extern struct acluser *EffectiveAclUser;
+#endif
+
+/* widths for Z0/Z1 switching */
+const int Z0width = 132;
+const int Z1width = 80;
+
+/* globals set in WriteString */
+static struct win *curr; /* window we are working on */
+static int rows, cols; /* window size of the curr window */
+
+int visual_bell = 0;
+int use_hardstatus = 1; /* display status line in hs */
+char *printcmd = 0;
+int use_altscreen = 0; /* enable alternate screen support? */
+
+unsigned char *blank; /* line filled with spaces */
+unsigned char *null; /* line filled with '\0' */
+
+struct mline mline_old;
+struct mline mline_blank;
+struct mline mline_null;
+
+struct mchar mchar_null;
+struct mchar mchar_blank = {' ' /* , 0, 0, ... */};
+struct mchar mchar_so = {' ', A_SO /* , 0, 0, ... */};
+
+int renditions[NUM_RENDS] = {65529 /* =ub */, 65531 /* =b */, 65533 /* =u */ };
+
+/* keep string_t and string_t_string in sync! */
+static char *string_t_string[] =
+{
+ "NONE",
+ "DCS", /* Device control string */
+ "OSC", /* Operating system command */
+ "APC", /* Application program command */
+ /* - used for status change */
+ "PM", /* Privacy message */
+ "AKA", /* title for current screen */
+ "GM", /* Global message to every display */
+ "STATUS" /* User hardstatus line */
+};
+
+/* keep state_t and state_t_string in sync! */
+static char *state_t_string[] =
+{
+ "LIT", /* Literal input */
+ "ESC", /* Start of escape sequence */
+ "ASTR", /* Start of control string */
+ "STRESC", /* ESC seen in control string */
+ "CSI", /* Reading arguments in "CSI Pn ;...*/
+ "PRIN", /* Printer mode */
+ "PRINESC", /* ESC seen in printer mode */
+ "PRINCSI", /* CSI seen in printer mode */
+ "PRIN4" /* CSI 4 seen in printer mode */
+};
+
+static int Special __P((int));
+static void DoESC __P((int, int));
+static void DoCSI __P((int, int));
+static void StringStart __P((enum string_t));
+static void StringChar __P((int));
+static int StringEnd __P((void));
+static void PrintStart __P((void));
+static void PrintChar __P((int));
+static void PrintFlush __P((void));
+#ifdef FONT
+static void DesignateCharset __P((int, int));
+static void MapCharset __P((int));
+static void MapCharsetR __P((int));
+#endif
+static void SaveCursor __P((struct cursor *));
+static void RestoreCursor __P((struct cursor *));
+static void BackSpace __P((void));
+static void Return __P((void));
+static void LineFeed __P((int));
+static void ReverseLineFeed __P((void));
+static void InsertChar __P((int));
+static void DeleteChar __P((int));
+static void DeleteLine __P((int));
+static void InsertLine __P((int));
+static void Scroll __P((char *, int, int, char *));
+static void ForwardTab __P((void));
+static void BackwardTab __P((void));
+static void ClearScreen __P((void));
+static void ClearFromBOS __P((void));
+static void ClearToEOS __P((void));
+static void ClearLineRegion __P((int, int));
+static void CursorRight __P((int));
+static void CursorUp __P((int));
+static void CursorDown __P((int));
+static void CursorLeft __P((int));
+static void ASetMode __P((int));
+static void SelectRendition __P((void));
+static void RestorePosRendition __P((void));
+static void FillWithEs __P((void));
+static void FindAKA __P((void));
+static void Report __P((char *, int, int));
+static void ScrollRegion __P((int));
+#ifdef COPY_PASTE
+static void WAddLineToHist __P((struct win *, struct mline *));
+#endif
+static void WLogString __P((struct win *, char *, int));
+static void WReverseVideo __P((struct win *, int));
+static int WindowChangedCheck __P((char *, int, int *));
+static void MFixLine __P((struct win *, int, struct mchar *));
+static void MScrollH __P((struct win *, int, int, int, int, int));
+static void MScrollV __P((struct win *, int, int, int, int));
+static void MClearArea __P((struct win *, int, int, int, int, int));
+static void MInsChar __P((struct win *, struct mchar *, int, int));
+static void MPutChar __P((struct win *, struct mchar *, int, int));
+static void MPutStr __P((struct win *, char *, int, struct mchar *, int, int));
+static void MWrapChar __P((struct win *, struct mchar *, int, int, int, int));
+#ifdef COLOR
+static void MBceLine __P((struct win *, int, int, int, int));
+#endif
+
+#ifdef COLOR
+# define CURR_BCE (curr->w_bce ? rend_getbg(&curr->w_rend) : 0)
+#else
+# define CURR_BCE 0
+#endif
+
+void
+ResetAnsiState(p)
+struct win *p;
+{
+ p->w_state = LIT;
+ p->w_StringType = NONE;
+}
+
+void
+ResetWindow(p)
+register struct win *p;
+{
+ register int i;
+
+ p->w_wrap = nwin_default.wrap;
+ p->w_origin = 0;
+ p->w_insert = 0;
+ p->w_revvid = 0;
+ p->w_mouse = 0;
+ p->w_curinv = 0;
+ p->w_curvvis = 0;
+ p->w_autolf = 0;
+ p->w_keypad = 0;
+ p->w_cursorkeys = 0;
+ p->w_top = 0;
+ p->w_bot = p->w_height - 1;
+ p->w_saved.on = 0;
+ p->w_x = p->w_y = 0;
+ p->w_state = LIT;
+ p->w_StringType = NONE;
+ bzero(p->w_tabs, p->w_width);
+ for (i = 8; i < p->w_width; i += 8)
+ p->w_tabs[i] = 1;
+ p->w_rend = mchar_null;
+#ifdef FONT
+ ResetCharsets(p);
+#endif
+#ifdef COLOR
+ p->w_bce = nwin_default.bce;
+#endif
+}
+
+/* adds max 22 bytes */
+int
+GetAnsiStatus(w, buf)
+struct win *w;
+char *buf;
+{
+ char *p = buf;
+
+ if (w->w_state == LIT)
+ return 0;
+
+ strcpy(p, state_t_string[w->w_state]);
+ p += strlen(p);
+ if (w->w_intermediate)
+ {
+ *p++ = '-';
+ if (w->w_intermediate > 0xff)
+ p += AddXChar(p, w->w_intermediate >> 8);
+ p += AddXChar(p, w->w_intermediate & 0xff);
+ *p = 0;
+ }
+ if (w->w_state == ASTR || w->w_state == STRESC)
+ sprintf(p, "-%s", string_t_string[w->w_StringType]);
+ p += strlen(p);
+ return p - buf;
+}
+
+
+#ifdef FONT
+
+void
+ResetCharsets(p)
+struct win *p;
+{
+ p->w_gr = nwin_default.gr;
+ p->w_c1 = nwin_default.c1;
+ SetCharsets(p, "BBBB02");
+ if (nwin_default.charset)
+ SetCharsets(p, nwin_default.charset);
+#ifdef ENCODINGS
+ ResetEncoding(p);
+#endif
+}
+
+void
+SetCharsets(p, s)
+struct win *p;
+char *s;
+{
+ int i;
+
+ for (i = 0; i < 4 && *s; i++, s++)
+ if (*s != '.')
+ p->w_charsets[i] = ((*s == 'B') ? ASCII : *s);
+ if (*s && *s++ != '.')
+ p->w_Charset = s[-1] - '0';
+ if (*s && *s != '.')
+ p->w_CharsetR = *s - '0';
+ p->w_ss = 0;
+ p->w_FontL = p->w_charsets[p->w_Charset];
+ p->w_FontR = p->w_charsets[p->w_CharsetR];
+}
+#endif /* FONT */
+
+/*****************************************************************/
+
+
+/*
+ * Here comes the vt100 emulator
+ * - writes logfiles,
+ * - sets timestamp and flags activity in window.
+ * - record program output in window scrollback
+ * - translate program output for the display and put it into the obuf.
+ *
+ */
+void
+WriteString(wp, buf, len)
+struct win *wp;
+register char *buf;
+register int len;
+{
+ register int c;
+#ifdef FONT
+ register int font;
+#endif
+ struct canvas *cv;
+
+ if (!len)
+ return;
+ if (wp->w_log)
+ WLogString(wp, buf, len);
+
+ /* set global variables (yuck!) */
+ curr = wp;
+ cols = curr->w_width;
+ rows = curr->w_height;
+
+ if (curr->w_silence)
+ SetTimeout(&curr->w_silenceev, curr->w_silencewait * 1000);
+
+ if (curr->w_monitor == MON_ON)
+ {
+ debug2("ACTIVITY %d %d\n", curr->w_monitor, curr->w_bell);
+ curr->w_monitor = MON_FOUND;
+ }
+
+ if (cols > 0 && rows > 0)
+ {
+ do
+ {
+ c = (unsigned char)*buf++;
+#ifdef FONT
+# ifdef DW_CHARS
+ if (!curr->w_mbcs)
+# endif
+ curr->w_rend.font = curr->w_FontL; /* Default: GL */
+#endif
+
+ /* The next part is only for speedup */
+ if (curr->w_state == LIT &&
+#ifdef UTF8
+ curr->w_encoding != UTF8 &&
+#endif
+#ifdef DW_CHARS
+ !is_dw_font(curr->w_rend.font) &&
+# ifdef ENCODINGS
+ curr->w_rend.font != KANA && !curr->w_mbcs &&
+# endif
+#endif
+#ifdef FONT
+ curr->w_rend.font != '<' &&
+#endif
+ c >= ' ' && c != 0x7f &&
+ ((c & 0x80) == 0 || ((c >= 0xa0 || !curr->w_c1) && !curr->w_gr)) && !curr->w_ss &&
+ !curr->w_insert && curr->w_x < cols - 1)
+ {
+ register int currx = curr->w_x;
+ char *imp = buf - 1;
+
+ while (currx < cols - 1)
+ {
+ currx++;
+ if (--len == 0)
+ break;
+ c = (unsigned char)*buf++;
+ if (c < ' ' || c == 0x7f || ((c & 0x80) && ((c < 0xa0 && curr->w_c1) || curr->w_gr)))
+ break;
+ }
+ currx -= curr->w_x;
+ if (currx > 0)
+ {
+ MPutStr(curr, imp, currx, &curr->w_rend, curr->w_x, curr->w_y);
+ LPutStr(&curr->w_layer, imp, currx, &curr->w_rend, curr->w_x, curr->w_y);
+ curr->w_x += currx;
+ }
+ if (len == 0)
+ break;
+ }
+ /* end of speedup code */
+
+#ifdef UTF8
+ if (curr->w_encoding == UTF8)
+ {
+ c = FromUtf8(c, &curr->w_decodestate);
+ if (c == -1)
+ continue;
+ if (c == -2)
+ {
+ c = UCS_REPL;
+ /* try char again */
+ buf--;
+ len++;
+ }
+ if (c > 0xff)
+ debug1("read UNICODE %04x\n", c);
+ }
+#endif
+
+ tryagain:
+ switch (curr->w_state)
+ {
+ case PRIN:
+ switch (c)
+ {
+ case '\033':
+ curr->w_state = PRINESC;
+ break;
+ default:
+ PrintChar(c);
+ }
+ break;
+ case PRINESC:
+ switch (c)
+ {
+ case '[':
+ curr->w_state = PRINCSI;
+ break;
+ default:
+ PrintChar('\033');
+ PrintChar(c);
+ curr->w_state = PRIN;
+ }
+ break;
+ case PRINCSI:
+ switch (c)
+ {
+ case '4':
+ curr->w_state = PRIN4;
+ break;
+ default:
+ PrintChar('\033');
+ PrintChar('[');
+ PrintChar(c);
+ curr->w_state = PRIN;
+ }
+ break;
+ case PRIN4:
+ switch (c)
+ {
+ case 'i':
+ curr->w_state = LIT;
+ PrintFlush();
+ if (curr->w_pdisplay && curr->w_pdisplay->d_printfd >= 0)
+ {
+ close(curr->w_pdisplay->d_printfd);
+ curr->w_pdisplay->d_printfd = -1;
+ }
+ curr->w_pdisplay = 0;
+ break;
+ default:
+ PrintChar('\033');
+ PrintChar('[');
+ PrintChar('4');
+ PrintChar(c);
+ curr->w_state = PRIN;
+ }
+ break;
+ case ASTR:
+ if (c == 0)
+ break;
+ if (c == '\033')
+ {
+ curr->w_state = STRESC;
+ break;
+ }
+ /* special xterm hack: accept SetStatus sequence. Yucc! */
+ /* allow ^E for title escapes */
+ if (!(curr->w_StringType == OSC && c < ' ' && c != '\005'))
+ if (!curr->w_c1 || c != ('\\' ^ 0xc0))
+ {
+ StringChar(c);
+ break;
+ }
+ c = '\\';
+ /* FALLTHROUGH */
+ case STRESC:
+ switch (c)
+ {
+ case '\\':
+ if (StringEnd() == 0 || len <= 1)
+ break;
+ /* check if somewhere a status is displayed */
+ for (cv = curr->w_layer.l_cvlist; cv; cv = cv->c_lnext)
+ {
+ display = cv->c_display;
+ if (D_status == STATUS_ON_WIN)
+ break;
+ }
+ if (cv)
+ {
+ if (len > IOSIZE + 1)
+ len = IOSIZE + 1;
+ curr->w_outlen = len - 1;
+ bcopy(buf, curr->w_outbuf, len - 1);
+ return; /* wait till status is gone */
+ }
+ break;
+ case '\033':
+ StringChar('\033');
+ break;
+ default:
+ curr->w_state = ASTR;
+ StringChar('\033');
+ StringChar(c);
+ break;
+ }
+ break;
+ case ESC:
+ switch (c)
+ {
+ case '[':
+ curr->w_NumArgs = 0;
+ curr->w_intermediate = 0;
+ bzero((char *) curr->w_args, MAXARGS * sizeof(int));
+ curr->w_state = CSI;
+ break;
+ case ']':
+ StringStart(OSC);
+ break;
+ case '_':
+ StringStart(APC);
+ break;
+ case 'P':
+ StringStart(DCS);
+ break;
+ case '^':
+ StringStart(PM);
+ break;
+ case '!':
+ StringStart(GM);
+ break;
+ case '"':
+ case 'k':
+ StringStart(AKA);
+ break;
+ default:
+ if (Special(c))
+ {
+ curr->w_state = LIT;
+ break;
+ }
+ debug1("not special. c = %x\n", c);
+ if (c >= ' ' && c <= '/')
+ {
+ if (curr->w_intermediate)
+ {
+#ifdef DW_CHARS
+ if (curr->w_intermediate == '$')
+ c |= '$' << 8;
+ else
+#endif
+ c = -1;
+ }
+ curr->w_intermediate = c;
+ }
+ else if (c >= '0' && c <= '~')
+ {
+ DoESC(c, curr->w_intermediate);
+ curr->w_state = LIT;
+ }
+ else
+ {
+ curr->w_state = LIT;
+ goto tryagain;
+ }
+ }
+ break;
+ case CSI:
+ switch (c)
+ {
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ if (curr->w_NumArgs >= 0 && curr->w_NumArgs < MAXARGS)
+ {
+ if (curr->w_args[curr->w_NumArgs] < 100000000)
+ curr->w_args[curr->w_NumArgs] =
+ 10 * curr->w_args[curr->w_NumArgs] + (c - '0');
+ }
+ break;
+ case ';':
+ case ':':
+ if (curr->w_NumArgs < MAXARGS)
+ curr->w_NumArgs++;
+ break;
+ default:
+ if (Special(c))
+ break;
+ if (c >= '@' && c <= '~')
+ {
+ if (curr->w_NumArgs < MAXARGS)
+ curr->w_NumArgs++;
+ DoCSI(c, curr->w_intermediate);
+ if (curr->w_state != PRIN)
+ curr->w_state = LIT;
+ }
+ else if ((c >= ' ' && c <= '/') || (c >= '<' && c <= '?'))
+ curr->w_intermediate = curr->w_intermediate ? -1 : c;
+ else
+ {
+ curr->w_state = LIT;
+ goto tryagain;
+ }
+ }
+ break;
+ case LIT:
+ default:
+#ifdef DW_CHARS
+ if (curr->w_mbcs)
+ if (c <= ' ' || c == 0x7f || (c >= 0x80 && c < 0xa0 && curr->w_c1))
+ curr->w_mbcs = 0;
+#endif
+ if (c < ' ')
+ {
+ if (c == '\033')
+ {
+ curr->w_intermediate = 0;
+ curr->w_state = ESC;
+ if (curr->w_autoaka < 0)
+ curr->w_autoaka = 0;
+ }
+ else
+ Special(c);
+ break;
+ }
+ if (c >= 0x80 && c < 0xa0 && curr->w_c1)
+#ifdef FONT
+ if ((curr->w_FontR & 0xf0) != 0x20
+# ifdef UTF8
+ || curr->w_encoding == UTF8
+# endif
+ )
+#endif
+ {
+ switch (c)
+ {
+ case 0xc0 ^ 'D':
+ case 0xc0 ^ 'E':
+ case 0xc0 ^ 'H':
+ case 0xc0 ^ 'M':
+ case 0xc0 ^ 'N': /* SS2 */
+ case 0xc0 ^ 'O': /* SS3 */
+ DoESC(c ^ 0xc0, 0);
+ break;
+ case 0xc0 ^ '[':
+ if (curr->w_autoaka < 0)
+ curr->w_autoaka = 0;
+ curr->w_NumArgs = 0;
+ curr->w_intermediate = 0;
+ bzero((char *) curr->w_args, MAXARGS * sizeof(int));
+ curr->w_state = CSI;
+ break;
+ case 0xc0 ^ 'P':
+ StringStart(DCS);
+ break;
+ default:
+ break;
+ }
+ break;
+ }
+
+#ifdef FONT
+# ifdef DW_CHARS
+ if (!curr->w_mbcs)
+ {
+# endif
+ if (c < 0x80 || curr->w_gr == 0)
+ curr->w_rend.font = curr->w_FontL;
+# ifdef ENCODINGS
+ else if (curr->w_gr == 2 && !curr->w_ss)
+ curr->w_rend.font = curr->w_FontE;
+# endif
+ else
+ curr->w_rend.font = curr->w_FontR;
+# ifdef DW_CHARS
+ }
+# endif
+# ifdef UTF8
+ if (curr->w_encoding == UTF8)
+ {
+ if (curr->w_rend.font == '0')
+ {
+ struct mchar mc, *mcp;
+
+ debug1("SPECIAL %x\n", c);
+ mc.image = c;
+ mc.mbcs = 0;
+ mc.font = '0';
+ mc.fontx = 0;
+ mcp = recode_mchar(&mc, 0, UTF8);
+ debug2("%02x %02x\n", mcp->image, mcp->font);
+ c = mcp->image | mcp->font << 8;
+ }
+ curr->w_rend.font = 0;
+ }
+# ifdef DW_CHARS
+ if (curr->w_encoding == UTF8 && utf8_isdouble(c))
+ curr->w_mbcs = 0xff;
+# endif
+ if (curr->w_encoding == UTF8 && c >= 0x0300 && utf8_iscomb(c))
+ {
+ int ox, oy;
+ struct mchar omc;
+
+ ox = curr->w_x - 1;
+ oy = curr->w_y;
+ if (ox < 0)
+ {
+ ox = curr->w_width - 1;
+ oy--;
+ }
+ if (oy < 0)
+ oy = 0;
+ copy_mline2mchar(&omc, &curr->w_mlines[oy], ox);
+ if (omc.image == 0xff && omc.font == 0xff && omc.fontx == 0)
+ {
+ ox--;
+ if (ox >= 0)
+ {
+ copy_mline2mchar(&omc, &curr->w_mlines[oy], ox);
+ omc.mbcs = 0xff;
+ }
+ }
+ if (ox >= 0)
+ {
+ utf8_handle_comb(c, &omc);
+ MFixLine(curr, oy, &omc);
+ copy_mchar2mline(&omc, &curr->w_mlines[oy], ox);
+ LPutChar(&curr->w_layer, &omc, ox, oy);
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+ }
+ break;
+ }
+ font = curr->w_rend.font;
+# endif
+# ifdef DW_CHARS
+# ifdef ENCODINGS
+ if (font == KANA && curr->w_encoding == SJIS && curr->w_mbcs == 0)
+ {
+ /* Lets see if it is the first byte of a kanji */
+ debug1("%x may be first of SJIS\n", c);
+ if ((0x81 <= c && c <= 0x9f) || (0xe0 <= c && c <= 0xef))
+ {
+ debug("YES!\n");
+ curr->w_mbcs = c;
+ break;
+ }
+ }
+# endif
+ if (font == 031 && c == 0x80 && !curr->w_mbcs)
+ font = curr->w_rend.font = 0;
+ if (is_dw_font(font) && c == ' ')
+ font = curr->w_rend.font = 0;
+ if (is_dw_font(font) || curr->w_mbcs)
+ {
+ int t = c;
+ if (curr->w_mbcs == 0)
+ {
+ curr->w_mbcs = c;
+ break;
+ }
+ if (curr->w_x == cols - 1)
+ {
+ curr->w_x += curr->w_wrap ? 1 : -1;
+ debug1("Patched w_x to %d\n", curr->w_x);
+ }
+# ifdef UTF8
+ if (curr->w_encoding != UTF8)
+# endif
+ {
+ c = curr->w_mbcs;
+# ifdef ENCODINGS
+ if (font == KANA && curr->w_encoding == SJIS)
+ {
+ debug2("SJIS !! %x %x\n", c, t);
+ /*
+ * SJIS -> EUC mapping:
+ * First byte:
+ * 81,82...9f -> 21,23...5d
+ * e0,e1...ef -> 5f,61...7d
+ * Second byte:
+ * 40-7e -> 21-5f
+ * 80-9e -> 60-7e
+ * 9f-fc -> 21-7e (increment first byte!)
+ */
+ if (0x40 <= t && t <= 0xfc && t != 0x7f)
+ {
+ if (c <= 0x9f) c = (c - 0x81) * 2 + 0x21;
+ else c = (c - 0xc1) * 2 + 0x21;
+ if (t <= 0x7e) t -= 0x1f;
+ else if (t <= 0x9e) t -= 0x20;
+ else t -= 0x7e, c++;
+ curr->w_rend.font = KANJI;
+ }
+ else
+ {
+ /* Incomplete shift-jis - skip first byte */
+ c = t;
+ t = 0;
+ }
+ debug2("SJIS after %x %x\n", c, t);
+ }
+# endif
+ if (t && curr->w_gr && font != 030 && font != 031)
+ {
+ t &= 0x7f;
+ if (t < ' ')
+ goto tryagain;
+ }
+ if (t == '\177')
+ break;
+ curr->w_mbcs = t;
+ }
+ }
+# endif /* DW_CHARS */
+ if (font == '<' && c >= ' ')
+ {
+ font = curr->w_rend.font = 0;
+ c |= 0x80;
+ }
+# ifdef UTF8
+ else if (curr->w_gr && curr->w_encoding != UTF8)
+# else
+ else if (curr->w_gr)
+# endif
+ {
+#ifdef ENCODINGS
+ if (c == 0x80 && font == 0 && curr->w_encoding == GBK)
+ c = 0xa4;
+ else
+ c &= 0x7f;
+ if (c < ' ' && font != 031)
+ goto tryagain;
+#else
+ c &= 0x7f;
+ if (c < ' ') /* this is ugly but kanji support */
+ goto tryagain; /* prevents nicer programming */
+#endif
+ }
+#endif /* FONT */
+ if (c == '\177')
+ break;
+ curr->w_rend.image = c;
+#ifdef UTF8
+ if (curr->w_encoding == UTF8)
+ {
+ curr->w_rend.font = c >> 8;
+ curr->w_rend.fontx = c >> 16;
+ }
+#endif
+#ifdef DW_CHARS
+ curr->w_rend.mbcs = curr->w_mbcs;
+#endif
+ if (curr->w_x < cols - 1)
+ {
+ if (curr->w_insert)
+ {
+ save_mline(&curr->w_mlines[curr->w_y], cols);
+ MInsChar(curr, &curr->w_rend, curr->w_x, curr->w_y);
+ LInsChar(&curr->w_layer, &curr->w_rend, curr->w_x, curr->w_y, &mline_old);
+ curr->w_x++;
+ }
+ else
+ {
+ MPutChar(curr, &curr->w_rend, curr->w_x, curr->w_y);
+ LPutChar(&curr->w_layer, &curr->w_rend, curr->w_x, curr->w_y);
+ curr->w_x++;
+ }
+ }
+ else if (curr->w_x == cols - 1)
+ {
+ MPutChar(curr, &curr->w_rend, curr->w_x, curr->w_y);
+ LPutChar(&curr->w_layer, &curr->w_rend, curr->w_x, curr->w_y);
+ if (curr->w_wrap)
+ curr->w_x++;
+ }
+ else
+ {
+ MWrapChar(curr, &curr->w_rend, curr->w_y, curr->w_top, curr->w_bot, curr->w_insert);
+ LWrapChar(&curr->w_layer, &curr->w_rend, curr->w_y, curr->w_top, curr->w_bot, curr->w_insert);
+ if (curr->w_y != curr->w_bot && curr->w_y != curr->w_height - 1)
+ curr->w_y++;
+ curr->w_x = 1;
+ }
+#ifdef FONT
+# ifdef DW_CHARS
+ if (curr->w_mbcs)
+ {
+ curr->w_rend.mbcs = curr->w_mbcs = 0;
+ curr->w_x++;
+ }
+# endif
+ if (curr->w_ss)
+ {
+ curr->w_FontL = curr->w_charsets[curr->w_Charset];
+ curr->w_FontR = curr->w_charsets[curr->w_CharsetR];
+ curr->w_rend.font = curr->w_FontL;
+ LSetRendition(&curr->w_layer, &curr->w_rend);
+ curr->w_ss = 0;
+ }
+#endif /* FONT */
+ break;
+ }
+ }
+ while (--len);
+ }
+ if (!printcmd && curr->w_state == PRIN)
+ PrintFlush();
+}
+
+static void
+WLogString(p, buf, len)
+struct win *p;
+char *buf;
+int len;
+{
+ if (!p->w_log)
+ return;
+ if (logtstamp_on && p->w_logsilence >= logtstamp_after * 2)
+ {
+ char *t = MakeWinMsg(logtstamp_string, p, '%');
+ logfwrite(p->w_log, t, strlen(t)); /* long time no write */
+ }
+ p->w_logsilence = 0;
+ if (logfwrite(p->w_log, buf, len) < 1)
+ {
+ WMsg(p, errno, "Error writing logfile");
+ logfclose(p->w_log);
+ p->w_log = 0;
+ }
+ if (!log_flush)
+ logfflush(p->w_log);
+}
+
+static int
+Special(c)
+register int c;
+{
+ switch (c)
+ {
+ case '\b':
+ BackSpace();
+ return 1;
+ case '\r':
+ Return();
+ return 1;
+ case '\n':
+ if (curr->w_autoaka)
+ FindAKA();
+ case '\013': /* Vertical tab is the same as Line Feed */
+ LineFeed(0);
+ return 1;
+ case '\007':
+ WBell(curr, visual_bell);
+ return 1;
+ case '\t':
+ ForwardTab();
+ return 1;
+#ifdef FONT
+ case '\017': /* SI */
+ MapCharset(G0);
+ return 1;
+ case '\016': /* SO */
+ MapCharset(G1);
+ return 1;
+#endif
+ }
+ return 0;
+}
+
+static void
+DoESC(c, intermediate)
+int c, intermediate;
+{
+ debug2("DoESC: %x - inter = %x\n", c, intermediate);
+ switch (intermediate)
+ {
+ case 0:
+ switch (c)
+ {
+ case 'E':
+ LineFeed(1);
+ break;
+ case 'D':
+ LineFeed(0);
+ break;
+ case 'M':
+ ReverseLineFeed();
+ break;
+ case 'H':
+ curr->w_tabs[curr->w_x] = 1;
+ break;
+ case 'Z': /* jph: Identify as VT100 */
+ Report("\033[?%d;%dc", 1, 2);
+ break;
+ case '7':
+ SaveCursor(&curr->w_saved);
+ break;
+ case '8':
+ RestoreCursor(&curr->w_saved);
+ break;
+ case 'c':
+ ClearScreen();
+ ResetWindow(curr);
+ LKeypadMode(&curr->w_layer, 0);
+ LCursorkeysMode(&curr->w_layer, 0);
+#ifndef TIOCPKT
+ WNewAutoFlow(curr, 1);
+#endif
+ /* XXX
+ SetRendition(&mchar_null);
+ InsertMode(0);
+ ChangeScrollRegion(0, rows - 1);
+ */
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+ break;
+ case '=':
+ LKeypadMode(&curr->w_layer, curr->w_keypad = 1);
+#ifndef TIOCPKT
+ WNewAutoFlow(curr, 0);
+#endif /* !TIOCPKT */
+ break;
+ case '>':
+ LKeypadMode(&curr->w_layer, curr->w_keypad = 0);
+#ifndef TIOCPKT
+ WNewAutoFlow(curr, 1);
+#endif /* !TIOCPKT */
+ break;
+#ifdef FONT
+ case 'n': /* LS2 */
+ MapCharset(G2);
+ break;
+ case 'o': /* LS3 */
+ MapCharset(G3);
+ break;
+ case '~':
+ MapCharsetR(G1); /* LS1R */
+ break;
+ /* { */
+ case '}':
+ MapCharsetR(G2); /* LS2R */
+ break;
+ case '|':
+ MapCharsetR(G3); /* LS3R */
+ break;
+ case 'N': /* SS2 */
+ if (curr->w_charsets[curr->w_Charset] != curr->w_charsets[G2]
+ || curr->w_charsets[curr->w_CharsetR] != curr->w_charsets[G2])
+ curr->w_FontR = curr->w_FontL = curr->w_charsets[curr->w_ss = G2];
+ else
+ curr->w_ss = 0;
+ break;
+ case 'O': /* SS3 */
+ if (curr->w_charsets[curr->w_Charset] != curr->w_charsets[G3]
+ || curr->w_charsets[curr->w_CharsetR] != curr->w_charsets[G3])
+ curr->w_FontR = curr->w_FontL = curr->w_charsets[curr->w_ss = G3];
+ else
+ curr->w_ss = 0;
+ break;
+#endif /* FONT */
+ case 'g': /* VBELL, private screen sequence */
+ WBell(curr, 1);
+ break;
+ }
+ break;
+ case '#':
+ switch (c)
+ {
+ case '8':
+ FillWithEs();
+ break;
+ }
+ break;
+#ifdef FONT
+ case '(':
+ DesignateCharset(c, G0);
+ break;
+ case ')':
+ DesignateCharset(c, G1);
+ break;
+ case '*':
+ DesignateCharset(c, G2);
+ break;
+ case '+':
+ DesignateCharset(c, G3);
+ break;
+# ifdef DW_CHARS
+/*
+ * ESC $ ( Fn: invoke multi-byte charset, Fn, to G0
+ * ESC $ Fn: same as above. (old sequence)
+ * ESC $ ) Fn: invoke multi-byte charset, Fn, to G1
+ * ESC $ * Fn: invoke multi-byte charset, Fn, to G2
+ * ESC $ + Fn: invoke multi-byte charset, Fn, to G3
+ */
+ case '$':
+ case '$'<<8 | '(':
+ DesignateCharset(c & 037, G0);
+ break;
+ case '$'<<8 | ')':
+ DesignateCharset(c & 037, G1);
+ break;
+ case '$'<<8 | '*':
+ DesignateCharset(c & 037, G2);
+ break;
+ case '$'<<8 | '+':
+ DesignateCharset(c & 037, G3);
+ break;
+# endif
+#endif /* FONT */
+ }
+}
+
+static void
+DoCSI(c, intermediate)
+int c, intermediate;
+{
+ register int i, a1 = curr->w_args[0], a2 = curr->w_args[1];
+
+ if (curr->w_NumArgs > MAXARGS)
+ curr->w_NumArgs = MAXARGS;
+ switch (intermediate)
+ {
+ case 0:
+ switch (c)
+ {
+ case 'H':
+ case 'f':
+ if (a1 < 1)
+ a1 = 1;
+ if (curr->w_origin)
+ a1 += curr->w_top;
+ if (a1 > rows)
+ a1 = rows;
+ if (a2 < 1)
+ a2 = 1;
+ if (a2 > cols)
+ a2 = cols;
+ LGotoPos(&curr->w_layer, --a2, --a1);
+ curr->w_x = a2;
+ curr->w_y = a1;
+ if (curr->w_autoaka)
+ curr->w_autoaka = a1 + 1;
+ break;
+ case 'J':
+ if (a1 < 0 || a1 > 2)
+ a1 = 0;
+ switch (a1)
+ {
+ case 0:
+ ClearToEOS();
+ break;
+ case 1:
+ ClearFromBOS();
+ break;
+ case 2:
+ ClearScreen();
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+ break;
+ }
+ break;
+ case 'K':
+ if (a1 < 0 || a1 > 2)
+ a1 %= 3;
+ switch (a1)
+ {
+ case 0:
+ ClearLineRegion(curr->w_x, cols - 1);
+ break;
+ case 1:
+ ClearLineRegion(0, curr->w_x);
+ break;
+ case 2:
+ ClearLineRegion(0, cols - 1);
+ break;
+ }
+ break;
+ case 'X':
+ a1 = curr->w_x + (a1 ? a1 - 1 : 0);
+ ClearLineRegion(curr->w_x, a1 < cols ? a1 : cols - 1);
+ break;
+ case 'A':
+ CursorUp(a1 ? a1 : 1);
+ break;
+ case 'B':
+ CursorDown(a1 ? a1 : 1);
+ break;
+ case 'C':
+ CursorRight(a1 ? a1 : 1);
+ break;
+ case 'D':
+ CursorLeft(a1 ? a1 : 1);
+ break;
+ case 'E':
+ curr->w_x = 0;
+ CursorDown(a1 ? a1 : 1); /* positions cursor */
+ break;
+ case 'F':
+ curr->w_x = 0;
+ CursorUp(a1 ? a1 : 1); /* positions cursor */
+ break;
+ case 'G':
+ case '`': /* HPA */
+ curr->w_x = a1 ? a1 - 1 : 0;
+ if (curr->w_x >= cols)
+ curr->w_x = cols - 1;
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+ break;
+ case 'd': /* VPA */
+ curr->w_y = a1 ? a1 - 1 : 0;
+ if (curr->w_y >= rows)
+ curr->w_y = rows - 1;
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+ break;
+ case 'm':
+ SelectRendition();
+ break;
+ case 'g':
+ if (a1 == 0)
+ curr->w_tabs[curr->w_x] = 0;
+ else if (a1 == 3)
+ bzero(curr->w_tabs, cols);
+ break;
+ case 'r':
+ if (!a1)
+ a1 = 1;
+ if (!a2)
+ a2 = rows;
+ if (a1 < 1 || a2 > rows || a1 >= a2)
+ break;
+ curr->w_top = a1 - 1;
+ curr->w_bot = a2 - 1;
+ /* ChangeScrollRegion(curr->w_top, curr->w_bot); */
+ if (curr->w_origin)
+ {
+ curr->w_y = curr->w_top;
+ curr->w_x = 0;
+ }
+ else
+ curr->w_y = curr->w_x = 0;
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+ break;
+ case 's':
+ SaveCursor(&curr->w_saved);
+ break;
+ case 't':
+ switch(a1)
+ {
+ case 11:
+ if (curr->w_layer.l_cvlist)
+ Report("\033[1t", 0, 0);
+ else
+ Report("\033[2t", 0, 0);
+ break;
+ case 7:
+ LRefreshAll(&curr->w_layer, 0);
+ break;
+ case 21:
+ a1 = strlen(curr->w_title);
+ if ((unsigned)(curr->w_inlen + 5 + a1) <= sizeof(curr->w_inbuf))
+ {
+ bcopy("\033]l", curr->w_inbuf + curr->w_inlen, 3);
+ bcopy(curr->w_title, curr->w_inbuf + curr->w_inlen + 3, a1);
+ bcopy("\033\\", curr->w_inbuf + curr->w_inlen + 3 + a1, 2);
+ curr->w_inlen += 5 + a1;
+ }
+ break;
+ case 8:
+ a1 = curr->w_args[2];
+ if (a1 < 1)
+ a1 = curr->w_width;
+ if (a2 < 1)
+ a2 = curr->w_height;
+ if (a1 > 10000 || a2 > 10000)
+ break;
+ WChangeSize(curr, a1, a2);
+ cols = curr->w_width;
+ rows = curr->w_height;
+ break;
+ default:
+ break;
+ }
+ break;
+ case 'u':
+ RestoreCursor(&curr->w_saved);
+ break;
+ case 'I':
+ if (!a1)
+ a1 = 1;
+ while (a1--)
+ ForwardTab();
+ break;
+ case 'Z':
+ if (!a1)
+ a1 = 1;
+ while (a1--)
+ BackwardTab();
+ break;
+ case 'L':
+ InsertLine(a1 ? a1 : 1);
+ break;
+ case 'M':
+ DeleteLine(a1 ? a1 : 1);
+ break;
+ case 'P':
+ DeleteChar(a1 ? a1 : 1);
+ break;
+ case '@':
+ InsertChar(a1 ? a1 : 1);
+ break;
+ case 'h':
+ ASetMode(1);
+ break;
+ case 'l':
+ ASetMode(0);
+ break;
+ case 'i': /* MC Media Control */
+ if (a1 == 5)
+ PrintStart();
+ break;
+ case 'n':
+ if (a1 == 5) /* Report terminal status */
+ Report("\033[0n", 0, 0);
+ else if (a1 == 6) /* Report cursor position */
+ Report("\033[%d;%dR", curr->w_y + 1, curr->w_x + 1);
+ break;
+ case 'c': /* Identify as VT100 */
+ if (a1 == 0)
+ Report("\033[?%d;%dc", 1, 2);
+ break;
+ case 'x': /* decreqtparm */
+ if (a1 == 0 || a1 == 1)
+ Report("\033[%d;1;1;112;112;1;0x", a1 + 2, 0);
+ break;
+ case 'p': /* obscure code from a 97801 term */
+ if (a1 == 6 || a1 == 7)
+ {
+ curr->w_curinv = 7 - a1;
+ LCursorVisibility(&curr->w_layer, curr->w_curinv ? -1 : curr->w_curvvis);
+ }
+ break;
+ case 'S': /* code from a 97801 term / DEC vt400 */
+ ScrollRegion(a1 ? a1 : 1);
+ break;
+ case 'T': /* code from a 97801 term / DEC vt400 */
+ case '^': /* SD as per ISO 6429 */
+ ScrollRegion(a1 ? -a1 : -1);
+ break;
+ }
+ break;
+ case '?':
+ for (a2 = 0; a2 < curr->w_NumArgs; a2++)
+ {
+ a1 = curr->w_args[a2];
+ debug2("\\E[?%d%c\n",a1,c);
+ if (c != 'h' && c != 'l')
+ break;
+ i = (c == 'h');
+ switch (a1)
+ {
+ case 1: /* CKM: cursor key mode */
+ LCursorkeysMode(&curr->w_layer, curr->w_cursorkeys = i);
+#ifndef TIOCPKT
+ WNewAutoFlow(curr, !i);
+#endif /* !TIOCPKT */
+ break;
+ case 2: /* ANM: ansi/vt52 mode */
+ if (i)
+ {
+#ifdef FONT
+# ifdef ENCODINGS
+ if (curr->w_encoding)
+ break;
+# endif
+ curr->w_charsets[0] = curr->w_charsets[1] =
+ curr->w_charsets[2] = curr->w_charsets[3] =
+ curr->w_FontL = curr->w_FontR = ASCII;
+ curr->w_Charset = 0;
+ curr->w_CharsetR = 2;
+ curr->w_ss = 0;
+#endif
+ }
+ break;
+ case 3: /* COLM: column mode */
+ i = (i ? Z0width : Z1width);
+ ClearScreen();
+ curr->w_x = 0;
+ curr->w_y = 0;
+ WChangeSize(curr, i, curr->w_height);
+ cols = curr->w_width;
+ rows = curr->w_height;
+ break;
+ /* case 4: SCLM: scrolling mode */
+ case 5: /* SCNM: screen mode */
+ if (i != curr->w_revvid)
+ WReverseVideo(curr, i);
+ curr->w_revvid = i;
+ break;
+ case 6: /* OM: origin mode */
+ if ((curr->w_origin = i) != 0)
+ {
+ curr->w_y = curr->w_top;
+ curr->w_x = 0;
+ }
+ else
+ curr->w_y = curr->w_x = 0;
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+ break;
+ case 7: /* AWM: auto wrap mode */
+ curr->w_wrap = i;
+ break;
+ /* case 8: ARM: auto repeat mode */
+ /* case 9: INLM: interlace mode */
+ case 9: /* X10 mouse tracking */
+ curr->w_mouse = i ? 9 : 0;
+ LMouseMode(&curr->w_layer, curr->w_mouse);
+ break;
+ /* case 10: EDM: edit mode */
+ /* case 11: LTM: line transmit mode */
+ /* case 13: SCFDM: space compression / field delimiting */
+ /* case 14: TEM: transmit execution mode */
+ /* case 16: EKEM: edit key execution mode */
+ /* case 18: PFF: Printer term form feed */
+ /* case 19: PEX: Printer extend screen / scroll. reg */
+ case 25: /* TCEM: text cursor enable mode */
+ curr->w_curinv = !i;
+ LCursorVisibility(&curr->w_layer, curr->w_curinv ? -1 : curr->w_curvvis);
+ break;
+ /* case 34: RLM: Right to left mode */
+ /* case 35: HEBM: hebrew keyboard map */
+ /* case 36: HEM: hebrew encoding */
+ /* case 38: TeK Mode */
+ /* case 40: 132 col enable */
+ /* case 42: NRCM: 7bit NRC character mode */
+ /* case 44: margin bell enable */
+ case 47: /* xterm-like alternate screen */
+ case 1047: /* xterm-like alternate screen */
+ case 1049: /* xterm-like alternate screen */
+ if (use_altscreen)
+ {
+ if (i)
+ {
+ if (!curr->w_alt.on) {
+ SaveCursor(&curr->w_alt.cursor);
+ EnterAltScreen(curr);
+ }
+ }
+ else
+ {
+ if (curr->w_alt.on) {
+ RestoreCursor(&curr->w_alt.cursor);
+ LeaveAltScreen(curr);
+ }
+ }
+ if (a1 == 47 && !i)
+ curr->w_saved.on = 0;
+ LRefreshAll(&curr->w_layer, 0);
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+ }
+ break;
+ case 1048:
+ if (i)
+ SaveCursor(&curr->w_saved);
+ else
+ RestoreCursor(&curr->w_saved);
+ break;
+ /* case 66: NKM: Numeric keypad appl mode */
+ /* case 68: KBUM: Keyboard usage mode (data process) */
+ case 1000: /* VT200 mouse tracking */
+ case 1001: /* VT200 highlight mouse */
+ case 1002: /* button event mouse*/
+ case 1003: /* any event mouse*/
+ curr->w_mouse = i ? a1 : 0;
+ LMouseMode(&curr->w_layer, curr->w_mouse);
+ break;
+ }
+ }
+ break;
+ case '>':
+ switch (c)
+ {
+ case 'c': /* secondary DA */
+ if (a1 == 0)
+ Report("\033[>%d;%d;0c", 83, nversion); /* 83 == 'S' */
+ break;
+ }
+ break;
+ }
+}
+
+
+static void
+StringStart(type)
+enum string_t type;
+{
+ curr->w_StringType = type;
+ curr->w_stringp = curr->w_string;
+ curr->w_state = ASTR;
+}
+
+static void
+StringChar(c)
+int c;
+{
+ if (curr->w_stringp >= curr->w_string + MAXSTR - 1)
+ curr->w_state = LIT;
+ else
+ *(curr->w_stringp)++ = c;
+}
+
+/*
+ * Do string processing. Returns -1 if output should be suspended
+ * until status is gone.
+ */
+static int
+StringEnd()
+{
+ struct canvas *cv;
+ char *p;
+ int typ;
+
+ curr->w_state = LIT;
+ *curr->w_stringp = '\0';
+ switch (curr->w_StringType)
+ {
+ case OSC: /* special xterm compatibility hack */
+ if (curr->w_string[0] == ';' || (p = index(curr->w_string, ';')) == 0)
+ break;
+ typ = atoi(curr->w_string);
+ p++;
+#ifdef MULTIUSER
+ if (typ == 83) /* 83 = 'S' */
+ {
+ /* special execute commands sequence */
+ char *args[MAXARGS];
+ int argl[MAXARGS];
+ struct acluser *windowuser;
+
+ windowuser = *FindUserPtr(":window:");
+ if (windowuser && Parse(p, sizeof(curr->w_string) - (p - curr->w_string), args, argl))
+ {
+ for (display = displays; display; display = display->d_next)
+ if (D_forecv->c_layer->l_bottom == &curr->w_layer)
+ break; /* found it */
+ if (display == 0 && curr->w_layer.l_cvlist)
+ display = curr->w_layer.l_cvlist->c_display;
+ if (display == 0)
+ display = displays;
+ EffectiveAclUser = windowuser;
+ fore = curr;
+ flayer = fore->w_savelayer ? fore->w_savelayer : &fore->w_layer;
+ DoCommand(args, argl);
+ EffectiveAclUser = 0;
+ fore = 0;
+ flayer = 0;
+ }
+ break;
+ }
+#endif
+#ifdef RXVT_OSC
+ if (typ == 0 || typ == 1 || typ == 2 || typ == 20 || typ == 39 || typ == 49)
+ {
+ int typ2;
+ typ2 = typ / 10;
+ if (--typ2 < 0)
+ typ2 = 0;
+ if (strcmp(curr->w_xtermosc[typ2], p))
+ {
+ strncpy(curr->w_xtermosc[typ2], p, sizeof(curr->w_xtermosc[typ2]) - 1);
+ curr->w_xtermosc[typ2][sizeof(curr->w_xtermosc[typ2]) - 1] = 0;
+
+ for (display = displays; display; display = display->d_next)
+ {
+ if (!D_CXT)
+ continue;
+ if (D_forecv->c_layer->l_bottom == &curr->w_layer)
+ SetXtermOSC(typ2, curr->w_xtermosc[typ2]);
+ if ((typ2 == 2 || typ2 == 3) && D_xtermosc[typ2])
+ Redisplay(0);
+ }
+ }
+ }
+ if (typ != 0 && typ != 2)
+ break;
+#else
+ if (typ < 0 || typ > 2)
+ break;
+#endif
+
+ curr->w_stringp -= p - curr->w_string;
+ if (curr->w_stringp > curr->w_string)
+ bcopy(p, curr->w_string, curr->w_stringp - curr->w_string);
+ *curr->w_stringp = '\0';
+ /* FALLTHROUGH */
+ case APC:
+ if (curr->w_hstatus)
+ {
+ if (strcmp(curr->w_hstatus, curr->w_string) == 0)
+ break; /* not changed */
+ free(curr->w_hstatus);
+ curr->w_hstatus = 0;
+ }
+ if (curr->w_string != curr->w_stringp)
+ curr->w_hstatus = SaveStr(curr->w_string);
+ WindowChanged(curr, 'h');
+ break;
+ case PM:
+ case GM:
+ for (display = displays; display; display = display->d_next)
+ {
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ if (cv->c_layer->l_bottom == &curr->w_layer)
+ break;
+ if (cv || curr->w_StringType == GM)
+ MakeStatus(curr->w_string);
+ }
+ return -1;
+ case DCS:
+ LAY_DISPLAYS(&curr->w_layer, AddStr(curr->w_string));
+ break;
+ case AKA:
+ if (curr->w_title == curr->w_akabuf && !*curr->w_string)
+ break;
+ if (curr->w_dynamicaka)
+ ChangeAKA(curr, curr->w_string, strlen(curr->w_string));
+ if (!*curr->w_string)
+ curr->w_autoaka = curr->w_y + 1;
+ break;
+ default:
+ break;
+ }
+ return 0;
+}
+
+static void
+PrintStart()
+{
+ curr->w_pdisplay = 0;
+
+ /* find us a nice display to print on, fore prefered */
+ display = curr->w_lastdisp;
+ if (!(display && curr == D_fore && (printcmd || D_PO)))
+ for (display = displays; display; display = display->d_next)
+ if (curr == D_fore && (printcmd || D_PO))
+ break;
+ if (!display)
+ {
+ struct canvas *cv;
+ for (cv = curr->w_layer.l_cvlist; cv; cv = cv->c_lnext)
+ {
+ display = cv->c_display;
+ if (printcmd || D_PO)
+ break;
+ }
+ if (!cv)
+ {
+ display = displays;
+ if (!display || display->d_next || !(printcmd || D_PO))
+ return;
+ }
+ }
+ curr->w_pdisplay = display;
+ curr->w_stringp = curr->w_string;
+ curr->w_state = PRIN;
+ if (printcmd && curr->w_pdisplay->d_printfd < 0)
+ curr->w_pdisplay->d_printfd = printpipe(curr, printcmd);
+}
+
+static void
+PrintChar(c)
+int c;
+{
+ if (curr->w_stringp >= curr->w_string + MAXSTR - 1)
+ PrintFlush();
+ *(curr->w_stringp)++ = c;
+}
+
+static void
+PrintFlush()
+{
+ display = curr->w_pdisplay;
+ if (display && printcmd)
+ {
+ char *bp = curr->w_string;
+ int len = curr->w_stringp - curr->w_string;
+ int r;
+ while (len && display->d_printfd >= 0)
+ {
+ r = write(display->d_printfd, bp, len);
+ if (r <= 0)
+ {
+ WMsg(curr, errno, "printing aborted");
+ close(display->d_printfd);
+ display->d_printfd = -1;
+ break;
+ }
+ bp += r;
+ len -= r;
+ }
+ }
+ else if (display && curr->w_stringp > curr->w_string)
+ {
+ AddCStr(D_PO);
+ AddStrn(curr->w_string, curr->w_stringp - curr->w_string);
+ AddCStr(D_PF);
+ Flush(3);
+ }
+ curr->w_stringp = curr->w_string;
+}
+
+
+void
+WNewAutoFlow(win, on)
+struct win *win;
+int on;
+{
+ debug1("WNewAutoFlow: %d\n", on);
+ if (win->w_flow & FLOW_AUTOFLAG)
+ win->w_flow = FLOW_AUTOFLAG | (FLOW_AUTO|FLOW_NOW) * on;
+ else
+ win->w_flow = (win->w_flow & ~FLOW_AUTO) | FLOW_AUTO * on;
+ LSetFlow(&win->w_layer, win->w_flow & FLOW_NOW);
+}
+
+
+#ifdef FONT
+
+static void
+DesignateCharset(c, n)
+int c, n;
+{
+ curr->w_ss = 0;
+# ifdef ENCODINGS
+ if (c == ('@' & 037)) /* map JIS 6226 to 0208 */
+ c = KANJI;
+# endif
+ if (c == 'B')
+ c = ASCII;
+ if (curr->w_charsets[n] != c)
+ {
+ curr->w_charsets[n] = c;
+ if (curr->w_Charset == n)
+ {
+ curr->w_FontL = c;
+ curr->w_rend.font = curr->w_FontL;
+ LSetRendition(&curr->w_layer, &curr->w_rend);
+ }
+ if (curr->w_CharsetR == n)
+ curr->w_FontR = c;
+ }
+}
+
+static void
+MapCharset(n)
+int n;
+{
+ curr->w_ss = 0;
+ if (curr->w_Charset != n)
+ {
+ curr->w_Charset = n;
+ curr->w_FontL = curr->w_charsets[n];
+ curr->w_rend.font = curr->w_FontL;
+ LSetRendition(&curr->w_layer, &curr->w_rend);
+ }
+}
+
+static void
+MapCharsetR(n)
+int n;
+{
+ curr->w_ss = 0;
+ if (curr->w_CharsetR != n)
+ {
+ curr->w_CharsetR = n;
+ curr->w_FontR = curr->w_charsets[n];
+ }
+ curr->w_gr = 1;
+}
+
+#endif /* FONT */
+
+static void
+SaveCursor(cursor)
+struct cursor *cursor;
+{
+ cursor->on = 1;
+ cursor->x = curr->w_x;
+ cursor->y = curr->w_y;
+ cursor->Rend = curr->w_rend;
+#ifdef FONT
+ cursor->Charset = curr->w_Charset;
+ cursor->CharsetR = curr->w_CharsetR;
+ bcopy((char *) curr->w_charsets, (char *) cursor->Charsets,
+ 4 * sizeof(int));
+#endif
+}
+
+static void
+RestoreCursor(cursor)
+struct cursor *cursor;
+{
+ if (!cursor->on)
+ return;
+ LGotoPos(&curr->w_layer, cursor->x, cursor->y);
+ curr->w_x = cursor->x;
+ curr->w_y = cursor->y;
+ curr->w_rend = cursor->Rend;
+#ifdef FONT
+ bcopy((char *) cursor->Charsets, (char *) curr->w_charsets,
+ 4 * sizeof(int));
+ curr->w_Charset = cursor->Charset;
+ curr->w_CharsetR = cursor->CharsetR;
+ curr->w_ss = 0;
+ curr->w_FontL = curr->w_charsets[curr->w_Charset];
+ curr->w_FontR = curr->w_charsets[curr->w_CharsetR];
+#endif
+ LSetRendition(&curr->w_layer, &curr->w_rend);
+}
+
+static void
+BackSpace()
+{
+ if (curr->w_x > 0)
+ {
+ curr->w_x--;
+ }
+ else if (curr->w_wrap && curr->w_y > 0)
+ {
+ curr->w_x = cols - 1;
+ curr->w_y--;
+ }
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+}
+
+static void
+Return()
+{
+ if (curr->w_x == 0)
+ return;
+ curr->w_x = 0;
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+}
+
+static void
+LineFeed(out_mode)
+int out_mode;
+{
+ /* out_mode: 0=lf, 1=cr+lf */
+ if (out_mode)
+ curr->w_x = 0;
+ if (curr->w_y != curr->w_bot) /* Don't scroll */
+ {
+ if (curr->w_y < rows-1)
+ curr->w_y++;
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+ return;
+ }
+ if (curr->w_autoaka > 1)
+ curr->w_autoaka--;
+ MScrollV(curr, 1, curr->w_top, curr->w_bot, CURR_BCE);
+ LScrollV(&curr->w_layer, 1, curr->w_top, curr->w_bot, CURR_BCE);
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+}
+
+static void
+ReverseLineFeed()
+{
+ if (curr->w_y == curr->w_top)
+ {
+ MScrollV(curr, -1, curr->w_top, curr->w_bot, CURR_BCE);
+ LScrollV(&curr->w_layer, -1, curr->w_top, curr->w_bot, CURR_BCE);
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+ }
+ else if (curr->w_y > 0)
+ CursorUp(1);
+}
+
+static void
+InsertChar(n)
+int n;
+{
+ register int y = curr->w_y, x = curr->w_x;
+
+ if (n <= 0)
+ return;
+ if (x == cols)
+ x--;
+ save_mline(&curr->w_mlines[y], cols);
+ MScrollH(curr, -n, y, x, curr->w_width - 1, CURR_BCE);
+ LScrollH(&curr->w_layer, -n, y, x, curr->w_width - 1, CURR_BCE, &mline_old);
+ LGotoPos(&curr->w_layer, x, y);
+}
+
+static void
+DeleteChar(n)
+int n;
+{
+ register int y = curr->w_y, x = curr->w_x;
+
+ if (x == cols)
+ x--;
+ save_mline(&curr->w_mlines[y], cols);
+ MScrollH(curr, n, y, x, curr->w_width - 1, CURR_BCE);
+ LScrollH(&curr->w_layer, n, y, x, curr->w_width - 1, CURR_BCE, &mline_old);
+ LGotoPos(&curr->w_layer, x, y);
+}
+
+static void
+DeleteLine(n)
+int n;
+{
+ if (curr->w_y < curr->w_top || curr->w_y > curr->w_bot)
+ return;
+ if (n > curr->w_bot - curr->w_y + 1)
+ n = curr->w_bot - curr->w_y + 1;
+ MScrollV(curr, n, curr->w_y, curr->w_bot, CURR_BCE);
+ LScrollV(&curr->w_layer, n, curr->w_y, curr->w_bot, CURR_BCE);
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+}
+
+static void
+InsertLine(n)
+int n;
+{
+ if (curr->w_y < curr->w_top || curr->w_y > curr->w_bot)
+ return;
+ if (n > curr->w_bot - curr->w_y + 1)
+ n = curr->w_bot - curr->w_y + 1;
+ MScrollV(curr, -n, curr->w_y, curr->w_bot, CURR_BCE);
+ LScrollV(&curr->w_layer, -n, curr->w_y, curr->w_bot, CURR_BCE);
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+}
+
+static void
+ScrollRegion(n)
+int n;
+{
+ MScrollV(curr, n, curr->w_top, curr->w_bot, CURR_BCE);
+ LScrollV(&curr->w_layer, n, curr->w_top, curr->w_bot, CURR_BCE);
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+}
+
+
+static void
+ForwardTab()
+{
+ register int x = curr->w_x;
+
+ if (x == cols)
+ {
+ LineFeed(1);
+ x = 0;
+ }
+ if (curr->w_tabs[x] && x < cols - 1)
+ x++;
+ while (x < cols - 1 && !curr->w_tabs[x])
+ x++;
+ curr->w_x = x;
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+}
+
+static void
+BackwardTab()
+{
+ register int x = curr->w_x;
+
+ if (curr->w_tabs[x] && x > 0)
+ x--;
+ while (x > 0 && !curr->w_tabs[x])
+ x--;
+ curr->w_x = x;
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+}
+
+static void
+ClearScreen()
+{
+ LClearArea(&curr->w_layer, 0, 0, curr->w_width - 1, curr->w_height - 1, CURR_BCE, 1);
+#ifdef COPY_PASTE
+ MScrollV(curr, curr->w_height, 0, curr->w_height - 1, CURR_BCE);
+#else
+ MClearArea(curr, 0, 0, curr->w_width - 1, curr->w_height - 1, CURR_BCE);
+#endif
+}
+
+static void
+ClearFromBOS()
+{
+ register int y = curr->w_y, x = curr->w_x;
+
+ LClearArea(&curr->w_layer, 0, 0, x, y, CURR_BCE, 1);
+ MClearArea(curr, 0, 0, x, y, CURR_BCE);
+ RestorePosRendition();
+}
+
+static void
+ClearToEOS()
+{
+ register int y = curr->w_y, x = curr->w_x;
+
+ if (x == 0 && y == 0)
+ {
+ ClearScreen();
+ RestorePosRendition();
+ return;
+ }
+ LClearArea(&curr->w_layer, x, y, cols - 1, rows - 1, CURR_BCE, 1);
+ MClearArea(curr, x, y, cols - 1, rows - 1, CURR_BCE);
+ RestorePosRendition();
+}
+
+static void
+ClearLineRegion(from, to)
+int from, to;
+{
+ register int y = curr->w_y;
+ LClearArea(&curr->w_layer, from, y, to, y, CURR_BCE, 1);
+ MClearArea(curr, from, y, to, y, CURR_BCE);
+ RestorePosRendition();
+}
+
+static void
+CursorRight(n)
+register int n;
+{
+ register int x = curr->w_x;
+
+ if (x == cols)
+ {
+ LineFeed(1);
+ x = 0;
+ }
+ if ((curr->w_x += n) >= cols)
+ curr->w_x = cols - 1;
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+}
+
+static void
+CursorUp(n)
+register int n;
+{
+ if (curr->w_y < curr->w_top) /* if above scrolling rgn, */
+ {
+ if ((curr->w_y -= n) < 0) /* ignore its limits */
+ curr->w_y = 0;
+ }
+ else
+ if ((curr->w_y -= n) < curr->w_top)
+ curr->w_y = curr->w_top;
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+}
+
+static void
+CursorDown(n)
+register int n;
+{
+ if (curr->w_y > curr->w_bot) /* if below scrolling rgn, */
+ {
+ if ((curr->w_y += n) > rows - 1) /* ignore its limits */
+ curr->w_y = rows - 1;
+ }
+ else
+ if ((curr->w_y += n) > curr->w_bot)
+ curr->w_y = curr->w_bot;
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+}
+
+static void
+CursorLeft(n)
+register int n;
+{
+ if ((curr->w_x -= n) < 0)
+ curr->w_x = 0;
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+}
+
+static void
+ASetMode(on)
+int on;
+{
+ register int i;
+
+ for (i = 0; i < curr->w_NumArgs; ++i)
+ {
+ switch (curr->w_args[i])
+ {
+ /* case 2: KAM: Lock keyboard */
+ case 4: /* IRM: Insert mode */
+ curr->w_insert = on;
+ LAY_DISPLAYS(&curr->w_layer, InsertMode(on));
+ break;
+ /* case 12: SRM: Echo mode on */
+ case 20: /* LNM: Linefeed mode */
+ curr->w_autolf = on;
+ break;
+ case 34:
+ curr->w_curvvis = !on;
+ LCursorVisibility(&curr->w_layer, curr->w_curinv ? -1 : curr->w_curvvis);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+static char rendlist[] =
+{
+ ~((1 << NATTR) - 1), A_BD, A_DI, A_SO, A_US, A_BL, 0, A_RV, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, ~(A_BD|A_SO|A_DI), ~A_SO, ~A_US, ~A_BL, 0, ~A_RV
+};
+
+static void
+SelectRendition()
+{
+#ifdef COLOR
+ register int j, i = 0, a = curr->w_rend.attr, c = curr->w_rend.color;
+# ifdef COLORS256
+ int cx = curr->w_rend.colorx;
+# endif
+#else
+ register int j, i = 0, a = curr->w_rend.attr;
+#endif
+
+ do
+ {
+ j = curr->w_args[i];
+#ifdef COLOR
+ if ((j == 38 || j == 48) && i + 2 < curr->w_NumArgs && curr->w_args[i + 1] == 5)
+ {
+ int jj;
+
+ i += 2;
+ jj = curr->w_args[i];
+ if (jj < 0 || jj > 255)
+ continue;
+# ifdef COLORS256
+ if (j == 38)
+ {
+ c = (c & 0xf0) | ((jj & 0x0f) ^ 9);
+ a |= A_BFG;
+ if (jj >= 8 && jj < 16)
+ c |= 0x08;
+ else
+ a ^= A_BFG;
+ a = (a & 0xbf) | (jj & 8 ? 0x40 : 0);
+ cx = (cx & 0xf0) | (jj >> 4 & 0x0f);
+ }
+ else
+ {
+ c = (c & 0x0f) | ((jj & 0x0f) ^ 9) << 4;
+ a |= A_BBG;
+ if (jj >= 8 && jj < 16)
+ c |= 0x80;
+ else
+ a ^= A_BBG;
+ cx = (cx & 0x0f) | (jj & 0xf0);
+ }
+ continue;
+# else
+ jj = color256to16(jj) + 30;
+ if (jj >= 38)
+ jj += 60 - 8;
+ j = j == 38 ? jj : jj + 10;
+# endif
+ }
+# ifdef COLORS16
+ if (j == 0 || (j >= 30 && j <= 39 && j != 38))
+ a &= 0xbf;
+ if (j == 0 || (j >= 40 && j <= 49 && j != 48))
+ a &= 0x7f;
+ if (j >= 90 && j <= 97)
+ a |= 0x40;
+ if (j >= 100 && j <= 107)
+ a |= 0x80;
+# endif
+ if (j >= 90 && j <= 97)
+ j -= 60;
+ if (j >= 100 && j <= 107)
+ j -= 60;
+ if (j >= 30 && j <= 39 && j != 38)
+ c = (c & 0xf0) | ((j - 30) ^ 9);
+ else if (j >= 40 && j <= 49 && j != 48)
+ c = (c & 0x0f) | (((j - 40) ^ 9) << 4);
+ if (j == 0)
+ c = 0;
+# ifdef COLORS256
+ if (j == 0 || (j >= 30 && j <= 39 && j != 38))
+ cx &= 0xf0;
+ if (j == 0 || (j >= 40 && j <= 49 && j != 48))
+ cx &= 0x0f;
+# endif
+#endif
+ if (j < 0 || j >= (int)(sizeof(rendlist)/sizeof(*rendlist)))
+ continue;
+ j = rendlist[j];
+ if (j & (1 << NATTR))
+ a &= j;
+ else
+ a |= j;
+ }
+ while (++i < curr->w_NumArgs);
+ curr->w_rend.attr = a;
+#ifdef COLOR
+ curr->w_rend.color = c;
+# ifdef COLORS256
+ curr->w_rend.colorx = cx;
+# endif
+#endif
+ LSetRendition(&curr->w_layer, &curr->w_rend);
+}
+
+static void
+FillWithEs()
+{
+ register int i;
+ register unsigned char *p, *ep;
+
+ LClearAll(&curr->w_layer, 1);
+ curr->w_y = curr->w_x = 0;
+ for (i = 0; i < rows; ++i)
+ {
+ clear_mline(&curr->w_mlines[i], 0, cols + 1);
+ p = curr->w_mlines[i].image;
+ ep = p + cols;
+ while (p < ep)
+ *p++ = 'E';
+ }
+ LRefreshAll(&curr->w_layer, 1);
+}
+
+
+/*
+ * Ugly autoaka hack support:
+ * ChangeAKA() sets a new aka
+ * FindAKA() searches for an autoaka match
+ */
+
+void
+ChangeAKA(p, s, l)
+struct win *p;
+char *s;
+int l;
+{
+ int i, c;
+
+ for (i = 0; l > 0; l--)
+ {
+ if (p->w_akachange + i == p->w_akabuf + sizeof(p->w_akabuf) - 1)
+ break;
+ c = (unsigned char)*s++;
+ if (c == 0)
+ break;
+ if (c < 32 || c == 127 || (c >= 128 && c < 160 && p->w_c1))
+ continue;
+ p->w_akachange[i++] = c;
+ }
+ p->w_akachange[i] = 0;
+ p->w_title = p->w_akachange;
+ if (p->w_akachange != p->w_akabuf)
+ if (p->w_akachange[0] == 0 || p->w_akachange[-1] == ':')
+ p->w_title = p->w_akabuf + strlen(p->w_akabuf) + 1;
+ WindowChanged(p, 't');
+ WindowChanged((struct win *)0, 'w');
+ WindowChanged((struct win *)0, 'W');
+}
+
+static void
+FindAKA()
+{
+ register unsigned char *cp, *line;
+ register struct win *wp = curr;
+ register int len = strlen(wp->w_akabuf);
+ int y;
+
+ y = (wp->w_autoaka > 0 && wp->w_autoaka <= wp->w_height) ? wp->w_autoaka - 1 : wp->w_y;
+ cols = wp->w_width;
+ try_line:
+ cp = line = wp->w_mlines[y].image;
+ if (wp->w_autoaka > 0 && *wp->w_akabuf != '\0')
+ {
+ for (;;)
+ {
+ if (cp - line >= cols - len)
+ {
+ if (++y == wp->w_autoaka && y < rows)
+ goto try_line;
+ return;
+ }
+ if (strncmp((char *)cp, wp->w_akabuf, len) == 0)
+ break;
+ cp++;
+ }
+ cp += len;
+ }
+ for (len = cols - (cp - line); len && *cp == ' '; len--, cp++)
+ ;
+ if (len)
+ {
+ if (wp->w_autoaka > 0 && (*cp == '!' || *cp == '%' || *cp == '^'))
+ wp->w_autoaka = -1;
+ else
+ wp->w_autoaka = 0;
+ line = cp;
+ while (len && *cp != ' ')
+ {
+ if (*cp++ == '/')
+ line = cp;
+ len--;
+ }
+ ChangeAKA(wp, (char *)line, cp - line);
+ }
+ else
+ wp->w_autoaka = 0;
+}
+
+static void
+RestorePosRendition()
+{
+ LGotoPos(&curr->w_layer, curr->w_x, curr->w_y);
+ LSetRendition(&curr->w_layer, &curr->w_rend);
+}
+
+/* Send a terminal report as if it were typed. */
+static void
+Report(fmt, n1, n2)
+char *fmt;
+int n1, n2;
+{
+ register int len;
+ char rbuf[40]; /* enough room for all replys */
+
+ sprintf(rbuf, fmt, n1, n2);
+ len = strlen(rbuf);
+
+#ifdef PSEUDOS
+ if (W_UWP(curr))
+ {
+ if ((unsigned)(curr->w_pwin->p_inlen + len) <= sizeof(curr->w_pwin->p_inbuf))
+ {
+ bcopy(rbuf, curr->w_pwin->p_inbuf + curr->w_pwin->p_inlen, len);
+ curr->w_pwin->p_inlen += len;
+ }
+ }
+ else
+#endif
+ {
+ if ((unsigned)(curr->w_inlen + len) <= sizeof(curr->w_inbuf))
+ {
+ bcopy(rbuf, curr->w_inbuf + curr->w_inlen, len);
+ curr->w_inlen += len;
+ }
+ }
+}
+
+
+
+/*
+ *====================================================================*
+ *====================================================================*
+ */
+
+/**********************************************************************
+ *
+ * Memory subsystem.
+ *
+ */
+
+static void
+MFixLine(p, y, mc)
+struct win *p;
+int y;
+struct mchar *mc;
+{
+ struct mline *ml = &p->w_mlines[y];
+ if (mc->attr && ml->attr == null)
+ {
+ if ((ml->attr = (unsigned char *)calloc(p->w_width + 1, 1)) == 0)
+ {
+ ml->attr = null;
+ mc->attr = p->w_rend.attr = 0;
+ WMsg(p, 0, "Warning: no space for attr - turned off");
+ }
+ }
+#ifdef FONT
+ if (mc->font && ml->font == null)
+ {
+ if ((ml->font = (unsigned char *)calloc(p->w_width + 1, 1)) == 0)
+ {
+ ml->font = null;
+ p->w_FontL = p->w_charsets[p->w_ss ? p->w_ss : p->w_Charset] = 0;
+ p->w_FontR = p->w_charsets[p->w_ss ? p->w_ss : p->w_CharsetR] = 0;
+ mc->font = mc->fontx = p->w_rend.font = 0;
+ WMsg(p, 0, "Warning: no space for font - turned off");
+ }
+ }
+ if (mc->fontx && ml->fontx == null)
+ {
+ if ((ml->fontx = (unsigned char *)calloc(p->w_width + 1, 1)) == 0)
+ {
+ ml->fontx = null;
+ mc->fontx = 0;
+ }
+ }
+#endif
+#ifdef COLOR
+ if (mc->color && ml->color == null)
+ {
+ if ((ml->color = (unsigned char *)calloc(p->w_width + 1, 1)) == 0)
+ {
+ ml->color = null;
+ mc->color = p->w_rend.color = 0;
+ WMsg(p, 0, "Warning: no space for color - turned off");
+ }
+ }
+# ifdef COLORS256
+ if (mc->colorx && ml->colorx == null)
+ {
+ if ((ml->colorx = (unsigned char *)calloc(p->w_width + 1, 1)) == 0)
+ {
+ ml->colorx = null;
+ mc->colorx = p->w_rend.colorx = 0;
+ WMsg(p, 0, "Warning: no space for extended colors - turned off");
+ }
+ }
+# endif
+#endif
+}
+
+/*****************************************************************/
+
+#ifdef DW_CHARS
+# define MKillDwRight(p, ml, x) \
+ if (dw_right(ml, x, p->w_encoding)) \
+ { \
+ if (x > 0) \
+ copy_mchar2mline(&mchar_blank, ml, x - 1); \
+ copy_mchar2mline(&mchar_blank, ml, x); \
+ }
+
+# define MKillDwLeft(p, ml, x) \
+ if (dw_left(ml, x, p->w_encoding)) \
+ { \
+ copy_mchar2mline(&mchar_blank, ml, x); \
+ copy_mchar2mline(&mchar_blank, ml, x + 1); \
+ }
+#else
+# define MKillDwRight(p, ml, x) ;
+# define MKillDwLeft(p, ml, x) ;
+#endif
+
+static void
+MScrollH(p, n, y, xs, xe, bce)
+struct win *p;
+int n, y, xs, xe, bce;
+{
+ struct mline *ml;
+
+ if (n == 0)
+ return;
+ ml = &p->w_mlines[y];
+ MKillDwRight(p, ml, xs);
+ MKillDwLeft(p, ml, xe);
+ if (n > 0)
+ {
+ if (xe - xs + 1 > n)
+ {
+ MKillDwRight(p, ml, xs + n);
+ bcopy_mline(ml, xs + n, xs, xe + 1 - xs - n);
+ }
+ else
+ n = xe - xs + 1;
+ clear_mline(ml, xe + 1 - n, n);
+#ifdef COLOR
+ if (bce)
+ MBceLine(p, y, xe + 1 - n, n, bce);
+#endif
+ }
+ else
+ {
+ n = -n;
+ if (xe - xs + 1 > n)
+ {
+ MKillDwLeft(p, ml, xe - n);
+ bcopy_mline(ml, xs, xs + n, xe + 1 - xs - n);
+ }
+ else
+ n = xe - xs + 1;
+ clear_mline(ml, xs, n);
+#ifdef COLOR
+ if (bce)
+ MBceLine(p, y, xs, n, bce);
+#endif
+ }
+}
+
+static void
+MScrollV(p, n, ys, ye, bce)
+struct win *p;
+int n, ys, ye, bce;
+{
+ int i, cnt1, cnt2;
+ struct mline tmp[256];
+ struct mline *ml;
+
+ if (n == 0)
+ return;
+ if (n > 0)
+ {
+ if (ye - ys + 1 < n)
+ n = ye - ys + 1;
+ if (n > 256)
+ {
+ MScrollV(p, n - 256, ys, ye, bce);
+ n = 256;
+ }
+#ifdef COPY_PASTE
+ if (compacthist)
+ {
+ ye = MFindUsedLine(p, ye, ys);
+ if (ye - ys + 1 < n)
+ n = ye - ys + 1;
+ if (n <= 0)
+ return;
+ }
+#endif
+ /* Clear lines */
+ ml = p->w_mlines + ys;
+ for (i = ys; i < ys + n; i++, ml++)
+ {
+#ifdef COPY_PASTE
+ if (ys == p->w_top)
+ WAddLineToHist(p, ml);
+#endif
+ if (ml->attr != null)
+ free(ml->attr);
+ ml->attr = null;
+#ifdef FONT
+ if (ml->font != null)
+ free(ml->font);
+ ml->font = null;
+ if (ml->fontx != null)
+ free(ml->fontx);
+ ml->fontx = null;
+#endif
+#ifdef COLOR
+ if (ml->color != null)
+ free(ml->color);
+ ml->color = null;
+# ifdef COLORS256
+ if (ml->colorx != null)
+ free(ml->colorx);
+ ml->colorx = null;
+# endif
+#endif
+ bclear((char *)ml->image, p->w_width + 1);
+#ifdef COLOR
+ if (bce)
+ MBceLine(p, i, 0, p->w_width, bce);
+#endif
+ }
+ /* switch 'em over */
+ cnt1 = n * sizeof(struct mline);
+ cnt2 = (ye - ys + 1 - n) * sizeof(struct mline);
+ if (cnt1 && cnt2)
+ Scroll((char *)(p->w_mlines + ys), cnt1, cnt2, (char *)tmp);
+ }
+ else
+ {
+ n = -n;
+ if (ye - ys + 1 < n)
+ n = ye - ys + 1;
+ if (n > 256)
+ {
+ MScrollV(p, - (n - 256), ys, ye, bce);
+ n = 256;
+ }
+
+ ml = p->w_mlines + ye;
+ /* Clear lines */
+ for (i = ye; i > ye - n; i--, ml--)
+ {
+ if (ml->attr != null)
+ free(ml->attr);
+ ml->attr = null;
+#ifdef FONT
+ if (ml->font != null)
+ free(ml->font);
+ ml->font = null;
+ if (ml->fontx != null)
+ free(ml->fontx);
+ ml->fontx = null;
+#endif
+#ifdef COLOR
+ if (ml->color != null)
+ free(ml->color);
+ ml->color = null;
+# ifdef COLORS256
+ if (ml->colorx != null)
+ free(ml->colorx);
+ ml->colorx = null;
+# endif
+#endif
+ bclear((char *)ml->image, p->w_width + 1);
+#ifdef COLOR
+ if (bce)
+ MBceLine(p, i, 0, p->w_width, bce);
+#endif
+ }
+ cnt1 = n * sizeof(struct mline);
+ cnt2 = (ye - ys + 1 - n) * sizeof(struct mline);
+ if (cnt1 && cnt2)
+ Scroll((char *)(p->w_mlines + ys), cnt2, cnt1, (char *)tmp);
+ }
+}
+
+static void
+Scroll(cp, cnt1, cnt2, tmp)
+char *cp, *tmp;
+int cnt1, cnt2;
+{
+ if (!cnt1 || !cnt2)
+ return;
+ if (cnt1 <= cnt2)
+ {
+ bcopy(cp, tmp, cnt1);
+ bcopy(cp + cnt1, cp, cnt2);
+ bcopy(tmp, cp + cnt2, cnt1);
+ }
+ else
+ {
+ bcopy(cp + cnt1, tmp, cnt2);
+ bcopy(cp, cp + cnt2, cnt1);
+ bcopy(tmp, cp, cnt2);
+ }
+}
+
+static void
+MClearArea(p, xs, ys, xe, ye, bce)
+struct win *p;
+int xs, ys, xe, ye, bce;
+{
+ int n, y;
+ int xxe;
+ struct mline *ml;
+
+ /* Check for zero-height window */
+ if (ys < 0 || ye < ys)
+ return;
+
+ /* check for magic margin condition */
+ if (xs >= p->w_width)
+ xs = p->w_width - 1;
+ if (xe >= p->w_width)
+ xe = p->w_width - 1;
+
+ MKillDwRight(p, p->w_mlines + ys, xs);
+ MKillDwLeft(p, p->w_mlines + ye, xe);
+
+ ml = p->w_mlines + ys;
+ for (y = ys; y <= ye; y++, ml++)
+ {
+ xxe = (y == ye) ? xe : p->w_width - 1;
+ n = xxe - xs + 1;
+ if (n > 0)
+ clear_mline(ml, xs, n);
+#ifdef COLOR
+ if (n > 0 && bce)
+ MBceLine(p, y, xs, xs + n - 1, bce);
+#endif
+ xs = 0;
+ }
+}
+
+static void
+MInsChar(p, c, x, y)
+struct win *p;
+struct mchar *c;
+int x, y;
+{
+ int n;
+ struct mline *ml;
+
+ ASSERT(x >= 0 && x < p->w_width);
+ MFixLine(p, y, c);
+ ml = p->w_mlines + y;
+ n = p->w_width - x - 1;
+ MKillDwRight(p, ml, x);
+ if (n > 0)
+ {
+ MKillDwRight(p, ml, p->w_width - 1);
+ bcopy_mline(ml, x, x + 1, n);
+ }
+ copy_mchar2mline(c, ml, x);
+#ifdef DW_CHARS
+ if (c->mbcs)
+ {
+ if (--n > 0)
+ {
+ MKillDwRight(p, ml, p->w_width - 1);
+ bcopy_mline(ml, x + 1, x + 2, n);
+ }
+ copy_mchar2mline(c, ml, x + 1);
+ ml->image[x + 1] = c->mbcs;
+# ifdef UTF8
+ if (p->w_encoding != UTF8)
+ ml->font[x + 1] |= 0x80;
+ else if (p->w_encoding == UTF8 && c->mbcs)
+ {
+ ml->font[x + 1] = c->mbcs;
+ ml->fontx[x + 1] = 0;
+ }
+# else
+ ml->font[x + 1] |= 0x80;
+# endif
+ }
+#endif
+}
+
+static void
+MPutChar(p, c, x, y)
+struct win *p;
+struct mchar *c;
+int x, y;
+{
+ struct mline *ml;
+
+ MFixLine(p, y, c);
+ ml = &p->w_mlines[y];
+ MKillDwRight(p, ml, x);
+ MKillDwLeft(p, ml, x);
+ copy_mchar2mline(c, ml, x);
+#ifdef DW_CHARS
+ if (c->mbcs)
+ {
+ MKillDwLeft(p, ml, x + 1);
+ copy_mchar2mline(c, ml, x + 1);
+ ml->image[x + 1] = c->mbcs;
+# ifdef UTF8
+ if (p->w_encoding != UTF8)
+ ml->font[x + 1] |= 0x80;
+ else if (p->w_encoding == UTF8 && c->mbcs)
+ {
+ ml->font[x + 1] = c->mbcs;
+ ml->fontx[x + 1] = 0;
+ }
+# else
+ ml->font[x + 1] |= 0x80;
+# endif
+ }
+#endif
+}
+
+
+static void
+MWrapChar(p, c, y, top, bot, ins)
+struct win *p;
+struct mchar *c;
+int y, top, bot;
+int ins;
+{
+ struct mline *ml;
+ int bce;
+
+#ifdef COLOR
+ bce = rend_getbg(c);
+#else
+ bce = 0;
+#endif
+ MFixLine(p, y, c);
+ ml = &p->w_mlines[y];
+ copy_mchar2mline(&mchar_null, ml, p->w_width);
+ if (y == bot)
+ MScrollV(p, 1, top, bot, bce);
+ else if (y < p->w_height - 1)
+ y++;
+ if (ins)
+ MInsChar(p, c, 0, y);
+ else
+ MPutChar(p, c, 0, y);
+}
+
+static void
+MPutStr(p, s, n, r, x, y)
+struct win *p;
+char *s;
+int n;
+struct mchar *r;
+int x, y;
+{
+ struct mline *ml;
+ int i;
+ unsigned char *b;
+
+ if (n <= 0)
+ return;
+ MFixLine(p, y, r);
+ ml = &p->w_mlines[y];
+ MKillDwRight(p, ml, x);
+ MKillDwLeft(p, ml, x + n - 1);
+ bcopy(s, (char *)ml->image + x, n);
+ if (ml->attr != null)
+ {
+ b = ml->attr + x;
+ for (i = n; i-- > 0;)
+ *b++ = r->attr;
+ }
+#ifdef FONT
+ if (ml->font != null)
+ {
+ b = ml->font + x;
+ for (i = n; i-- > 0;)
+ *b++ = r->font;
+ }
+ if (ml->fontx != null)
+ {
+ b = ml->fontx + x;
+ for (i = n; i-- > 0;)
+ *b++ = r->fontx;
+ }
+#endif
+#ifdef COLOR
+ if (ml->color != null)
+ {
+ b = ml->color + x;
+ for (i = n; i-- > 0;)
+ *b++ = r->color;
+ }
+# ifdef COLORS256
+ if (ml->colorx != null)
+ {
+ b = ml->colorx + x;
+ for (i = n; i-- > 0;)
+ *b++ = r->colorx;
+ }
+# endif
+#endif
+}
+
+#ifdef COLOR
+static void
+MBceLine(p, y, xs, xe, bce)
+struct win *p;
+int y, xs, xe, bce;
+{
+ struct mchar mc;
+ struct mline *ml;
+ int x;
+
+ mc = mchar_null;
+ rend_setbg(&mc, bce);
+ MFixLine(p, y, &mc);
+ ml = p->w_mlines + y;
+# ifdef COLORS16
+ if (mc.attr)
+ for (x = xs; x <= xe; x++)
+ ml->attr[x] = mc.attr;
+# endif
+ if (mc.color)
+ for (x = xs; x <= xe; x++)
+ ml->color[x] = mc.color;
+# ifdef COLORS256
+ if (mc.colorx)
+ for (x = xs; x <= xe; x++)
+ ml->colorx[x] = mc.colorx;
+# endif
+}
+#endif
+
+
+#ifdef COPY_PASTE
+static void
+WAddLineToHist(wp, ml)
+struct win *wp;
+struct mline *ml;
+{
+ register unsigned char *q, *o;
+ struct mline *hml;
+
+ if (wp->w_histheight == 0)
+ return;
+ hml = &wp->w_hlines[wp->w_histidx];
+ q = ml->image; ml->image = hml->image; hml->image = q;
+
+ q = ml->attr; o = hml->attr; hml->attr = q; ml->attr = null;
+ if (o != null)
+ free(o);
+
+#ifdef FONT
+ q = ml->font; o = hml->font; hml->font = q; ml->font = null;
+ if (o != null)
+ free(o);
+ q = ml->fontx; o = hml->fontx; hml->fontx = q; ml->fontx = null;
+ if (o != null)
+ free(o);
+#endif
+
+#ifdef COLOR
+ q = ml->color; o = hml->color; hml->color = q; ml->color = null;
+ if (o != null)
+ free(o);
+# ifdef COLORS256
+ q = ml->colorx; o = hml->colorx; hml->colorx = q; ml->colorx = null;
+ if (o != null)
+ free(o);
+# endif
+#endif
+
+ if (++wp->w_histidx >= wp->w_histheight)
+ wp->w_histidx = 0;
+ if (wp->w_scrollback_height < wp->w_histheight)
+ ++wp->w_scrollback_height;
+}
+#endif
+
+int
+MFindUsedLine(p, ye, ys)
+struct win *p;
+int ys, ye;
+{
+ int y;
+ struct mline *ml = p->w_mlines + ye;
+
+ debug2("MFindUsedLine: %d %d\n", ye, ys);
+ for (y = ye; y >= ys; y--, ml--)
+ {
+ if (bcmp((char*)ml->image, blank, p->w_width))
+ break;
+ if (ml->attr != null && bcmp((char*)ml->attr, null, p->w_width))
+ break;
+#ifdef COLOR
+ if (ml->color != null && bcmp((char*)ml->color, null, p->w_width))
+ break;
+# ifdef COLORS256
+ if (ml->colorx != null && bcmp((char*)ml->colorx, null, p->w_width))
+ break;
+# endif
+#endif
+#ifdef UTF8
+ if (p->w_encoding == UTF8)
+ {
+ if (ml->font != null && bcmp((char*)ml->font, null, p->w_width))
+ break;
+ if (ml->fontx != null && bcmp((char*)ml->fontx, null, p->w_width))
+ break;
+ }
+#endif
+ }
+ debug1("MFindUsedLine returning %d\n", y);
+ return y;
+}
+
+
+/*
+ *====================================================================*
+ *====================================================================*
+ */
+
+/*
+ * Tricky: send only one bell even if the window is displayed
+ * more than once.
+ */
+void
+WBell(p, visual)
+struct win *p;
+int visual;
+{
+ struct canvas *cv;
+ if (displays == NULL)
+ p->w_bell = BELL_DONE;
+ for (display = displays; display; display = display->d_next)
+ {
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ if (cv->c_layer->l_bottom == &p->w_layer)
+ break;
+ if (cv && !visual)
+ AddCStr(D_BL);
+ else if (cv && D_VB)
+ AddCStr(D_VB);
+ else
+ p->w_bell = visual ? BELL_VISUAL : BELL_FOUND;
+ }
+}
+
+/*
+ * This should be reverse video.
+ * Only change video if window is fore.
+ * Because it is used in some termcaps to emulate
+ * a visual bell we do this hack here.
+ * (screen uses \Eg as special vbell sequence)
+ */
+static void
+WReverseVideo(p, on)
+struct win *p;
+int on;
+{
+ struct canvas *cv;
+ for (cv = p->w_layer.l_cvlist; cv; cv = cv->c_lnext)
+ {
+ display = cv->c_display;
+ if (cv != D_forecv)
+ continue;
+ ReverseVideo(on);
+ if (!on && p->w_revvid && !D_CVR)
+ {
+ if (D_VB)
+ AddCStr(D_VB);
+ else
+ p->w_bell = BELL_VISUAL;
+ }
+ }
+}
+
+void
+WMsg(p, err, str)
+struct win *p;
+int err;
+char *str;
+{
+ extern struct layer *flayer;
+ struct layer *oldflayer = flayer;
+ flayer = &p->w_layer;
+ LMsg(err, "%s", str);
+ flayer = oldflayer;
+}
+
+void
+WChangeSize(p, w, h)
+struct win *p;
+int w, h;
+{
+ int wok = 0;
+ struct canvas *cv;
+
+ if (p->w_layer.l_cvlist == 0)
+ {
+ /* window not displayed -> works always */
+ ChangeWindowSize(p, w, h, p->w_histheight);
+ return;
+ }
+ for (cv = p->w_layer.l_cvlist; cv; cv = cv->c_lnext)
+ {
+ display = cv->c_display;
+ if (p != D_fore)
+ continue; /* change only fore */
+ if (D_CWS)
+ break;
+ if (D_CZ0 && (w == Z0width || w == Z1width))
+ wok = 1;
+ }
+ if (cv == 0 && wok == 0) /* can't change any display */
+ return;
+ if (!D_CWS)
+ h = p->w_height;
+ ChangeWindowSize(p, w, h, p->w_histheight);
+ for (display = displays; display; display = display->d_next)
+ {
+ if (p == D_fore)
+ {
+ if (D_cvlist && D_cvlist->c_next == 0)
+ ResizeDisplay(w, h);
+ else
+ ResizeDisplay(w, D_height);
+ ResizeLayersToCanvases(); /* XXX Hmm ? */
+ continue;
+ }
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ if (cv->c_layer->l_bottom == &p->w_layer)
+ break;
+ if (cv)
+ Redisplay(0);
+ }
+}
+
+static int
+WindowChangedCheck(s, what, hp)
+char *s;
+int what;
+int *hp;
+{
+ int h = 0;
+ int l;
+ while(*s)
+ {
+ if (*s++ != (hp ? '%' : '\005'))
+ continue;
+ l = 0;
+ s += (*s == '+');
+ s += (*s == '-');
+ while (*s >= '0' && *s <= '9')
+ s++;
+ if (*s == 'L')
+ {
+ s++;
+ l = 0x100;
+ }
+ if (*s == 'h')
+ h = 1;
+ if (*s == what || ((*s | l) == what) || what == 'd')
+ break;
+ if (*s)
+ s++;
+ }
+ if (hp)
+ *hp = h;
+ return *s ? 1 : 0;
+}
+
+void
+WindowChanged(p, what)
+struct win *p;
+int what;
+{
+ int inwstr, inhstr, inlstr;
+ int inwstrh = 0, inhstrh = 0, inlstrh = 0;
+ int got, ox, oy;
+ struct display *olddisplay = display;
+ struct canvas *cv;
+
+ inwstr = inhstr = 0;
+
+ if (what == 'f')
+ {
+ WindowChanged((struct win *)0, 'w'|0x100);
+ WindowChanged((struct win *)0, 'W'|0x100);
+ }
+
+ if (what)
+ {
+ inwstr = WindowChangedCheck(captionstring, what, &inwstrh);
+ inhstr = WindowChangedCheck(hstatusstring, what, &inhstrh);
+ inlstr = WindowChangedCheck(wliststr, what, &inlstrh);
+ }
+ else
+ {
+ inwstr = inhstr = 0;
+ inlstr = 1;
+ }
+
+ if (p == 0)
+ {
+ for (display = displays; display; display = display->d_next)
+ {
+ ox = D_x;
+ oy = D_y;
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ {
+ if (inlstr || (inlstrh && p && p->w_hstatus && *p->w_hstatus && WindowChangedCheck(p->w_hstatus, what, (int *)0)))
+ WListUpdatecv(cv, (struct win *)0);
+ p = Layer2Window(cv->c_layer);
+ if (inwstr || (inwstrh && p && p->w_hstatus && *p->w_hstatus && WindowChangedCheck(p->w_hstatus, what, (int *)0)))
+ if (cv->c_ye + 1 < D_height)
+ RefreshLine(cv->c_ye + 1, 0, D_width - 1, 0);
+ }
+ p = D_fore;
+ if (inhstr || (inhstrh && p && p->w_hstatus && *p->w_hstatus && WindowChangedCheck(p->w_hstatus, what, (int *)0)))
+ RefreshHStatus();
+ if (ox != -1 && oy != -1)
+ GotoPos(ox, oy);
+ }
+ display = olddisplay;
+ return;
+ }
+
+ if (p->w_hstatus && *p->w_hstatus && (inwstrh || inhstrh || inlstrh) && WindowChangedCheck(p->w_hstatus, what, (int *)0))
+ {
+ inwstr |= inwstrh;
+ inhstr |= inhstrh;
+ inlstr |= inlstrh;
+ }
+ if (!inwstr && !inhstr && !inlstr)
+ return;
+ for (display = displays; display; display = display->d_next)
+ {
+ got = 0;
+ ox = D_x;
+ oy = D_y;
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ {
+ if (inlstr)
+ WListUpdatecv(cv, p);
+ if (Layer2Window(cv->c_layer) != p)
+ continue;
+ got = 1;
+ if (inwstr && cv->c_ye + 1 < D_height)
+ RefreshLine(cv->c_ye + 1, 0, D_width - 1, 0);
+ }
+ if (got && inhstr && p == D_fore)
+ RefreshHStatus();
+ if (ox != -1 && oy != -1)
+ GotoPos(ox, oy);
+ }
+ display = olddisplay;
+}
+
diff --git a/ansi.h b/ansi.h
new file mode 100644
index 0000000..72992b4
--- /dev/null
+++ b/ansi.h
@@ -0,0 +1,175 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+#define NATTR 6
+
+#define ATTR_DI 0 /* Dim mode */
+#define ATTR_US 1 /* Underscore mode */
+#define ATTR_BD 2 /* Bold mode */
+#define ATTR_RV 3 /* Reverse mode */
+#define ATTR_SO 4 /* Standout mode */
+#define ATTR_BL 5 /* Blinking */
+
+#define A_DI (1<<ATTR_DI)
+#define A_US (1<<ATTR_US)
+#define A_BD (1<<ATTR_BD)
+#define A_RV (1<<ATTR_RV)
+#define A_SO (1<<ATTR_SO)
+#define A_BL (1<<ATTR_BL)
+#define A_MAX (1<<(NATTR-1))
+
+#define ATYP_M (1<<0)
+#define ATYP_S (1<<1)
+#define ATYP_U (1<<2)
+
+#ifdef COLORS16
+/* pseudo attributes */
+# define ATTR_BFG 6 /* bright foreground */
+# define ATTR_BBG 7 /* bright background */
+# define A_BFG (1<<ATTR_BFG)
+# define A_BBG (1<<ATTR_BBG)
+#endif
+
+/*
+ * Parser state
+ */
+/* keep state_t and state_t_string in sync! */
+enum state_t
+{
+ LIT, /* Literal input */
+ ESC, /* Start of escape sequence */
+ ASTR, /* Start of control string */
+ STRESC, /* ESC seen in control string */
+ CSI, /* Reading arguments in "CSI Pn ;...*/
+ PRIN, /* Printer mode */
+ PRINESC, /* ESC seen in printer mode */
+ PRINCSI, /* CSI seen in printer mode */
+ PRIN4 /* CSI 4 seen in printer mode */
+};
+
+/* keep string_t and string_t_string in sync! */
+enum string_t
+{
+ NONE,
+ DCS, /* Device control string */
+ OSC, /* Operating system command */
+ APC, /* Application program command */
+ /* - used for status change */
+ PM, /* Privacy message */
+ AKA, /* title for current screen */
+ GM, /* Global message to every display */
+ STATUS /* User hardstatus line */
+};
+
+/*
+ * Types of movement used by GotoPos()
+ */
+enum move_t {
+ M_NONE,
+ M_UP,
+ M_CUP,
+ M_DO,
+ M_CDO,
+ M_LE,
+ M_CLE,
+ M_RI,
+ M_CRI,
+ M_RW,
+ M_CR /* CR and rewrite */
+};
+
+#define EXPENSIVE 1000
+
+#define G0 0
+#define G1 1
+#define G2 2
+#define G3 3
+
+#define ASCII 0
+
+#ifdef TOPSTAT
+#define STATLINE (0)
+#else
+#define STATLINE (D_height-1)
+#endif
+
+#ifdef ENCODINGS
+
+#define KANJI ('B' & 037)
+#define KANJI0212 ('D' & 037)
+#define KANA 'I'
+
+#define EUC_JP 1
+#define SJIS 2
+#define EUC_KR 3
+#define EUC_CN 4
+#define BIG5 5
+#define KOI8R 6
+#define CP1251 7
+#define GBK 20
+
+#define EUC EUC_JP
+
+#endif
+
+#ifdef UTF8
+#undef UTF8
+#define UTF8 8
+#endif
+
+#ifdef UTF8
+# define UCS_REPL 0xfffd /* character for illegal codes */
+# define UCS_REPL_DW 0xff1f /* character for illegal codes */
+# define UCS_HIDDEN 0xffff
+#endif
+
+#ifdef DW_CHARS
+# define is_dw_font(f) ((f) && ((f) & 0x60) == 0)
+
+# ifdef UTF8
+# define dw_left(ml, x, enc) ((enc == UTF8) ? \
+ (unsigned char)(ml)->font[(x) + 1] == 0xff && (unsigned char)(ml)->image[(x) + 1] == 0xff : \
+ ((unsigned char)(ml)->font[x] & 0x1f) != 0 && ((unsigned char)(ml)->font[x] & 0xe0) == 0 \
+ )
+# define dw_right(ml, x, enc) ((enc == UTF8) ? \
+ (unsigned char)(ml)->font[x] == 0xff && (unsigned char)(ml)->image[x] == 0xff : \
+ ((unsigned char)(ml)->font[x] & 0xe0) == 0x80 \
+ )
+# else
+# define dw_left(ml, x, enc) ( \
+ ((unsigned char)(ml)->font[x] & 0x1f) != 0 && ((unsigned char)(ml)->font[x] & 0xe0) == 0 \
+ )
+# define dw_right(ml, x, enc) ( \
+ ((unsigned char)(ml)->font[x] & 0xe0) == 0x80 \
+ )
+# endif /* UTF8 */
+#else
+# define dw_left(ml, x, enc) 0
+# define dw_right(ml, x, enc) 0
+#endif
diff --git a/attacher.c b/attacher.c
new file mode 100644
index 0000000..196993f
--- /dev/null
+++ b/attacher.c
@@ -0,0 +1,1113 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include "config.h"
+#include <stdbool.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <signal.h>
+#include "screen.h"
+#include "extern.h"
+
+#include <pwd.h>
+
+static int WriteMessage __P((int, struct msg *));
+static sigret_t AttacherSigInt __P(SIGPROTOARG);
+#if defined(SIGWINCH) && defined(TIOCGWINSZ)
+static sigret_t AttacherWinch __P(SIGPROTOARG);
+#endif
+#ifdef LOCK
+static sigret_t DoLock __P(SIGPROTOARG);
+static void LockTerminal __P((void));
+static sigret_t LockHup __P(SIGPROTOARG);
+static void screen_builtin_lck __P((void));
+#endif
+#ifdef DEBUG
+static sigret_t AttacherChld __P(SIGPROTOARG);
+#endif
+static sigret_t AttachSigCont __P(SIGPROTOARG);
+
+extern int real_uid, real_gid, eff_uid, eff_gid;
+extern char *SockName, *SockMatch, SockPath[];
+extern char HostName[];
+extern struct passwd *ppp;
+extern char *attach_tty, *attach_term, *LoginName, *preselect;
+/* Indicator whether the current tty exists in another namespace. */
+extern bool attach_tty_is_in_new_ns;
+/* Content of the tty symlink when attach_tty_is_in_new_ns == true. */
+extern char attach_tty_name_in_ns[];
+extern int xflag, dflag, rflag, quietflag, adaptflag;
+extern struct mode attach_Mode;
+extern struct NewWindow nwin_options;
+extern int MasterPid, attach_fd;
+
+#ifdef MULTIUSER
+extern char *multi;
+extern int multiattach, multi_uid, own_uid;
+extern int tty_mode, tty_oldmode;
+# ifndef USE_SETEUID
+static int multipipe[2];
+# endif
+#endif
+
+
+static int ContinuePlease;
+
+static sigret_t
+AttachSigCont SIGDEFARG
+{
+ debug("SigCont()\n");
+ ContinuePlease = 1;
+ SIGRETURN;
+}
+
+static int QueryResult;
+
+static sigret_t
+QueryResultSuccess SIGDEFARG
+{
+ QueryResult = 1;
+ SIGRETURN;
+}
+
+static sigret_t
+QueryResultFail SIGDEFARG
+{
+ QueryResult = 2;
+ SIGRETURN;
+}
+
+/*
+ * Send message to a screen backend.
+ * returns 1 if we could attach one, or 0 if none.
+ * Understands MSG_ATTACH, MSG_DETACH, MSG_POW_DETACH
+ * MSG_CONT, MSG_WINCH and nothing else!
+ *
+ * if type == MSG_ATTACH and sockets are used, attaches
+ * tty filedescriptor.
+ */
+
+static int
+WriteMessage(s, m)
+int s;
+struct msg *m;
+{
+ int r, l = sizeof(*m);
+ bool is_socket;
+
+ is_socket = IsSocket(SockPath);
+ if (is_socket && m->type == MSG_ATTACH)
+ return SendAttachMsg(s, m, attach_fd);
+
+ while(l > 0)
+ {
+ r = write(s, (char *)m + (sizeof(*m) - l), l);
+ if (r == -1 && errno == EINTR)
+ continue;
+ if (r == -1 || r == 0)
+ return -1;
+ l -= r;
+ }
+ return 0;
+}
+
+
+int
+Attach(how)
+int how;
+{
+ int n, lasts;
+ struct msg m;
+ struct stat st;
+ char *s;
+ bool is_socket;
+
+ debug2("Attach: how=%d, tty=%s\n", how, attach_tty);
+#ifdef MULTIUSER
+# ifndef USE_SETEUID
+ while ((how == MSG_ATTACH || how == MSG_CONT) && multiattach)
+ {
+ int ret;
+
+ if (pipe(multipipe))
+ Panic(errno, "pipe");
+ if (chmod(attach_tty, 0666))
+ Panic(errno, "chmod %s", attach_tty);
+ tty_oldmode = tty_mode;
+ eff_uid = -1; /* make UserContext fork */
+ real_uid = multi_uid;
+ if ((ret = UserContext()) <= 0)
+ {
+ char dummy;
+ eff_uid = 0;
+ real_uid = own_uid;
+ if (ret < 0)
+ Panic(errno, "UserContext");
+ close(multipipe[1]);
+ read(multipipe[0], &dummy, 1);
+ if (tty_oldmode >= 0)
+ {
+ chmod(attach_tty, tty_oldmode);
+ tty_oldmode = -1;
+ }
+ ret = UserStatus();
+#ifdef LOCK
+ if (ret == SIG_LOCK)
+ LockTerminal();
+ else
+#endif
+#ifdef SIGTSTP
+ if (ret == SIG_STOP)
+ kill(getpid(), SIGTSTP);
+ else
+#endif
+ if (ret == SIG_POWER_BYE)
+ {
+ int ppid;
+ if (setgid(real_gid) || setuid(real_uid))
+ Panic(errno, "setuid/gid");
+ if ((ppid = getppid()) > 1)
+ Kill(ppid, SIGHUP);
+ exit(0);
+ }
+ else
+ exit(ret);
+ dflag = 0;
+#ifdef MULTI
+ xflag = 1;
+#endif
+ how = MSG_ATTACH;
+ continue;
+ }
+ close(multipipe[0]);
+ eff_uid = real_uid;
+ break;
+ }
+# else /* USE_SETEUID */
+ if ((how == MSG_ATTACH || how == MSG_CONT) && multiattach)
+ {
+ real_uid = multi_uid;
+ eff_uid = own_uid;
+#ifdef HAVE_SETRESUID
+ if (setresuid(multi_uid, own_uid, multi_uid))
+ Panic(errno, "setresuid");
+#else
+ xseteuid(multi_uid);
+ xseteuid(own_uid);
+#endif
+ if (chmod(attach_tty, 0666))
+ Panic(errno, "chmod %s", attach_tty);
+ tty_oldmode = tty_mode;
+ }
+# endif /* USE_SETEUID */
+#endif /* MULTIUSER */
+
+ bzero((char *) &m, sizeof(m));
+ m.type = how;
+ m.protocol_revision = MSG_REVISION;
+ strncpy(m.m_tty, attach_tty_is_in_new_ns ? attach_tty_name_in_ns : attach_tty, sizeof(m.m_tty) - 1);
+ m.m_tty[sizeof(m.m_tty) - 1] = 0;
+
+ is_socket = IsSocket(SockPath);
+ if (how == MSG_WINCH)
+ {
+ if ((lasts = MakeClientSocket(0, is_socket)) >= 0)
+ {
+ WriteMessage(lasts, &m);
+ close(lasts);
+ }
+ return 0;
+ }
+
+ if (how == MSG_CONT)
+ {
+ if ((lasts = MakeClientSocket(0, is_socket)) < 0)
+ {
+ Panic(0, "Sorry, cannot contact session \"%s\" again.\r\n",
+ SockName);
+ }
+ }
+ else
+ {
+ n = FindSocket(&lasts, (int *)0, (int *)0, SockMatch, &is_socket);
+ switch (n)
+ {
+ case 0:
+ if (rflag && (rflag & 1) == 0)
+ return 0;
+ if (quietflag)
+ eexit(10);
+ if (SockMatch && *SockMatch) {
+ Panic(0, "There is no screen to be %sed matching %s.",
+ xflag ? "attach" :
+ dflag ? "detach" :
+ "resum", SockMatch);
+ } else {
+ Panic(0, "There is no screen to be %sed.",
+ xflag ? "attach" :
+ dflag ? "detach" :
+ "resum");
+ }
+ /* NOTREACHED */
+ case 1:
+ break;
+ default:
+ if (rflag < 3)
+ {
+ if (quietflag)
+ eexit(10 + n);
+ Panic(0, "Type \"screen [-d] -r [pid.]tty.host\" to resume one of them.");
+ }
+ /* NOTREACHED */
+ }
+ }
+ /*
+ * Go in UserContext. Advantage is, you can kill your attacher
+ * when things go wrong. Any disadvantages? jw.
+ * Do this before the attach to prevent races!
+ */
+#ifdef MULTIUSER
+ if (!multiattach)
+#endif
+ {
+ if (setuid(real_uid))
+ Panic(errno, "setuid");
+ }
+#if defined(MULTIUSER) && defined(USE_SETEUID)
+ else
+ {
+ /* This call to xsetuid should also set the saved uid */
+ xseteuid(real_uid); /* multi_uid, allow backend to send signals */
+ }
+#endif
+ if (setgid(real_gid))
+ Panic(errno, "setgid");
+ eff_uid = real_uid;
+ eff_gid = real_gid;
+
+ debug2("Attach: uid %d euid %d\n", (int)getuid(), (int)geteuid());
+ MasterPid = 0;
+ for (s = SockName; *s; s++)
+ {
+ if (*s > '9' || *s < '0')
+ break;
+ MasterPid = 10 * MasterPid + (*s - '0');
+ }
+ debug1("Attach decided, it is '%s'\n", SockPath);
+ debug1("Attach found MasterPid == %d\n", MasterPid);
+ if (stat(SockPath, &st) == -1)
+ Panic(errno, "stat %s", SockPath);
+ if ((st.st_mode & 0600) != 0600)
+ Panic(0, "Socket is in wrong mode (%03o)", (int)st.st_mode);
+
+ /*
+ * Change: if -x or -r ignore failing -d
+ */
+ if ((xflag || rflag) && dflag && (st.st_mode & 0700) == 0600)
+ dflag = 0;
+
+ /*
+ * Without -x, the mode must match.
+ * With -x the mode is irrelevant unless -d.
+ */
+ if ((dflag || !xflag) && (st.st_mode & 0700) != (dflag ? 0700 : 0600))
+ Panic(0, "That screen is %sdetached.", dflag ? "already " : "not ");
+#ifdef REMOTE_DETACH
+ if (dflag &&
+ (how == MSG_DETACH || how == MSG_POW_DETACH))
+ {
+ m.m.detach.dpid = getpid();
+ strncpy(m.m.detach.duser, LoginName, sizeof(m.m.detach.duser) - 1);
+ m.m.detach.duser[sizeof(m.m.detach.duser) - 1] = 0;
+# ifdef POW_DETACH
+ if (dflag == 2)
+ m.type = MSG_POW_DETACH;
+ else
+# endif
+ m.type = MSG_DETACH;
+ /* If there is no password for the session, or the user enters the correct
+ * password, then we get a SIGCONT. Otherwise we get a SIG_BYE */
+ signal(SIGCONT, AttachSigCont);
+ if (WriteMessage(lasts, &m))
+ Panic(errno, "WriteMessage");
+ close(lasts);
+ while (!ContinuePlease)
+ pause(); /* wait for SIGCONT */
+ signal(SIGCONT, SIG_DFL);
+ ContinuePlease = 0;
+ if (how != MSG_ATTACH)
+ return 0; /* we detached it. jw. */
+ sleep(1); /* we dont want to overrun our poor backend. jw. */
+ if ((lasts = MakeClientSocket(0, is_socket)) == -1)
+ Panic(0, "Cannot contact screen again. Sigh.");
+ m.type = how;
+ }
+#endif
+ ASSERT(how == MSG_ATTACH || how == MSG_CONT);
+ strncpy(m.m.attach.envterm, attach_term, MAXTERMLEN);
+ m.m.attach.envterm[MAXTERMLEN] = 0;
+ debug1("attach: sending %d bytes... ", (int)sizeof(m));
+
+ strncpy(m.m.attach.auser, LoginName, sizeof(m.m.attach.auser) - 1);
+ m.m.attach.auser[sizeof(m.m.attach.auser) - 1] = 0;
+ m.m.attach.esc = DefaultEsc;
+ m.m.attach.meta_esc = DefaultMetaEsc;
+ strncpy(m.m.attach.preselect, preselect ? preselect : "", sizeof(m.m.attach.preselect) - 1);
+ m.m.attach.preselect[sizeof(m.m.attach.preselect) - 1] = 0;
+ m.m.attach.apid = getpid();
+ m.m.attach.adaptflag = adaptflag;
+ m.m.attach.lines = m.m.attach.columns = 0;
+ if ((s = getenv("LINES")))
+ m.m.attach.lines = atoi(s);
+ if ((s = getenv("COLUMNS")))
+ m.m.attach.columns = atoi(s);
+ m.m.attach.encoding = nwin_options.encoding > 0 ? nwin_options.encoding + 1 : 0;
+
+#ifdef REMOTE_DETACH
+#ifdef POW_DETACH
+ if (dflag == 2)
+ m.m.attach.detachfirst = MSG_POW_DETACH;
+ else
+#endif
+ if (dflag)
+ m.m.attach.detachfirst = MSG_DETACH;
+ else
+#endif
+ m.m.attach.detachfirst = MSG_ATTACH;
+
+#ifdef MULTIUSER
+ /* setup CONT signal handler to repair the terminal mode */
+ if (multi && (how == MSG_ATTACH || how == MSG_CONT))
+ signal(SIGCONT, AttachSigCont);
+#endif
+
+ if (WriteMessage(lasts, &m))
+ Panic(errno, "WriteMessage");
+ close(lasts);
+ debug1("Attach(%d): sent\n", m.type);
+#ifdef MULTIUSER
+ if (multi && (how == MSG_ATTACH || how == MSG_CONT))
+ {
+ while (!ContinuePlease)
+ pause(); /* wait for SIGCONT */
+ signal(SIGCONT, SIG_DFL);
+ ContinuePlease = 0;
+# ifndef USE_SETEUID
+ close(multipipe[1]);
+# else
+ xseteuid(own_uid);
+ if (tty_oldmode >= 0)
+ if (chmod(attach_tty, tty_oldmode))
+ Panic(errno, "chmod %s", attach_tty);
+ tty_oldmode = -1;
+ xseteuid(real_uid);
+# endif
+ }
+#endif
+ rflag = 0;
+ return 1;
+}
+
+
+static int AttacherPanic = 0;
+
+#ifdef DEBUG
+static sigret_t
+AttacherChld SIGDEFARG
+{
+ AttacherPanic = 1;
+ SIGRETURN;
+}
+#endif
+
+static sigret_t
+AttacherSigAlarm SIGDEFARG
+{
+#ifdef DEBUG
+ static int tick_cnt = 0;
+ if ((tick_cnt = (tick_cnt + 1) % 4) == 0)
+ debug("tick\n");
+#endif
+ SIGRETURN;
+}
+
+/*
+ * the frontend's Interrupt handler
+ * we forward SIGINT to the poor backend
+ */
+static sigret_t
+AttacherSigInt SIGDEFARG
+{
+ signal(SIGINT, AttacherSigInt);
+ Kill(MasterPid, SIGINT);
+ SIGRETURN;
+}
+
+/*
+ * Unfortunately this is also the SIGHUP handler, so we have to
+ * check if the backend is already detached.
+ */
+
+sigret_t
+AttacherFinit SIGDEFARG
+{
+ struct stat statb;
+ struct msg m;
+ int s;
+ bool is_socket;
+
+ debug("AttacherFinit();\n");
+ signal(SIGHUP, SIG_IGN);
+ /* Check if signal comes from backend */
+ if (stat(SockPath, &statb) == 0 && (statb.st_mode & 0777) != 0600)
+ {
+ debug("Detaching backend!\n");
+ bzero((char *) &m, sizeof(m));
+ strncpy(m.m_tty, attach_tty_is_in_new_ns ? attach_tty_name_in_ns : attach_tty, sizeof(m.m_tty) - 1);
+ m.m_tty[sizeof(m.m_tty) - 1] = 0;
+ debug1("attach_tty is %s\n", attach_tty);
+ m.m.detach.dpid = getpid();
+ m.type = MSG_HANGUP;
+ m.protocol_revision = MSG_REVISION;
+ is_socket = IsSocket(SockPath);
+ if ((s = MakeClientSocket(0, is_socket)) >= 0)
+ {
+ WriteMessage(s, &m);
+ close(s);
+ }
+ }
+#ifdef MULTIUSER
+ if (tty_oldmode >= 0)
+ {
+ if (setuid(own_uid))
+ Panic(errno, "setuid");
+ chmod(attach_tty, tty_oldmode);
+ }
+#endif
+ exit(0);
+ SIGRETURN;
+}
+
+#ifdef POW_DETACH
+static sigret_t
+AttacherFinitBye SIGDEFARG
+{
+ int ppid;
+ debug("AttacherFintBye()\n");
+#if defined(MULTIUSER) && !defined(USE_SETEUID)
+ if (multiattach)
+ exit(SIG_POWER_BYE);
+#endif
+ if (setgid(real_gid))
+ Panic(errno, "setgid");
+#ifdef MULTIUSER
+ if (setuid(own_uid))
+ Panic(errno, "setuid");
+#else
+ if (setuid(real_uid))
+ Panic(errno, "setuid");
+#endif
+ /* we don't want to disturb init (even if we were root), eh? jw */
+ if ((ppid = getppid()) > 1)
+ Kill(ppid, SIGHUP); /* carefully say good bye. jw. */
+ exit(0);
+ SIGRETURN;
+}
+#endif
+
+#if defined(DEBUG) && defined(SIG_NODEBUG)
+static sigret_t
+AttacherNoDebug SIGDEFARG
+{
+ debug("AttacherNoDebug()\n");
+ signal(SIG_NODEBUG, AttacherNoDebug);
+ if (dfp)
+ {
+ debug("debug: closing debug file.\n");
+ fflush(dfp);
+ fclose(dfp);
+ dfp = NULL;
+ }
+ SIGRETURN;
+}
+#endif /* SIG_NODEBUG */
+
+static int SuspendPlease;
+
+static sigret_t
+SigStop SIGDEFARG
+{
+ debug("SigStop()\n");
+ SuspendPlease = 1;
+ SIGRETURN;
+}
+
+#ifdef LOCK
+static int LockPlease;
+
+static sigret_t
+DoLock SIGDEFARG
+{
+# ifdef SYSVSIGS
+ signal(SIG_LOCK, DoLock);
+# endif
+ debug("DoLock()\n");
+ LockPlease = 1;
+ SIGRETURN;
+}
+#endif
+
+#if defined(SIGWINCH) && defined(TIOCGWINSZ)
+static int SigWinchPlease;
+
+static sigret_t
+AttacherWinch SIGDEFARG
+{
+ debug("AttacherWinch()\n");
+ SigWinchPlease = 1;
+ SIGRETURN;
+}
+#endif
+
+
+/*
+ * Attacher loop - no return
+ */
+
+void
+Attacher()
+{
+ signal(SIGHUP, AttacherFinit);
+ signal(SIG_BYE, AttacherFinit);
+#ifdef POW_DETACH
+ signal(SIG_POWER_BYE, AttacherFinitBye);
+#endif
+#if defined(DEBUG) && defined(SIG_NODEBUG)
+ signal(SIG_NODEBUG, AttacherNoDebug);
+#endif
+#ifdef LOCK
+ signal(SIG_LOCK, DoLock);
+#endif
+ signal(SIGINT, AttacherSigInt);
+#ifdef BSDJOBS
+ signal(SIG_STOP, SigStop);
+#endif
+#if defined(SIGWINCH) && defined(TIOCGWINSZ)
+ signal(SIGWINCH, AttacherWinch);
+#endif
+#ifdef DEBUG
+ signal(SIGCHLD, AttacherChld);
+#endif
+ debug("attacher: going for a nap.\n");
+ dflag = 0;
+#ifdef MULTI
+ xflag = 1;
+#endif
+ for (;;)
+ {
+ signal(SIGALRM, AttacherSigAlarm);
+ alarm(15);
+ pause();
+ alarm(0);
+ if (kill(MasterPid, 0) < 0 && errno != EPERM)
+ {
+ debug1("attacher: Panic! MasterPid %d does not exist.\n", MasterPid);
+ AttacherPanic++;
+ }
+ if (AttacherPanic)
+ {
+ fcntl(0, F_SETFL, 0);
+ SetTTY(0, &attach_Mode);
+ printf("\nError: Cannot find master process to attach to!\n");
+ eexit(1);
+ }
+#ifdef BSDJOBS
+ if (SuspendPlease)
+ {
+ SuspendPlease = 0;
+#if defined(MULTIUSER) && !defined(USE_SETEUID)
+ if (multiattach)
+ exit(SIG_STOP);
+#endif
+ signal(SIGTSTP, SIG_DFL);
+ debug("attacher: killing myself SIGTSTP\n");
+ kill(getpid(), SIGTSTP);
+ debug("attacher: continuing from stop\n");
+ signal(SIG_STOP, SigStop);
+ (void) Attach(MSG_CONT);
+ }
+#endif
+#ifdef LOCK
+ if (LockPlease)
+ {
+ LockPlease = 0;
+#if defined(MULTIUSER) && !defined(USE_SETEUID)
+ if (multiattach)
+ exit(SIG_LOCK);
+#endif
+ LockTerminal();
+# ifdef SYSVSIGS
+ signal(SIG_LOCK, DoLock);
+# endif
+ (void) Attach(MSG_CONT);
+ }
+#endif /* LOCK */
+#if defined(SIGWINCH) && defined(TIOCGWINSZ)
+ if (SigWinchPlease)
+ {
+ SigWinchPlease = 0;
+# ifdef SYSVSIGS
+ signal(SIGWINCH, AttacherWinch);
+# endif
+ (void) Attach(MSG_WINCH);
+ }
+#endif /* SIGWINCH */
+ }
+}
+
+#ifdef LOCK
+
+/* ADDED by Rainer Pruy 10/15/87 */
+/* POLISHED by mls. 03/10/91 */
+
+static char LockEnd[] = "Welcome back to screen !!\n";
+
+static sigret_t
+LockHup SIGDEFARG
+{
+ int ppid = getppid();
+ if (setgid(real_gid))
+ Panic(errno, "setgid");
+#ifdef MULTIUSER
+ if (setuid(own_uid))
+ Panic(errno, "setuid");
+#else
+ if (setuid(real_uid))
+ Panic(errno, "setuid");
+#endif
+ if (ppid > 1)
+ Kill(ppid, SIGHUP);
+ exit(0);
+}
+
+static void
+LockTerminal()
+{
+ char *prg;
+ int sig, pid;
+ sigret_t (*sigs[NSIG])__P(SIGPROTOARG);
+
+ for (sig = 1; sig < NSIG; sig++)
+ sigs[sig] = signal(sig, sig == SIGCHLD ? SIG_DFL : SIG_IGN);
+ signal(SIGHUP, LockHup);
+ printf("\n");
+
+ prg = getenv("LOCKPRG");
+ if (prg && strcmp(prg, "builtin") && !access(prg, X_OK))
+ {
+ signal(SIGCHLD, SIG_DFL);
+ debug1("lockterminal: '%s' seems executable, execl it!\n", prg);
+ if ((pid = fork()) == 0)
+ {
+ /* Child */
+ if (setgid(real_gid))
+ Panic(errno, "setgid");
+#ifdef MULTIUSER
+ if (setuid(own_uid))
+ Panic(errno, "setuid");
+#else
+ if (setuid(real_uid)) /* this should be done already */
+ Panic(errno, "setuid");
+#endif
+ closeallfiles(0); /* important: /etc/shadow may be open */
+ execl(prg, "SCREEN-LOCK", NULL);
+ exit(errno);
+ }
+ if (pid == -1)
+ Msg(errno, "Cannot lock terminal - fork failed");
+ else
+ {
+#ifdef BSDWAIT
+ union wait wstat;
+#else
+ int wstat;
+#endif
+ int wret;
+
+#ifdef hpux
+ signal(SIGCHLD, SIG_DFL);
+#endif
+ errno = 0;
+ while (((wret = wait(&wstat)) != pid) ||
+ ((wret == -1) && (errno == EINTR))
+ )
+ errno = 0;
+
+ if (errno)
+ {
+ Msg(errno, "Lock");
+ sleep(2);
+ }
+ else if (WTERMSIG(wstat) != 0)
+ {
+ fprintf(stderr, "Lock: %s: Killed by signal: %d%s\n", prg,
+ WTERMSIG(wstat), WIFCORESIG(wstat) ? " (Core dumped)" : "");
+ sleep(2);
+ }
+ else if (WEXITSTATUS(wstat))
+ {
+ debug2("Lock: %s: return code %d\n", prg, WEXITSTATUS(wstat));
+ }
+ else
+ printf("%s", LockEnd);
+ }
+ }
+ else
+ {
+ if (prg)
+ {
+ debug1("lockterminal: '%s' seems NOT executable, we use our builtin\n", prg);
+ }
+ else
+ {
+ debug("lockterminal: using buitin.\n");
+ }
+ screen_builtin_lck();
+ }
+ /* reset signals */
+ for (sig = 1; sig < NSIG; sig++)
+ {
+ if (sigs[sig] != (sigret_t(*)__P(SIGPROTOARG)) -1)
+ signal(sig, sigs[sig]);
+ }
+} /* LockTerminal */
+
+#ifdef USE_PAM
+
+/*
+ * PAM support by Pablo Averbuj <pablo@averbuj.com>
+ */
+
+#include <security/pam_appl.h>
+
+static int PAM_conv __P((int, const struct pam_message **, struct pam_response **, void *));
+
+static int
+PAM_conv(num_msg, msg, resp, appdata_ptr)
+int num_msg;
+const struct pam_message **msg;
+struct pam_response **resp;
+void *appdata_ptr;
+{
+ int replies = 0;
+ struct pam_response *reply = NULL;
+
+ reply = malloc(sizeof(struct pam_response)*num_msg);
+ if (!reply)
+ return PAM_CONV_ERR;
+ #define COPY_STRING(s) (s) ? strdup(s) : NULL
+
+ for (replies = 0; replies < num_msg; replies++)
+ {
+ switch (msg[replies]->msg_style)
+ {
+ case PAM_PROMPT_ECHO_OFF:
+ /* wants password */
+ reply[replies].resp_retcode = PAM_SUCCESS;
+ reply[replies].resp = appdata_ptr ? strdup((char *)appdata_ptr) : 0;
+ break;
+ case PAM_TEXT_INFO:
+ /* ignore the informational mesage */
+ /* but first clear out any drek left by malloc */
+ reply[replies].resp = NULL;
+ break;
+ case PAM_PROMPT_ECHO_ON:
+ /* user name given to PAM already */
+ /* fall through */
+ default:
+ /* unknown or PAM_ERROR_MSG */
+ free(reply);
+ return PAM_CONV_ERR;
+ }
+ }
+ *resp = reply;
+ return PAM_SUCCESS;
+}
+
+static struct pam_conv PAM_conversation = {
+ &PAM_conv,
+ NULL
+};
+
+
+#endif
+
+/* -- original copyright by Luigi Cannelloni 1985 (luigi@faui70.UUCP) -- */
+static void
+screen_builtin_lck()
+{
+ char fullname[100], *cp1, message[100 + 100];
+#ifdef USE_PAM
+ pam_handle_t *pamh = 0;
+ int pam_error;
+ char *tty_name;
+#endif
+ char *pass = 0, mypass[16 + 1], salt[3];
+ int using_pam = 1;
+
+#ifdef USE_PAM
+ if (!ppp->pw_uid)
+ {
+#endif
+ using_pam = 0;
+ pass = ppp->pw_passwd;
+ if (pass == 0 || *pass == 0)
+ {
+ if ((pass = getpass("Key: ")))
+ {
+ strncpy(mypass, pass, sizeof(mypass) - 1);
+ mypass[sizeof(mypass) - 1] = 0;
+ if (*mypass == 0)
+ return;
+ if ((pass = getpass("Again: ")))
+ {
+ if (strcmp(mypass, pass))
+ {
+ fprintf(stderr, "Passwords don't match.\007\n");
+ sleep(2);
+ return;
+ }
+ }
+ }
+ if (pass == 0)
+ {
+ fprintf(stderr, "Getpass error.\007\n");
+ sleep(2);
+ return;
+ }
+
+ salt[0] = 'A' + (int)(time(0) % 26);
+ salt[1] = 'A' + (int)((time(0) >> 6) % 26);
+ salt[2] = 0;
+ pass = crypt(mypass, salt);
+ if (!pass)
+ {
+ fprintf(stderr, "crypt() error.\007\n");
+ sleep(2);
+ return;
+ }
+ pass = ppp->pw_passwd = SaveStr(pass);
+ }
+#ifdef USE_PAM
+ }
+#endif
+
+ debug("screen_builtin_lck looking in gcos field\n");
+ strncpy(fullname, ppp->pw_gecos, sizeof(fullname) - 9);
+ fullname[sizeof(fullname) - 9] = 0;
+
+ if ((cp1 = index(fullname, ',')) != NULL)
+ *cp1 = '\0';
+ if ((cp1 = index(fullname, '&')) != NULL)
+ {
+ strncpy(cp1, ppp->pw_name, 8);
+ cp1[8] = 0;
+ if (*cp1 >= 'a' && *cp1 <= 'z')
+ *cp1 -= 'a' - 'A';
+ }
+
+ sprintf(message, "Screen used by %s%s<%s> on %s.\nPassword:\007",
+ fullname, fullname[0] ? " " : "", ppp->pw_name, HostName);
+
+ /* loop here to wait for correct password */
+ for (;;)
+ {
+ debug("screen_builtin_lck awaiting password\n");
+ errno = 0;
+ if ((cp1 = getpass(message)) == NULL)
+ {
+ AttacherFinit(SIGARG);
+ /* NOTREACHED */
+ }
+ if (using_pam)
+ {
+#ifdef USE_PAM
+ PAM_conversation.appdata_ptr = cp1;
+ pam_error = pam_start("screen", ppp->pw_name, &PAM_conversation, &pamh);
+ if (pam_error != PAM_SUCCESS)
+ AttacherFinit(SIGARG); /* goodbye */
+
+ if (strncmp(attach_tty, "/dev/", 5) == 0)
+ tty_name = attach_tty + 5;
+ else
+ tty_name = attach_tty;
+ pam_error = pam_set_item(pamh, PAM_TTY, tty_name);
+ if (pam_error != PAM_SUCCESS)
+ AttacherFinit(SIGARG); /* goodbye */
+
+ pam_error = pam_authenticate(pamh, 0);
+ pam_end(pamh, pam_error);
+ PAM_conversation.appdata_ptr = 0;
+ if (pam_error == PAM_SUCCESS)
+ break;
+#endif
+ }
+ else
+ {
+ char *buf = crypt(cp1, pass);
+ if (buf && !strncmp(buf, pass, strlen(pass)))
+ break;
+ }
+ debug("screen_builtin_lck: NO!!!!!\n");
+ bzero(cp1, strlen(cp1));
+ }
+ bzero(cp1, strlen(cp1));
+ debug("password ok.\n");
+}
+
+#endif /* LOCK */
+
+
+void
+SendCmdMessage(sty, match, av, query)
+char *sty;
+char *match;
+char **av;
+int query;
+{
+ int i, s;
+ struct msg m;
+ char *p;
+ int len, n;
+ bool is_socket;
+
+ if (sty == 0)
+ {
+ i = FindSocket(&s, (int *)0, (int *)0, match, &is_socket);
+ if (i == 0)
+ Panic(0, "No screen session found.");
+ if (i != 1)
+ Panic(0, "Use -S to specify a session.");
+ }
+ else
+ {
+#ifdef NAME_MAX
+ if (strlen(sty) > NAME_MAX)
+ sty[NAME_MAX] = 0;
+#endif
+ if (strlen(sty) > 2 * MAXSTR - 1)
+ sty[2 * MAXSTR - 1] = 0;
+ sprintf(SockPath + strlen(SockPath), "/%s", sty);
+ is_socket = IsSocket(SockPath);
+ if ((s = MakeClientSocket(1, is_socket)) == -1)
+ exit(1);
+ }
+ bzero((char *)&m, sizeof(m));
+ m.type = query ? MSG_QUERY : MSG_COMMAND;
+ if (attach_tty)
+ {
+ strncpy(m.m_tty, attach_tty_is_in_new_ns ? attach_tty_name_in_ns : attach_tty, sizeof(m.m_tty) - 1);
+ m.m_tty[sizeof(m.m_tty) - 1] = 0;
+ }
+ p = m.m.command.cmd;
+ n = 0;
+ for (; *av && n < MAXARGS - 1; ++av, ++n)
+ {
+ len = strlen(*av) + 1;
+ if (p + len >= m.m.command.cmd + sizeof(m.m.command.cmd) - 1)
+ break;
+ strcpy(p, *av);
+ p += len;
+ }
+ *p = 0;
+ m.m.command.nargs = n;
+ strncpy(m.m.attach.auser, LoginName, sizeof(m.m.attach.auser) - 1);
+ m.m.command.auser[sizeof(m.m.command.auser) - 1] = 0;
+ m.protocol_revision = MSG_REVISION;
+ strncpy(m.m.command.preselect, preselect ? preselect : "", sizeof(m.m.command.preselect) - 1);
+ m.m.command.preselect[sizeof(m.m.command.preselect) - 1] = 0;
+ m.m.command.apid = getpid();
+ debug1("SendCommandMsg writing '%s'\n", m.m.command.cmd);
+ if (query)
+ {
+ /* Create a server socket so we can get back the result */
+ char *sp = SockPath + strlen(SockPath);
+ char query[] = "-queryX";
+ char c;
+ int r = -1;
+ for (c = 'A'; c <= 'Z'; c++)
+ {
+ query[6] = c;
+ strcpy(sp, query); /* XXX: strncpy? */
+ if ((r = MakeServerSocket(is_socket)) >= 0)
+ break;
+ }
+ if (r < 0)
+ {
+ for (c = '0'; c <= '9'; c++)
+ {
+ query[6] = c;
+ strcpy(sp, query);
+ if ((r = MakeServerSocket(is_socket)) >= 0)
+ break;
+ }
+ }
+
+ if (r < 0)
+ Panic(0, "Could not create a listening socket to read the results.");
+
+ strncpy(m.m.command.writeback, SockPath, sizeof(m.m.command.writeback) - 1);
+ m.m.command.writeback[sizeof(m.m.command.writeback) - 1] = '\0';
+
+ /* Send the message, then wait for a response */
+ signal(SIGCONT, QueryResultSuccess);
+ signal(SIG_BYE, QueryResultFail);
+ if (WriteMessage(s, &m))
+ Msg(errno, "write");
+ close(s);
+ while (!QueryResult)
+ pause();
+ signal(SIGCONT, SIG_DFL);
+ signal(SIG_BYE, SIG_DFL);
+
+ /* Read the result and spit it out to stdout */
+ ReceiveRaw(r);
+ unlink(SockPath);
+ if (QueryResult == 2) /* An error happened */
+ exit(1);
+ }
+ else
+ {
+ if (WriteMessage(s, &m))
+ Msg(errno, "write");
+ close(s);
+ }
+}
+
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..520249c
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec autoreconf
diff --git a/braille.c b/braille.c
new file mode 100644
index 0000000..f027dd2
--- /dev/null
+++ b/braille.c
@@ -0,0 +1,945 @@
+/*
+ * A braille interface to unix tty terminals
+ *
+ * Authors: Hadi Bargi Rangin bargi@dots.physics.orst.edu
+ * Bill Barry barryb@dots.physics.orst.edu
+ *
+ * Copyright (c) 1995 by Science Access Project, Oregon State University.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+#include "config.h"
+#include "screen.h"
+#include "extern.h"
+#include "braille.h"
+
+#ifdef HAVE_BRAILLE
+
+
+extern int bd_init_powerbraille_40 __P((void));
+extern int bd_init_powerbraille_80 __P((void));
+extern int bd_init_navigator_40 __P((void));
+
+extern struct layer *flayer;
+extern struct display *displays, *display;
+extern char *rc_name;
+
+
+
+
+/* global variables */
+
+struct braille_display bd;
+
+struct bd_type {
+ char *name;
+ int (*init) __P((void));
+};
+
+static struct bd_type bd_typelist[] =
+{
+ {"powerbraille_40", bd_init_powerbraille_40},
+ {"powerbraille_80", bd_init_powerbraille_80},
+ {"navigator_40" , bd_init_navigator_40}
+};
+
+static void position_braille_cursor __P((void));
+static int initialize_braille_display_type __P((char *));
+static int open_braille_device __P(());
+static int load_braille_table __P((char *));
+static void bd_signal __P((void));
+static void bd_bc_left __P((void));
+static void bd_bc_right __P((void));
+static void bd_bc_up __P((void));
+static void bd_bc_down __P((void));
+static void bd_upper_left __P((void));
+static void bd_upper_right __P((void));
+static void bd_lower_left __P((void));
+static void bd_lower_right __P((void));
+static int bd_do_search __P((int, int, int));
+static void bd_normalize __P((int, int));
+static void bd_readev_fn __P((struct event *, char *));
+static void bd_writeev_fn __P((struct event *, char *));
+static void bd_selectev_fn __P((struct event *, char *));
+
+static unsigned char btable_local [] =
+{
+ 0xC8,0xC1,0xC3,0xC9,0xD9,0xD1,0xCB,0xDB,
+ 0xD3,0xCA,0xDA,0xC5,0xC7,0xCD,0xDD,0xD5,
+ 0xCF,0xDF,0xD7,0xCE,0xDE,0xE5,0xE7,0xFA,
+ 0xED,0xFD,0xF5,0xEA,0xF3,0xFB,0xD8,0xF8,
+ 0x00,0x2E,0x10,0x3C,0x2B,0x29,0x2F,0x04,
+ 0x37,0x3E,0x21,0x2C,0x20,0x24,0x28,0x0C,
+ 0x34,0x02,0x06,0x12,0x32,0x22,0x16,0x36,
+ 0x26,0x14,0x31,0x30,0x23,0x3F,0x1C,0x39,
+ 0x48,0x41,0x43,0x49,0x59,0x51,0x4B,0x5B,
+ 0x53,0x4A,0x5A,0x45,0x47,0x4D,0x5D,0x55,
+ 0x4F,0x5F,0x57,0x4E,0x5E,0x65,0x67,0x7A,
+ 0x6D,0x7D,0x75,0x6A,0x73,0x7B,0x58,0x38,
+ 0x08,0x01,0x03,0x09,0x19,0x11,0x0B,0x1B,
+ 0x13,0x0A,0x1A,0x05,0x07,0x0D,0x1D,0x15,
+ 0x0F,0x1F,0x17,0x0E,0x1E,0x25,0x27,0x3A,
+ 0x2D,0x3D,0x35,0x2A,0x33,0x3B,0x18,0x78,
+ 0x88,0x81,0x83,0x89,0x99,0x91,0x8B,0x9B,
+ 0x93,0x8A,0x9A,0x85,0x87,0x8D,0x9D,0x95,
+ 0x8F,0x9F,0x97,0x8E,0x9E,0xA5,0xA7,0xBA,
+ 0xAD,0xBD,0xB5,0xAA,0xB3,0xBB,0x98,0xB8,
+ 0x40,0x6E,0x50,0x7C,0x6B,0x69,0x6F,0x44,
+ 0x77,0x7E,0x61,0x6C,0x60,0x64,0x68,0x4C,
+ 0x74,0x42,0x46,0x52,0x72,0x62,0x56,0x76,
+ 0x66,0x54,0x71,0x70,0x63,0x7F,0x5C,0x79,
+ 0xC0,0xEE,0xD0,0xFC,0xEB,0xE9,0xEF,0xC4,
+ 0xF7,0xFE,0xE1,0xEC,0xE0,0xE4,0xE8,0xCC,
+ 0xF4,0xC2,0xC6,0xD2,0xF2,0xE2,0xD6,0xF6,
+ 0xE6,0xD4,0xF1,0xF0,0xE3,0xFF,0xDC,0xF9,
+ 0x80,0xAE,0x90,0xBC,0xAB,0xA9,0xAF,0x84,
+ 0xB7,0xBE,0xA1,0xAC,0xA0,0xA4,0xA8,0x8C,
+ 0xB4,0x82,0x86,0x92,0xB2,0xA2,0x96,0xB6,
+ 0xA6,0x94,0xB1,0xB0,0xA3,0xBF,0x9C,0xB9
+};
+
+void
+InitBraille()
+{
+ bd.bd_start_braille=0;
+ bd.bd_port = 0;
+ bd.bd_braille_table = SaveStr("internal us-braille.tbl");
+ bd.bd_type = 0;
+ bd.bd_baud = 9600;
+ bd.bd_bell = 1;
+ bd.bd_eightdot = 1;
+ bd.bd_info = 0;
+ bd.bd_link = 1;
+ bd.bd_ncells = 0;
+ bd.bd_width = 0;
+ bd.bd_ncrc = 1;
+ bd.bd_scroll = 1;
+ bd.bd_skip = 0;
+ bd.bd_using_braille = 0;
+ bd.bd_obuflen = 0;
+ bd.bd_fd = -1;
+ bcopy((char *)btable_local, bd.bd_btable, 256);
+}
+
+static int
+initialize_braille_display_type(s)
+char *s;
+{
+ int i;
+
+ for (i = 0; i < sizeof(bd_typelist)/sizeof(*bd_typelist); i++)
+ if (!strcmp(s, bd_typelist[i].name))
+ break;
+ if (i == sizeof(bd_typelist)/sizeof(*bd_typelist))
+ {
+ Msg(0, "No entry for bd_type: %s ", s);
+ return -1;
+ }
+ bd.bd_type = bd_typelist[i].name;
+ if ((*bd_typelist[i].init)())
+ return -1;
+
+ if (!bd.bd_width)
+ bd.bd_width = bd.bd_ncells;
+
+ return 0;
+}
+
+void
+StartBraille()
+{
+ bd.bd_dpy = displays;
+
+ debug("StartBraille called\n");
+ evdeq(&bd.bd_readev);
+ evdeq(&bd.bd_writeev);
+ evdeq(&bd.bd_selectev);
+ bd.bd_using_braille = 0;
+
+ if (!bd.bd_start_braille)
+ return;
+
+ if (bd.bd_type == 0 || bd.bd_port == 0)
+ return;
+
+ if (bd.bd_fd < 0 && open_braille_device())
+ {
+ Msg(0, "bd_port turned off");
+ free(bd.bd_port);
+ bd.bd_port = 0;
+ return;
+ }
+
+ /* check if braille display is connected and turned on */
+ if (bd.bd_response_test())
+ {
+ Msg(0, "Make sure that braille display is connected and turned on. ");
+ Msg(0, "start_braille turned off");
+ bd.bd_start_braille = 0;
+ }
+ else
+ {
+ bd.bd_using_braille = 1;
+ bd.bd_readev.fd = bd.bd_writeev.fd = bd.bd_fd;
+ bd.bd_readev.type = EV_READ;
+ bd.bd_writeev.type = EV_WRITE;
+ bd.bd_selectev.type = EV_ALWAYS;
+ bd.bd_readev.data = bd.bd_writeev.data = bd.bd_selectev.data = (char *)&bd;
+ bd.bd_readev.handler = bd_readev_fn;
+ bd.bd_writeev.handler = bd_writeev_fn;
+ bd.bd_selectev.handler = bd_selectev_fn;
+ evenq(&bd.bd_readev);
+ bd.bd_writeev.condpos = &bd.bd_obuflen;
+ bd.bd_writeev.condneg = 0;
+ evenq(&bd.bd_writeev);
+ bd.bd_selectev.pri = -20;
+ evenq(&bd.bd_selectev);
+ }
+}
+
+
+static int
+load_braille_table(tablename)
+char *tablename;
+{
+ int i, j, c, p;
+ FILE *fp;
+ char buffer[80], a[10];
+
+ if ((fp = secfopen(tablename, "r")) == 0)
+ {
+ Msg(errno, "Braille table not found: %s ", tablename);
+ return -1;
+ }
+ bzero(bd.bd_btable, 256);
+ /* format:
+ * Dec Hex Braille Description
+ * 7 07 (12-45--8) BEL
+ */
+ while (fgets(buffer, sizeof(buffer), fp))
+ {
+ if (buffer[0] == '#')
+ continue;
+ sscanf(buffer,"%d %x %8s", &i, &j, a);
+ if (i < 0 || i > 255)
+ continue;
+ for (j=1, p=1, c=0; j<9; j++, p*=2)
+ if (a[j] == '0' + j)
+ c += p;
+ bd.bd_btable[i] = c;
+ }
+ fclose(fp);
+ return 0;
+}
+
+
+static int
+open_braille_device(s)
+char *s;
+{
+ char str[256];
+
+ sprintf(str, "%d cs8 -istrip ixon ixoff", bd.bd_baud);
+ bd.bd_fd = OpenTTY(bd.bd_port, str);
+ if (bd.bd_fd == -1)
+ {
+ Msg(errno, "open comm port failed: %s ", bd.bd_port);
+ return -1;
+ }
+ fcntl(bd.bd_fd, F_SETFL, FNBLOCK);
+ return 0;
+}
+
+
+static void
+position_braille_cursor()
+{
+ int sx = bd.bd_sx;
+ int bx = BD_FORE->w_bd_x;
+ int eol = BD_FORE->w_width;
+ int w = bd.bd_width;
+
+ if (bd.bd_scroll)
+ bx = sx - w + bd.bd_ncrc; /* keep rc centered in window */
+ else
+ bx = w * (int)(sx / w); /* increase bc in integral steps */
+
+ if (bx > eol - w)
+ bx = eol - w;
+ if (bx < 0)
+ bx = 0;
+ BD_FORE->w_bd_x = bx;
+ BD_FORE->w_bd_y = bd.bd_sy;
+}
+
+
+void
+RefreshBraille()
+{
+ int i, y, xs, xe;
+ int cursor_pos;
+
+ if (!bd.bd_using_braille)
+ return;
+ if (!BD_FORE)
+ return;
+ bcopy(bd.bd_line, bd.bd_oline, bd.bd_ncells);
+ bd.bd_refreshing = 1;
+ flayer = bd.bd_dpy->d_forecv->c_layer;
+ bd.bd_sx = flayer->l_x;
+ bd.bd_sy = flayer->l_y;
+ display = bd.bd_dpy;
+ if ((D_obufp != D_obuf) && bd.bd_link)
+ {
+ /* jump to real cursor */
+ debug("calling position_braille_cursor\n");
+ position_braille_cursor();
+ }
+ bclear(bd.bd_line, bd.bd_ncells);
+
+ y = BD_FORE->w_bd_y;
+ xs = BD_FORE->w_bd_x;
+
+ if (bd.bd_info & 1)
+ {
+ sprintf(bd.bd_line, "%02d%02d", (BD_FORE->w_bd_x + 1) % 100, (BD_FORE->w_bd_y + 1) % 100);
+ bd.bd_line[4] = ' ';
+ }
+ if (bd.bd_info & 2)
+ {
+ sprintf(bd.bd_line + bd.bd_ncells - 4, "%02d%02d",(bd.bd_sx +1) % 100, (bd.bd_sy +1) % 100);
+ }
+
+ xe = xs + bd.bd_width - 1;
+
+ if (xs > flayer->l_width - 1)
+ xs = flayer->l_width - 1;
+ if (xe > flayer->l_width - 1)
+ xe = flayer->l_width - 1;
+
+ if (D_status)
+ {
+ sprintf(bd.bd_line, "**%-*.*s", bd.bd_ncells - 2, bd.bd_ncells - 2, D_status_lastmsg ? D_status_lastmsg : "unknown msg");
+ xs = xe = -1;
+ }
+ else if (xs <= xe)
+ {
+ LayRedisplayLine(-1, xs, xe, 1);
+ LayRedisplayLine(y, xs, xe, 1);
+ }
+
+ debug1("Braille: got >%s<\n", bd.bd_line);
+
+ bd.bd_refreshing = 0;
+
+ if (y == bd.bd_sy && xs <= bd.bd_sx && bd.bd_sx <= xe)
+ cursor_pos = bd.bd_sx - xs + (bd.bd_info & 1 ? 4 : 0);
+ else
+ cursor_pos = bd.bd_ncells;
+ for (i = 0; i < bd.bd_ncells; i++)
+ if (bd.bd_line[i] != bd.bd_oline[i])
+ break;
+ if (bd.bd_cursorpos != cursor_pos || i < bd.bd_ncells)
+ bd.write_line_braille(bd.bd_line, bd.bd_ncells, cursor_pos);
+ bd.bd_cursorpos = cursor_pos;
+}
+
+
+/**********************************************************************
+ *
+ */
+
+/*
+ * So, why is there a Flush() down below? The reason is simple: the
+ * cursor warp (if bd_link is on) checks the obuf to see if something
+ * happened. If there would be no Flush, screen would warp the
+ * bd cursor if a bd movement command tries to ring the bell.
+ * (In other words: this is a gross hack!)
+ */
+static void
+bd_signal()
+{
+ if (!bd.bd_bell)
+ return;
+ display = bd.bd_dpy;
+ if (D_obufp != D_obuf)
+ AddCStr(D_BL);
+ else
+ {
+ AddCStr(D_BL);
+ Flush(0);
+ }
+}
+
+static int
+bd_do_search(y, xs, xe)
+int y, xs, xe;
+{
+ int oy = BD_FORE->w_bd_y;
+
+ if (!bd.bd_skip) /* no skip mode, found it */
+ {
+ if (xs > xe)
+ return 0;
+ bd.bd_searchmin = xs;
+ bd.bd_searchmax = xe;
+ return 1;
+ }
+ flayer = bd.bd_dpy->d_forecv->c_layer;
+ bd.bd_searchmax = -1;
+ bd.bd_searchmin = flayer->l_width;
+ if (xs <= xe)
+ {
+ BD_FORE->w_bd_y = y; /* stupid hack */
+ bd.bd_refreshing = bd.bd_searching = 1;
+ bd.bd_searchstart = xs;
+ bd.bd_searchend = xe;
+ LayRedisplayLine(-1, xs, xe, 1);
+ LayRedisplayLine(y, xs, xe, 1);
+ bd.bd_refreshing = bd.bd_searching = 0;
+ BD_FORE->w_bd_y = oy;
+ }
+ return bd.bd_searchmax >= 0;
+}
+
+static void
+bd_normalize(x, y)
+int x, y;
+{
+ if (x > BD_FORE->w_width - bd.bd_width)
+ x = BD_FORE->w_width - bd.bd_width;
+ if (x < 0)
+ x = 0;
+ if (y < 0)
+ {
+ bd_signal();
+ y = 0;
+ }
+ if (y >= BD_FORE->w_height)
+ {
+ bd_signal();
+ y = BD_FORE->w_height - 1;
+ }
+ if (x != BD_FORE->w_bd_x || y != BD_FORE->w_bd_y)
+ bd.bd_moved = 1;
+ BD_FORE->w_bd_x = x;
+ BD_FORE->w_bd_y = y;
+}
+
+static void
+bd_bc_left()
+{
+ int bx = BD_FORE->w_bd_x, by = BD_FORE->w_bd_y;
+ int ex;
+
+ ex = bx - 1;
+ bx = 0;
+ for (; by >= 0; by--)
+ {
+ if (bd_do_search(by, 0, ex))
+ {
+ if (!bd.bd_skip && by != BD_FORE->w_bd_y)
+ bd_signal();
+ bx = bd.bd_searchmax + 1 - bd.bd_width;
+ break;
+ }
+ ex = BD_FORE->w_width - 1;
+ }
+ bd_normalize(bx, by);
+}
+
+static void
+bd_bc_right()
+{
+ int bx = BD_FORE->w_bd_x, by = BD_FORE->w_bd_y;
+ int sx;
+
+ sx = bx + bd.bd_width;
+ bx = BD_FORE->w_width - bd.bd_width;
+ for (; by < BD_FORE->w_height; by++)
+ {
+ if (bd_do_search(by, sx, BD_FORE->w_width - 1))
+ {
+ if (!bd.bd_skip && by != BD_FORE->w_bd_y)
+ bd_signal();
+ bx = bd.bd_searchmin;
+ break;
+ }
+ sx = 0;
+ }
+ bd_normalize(bx, by);
+}
+
+static void
+bd_bc_up()
+{
+ int bx = BD_FORE->w_bd_x, by = BD_FORE->w_bd_y;
+
+ for (by--; by >= 0; by--)
+ if (bd_do_search(by, bx, bx + bd.bd_width - 1))
+ break;
+ bd_normalize(bx, by);
+}
+
+static void
+bd_bc_down()
+{
+ int bx = BD_FORE->w_bd_x, by = BD_FORE->w_bd_y;
+
+ for (by++; by < BD_FORE->w_height; by++)
+ if (bd_do_search(by, bx, bx + bd.bd_width - 1))
+ break;
+ bd_normalize(bx, by);
+}
+
+
+static void
+bd_upper_left()
+{
+ bd_normalize(0, 0);
+}
+
+
+static void
+bd_upper_right()
+{
+ bd_normalize(BD_FORE->w_width - bd.bd_width, 0);
+}
+
+
+static void
+bd_lower_left()
+{
+ bd_normalize(0, BD_FORE->w_height - 1);
+}
+
+
+static void
+bd_lower_right()
+{
+ bd_normalize(BD_FORE->w_width - bd.bd_width, BD_FORE->w_height -1);
+}
+
+/**********************************************************************
+ *
+ */
+
+
+static void
+bd_check(x, c)
+int x, c;
+{
+ if (c == ' ')
+ return;
+ if (x < bd.bd_searchstart || x > bd.bd_searchend)
+ return;
+ if (x > bd.bd_searchmax)
+ bd.bd_searchmax = x;
+ if (x < bd.bd_searchmin)
+ bd.bd_searchmin = x;
+}
+
+
+
+/*ARGSUSED*/
+void
+BGotoPos(la, x, y)
+struct layer *la;
+int x, y;
+{
+}
+
+/*ARGSUSED*/
+void
+BCDisplayLine(la, ml, y, xs, xe, isblank)
+struct layer *la;
+struct mline *ml;
+int y, xs, xe;
+int isblank;
+{
+ int x;
+ int sx, ex;
+ char *l;
+
+ if (y != BD_FORE->w_bd_y)
+ return;
+ if (bd.bd_searching)
+ {
+ for (x = xs; x <= xe; x++)
+ bd_check(x, ml->image[x]);
+ return;
+ }
+ l = bd.bd_line;
+ sx = BD_FORE->w_bd_x;
+ ex = sx + bd.bd_width - 1;
+ if (bd.bd_info & 1)
+ l += 4;
+ for (x = xs; x <= xe; x++)
+ if (x >= sx && x <= ex)
+ l[x - sx] = ml->image[x];
+}
+
+/*ARGSUSED*/
+void
+BPutChar(la, c, x, y)
+struct layer *la;
+struct mchar *c;
+int x, y;
+{
+ int sx, ex;
+ char *l;
+
+ if (y != BD_FORE->w_bd_y)
+ return;
+ if (bd.bd_searching)
+ {
+ bd_check(x, c->image);
+ return;
+ }
+ l = bd.bd_line;
+ sx = BD_FORE->w_bd_x;
+ ex = sx + bd.bd_width - 1;
+ if (bd.bd_info & 1)
+ l += 4;
+ if (x >= sx && x <= ex)
+ l[x - sx] = c->image;
+}
+
+/*ARGSUSED*/
+void
+BPutStr(la, s, n, r, x, y)
+struct layer *la;
+char *s;
+int n;
+struct mchar *r;
+int x, y;
+{
+ int sx, ex;
+ char *l;
+
+ if (y != BD_FORE->w_bd_y)
+ return;
+ if (bd.bd_searching)
+ {
+ for (; n > 0; n--, s++, x++)
+ bd_check(x, *s);
+ return;
+ }
+ l = bd.bd_line;
+ sx = BD_FORE->w_bd_x;
+ ex = sx + bd.bd_width - 1;
+ if (bd.bd_info & 1)
+ l += 4;
+ for (; n > 0; n--, s++, x++)
+ if (x >= sx && x <= ex)
+ l[x - sx] = *s;
+}
+
+
+
+/**********************************************************************
+ *
+ */
+
+static char *infonames[] = {"none", "bc", "sc", "bc+sc"};
+
+void
+DoBrailleAction(act, msgok)
+struct action *act;
+int msgok;
+{
+ int nr, dosig;
+ int n, l, o;
+ char *s, **args;
+ struct stat st;
+
+ nr = act->nr;
+ args = act->args;
+ dosig = display && !*rc_name;
+
+ switch(nr)
+ {
+ case RC_BD_BELL:
+ if (ParseSwitch(act, &bd.bd_bell) || !msgok)
+ {
+ bd_signal();
+ break;
+ }
+ Msg(0, bd.bd_bell ? "bd_bell is on." : "bd_bell is off.");
+ break;
+
+ case RC_BD_EIGHTDOT:
+ if (ParseSwitch(act, &bd.bd_eightdot) || !msgok)
+ break;
+ Msg(0, "switched to %d-dots system.", bd.bd_eightdot ? 8 : 6);
+ break;
+
+ case RC_BD_INFO:
+ n = bd.bd_info;
+ if (*args)
+ {
+ if (strlen(*args) == 4)
+ n = args[0][n] - '0';
+ else if (ParseNum(act, &n))
+ break;
+ }
+ if (n < 0 || n > 3)
+ {
+ Msg(0, "Out of range; 0 <= bd_info >= 3 ");
+ break;
+ }
+ /* bd_width at the beginning is unknown */
+ if (bd.bd_width == 0)
+ break;
+
+ o = (bd.bd_info * 2 + 2) & 12;
+ l = (n * 2 + 2) & 12;
+ if (l >= bd.bd_ncells)
+ {
+ Msg(0, "bd_info is too large for braille display.");
+ break;
+ }
+ if (l >= bd.bd_width + o)
+ {
+ Msg(0, "bd_info is too large for bd_width.");
+ break;
+ }
+ bd.bd_width += o - l;
+ bd.bd_info = n;
+
+ if (msgok)
+ Msg(0, "bd_info is %s.", infonames[n]);
+ position_braille_cursor();
+ break;
+
+ case RC_BD_LINK:
+ if (*args == 0 && bd.bd_moved)
+ bd.bd_link = 0;
+ if (ParseSwitch(act, &bd.bd_link))
+ break;
+ if (bd.bd_link)
+ {
+ bd.bd_moved = 0;
+ if (dosig)
+ bd_signal();
+ position_braille_cursor();
+ }
+ if (msgok)
+ Msg(0, bd.bd_link ? "bd_link is on." : "bd_link is off.");
+ break;
+
+ case RC_BD_SKIP:
+ if (ParseSwitch(act, &bd.bd_skip))
+ break;
+ if (bd.bd_skip && dosig)
+ bd_signal();
+ if (msgok)
+ Msg(0, bd.bd_skip ? "bd_skip is on." : "bd_skip is off.");
+ break;
+
+ case RC_BD_SCROLL:
+ if (ParseSwitch(act, &bd.bd_scroll) || !msgok)
+ {
+ position_braille_cursor();
+ break;
+ }
+ Msg(0, bd.bd_scroll ? "bd_scroll is on." : "bd_scroll is off.");
+ break;
+
+ case RC_BD_NCRC:
+ n = bd.bd_ncrc;
+ if (*args)
+ {
+ if (args[0][0] == '+')
+ n = (n + atoi(*args + 1)) % bd.bd_width + 1;
+ else if (args[0][0] == '-')
+ n = (n - atoi(*args + 1)) % bd.bd_width + 1;
+ else if (ParseNum(act, &n))
+ break;
+ }
+ if (n < 1 || n > bd.bd_width)
+ {
+ Msg(0, "Out of range; 1 <= bd_ncrc >= %d", bd.bd_width);
+ break;
+ }
+ bd.bd_ncrc = n;
+ if (msgok)
+ Msg(0, "bd_ncrc status is: %d ", bd.bd_ncrc);
+ position_braille_cursor();
+ break;
+
+ case RC_BD_BRAILLE_TABLE:
+ s = 0;
+ if (*args)
+ {
+ if (ParseSaveStr(act, &s))
+ break;
+ if (load_braille_table(s))
+ {
+ free(s);
+ break;
+ }
+ if (bd.bd_braille_table)
+ free(bd.bd_braille_table);
+ bd.bd_braille_table = s;
+ }
+ if (msgok)
+ Msg(0, "bd_braille_table is: %s ", bd.bd_braille_table);
+ break;
+
+ case RC_BD_PORT:
+ s = 0;
+ if (*args)
+ {
+ if (ParseSaveStr(act, &s))
+ break;
+
+ if (stat(s, &st) || !S_ISCHR(st.st_mode) || access(s, R_OK|W_OK))
+ {
+ Msg(0, "Cannot access braille device port %s", s);
+ free(s);
+ break;
+ }
+ if (bd.bd_fd >= 0)
+ close(bd.bd_fd);
+ bd.bd_fd = -1;
+ if (bd.bd_port)
+ free(bd.bd_port);
+ bd.bd_port = s;
+ }
+ if (msgok)
+ Msg(0, "bd_port is: %s ", bd.bd_port ? bd.bd_port : "not set");
+ StartBraille();
+ break;
+
+ case RC_BD_TYPE:
+ s = 0;
+ if (*args)
+ if (ParseSaveStr(act, &s) || initialize_braille_display_type(s))
+ break;
+ if (msgok)
+ Msg(0, "bd_type is: %s ", bd.bd_type ? bd.bd_type : "not set");
+ StartBraille();
+ break;
+
+ case RC_BD_START_BRAILLE:
+ if (ParseSwitch(act, &bd.bd_start_braille))
+ break;
+ if (msgok)
+ Msg(0, bd.bd_start_braille ? "bd_start_braille is on." : "bd_start_braille is off.");
+ StartBraille();
+ break;
+
+ case RC_BD_WIDTH:
+ n = bd.bd_width;
+ if (*args)
+ {
+ if (ParseNum(act, &n))
+ break;
+ }
+ if (n <= 0)
+ {
+ Msg(0, "Invalid value for bd_width: %d ", n);
+ break;
+ }
+ l = (bd.bd_info * 2 + 2) & 12;
+ if (n > bd.bd_ncells - l || n < l)
+ {
+ Msg(0, "bd_info is too large for bd_width.");
+ break;
+ }
+ bd.bd_width = n;
+ if (msgok)
+ Msg(0, "bd_width is: %d ", bd.bd_width);
+ break;
+
+ case RC_BD_BC_LEFT:
+ bd_bc_left();
+ break;
+
+ case RC_BD_BC_RIGHT:
+ bd_bc_right();
+ break;
+
+ case RC_BD_BC_UP:
+ bd_bc_up();
+ break;
+
+ case RC_BD_BC_DOWN:
+ bd_bc_down();
+ break;
+
+ case RC_BD_UPPER_LEFT:
+ bd_upper_left();
+ break;
+
+ case RC_BD_UPPER_RIGHT:
+ bd_upper_right();
+ break;
+
+ case RC_BD_LOWER_LEFT:
+ bd_lower_left();
+ break;
+
+ case RC_BD_LOWER_RIGHT:
+ bd_lower_right();
+ break;
+
+ default:
+ break;
+ }
+}
+
+static void
+bd_readev_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ bd.buttonpress();
+}
+
+static void
+bd_writeev_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ int len;
+
+ if (bd.bd_obuflen == 0)
+ return;
+ if ((len = write(bd.bd_fd, bd.bd_obuf, bd.bd_obuflen)) < 0)
+ len = bd.bd_obuflen; /* dead braille display */
+ if ((bd.bd_obuflen -= len))
+ bcopy(bd.bd_obuf + len, bd.bd_obuf, bd.bd_obuflen);
+}
+
+static void
+bd_selectev_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ RefreshBraille();
+}
+
+#endif /* HAVE_BRAILLE */
diff --git a/braille.h b/braille.h
new file mode 100644
index 0000000..a0cb4e9
--- /dev/null
+++ b/braille.h
@@ -0,0 +1,83 @@
+/*
+ * Authors: Hadi Bargi Rangin bargi@dots.physics.orst.edu
+ * Bill Barry barryb@dots.physics.orst.edu
+ * Randy Lundquist randyl@dots.physics.orst.edu
+ *
+ * Modifications Copyright (c) 1995 by
+ * Science Access Project, Oregon State University.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+#ifdef HAVE_BRAILLE
+
+extern void StartBraille __P((void));
+
+struct braille_display
+{
+ struct display *bd_dpy; /* display we are connected to */
+ int bd_start_braille; /* screenrc var to request to turn braille on */
+ int bd_using_braille; /* all is fine, use braille */
+ struct event bd_readev;
+ struct event bd_writeev;
+ struct event bd_selectev;
+ int bd_fd; /* file descriptor */
+ int bd_obuflen; /* current number of charactors in output buffer */
+ char bd_obuf[IOSIZE];
+ int bd_info; /* default, no info, 0,1,2,3 */
+ int bd_ncrc; /* default 1, numbers of cells on the right side of real cursor, 1...bd_width */
+ int bd_skip; /* default off, on/off */
+ int bd_link; /* default, linked, on/off */
+ int bd_width; /* length of braille display to use, <=bd_ncells */
+ int bd_scroll; /* default on, scroll on/off */
+ char *bd_braille_table; /* braille code */
+
+ int bd_bell; /* bell used for navigation on/off */
+ int bd_ncells; /* real number of cells on braille display */
+ int bd_eightdot; /* eightdot on/off */
+ int bd_baud; /* communication baudrate between port and braille display */
+ char *bd_port; /* serial port to use */
+ char *bd_type; /* kind of braille display */
+ double bd_version; /* rom version of braille display */
+ char bd_btable[256]; /* braille translation table */
+
+ /* functions which communicate with braille displays */
+ int (*write_line_braille) __P((char [],int, int));
+ void (*buttonpress) __P((void));
+ int (*bd_response_test) __P((void));
+
+ int bd_refreshing; /* are we doing a refresh? */
+ char bd_line[40+1]; /* bd_ncells chars displayed on braille */
+ int bd_cursorpos; /* cursor position on braille */
+ char bd_oline[40+1]; /* bd_ncells chars displayed on braille */
+ int bd_sx, bd_sy; /* screen cursor pos */
+ int bd_moved; /* used braille move keys */
+
+ int bd_searching; /* are we seaching (bd_skip is on) */
+ int bd_searchmax; /* search: max x */
+ int bd_searchmin; /* search: min x */
+ int bd_searchstart;
+ int bd_searchend;
+};
+
+extern struct braille_display bd;
+
+#define BD_FORE bd.bd_dpy->d_fore
+
+#endif
diff --git a/braille_tsi.c b/braille_tsi.c
new file mode 100644
index 0000000..6f84913
--- /dev/null
+++ b/braille_tsi.c
@@ -0,0 +1,319 @@
+/* bd-tsi.c, TSI specific key bindings and display commands
+ *
+ * dotscreen
+ * A braille interface to unix tty terminals
+ * Authors: Hadi Bargi Rangin bargi@dots.physics.orst.edu
+ * Bill Barry barryb@dots.physics.orst.edu
+ *
+ * Copyright (c) 1995 by Science Access Project, Oregon State University.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include "config.h"
+#include "screen.h"
+#include "extern.h"
+#include "braille.h"
+
+#ifdef HAVE_BRAILLE
+
+extern struct display *display;
+
+struct key2rc {
+ int key;
+ int nr;
+ char *arg1;
+ char *arg2;
+};
+
+
+static int tsi_ctype = 1; /* cursor type, 0,1,2 */
+
+static int tsi_line_type; /* indicates number of cells on powerbraille
+ display 01=20 cells 02=40 cells 03=80 cells */
+
+static int display_status_tsi __P((void));
+static int write_line_tsi __P((char *, int, int));
+static void buttonpress_tsi __P((struct key2rc *));
+static void buttonpress_navigator_40 __P((void));
+static void buttonpress_powerbraille_40 __P((void));
+static void buttonpress_powerbraille_80 __P((void));
+
+int
+bd_init_powerbraille_40()
+{
+ bd.write_line_braille = write_line_tsi;
+ bd.buttonpress = buttonpress_powerbraille_40;
+ bd.bd_response_test = display_status_tsi;
+ bd.bd_ncells = 40;
+ tsi_line_type = 2;
+ return 0;
+}
+
+int
+bd_init_powerbraille_80()
+{
+ bd.write_line_braille = write_line_tsi;
+ bd.buttonpress = buttonpress_powerbraille_80;
+ bd.bd_response_test = display_status_tsi;
+ bd.bd_ncells = 80;
+ tsi_line_type = 3;
+ return 0;
+}
+
+int
+bd_init_navigator_40()
+{
+ bd.write_line_braille = write_line_tsi;
+ bd.buttonpress = buttonpress_navigator_40;
+ bd.bd_response_test = display_status_tsi;
+ bd.bd_ncells = 40;
+ tsi_line_type = 2;
+ return 0;
+}
+
+static int
+display_status_tsi()
+{
+ char obuf[3],ibuf[20];
+ int r;
+
+ obuf[0] = 0xff;
+ obuf[1] = 0xff;
+ obuf[2] = 0x0a;
+ r = read(bd.bd_fd, ibuf, 20); /* flush the input port */
+ r = write(bd.bd_fd, obuf, 3);
+ if (r != 3)
+ return -1;
+
+ /* we have written to the display asking for a response
+ we wait 1 second for the response, read it and if no
+ response we wait 2 seconds, if still no response,
+ return -1 to indicate no braille display available */
+ sleep(1);
+ r = read(bd.bd_fd, ibuf, 2);
+ if (r == -1)
+ {
+ sleep(2);
+ r = read(bd.bd_fd, ibuf, 2);
+ }
+ debug2("first chars from braille display %d %d\n",ibuf[0],ibuf[1]);
+ if (r != 2 || ibuf[0] != 0 || ibuf[1] != 5)
+ return -1;
+
+ r= read(bd.bd_fd,ibuf,2);
+ if (r != 2)
+ return -1;
+ debug2("braille display size:%d dots:%d\n", ibuf[0], ibuf[1]);
+ bd.bd_ncells = (unsigned char)ibuf[0];
+ if (bd.bd_ncells <= 1)
+ return -1;
+ r = read(bd.bd_fd,ibuf,1);
+ if (r != 1)
+ return -1;
+ if (ibuf[0] == 'V')
+ r = read(bd.bd_fd, ibuf, 3);
+ else
+ r = read(bd.bd_fd, ibuf + 1, 2) + 1;
+ if (r != 3)
+ return -1;
+ ibuf[3] = 0;
+ debug1("braille display version %s\n", ibuf);
+ bd.bd_version = atof(ibuf);
+ return 0;
+}
+
+
+static int
+write_line_tsi (bstr,line_length, cursor_pos)
+char *bstr;
+int line_length, cursor_pos;
+{
+ int obp, i;
+ bd.bd_obuf[0] = 0xff;
+ bd.bd_obuf[1] = 0xff;
+ bd.bd_obuf[2] = tsi_line_type;
+ bd.bd_obuf[3] = 0x07;
+ bd.bd_obuf[4] = cursor_pos;
+ bd.bd_obuf[5] = tsi_ctype;
+ obp=6;
+
+ for (i=0; i < line_length; i++)
+ {
+ bd.bd_obuf[2*i+obp] = 0;
+ bd.bd_obuf[2*i+1+obp] = bd.bd_btable[(int)(unsigned char)bstr[i]];
+ }
+ for (i=line_length; i < bd.bd_ncells; i++)
+ {
+ bd.bd_obuf[2*i+obp] = 0;
+ bd.bd_obuf[2*i+1+obp] = bd.bd_btable[(int)' '];
+ }
+
+ bd.bd_obuflen = 2*bd.bd_ncells + obp ;
+ return 0;
+}
+
+static struct key2rc keys_navigator_40[] = {
+ {0x4000000, RC_STUFF, "-k", "kl"}, /* 1 */
+ {0x10000000, RC_STUFF, "-k", "kr"}, /* 3 */
+ {0x8000000, RC_STUFF, "-k", "ku"}, /* 2 */
+ {0x20000000, RC_STUFF, "-k", "kd"}, /* 4 */
+ {0x2000, RC_BD_BC_LEFT, 0, 0}, /* 6 */
+ {0x8000, RC_BD_BC_RIGHT, 0, 0}, /* 8 */
+ {0x4000, RC_BD_BC_UP, 0, 0}, /* 7 */
+ {0x10000, RC_BD_BC_DOWN, 0, 0}, /* 9 */
+ {0x6000, RC_BD_UPPER_LEFT, 0, 0}, /* 6, 7 */
+ {0xc000, RC_BD_UPPER_RIGHT, 0, 0}, /* 7, 8 */
+ {0x12000, RC_BD_LOWER_LEFT, 0, 0}, /* 6, 9 */
+ {0x18000, RC_BD_LOWER_RIGHT, 0, 0}, /* 8, 9 */
+ {0xa000, RC_BD_INFO, "1032", 0}, /* bc 6, 8 */
+ {0x14000000, RC_BD_INFO, "2301", 0}, /* sc 1, 3 */
+ {0x4008000, RC_BD_INFO, "3330", 0}, /* bc+sc 1, 8 */
+ {0x8010000, RC_BD_BELL, 0, 0}, /* 2, 9 */
+ {0x8004000, RC_BD_EIGHTDOT, 0, 0}, /* 2, 7 */
+ {0x40000000, RC_STUFF, "\015", 0}, /* 5 */
+ {0x20000, RC_BD_LINK, 0, 0}, /* 10 */
+ {0x10002000, RC_BD_SCROLL, 0, 0}, /* 3, 6 */
+ {0x20010000, RC_BD_NCRC, "+", 0}, /* 4, 9 */
+ {0x14000, RC_BD_SKIP, 0, 0}, /* 7, 9*/
+ {-1, RC_ILLEGAL, 0, 0}
+};
+
+static struct key2rc keys_powerbraille_40[] = {
+ {0x4000000, RC_STUFF, "-k", "kl"}, /* 1 */
+ {0x10000000, RC_STUFF, "-k", "kr"}, /* 3 */
+ {0x8000000, RC_STUFF, "-k", "ku"}, /* 2 */
+ {0x20000000, RC_STUFF, "-k", "kd"}, /* 4 */
+ {0x2000, RC_BD_BC_LEFT, 0, 0}, /* 6 */
+ {0x8000, RC_BD_BC_RIGHT, 0, 0}, /* 8 */
+ {0x4000, RC_BD_BC_UP, 0, 0}, /* 7 */
+ {0x10000, RC_BD_BC_DOWN, 0, 0}, /* 9 */
+ {0x8002000, RC_BD_UPPER_LEFT, 0, 0}, /* 2, 6 */
+ {0xc000, RC_BD_UPPER_RIGHT, 0, 0}, /* 7, 8 */
+ {0x20002000, RC_BD_LOWER_LEFT, 0, 0}, /* 3, 6 */
+ {0x18000, RC_BD_LOWER_RIGHT, 0, 0}, /* 8, 9 */
+ {0x8008000, RC_BD_INFO, "1032", 0}, /* bc 2, 8 */
+ {0x6000, RC_BD_INFO, "2301", 0}, /* 6, 7 */
+ {0x8004000, RC_BD_INFO, "3330", 0}, /* bc+sc 2, 7 */
+ {0x8010000, RC_BD_BELL, 0, 0}, /* 2, 9 */
+ {0x20008000, RC_BD_EIGHTDOT, 0, 0}, /* 4, 6 */
+ {0x40000000, RC_STUFF, "\015", 0}, /* 5 */
+ {0x20000, RC_BD_LINK, 0, 0}, /* 10 */
+ {0xa000, RC_BD_SCROLL, 0, 0}, /* 6, 8 */
+ {0x20010000, RC_BD_NCRC, "+", 0}, /* 4, 9 */
+ {0x20004000, RC_BD_SKIP, 0, 0}, /* 4, 7 */
+ {-1, RC_ILLEGAL, 0, 0}
+};
+
+
+static struct key2rc keys_powerbraille_80[] = {
+ {0x4000000, RC_STUFF, "-k", "kl"}, /* 1 */
+ {0x10000000, RC_STUFF, "-k", "kr"}, /* 3 */
+ {0x8000000, RC_STUFF, "-k", "ku"}, /* 2 */
+ {0x20000000, RC_STUFF, "-k", "kd"}, /* 4 */
+ {0x40000, RC_BD_BC_LEFT, 0, 0}, /* 6 */
+ {0x100000, RC_BD_BC_RIGHT, 0, 0}, /* 8 */
+ {0x4000, RC_BD_BC_UP, 0, 0}, /* 7 */
+ {0x10000, RC_BD_BC_DOWN, 0, 0}, /* 9 */
+ {0x44000, RC_BD_UPPER_LEFT, 0, 0}, /* 6, 7 */
+ {0x104000, RC_BD_UPPER_RIGHT, 0, 0}, /* 7, 8 */
+ {0x50000, RC_BD_LOWER_LEFT, 0, 0}, /* 6, 9 */
+ {0x110000, RC_BD_LOWER_RIGHT, 0, 0}, /* 8, 9 */
+ {0x8100000, RC_BD_INFO, "1032", 0}, /* 2, 8 */
+ {0x8040000, RC_BD_INFO, "2301", 0}, /* 2, 6 */
+ {0x140000, RC_BD_INFO, "3330", 0}, /* 6, 8 */
+ {0x8010000, RC_BD_BELL, 0, 0}, /* 2, 9 */
+ {0x8004000, RC_BD_EIGHTDOT, 0, 0}, /* 2, 7 */
+ {0x40000000, RC_STUFF, "\015", 0}, /* 5 */
+ {0x20000, RC_BD_LINK, 0, 0}, /* 10 */
+ {0x20004000, RC_BD_SCROLL, 0, 0}, /* 4, 7 */
+ {0x20010000, RC_BD_NCRC, "+", 0}, /* 4, 9 */
+ {0x40010000, RC_BD_SKIP, 0, 0}, /* 5, 9 */
+ {-1, RC_ILLEGAL, 0, 0}
+};
+
+static void
+buttonpress_tsi(tab)
+struct key2rc *tab;
+{
+ int i, nb;
+ int bkeys;
+ unsigned char buf[10];
+ nb = read(bd.bd_fd, buf, 10);
+ debug1("buttonpress_tsi: read %d bytes\n", nb);
+ for (i=0, bkeys=0; i < nb; i++)
+ {
+ switch (buf[i] & 0xE0)
+ {
+ case 0x00: bkeys += ((int)(buf[i] & 0x1f) ); break;
+ case 0x20: bkeys += ((int)(buf[i] & 0x1f) << 5 ); break;
+ case 0x40: bkeys += ((int)(buf[i] & 0x1f) << 9 ); break;
+ case 0x60: bkeys += ((int)(buf[i] & 0x1f) << 13 ); break;
+ case 0xA0: bkeys += ((int)(buf[i] & 0x1f) << 18 ); break;
+ case 0xC0: bkeys += ((int)(buf[i] & 0x1f) << 22 ); break;
+ case 0xE0: bkeys += ((int)(buf[i] & 0x1f) << 26 ); break;
+ default: break;
+ }
+ }
+ debug1("bkeys %x\n", bkeys);
+ for (i = 0; tab[i].key != -1; i++)
+ if (bkeys == tab[i].key)
+ break;
+ debug1("bkey index %d\n", i);
+ if (tab[i].key != -1 && tab[i].nr != RC_ILLEGAL)
+ {
+ char *args[3];
+ int argl[2];
+
+ struct action act;
+ args[0] = tab[i].arg1;
+ args[1] = tab[i].arg2;
+ args[2] = 0;
+ argl[0] = args[0] ? strlen(args[0]) : 0;
+ argl[1] = args[1] ? strlen(args[1]) : 0;
+ act.nr = tab[i].nr;
+ act.args = args;
+ act.argl = argl;
+ display = bd.bd_dpy;
+ DoAction(&act, -2);
+ }
+}
+
+
+static void
+buttonpress_navigator_40()
+{
+ buttonpress_tsi(keys_navigator_40);
+}
+
+static void
+buttonpress_powerbraille_40()
+{
+ buttonpress_tsi(keys_powerbraille_40);
+}
+
+static void
+buttonpress_powerbraille_80()
+{
+ buttonpress_tsi(keys_powerbraille_80);
+}
+
+#endif /* HAVE_BRAILLE */
+
+
diff --git a/canvas.c b/canvas.c
new file mode 100644
index 0000000..7a31b0a
--- /dev/null
+++ b/canvas.c
@@ -0,0 +1,918 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include "config.h"
+#include "screen.h"
+#include "extern.h"
+#include "canvas.h"
+#include "list_generic.h"
+
+extern struct display *display;
+extern struct win *fore, *windows;
+extern struct layer *flayer;
+extern int captionalways;
+extern struct LayFuncs BlankLf;
+extern int focusminwidth, focusminheight;
+
+static void
+CanvasInitBlank(cv)
+struct canvas *cv;
+{
+ cv->c_blank.l_cvlist = cv;
+ cv->c_blank.l_width = cv->c_xe - cv->c_xs + 1;
+ cv->c_blank.l_height = cv->c_ye - cv->c_ys + 1;
+ cv->c_blank.l_x = cv->c_blank.l_y = 0;
+ cv->c_blank.l_layfn = &BlankLf;
+ cv->c_blank.l_data = 0;
+ cv->c_blank.l_next = 0;
+ cv->c_blank.l_bottom = &cv->c_blank;
+ cv->c_blank.l_blocking = 0;
+ cv->c_layer = &cv->c_blank;
+}
+
+static void
+FreePerp(pcv)
+struct canvas *pcv;
+{
+ struct canvas *cv;
+
+ if (!pcv->c_slperp)
+ return;
+ cv = pcv->c_slperp;
+ cv->c_slprev = pcv->c_slprev;
+ if (cv->c_slprev)
+ cv->c_slprev->c_slnext = cv;
+ cv->c_slback = pcv->c_slback;
+ if (cv->c_slback && cv->c_slback->c_slperp == pcv)
+ cv->c_slback->c_slperp = cv;
+ cv->c_slorient = pcv->c_slorient;
+ cv->c_slweight = pcv->c_slweight;
+ while (cv->c_slnext)
+ {
+ cv = cv->c_slnext;
+ cv->c_slorient = pcv->c_slorient;
+ cv->c_slback = pcv->c_slback;
+ cv->c_slweight = pcv->c_slweight;
+ }
+ cv->c_slnext = pcv->c_slnext;
+ if (cv->c_slnext)
+ cv->c_slnext->c_slprev = cv;
+ LayerCleanupMemory(&pcv->c_blank);
+ free(pcv);
+}
+
+void
+FreeCanvas(cv)
+struct canvas *cv;
+{
+ struct viewport *vp, *nvp;
+ struct canvas **cvp;
+ struct win *p;
+
+ if (cv->c_slprev)
+ cv->c_slprev->c_slnext = cv->c_slnext;
+ if (cv->c_slnext)
+ cv->c_slnext->c_slprev = cv->c_slprev;
+ if (cv->c_slback && cv->c_slback->c_slperp == cv)
+ cv->c_slback->c_slperp = cv->c_slnext ? cv->c_slnext : cv->c_slprev;
+ if (cv->c_slperp)
+ {
+ while (cv->c_slperp)
+ FreeCanvas(cv->c_slperp);
+ LayerCleanupMemory(&cv->c_blank);
+ free(cv);
+ return;
+ }
+
+ if (display)
+ {
+ if (D_forecv == cv)
+ D_forecv = 0;
+ /* remove from canvas chain as SetCanvasWindow might call
+ * some layer function */
+ for (cvp = &D_cvlist; *cvp ; cvp = &(*cvp)->c_next)
+ if (*cvp == cv)
+ {
+ *cvp = cv->c_next;
+ break;
+ }
+ }
+ p = cv->c_layer ? Layer2Window(cv->c_layer) : 0;
+ SetCanvasWindow(cv, 0);
+ if (p)
+ WindowChanged(p, 'u');
+ if (flayer == cv->c_layer)
+ flayer = 0;
+ for (vp = cv->c_vplist; vp; vp = nvp)
+ {
+ vp->v_canvas = 0;
+ nvp = vp->v_next;
+ vp->v_next = 0;
+ free(vp);
+ }
+ evdeq(&cv->c_captev);
+ LayerCleanupMemory(&cv->c_blank);
+ free(cv);
+}
+
+int
+CountCanvas(cv)
+struct canvas *cv;
+{
+ int num = 0;
+ for (; cv; cv = cv->c_slnext)
+ {
+ if (cv->c_slperp)
+ {
+ struct canvas *cvp;
+ int nump = 1, n;
+ for (cvp = cv->c_slperp; cvp; cvp = cvp->c_slnext)
+ if (cvp->c_slperp)
+ {
+ n = CountCanvas(cvp->c_slperp);
+ if (n > nump)
+ nump = n;
+ }
+ num += nump;
+ }
+ else
+ num++;
+ }
+ return num;
+}
+
+int
+CountCanvasPerp(cv)
+struct canvas *cv;
+{
+ struct canvas *cvp;
+ int num = 1, n;
+ for (cvp = cv->c_slperp; cvp; cvp = cvp->c_slnext)
+ if (cvp->c_slperp)
+ {
+ n = CountCanvas(cvp->c_slperp);
+ if (n > num)
+ num = n;
+ }
+ return num;
+}
+
+struct canvas *
+FindCanvas(x, y)
+int x, y;
+{
+ struct canvas *cv, *mcv = 0;
+ int m, mm = 0;
+
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ {
+ /* ye + 1 because of caption line */
+ if (x >= cv->c_xs && x <= cv->c_xe && y >= cv->c_ys && y <= cv->c_ye + 1)
+ return cv;
+ if (cv == D_forecv)
+ continue;
+ m = 0;
+ if (x >= D_forecv->c_xs && x <= D_forecv->c_xe)
+ {
+ if (x < cv->c_xs || x > cv->c_xe)
+ continue;
+ if (y < D_forecv->c_ys && y < cv->c_ys)
+ continue;
+ if (y > D_forecv->c_ye + 1 && y > cv->c_ye + 1)
+ continue;
+ if (y < cv->c_ys)
+ m = cv->c_ys - y;
+ if (y > cv->c_ye + 1)
+ m = y - (cv->c_ye + 1);
+ }
+ if (y >= D_forecv->c_ys && y <= D_forecv->c_ye + 1)
+ {
+ if (y < cv->c_ys || y > cv->c_ye + 1)
+ continue;
+ if (x < D_forecv->c_xs && x < cv->c_xs)
+ continue;
+ if (x > D_forecv->c_xe && x > cv->c_xe)
+ continue;
+ if (x < cv->c_xs)
+ m = cv->c_xs - x;
+ if (x > cv->c_xe)
+ m = x - cv->c_xe;
+ }
+ if (m && (!mm || m < mm))
+ {
+ mcv = cv;
+ mm = m;
+ }
+ }
+ return mcv ? mcv : D_forecv;
+}
+
+void
+SetCanvasWindow(cv, wi)
+struct canvas *cv;
+struct win *wi;
+{
+ struct win *p = 0, **pp;
+ struct layer *l;
+ struct canvas *cvp, **cvpp;
+
+ l = cv->c_layer;
+ display = cv->c_display;
+
+ if (l)
+ {
+ /* remove old layer */
+ for (cvpp = &l->l_cvlist; (cvp = *cvpp); cvpp = &cvp->c_lnext)
+ if (cvp == cv)
+ break;
+ ASSERT(cvp);
+ *cvpp = cvp->c_lnext;
+
+ p = Layer2Window(l);
+ l = cv->c_layer;
+ cv->c_layer = 0;
+
+ if (p && cv == D_forecv)
+ {
+#ifdef MULTIUSER
+ ReleaseAutoWritelock(display, p);
+#endif
+ if (p->w_silence)
+ {
+ SetTimeout(&p->w_silenceev, p->w_silencewait * 1000);
+ evenq(&p->w_silenceev);
+ }
+ D_other = fore;
+ D_fore = 0;
+ }
+ if (l->l_cvlist == 0 && (p == 0 || l != p->w_savelayer))
+ KillLayerChain(l);
+ }
+
+ /* find right layer to display on canvas */
+ if (wi && wi->w_type != W_TYPE_GROUP)
+ {
+ l = &wi->w_layer;
+ if (wi->w_savelayer && (wi->w_blocked || wi->w_savelayer->l_cvlist == 0))
+ l = wi->w_savelayer;
+ }
+ else
+ {
+ l = &cv->c_blank;
+ if (wi)
+ l->l_data = (char *)wi;
+ else
+ l->l_data = 0;
+ }
+
+ /* add our canvas to the layer's canvaslist */
+ ASSERT(l->l_cvlist != cv);
+ cv->c_lnext = l->l_cvlist;
+ l->l_cvlist = cv;
+ cv->c_layer = l;
+ cv->c_xoff = cv->c_xs;
+ cv->c_yoff = cv->c_ys;
+ RethinkViewportOffsets(cv);
+
+ if (flayer == 0)
+ flayer = l;
+
+ if (wi && wi->w_type == W_TYPE_GROUP)
+ {
+ /* auto-start windowlist on groups */
+ struct display *d = display;
+ struct layer *oldflayer = flayer;
+ flayer = l;
+ display_windows(0, 0, wi);
+ flayer = oldflayer;
+ display = d;
+ }
+
+ if (wi && D_other == wi)
+ D_other = wi->w_next; /* Might be 0, but that's OK. */
+ if (cv == D_forecv)
+ {
+ D_fore = wi;
+ fore = D_fore; /* XXX ? */
+ if (wi)
+ {
+#ifdef MULTIUSER
+ ObtainAutoWritelock(display, wi);
+#endif
+ /*
+ * Place the window at the head of the most-recently-used list
+ */
+ if (windows != wi)
+ {
+ for (pp = &windows; (p = *pp); pp = &p->w_next)
+ if (p == wi)
+ break;
+ ASSERT(p);
+ *pp = p->w_next;
+ p->w_next = windows;
+ windows = p;
+ WListLinkChanged();
+ }
+ }
+ }
+}
+
+static void
+cv_winid_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ int ox, oy;
+ struct canvas *cv = (struct canvas *)data;
+
+ display = cv->c_display;
+ if (D_status == STATUS_ON_WIN)
+ {
+ SetTimeout(ev, 1);
+ evenq(ev);
+ return;
+ }
+ ox = D_x;
+ oy = D_y;
+ if (cv->c_ye + 1 < D_height)
+ RefreshLine(cv->c_ye + 1, 0, D_width - 1, 0);
+ if (ox != -1 && oy != -1)
+ GotoPos(ox, oy);
+}
+
+int
+MakeDefaultCanvas()
+{
+ struct canvas *cv;
+
+ ASSERT(display);
+ if ((cv = (struct canvas *)calloc(1, sizeof *cv)) == 0)
+ return -1;
+ cv->c_xs = 0;
+ cv->c_xe = D_width - 1;
+ cv->c_ys = (D_has_hstatus == HSTATUS_FIRSTLINE);
+ cv->c_ye = D_height - 1 - (D_has_hstatus == HSTATUS_LASTLINE) - captionalways;
+ debug2("MakeDefaultCanvas 0,0 %d,%d\n", cv->c_xe, cv->c_ye);
+ cv->c_xoff = 0;
+ cv->c_yoff = 0;
+ cv->c_next = 0;
+ cv->c_display = display;
+ cv->c_vplist = 0;
+ cv->c_slnext = 0;
+ cv->c_slprev = 0;
+ cv->c_slperp = 0;
+ cv->c_slweight = 1;
+ cv->c_slback = &D_canvas;
+ D_canvas.c_slperp = cv;
+ D_canvas.c_xs = cv->c_xs;
+ D_canvas.c_xe = cv->c_xe;
+ D_canvas.c_ys = cv->c_ys;
+ D_canvas.c_ye = cv->c_ye;
+ cv->c_slorient = SLICE_UNKN;
+ cv->c_captev.type = EV_TIMEOUT;
+ cv->c_captev.data = (char *)cv;
+ cv->c_captev.handler = cv_winid_fn;
+
+ CanvasInitBlank(cv);
+ cv->c_lnext = 0;
+
+ D_cvlist = cv;
+ RethinkDisplayViewports();
+ D_forecv = cv; /* default input focus */
+ return 0;
+}
+
+static struct canvas **
+CreateCanvasChainRec(cv, cvp)
+struct canvas *cv;
+struct canvas **cvp;
+{
+ for (; cv; cv = cv->c_slnext)
+ {
+ if (cv->c_slperp)
+ cvp = CreateCanvasChainRec(cv->c_slperp, cvp);
+ else
+ {
+ *cvp = cv;
+ cvp = &cv->c_next;
+ }
+ }
+ return cvp;
+}
+
+void
+RecreateCanvasChain()
+{
+ struct canvas **cvp;
+ cvp = CreateCanvasChainRec(D_canvas.c_slperp, &D_cvlist);
+ *cvp = 0;
+}
+
+void
+EqualizeCanvas(cv, gflag)
+struct canvas *cv;
+int gflag;
+{
+ struct canvas *cv2;
+ for (; cv; cv = cv->c_slnext)
+ {
+ if (cv->c_slperp && gflag)
+ {
+ cv->c_slweight = CountCanvasPerp(cv);
+ for (cv2 = cv->c_slperp; cv2; cv2 = cv2->c_slnext)
+ if (cv2->c_slperp)
+ EqualizeCanvas(cv2->c_slperp, gflag);
+ }
+ else
+ cv->c_slweight = 1;
+ }
+}
+
+void
+ResizeCanvas(cv)
+struct canvas *cv;
+{
+ struct canvas *cv2, *cvn, *fcv;
+ int nh, i, maxi, hh, m, w, wsum;
+ int need, got;
+ int xs, ys, xe, ye;
+ int focusmin = 0;
+
+ xs = cv->c_xs;
+ ys = cv->c_ys;
+ xe = cv->c_xe;
+ ye = cv->c_ye;
+ cv = cv->c_slperp;
+ debug2("ResizeCanvas: %d,%d", xs, ys);
+ debug2(" %d,%d\n", xe, ye);
+ if (cv == 0)
+ return;
+ if (cv->c_slorient == SLICE_UNKN)
+ {
+ ASSERT(!cv->c_slnext && !cv->c_slperp);
+ cv->c_xs = xs;
+ cv->c_xe = xe;
+ cv->c_ys = ys;
+ cv->c_ye = ye;
+ cv->c_xoff = cv->c_xs;
+ cv->c_yoff = cv->c_ys;
+ cv->c_blank.l_width = cv->c_xe - cv->c_xs + 1;
+ cv->c_blank.l_height = cv->c_ye - cv->c_ys + 1;
+ return;
+ }
+
+ fcv = 0;
+ if (focusminwidth || focusminheight)
+ {
+ debug("searching for focus canvas\n");
+ cv2 = D_forecv;
+ while (cv2->c_slback)
+ {
+ if (cv2->c_slback == cv->c_slback)
+ {
+ fcv = cv2;
+ focusmin = cv->c_slorient == SLICE_VERT ? focusminheight : focusminwidth;
+ if (focusmin > 0)
+ focusmin--;
+ else if (focusmin < 0)
+ focusmin = cv->c_slorient == SLICE_VERT ? ye - ys + 2 : xe - xs + 2;
+ debug1("found, focusmin=%d\n", focusmin);
+ }
+ cv2 = cv2->c_slback;
+ }
+ }
+ if (focusmin)
+ {
+ m = CountCanvas(cv) * 2;
+ nh = cv->c_slorient == SLICE_VERT ? ye - ys + 2 : xe - xs + 2;
+ nh -= m;
+ if (nh < 0)
+ nh = 0;
+ if (focusmin > nh)
+ focusmin = nh;
+ debug1("corrected to %d\n", focusmin);
+ }
+
+ /* pass 1: calculate weight sum */
+ for (cv2 = cv, wsum = 0; cv2; cv2 = cv2->c_slnext)
+ {
+ debug1(" weight %d\n", cv2->c_slweight);
+ wsum += cv2->c_slweight;
+ }
+ debug1("wsum = %d\n", wsum);
+ if (wsum == 0)
+ wsum = 1;
+ w = wsum;
+
+ /* pass 2: calculate need/excess space */
+ nh = cv->c_slorient == SLICE_VERT ? ye - ys + 2 : xe - xs + 2;
+ for (cv2 = cv, need = got = 0; cv2; cv2 = cv2->c_slnext)
+ {
+ m = cv2->c_slperp ? CountCanvasPerp(cv2) * 2 - 1 : 1;
+ if (cv2 == fcv)
+ m += focusmin;
+ hh = cv2->c_slweight ? nh * cv2->c_slweight / w : 0;
+ w -= cv2->c_slweight;
+ nh -= hh;
+ debug2(" should %d min %d\n", hh, m);
+ if (hh <= m + 1)
+ need += m + 1 - hh;
+ else
+ got += hh - m - 1;
+ }
+ debug2("need: %d, got %d\n", need, got);
+ if (need > got)
+ need = got;
+
+ /* pass 3: distribute space */
+ nh = cv->c_slorient == SLICE_VERT ? ye - ys + 2 : xe - xs + 2;
+ i = cv->c_slorient == SLICE_VERT ? ys : xs;
+ maxi = cv->c_slorient == SLICE_VERT ? ye : xe;
+ w = wsum;
+ for (; cv; cv = cvn)
+ {
+ cvn = cv->c_slnext;
+ if (i > maxi)
+ {
+ if (cv->c_slprev && !cv->c_slback->c_slback && !cv->c_slprev->c_slperp && !cv->c_slprev->c_slprev)
+ {
+ cv->c_slprev->c_slorient = SLICE_UNKN;
+ if (!captionalways)
+ {
+ cv->c_slback->c_ye++;
+ cv->c_slprev->c_ye++;
+ }
+ }
+ SetCanvasWindow(cv, 0);
+ FreeCanvas(cv);
+ continue;
+ }
+ m = cv->c_slperp ? CountCanvasPerp(cv) * 2 - 1 : 1;
+ if (cv == fcv)
+ m += focusmin;
+ hh = cv->c_slweight ? nh * cv->c_slweight / w : 0;
+ w -= cv->c_slweight;
+ nh -= hh;
+ debug2(" should %d min %d\n", hh, m);
+ if (hh <= m + 1)
+ {
+ hh = m + 1;
+ debug1(" -> %d\n", hh);
+ }
+ else
+ {
+ int hx = 1; //FIXME Division by zero (got) is posible. "hx = 1" is random number here!!!
+ if (got != 0)
+ hx = need * (hh - m - 1) / got;
+ else
+ debug(" got = 0\n");
+
+ debug3(" -> %d - %d = %d\n", hh, hx, hh - hx);
+ got -= (hh - m - 1);
+ hh -= hx;
+ need -= hx;
+ debug2(" now need=%d got=%d\n", need, got);
+ }
+ ASSERT(hh >= m + 1);
+ /* hh is window size plus pation line */
+ if (i + hh > maxi + 2)
+ {
+ hh = maxi + 2 - i;
+ debug1(" not enough space, reducing to %d\n", hh);
+ }
+ if (i + hh == maxi + 1)
+ {
+ hh++;
+ debug(" incrementing as no other canvas will fit\n");
+ }
+ if (cv->c_slorient == SLICE_VERT)
+ {
+ cv->c_xs = xs;
+ cv->c_xe = xe;
+ cv->c_ys = i;
+ cv->c_ye = i + hh - 2;
+ cv->c_xoff = xs;
+ cv->c_yoff = i;
+ }
+ else
+ {
+ cv->c_xs = i;
+ cv->c_xe = i + hh - 2;
+ cv->c_ys = ys;
+ cv->c_ye = ye;
+ cv->c_xoff = i;
+ cv->c_yoff = ys;
+ }
+ cv->c_xoff = cv->c_xs;
+ cv->c_yoff = cv->c_ys;
+ cv->c_blank.l_width = cv->c_xe - cv->c_xs + 1;
+ cv->c_blank.l_height = cv->c_ye - cv->c_ys + 1;
+ if (cv->c_slperp)
+ {
+ ResizeCanvas(cv);
+ if (!cv->c_slperp->c_slnext)
+ {
+ debug("deleting perp node\n");
+ FreePerp(cv->c_slperp);
+ FreePerp(cv);
+ }
+ }
+ i += hh;
+ }
+}
+
+static struct canvas *
+AddPerp(cv)
+struct canvas *cv;
+{
+ struct canvas *pcv;
+ debug("Creating new perp node\n");
+
+ if ((pcv = (struct canvas *)calloc(1, sizeof *cv)) == 0)
+ return 0;
+ pcv->c_next = 0;
+ pcv->c_display = cv->c_display;
+ pcv->c_slnext = cv->c_slnext;
+ pcv->c_slprev = cv->c_slprev;
+ pcv->c_slperp = cv;
+ pcv->c_slback = cv->c_slback;
+ if (cv->c_slback && cv->c_slback->c_slperp == cv)
+ cv->c_slback->c_slperp = pcv;
+ pcv->c_slorient = cv->c_slorient;
+ pcv->c_xoff = 0;
+ pcv->c_yoff = 0;
+ pcv->c_xs = cv->c_xs;
+ pcv->c_xe = cv->c_xe;
+ pcv->c_ys = cv->c_ys;
+ pcv->c_ye = cv->c_ye;
+ if (pcv->c_slnext)
+ pcv->c_slnext->c_slprev = pcv;
+ if (pcv->c_slprev)
+ pcv->c_slprev->c_slnext = pcv;
+ pcv->c_slweight = cv->c_slweight;
+ CanvasInitBlank(pcv);
+ cv->c_slweight = 1;
+ cv->c_slnext = 0;
+ cv->c_slprev = 0;
+ cv->c_slperp = 0;
+ cv->c_slback = pcv;
+ cv->c_slorient = SLICE_UNKN;
+ return pcv;
+}
+
+int
+AddCanvas(orient)
+int orient;
+{
+ struct canvas *cv;
+ int xs, xe, ys, ye;
+ int h, num;
+
+ cv = D_forecv;
+ debug2("AddCanvas orient %d, forecv is %d\n", orient, cv->c_slorient);
+
+ if (cv->c_slorient != SLICE_UNKN && cv->c_slorient != orient)
+ if (!AddPerp(cv))
+ return -1;
+
+ cv = D_forecv;
+ xs = cv->c_slback->c_xs;
+ xe = cv->c_slback->c_xe;
+ ys = cv->c_slback->c_ys;
+ ye = cv->c_slback->c_ye;
+ if (!captionalways && cv == D_canvas.c_slperp && !cv->c_slnext)
+ ye--; /* need space for caption */
+ debug2("Adding Canvas to slice %d,%d ", xs, ys);
+ debug2("%d,%d\n", xe, ye);
+
+ num = CountCanvas(cv->c_slback->c_slperp) + 1;
+ debug1("Num = %d\n", num);
+ if (orient == SLICE_VERT)
+ h = ye - ys + 1;
+ else
+ h = xe - xs + 1;
+
+ h -= 2 * num - 1;
+ if (h < 0)
+ return -1; /* can't fit in */
+
+ if ((cv = (struct canvas *)calloc(1, sizeof *cv)) == 0)
+ return -1;
+
+ D_forecv->c_slback->c_ye = ye; /* in case we modified it above */
+ D_forecv->c_slorient = orient; /* in case it was UNKN */
+ cv->c_slnext = D_forecv->c_slnext;
+ cv->c_slprev = D_forecv;
+ D_forecv->c_slnext = cv;
+ if (cv->c_slnext)
+ cv->c_slnext->c_slprev = cv;
+ cv->c_slorient = orient;
+ cv->c_slback = D_forecv->c_slback;
+
+ cv->c_xs = xs;
+ cv->c_xe = xe;
+ cv->c_ys = ys;
+ cv->c_ye = ye;
+ cv->c_xoff = 0;
+ cv->c_yoff = 0;
+ cv->c_display = display;
+ cv->c_vplist = 0;
+ cv->c_captev.type = EV_TIMEOUT;
+ cv->c_captev.data = (char *)cv;
+ cv->c_captev.handler = cv_winid_fn;
+
+ CanvasInitBlank(cv);
+ cv->c_lnext = 0;
+
+ cv->c_next = 0;
+
+ cv = cv->c_slback;
+ EqualizeCanvas(cv->c_slperp, 0);
+ ResizeCanvas(cv);
+ RecreateCanvasChain();
+ RethinkDisplayViewports();
+ ResizeLayersToCanvases();
+ return 0;
+}
+
+void
+RemCanvas()
+{
+ int ye;
+ struct canvas *cv;
+
+ debug("RemCanvas\n");
+ cv = D_forecv;
+ ye = cv->c_slback->c_ye;
+ if (cv->c_slorient == SLICE_UNKN)
+ return;
+ while (cv->c_slprev)
+ cv = cv->c_slprev;
+ if (!cv->c_slnext)
+ return;
+ if (!cv->c_slnext->c_slnext && cv->c_slback->c_slback)
+ {
+ /* two canvases in slice, kill perp node */
+ cv = D_forecv;
+ debug("deleting perp node\n");
+ FreePerp(cv->c_slprev ? cv->c_slprev : cv->c_slnext);
+ FreePerp(cv->c_slback);
+ }
+ /* free canvas */
+ cv = D_forecv;
+ D_forecv = cv->c_slprev;
+ if (!D_forecv)
+ D_forecv = cv->c_slnext;
+ FreeCanvas(cv);
+
+ cv = D_forecv;
+ while (D_forecv->c_slperp)
+ D_forecv = D_forecv->c_slperp;
+
+ /* if only one canvas left, set orient back to unknown */
+ if (!cv->c_slnext && !cv->c_slprev && !cv->c_slback->c_slback && !cv->c_slperp)
+ {
+ cv->c_slorient = SLICE_UNKN;
+ if (!captionalways)
+ cv->c_slback->c_ye = ++ye; /* caption line no longer needed */
+ }
+ cv = cv->c_slback;
+ EqualizeCanvas(cv->c_slperp, 0);
+ ResizeCanvas(cv);
+
+ D_fore = Layer2Window(D_forecv->c_layer);
+ flayer = D_forecv->c_layer;
+
+ RecreateCanvasChain();
+ RethinkDisplayViewports();
+ ResizeLayersToCanvases();
+}
+
+void
+OneCanvas()
+{
+ struct canvas *cv = D_forecv, *ocv = 0;
+
+ if (cv->c_slprev)
+ {
+ ocv = cv->c_slprev;
+ cv->c_slprev->c_slnext = cv->c_slnext;
+ }
+ if (cv->c_slnext)
+ {
+ ocv = cv->c_slnext;
+ cv->c_slnext->c_slprev = cv->c_slprev;
+ }
+ if (!ocv)
+ return;
+ if (cv->c_slback && cv->c_slback->c_slperp == cv)
+ cv->c_slback->c_slperp = ocv;
+ cv->c_slorient = SLICE_UNKN;
+ while (D_canvas.c_slperp)
+ FreeCanvas(D_canvas.c_slperp);
+ cv = D_forecv;
+ D_canvas.c_slperp = cv;
+ cv->c_slback = &D_canvas;
+ cv->c_slnext = 0;
+ cv->c_slprev = 0;
+ ASSERT(!cv->c_slperp);
+ if (!captionalways)
+ D_canvas.c_ye++; /* caption line no longer needed */
+ ResizeCanvas(&D_canvas);
+ RecreateCanvasChain();
+ RethinkDisplayViewports();
+ ResizeLayersToCanvases();
+}
+
+void
+DupLayoutCv(cvf, cvt, save)
+struct canvas *cvf, *cvt;
+int save;
+{
+ while(cvf)
+ {
+ cvt->c_slorient = cvf->c_slorient;
+ cvt->c_slweight = cvf->c_slweight;
+ if (cvf == D_forecv)
+ D_forecv = cvt;
+ if (!save)
+ {
+ cvt->c_display = display;
+ if (!cvf->c_slperp)
+ {
+ cvt->c_captev.type = EV_TIMEOUT;
+ cvt->c_captev.data = (char *)cvt;
+ cvt->c_captev.handler = cv_winid_fn;
+ cvt->c_blank.l_cvlist = 0;
+ cvt->c_blank.l_layfn = &BlankLf;
+ cvt->c_blank.l_bottom = &cvt->c_blank;
+ }
+ cvt->c_layer = cvf->c_layer;
+ }
+ else
+ {
+ struct win *p = cvf->c_layer ? Layer2Window(cvf->c_layer) : 0;
+ cvt->c_layer = p ? &p->w_layer : 0;
+ }
+ if (cvf->c_slperp)
+ {
+ cvt->c_slperp = (struct canvas *)calloc(1, sizeof(struct canvas));
+ cvt->c_slperp->c_slback = cvt;
+ CanvasInitBlank(cvt->c_slperp);
+ DupLayoutCv(cvf->c_slperp, cvt->c_slperp, save);
+ }
+ if (cvf->c_slnext)
+ {
+ cvt->c_slnext = (struct canvas *)calloc(1, sizeof(struct canvas));
+ cvt->c_slnext->c_slprev = cvt;
+ cvt->c_slnext->c_slback = cvt->c_slback;
+ CanvasInitBlank(cvt->c_slnext);
+ }
+ cvf = cvf->c_slnext;
+ cvt = cvt->c_slnext;
+ }
+}
+
+void
+PutWindowCv(cv)
+struct canvas *cv;
+{
+ struct win *p;
+ for (; cv; cv = cv->c_slnext)
+ {
+ if (cv->c_slperp)
+ {
+ PutWindowCv(cv->c_slperp);
+ continue;
+ }
+ p = cv->c_layer ? (struct win *)cv->c_layer->l_data : 0;
+ cv->c_layer = 0;
+ SetCanvasWindow(cv, p);
+ }
+}
+
diff --git a/canvas.h b/canvas.h
new file mode 100644
index 0000000..6aeb3d8
--- /dev/null
+++ b/canvas.h
@@ -0,0 +1,101 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+#ifndef SCREEN_CANVAS_H
+#define SCREEN_CANVAS_H
+
+#define SLICE_UNKN 0
+#define SLICE_VERT (1 << 0)
+#define SLICE_HORI (1 << 1)
+
+#define SLICE_THIS (1 << 2) /* used in equal test */
+#define SLICE_GLOBAL (1 << 3)
+
+struct canvas
+{
+ struct canvas *c_next; /* next canvas on display */
+ struct display *c_display; /* back pointer to display */
+
+ struct canvas *c_slnext; /* next canvas in display slice */
+ struct canvas *c_slprev; /* prev canvas in display slice */
+ struct canvas *c_slperp; /* perpendicular slice */
+ struct canvas *c_slback; /* perpendicular slice back pointer */
+ int c_slorient; /* our slice orientation */
+ int c_slweight; /* size ratio */
+
+ struct viewport *c_vplist;
+ struct layer *c_layer; /* layer on this canvas */
+ struct canvas *c_lnext; /* next canvas that displays layer */
+ struct layer c_blank; /* bottom layer, always blank */
+ int c_xoff; /* canvas x offset on display */
+ int c_yoff; /* canvas y offset on display */
+ int c_xs;
+ int c_xe;
+ int c_ys;
+ int c_ye;
+ struct event c_captev; /* caption changed event */
+};
+
+struct win; /* forward declaration */
+
+extern void SetCanvasWindow __P((struct canvas *, struct win *));
+extern void SetForeCanvas __P((struct display *, struct canvas *));
+extern struct canvas *FindCanvas __P((int, int));
+extern int MakeDefaultCanvas __P((void));
+extern int AddCanvas __P((int));
+extern void RemCanvas __P((void));
+extern void OneCanvas __P((void));
+extern void FreeCanvas __P((struct canvas *));
+extern void ResizeCanvas __P((struct canvas *));
+extern void RecreateCanvasChain __P((void));
+extern void RethinkViewportOffsets __P((struct canvas *));
+extern int CountCanvasPerp __P((struct canvas *));
+extern void EqualizeCanvas __P((struct canvas *, int));
+extern void DupLayoutCv __P((struct canvas *, struct canvas *, int));
+extern void PutWindowCv __P((struct canvas *));
+
+#define CV_CALL(cv, cmd) \
+{ \
+ struct display *olddisplay = display; \
+ struct layer *oldflayer = flayer; \
+ struct layer *l = cv->c_layer; \
+ struct canvas *cvlist = l->l_cvlist; \
+ struct canvas *cvlnext = cv->c_lnext; \
+ flayer = l; \
+ l->l_cvlist = cv; \
+ cv->c_lnext = 0; \
+ cmd; \
+ flayer = oldflayer; \
+ l->l_cvlist = cvlist; \
+ cv->c_lnext = cvlnext; \
+ display = olddisplay; \
+}
+
+#endif /* SCREEN_CANVAS_H */
+
diff --git a/comm.c b/comm.c
new file mode 100644
index 0000000..c11a5ae
--- /dev/null
+++ b/comm.c
@@ -0,0 +1,348 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+#ifdef HAVE_BRAILLE
+ * Modified by:
+ * Authors: Hadi Bargi Rangin bargi@dots.physics.orst.edu
+ * Bill Barry barryb@dots.physics.orst.edu
+ *
+ * Modifications Copyright (c) 1995 by
+ * Science Access Project, Oregon State University.
+#endif
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include "config.h"
+#include "os.h"
+#include "acls.h"
+#include "comm.h"
+
+#define bcopy :-( /* or include screen.h here */
+
+/* Must be in alpha order ! */
+
+struct comm comms[RC_LAST + 1] =
+{
+#ifdef MULTIUSER
+ { "acladd", ARGS_1234 },
+ { "aclchg", ARGS_23 },
+ { "acldel", ARGS_1 },
+ { "aclgrp", ARGS_12 },
+ { "aclumask", ARGS_1|ARGS_ORMORE },
+#endif
+ { "activity", ARGS_1 },
+#ifdef MULTIUSER
+ { "addacl", ARGS_1234 },
+#endif
+ { "allpartial", NEED_DISPLAY|ARGS_1 },
+ { "altscreen", ARGS_01 },
+ { "at", ARGS_2|ARGS_ORMORE },
+#ifdef COLOR
+ { "attrcolor", ARGS_12 },
+#endif
+ { "autodetach", ARGS_1 },
+#ifdef AUTO_NUKE
+ { "autonuke", NEED_DISPLAY|ARGS_1 },
+#endif
+ { "backtick", ARGS_1|ARGS_ORMORE },
+#ifdef COLOR
+ { "bce", NEED_FORE|ARGS_01 },
+#endif
+
+#ifdef HAVE_BRAILLE
+/* keywords for braille display (bd) */
+ { "bd_bc_down", ARGS_0 },
+ { "bd_bc_left", ARGS_0 },
+ { "bd_bc_right", ARGS_0 },
+ { "bd_bc_up", ARGS_0 },
+ { "bd_bell", ARGS_01 },
+ { "bd_braille_table", ARGS_01 },
+ { "bd_eightdot", ARGS_01 },
+ { "bd_info", ARGS_01 },
+ { "bd_link", ARGS_01 },
+ { "bd_lower_left", ARGS_0 },
+ { "bd_lower_right", ARGS_0 },
+ { "bd_ncrc", ARGS_01 },
+ { "bd_port", ARGS_01 },
+ { "bd_scroll", ARGS_01 },
+ { "bd_skip", ARGS_01 },
+ { "bd_start_braille", ARGS_01 },
+ { "bd_type", ARGS_01 },
+ { "bd_upper_left", ARGS_0 },
+ { "bd_upper_right", ARGS_0 },
+ { "bd_width", ARGS_01 },
+#endif
+
+ { "bell", ARGS_01 },
+ { "bell_msg", ARGS_01 },
+ { "bind", ARGS_1|ARGS_ORMORE },
+#ifdef MAPKEYS
+ { "bindkey", ARGS_0|ARGS_ORMORE },
+#endif
+ { "blanker", NEED_DISPLAY|ARGS_0},
+#ifdef BLANKER_PRG
+ { "blankerprg", ARGS_0|ARGS_ORMORE },
+#endif
+ { "break", NEED_FORE|ARGS_01 },
+ { "breaktype", NEED_FORE|ARGS_01 },
+#ifdef COPY_PASTE
+ { "bufferfile", ARGS_01 },
+#endif
+ { "bumpleft", NEED_FORE|ARGS_0 },
+ { "bumpright", NEED_FORE|ARGS_0 },
+ { "c1", NEED_FORE|ARGS_01 },
+ { "caption", ARGS_12 },
+#ifdef MULTIUSER
+ { "chacl", ARGS_23 },
+#endif
+ { "charset", NEED_FORE|ARGS_1 },
+ { "chdir", ARGS_01 },
+#ifdef DW_CHARS
+ { "cjkwidth", ARGS_01 },
+#endif
+ { "clear", NEED_FORE|ARGS_0 },
+ { "collapse", ARGS_0 },
+ { "colon", NEED_LAYER|ARGS_01 },
+ { "command", NEED_DISPLAY|ARGS_02 },
+#ifdef COPY_PASTE
+ { "compacthist", ARGS_01 },
+#endif
+ { "console", NEED_FORE|ARGS_01 },
+#ifdef COPY_PASTE
+ { "copy", NEED_FORE|NEED_DISPLAY|ARGS_0 },
+ { "crlf", ARGS_01 },
+#endif
+ { "debug", ARGS_01 },
+#ifdef AUTO_NUKE
+ { "defautonuke", ARGS_1 },
+#endif
+#ifdef COLOR
+ { "defbce", ARGS_1 },
+#endif
+ { "defbreaktype", ARGS_01 },
+ { "defc1", ARGS_1 },
+ { "defcharset", ARGS_01 },
+ { "defdynamictitle", ARGS_1 },
+#ifdef ENCODINGS
+ { "defencoding", ARGS_1 },
+#endif
+ { "defescape", ARGS_1 },
+ { "defflow", ARGS_12 },
+ { "defgr", ARGS_1 },
+ { "defhstatus", ARGS_01 },
+#ifdef ENCODINGS
+ { "defkanji", ARGS_1 },
+#endif
+ { "deflog", ARGS_1 },
+#if defined(UTMPOK) && defined(LOGOUTOK)
+ { "deflogin", ARGS_1 },
+#endif
+ { "defmode", ARGS_1 },
+ { "defmonitor", ARGS_1 },
+ { "defmousetrack", ARGS_1 },
+#ifdef MULTI
+ { "defnonblock", ARGS_1 },
+#endif
+ { "defobuflimit", ARGS_1 },
+#ifdef COPY_PASTE
+ { "defscrollback", ARGS_1 },
+#endif
+ { "defshell", ARGS_1 },
+ { "defsilence", ARGS_1 },
+ { "defslowpaste", ARGS_1 },
+#ifdef UTF8
+ { "defutf8", ARGS_1 },
+#endif
+ { "defwrap", ARGS_1 },
+ { "defwritelock", ARGS_1 },
+#ifdef DETACH
+ { "detach", NEED_DISPLAY|ARGS_01 },
+#endif
+ { "digraph", NEED_LAYER|ARGS_012 },
+ { "dinfo", NEED_DISPLAY|ARGS_0 },
+ { "displays", NEED_LAYER|ARGS_0 },
+ { "dumptermcap", NEED_FORE|ARGS_0 },
+ { "dynamictitle", ARGS_1 },
+ { "echo", CAN_QUERY|ARGS_12 },
+#ifdef ENCODINGS
+ { "encoding", ARGS_12 },
+#endif
+ { "escape", ARGS_1 },
+ { "eval", ARGS_1|ARGS_ORMORE },
+#ifdef PSEUDOS
+ { "exec", ARGS_0|ARGS_ORMORE },
+#endif
+ { "fit", NEED_DISPLAY|ARGS_0 },
+ { "flow", NEED_FORE|ARGS_01 },
+ { "focus", NEED_DISPLAY|ARGS_01 },
+ { "focusminsize", ARGS_02 },
+ { "gr", NEED_FORE|ARGS_01 },
+ { "group", NEED_FORE|ARGS_01 },
+ { "hardcopy", NEED_FORE|ARGS_012 },
+ { "hardcopy_append", ARGS_1 },
+ { "hardcopydir", ARGS_01 },
+ { "hardstatus", ARGS_012 },
+ { "height", ARGS_0123 },
+ { "help", NEED_LAYER|ARGS_02 },
+#ifdef COPY_PASTE
+ { "history", NEED_DISPLAY|NEED_FORE|ARGS_0 },
+#endif
+ { "hstatus", NEED_FORE|ARGS_1 },
+ { "idle", ARGS_0|ARGS_ORMORE },
+ { "ignorecase", ARGS_01 },
+ { "info", CAN_QUERY|NEED_LAYER|ARGS_0 },
+#ifdef ENCODINGS
+ { "kanji", NEED_FORE|ARGS_12 },
+#endif
+ { "kill", NEED_FORE|ARGS_0 },
+ { "lastmsg", CAN_QUERY|NEED_DISPLAY|ARGS_0 },
+ { "layout", ARGS_1|ARGS_ORMORE},
+ { "license", NEED_LAYER|ARGS_0 },
+#ifdef LOCK
+ { "lockscreen", NEED_DISPLAY|ARGS_0 },
+#endif
+ { "log", NEED_FORE|ARGS_01 },
+ { "logfile", ARGS_012 },
+#if defined(UTMPOK) && defined(LOGOUTOK)
+ { "login", NEED_FORE|ARGS_01 },
+#endif
+ { "logtstamp", ARGS_012 },
+#ifdef MAPKEYS
+ { "mapdefault", NEED_DISPLAY|ARGS_0 },
+ { "mapnotnext", NEED_DISPLAY|ARGS_0 },
+ { "maptimeout", ARGS_01 },
+#endif
+#ifdef COPY_PASTE
+ { "markkeys", ARGS_1 },
+#endif
+ { "maxwin", ARGS_01 },
+ { "meta", NEED_LAYER|ARGS_0 },
+ { "monitor", NEED_FORE|ARGS_01 },
+ { "mousetrack", NEED_DISPLAY | ARGS_01 },
+ { "msgminwait", ARGS_1 },
+ { "msgwait", ARGS_1 },
+#ifdef MULTIUSER
+ { "multiuser", ARGS_1 },
+#endif
+ { "nethack", ARGS_1 },
+ { "next", ARGS_0 },
+#ifdef MULTI
+ { "nonblock", NEED_DISPLAY|ARGS_01 },
+#endif
+ { "number", CAN_QUERY|NEED_FORE|ARGS_01 },
+ { "obuflimit", NEED_DISPLAY|ARGS_01 },
+ { "only", NEED_DISPLAY|ARGS_0 },
+ { "other", ARGS_0 },
+ { "partial", NEED_FORE|ARGS_01 },
+#ifdef PASSWORD
+ { "password", ARGS_01 },
+#endif
+#ifdef COPY_PASTE
+ { "paste", NEED_LAYER|ARGS_012 },
+ { "pastefont", ARGS_01 },
+#endif
+ { "pow_break", NEED_FORE|ARGS_01 },
+#if defined(DETACH) && defined(POW_DETACH)
+ { "pow_detach", NEED_DISPLAY|ARGS_0 },
+ { "pow_detach_msg", ARGS_01 },
+#endif
+ { "prev", ARGS_0 },
+ { "printcmd", ARGS_01 },
+ { "process", NEED_DISPLAY|ARGS_01 },
+ { "quit", ARGS_0 },
+#ifdef COPY_PASTE
+ { "readbuf", ARGS_0123 },
+#endif
+ { "readreg", ARGS_0|ARGS_ORMORE },
+ { "redisplay", NEED_DISPLAY|ARGS_0 },
+ { "register", ARGS_24 },
+ { "remove", NEED_DISPLAY|ARGS_0 },
+#ifdef COPY_PASTE
+ { "removebuf", ARGS_0 },
+#endif
+ { "rendition", ARGS_23 },
+ { "reset", NEED_FORE|ARGS_0 },
+ { "resize", NEED_DISPLAY|ARGS_0|ARGS_ORMORE },
+ { "screen", ARGS_0|ARGS_ORMORE },
+#ifdef COPY_PASTE
+ { "scrollback", NEED_FORE|ARGS_1 },
+#endif
+ { "select", CAN_QUERY|ARGS_01 },
+ { "sessionname", ARGS_01 },
+ { "setenv", ARGS_012 },
+ { "setsid", ARGS_1 },
+ { "shell", ARGS_1 },
+ { "shelltitle", ARGS_1 },
+ { "silence", NEED_FORE|ARGS_01 },
+ { "silencewait", ARGS_1 },
+ { "sleep", ARGS_1 },
+ { "slowpaste", NEED_FORE|ARGS_01 },
+ { "sorendition", ARGS_012 },
+ { "sort", ARGS_0},
+ { "source", ARGS_1 },
+ { "split", NEED_DISPLAY|ARGS_01 },
+ { "startup_message", ARGS_1 },
+ { "stuff", NEED_LAYER|ARGS_012 },
+#ifdef MULTIUSER
+ { "su", NEED_DISPLAY|ARGS_012 },
+#endif
+#ifdef BSDJOBS
+ { "suspend", NEED_DISPLAY|ARGS_0 },
+#endif
+ { "term", ARGS_1 },
+ { "termcap", ARGS_23 },
+ { "termcapinfo", ARGS_23 },
+ { "terminfo", ARGS_23 },
+ { "time", CAN_QUERY|ARGS_01 },
+ { "title", CAN_QUERY|NEED_FORE|ARGS_01 },
+ { "umask", ARGS_1|ARGS_ORMORE },
+ { "unbindall", ARGS_0 },
+ { "unsetenv", ARGS_1 },
+#ifdef UTF8
+ { "utf8", NEED_FORE|ARGS_012 },
+#endif
+ { "vbell", ARGS_01 },
+ { "vbell_msg", ARGS_01 },
+ { "vbellwait", ARGS_1 },
+ { "verbose", ARGS_01 },
+ { "version", ARGS_0 },
+ { "wall", NEED_DISPLAY|ARGS_1},
+ { "width", ARGS_0123 },
+ { "windowlist", ARGS_012 },
+ { "windows", CAN_QUERY|ARGS_01 },
+ { "wrap", NEED_FORE|ARGS_01 },
+#ifdef COPY_PASTE
+ { "writebuf", ARGS_0123 },
+#endif
+ { "writelock", NEED_FORE|ARGS_01 },
+ { "xoff", NEED_LAYER|ARGS_0 },
+ { "xon", NEED_LAYER|ARGS_0 },
+#ifdef ZMODEM
+ { "zmodem", ARGS_012 },
+#endif
+ { "zombie", ARGS_012 },
+ { "zombie_timeout", ARGS_1 }
+};
diff --git a/comm.sh b/comm.sh
new file mode 100644
index 0000000..ad2210c
--- /dev/null
+++ b/comm.sh
@@ -0,0 +1,96 @@
+#! /bin/sh
+
+if test -z "$AWK"; then
+ AWK=awk
+fi
+if test -z "$CC"; then
+ CC=cc
+fi
+if test -z "$srcdir"; then
+ srcdir=.
+fi
+
+LC_ALL=C
+export LC_ALL
+
+rm -f comm.h
+cat << EOF > comm.h
+/*
+ * This file is automagically created from comm.c -- DO NOT EDIT
+ */
+
+struct comm
+{
+ char *name;
+ int flags;
+#ifdef MULTIUSER
+ AclBits userbits[ACL_BITS_PER_CMD];
+#endif
+};
+
+#define ARGS_MASK (3)
+
+#define ARGS_0 (0)
+#define ARGS_1 (1)
+#define ARGS_2 (2)
+#define ARGS_3 (3)
+
+#define ARGS_PLUS1 (1<<2)
+#define ARGS_PLUS2 (1<<3)
+#define ARGS_PLUS3 (1<<4)
+#define ARGS_ORMORE (1<<5)
+
+#define NEED_FORE (1<<6) /* this command needs a fore window */
+#define NEED_DISPLAY (1<<7) /* this command needs a display */
+#define NEED_LAYER (1<<8) /* this command needs a layer */
+#define CAN_QUERY (1<<9) /* this command can be queried, i.e. used with -Q to
+ get back a result to stdout */
+
+#define ARGS_01 (ARGS_0 | ARGS_PLUS1)
+#define ARGS_02 (ARGS_0 | ARGS_PLUS2)
+#define ARGS_12 (ARGS_1 | ARGS_PLUS1)
+#define ARGS_23 (ARGS_2 | ARGS_PLUS1)
+#define ARGS_24 (ARGS_2 | ARGS_PLUS2)
+#define ARGS_34 (ARGS_3 | ARGS_PLUS1)
+#define ARGS_012 (ARGS_0 | ARGS_PLUS1 | ARGS_PLUS2)
+#define ARGS_0123 (ARGS_0 | ARGS_PLUS1 | ARGS_PLUS2 | ARGS_PLUS3)
+#define ARGS_123 (ARGS_1 | ARGS_PLUS1 | ARGS_PLUS2)
+#define ARGS_124 (ARGS_1 | ARGS_PLUS1 | ARGS_PLUS3)
+#define ARGS_1234 (ARGS_1 | ARGS_PLUS1 | ARGS_PLUS2 | ARGS_PLUS3)
+
+struct action
+{
+ int nr;
+ char **args;
+ int *argl;
+ int quiet; /* Suppress (currently unused)
+ 0x01 - Error message
+ 0x02 - Normal message
+ */
+};
+
+#define RC_ILLEGAL -1
+
+EOF
+$AWK < ${srcdir}/comm.c >> comm.h '
+/^ [{] ".*/ { if (old > $2) {
+ printf("***ERROR: %s <= %s !!!\n\n", $2, old);
+ exit 1;
+ }
+ old = $2;
+ }
+'
+
+$CC -E -I. -I${srcdir} ${srcdir}/comm.c > comm.cpp
+sed < comm.cpp \
+ -n \
+ -e '/^ *{ "/y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \
+ -e '/^ *{ "/s/^ *{ "\([^"]*\)".*/\1/p' \
+| $AWK '
+/.*/ { printf "#define RC_%s %d\n",$0,i++;
+ }
+END { printf "\n#define RC_LAST %d\n",i-1;
+ }
+' >> comm.h
+chmod a-w comm.h
+rm -f comm.cpp
diff --git a/config.h.in b/config.h.in
new file mode 100644
index 0000000..cdb2b97
--- /dev/null
+++ b/config.h.in
@@ -0,0 +1,720 @@
+/* config.h.in. Generated from configure.ac by autoheader. */
+/* Copyright (c) 1993-2000
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+
+
+
+
+/**********************************************************************
+ *
+ * User Configuration Section
+ */
+
+/*
+ * Maximum of simultaneously allowed windows per screen session.
+ */
+#ifndef MAXWIN
+# define MAXWIN 100
+#endif
+
+/*
+ * Define SOCKDIR to be the directory to contain the named sockets
+ * screen creates. This should be in a common subdirectory, such as
+ * /usr/local or /tmp. It makes things a little more secure if you
+ * choose a directory which is not writable by everyone or where the
+ * "sticky" bit is on, but this isn't required.
+ * If SOCKDIR is not defined screen will put the named sockets in
+ * the user's home directory. Notice that this can cause you problems
+ * if some user's HOME directories are AFS- or NFS-mounted. Especially
+ * AFS is unlikely to support named sockets.
+ *
+ * Screen will name the subdirectories "S-$USER" (e.g /tmp/S-davison).
+ */
+#undef SOCKDIR
+
+/*
+ * Define this if the SOCKDIR is not shared between hosts.
+ */
+#define SOCKDIR_IS_LOCAL_TO_HOST
+
+/*
+ * Screen can look for the environment variable $SYSSCREENRC and -if it
+ * exists- load the file specified in that variable as global screenrc.
+ * If you want to enable this feature, define ALLOW_SYSSCREENRC to one (1).
+ * Otherwise ETCSCREENRC is always loaded.
+ */
+#define ALLOW_SYSSCREENRC 1
+
+/*
+ * Define CHECKLOGIN to force Screen users to enter their Unix password
+ * in addition to the screen password.
+ *
+ * Define NOSYSLOG if yo do not have logging facilities. Currently
+ * syslog() will be used to trace ``su'' commands only.
+ */
+#define CHECKLOGIN 1
+#undef NOSYSLOG
+
+
+/*
+ * define PTYMODE if you do not like the default of 0622, which allows
+ * public write to your pty.
+ * define PTYGROUP to some numerical group-id if you do not want the
+ * tty to be in "your" group.
+ * Note, screen is unable to change mode or group of the pty if it
+ * is not installed with sufficient privilege. (e.g. set-uid-root)
+ * define PTYROFS if the /dev/pty devices are mounted on a read-only
+ * filesystem so screen should not even attempt to set mode or group
+ * even if running as root (e.g. on TiVo).
+ */
+#undef PTYMODE
+#undef PTYGROUP
+#undef PTYROFS
+
+/*
+ * If screen is NOT installed set-uid root, screen can provide tty
+ * security by exclusively locking the ptys. While this keeps other
+ * users from opening your ptys, it also keeps your own subprocesses
+ * from being able to open /dev/tty. Define LOCKPTY to add this
+ * exclusive locking.
+ */
+#undef LOCKPTY
+
+/*
+ * If you'd rather see the status line on the first line of your
+ * terminal rather than the last, define TOPSTAT.
+ */
+#undef TOPSTAT
+
+/*
+ * define DETACH can detach a session. An absolute 'must'.
+ */
+#define DETACH
+
+/*
+ * here come the erlangen extensions to screen:
+ * define LOCK if you want to use a lock program for a screenlock.
+ * define PASSWORD for secure reattach of your screen.
+ * define COPY_PASTE to use the famous hacker's treasure zoo.
+ * define POW_DETACH to have a detach_and_logout key (requires DETACH).
+ * define REMOTE_DETACH (-d option) to move screen between terminals.
+ * define AUTO_NUKE to enable Tim MacKenzies clear screen nuking
+ * define PSEUDOS to allow window input/output filtering
+ * define MULTI to allow multiple attaches.
+ * define MULTIUSER to allow other users attach to your session
+ * (if they are in the acl, of course)
+ * define MAPKEYS to include input keyboard translation.
+ * define FONT to support ISO2022/alternet charset support
+ * define COLOR to include ansi color support. This may expose
+ * a bug in x11r6-color-xterm.
+ * define DW_CHARS to include support for double-width character
+ * sets.
+ * define ENCODINGS to include support for encodings like euc or big5.
+ * Needs FONT to work.
+ * define UTF8 if you want support for UTF-8 encoding.
+ * Needs FONT and ENCODINGS to work.
+ * define COLORS16 if you want 16 colors.
+ * Needs COLOR to work.
+ * define BUILTIN_TELNET to add telnet support to screen.
+ * Syntax: screen //telnet host [port]
+ * define RXVT_OSC if you want support for rxvts special
+ * change fgcolor/bgcolor/bgpicture sequences
+ */
+#undef SIMPLESCREEN
+#ifndef SIMPLESCREEN
+# define LOCK
+# define PASSWORD
+# define COPY_PASTE
+# define REMOTE_DETACH
+# define POW_DETACH
+# define AUTO_NUKE
+# define PSEUDOS
+# define MULTI
+# define MULTIUSER
+# define MAPKEYS
+# define COLOR
+# define FONT
+# define DW_CHARS
+# define ENCODINGS
+# define UTF8
+# define COLORS16
+# define ZMODEM
+# define BLANKER_PRG
+#endif /* SIMPLESCREEN */
+
+#undef BUILTIN_TELNET
+#undef RXVT_OSC
+#undef COLORS256
+
+
+/*
+ * If you have a braille display you should define HAVE_BRAILLE.
+ * The code inside #ifdef HAVE_BRAILLE was contributed by Hadi Bargi
+ * Rangin (bargi@dots.physics.orst.edu).
+ * WARNING: this is more or less unsupported code, it may be full of
+ * bugs leading to security holes, enable at your own risk!
+ */
+#undef HAVE_BRAILLE
+
+
+/*
+ * As error messages are mostly meaningless to the user, we
+ * try to throw out phrases that are somewhat more familiar
+ * to ...well, at least familiar to us NetHack players.
+ */
+#ifndef NONETHACK
+# define NETHACK
+#endif /* NONETHACK */
+
+/*
+ * If screen is installed with permissions to update /etc/utmp (such
+ * as if it is installed set-uid root), define UTMPOK.
+ */
+#define UTMPOK
+
+/* Set LOGINDEFAULT to one (1)
+ * if you want entries added to /etc/utmp by default, else set it to
+ * zero (0).
+ * LOGINDEFAULT will be one (1) whenever LOGOUTOK is undefined!
+ */
+#define LOGINDEFAULT 1
+
+/* Set LOGOUTOK to one (1)
+ * if you want the user to be able to log her/his windows out.
+ * (Meaning: They are there, but not visible in /etc/utmp).
+ * Disabling this feature only makes sense if you have a secure /etc/utmp
+ * database.
+ * Negative examples: suns usually have a world writable utmp file,
+ * xterm will run perfectly without s-bit.
+ *
+ * If LOGOUTOK is undefined and UTMPOK is defined, all windows are
+ * initially and permanently logged in.
+ *
+ * Set CAREFULUTMP to one (1) if you want that users have at least one
+ * window per screen session logged in.
+ */
+#define LOGOUTOK 1
+#undef CAREFULUTMP
+
+
+/*
+ * If UTMPOK is defined and your system (incorrectly) counts logins by
+ * counting non-null entries in /etc/utmp (instead of counting non-null
+ * entries with no hostname that are not on a pseudo tty), define USRLIMIT
+ * to have screen put an upper-limit on the number of entries to write
+ * into /etc/utmp. This helps to keep you from exceeding a limited-user
+ * license.
+ */
+#undef USRLIMIT
+
+/*
+ * both must be defined if you want to favor tcsendbreak over
+ * other calls to generate a break condition on serial lines.
+ * (Do not bother, if you are not using plain tty windows.)
+ */
+#define POSIX_HAS_A_GOOD_TCSENDBREAK
+#define SUNOS4_AND_WE_TRUST_TCSENDBREAK
+
+/*
+ * to lower the interrupt load on the host machine, you may want to
+ * adjust the VMIN and VTIME settings used for plain tty windows.
+ * See the termio(4) manual page (Non-Canonical Mode Input Processing)
+ * for details.
+ * if undefined, VMIN=1, VTIME=0 is used as a default - this gives you
+ * best user responsiveness, but highest interrupt frequency.
+ * (Do not bother, if you are not using plain tty windows.)
+ */
+#define TTYVMIN 100
+#define TTYVTIME 2
+
+/*
+ * looks like the above values are ignored by setting FNDELAY.
+ * This is default for all pty/ttys, you may disable it for
+ * ttys here. After playing with it for a while, one may find out
+ * that this feature may cause screen to lock up.
+ */
+#ifdef bsdi
+# define TTY_DISABLE_FNBLOCK /* select barfs without it ... */
+#endif
+
+
+/*
+ * Some terminals, e.g. Wyse 120, use a bitfield to select attributes.
+ * This doesn't work with the standard so/ul/m? terminal entries,
+ * because they will cancel each other out.
+ * On TERMINFO machines, "sa" (sgr) may work. If you want screen
+ * to switch attributes only with sgr, define USE_SGR.
+ * This is *not* recomended, do this only if you must.
+ */
+#undef USE_SGR
+
+
+/*
+ * Define USE_LOCALE if you want screen to use the locale names
+ * for the name of the month and day of the week.
+ */
+#define USE_LOCALE
+
+/*
+ * Define USE_PAM if your system supports PAM (Pluggable Authentication
+ * Modules) and you want screen to use it instead of calling crypt().
+ * (You may also need to add -lpam to LIBS in the Makefile.)
+ */
+#undef USE_PAM
+
+/*
+ * Define CHECK_SCREEN_W if you want screen to set TERM to screen-w
+ * if the terminal width is greater than 131 columns. No longer needed
+ * on modern systems which use $COLUMNS or the tty settings instead.
+ */
+#undef CHECK_SCREEN_W
+
+/**********************************************************************
+ *
+ * End of User Configuration Section
+ *
+ * Rest of this file is modified by 'configure'
+ * Change at your own risk!
+ *
+ */
+
+/*
+ * Some defines to identify special unix variants
+ */
+#ifndef SVR4
+#undef SVR4
+#endif
+
+/* #ifndef __osf__ */
+#ifndef MIPS
+#undef MIPS
+#endif
+/* #endif */
+
+#ifndef OSX
+#undef OSX
+#endif
+
+#ifndef ISC
+#undef ISC
+#endif
+
+#ifndef sysV68
+#undef sysV68
+#endif
+
+#ifndef _POSIX_SOURCE
+#undef _POSIX_SOURCE
+#endif
+
+/*
+ * Define POSIX if your system supports IEEE Std 1003.1-1988 (POSIX).
+ */
+#undef POSIX
+
+/*
+ * Define BSDJOBS if you have BSD-style job control (both process
+ * groups and a tty that deals correctly with them).
+ */
+#undef BSDJOBS
+
+/*
+ * Define TERMIO if you have struct termio instead of struct sgttyb.
+ * This is usually the case for SVID systems, where BSD uses sgttyb.
+ * POSIX systems should define this anyway, even though they use
+ * struct termios.
+ */
+#undef TERMIO
+
+/*
+ * Define CYTERMIO if you have cyrillic termio modes.
+ */
+#undef CYTERMIO
+
+/*
+ * Define TERMINFO if your machine emulates the termcap routines
+ * with the terminfo database.
+ * Thus the .screenrc file is parsed for
+ * the command 'terminfo' and not 'termcap'.
+ */
+#undef TERMINFO
+
+/*
+ * If your library does not define ospeed, define this.
+ */
+#undef NEED_OSPEED
+
+/*
+ * Define SYSV if your machine is SYSV complient (Sys V, HPUX, A/UX)
+ */
+#ifndef SYSV
+#undef SYSV
+#endif
+
+/*
+ * Define SIGVOID if your signal handlers return void. On older
+ * systems, signal returns int, but on newer ones, it returns void.
+ */
+#undef SIGVOID
+
+/*
+ * Define USESIGSET if you have sigset for BSD 4.1 reliable signals.
+ */
+#undef USESIGSET
+
+/*
+ * Define SYSVSIGS if signal handlers must be reinstalled after
+ * they have been called.
+ */
+#undef SYSVSIGS
+
+/*
+ * Define BSDWAIT if your system defines a 'union wait' in <sys/wait.h>
+ *
+ * Only allow BSDWAIT i.e. wait3 on nonposix systems, since
+ * posix implies wait(3) and waitpid(3). vdlinden@fwi.uva.nl
+ *
+ */
+#ifndef POSIX
+#undef BSDWAIT
+#endif
+
+/*
+ * On RISCOS we prefer wait2() over wait3(). rouilj@sni-usa.com
+ */
+#ifdef BSDWAIT
+#undef USE_WAIT2
+#endif
+
+/*
+ * If your system has getutent(), pututline(), etc. to write to the
+ * utmp file, define GETUTENT.
+ */
+#undef GETUTENT
+
+/*
+ * Define UTHOST if the utmp file has a host field.
+ */
+#undef UTHOST
+
+/*
+ * Define if you have the utempter utmp helper program
+ */
+#undef HAVE_UTEMPTER
+
+/*
+ * If ttyslot() breaks getlogin() by returning indexes to utmp entries
+ * of type DEAD_PROCESS, then our getlogin() replacement should be
+ * selected by defining BUGGYGETLOGIN.
+ */
+#undef BUGGYGETLOGIN
+
+/*
+ * If your system has the calls setreuid() and setregid(),
+ * define HAVE_SETREUID. Otherwise screen will use a forked process to
+ * safely create output files without retaining any special privileges.
+ */
+#undef HAVE_SETRESUID
+#undef HAVE_SETREUID
+
+/*
+ * If your system supports BSD4.4's seteuid() and setegid(), define
+ * HAVE_SETEUID.
+ */
+#undef HAVE_SETEUID
+
+/*
+ * execvpe is now defined in some systems.
+ */
+#undef HAVE_EXECVPE
+
+/*
+ * If you want the "time" command to display the current load average
+ * define LOADAV. Maybe you must install screen with the needed
+ * privileges to read /dev/kmem.
+ * Note that NLIST_ stuff is only checked, when getloadavg() is not available.
+ */
+#undef LOADAV
+
+#undef LOADAV_NUM
+#undef LOADAV_TYPE
+#undef LOADAV_SCALE
+#undef LOADAV_GETLOADAVG
+#undef LOADAV_UNIX
+#undef LOADAV_AVENRUN
+#undef LOADAV_USE_NLIST64
+
+#undef NLIST_DECLARED
+#undef NLIST_STRUCT
+#undef NLIST_NAME_UNION
+
+/*
+ * If your system has the new format /etc/ttys (like 4.3 BSD) and the
+ * getttyent(3) library functions, define GETTTYENT.
+ */
+#undef GETTTYENT
+
+/*
+ * Define USEBCOPY if the bcopy/memcpy from your system's C library
+ * supports the overlapping of source and destination blocks. When
+ * undefined, screen uses its own (probably slower) version of bcopy().
+ *
+ * SYSV machines may have a working memcpy() -- Oh, this is
+ * quite unlikely. Tell me if you see one.
+ * "But then, memmove() should work, if at all available" he thought...
+ * Boing, never say "works everywhere" unless you checked SCO UNIX.
+ * Their memove fails the test in the configure script. Sigh. (Juergen)
+ */
+#undef USEBCOPY
+#undef USEMEMCPY
+#undef USEMEMMOVE
+
+/*
+ * If your system has vsprintf() and requires the use of the macros in
+ * "varargs.h" to use functions with variable arguments,
+ * define USEVARARGS.
+ */
+#undef USEVARARGS
+
+/*
+ * If the select return value doesn't treat a descriptor that is
+ * usable for reading and writing as two hits, define SELECT_BROKEN.
+ */
+#undef SELECT_BROKEN
+
+/*
+ * Define this if your system exits select() immediatly if a pipe is
+ * opened read-only and no writer has opened it.
+ */
+#undef BROKEN_PIPE
+
+/*
+ * Define this if the unix-domain socket implementation doesn't
+ * create a socket in the filesystem.
+ */
+#undef SOCK_NOT_IN_FS
+
+/*
+ * If your system has setenv() and unsetenv() define USESETENV
+ */
+#undef USESETENV
+
+/*
+ * If setenv() takes 3 arguments define HAVE_SETENV_3
+ */
+#undef HAVE_SETENV_3
+
+/*
+ * If setenv() takes 2 arguments define HAVE_SETENV_2
+ */
+#undef HAVE_SETENV_2
+
+/*
+ * If your system does not come with a setenv()/putenv()/getenv()
+ * functions, you may bring in our own code by defining NEEDPUTENV.
+ */
+#undef NEEDPUTENV
+
+/*
+ * If the passwords are stored in a shadow file and you want the
+ * builtin lock to work properly, define SHADOWPW.
+ */
+#undef SHADOWPW
+
+/*
+ * define HAVE_NL_LANGINFO if your system has the nl_langinfo() call
+ * and <langinfo.h> defines CODESET.
+ */
+#undef HAVE_NL_LANGINFO
+
+/*
+ * Newer versions of Solaris include fdwalk, which can greatly improve
+ * the startup time of screen; otherwise screen spends a lot of time
+ * closing file descriptors.
+ */
+#undef HAVE_FDWALK
+
+/*
+ * define HAVE_DEV_PTC if you have a /dev/ptc character special
+ * device.
+ */
+#undef HAVE_DEV_PTC
+
+/*
+ * define HAVE_SVR4_PTYS if you have a /dev/ptmx character special
+ * device and support the ptsname(), grantpt(), unlockpt() functions.
+ */
+#undef HAVE_SVR4_PTYS
+
+/*
+ * define PTYRANGE0 and or PTYRANGE1 if you want to adapt screen
+ * to unusual environments. E.g. For SunOs the defaults are "qpr" and
+ * "0123456789abcdef". For SunOs 4.1.2
+ * #define PTYRANGE0 "pqrstuvwxyzPQRST"
+ * is recommended by Dan Jacobson.
+ */
+#undef PTYRANGE0
+#undef PTYRANGE1
+
+
+/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
+ */
+#undef HAVE_DIRENT_H
+
+/* Define to 1 if you have the `fchmod' function. */
+#undef HAVE_FCHMOD
+
+/* Define to 1 if you have the `fchown' function. */
+#undef HAVE_FCHOWN
+
+/* Define to 1 if you have the `getcwd' function. */
+#undef HAVE_GETCWD
+
+/* Define to 1 if you have the `getpt' function. */
+#undef HAVE_GETPT
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you support file names longer than 14 characters. */
+#undef HAVE_LONG_FILE_NAMES
+
+/* Define to 1 if you have the `lstat' function. */
+#undef HAVE_LSTAT
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
+#undef HAVE_NDIR_H
+
+/* Define to 1 if you have the `openpty' function. */
+#undef HAVE_OPENPTY
+
+/* Define to 1 if you have the `rename' function. */
+#undef HAVE_RENAME
+
+/* Define to 1 if you have the `setlocale' function. */
+#undef HAVE_SETLOCALE
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the `strerror' function. */
+#undef HAVE_STRERROR
+
+/* Define to 1 if you have the `strftime' function. */
+#undef HAVE_STRFTIME
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the <stropts.h> header file. */
+#undef HAVE_STROPTS_H
+
+/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
+ */
+#undef HAVE_SYS_DIR_H
+
+/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
+ */
+#undef HAVE_SYS_NDIR_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Define to 1 if you have the `utimes' function. */
+#undef HAVE_UTIMES
+
+/* Define to 1 if you have the `vsnprintf' function. */
+#undef HAVE_VSNPRINTF
+
+/* Define to 1 if you have the `_exit' function. */
+#undef HAVE__EXIT
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the home page for this package. */
+#undef PACKAGE_URL
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
+/* Enable extensions on AIX 3, Interix. */
+#ifndef _ALL_SOURCE
+# undef _ALL_SOURCE
+#endif
+/* Enable GNU extensions on systems that have them. */
+#ifndef _GNU_SOURCE
+# undef _GNU_SOURCE
+#endif
+/* Enable threading extensions on Solaris. */
+#ifndef _POSIX_PTHREAD_SEMANTICS
+# undef _POSIX_PTHREAD_SEMANTICS
+#endif
+/* Enable extensions on HP NonStop. */
+#ifndef _TANDEM_SOURCE
+# undef _TANDEM_SOURCE
+#endif
+/* Enable general extensions on Solaris. */
+#ifndef __EXTENSIONS__
+# undef __EXTENSIONS__
+#endif
+
+
+/* Define to 1 if on MINIX. */
+#undef _MINIX
+
+/* Define to 2 if the system does not provide POSIX.1 features except with
+ this defined. */
+#undef _POSIX_1_SOURCE
+
+/* Define to 1 if you need to in order for `stat' and other things to work. */
+#undef _POSIX_SOURCE
diff --git a/configure b/configure
new file mode 100755
index 0000000..7817336
--- /dev/null
+++ b/configure
@@ -0,0 +1,8034 @@
+#! /bin/sh
+# From configure.ac Revision.
+# Guess values for system-dependent variables and create Makefiles.
+# Generated by GNU Autoconf 2.69.
+#
+#
+# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
+#
+#
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+ emulate sh
+ NULLCMD=:
+ # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+ # is contrary to our usage. Disable this feature.
+ alias -g '${1+"$@"}'='"$@"'
+ setopt NO_GLOB_SUBST
+else
+ case `(set -o) 2>/dev/null` in #(
+ *posix*) :
+ set -o posix ;; #(
+ *) :
+ ;;
+esac
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+ as_echo='print -r --'
+ as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+ as_echo='printf %s\n'
+ as_echo_n='printf %s'
+else
+ if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+ as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+ as_echo_n='/usr/ucb/echo -n'
+ else
+ as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+ as_echo_n_body='eval
+ arg=$1;
+ case $arg in #(
+ *"$as_nl"*)
+ expr "X$arg" : "X\\(.*\\)$as_nl";
+ arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+ esac;
+ expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+ '
+ export as_echo_n_body
+ as_echo_n='sh -c $as_echo_n_body as_echo'
+ fi
+ export as_echo_body
+ as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+ PATH_SEPARATOR=:
+ (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+ (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+ PATH_SEPARATOR=';'
+ }
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order. Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" "" $as_nl"
+
+# Find who we are. Look in the path if we contain no directory separator.
+as_myself=
+case $0 in #((
+ *[\\/]* ) as_myself=$0 ;;
+ *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+ done
+IFS=$as_save_IFS
+
+ ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+ as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+ $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+ exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there. '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+# Use a proper internal environment variable to ensure we don't fall
+ # into an infinite loop, continuously re-executing ourselves.
+ if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then
+ _as_can_reexec=no; export _as_can_reexec;
+ # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+ *v*x* | *x*v* ) as_opts=-vx ;;
+ *v* ) as_opts=-v ;;
+ *x* ) as_opts=-x ;;
+ * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+as_fn_exit 255
+ fi
+ # We don't want this to propagate to other subprocesses.
+ { _as_can_reexec=; unset _as_can_reexec;}
+if test "x$CONFIG_SHELL" = x; then
+ as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
+ emulate sh
+ NULLCMD=:
+ # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which
+ # is contrary to our usage. Disable this feature.
+ alias -g '\${1+\"\$@\"}'='\"\$@\"'
+ setopt NO_GLOB_SUBST
+else
+ case \`(set -o) 2>/dev/null\` in #(
+ *posix*) :
+ set -o posix ;; #(
+ *) :
+ ;;
+esac
+fi
+"
+ as_required="as_fn_return () { (exit \$1); }
+as_fn_success () { as_fn_return 0; }
+as_fn_failure () { as_fn_return 1; }
+as_fn_ret_success () { return 0; }
+as_fn_ret_failure () { return 1; }
+
+exitcode=0
+as_fn_success || { exitcode=1; echo as_fn_success failed.; }
+as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }
+as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }
+as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }
+if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
+
+else
+ exitcode=1; echo positional parameters were not saved.
+fi
+test x\$exitcode = x0 || exit 1
+test -x / || exit 1"
+ as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
+ as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
+ eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
+ test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1
+test \$(( 1 + 1 )) = 2 || exit 1"
+ if (eval "$as_required") 2>/dev/null; then :
+ as_have_required=yes
+else
+ as_have_required=no
+fi
+ if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then :
+
+else
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_found=false
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ as_found=:
+ case $as_dir in #(
+ /*)
+ for as_base in sh bash ksh sh5; do
+ # Try only shells that exist, to save several forks.
+ as_shell=$as_dir/$as_base
+ if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
+ { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then :
+ CONFIG_SHELL=$as_shell as_have_required=yes
+ if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then :
+ break 2
+fi
+fi
+ done;;
+ esac
+ as_found=false
+done
+$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
+ { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then :
+ CONFIG_SHELL=$SHELL as_have_required=yes
+fi; }
+IFS=$as_save_IFS
+
+
+ if test "x$CONFIG_SHELL" != x; then :
+ export CONFIG_SHELL
+ # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+ *v*x* | *x*v* ) as_opts=-vx ;;
+ *v* ) as_opts=-v ;;
+ *x* ) as_opts=-x ;;
+ * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+exit 255
+fi
+
+ if test x$as_have_required = xno; then :
+ $as_echo "$0: This script requires a shell more modern than all"
+ $as_echo "$0: the shells that I found on your system."
+ if test x${ZSH_VERSION+set} = xset ; then
+ $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should"
+ $as_echo "$0: be upgraded to zsh 4.3.4 or later."
+ else
+ $as_echo "$0: Please tell bug-autoconf@gnu.org about your system,
+$0: including any error possibly output before this
+$0: message. Then install a modern shell, or manually run
+$0: the script under such a shell if you do have one."
+ fi
+ exit 1
+fi
+fi
+fi
+SHELL=${CONFIG_SHELL-/bin/sh}
+export SHELL
+# Unset more variables known to interfere with behavior of common tools.
+CLICOLOR_FORCE= GREP_OPTIONS=
+unset CLICOLOR_FORCE GREP_OPTIONS
+
+## --------------------- ##
+## M4sh Shell Functions. ##
+## --------------------- ##
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+ { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+ return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+ set +e
+ as_fn_set_status $1
+ exit $1
+} # as_fn_exit
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
+ case $as_dir in #(
+ -*) as_dir=./$as_dir;;
+ esac
+ test -d "$as_dir" || eval $as_mkdir_p || {
+ as_dirs=
+ while :; do
+ case $as_dir in #(
+ *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+ *) as_qdir=$as_dir;;
+ esac
+ as_dirs="'$as_qdir' $as_dirs"
+ as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$as_dir" : 'X\(//\)[^/]' \| \
+ X"$as_dir" : 'X\(//\)$' \| \
+ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)[^/].*/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
+ test -d "$as_dir" && break
+ done
+ test -z "$as_dirs" || eval "mkdir $as_dirs"
+ } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+ test -f "$1" && test -x "$1"
+} # as_fn_executable_p
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+ eval 'as_fn_append ()
+ {
+ eval $1+=\$2
+ }'
+else
+ as_fn_append ()
+ {
+ eval $1=\$$1\$2
+ }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+ eval 'as_fn_arith ()
+ {
+ as_val=$(( $* ))
+ }'
+else
+ as_fn_arith ()
+ {
+ as_val=`expr "$@" || test $? -eq 1`
+ }
+fi # as_fn_arith
+
+
+# as_fn_error STATUS ERROR [LINENO LOG_FD]
+# ----------------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with STATUS, using 1 if that was 0.
+as_fn_error ()
+{
+ as_status=$1; test $as_status -eq 0 && as_status=1
+ if test "$4"; then
+ as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
+ fi
+ $as_echo "$as_me: error: $2" >&2
+ as_fn_exit $as_status
+} # as_fn_error
+
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+ test "X`expr 00001 : '.*\(...\)'`" = X001; then
+ as_expr=expr
+else
+ as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+ as_basename=basename
+else
+ as_basename=false
+fi
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+ as_dirname=dirname
+else
+ as_dirname=false
+fi
+
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+ X"$0" : 'X\(//\)$' \| \
+ X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+ sed '/^.*\/\([^/][^/]*\)\/*$/{
+ s//\1/
+ q
+ }
+ /^X\/\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\/\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
+
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+
+ as_lineno_1=$LINENO as_lineno_1a=$LINENO
+ as_lineno_2=$LINENO as_lineno_2a=$LINENO
+ eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" &&
+ test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || {
+ # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-)
+ sed -n '
+ p
+ /[$]LINENO/=
+ ' <$as_myself |
+ sed '
+ s/[$]LINENO.*/&-/
+ t lineno
+ b
+ :lineno
+ N
+ :loop
+ s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
+ t loop
+ s/-\n.*//
+ ' >$as_me.lineno &&
+ chmod +x "$as_me.lineno" ||
+ { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
+
+ # If we had to re-execute with $CONFIG_SHELL, we're ensured to have
+ # already done that, so ensure we don't try to do so again and fall
+ # in an infinite loop. This has already happened in practice.
+ _as_can_reexec=no; export _as_can_reexec
+ # Don't try to exec as it changes $[0], causing all sort of problems
+ # (the dirname of $[0] is not the place where we might find the
+ # original and so on. Autoconf is especially sensitive to this).
+ . "./$as_me.lineno"
+ # Exit status is that of the last command.
+ exit
+}
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in #(((((
+-n*)
+ case `echo 'xy\c'` in
+ *c*) ECHO_T=' ';; # ECHO_T is single tab character.
+ xy) ECHO_C='\c';;
+ *) echo `echo ksh88 bug on AIX 6.1` > /dev/null
+ ECHO_T=' ';;
+ esac;;
+*)
+ ECHO_N='-n';;
+esac
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+ rm -f conf$$.dir/conf$$.file
+else
+ rm -f conf$$.dir
+ mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+ if ln -s conf$$.file conf$$ 2>/dev/null; then
+ as_ln_s='ln -s'
+ # ... but there are two gotchas:
+ # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+ # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+ # In both cases, we have to default to `cp -pR'.
+ ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+ as_ln_s='cp -pR'
+ elif ln conf$$.file conf$$ 2>/dev/null; then
+ as_ln_s=ln
+ else
+ as_ln_s='cp -pR'
+ fi
+else
+ as_ln_s='cp -pR'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+if mkdir -p . 2>/dev/null; then
+ as_mkdir_p='mkdir -p "$as_dir"'
+else
+ test -d ./-p && rmdir ./-p
+ as_mkdir_p=false
+fi
+
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+test -n "$DJDIR" || exec 7<&0 </dev/null
+exec 6>&1
+
+# Name of the host.
+# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status,
+# so uname gets run too.
+ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
+
+#
+# Initializations.
+#
+ac_default_prefix=/usr/local
+ac_clean_files=
+ac_config_libobj_dir=.
+LIBOBJS=
+cross_compiling=no
+subdirs=
+MFLAGS=
+MAKEFLAGS=
+
+# Identity of this package.
+PACKAGE_NAME=
+PACKAGE_TARNAME=
+PACKAGE_VERSION=
+PACKAGE_STRING=
+PACKAGE_BUGREPORT=
+PACKAGE_URL=
+
+ac_unique_file="screen.c"
+# Factoring default headers for most tests.
+ac_includes_default="\
+#include <stdio.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
+#endif
+#ifdef HAVE_STRING_H
+# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
+# include <memory.h>
+# endif
+# include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif"
+
+ac_subst_vars='LTLIBOBJS
+LIBOBJS
+ETCSCREENRC
+XTERMPATH
+WRITEPATH
+INSTALL_DATA
+INSTALL_SCRIPT
+INSTALL_PROGRAM
+AWK
+EGREP
+GREP
+CPP
+OBJEXT
+EXEEXT
+ac_ct_CC
+CPPFLAGS
+LDFLAGS
+CFLAGS
+CC
+ac_prefix_program
+VERSION
+target_alias
+host_alias
+build_alias
+LIBS
+ECHO_T
+ECHO_N
+ECHO_C
+DEFS
+mandir
+localedir
+libdir
+psdir
+pdfdir
+dvidir
+htmldir
+infodir
+docdir
+oldincludedir
+includedir
+localstatedir
+sharedstatedir
+sysconfdir
+datadir
+datarootdir
+libexecdir
+sbindir
+bindir
+program_transform_name
+prefix
+exec_prefix
+PACKAGE_URL
+PACKAGE_BUGREPORT
+PACKAGE_STRING
+PACKAGE_VERSION
+PACKAGE_TARNAME
+PACKAGE_NAME
+PATH_SEPARATOR
+SHELL'
+ac_subst_files=''
+ac_user_opts='
+enable_option_checking
+enable_socket_dir
+with_socket_dir
+with_pty_mode
+with_pty_group
+enable_pam
+enable_use_locale
+enable_telnet
+enable_colors256
+enable_rxvt_osc
+with_sys_screenrc
+'
+ ac_precious_vars='build_alias
+host_alias
+target_alias
+CC
+CFLAGS
+LDFLAGS
+LIBS
+CPPFLAGS
+CPP'
+
+
+# Initialize some variables set by options.
+ac_init_help=
+ac_init_version=false
+ac_unrecognized_opts=
+ac_unrecognized_sep=
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+cache_file=/dev/null
+exec_prefix=NONE
+no_create=
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+verbose=
+x_includes=NONE
+x_libraries=NONE
+
+# Installation directory options.
+# These are left unexpanded so users can "make install exec_prefix=/foo"
+# and all the variables that are supposed to be based on exec_prefix
+# by default will actually change.
+# Use braces instead of parens because sh, perl, etc. also accept them.
+# (The list follows the same order as the GNU Coding Standards.)
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datarootdir='${prefix}/share'
+datadir='${datarootdir}'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+docdir='${datarootdir}/doc/${PACKAGE}'
+infodir='${datarootdir}/info'
+htmldir='${docdir}'
+dvidir='${docdir}'
+pdfdir='${docdir}'
+psdir='${docdir}'
+libdir='${exec_prefix}/lib'
+localedir='${datarootdir}/locale'
+mandir='${datarootdir}/man'
+
+ac_prev=
+ac_dashdash=
+for ac_option
+do
+ # If the previous option needs an argument, assign it.
+ if test -n "$ac_prev"; then
+ eval $ac_prev=\$ac_option
+ ac_prev=
+ continue
+ fi
+
+ case $ac_option in
+ *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
+ *=) ac_optarg= ;;
+ *) ac_optarg=yes ;;
+ esac
+
+ # Accept the important Cygnus configure options, so we can diagnose typos.
+
+ case $ac_dashdash$ac_option in
+ --)
+ ac_dashdash=yes ;;
+
+ -bindir | --bindir | --bindi | --bind | --bin | --bi)
+ ac_prev=bindir ;;
+ -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+ bindir=$ac_optarg ;;
+
+ -build | --build | --buil | --bui | --bu)
+ ac_prev=build_alias ;;
+ -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+ build_alias=$ac_optarg ;;
+
+ -cache-file | --cache-file | --cache-fil | --cache-fi \
+ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+ ac_prev=cache_file ;;
+ -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+ cache_file=$ac_optarg ;;
+
+ --config-cache | -C)
+ cache_file=config.cache ;;
+
+ -datadir | --datadir | --datadi | --datad)
+ ac_prev=datadir ;;
+ -datadir=* | --datadir=* | --datadi=* | --datad=*)
+ datadir=$ac_optarg ;;
+
+ -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \
+ | --dataroo | --dataro | --datar)
+ ac_prev=datarootdir ;;
+ -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \
+ | --dataroot=* | --dataroo=* | --dataro=* | --datar=*)
+ datarootdir=$ac_optarg ;;
+
+ -disable-* | --disable-*)
+ ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
+ # Reject names that are not valid shell variable names.
+ expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+ as_fn_error $? "invalid feature name: $ac_useropt"
+ ac_useropt_orig=$ac_useropt
+ ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+ case $ac_user_opts in
+ *"
+"enable_$ac_useropt"
+"*) ;;
+ *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig"
+ ac_unrecognized_sep=', ';;
+ esac
+ eval enable_$ac_useropt=no ;;
+
+ -docdir | --docdir | --docdi | --doc | --do)
+ ac_prev=docdir ;;
+ -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*)
+ docdir=$ac_optarg ;;
+
+ -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv)
+ ac_prev=dvidir ;;
+ -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)
+ dvidir=$ac_optarg ;;
+
+ -enable-* | --enable-*)
+ ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
+ # Reject names that are not valid shell variable names.
+ expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+ as_fn_error $? "invalid feature name: $ac_useropt"
+ ac_useropt_orig=$ac_useropt
+ ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+ case $ac_user_opts in
+ *"
+"enable_$ac_useropt"
+"*) ;;
+ *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig"
+ ac_unrecognized_sep=', ';;
+ esac
+ eval enable_$ac_useropt=\$ac_optarg ;;
+
+ -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+ | --exec | --exe | --ex)
+ ac_prev=exec_prefix ;;
+ -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+ | --exec=* | --exe=* | --ex=*)
+ exec_prefix=$ac_optarg ;;
+
+ -gas | --gas | --ga | --g)
+ # Obsolete; use --with-gas.
+ with_gas=yes ;;
+
+ -help | --help | --hel | --he | -h)
+ ac_init_help=long ;;
+ -help=r* | --help=r* | --hel=r* | --he=r* | -hr*)
+ ac_init_help=recursive ;;
+ -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
+ ac_init_help=short ;;
+
+ -host | --host | --hos | --ho)
+ ac_prev=host_alias ;;
+ -host=* | --host=* | --hos=* | --ho=*)
+ host_alias=$ac_optarg ;;
+
+ -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht)
+ ac_prev=htmldir ;;
+ -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \
+ | --ht=*)
+ htmldir=$ac_optarg ;;
+
+ -includedir | --includedir | --includedi | --included | --include \
+ | --includ | --inclu | --incl | --inc)
+ ac_prev=includedir ;;
+ -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+ | --includ=* | --inclu=* | --incl=* | --inc=*)
+ includedir=$ac_optarg ;;
+
+ -infodir | --infodir | --infodi | --infod | --info | --inf)
+ ac_prev=infodir ;;
+ -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+ infodir=$ac_optarg ;;
+
+ -libdir | --libdir | --libdi | --libd)
+ ac_prev=libdir ;;
+ -libdir=* | --libdir=* | --libdi=* | --libd=*)
+ libdir=$ac_optarg ;;
+
+ -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+ | --libexe | --libex | --libe)
+ ac_prev=libexecdir ;;
+ -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+ | --libexe=* | --libex=* | --libe=*)
+ libexecdir=$ac_optarg ;;
+
+ -localedir | --localedir | --localedi | --localed | --locale)
+ ac_prev=localedir ;;
+ -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*)
+ localedir=$ac_optarg ;;
+
+ -localstatedir | --localstatedir | --localstatedi | --localstated \
+ | --localstate | --localstat | --localsta | --localst | --locals)
+ ac_prev=localstatedir ;;
+ -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+ | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*)
+ localstatedir=$ac_optarg ;;
+
+ -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+ ac_prev=mandir ;;
+ -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+ mandir=$ac_optarg ;;
+
+ -nfp | --nfp | --nf)
+ # Obsolete; use --without-fp.
+ with_fp=no ;;
+
+ -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+ | --no-cr | --no-c | -n)
+ no_create=yes ;;
+
+ -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+ no_recursion=yes ;;
+
+ -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+ | --oldin | --oldi | --old | --ol | --o)
+ ac_prev=oldincludedir ;;
+ -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+ oldincludedir=$ac_optarg ;;
+
+ -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+ ac_prev=prefix ;;
+ -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+ prefix=$ac_optarg ;;
+
+ -program-prefix | --program-prefix | --program-prefi | --program-pref \
+ | --program-pre | --program-pr | --program-p)
+ ac_prev=program_prefix ;;
+ -program-prefix=* | --program-prefix=* | --program-prefi=* \
+ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+ program_prefix=$ac_optarg ;;
+
+ -program-suffix | --program-suffix | --program-suffi | --program-suff \
+ | --program-suf | --program-su | --program-s)
+ ac_prev=program_suffix ;;
+ -program-suffix=* | --program-suffix=* | --program-suffi=* \
+ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+ program_suffix=$ac_optarg ;;
+
+ -program-transform-name | --program-transform-name \
+ | --program-transform-nam | --program-transform-na \
+ | --program-transform-n | --program-transform- \
+ | --program-transform | --program-transfor \
+ | --program-transfo | --program-transf \
+ | --program-trans | --program-tran \
+ | --progr-tra | --program-tr | --program-t)
+ ac_prev=program_transform_name ;;
+ -program-transform-name=* | --program-transform-name=* \
+ | --program-transform-nam=* | --program-transform-na=* \
+ | --program-transform-n=* | --program-transform-=* \
+ | --program-transform=* | --program-transfor=* \
+ | --program-transfo=* | --program-transf=* \
+ | --program-trans=* | --program-tran=* \
+ | --progr-tra=* | --program-tr=* | --program-t=*)
+ program_transform_name=$ac_optarg ;;
+
+ -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd)
+ ac_prev=pdfdir ;;
+ -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*)
+ pdfdir=$ac_optarg ;;
+
+ -psdir | --psdir | --psdi | --psd | --ps)
+ ac_prev=psdir ;;
+ -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)
+ psdir=$ac_optarg ;;
+
+ -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+ | -silent | --silent | --silen | --sile | --sil)
+ silent=yes ;;
+
+ -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+ ac_prev=sbindir ;;
+ -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+ | --sbi=* | --sb=*)
+ sbindir=$ac_optarg ;;
+
+ -sharedstatedir | --sharedstatedir | --sharedstatedi \
+ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+ | --sharedst | --shareds | --shared | --share | --shar \
+ | --sha | --sh)
+ ac_prev=sharedstatedir ;;
+ -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+ | --sha=* | --sh=*)
+ sharedstatedir=$ac_optarg ;;
+
+ -site | --site | --sit)
+ ac_prev=site ;;
+ -site=* | --site=* | --sit=*)
+ site=$ac_optarg ;;
+
+ -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+ ac_prev=srcdir ;;
+ -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+ srcdir=$ac_optarg ;;
+
+ -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+ | --syscon | --sysco | --sysc | --sys | --sy)
+ ac_prev=sysconfdir ;;
+ -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+ sysconfdir=$ac_optarg ;;
+
+ -target | --target | --targe | --targ | --tar | --ta | --t)
+ ac_prev=target_alias ;;
+ -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+ target_alias=$ac_optarg ;;
+
+ -v | -verbose | --verbose | --verbos | --verbo | --verb)
+ verbose=yes ;;
+
+ -version | --version | --versio | --versi | --vers | -V)
+ ac_init_version=: ;;
+
+ -with-* | --with-*)
+ ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
+ # Reject names that are not valid shell variable names.
+ expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+ as_fn_error $? "invalid package name: $ac_useropt"
+ ac_useropt_orig=$ac_useropt
+ ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+ case $ac_user_opts in
+ *"
+"with_$ac_useropt"
+"*) ;;
+ *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig"
+ ac_unrecognized_sep=', ';;
+ esac
+ eval with_$ac_useropt=\$ac_optarg ;;
+
+ -without-* | --without-*)
+ ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'`
+ # Reject names that are not valid shell variable names.
+ expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+ as_fn_error $? "invalid package name: $ac_useropt"
+ ac_useropt_orig=$ac_useropt
+ ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+ case $ac_user_opts in
+ *"
+"with_$ac_useropt"
+"*) ;;
+ *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig"
+ ac_unrecognized_sep=', ';;
+ esac
+ eval with_$ac_useropt=no ;;
+
+ --x)
+ # Obsolete; use --with-x.
+ with_x=yes ;;
+
+ -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+ | --x-incl | --x-inc | --x-in | --x-i)
+ ac_prev=x_includes ;;
+ -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+ x_includes=$ac_optarg ;;
+
+ -x-libraries | --x-libraries | --x-librarie | --x-librari \
+ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+ ac_prev=x_libraries ;;
+ -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+ x_libraries=$ac_optarg ;;
+
+ -*) as_fn_error $? "unrecognized option: \`$ac_option'
+Try \`$0 --help' for more information"
+ ;;
+
+ *=*)
+ ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
+ # Reject names that are not valid shell variable names.
+ case $ac_envvar in #(
+ '' | [0-9]* | *[!_$as_cr_alnum]* )
+ as_fn_error $? "invalid variable name: \`$ac_envvar'" ;;
+ esac
+ eval $ac_envvar=\$ac_optarg
+ export $ac_envvar ;;
+
+ *)
+ # FIXME: should be removed in autoconf 3.0.
+ $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
+ expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
+ $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
+ : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}"
+ ;;
+
+ esac
+done
+
+if test -n "$ac_prev"; then
+ ac_option=--`echo $ac_prev | sed 's/_/-/g'`
+ as_fn_error $? "missing argument to $ac_option"
+fi
+
+if test -n "$ac_unrecognized_opts"; then
+ case $enable_option_checking in
+ no) ;;
+ fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;;
+ *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
+ esac
+fi
+
+# Check all directory arguments for consistency.
+for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
+ datadir sysconfdir sharedstatedir localstatedir includedir \
+ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
+ libdir localedir mandir
+do
+ eval ac_val=\$$ac_var
+ # Remove trailing slashes.
+ case $ac_val in
+ */ )
+ ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
+ eval $ac_var=\$ac_val;;
+ esac
+ # Be sure to have absolute directory names.
+ case $ac_val in
+ [\\/$]* | ?:[\\/]* ) continue;;
+ NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
+ esac
+ as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val"
+done
+
+# There might be people who depend on the old broken behavior: `$host'
+# used to hold the argument of --host etc.
+# FIXME: To remove some day.
+build=$build_alias
+host=$host_alias
+target=$target_alias
+
+# FIXME: To remove some day.
+if test "x$host_alias" != x; then
+ if test "x$build_alias" = x; then
+ cross_compiling=maybe
+ elif test "x$build_alias" != "x$host_alias"; then
+ cross_compiling=yes
+ fi
+fi
+
+ac_tool_prefix=
+test -n "$host_alias" && ac_tool_prefix=$host_alias-
+
+test "$silent" = yes && exec 6>/dev/null
+
+
+ac_pwd=`pwd` && test -n "$ac_pwd" &&
+ac_ls_di=`ls -di .` &&
+ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` ||
+ as_fn_error $? "working directory cannot be determined"
+test "X$ac_ls_di" = "X$ac_pwd_ls_di" ||
+ as_fn_error $? "pwd does not report name of working directory"
+
+
+# Find the source files, if location was not specified.
+if test -z "$srcdir"; then
+ ac_srcdir_defaulted=yes
+ # Try the directory containing this script, then the parent directory.
+ ac_confdir=`$as_dirname -- "$as_myself" ||
+$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$as_myself" : 'X\(//\)[^/]' \| \
+ X"$as_myself" : 'X\(//\)$' \| \
+ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_myself" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)[^/].*/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
+ srcdir=$ac_confdir
+ if test ! -r "$srcdir/$ac_unique_file"; then
+ srcdir=..
+ fi
+else
+ ac_srcdir_defaulted=no
+fi
+if test ! -r "$srcdir/$ac_unique_file"; then
+ test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
+ as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir"
+fi
+ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
+ac_abs_confdir=`(
+ cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg"
+ pwd)`
+# When building in place, set srcdir=.
+if test "$ac_abs_confdir" = "$ac_pwd"; then
+ srcdir=.
+fi
+# Remove unnecessary trailing slashes from srcdir.
+# Double slashes in file names in object file debugging info
+# mess up M-x gdb in Emacs.
+case $srcdir in
+*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;;
+esac
+for ac_var in $ac_precious_vars; do
+ eval ac_env_${ac_var}_set=\${${ac_var}+set}
+ eval ac_env_${ac_var}_value=\$${ac_var}
+ eval ac_cv_env_${ac_var}_set=\${${ac_var}+set}
+ eval ac_cv_env_${ac_var}_value=\$${ac_var}
+done
+
+#
+# Report the --help message.
+#
+if test "$ac_init_help" = "long"; then
+ # Omit some internal or obsolete options to make the list less imposing.
+ # This message is too long to be a string in the A/UX 3.1 sh.
+ cat <<_ACEOF
+\`configure' configures this package to adapt to many kinds of systems.
+
+Usage: $0 [OPTION]... [VAR=VALUE]...
+
+To assign environment variables (e.g., CC, CFLAGS...), specify them as
+VAR=VALUE. See below for descriptions of some of the useful variables.
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+ -h, --help display this help and exit
+ --help=short display options specific to this package
+ --help=recursive display the short help of all the included packages
+ -V, --version display version information and exit
+ -q, --quiet, --silent do not print \`checking ...' messages
+ --cache-file=FILE cache test results in FILE [disabled]
+ -C, --config-cache alias for \`--cache-file=config.cache'
+ -n, --no-create do not create output files
+ --srcdir=DIR find the sources in DIR [configure dir or \`..']
+
+Installation directories:
+ --prefix=PREFIX install architecture-independent files in PREFIX
+ [$ac_default_prefix]
+ --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
+ [PREFIX]
+
+By default, \`make install' will install all the files in
+\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify
+an installation prefix other than \`$ac_default_prefix' using \`--prefix',
+for instance \`--prefix=\$HOME'.
+
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+ --bindir=DIR user executables [EPREFIX/bin]
+ --sbindir=DIR system admin executables [EPREFIX/sbin]
+ --libexecdir=DIR program executables [EPREFIX/libexec]
+ --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
+ --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
+ --localstatedir=DIR modifiable single-machine data [PREFIX/var]
+ --libdir=DIR object code libraries [EPREFIX/lib]
+ --includedir=DIR C header files [PREFIX/include]
+ --oldincludedir=DIR C header files for non-gcc [/usr/include]
+ --datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
+ --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
+ --infodir=DIR info documentation [DATAROOTDIR/info]
+ --localedir=DIR locale-dependent data [DATAROOTDIR/locale]
+ --mandir=DIR man documentation [DATAROOTDIR/man]
+ --docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE]
+ --htmldir=DIR html documentation [DOCDIR]
+ --dvidir=DIR dvi documentation [DOCDIR]
+ --pdfdir=DIR pdf documentation [DOCDIR]
+ --psdir=DIR ps documentation [DOCDIR]
+_ACEOF
+
+ cat <<\_ACEOF
+_ACEOF
+fi
+
+if test -n "$ac_init_help"; then
+
+ cat <<\_ACEOF
+
+Optional Features:
+ --disable-option-checking ignore unrecognized --enable/--with options
+ --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
+ --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
+ --disable-socket-dir disable system wide socket-dir and use ~/.screen instead
+ --enable-pam enable PAM support
+ --enable-use-locale use localized month/day names
+ --enable-telnet enable builtin telnet
+ --enable-colors256 enable support for 256 colors
+ --enable-rxvt_osc enable support for rxvt OSC codes
+
+Optional Packages:
+ --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
+ --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
+ --with-socket-dir=path where to put the per-user sockets
+ --with-pty-mode=mode default mode for ptys
+ --with-pty-group=group default group for ptys
+ --with-sys-screenrc=path to the global screenrc file
+
+Some influential environment variables:
+ CC C compiler command
+ CFLAGS C compiler flags
+ LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
+ nonstandard directory <lib dir>
+ LIBS libraries to pass to the linker, e.g. -l<library>
+ CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
+ you have headers in a nonstandard directory <include dir>
+ CPP C preprocessor
+
+Use these variables to override the choices made by `configure' or to help
+it to find libraries and programs with nonstandard names/locations.
+
+Report bugs to the package provider.
+_ACEOF
+ac_status=$?
+fi
+
+if test "$ac_init_help" = "recursive"; then
+ # If there are subdirs, report their specific --help.
+ for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
+ test -d "$ac_dir" ||
+ { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } ||
+ continue
+ ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+ ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+ # A ".." for each directory in $ac_dir_suffix.
+ ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+ case $ac_top_builddir_sub in
+ "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+ *) ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+ esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+ .) # We are building in place.
+ ac_srcdir=.
+ ac_top_srcdir=$ac_top_builddir_sub
+ ac_abs_top_srcdir=$ac_pwd ;;
+ [\\/]* | ?:[\\/]* ) # Absolute name.
+ ac_srcdir=$srcdir$ac_dir_suffix;
+ ac_top_srcdir=$srcdir
+ ac_abs_top_srcdir=$srcdir ;;
+ *) # Relative name.
+ ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+ ac_top_srcdir=$ac_top_build_prefix$srcdir
+ ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+ cd "$ac_dir" || { ac_status=$?; continue; }
+ # Check for guested configure.
+ if test -f "$ac_srcdir/configure.gnu"; then
+ echo &&
+ $SHELL "$ac_srcdir/configure.gnu" --help=recursive
+ elif test -f "$ac_srcdir/configure"; then
+ echo &&
+ $SHELL "$ac_srcdir/configure" --help=recursive
+ else
+ $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
+ fi || ac_status=$?
+ cd "$ac_pwd" || { ac_status=$?; break; }
+ done
+fi
+
+test -n "$ac_init_help" && exit $ac_status
+if $ac_init_version; then
+ cat <<\_ACEOF
+configure
+generated by GNU Autoconf 2.69
+
+Copyright (C) 2012 Free Software Foundation, Inc.
+This configure script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it.
+_ACEOF
+ exit
+fi
+
+## ------------------------ ##
+## Autoconf initialization. ##
+## ------------------------ ##
+
+# ac_fn_c_try_compile LINENO
+# --------------------------
+# Try to compile conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_compile ()
+{
+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ rm -f conftest.$ac_objext
+ if { { ac_try="$ac_compile"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_compile") 2>conftest.err
+ ac_status=$?
+ if test -s conftest.err; then
+ grep -v '^ *+' conftest.err >conftest.er1
+ cat conftest.er1 >&5
+ mv -f conftest.er1 conftest.err
+ fi
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; } && {
+ test -z "$ac_c_werror_flag" ||
+ test ! -s conftest.err
+ } && test -s conftest.$ac_objext; then :
+ ac_retval=0
+else
+ $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ ac_retval=1
+fi
+ eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+ as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_compile
+
+# ac_fn_c_try_cpp LINENO
+# ----------------------
+# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_cpp ()
+{
+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ if { { ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err
+ ac_status=$?
+ if test -s conftest.err; then
+ grep -v '^ *+' conftest.err >conftest.er1
+ cat conftest.er1 >&5
+ mv -f conftest.er1 conftest.err
+ fi
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; } > conftest.i && {
+ test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+ test ! -s conftest.err
+ }; then :
+ ac_retval=0
+else
+ $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ ac_retval=1
+fi
+ eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+ as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_cpp
+
+# ac_fn_c_try_link LINENO
+# -----------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_link ()
+{
+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ rm -f conftest.$ac_objext conftest$ac_exeext
+ if { { ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_link") 2>conftest.err
+ ac_status=$?
+ if test -s conftest.err; then
+ grep -v '^ *+' conftest.err >conftest.er1
+ cat conftest.er1 >&5
+ mv -f conftest.er1 conftest.err
+ fi
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; } && {
+ test -z "$ac_c_werror_flag" ||
+ test ! -s conftest.err
+ } && test -s conftest$ac_exeext && {
+ test "$cross_compiling" = yes ||
+ test -x conftest$ac_exeext
+ }; then :
+ ac_retval=0
+else
+ $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ ac_retval=1
+fi
+ # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
+ # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
+ # interfere with the next link command; also delete a directory that is
+ # left behind by Apple's compiler. We do this before executing the actions.
+ rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+ eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+ as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_link
+
+# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
+# -------------------------------------------------------
+# Tests whether HEADER exists, giving a warning if it cannot be compiled using
+# the include files in INCLUDES and setting the cache variable VAR
+# accordingly.
+ac_fn_c_check_header_mongrel ()
+{
+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ if eval \${$3+:} false; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+ $as_echo_n "(cached) " >&6
+fi
+eval ac_res=\$$3
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+else
+ # Is the header compilable?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5
+$as_echo_n "checking $2 usability... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_header_compiler=yes
+else
+ ac_header_compiler=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5
+$as_echo "$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5
+$as_echo_n "checking $2 presence... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <$2>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+ ac_header_preproc=yes
+else
+ ac_header_preproc=no
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5
+$as_echo "$ac_header_preproc" >&6; }
+
+# So? What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #((
+ yes:no: )
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5
+$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;}
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+ ;;
+ no:yes:* )
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5
+$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;}
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5
+$as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;}
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5
+$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;}
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5
+$as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;}
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+ ;;
+esac
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ eval "$3=\$ac_header_compiler"
+fi
+eval ac_res=\$$3
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+fi
+ eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_header_mongrel
+
+# ac_fn_c_try_run LINENO
+# ----------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
+# that executables *can* be run.
+ac_fn_c_try_run ()
+{
+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ if { { ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_link") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
+ { { case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_try") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; }; then :
+ ac_retval=0
+else
+ $as_echo "$as_me: program exited with status $ac_status" >&5
+ $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ ac_retval=$ac_status
+fi
+ rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+ eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+ as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_run
+
+# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES
+# -------------------------------------------------------
+# Tests whether HEADER exists and can be compiled using the include files in
+# INCLUDES, setting the cache variable VAR accordingly.
+ac_fn_c_check_header_compile ()
+{
+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ eval "$3=yes"
+else
+ eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+ eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_header_compile
+
+# ac_fn_c_check_func LINENO FUNC VAR
+# ----------------------------------
+# Tests whether FUNC exists, setting the cache variable VAR accordingly
+ac_fn_c_check_func ()
+{
+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+/* Define $2 to an innocuous variant, in case <limits.h> declares $2.
+ For example, HP-UX 11i <limits.h> declares gettimeofday. */
+#define $2 innocuous_$2
+
+/* System header to define __stub macros and hopefully few prototypes,
+ which can conflict with char $2 (); below.
+ Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+ <limits.h> exists even on freestanding compilers. */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $2
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $2 ();
+/* The GNU C library defines this for functions which it implements
+ to always fail with ENOSYS. Some functions are actually named
+ something starting with __ and the normal name is an alias. */
+#if defined __stub_$2 || defined __stub___$2
+choke me
+#endif
+
+int
+main ()
+{
+return $2 ();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ eval "$3=yes"
+else
+ eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+ eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_func
+cat >config.log <<_ACEOF
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+
+It was created by $as_me, which was
+generated by GNU Autoconf 2.69. Invocation command line was
+
+ $ $0 $@
+
+_ACEOF
+exec 5>>config.log
+{
+cat <<_ASUNAME
+## --------- ##
+## Platform. ##
+## --------- ##
+
+hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
+/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown`
+
+/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown`
+/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
+/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown`
+/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown`
+/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown`
+/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown`
+
+_ASUNAME
+
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ $as_echo "PATH: $as_dir"
+ done
+IFS=$as_save_IFS
+
+} >&5
+
+cat >&5 <<_ACEOF
+
+
+## ----------- ##
+## Core tests. ##
+## ----------- ##
+
+_ACEOF
+
+
+# Keep a trace of the command line.
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Strip out --silent because we don't want to record it for future runs.
+# Also quote any args containing shell meta-characters.
+# Make two passes to allow for proper duplicate-argument suppression.
+ac_configure_args=
+ac_configure_args0=
+ac_configure_args1=
+ac_must_keep_next=false
+for ac_pass in 1 2
+do
+ for ac_arg
+ do
+ case $ac_arg in
+ -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
+ -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+ | -silent | --silent | --silen | --sile | --sil)
+ continue ;;
+ *\'*)
+ ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
+ esac
+ case $ac_pass in
+ 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;;
+ 2)
+ as_fn_append ac_configure_args1 " '$ac_arg'"
+ if test $ac_must_keep_next = true; then
+ ac_must_keep_next=false # Got value, back to normal.
+ else
+ case $ac_arg in
+ *=* | --config-cache | -C | -disable-* | --disable-* \
+ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
+ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
+ | -with-* | --with-* | -without-* | --without-* | --x)
+ case "$ac_configure_args0 " in
+ "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
+ esac
+ ;;
+ -* ) ac_must_keep_next=true ;;
+ esac
+ fi
+ as_fn_append ac_configure_args " '$ac_arg'"
+ ;;
+ esac
+ done
+done
+{ ac_configure_args0=; unset ac_configure_args0;}
+{ ac_configure_args1=; unset ac_configure_args1;}
+
+# When interrupted or exit'd, cleanup temporary files, and complete
+# config.log. We remove comments because anyway the quotes in there
+# would cause problems or look ugly.
+# WARNING: Use '\'' to represent an apostrophe within the trap.
+# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.
+trap 'exit_status=$?
+ # Save into config.log some information that might help in debugging.
+ {
+ echo
+
+ $as_echo "## ---------------- ##
+## Cache variables. ##
+## ---------------- ##"
+ echo
+ # The following way of writing the cache mishandles newlines in values,
+(
+ for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do
+ eval ac_val=\$$ac_var
+ case $ac_val in #(
+ *${as_nl}*)
+ case $ac_var in #(
+ *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+ esac
+ case $ac_var in #(
+ _ | IFS | as_nl) ;; #(
+ BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+ *) { eval $ac_var=; unset $ac_var;} ;;
+ esac ;;
+ esac
+ done
+ (set) 2>&1 |
+ case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #(
+ *${as_nl}ac_space=\ *)
+ sed -n \
+ "s/'\''/'\''\\\\'\'''\''/g;
+ s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p"
+ ;; #(
+ *)
+ sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+ ;;
+ esac |
+ sort
+)
+ echo
+
+ $as_echo "## ----------------- ##
+## Output variables. ##
+## ----------------- ##"
+ echo
+ for ac_var in $ac_subst_vars
+ do
+ eval ac_val=\$$ac_var
+ case $ac_val in
+ *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+ esac
+ $as_echo "$ac_var='\''$ac_val'\''"
+ done | sort
+ echo
+
+ if test -n "$ac_subst_files"; then
+ $as_echo "## ------------------- ##
+## File substitutions. ##
+## ------------------- ##"
+ echo
+ for ac_var in $ac_subst_files
+ do
+ eval ac_val=\$$ac_var
+ case $ac_val in
+ *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+ esac
+ $as_echo "$ac_var='\''$ac_val'\''"
+ done | sort
+ echo
+ fi
+
+ if test -s confdefs.h; then
+ $as_echo "## ----------- ##
+## confdefs.h. ##
+## ----------- ##"
+ echo
+ cat confdefs.h
+ echo
+ fi
+ test "$ac_signal" != 0 &&
+ $as_echo "$as_me: caught signal $ac_signal"
+ $as_echo "$as_me: exit $exit_status"
+ } >&5
+ rm -f core *.core core.conftest.* &&
+ rm -f -r conftest* confdefs* conf$$* $ac_clean_files &&
+ exit $exit_status
+' 0
+for ac_signal in 1 2 13 15; do
+ trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal
+done
+ac_signal=0
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -f -r conftest* confdefs.h
+
+$as_echo "/* confdefs.h */" > confdefs.h
+
+# Predefined preprocessor variables.
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_NAME "$PACKAGE_NAME"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_VERSION "$PACKAGE_VERSION"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_STRING "$PACKAGE_STRING"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_URL "$PACKAGE_URL"
+_ACEOF
+
+
+# Let the site file select an alternate cache file if it wants to.
+# Prefer an explicitly selected file to automatically selected ones.
+ac_site_file1=NONE
+ac_site_file2=NONE
+if test -n "$CONFIG_SITE"; then
+ # We do not want a PATH search for config.site.
+ case $CONFIG_SITE in #((
+ -*) ac_site_file1=./$CONFIG_SITE;;
+ */*) ac_site_file1=$CONFIG_SITE;;
+ *) ac_site_file1=./$CONFIG_SITE;;
+ esac
+elif test "x$prefix" != xNONE; then
+ ac_site_file1=$prefix/share/config.site
+ ac_site_file2=$prefix/etc/config.site
+else
+ ac_site_file1=$ac_default_prefix/share/config.site
+ ac_site_file2=$ac_default_prefix/etc/config.site
+fi
+for ac_site_file in "$ac_site_file1" "$ac_site_file2"
+do
+ test "x$ac_site_file" = xNONE && continue
+ if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
+$as_echo "$as_me: loading site script $ac_site_file" >&6;}
+ sed 's/^/| /' "$ac_site_file" >&5
+ . "$ac_site_file" \
+ || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "failed to load site script $ac_site_file
+See \`config.log' for more details" "$LINENO" 5; }
+ fi
+done
+
+if test -r "$cache_file"; then
+ # Some versions of bash will fail to source /dev/null (special files
+ # actually), so we avoid doing that. DJGPP emulates it as a regular file.
+ if test /dev/null != "$cache_file" && test -f "$cache_file"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
+$as_echo "$as_me: loading cache $cache_file" >&6;}
+ case $cache_file in
+ [\\/]* | ?:[\\/]* ) . "$cache_file";;
+ *) . "./$cache_file";;
+ esac
+ fi
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5
+$as_echo "$as_me: creating cache $cache_file" >&6;}
+ >$cache_file
+fi
+
+# Check that the precious variables saved in the cache have kept the same
+# value.
+ac_cache_corrupted=false
+for ac_var in $ac_precious_vars; do
+ eval ac_old_set=\$ac_cv_env_${ac_var}_set
+ eval ac_new_set=\$ac_env_${ac_var}_set
+ eval ac_old_val=\$ac_cv_env_${ac_var}_value
+ eval ac_new_val=\$ac_env_${ac_var}_value
+ case $ac_old_set,$ac_new_set in
+ set,)
+ { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
+ ac_cache_corrupted=: ;;
+ ,set)
+ { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
+ ac_cache_corrupted=: ;;
+ ,);;
+ *)
+ if test "x$ac_old_val" != "x$ac_new_val"; then
+ # differences in whitespace do not lead to failure.
+ ac_old_val_w=`echo x $ac_old_val`
+ ac_new_val_w=`echo x $ac_new_val`
+ if test "$ac_old_val_w" != "$ac_new_val_w"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5
+$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
+ ac_cache_corrupted=:
+ else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
+$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;}
+ eval $ac_var=\$ac_old_val
+ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5
+$as_echo "$as_me: former value: \`$ac_old_val'" >&2;}
+ { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5
+$as_echo "$as_me: current value: \`$ac_new_val'" >&2;}
+ fi;;
+ esac
+ # Pass precious variables to config.status.
+ if test "$ac_new_set" = set; then
+ case $ac_new_val in
+ *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
+ *) ac_arg=$ac_var=$ac_new_val ;;
+ esac
+ case " $ac_configure_args " in
+ *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy.
+ *) as_fn_append ac_configure_args " '$ac_arg'" ;;
+ esac
+ fi
+done
+if $ac_cache_corrupted; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+ { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
+$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;}
+ as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5
+fi
+## -------------------- ##
+## Main body of script. ##
+## -------------------- ##
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+ac_config_headers="$ac_config_headers config.h"
+
+
+
+
+rev=`sed < ${srcdir}/patchlevel.h -n -e '/#define REV/s/#define REV *//p'`
+vers=`sed < ${srcdir}/patchlevel.h -n -e '/#define VERS/s/#define VERS *//p'`
+pat=`sed < ${srcdir}/patchlevel.h -n -e '/#define PATCHLEVEL/s/#define PATCHLEVEL *//p'`
+VERSION="$rev.$vers.$pat"
+echo "this is screen version $VERSION" 1>&6
+
+
+if test "x$prefix" = xNONE; then
+ $as_echo_n "checking for prefix by " >&6
+ # Extract the first word of "screen", so it can be a program name with args.
+set dummy screen; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_ac_prefix_program+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ case $ac_prefix_program in
+ [\\/]* | ?:[\\/]*)
+ ac_cv_path_ac_prefix_program="$ac_prefix_program" # Let the user override the test with a path.
+ ;;
+ *)
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_path_ac_prefix_program="$as_dir/$ac_word$ac_exec_ext"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+ ;;
+esac
+fi
+ac_prefix_program=$ac_cv_path_ac_prefix_program
+if test -n "$ac_prefix_program"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_prefix_program" >&5
+$as_echo "$ac_prefix_program" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ if test -n "$ac_prefix_program"; then
+ prefix=`$as_dirname -- "$ac_prefix_program" ||
+$as_expr X"$ac_prefix_program" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$ac_prefix_program" : 'X\(//\)[^/]' \| \
+ X"$ac_prefix_program" : 'X\(//\)$' \| \
+ X"$ac_prefix_program" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$ac_prefix_program" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)[^/].*/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
+ prefix=`$as_dirname -- "$prefix" ||
+$as_expr X"$prefix" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$prefix" : 'X\(//\)[^/]' \| \
+ X"$prefix" : 'X\(//\)$' \| \
+ X"$prefix" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$prefix" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)[^/].*/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
+ fi
+fi
+
+if test "x$prefix" = xNONE; then
+ $as_echo_n "checking for prefix by " >&6
+ # Extract the first word of "gzip", so it can be a program name with args.
+set dummy gzip; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_ac_prefix_program+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ case $ac_prefix_program in
+ [\\/]* | ?:[\\/]*)
+ ac_cv_path_ac_prefix_program="$ac_prefix_program" # Let the user override the test with a path.
+ ;;
+ *)
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_path_ac_prefix_program="$as_dir/$ac_word$ac_exec_ext"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+ ;;
+esac
+fi
+ac_prefix_program=$ac_cv_path_ac_prefix_program
+if test -n "$ac_prefix_program"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_prefix_program" >&5
+$as_echo "$ac_prefix_program" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ if test -n "$ac_prefix_program"; then
+ prefix=`$as_dirname -- "$ac_prefix_program" ||
+$as_expr X"$ac_prefix_program" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$ac_prefix_program" : 'X\(//\)[^/]' \| \
+ X"$ac_prefix_program" : 'X\(//\)$' \| \
+ X"$ac_prefix_program" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$ac_prefix_program" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)[^/].*/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
+ prefix=`$as_dirname -- "$prefix" ||
+$as_expr X"$prefix" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$prefix" : 'X\(//\)[^/]' \| \
+ X"$prefix" : 'X\(//\)$' \| \
+ X"$prefix" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$prefix" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)[^/].*/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
+ fi
+fi
+
+
+old_CFLAGS="$CFLAGS"
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+if test -n "$ac_tool_prefix"; then
+ # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}gcc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_prog_CC="${ac_tool_prefix}gcc"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+ ac_ct_CC=$CC
+ # Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_CC+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$ac_ct_CC"; then
+ ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_prog_ac_ct_CC="gcc"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+ if test "x$ac_ct_CC" = x; then
+ CC=""
+ else
+ case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+ CC=$ac_ct_CC
+ fi
+else
+ CC="$ac_cv_prog_CC"
+fi
+
+if test -z "$CC"; then
+ if test -n "$ac_tool_prefix"; then
+ # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}cc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_prog_CC="${ac_tool_prefix}cc"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ fi
+fi
+if test -z "$CC"; then
+ # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+ ac_prog_rejected=no
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
+ ac_prog_rejected=yes
+ continue
+ fi
+ ac_cv_prog_CC="cc"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+if test $ac_prog_rejected = yes; then
+ # We found a bogon in the path, so make sure we never use it.
+ set dummy $ac_cv_prog_CC
+ shift
+ if test $# != 0; then
+ # We chose a different compiler from the bogus one.
+ # However, it has the same basename, so the bogon will be chosen
+ # first if we set CC to just the basename; use the full file name.
+ shift
+ ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
+ fi
+fi
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$CC"; then
+ if test -n "$ac_tool_prefix"; then
+ for ac_prog in cl.exe
+ do
+ # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ test -n "$CC" && break
+ done
+fi
+if test -z "$CC"; then
+ ac_ct_CC=$CC
+ for ac_prog in cl.exe
+do
+ # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_CC+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$ac_ct_CC"; then
+ ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_prog_ac_ct_CC="$ac_prog"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ test -n "$ac_ct_CC" && break
+done
+
+ if test "x$ac_ct_CC" = x; then
+ CC=""
+ else
+ case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+ CC=$ac_ct_CC
+ fi
+fi
+
+fi
+
+
+test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "no acceptable C compiler found in \$PATH
+See \`config.log' for more details" "$LINENO" 5; }
+
+# Provide some information about the compiler.
+$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
+set X $ac_compile
+ac_compiler=$2
+for ac_option in --version -v -V -qversion; do
+ { { ac_try="$ac_compiler $ac_option >&5"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_compiler $ac_option >&5") 2>conftest.err
+ ac_status=$?
+ if test -s conftest.err; then
+ sed '10a\
+... rest of stderr output deleted ...
+ 10q' conftest.err >conftest.er1
+ cat conftest.er1 >&5
+ fi
+ rm -f conftest.er1 conftest.err
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }
+done
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out"
+# Try to create an executable without -o first, disregard a.out.
+# It will help us diagnose broken compilers, and finding out an intuition
+# of exeext.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
+$as_echo_n "checking whether the C compiler works... " >&6; }
+ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
+
+# The possible output files:
+ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*"
+
+ac_rmfiles=
+for ac_file in $ac_files
+do
+ case $ac_file in
+ *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
+ * ) ac_rmfiles="$ac_rmfiles $ac_file";;
+ esac
+done
+rm -f $ac_rmfiles
+
+if { { ac_try="$ac_link_default"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_link_default") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; then :
+ # Autoconf-2.13 could set the ac_cv_exeext variable to `no'.
+# So ignore a value of `no', otherwise this would lead to `EXEEXT = no'
+# in a Makefile. We should not override ac_cv_exeext if it was cached,
+# so that the user can short-circuit this test for compilers unknown to
+# Autoconf.
+for ac_file in $ac_files ''
+do
+ test -f "$ac_file" || continue
+ case $ac_file in
+ *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )
+ ;;
+ [ab].out )
+ # We found the default executable, but exeext='' is most
+ # certainly right.
+ break;;
+ *.* )
+ if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
+ then :; else
+ ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+ fi
+ # We set ac_cv_exeext here because the later test for it is not
+ # safe: cross compilers may not add the suffix if given an `-o'
+ # argument, so we may need to know it at that point already.
+ # Even if this section looks crufty: it has the advantage of
+ # actually working.
+ break;;
+ * )
+ break;;
+ esac
+done
+test "$ac_cv_exeext" = no && ac_cv_exeext=
+
+else
+ ac_file=''
+fi
+if test -z "$ac_file"; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+$as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error 77 "C compiler cannot create executables
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
+$as_echo_n "checking for C compiler default output file name... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
+$as_echo "$ac_file" >&6; }
+ac_exeext=$ac_cv_exeext
+
+rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out
+ac_clean_files=$ac_clean_files_save
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
+$as_echo_n "checking for suffix of executables... " >&6; }
+if { { ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_link") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; then :
+ # If both `conftest.exe' and `conftest' are `present' (well, observable)
+# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will
+# work properly (i.e., refer to `conftest.exe'), while it won't with
+# `rm'.
+for ac_file in conftest.exe conftest conftest.*; do
+ test -f "$ac_file" || continue
+ case $ac_file in
+ *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
+ *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+ break;;
+ * ) break;;
+ esac
+done
+else
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details" "$LINENO" 5; }
+fi
+rm -f conftest conftest$ac_cv_exeext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
+$as_echo "$ac_cv_exeext" >&6; }
+
+rm -f conftest.$ac_ext
+EXEEXT=$ac_cv_exeext
+ac_exeext=$EXEEXT
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <stdio.h>
+int
+main ()
+{
+FILE *f = fopen ("conftest.out", "w");
+ return ferror (f) || fclose (f) != 0;
+
+ ;
+ return 0;
+}
+_ACEOF
+ac_clean_files="$ac_clean_files conftest.out"
+# Check that the compiler produces executables we can run. If not, either
+# the compiler is broken, or we cross compile.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
+$as_echo_n "checking whether we are cross compiling... " >&6; }
+if test "$cross_compiling" != yes; then
+ { { ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_link") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }
+ if { ac_try='./conftest$ac_cv_exeext'
+ { { case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_try") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; }; then
+ cross_compiling=no
+ else
+ if test "$cross_compiling" = maybe; then
+ cross_compiling=yes
+ else
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details" "$LINENO" 5; }
+ fi
+ fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
+$as_echo "$cross_compiling" >&6; }
+
+rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out
+ac_clean_files=$ac_clean_files_save
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
+$as_echo_n "checking for suffix of object files... " >&6; }
+if ${ac_cv_objext+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.o conftest.obj
+if { { ac_try="$ac_compile"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_compile") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; then :
+ for ac_file in conftest.o conftest.obj conftest.*; do
+ test -f "$ac_file" || continue;
+ case $ac_file in
+ *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;;
+ *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
+ break;;
+ esac
+done
+else
+ $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot compute suffix of object files: cannot compile
+See \`config.log' for more details" "$LINENO" 5; }
+fi
+rm -f conftest.$ac_cv_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5
+$as_echo "$ac_cv_objext" >&6; }
+OBJEXT=$ac_cv_objext
+ac_objext=$OBJEXT
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
+$as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
+if ${ac_cv_c_compiler_gnu+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+#ifndef __GNUC__
+ choke me
+#endif
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_compiler_gnu=yes
+else
+ ac_compiler_gnu=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_c_compiler_gnu=$ac_compiler_gnu
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
+$as_echo "$ac_cv_c_compiler_gnu" >&6; }
+if test $ac_compiler_gnu = yes; then
+ GCC=yes
+else
+ GCC=
+fi
+ac_test_CFLAGS=${CFLAGS+set}
+ac_save_CFLAGS=$CFLAGS
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
+$as_echo_n "checking whether $CC accepts -g... " >&6; }
+if ${ac_cv_prog_cc_g+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_save_c_werror_flag=$ac_c_werror_flag
+ ac_c_werror_flag=yes
+ ac_cv_prog_cc_g=no
+ CFLAGS="-g"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_prog_cc_g=yes
+else
+ CFLAGS=""
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+else
+ ac_c_werror_flag=$ac_save_c_werror_flag
+ CFLAGS="-g"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_prog_cc_g=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ ac_c_werror_flag=$ac_save_c_werror_flag
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
+$as_echo "$ac_cv_prog_cc_g" >&6; }
+if test "$ac_test_CFLAGS" = set; then
+ CFLAGS=$ac_save_CFLAGS
+elif test $ac_cv_prog_cc_g = yes; then
+ if test "$GCC" = yes; then
+ CFLAGS="-g -O2"
+ else
+ CFLAGS="-g"
+ fi
+else
+ if test "$GCC" = yes; then
+ CFLAGS="-O2"
+ else
+ CFLAGS=
+ fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
+$as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
+if ${ac_cv_prog_cc_c89+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_cv_prog_cc_c89=no
+ac_save_CC=$CC
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <stdarg.h>
+#include <stdio.h>
+struct stat;
+/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */
+struct buf { int x; };
+FILE * (*rcsopen) (struct buf *, struct stat *, int);
+static char *e (p, i)
+ char **p;
+ int i;
+{
+ return p[i];
+}
+static char *f (char * (*g) (char **, int), char **p, ...)
+{
+ char *s;
+ va_list v;
+ va_start (v,p);
+ s = g (p, va_arg (v,int));
+ va_end (v);
+ return s;
+}
+
+/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has
+ function prototypes and stuff, but not '\xHH' hex character constants.
+ These don't provoke an error unfortunately, instead are silently treated
+ as 'x'. The following induces an error, until -std is added to get
+ proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an
+ array size at least. It's necessary to write '\x00'==0 to get something
+ that's true only with -std. */
+int osf4_cc_array ['\x00' == 0 ? 1 : -1];
+
+/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
+ inside strings and character constants. */
+#define FOO(x) 'x'
+int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
+
+int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};
+int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
+int argc;
+char **argv;
+int
+main ()
+{
+return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1];
+ ;
+ return 0;
+}
+_ACEOF
+for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
+ -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+do
+ CC="$ac_save_CC $ac_arg"
+ if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_prog_cc_c89=$ac_arg
+fi
+rm -f core conftest.err conftest.$ac_objext
+ test "x$ac_cv_prog_cc_c89" != "xno" && break
+done
+rm -f conftest.$ac_ext
+CC=$ac_save_CC
+
+fi
+# AC_CACHE_VAL
+case "x$ac_cv_prog_cc_c89" in
+ x)
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
+$as_echo "none needed" >&6; } ;;
+ xno)
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
+$as_echo "unsupported" >&6; } ;;
+ *)
+ CC="$CC $ac_cv_prog_cc_c89"
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
+$as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
+esac
+if test "x$ac_cv_prog_cc_c89" != xno; then :
+
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
+$as_echo_n "checking how to run the C preprocessor... " >&6; }
+# On Suns, sometimes $CPP names a directory.
+if test -n "$CPP" && test -d "$CPP"; then
+ CPP=
+fi
+if test -z "$CPP"; then
+ if ${ac_cv_prog_CPP+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ # Double quotes because CPP needs to be expanded
+ for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
+ do
+ ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+ # Use a header file that comes with gcc, so configuring glibc
+ # with a fresh cross-compiler works.
+ # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+ # <limits.h> exists even on freestanding compilers.
+ # On the NeXT, cc -E runs the code through the compiler's parser,
+ # not just through cpp. "Syntax error" is here to catch this case.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+ Syntax error
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
+ # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+ # OK, works on sane cases. Now check whether nonexistent headers
+ # can be detected and how.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <ac_nonexistent.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+ # Broken: success on invalid input.
+continue
+else
+ # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.i conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then :
+ break
+fi
+
+ done
+ ac_cv_prog_CPP=$CPP
+
+fi
+ CPP=$ac_cv_prog_CPP
+else
+ ac_cv_prog_CPP=$CPP
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
+$as_echo "$CPP" >&6; }
+ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+ # Use a header file that comes with gcc, so configuring glibc
+ # with a fresh cross-compiler works.
+ # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+ # <limits.h> exists even on freestanding compilers.
+ # On the NeXT, cc -E runs the code through the compiler's parser,
+ # not just through cpp. "Syntax error" is here to catch this case.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+ Syntax error
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
+ # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+ # OK, works on sane cases. Now check whether nonexistent headers
+ # can be detected and how.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <ac_nonexistent.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+ # Broken: success on invalid input.
+continue
+else
+ # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.i conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then :
+
+else
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details" "$LINENO" 5; }
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
+$as_echo_n "checking for grep that handles long lines and -e... " >&6; }
+if ${ac_cv_path_GREP+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -z "$GREP"; then
+ ac_path_GREP_found=false
+ # Loop through the user's path and test for each of PROGNAME-LIST
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_prog in grep ggrep; do
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
+ as_fn_executable_p "$ac_path_GREP" || continue
+# Check for GNU ac_path_GREP and select it if it is found.
+ # Check for GNU $ac_path_GREP
+case `"$ac_path_GREP" --version 2>&1` in
+*GNU*)
+ ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;;
+*)
+ ac_count=0
+ $as_echo_n 0123456789 >"conftest.in"
+ while :
+ do
+ cat "conftest.in" "conftest.in" >"conftest.tmp"
+ mv "conftest.tmp" "conftest.in"
+ cp "conftest.in" "conftest.nl"
+ $as_echo 'GREP' >> "conftest.nl"
+ "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+ diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+ as_fn_arith $ac_count + 1 && ac_count=$as_val
+ if test $ac_count -gt ${ac_path_GREP_max-0}; then
+ # Best one so far, save it but keep looking for a better one
+ ac_cv_path_GREP="$ac_path_GREP"
+ ac_path_GREP_max=$ac_count
+ fi
+ # 10*(2^10) chars as input seems more than enough
+ test $ac_count -gt 10 && break
+ done
+ rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+ $ac_path_GREP_found && break 3
+ done
+ done
+ done
+IFS=$as_save_IFS
+ if test -z "$ac_cv_path_GREP"; then
+ as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+ fi
+else
+ ac_cv_path_GREP=$GREP
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5
+$as_echo "$ac_cv_path_GREP" >&6; }
+ GREP="$ac_cv_path_GREP"
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
+$as_echo_n "checking for egrep... " >&6; }
+if ${ac_cv_path_EGREP+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
+ then ac_cv_path_EGREP="$GREP -E"
+ else
+ if test -z "$EGREP"; then
+ ac_path_EGREP_found=false
+ # Loop through the user's path and test for each of PROGNAME-LIST
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_prog in egrep; do
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
+ as_fn_executable_p "$ac_path_EGREP" || continue
+# Check for GNU ac_path_EGREP and select it if it is found.
+ # Check for GNU $ac_path_EGREP
+case `"$ac_path_EGREP" --version 2>&1` in
+*GNU*)
+ ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;;
+*)
+ ac_count=0
+ $as_echo_n 0123456789 >"conftest.in"
+ while :
+ do
+ cat "conftest.in" "conftest.in" >"conftest.tmp"
+ mv "conftest.tmp" "conftest.in"
+ cp "conftest.in" "conftest.nl"
+ $as_echo 'EGREP' >> "conftest.nl"
+ "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+ diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+ as_fn_arith $ac_count + 1 && ac_count=$as_val
+ if test $ac_count -gt ${ac_path_EGREP_max-0}; then
+ # Best one so far, save it but keep looking for a better one
+ ac_cv_path_EGREP="$ac_path_EGREP"
+ ac_path_EGREP_max=$ac_count
+ fi
+ # 10*(2^10) chars as input seems more than enough
+ test $ac_count -gt 10 && break
+ done
+ rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+ $ac_path_EGREP_found && break 3
+ done
+ done
+ done
+IFS=$as_save_IFS
+ if test -z "$ac_cv_path_EGREP"; then
+ as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+ fi
+else
+ ac_cv_path_EGREP=$EGREP
+fi
+
+ fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5
+$as_echo "$ac_cv_path_EGREP" >&6; }
+ EGREP="$ac_cv_path_EGREP"
+
+
+if test $ac_cv_c_compiler_gnu = yes; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC needs -traditional" >&5
+$as_echo_n "checking whether $CC needs -traditional... " >&6; }
+if ${ac_cv_prog_gcc_traditional+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_pattern="Autoconf.*'x'"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <sgtty.h>
+Autoconf TIOCGETP
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "$ac_pattern" >/dev/null 2>&1; then :
+ ac_cv_prog_gcc_traditional=yes
+else
+ ac_cv_prog_gcc_traditional=no
+fi
+rm -f conftest*
+
+
+ if test $ac_cv_prog_gcc_traditional = no; then
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <termio.h>
+Autoconf TCGETA
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "$ac_pattern" >/dev/null 2>&1; then :
+ ac_cv_prog_gcc_traditional=yes
+fi
+rm -f conftest*
+
+ fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_gcc_traditional" >&5
+$as_echo "$ac_cv_prog_gcc_traditional" >&6; }
+ if test $ac_cv_prog_gcc_traditional = yes; then
+ CC="$CC -traditional"
+ fi
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing strerror" >&5
+$as_echo_n "checking for library containing strerror... " >&6; }
+if ${ac_cv_search_strerror+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char strerror ();
+int
+main ()
+{
+return strerror ();
+ ;
+ return 0;
+}
+_ACEOF
+for ac_lib in '' cposix; do
+ if test -z "$ac_lib"; then
+ ac_res="none required"
+ else
+ ac_res=-l$ac_lib
+ LIBS="-l$ac_lib $ac_func_search_save_LIBS"
+ fi
+ if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_search_strerror=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext
+ if ${ac_cv_search_strerror+:} false; then :
+ break
+fi
+done
+if ${ac_cv_search_strerror+:} false; then :
+
+else
+ ac_cv_search_strerror=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_strerror" >&5
+$as_echo "$ac_cv_search_strerror" >&6; }
+ac_res=$ac_cv_search_strerror
+if test "$ac_res" != no; then :
+ test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
+$as_echo_n "checking for ANSI C header files... " >&6; }
+if ${ac_cv_header_stdc+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_header_stdc=yes
+else
+ ac_cv_header_stdc=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $ac_cv_header_stdc = yes; then
+ # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <string.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "memchr" >/dev/null 2>&1; then :
+
+else
+ ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+ # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <stdlib.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "free" >/dev/null 2>&1; then :
+
+else
+ ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+ # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+ if test "$cross_compiling" = yes; then :
+ :
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <ctype.h>
+#include <stdlib.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#else
+# define ISLOWER(c) \
+ (('a' <= (c) && (c) <= 'i') \
+ || ('j' <= (c) && (c) <= 'r') \
+ || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
+#endif
+
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int
+main ()
+{
+ int i;
+ for (i = 0; i < 256; i++)
+ if (XOR (islower (i), ISLOWER (i))
+ || toupper (i) != TOUPPER (i))
+ return 2;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+
+else
+ ac_cv_header_stdc=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5
+$as_echo "$ac_cv_header_stdc" >&6; }
+if test $ac_cv_header_stdc = yes; then
+
+$as_echo "#define STDC_HEADERS 1" >>confdefs.h
+
+fi
+
+# On IRIX 5.3, sys/types and inttypes.h are conflicting.
+for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
+ inttypes.h stdint.h unistd.h
+do :
+ as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default
+"
+if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+ cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+
+ ac_fn_c_check_header_mongrel "$LINENO" "minix/config.h" "ac_cv_header_minix_config_h" "$ac_includes_default"
+if test "x$ac_cv_header_minix_config_h" = xyes; then :
+ MINIX=yes
+else
+ MINIX=
+fi
+
+
+ if test "$MINIX" = yes; then
+
+$as_echo "#define _POSIX_SOURCE 1" >>confdefs.h
+
+
+$as_echo "#define _POSIX_1_SOURCE 2" >>confdefs.h
+
+
+$as_echo "#define _MINIX 1" >>confdefs.h
+
+ fi
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether it is safe to define __EXTENSIONS__" >&5
+$as_echo_n "checking whether it is safe to define __EXTENSIONS__... " >&6; }
+if ${ac_cv_safe_to_define___extensions__+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+# define __EXTENSIONS__ 1
+ $ac_includes_default
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_safe_to_define___extensions__=yes
+else
+ ac_cv_safe_to_define___extensions__=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_safe_to_define___extensions__" >&5
+$as_echo "$ac_cv_safe_to_define___extensions__" >&6; }
+ test $ac_cv_safe_to_define___extensions__ = yes &&
+ $as_echo "#define __EXTENSIONS__ 1" >>confdefs.h
+
+ $as_echo "#define _ALL_SOURCE 1" >>confdefs.h
+
+ $as_echo "#define _GNU_SOURCE 1" >>confdefs.h
+
+ $as_echo "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h
+
+ $as_echo "#define _TANDEM_SOURCE 1" >>confdefs.h
+
+
+
+if test "$cross_compiling" = yes; then :
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+main(){exit(0);}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+
+else
+
+if test $CC != cc ; then
+echo "Your $CC failed - restarting with CC=cc" 1>&6
+
+echo "" 1>&6
+
+CC=cc
+export CC
+exec $0 $configure_args
+fi
+
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+if test "$cross_compiling" = yes; then :
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+main(){exit(0);}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+
+else
+ exec 5>&2
+eval $ac_link
+echo "CC=$CC; CFLAGS=$CFLAGS; LIBS=$LIBS;" 1>&6
+
+echo "$ac_compile" 1>&6
+
+as_fn_error $? "Can't run the compiler - sorry" "$LINENO" 5
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+if test "$cross_compiling" = yes; then :
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+main()
+{
+ int __something_strange_();
+ __something_strange_(0);
+}
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+ as_fn_error $? "Your compiler does not set the exit status - sorry" "$LINENO" 5
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+for ac_prog in gawk mawk nawk awk
+do
+ # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_AWK+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$AWK"; then
+ ac_cv_prog_AWK="$AWK" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_prog_AWK="$ac_prog"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+AWK=$ac_cv_prog_AWK
+if test -n "$AWK"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5
+$as_echo "$AWK" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ test -n "$AWK" && break
+done
+
+
+ac_aux_dir=
+for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
+ if test -f "$ac_dir/install-sh"; then
+ ac_aux_dir=$ac_dir
+ ac_install_sh="$ac_aux_dir/install-sh -c"
+ break
+ elif test -f "$ac_dir/install.sh"; then
+ ac_aux_dir=$ac_dir
+ ac_install_sh="$ac_aux_dir/install.sh -c"
+ break
+ elif test -f "$ac_dir/shtool"; then
+ ac_aux_dir=$ac_dir
+ ac_install_sh="$ac_aux_dir/shtool install -c"
+ break
+ fi
+done
+if test -z "$ac_aux_dir"; then
+ as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5
+fi
+
+# These three variables are undocumented and unsupported,
+# and are intended to be withdrawn in a future Autoconf release.
+# They can cause serious problems if a builder's source tree is in a directory
+# whose full name contains unusual characters.
+ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var.
+ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var.
+ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var.
+
+
+# Find a good install program. We prefer a C program (faster),
+# so one script is as good as another. But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AmigaOS /C/install, which installs bootblocks on floppy discs
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# OS/2's system install, which has a completely different semantic
+# ./install, which can be erroneously created by make from ./install.sh.
+# Reject install programs that cannot install multiple files.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5
+$as_echo_n "checking for a BSD-compatible install... " >&6; }
+if test -z "$INSTALL"; then
+if ${ac_cv_path_install+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ # Account for people who put trailing slashes in PATH elements.
+case $as_dir/ in #((
+ ./ | .// | /[cC]/* | \
+ /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \
+ ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \
+ /usr/ucb/* ) ;;
+ *)
+ # OSF1 and SCO ODT 3.0 have their own names for install.
+ # Don't use installbsd from OSF since it installs stuff as root
+ # by default.
+ for ac_prog in ginstall scoinst install; do
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then
+ if test $ac_prog = install &&
+ grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+ # AIX install. It has an incompatible calling convention.
+ :
+ elif test $ac_prog = install &&
+ grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+ # program-specific install script used by HP pwplus--don't use.
+ :
+ else
+ rm -rf conftest.one conftest.two conftest.dir
+ echo one > conftest.one
+ echo two > conftest.two
+ mkdir conftest.dir
+ if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" &&
+ test -s conftest.one && test -s conftest.two &&
+ test -s conftest.dir/conftest.one &&
+ test -s conftest.dir/conftest.two
+ then
+ ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
+ break 3
+ fi
+ fi
+ fi
+ done
+ done
+ ;;
+esac
+
+ done
+IFS=$as_save_IFS
+
+rm -rf conftest.one conftest.two conftest.dir
+
+fi
+ if test "${ac_cv_path_install+set}" = set; then
+ INSTALL=$ac_cv_path_install
+ else
+ # As a last resort, use the slow shell script. Don't cache a
+ # value for INSTALL within a source directory, because that will
+ # break other packages using the cache if that directory is
+ # removed, or if the value is a relative name.
+ INSTALL=$ac_install_sh
+ fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5
+$as_echo "$INSTALL" >&6; }
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+
+if test -f etc/toolcheck; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for buggy tools..." >&5
+$as_echo "$as_me: checking for buggy tools..." >&6;}
+sh etc/toolcheck 1>&6
+fi
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if a system-wide socket dir should be used" >&5
+$as_echo_n "checking if a system-wide socket dir should be used... " >&6; }
+# Check whether --enable-socket-dir was given.
+if test "${enable_socket_dir+set}" = set; then :
+ enableval=$enable_socket_dir;
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no. ~/.screen will be used instead." >&5
+$as_echo "no. ~/.screen will be used instead." >&6; }
+
+else
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for the socket dir" >&5
+$as_echo_n "checking for the socket dir... " >&6; }
+ SOCKDIR="(eff_uid ? \"/tmp/uscreens\" : \"/tmp/screens\")"
+
+# Check whether --with-socket-dir was given.
+if test "${with_socket_dir+set}" = set; then :
+ withval=$with_socket_dir;
+ case "${withval}" in
+ *\"*) SOCKDIR="${withval}" ;;
+ *) SOCKDIR="\"${withval}\"" ;;
+ esac
+
+fi
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${SOCKDIR}" >&5
+$as_echo "${SOCKDIR}" >&6; }
+ cat >>confdefs.h <<_ACEOF
+#define SOCKDIR $SOCKDIR
+_ACEOF
+
+
+
+fi
+
+
+
+if test -n "$ISC"; then
+ $as_echo "#define ISC 1" >>confdefs.h
+ LIBS="$LIBS -linet"
+fi
+
+
+if test -f /sysV68 ; then
+$as_echo "#define sysV68 1" >>confdefs.h
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for MIPS..." >&5
+$as_echo "$as_me: checking for MIPS..." >&6;}
+if test -f /lib/libmld.a || test -f /usr/lib/libmld.a || test -f /usr/lib/cmplrs/cc/libmld.a; then
+oldlibs="$LIBS"
+test -f /bin/mx || LIBS="$LIBS -lmld" # for nlist. But not on alpha.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking mld library..." >&5
+$as_echo "$as_me: checking mld library..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+ LIBS="$oldlibs"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+if test -r /dev/ptc; then
+$as_echo "#define MIPS 1" >>confdefs.h
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking wait3..." >&5
+$as_echo "$as_me: checking wait3..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+wait3();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking wait2..." >&5
+$as_echo "$as_me: checking wait2..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+wait2();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ $as_echo "#define USE_WAIT2 1" >>confdefs.h
+ LIBS="$LIBS -lbsd" ; CC="$CC -I/usr/include/bsd"
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Ultrix..." >&5
+$as_echo "$as_me: checking for Ultrix..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#if defined(ultrix) || defined(__ultrix)
+ yes;
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "yes" >/dev/null 2>&1; then :
+ ULTRIX=1
+fi
+rm -f conftest*
+
+
+if test -f /usr/lib/libpyr.a ; then
+oldlibs="$LIBS"
+LIBS="$LIBS -lpyr"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Pyramid OSX..." >&5
+$as_echo "$as_me: checking Pyramid OSX..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+open_controlling_pty("")
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ $as_echo "#define OSX 1" >>confdefs.h
+
+else
+ LIBS="$oldlibs"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for butterfly..." >&5
+$as_echo "$as_me: checking for butterfly..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#if defined(butterfly)
+ yes;
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "yes" >/dev/null 2>&1; then :
+ butterfly=1
+fi
+rm -f conftest*
+
+
+if test -z "$butterfly"; then
+if test -n "$ULTRIX"; then
+ test -z "$GCC" && CC="$CC -YBSD"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for POSIX.1..." >&5
+$as_echo "$as_me: checking for POSIX.1..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <sys/types.h>
+#include <unistd.h>
+main () {
+#ifdef _POSIX_VERSION
+ yes;
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "yes" >/dev/null 2>&1; then :
+ echo "- you have a POSIX system" 1>&6
+ $as_echo "#define POSIX 1" >>confdefs.h
+ posix=1
+fi
+rm -f conftest*
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for System V..." >&5
+$as_echo "$as_me: checking for System V..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <sys/types.h>
+#include <signal.h>
+#include <fcntl.h>
+int
+main ()
+{
+int x = SIGCHLD | FNDELAY;
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+else
+ $as_echo "#define SYSV 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sequent/ptx..." >&5
+$as_echo "$as_me: checking for sequent/ptx..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#ifdef _SEQUENT_
+ yes;
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "yes" >/dev/null 2>&1; then :
+ LIBS="$LIBS -lsocket -linet";seqptx=1
+fi
+rm -f conftest*
+
+
+oldlibs="$LIBS"
+LIBS="$LIBS -lelf"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking SVR4..." >&5
+$as_echo "$as_me: checking SVR4..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <utmpx.h>
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ ac_fn_c_check_header_mongrel "$LINENO" "dwarf.h" "ac_cv_header_dwarf_h" "$ac_includes_default"
+if test "x$ac_cv_header_dwarf_h" = xyes; then :
+ $as_echo "#define SVR4 1" >>confdefs.h
+ $as_echo "#define BUGGYGETLOGIN 1" >>confdefs.h
+
+else
+ ac_fn_c_check_header_mongrel "$LINENO" "elf.h" "ac_cv_header_elf_h" "$ac_includes_default"
+if test "x$ac_cv_header_elf_h" = xyes; then :
+ $as_echo "#define SVR4 1" >>confdefs.h
+ $as_echo "#define BUGGYGETLOGIN 1" >>confdefs.h
+
+fi
+
+
+fi
+
+
+
+else
+ LIBS="$oldlibs"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+for ac_header in stropts.h string.h strings.h
+do :
+ as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
+if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+ cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Solaris 2.x..." >&5
+$as_echo "$as_me: checking for Solaris 2.x..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#if defined(SVR4) && defined(sun)
+ yes
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "yes" >/dev/null 2>&1; then :
+ LIBS="$LIBS -lsocket -lnsl -lkstat"
+fi
+rm -f conftest*
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking BSD job jontrol..." >&5
+$as_echo "$as_me: checking BSD job jontrol..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+int
+main ()
+{
+
+#ifdef POSIX
+tcsetpgrp(0, 0);
+#else
+int x = TIOCSPGRP;
+#ifdef SYSV
+setpgrp();
+#else
+int y = TIOCNOTTY;
+#endif
+#endif
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ echo "- you have jobcontrol" 1>&6
+ $as_echo "#define BSDJOBS 1" >>confdefs.h
+
+else
+ echo "- you don't have jobcontrol" 1>&6
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking setresuid..." >&5
+$as_echo "$as_me: checking setresuid..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+setresuid(0, 0, 0);
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ $as_echo "#define HAVE_SETRESUID 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking setreuid..." >&5
+$as_echo "$as_me: checking setreuid..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+setreuid(0, 0);
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ $as_echo "#define HAVE_SETREUID 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking seteuid..." >&5
+$as_echo "$as_me: checking seteuid..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+#if defined(linux) || defined(NeXT) || defined(_AUX_SOURCE) || defined(AUX) || defined(ultrix) || (defined(sun) && defined(SVR4)) || defined(ISC) || defined(sony_news)
+seteuid_is_broken(0);
+#else
+seteuid(0);
+#endif
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ $as_echo "#define HAVE_SETEUID 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking execvpe..." >&5
+$as_echo "$as_me: checking execvpe..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ execvpe(0, 0, 0);
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ $as_echo "#define HAVE_EXECVPE 1" >>confdefs.h
+
+CFLAGS="$CFLAGS -D_GNU_SOURCE"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking select..." >&5
+$as_echo "$as_me: checking select..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+select(0, 0, 0, 0, 0);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+ LIBS="$LIBS -lnet -lnsl"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking select with $LIBS..." >&5
+$as_echo "$as_me: checking select with $LIBS..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+select(0, 0, 0, 0, 0);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+ as_fn_error $? "!!! no select - no screen" "$LINENO" 5
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking fifos..." >&5
+$as_echo "$as_me: checking fifos..." >&6;}
+if test "$cross_compiling" = yes; then :
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* For select - According to POSIX 1003.1-2001 */
+#include <sys/select.h>
+
+/* For select - According to earlier standards */
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#ifndef O_NONBLOCK
+#define O_NONBLOCK O_NDELAY
+#endif
+#ifndef S_IFIFO
+#define S_IFIFO 0010000
+#endif
+
+char *fin = "/tmp/conftest$$";
+
+main()
+{
+ struct stat stb;
+ fd_set f;
+
+ (void)alarm(5);
+ unlink(fin);
+#ifdef POSIX
+ if (mkfifo(fin, 0777))
+#else
+ if (mknod(fin, S_IFIFO|0777, 0))
+#endif
+ exit(1);
+ if (stat(fin, &stb) || (stb.st_mode & S_IFIFO) != S_IFIFO)
+ exit(1);
+ close(0);
+#ifdef __386BSD__
+ /*
+ * The next test fails under 386BSD, but screen works using fifos.
+ * Fifos in O_RDWR mode are only used for the BROKEN_PIPE case and for
+ * the select() configuration test.
+ */
+ exit(0);
+#endif
+ if (open(fin, O_RDONLY | O_NONBLOCK))
+ exit(1);
+ if (fork() == 0)
+ {
+ close(0);
+ if (open(fin, O_WRONLY | O_NONBLOCK))
+ exit(1);
+ close(0);
+ if (open(fin, O_WRONLY | O_NONBLOCK))
+ exit(1);
+ if (write(0, "TEST", 4) == -1)
+ exit(1);
+ exit(0);
+ }
+ FD_SET(0, &f);
+ if (select(1, &f, 0, 0, 0) == -1)
+ exit(1);
+ exit(0);
+}
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+ echo "- your fifos are usable" 1>&6
+ fifo=1
+else
+ echo "- your fifos are not usable" 1>&6
+
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+rm -f /tmp/conftest*
+
+if test -n "$fifo"; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for broken fifo implementation..." >&5
+$as_echo "$as_me: checking for broken fifo implementation..." >&6;}
+if test "$cross_compiling" = yes; then :
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* For select - According to POSIX 1003.1-2001 */
+#include <sys/select.h>
+
+/* For select - According to earlier standards */
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#ifndef O_NONBLOCK
+#define O_NONBLOCK O_NDELAY
+#endif
+#ifndef S_IFIFO
+#define S_IFIFO 0010000
+#endif
+
+char *fin = "/tmp/conftest$$";
+
+main()
+{
+ struct timeval tv;
+ fd_set f;
+
+#ifdef POSIX
+ if (mkfifo(fin, 0600))
+#else
+ if (mknod(fin, S_IFIFO|0600, 0))
+#endif
+ exit(1);
+ close(0);
+ if (open(fin, O_RDONLY|O_NONBLOCK))
+ exit(1);
+ FD_SET(0, &f);
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ if (select(1, &f, 0, 0, &tv))
+ exit(1);
+ exit(0);
+}
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+ echo "- your implementation is ok" 1>&6
+
+else
+ echo "- you have a broken implementation" 1>&6
+ $as_echo "#define BROKEN_PIPE 1" >>confdefs.h
+ fifobr=1
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+rm -f /tmp/conftest*
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking sockets..." >&5
+$as_echo "$as_me: checking sockets..." >&6;}
+if test "$cross_compiling" = yes; then :
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* For select - According to POSIX 1003.1-2001 */
+#include <sys/select.h>
+
+/* For select - According to earlier standards */
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+char *son = "/tmp/conftest$$";
+
+main()
+{
+ int s1, s2, l;
+ struct sockaddr_un a;
+ fd_set f;
+
+ (void)alarm(5);
+ if ((s1 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+ exit(1);
+ a.sun_family = AF_UNIX;
+ strcpy(a.sun_path, son);
+ (void) unlink(son);
+ if (bind(s1, (struct sockaddr *) &a, strlen(son)+2) == -1)
+ exit(1);
+ if (listen(s1, 2))
+ exit(1);
+ if (fork() == 0)
+ {
+ if ((s2 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+ kill(getppid(), 3);
+ (void)connect(s2, (struct sockaddr *)&a, strlen(son) + 2);
+ if (write(s2, "HELLO", 5) == -1)
+ kill(getppid(), 3);
+ exit(0);
+ }
+ l = sizeof(a);
+ close(0);
+ if (accept(s1, &a, &l))
+ exit(1);
+ FD_SET(0, &f);
+ if (select(1, &f, 0, 0, 0) == -1)
+ exit(1);
+ exit(0);
+}
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+ echo "- your sockets are usable" 1>&6
+ sock=1
+else
+ echo "- your sockets are not usable" 1>&6
+
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+rm -f /tmp/conftest*
+
+if test -n "$sock"; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking socket implementation..." >&5
+$as_echo "$as_me: checking socket implementation..." >&6;}
+if test "$cross_compiling" = yes; then :
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* For select - According to POSIX 1003.1-2001 */
+#include <sys/select.h>
+
+/* For select - According to earlier standards */
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+char *son = "/tmp/conftest$$";
+
+main()
+{
+ int s;
+ struct stat stb;
+ struct sockaddr_un a;
+ if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+ exit(0);
+ a.sun_family = AF_UNIX;
+ strcpy(a.sun_path, son);
+ (void) unlink(son);
+ if (bind(s, (struct sockaddr *) &a, strlen(son)+2) == -1)
+ exit(0);
+ if (stat(son, &stb))
+ exit(1);
+ close(s);
+ exit(0);
+}
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+ echo "- you are normal" 1>&6
+
+else
+ echo "- unix domain sockets are not kept in the filesystem" 1>&6
+
+$as_echo "#define SOCK_NOT_IN_FS 1" >>confdefs.h
+ socknofs=1
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+rm -f /tmp/conftest*
+fi
+
+
+
+if test "$cross_compiling" = yes; then :
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* For select - According to POSIX 1003.1-2001 */
+#include <sys/select.h>
+
+/* For select - According to earlier standards */
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+#include <fcntl.h>
+
+char *nam = "/tmp/conftest$$";
+
+#ifndef O_NONBLOCK
+#define O_NONBLOCK O_NDELAY
+#ifndef S_IFIFO
+#define S_IFIFO 0010000
+
+
+main()
+{
+ fd_set f;
+
+#ifdef __FreeBSD__
+/* From Andrew A. Chernov (ache@astral.msk.su):
+ * opening RDWR fifo fails in BSD 4.4, but select return values are
+ * right.
+ */
+ exit(0);
+#endif
+ (void)alarm(5);
+#ifdef POSIX
+ if (mkfifo(nam, 0777))
+#else
+ if (mknod(nam, S_IFIFO|0777, 0))
+#endif
+ exit(1);
+ close(0);
+ if (open(nam, O_RDWR | O_NONBLOCK))
+ exit(1);
+ if (write(0, "TEST", 4) == -1)
+ exit(1);
+
+#else
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+main()
+{
+ int s1, s2, l;
+ struct sockaddr_un a;
+ fd_set f;
+
+ (void)alarm(5);
+ if ((s1 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+ exit(1);
+ a.sun_family = AF_UNIX;
+ strcpy(a.sun_path, nam);
+ (void) unlink(nam);
+ if (bind(s1, (struct sockaddr *) &a, strlen(nam)+2) == -1)
+ exit(1);
+ if (listen(s1, 2))
+ exit(1);
+ if (fork() == 0)
+ {
+ if ((s2 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+ kill(getppid(), 3);
+ (void)connect(s2, (struct sockaddr *)&a, strlen(nam) + 2);
+ if (write(s2, "HELLO", 5) == -1)
+ kill(getppid(), 3);
+ exit(0);
+ }
+ l = sizeof(a);
+ close(0);
+ if (accept(s1, (struct sockaddr *)&a, &l))
+ exit(1);
+#endif
+
+
+ FD_SET(0, &f);
+ if (select(1, &f, 0, 0, 0) == -1)
+ exit(1);
+ if (select(1, &f, &f, 0, 0) != 2)
+ exit(1);
+ exit(0);
+}
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+ echo "- select is ok" 1>&6
+
+else
+ echo "- select can't count" 1>&6
+ $as_echo "#define SELECT_BROKEN 1" >>confdefs.h
+
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for tgetent..." >&5
+$as_echo "$as_me: checking for tgetent..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+tgetent((char *)0, (char *)0);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+ olibs="$LIBS"
+LIBS="-lcurses $olibs"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking libcurses..." >&5
+$as_echo "$as_me: checking libcurses..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+#ifdef __hpux
+__sorry_hpux_libcurses_is_totally_broken_in_10_10();
+#else
+tgetent((char *)0, (char *)0);
+#endif
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+ LIBS="-ltermcap $olibs"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking libtermcap..." >&5
+$as_echo "$as_me: checking libtermcap..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+tgetent((char *)0, (char *)0);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+ LIBS="-ltermlib $olibs"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking libtermlib..." >&5
+$as_echo "$as_me: checking libtermlib..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+tgetent((char *)0, (char *)0);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+ LIBS="-lncursesw $olibs"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking libncursesw..." >&5
+$as_echo "$as_me: checking libncursesw..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+tgetent((char *)0, (char *)0);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+ LIBS="-ltinfow $olibs"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking libtinfow..." >&5
+$as_echo "$as_me: checking libtinfow..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+tgetent((char *)0, (char *)0);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+ LIBS="-lncurses $olibs"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking libncurses..." >&5
+$as_echo "$as_me: checking libncurses..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+tgetent((char *)0, (char *)0);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+ LIBS="-ltinfo $olibs"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking libtinfo..." >&5
+$as_echo "$as_me: checking libtinfo..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+tgetent((char *)0, (char *)0);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+ as_fn_error $? "!!! no tgetent - no screen" "$LINENO" 5
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+
+if test "$cross_compiling" = yes; then :
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+main()
+{
+ exit(strcmp(tgoto("%p1%d", 0, 1), "1") ? 0 : 1);
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+ echo "- you use the termcap database" 1>&6
+
+else
+ echo "- you use the terminfo database" 1>&6
+ $as_echo "#define TERMINFO 1" >>confdefs.h
+
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking ospeed..." >&5
+$as_echo "$as_me: checking ospeed..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+extern short ospeed;
+int
+main ()
+{
+ospeed=5;
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+ $as_echo "#define NEED_OSPEED 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for /dev/ptc..." >&5
+$as_echo "$as_me: checking for /dev/ptc..." >&6;}
+if test -r /dev/ptc; then
+$as_echo "#define HAVE_DEV_PTC 1" >>confdefs.h
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SVR4 ptys..." >&5
+$as_echo "$as_me: checking for SVR4 ptys..." >&6;}
+sysvr4ptys=
+if test -c /dev/ptmx ; then
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+ptsname(0);grantpt(0);unlockpt(0);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ $as_echo "#define HAVE_SVR4_PTYS 1" >>confdefs.h
+
+sysvr4ptys=1
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+
+for ac_func in getpt
+do :
+ ac_fn_c_check_func "$LINENO" "getpt" "ac_cv_func_getpt"
+if test "x$ac_cv_func_getpt" = xyes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_GETPT 1
+_ACEOF
+
+fi
+done
+
+
+if test -z "$sysvr4ptys"; then
+for ac_func in openpty
+do :
+ ac_fn_c_check_func "$LINENO" "openpty" "ac_cv_func_openpty"
+if test "x$ac_cv_func_openpty" = xyes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_OPENPTY 1
+_ACEOF
+
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for openpty in -lutil" >&5
+$as_echo_n "checking for openpty in -lutil... " >&6; }
+if ${ac_cv_lib_util_openpty+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_check_lib_save_LIBS=$LIBS
+LIBS="-lutil $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char openpty ();
+int
+main ()
+{
+return openpty ();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_lib_util_openpty=yes
+else
+ ac_cv_lib_util_openpty=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_util_openpty" >&5
+$as_echo "$ac_cv_lib_util_openpty" >&6; }
+if test "x$ac_cv_lib_util_openpty" = xyes; then :
+ $as_echo "#define HAVE_OPENPTY 1" >>confdefs.h
+ LIBS="$LIBS -lutil"
+fi
+
+fi
+done
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ptyranges..." >&5
+$as_echo "$as_me: checking for ptyranges..." >&6;}
+if test -d /dev/ptym ; then
+pdir='/dev/ptym'
+else
+pdir='/dev'
+fi
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#ifdef M_UNIX
+ yes;
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "yes" >/dev/null 2>&1; then :
+ ptys=`echo /dev/ptyp??`
+else
+ ptys=`echo $pdir/pty??`
+fi
+rm -f conftest*
+
+if test "$ptys" != "$pdir/pty??" ; then
+p0=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\).$/\1/g' | sort -u | tr -d '\012'`
+p1=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\)$/\1/g' | sort -u | tr -d '\012'`
+cat >>confdefs.h <<_ACEOF
+#define PTYRANGE0 "$p0"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PTYRANGE1 "$p1"
+_ACEOF
+
+fi
+
+
+# Check whether --with-pty-mode was given.
+if test "${with_pty_mode+set}" = set; then :
+ withval=$with_pty_mode; ptymode="${withval}"
+fi
+
+
+# Check whether --with-pty-group was given.
+if test "${with_pty_group+set}" = set; then :
+ withval=$with_pty_group; ptygrp="${withval}"
+fi
+
+test -n "$ptymode" || ptymode=0620
+if test -n "$ptygrp" ; then
+cat >>confdefs.h <<_ACEOF
+#define PTYMODE $ptymode
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PTYGROUP $ptygrp
+_ACEOF
+
+else
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking default tty permissions/group..." >&5
+$as_echo "$as_me: checking default tty permissions/group..." >&6;}
+rm -f conftest_grp
+if test "$cross_compiling" = yes; then :
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+main()
+{
+ struct stat sb;
+ char *x,*ttyname();
+ int om, m;
+ FILE *fp;
+
+ if (!(x = ttyname(0))) exit(1);
+ if (stat(x, &sb)) exit(1);
+ om = sb.st_mode;
+ if (om & 002) exit(0);
+ m = system("mesg y");
+ if (m == -1 || m == 127) exit(1);
+ if (stat(x, &sb)) exit(1);
+ m = sb.st_mode;
+ if (chmod(x, om)) exit(1);
+ if (m & 002) exit(0);
+ if (sb.st_gid == getgid()) exit(1);
+ if (!(fp=fopen("conftest_grp", "w")))
+ exit(1);
+ fprintf(fp, "%d\n", sb.st_gid);
+ fclose(fp);
+ exit(0);
+}
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+
+ if test -f conftest_grp; then
+ ptygrp=`cat conftest_grp`
+ echo "- pty mode: $ptymode, group: $ptygrp" 1>&6
+
+ cat >>confdefs.h <<_ACEOF
+#define PTYMODE $ptymode
+_ACEOF
+
+ cat >>confdefs.h <<_ACEOF
+#define PTYGROUP $ptygrp
+_ACEOF
+
+ else
+ echo "- ptys are world accessable" 1>&6
+
+ fi
+
+else
+
+ WRITEPATH=''
+ XTERMPATH=''
+ # Extract the first word of "write", so it can be a program name with args.
+set dummy write; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_WRITEPATH+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ case $WRITEPATH in
+ [\\/]* | ?:[\\/]*)
+ ac_cv_path_WRITEPATH="$WRITEPATH" # Let the user override the test with a path.
+ ;;
+ *)
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_path_WRITEPATH="$as_dir/$ac_word$ac_exec_ext"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+ ;;
+esac
+fi
+WRITEPATH=$ac_cv_path_WRITEPATH
+if test -n "$WRITEPATH"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $WRITEPATH" >&5
+$as_echo "$WRITEPATH" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ # Extract the first word of "xterm", so it can be a program name with args.
+set dummy xterm; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_XTERMPATH+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ case $XTERMPATH in
+ [\\/]* | ?:[\\/]*)
+ ac_cv_path_XTERMPATH="$XTERMPATH" # Let the user override the test with a path.
+ ;;
+ *)
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_path_XTERMPATH="$as_dir/$ac_word$ac_exec_ext"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+ ;;
+esac
+fi
+XTERMPATH=$ac_cv_path_XTERMPATH
+if test -n "$XTERMPATH"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XTERMPATH" >&5
+$as_echo "$XTERMPATH" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ found=
+ if test -n "$WRITEPATH$XTERMPATH"; then
+ findfollow=
+ lsfollow=
+ found=`find $WRITEPATH $XTERMPATH -follow -print 2>/dev/null`
+ if test -n "$found"; then
+ findfollow=-follow
+ lsfollow=L
+ fi
+ if test -n "$XTERMPATH"; then
+ ptygrpn=`ls -l$lsfollow $XTERMPATH | sed -n -e 1p | $AWK '{print $4}'`
+ if test tty != "$ptygrpn"; then
+ XTERMPATH=
+ fi
+ fi
+ fi
+ if test -n "$WRITEPATH$XTERMPATH"; then
+ found=`find $WRITEPATH $XTERMPATH $findfollow -perm -2000 -print`
+ if test -n "$found"; then
+ ptygrp=`ls -ln$lsfollow $found | sed -n -e 1p | $AWK '{print $4}'`
+ echo "- pty mode: $ptymode, group: $ptygrp" 1>&6
+
+ cat >>confdefs.h <<_ACEOF
+#define PTYMODE $ptymode
+_ACEOF
+
+ cat >>confdefs.h <<_ACEOF
+#define PTYGROUP $ptygrp
+_ACEOF
+
+ else
+ echo "- ptys are world accessable" 1>&6
+
+ fi
+ else
+ echo "- can't determine - assume ptys are world accessable" 1>&6
+
+ fi
+
+
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+rm -f conftest_grp
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking getutent..." >&5
+$as_echo "$as_me: checking getutent..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <time.h> /* to get time_t on SCO */
+#include <sys/types.h>
+#if defined(SVR4) && !defined(DGUX)
+#include <utmpx.h>
+#define utmp utmpx
+#else
+#include <utmp.h>
+#endif
+#ifdef __hpux
+#define pututline _pututline
+#endif
+
+int
+main ()
+{
+int x = DEAD_PROCESS; pututline((struct utmp *)0); getutent();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ $as_echo "#define GETUTENT 1" >>confdefs.h
+
+else
+ olibs="$LIBS"
+LIBS="$LIBS -lgen"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking getutent with -lgen..." >&5
+$as_echo "$as_me: checking getutent with -lgen..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <time.h>
+#include <sys/types.h>
+#if defined(SVR4) && !defined(DGUX)
+#include <utmpx.h>
+#define utmp utmpx
+#else
+#include <utmp.h>
+#endif
+#ifdef __hpux
+#define pututline _pututline
+#endif
+
+int
+main ()
+{
+int x = DEAD_PROCESS; pututline((struct utmp *)0); getutent();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ $as_echo "#define GETUTENT 1" >>confdefs.h
+
+else
+ LIBS="$olibs"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking ut_host..." >&5
+$as_echo "$as_me: checking ut_host..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <time.h>
+#include <sys/types.h>
+#if defined(SVR4) && !defined(DGUX)
+#include <utmpx.h>
+#define utmp utmpx
+#else
+#include <utmp.h>
+#endif
+
+int
+main ()
+{
+struct utmp u; u.ut_host[0] = 0;
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ $as_echo "#define UTHOST 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_fn_c_check_header_mongrel "$LINENO" "utempter.h" "ac_cv_header_utempter_h" "$ac_includes_default"
+if test "x$ac_cv_header_utempter_h" = xyes; then :
+ have_utempter=yes
+else
+ have_utempter=no
+fi
+
+
+if test "$have_utempter" = yes; then
+ $as_echo "#define HAVE_UTEMPTER 1" >>confdefs.h
+
+ LIBS="$LIBS -lutempter"
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libutil(s)..." >&5
+$as_echo "$as_me: checking for libutil(s)..." >&6;}
+test -f /usr/lib/libutils.a && LIBS="$LIBS -lutils"
+test -f /usr/lib/libutil.a && LIBS="$LIBS -lutil"
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking getloadavg..." >&5
+$as_echo "$as_me: checking getloadavg..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+getloadavg((double *)0, 0);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ $as_echo "#define LOADAV_GETLOADAVG 1" >>confdefs.h
+ load=1
+else
+ if test -f /usr/lib/libkvm.a ; then
+olibs="$LIBS"
+LIBS="$LIBS -lkvm"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking getloadavg with -lkvm..." >&5
+$as_echo "$as_me: checking getloadavg with -lkvm..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+getloadavg((double *)0, 0);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ $as_echo "#define LOADAV_GETLOADAVG 1" >>confdefs.h
+ load=1
+else
+ LIBS="$olibs"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+
+if test -z "$load" ; then
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#if defined(NeXT) || defined(apollo) || defined(linux)
+ yes;
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "yes" >/dev/null 2>&1; then :
+ load=1
+fi
+rm -f conftest*
+
+fi
+if test -z "$load" ; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for kernelfile..." >&5
+$as_echo "$as_me: checking for kernelfile..." >&6;}
+for core in /unix /vmunix /dynix /hp-ux /xelos /dev/ksyms /kernel/unix /kernel/genunix /unicos /mach /netbsd /386bsd /dgux /bsd /stand/vmunix; do
+ if test -f $core || test -c $core; then
+ break
+ fi
+done
+if test ! -f $core && test ! -c $core ; then
+ echo "- no kernelfile found" 1>&6
+
+else
+ echo "- using kernelfile '$core'" 1>&6
+
+ if test -r $core ; then
+ cat >>confdefs.h <<_ACEOF
+#define LOADAV_UNIX "$core"
+_ACEOF
+
+ ac_fn_c_check_header_mongrel "$LINENO" "nlist.h" "ac_cv_header_nlist_h" "$ac_includes_default"
+if test "x$ac_cv_header_nlist_h" = xyes; then :
+ $as_echo "#define NLIST_STRUCT 1" >>confdefs.h
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking n_un in struct nlist..." >&5
+$as_echo "$as_me: checking n_un in struct nlist..." >&6;}
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <nlist.h>
+int
+main ()
+{
+struct nlist n; n.n_un.n_name = 0;
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ $as_echo "#define NLIST_NAME_UNION 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for nlist declaration..." >&5
+$as_echo "$as_me: checking for nlist declaration..." >&6;}
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#ifdef NLIST_STRUCT
+# include <nlist.h>
+#else
+# include <a.out.h>
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "nlist(( | )( | )*.*\(|\()" >/dev/null 2>&1; then :
+ $as_echo "#define NLIST_DECLARED 1" >>confdefs.h
+
+fi
+rm -f conftest*
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for avenrun symbol..." >&5
+$as_echo "$as_me: checking for avenrun symbol..." >&6;}
+ nlist64=
+ for av in avenrun _avenrun _Loadavg avenrun _avenrun _Loadavg; do
+ if test "$cross_compiling" = yes; then :
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <sys/types.h>
+#ifdef NLIST_STRUCT
+#include <nlist.h>
+#else
+#include <a.out.h>
+#endif
+
+$nlist64
+
+struct nlist nl[2];
+
+main()
+{
+#if !defined(_AUX_SOURCE) && !defined(AUX)
+# ifdef NLIST_NAME_UNION
+ nl[0].n_un.n_name = "$av";
+# else
+ nl[0].n_name = "$av";
+# endif
+#else
+ strncpy(nl[0].n_name, "$av", sizeof(nl[0].n_name));
+#endif
+ nlist(LOADAV_UNIX, nl);
+ if (nl[0].n_value == 0)
+ exit(1);
+ exit(0);
+}
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+ avensym=$av;break
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+ if test "$av" = _Loadavg; then
+ nlist64='#define nlist nlist64'
+ fi
+ done
+ if test -z "$avensym" ; then
+ echo "- no avenrun symbol found" 1>&6
+
+ else
+ echo "- using avenrun symbol '$avensym'" 1>&6
+
+ cat >>confdefs.h <<_ACEOF
+#define LOADAV_AVENRUN "$avensym"
+_ACEOF
+
+ if test -n "$nlist64"; then
+ echo "- used nlist64 to find it" 1>&6
+
+ $as_echo "#define LOADAV_USE_NLIST64 1" >>confdefs.h
+
+ fi
+ load=1
+ fi
+ else
+ echo "Can't configure the load average display feature" 1>&6
+
+ echo "because $core is not readable by you." 1>&6
+
+ echo "To configure the load average display feature" 1>&6
+
+ echo "re-run configure as root if possible." 1>&6
+
+ echo "If you are not the system administrator then disregard" 1>&6
+
+ echo "this warning. You can still use screen without" 1>&6
+
+ echo "the load average display feature." 1>&6
+
+ fi
+fi
+fi
+
+cat > conftest.c <<EOF
+#include "confdefs.h"
+
+#include <sys/types.h>
+#include <sys/param.h>
+
+_CUT_HERE_
+
+#if !defined(LOADAV_GETLOADAVG) && ((defined(hp300) && !defined(__hpux)) || defined(sun) || (defined(ultrix) && defined(mips)) || defined(_SEQUENT_) || defined(sgi) || (defined(SVR4) && !defined(__hpux)) || defined(sony_news) || (!defined(__osf__) && defined(__alpha)) || defined(_IBMR2) || defined(_AUX_SOURCE) || defined(AUX) || defined(m88k))
+loadtype=long
+# if defined(apollo) || defined(_IBMR2) || defined(_AUX_SOURCE) || defined(AUX)
+loadscale=65536
+# else
+# if defined(FSCALE) && !defined(__osf__)
+# undef FSCALE
+loadscale=FSCALE
+# else
+# ifdef sgi
+loadtype=int
+loadscale=1024
+# else
+# if defined(MIPS) || defined(SVR4) || defined(m88k)
+loadscale=256
+# else /* not MIPS */
+loadscale=1000 /* our default value */
+# endif /* MIPS */
+# endif /* sgi */
+# endif /* not FSCALE */
+# endif /* not apollo */
+#else
+loadtype=double
+loadscale=1
+#endif
+#ifdef alliant
+loadnum=4
+#else
+loadnum=3
+#endif
+
+EOF
+eval "$ac_cpp conftest.c 2>&5 | sed -e '1,/_CUT_HERE_/d' -e 's/ //g' > conftest.out"
+. ./conftest.out
+rm -f conftest*
+
+
+if test -n "$load" ; then $as_echo "#define LOADAV 1" >>confdefs.h
+ fi
+if test -n "$loadtype" ; then cat >>confdefs.h <<_ACEOF
+#define LOADAV_TYPE $loadtype
+_ACEOF
+ fi
+if test -n "$loadnum" ; then cat >>confdefs.h <<_ACEOF
+#define LOADAV_NUM $loadnum
+_ACEOF
+ fi
+if test -n "$loadscale" ; then cat >>confdefs.h <<_ACEOF
+#define LOADAV_SCALE $loadscale
+_ACEOF
+ fi
+
+if test -n "$posix" ; then
+
+echo "assuming posix signal definition" 1>&6
+
+$as_echo "#define SIGVOID 1" >>confdefs.h
+
+
+else
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking return type of signal handlers..." >&5
+$as_echo "$as_me: checking return type of signal handlers..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <sys/types.h>
+#include <signal.h>
+#ifdef signal
+#undef signal
+#endif
+extern void (*signal ()) ();
+int
+main ()
+{
+int i;
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ $as_echo "#define SIGVOID 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking sigset..." >&5
+$as_echo "$as_me: checking sigset..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <sys/types.h>
+#include <signal.h>
+
+int
+main ()
+{
+
+#ifdef SIGVOID
+sigset(0, (void (*)())0);
+#else
+sigset(0, (int (*)())0);
+#endif
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ $as_echo "#define USESIGSET 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking signal implementation..." >&5
+$as_echo "$as_me: checking signal implementation..." >&6;}
+if test "$cross_compiling" = yes; then :
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <sys/types.h>
+#include <signal.h>
+
+#ifndef SIGCLD
+#define SIGCLD SIGCHLD
+#endif
+#ifdef USESIGSET
+#define signal sigset
+#endif
+
+int got;
+
+#ifdef SIGVOID
+void
+#endif
+hand()
+{
+ got++;
+}
+
+main()
+{
+ /* on hpux we use sigvec to get bsd signals */
+#ifdef __hpux
+ (void)signal(SIGCLD, hand);
+ kill(getpid(), SIGCLD);
+ kill(getpid(), SIGCLD);
+ if (got < 2)
+ exit(1);
+#endif
+ exit(0);
+}
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+
+else
+ $as_echo "#define SYSVSIGS 1" >>confdefs.h
+
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for crypt and sec libraries..." >&5
+$as_echo "$as_me: checking for crypt and sec libraries..." >&6;}
+test -f /lib/libcrypt_d.a || test -f /usr/lib/libcrypt_d.a && LIBS="$LIBS -lcrypt_d"
+oldlibs="$LIBS"
+LIBS="$LIBS -lcrypt"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking crypt..." >&5
+$as_echo "$as_me: checking crypt..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+ LIBS="$oldlibs"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+test -f /lib/libsec.a || test -f /usr/lib/libsec.a && LIBS="$LIBS -lsec"
+test -f /lib/libshadow.a || test -f /usr/lib/libshadow.a && LIBS="$LIBS -lshadow"
+oldlibs="$LIBS"
+LIBS="$LIBS -lsun"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking IRIX sun library..." >&5
+$as_echo "$as_me: checking IRIX sun library..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+ LIBS="$oldlibs"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking syslog..." >&5
+$as_echo "$as_me: checking syslog..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+closelog();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+ oldlibs="$LIBS"
+LIBS="$LIBS -lbsd"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking syslog in libbsd.a..." >&5
+$as_echo "$as_me: checking syslog in libbsd.a..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+closelog();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ echo "- found." 1>&6
+
+else
+ LIBS="$oldlibs"
+echo "- bad news: syslog missing." 1>&6
+ $as_echo "#define NOSYSLOG 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#ifdef M_UNIX
+ yes;
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "yes" >/dev/null 2>&1; then :
+ LIBS="$LIBS -lsocket -lcrypt_i"
+fi
+rm -f conftest*
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking wait union..." >&5
+$as_echo "$as_me: checking wait union..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <sys/types.h>
+#include <sys/wait.h>
+
+int
+main ()
+{
+
+ union wait x;
+ int y;
+#ifdef WEXITSTATUS
+ y = WEXITSTATUS(x);
+#endif
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ $as_echo "#define BSDWAIT 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test -z "$butterfly"; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for termio or termios..." >&5
+$as_echo "$as_me: checking for termio or termios..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <termio.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+ $as_echo "#define TERMIO 1" >>confdefs.h
+
+else
+ if test -n "$posix"; then
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <termios.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+ $as_echo "#define TERMIO 1" >>confdefs.h
+
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+fi
+
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking getspnam..." >&5
+$as_echo "$as_me: checking getspnam..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <shadow.h>
+int
+main ()
+{
+getspnam("x");
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ $as_echo "#define SHADOWPW 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking getttyent..." >&5
+$as_echo "$as_me: checking getttyent..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+getttyent();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ $as_echo "#define GETTTYENT 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking fdwalk..." >&5
+$as_echo "$as_me: checking fdwalk..." >&6;}
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <stdlib.h>
+int
+main ()
+{
+fdwalk(NULL, NULL);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ $as_echo "#define HAVE_FDWALK 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether memcpy/memmove/bcopy handles overlapping arguments..." >&5
+$as_echo "$as_me: checking whether memcpy/memmove/bcopy handles overlapping arguments..." >&6;}
+if test "$cross_compiling" = yes; then :
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+main() {
+ char buf[10];
+ strcpy(buf, "abcdefghi");
+ bcopy(buf, buf + 2, 3);
+ if (strncmp(buf, "ababcf", 6))
+ exit(1);
+ strcpy(buf, "abcdefghi");
+ bcopy(buf + 2, buf, 3);
+ if (strncmp(buf, "cdedef", 6))
+ exit(1);
+ exit(0); /* libc version works properly. */
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+ $as_echo "#define USEBCOPY 1" >>confdefs.h
+
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+if test "$cross_compiling" = yes; then :
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#define bcopy(s,d,l) memmove(d,s,l)
+main() {
+ char buf[10];
+ strcpy(buf, "abcdefghi");
+ bcopy(buf, buf + 2, 3);
+ if (strncmp(buf, "ababcf", 6))
+ exit(1);
+ strcpy(buf, "abcdefghi");
+ bcopy(buf + 2, buf, 3);
+ if (strncmp(buf, "cdedef", 6))
+ exit(1);
+ exit(0); /* libc version works properly. */
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+ $as_echo "#define USEMEMMOVE 1" >>confdefs.h
+
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+
+if test "$cross_compiling" = yes; then :
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#define bcopy(s,d,l) memcpy(d,s,l)
+main() {
+ char buf[10];
+ strcpy(buf, "abcdefghi");
+ bcopy(buf, buf + 2, 3);
+ if (strncmp(buf, "ababcf", 6))
+ exit(1);
+ strcpy(buf, "abcdefghi");
+ bcopy(buf + 2, buf, 3);
+ if (strncmp(buf, "cdedef", 6))
+ exit(1);
+ exit(0); /* libc version works properly. */
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+ $as_echo "#define USEMEMCPY 1" >>confdefs.h
+
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for long file names" >&5
+$as_echo_n "checking for long file names... " >&6; }
+if ${ac_cv_sys_long_file_names+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_cv_sys_long_file_names=yes
+# Test for long file names in all the places we know might matter:
+# . the current directory, where building will happen
+# $prefix/lib where we will be installing things
+# $exec_prefix/lib likewise
+# $TMPDIR if set, where it might want to write temporary files
+# /tmp where it might want to write temporary files
+# /var/tmp likewise
+# /usr/tmp likewise
+for ac_dir in . "$TMPDIR" /tmp /var/tmp /usr/tmp "$prefix/lib" "$exec_prefix/lib"; do
+ # Skip $TMPDIR if it is empty or bogus, and skip $exec_prefix/lib
+ # in the usual case where exec_prefix is '${prefix}'.
+ case $ac_dir in #(
+ . | /* | ?:[\\/]*) ;; #(
+ *) continue;;
+ esac
+ test -w "$ac_dir/." || continue # It is less confusing to not echo anything here.
+ ac_xdir=$ac_dir/cf$$
+ (umask 077 && mkdir "$ac_xdir" 2>/dev/null) || continue
+ ac_tf1=$ac_xdir/conftest9012345
+ ac_tf2=$ac_xdir/conftest9012346
+ touch "$ac_tf1" 2>/dev/null && test -f "$ac_tf1" && test ! -f "$ac_tf2" ||
+ ac_cv_sys_long_file_names=no
+ rm -f -r "$ac_xdir" 2>/dev/null
+ test $ac_cv_sys_long_file_names = no && break
+done
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_long_file_names" >&5
+$as_echo "$ac_cv_sys_long_file_names" >&6; }
+if test $ac_cv_sys_long_file_names = yes; then
+
+$as_echo "#define HAVE_LONG_FILE_NAMES 1" >>confdefs.h
+
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for vsprintf" >&5
+$as_echo_n "checking for vsprintf... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <stdarg.h>
+int
+main ()
+{
+va_list valist; vsprintf(0,0,valist);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; };$as_echo "#define USEVARARGS 1" >>confdefs.h
+
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+
+ac_header_dirent=no
+for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h; do
+ as_ac_Header=`$as_echo "ac_cv_header_dirent_$ac_hdr" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_hdr that defines DIR" >&5
+$as_echo_n "checking for $ac_hdr that defines DIR... " >&6; }
+if eval \${$as_ac_Header+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <sys/types.h>
+#include <$ac_hdr>
+
+int
+main ()
+{
+if ((DIR *) 0)
+return 0;
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ eval "$as_ac_Header=yes"
+else
+ eval "$as_ac_Header=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$as_ac_Header
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+ cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_hdr" | $as_tr_cpp` 1
+_ACEOF
+
+ac_header_dirent=$ac_hdr; break
+fi
+
+done
+# Two versions of opendir et al. are in -ldir and -lx on SCO Xenix.
+if test $ac_header_dirent = dirent.h; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing opendir" >&5
+$as_echo_n "checking for library containing opendir... " >&6; }
+if ${ac_cv_search_opendir+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char opendir ();
+int
+main ()
+{
+return opendir ();
+ ;
+ return 0;
+}
+_ACEOF
+for ac_lib in '' dir; do
+ if test -z "$ac_lib"; then
+ ac_res="none required"
+ else
+ ac_res=-l$ac_lib
+ LIBS="-l$ac_lib $ac_func_search_save_LIBS"
+ fi
+ if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_search_opendir=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext
+ if ${ac_cv_search_opendir+:} false; then :
+ break
+fi
+done
+if ${ac_cv_search_opendir+:} false; then :
+
+else
+ ac_cv_search_opendir=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_opendir" >&5
+$as_echo "$ac_cv_search_opendir" >&6; }
+ac_res=$ac_cv_search_opendir
+if test "$ac_res" != no; then :
+ test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing opendir" >&5
+$as_echo_n "checking for library containing opendir... " >&6; }
+if ${ac_cv_search_opendir+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char opendir ();
+int
+main ()
+{
+return opendir ();
+ ;
+ return 0;
+}
+_ACEOF
+for ac_lib in '' x; do
+ if test -z "$ac_lib"; then
+ ac_res="none required"
+ else
+ ac_res=-l$ac_lib
+ LIBS="-l$ac_lib $ac_func_search_save_LIBS"
+ fi
+ if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_search_opendir=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext
+ if ${ac_cv_search_opendir+:} false; then :
+ break
+fi
+done
+if ${ac_cv_search_opendir+:} false; then :
+
+else
+ ac_cv_search_opendir=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_opendir" >&5
+$as_echo "$ac_cv_search_opendir" >&6; }
+ac_res=$ac_cv_search_opendir
+if test "$ac_res" != no; then :
+ test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for setenv" >&5
+$as_echo_n "checking for setenv... " >&6; }
+if test -z "$ac_setenv_args"; then
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <stdlib.h>
+int
+main ()
+{
+
+ setenv((char *) 0, (char *) 0, 0);
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ ac_setenv_args=3
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+if test -z "$ac_setenv_args"; then
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <stdlib.h>
+int
+main ()
+{
+
+ setenv((char *) 0, (char *) 0);
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ ac_setenv_args=2
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+if test -n "$ac_setenv_args"; then
+ $as_echo "#define USESETENV 1" >>confdefs.h
+
+ if test "$ac_setenv_args" = 3; then
+ $as_echo "#define HAVE_SETENV_3 1" >>confdefs.h
+
+ elif test "$ac_setenv_args" = 2; then
+ $as_echo "#define HAVE_SETENV_2 1" >>confdefs.h
+
+ fi
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for putenv" >&5
+$as_echo_n "checking for putenv... " >&6; }
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+putenv((char *)0);unsetenv((char *)0);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; };$as_echo "#define NEEDPUTENV 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for nl_langinfo(CODESET)" >&5
+$as_echo_n "checking for nl_langinfo(CODESET)... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <langinfo.h>
+
+int
+main ()
+{
+nl_langinfo(CODESET);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; };$as_echo "#define HAVE_NL_LANGINFO 1" >>confdefs.h
+
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing gethostname" >&5
+$as_echo_n "checking for library containing gethostname... " >&6; }
+if ${ac_cv_search_gethostname+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char gethostname ();
+int
+main ()
+{
+return gethostname ();
+ ;
+ return 0;
+}
+_ACEOF
+for ac_lib in '' nsl; do
+ if test -z "$ac_lib"; then
+ ac_res="none required"
+ else
+ ac_res=-l$ac_lib
+ LIBS="-l$ac_lib $ac_func_search_save_LIBS"
+ fi
+ if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_search_gethostname=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext
+ if ${ac_cv_search_gethostname+:} false; then :
+ break
+fi
+done
+if ${ac_cv_search_gethostname+:} false; then :
+
+else
+ ac_cv_search_gethostname=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_gethostname" >&5
+$as_echo "$ac_cv_search_gethostname" >&6; }
+ac_res=$ac_cv_search_gethostname
+if test "$ac_res" != no; then :
+ test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+
+for ac_func in rename fchmod fchown strerror lstat _exit utimes vsnprintf getcwd setlocale strftime
+do :
+ as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
+ cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
+# Check whether --enable-pam was given.
+if test "${enable_pam+set}" = set; then :
+ enableval=$enable_pam;
+fi
+
+if test "$enable_pam" = "yes"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for PAM support" >&5
+$as_echo_n "checking for PAM support... " >&6; }
+ oldlibs="$LIBS"
+ LIBS="$LIBS -lpam"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <security/pam_appl.h>
+int
+main ()
+{
+
+ pam_start(0, 0, 0, 0);
+ pam_authenticate(0, 0);
+ pam_end(0,0);
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; };$as_echo "#define USE_PAM 1" >>confdefs.h
+
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; };LIBS="$oldlibs"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+
+# Check whether --enable-use_locale was given.
+if test "${enable_use_locale+set}" = set; then :
+ enableval=$enable_use_locale;
+fi
+
+if test "$enable_use_locale" = "yes"; then
+ $as_echo "#define USE_LOCALE 1" >>confdefs.h
+
+fi
+# Check whether --enable-telnet was given.
+if test "${enable_telnet+set}" = set; then :
+ enableval=$enable_telnet;
+fi
+
+if test "$enable_telnet" = "yes"; then
+ $as_echo "#define BUILTIN_TELNET 1" >>confdefs.h
+
+fi
+# Check whether --enable-colors256 was given.
+if test "${enable_colors256+set}" = set; then :
+ enableval=$enable_colors256;
+fi
+
+if test "$enable_colors256" = "yes"; then
+ $as_echo "#define COLORS256 1" >>confdefs.h
+
+fi
+# Check whether --enable-rxvt_osc was given.
+if test "${enable_rxvt_osc+set}" = set; then :
+ enableval=$enable_rxvt_osc;
+fi
+
+if test "$enable_rxvt_osc" = "yes"; then
+ $as_echo "#define RXVT_OSC 1" >>confdefs.h
+
+fi
+
+if test -z "$old_CFLAGS"; then
+ if test "x$CFLAGS" = "x-g"; then
+ CFLAGS="-O"
+ fi
+fi
+test -n "$seqptx" && LIBS="-ltermcap -lc -lsocket -linet -lnsl -lsec -lseq"
+
+if test "$cross_compiling" = yes; then :
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+main(){exit(0);}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+
+else
+ as_fn_error $? "Can't run the compiler - internal error. Sorry." "$LINENO" 5
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+ETCSCREENRC=
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for the global screenrc file" >&5
+$as_echo_n "checking for the global screenrc file... " >&6; }
+
+# Check whether --with-sys-screenrc was given.
+if test "${with_sys_screenrc+set}" = set; then :
+ withval=$with_sys_screenrc; ETCSCREENRC="${withval}"
+fi
+
+
+
+ac_config_files="$ac_config_files Makefile doc/Makefile"
+
+ac_config_commands="$ac_config_commands default"
+
+cat >confcache <<\_ACEOF
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems. If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+_ACEOF
+
+# The following way of writing the cache mishandles newlines in values,
+# but we know of no workaround that is simple, portable, and efficient.
+# So, we kill variables containing newlines.
+# Ultrix sh set writes to stderr and can't be redirected directly,
+# and sets the high bit in the cache file unless we assign to the vars.
+(
+ for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do
+ eval ac_val=\$$ac_var
+ case $ac_val in #(
+ *${as_nl}*)
+ case $ac_var in #(
+ *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+ esac
+ case $ac_var in #(
+ _ | IFS | as_nl) ;; #(
+ BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+ *) { eval $ac_var=; unset $ac_var;} ;;
+ esac ;;
+ esac
+ done
+
+ (set) 2>&1 |
+ case $as_nl`(ac_space=' '; set) 2>&1` in #(
+ *${as_nl}ac_space=\ *)
+ # `set' does not quote correctly, so add quotes: double-quote
+ # substitution turns \\\\ into \\, and sed turns \\ into \.
+ sed -n \
+ "s/'/'\\\\''/g;
+ s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
+ ;; #(
+ *)
+ # `set' quotes correctly as required by POSIX, so do not add quotes.
+ sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+ ;;
+ esac |
+ sort
+) |
+ sed '
+ /^ac_cv_env_/b end
+ t clear
+ :clear
+ s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
+ t end
+ s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
+ :end' >>confcache
+if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
+ if test -w "$cache_file"; then
+ if test "x$cache_file" != "x/dev/null"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
+$as_echo "$as_me: updating cache $cache_file" >&6;}
+ if test ! -f "$cache_file" || test -h "$cache_file"; then
+ cat confcache >"$cache_file"
+ else
+ case $cache_file in #(
+ */* | ?:*)
+ mv -f confcache "$cache_file"$$ &&
+ mv -f "$cache_file"$$ "$cache_file" ;; #(
+ *)
+ mv -f confcache "$cache_file" ;;
+ esac
+ fi
+ fi
+ else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
+$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
+ fi
+fi
+rm -f confcache
+
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+DEFS=-DHAVE_CONFIG_H
+
+ac_libobjs=
+ac_ltlibobjs=
+U=
+for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
+ # 1. Remove the extension, and $U if already installed.
+ ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
+ ac_i=`$as_echo "$ac_i" | sed "$ac_script"`
+ # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR
+ # will be set to the directory where LIBOBJS objects are built.
+ as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext"
+ as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo'
+done
+LIBOBJS=$ac_libobjs
+
+LTLIBOBJS=$ac_ltlibobjs
+
+
+
+: "${CONFIG_STATUS=./config.status}"
+ac_write_fail=0
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files $CONFIG_STATUS"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
+$as_echo "$as_me: creating $CONFIG_STATUS" >&6;}
+as_write_fail=0
+cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1
+#! $SHELL
+# Generated by $as_me.
+# Run this file to recreate the current configuration.
+# Compiler output produced by configure, useful for debugging
+# configure, is in config.log if it exists.
+
+debug=false
+ac_cs_recheck=false
+ac_cs_silent=false
+
+SHELL=\${CONFIG_SHELL-$SHELL}
+export SHELL
+_ASEOF
+cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+ emulate sh
+ NULLCMD=:
+ # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+ # is contrary to our usage. Disable this feature.
+ alias -g '${1+"$@"}'='"$@"'
+ setopt NO_GLOB_SUBST
+else
+ case `(set -o) 2>/dev/null` in #(
+ *posix*) :
+ set -o posix ;; #(
+ *) :
+ ;;
+esac
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+ as_echo='print -r --'
+ as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+ as_echo='printf %s\n'
+ as_echo_n='printf %s'
+else
+ if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+ as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+ as_echo_n='/usr/ucb/echo -n'
+ else
+ as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+ as_echo_n_body='eval
+ arg=$1;
+ case $arg in #(
+ *"$as_nl"*)
+ expr "X$arg" : "X\\(.*\\)$as_nl";
+ arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+ esac;
+ expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+ '
+ export as_echo_n_body
+ as_echo_n='sh -c $as_echo_n_body as_echo'
+ fi
+ export as_echo_body
+ as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+ PATH_SEPARATOR=:
+ (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+ (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+ PATH_SEPARATOR=';'
+ }
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order. Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" "" $as_nl"
+
+# Find who we are. Look in the path if we contain no directory separator.
+as_myself=
+case $0 in #((
+ *[\\/]* ) as_myself=$0 ;;
+ *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+ done
+IFS=$as_save_IFS
+
+ ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+ as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+ $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+ exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there. '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+
+# as_fn_error STATUS ERROR [LINENO LOG_FD]
+# ----------------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with STATUS, using 1 if that was 0.
+as_fn_error ()
+{
+ as_status=$1; test $as_status -eq 0 && as_status=1
+ if test "$4"; then
+ as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
+ fi
+ $as_echo "$as_me: error: $2" >&2
+ as_fn_exit $as_status
+} # as_fn_error
+
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+ return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+ set +e
+ as_fn_set_status $1
+ exit $1
+} # as_fn_exit
+
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+ { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+ eval 'as_fn_append ()
+ {
+ eval $1+=\$2
+ }'
+else
+ as_fn_append ()
+ {
+ eval $1=\$$1\$2
+ }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+ eval 'as_fn_arith ()
+ {
+ as_val=$(( $* ))
+ }'
+else
+ as_fn_arith ()
+ {
+ as_val=`expr "$@" || test $? -eq 1`
+ }
+fi # as_fn_arith
+
+
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+ test "X`expr 00001 : '.*\(...\)'`" = X001; then
+ as_expr=expr
+else
+ as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+ as_basename=basename
+else
+ as_basename=false
+fi
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+ as_dirname=dirname
+else
+ as_dirname=false
+fi
+
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+ X"$0" : 'X\(//\)$' \| \
+ X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+ sed '/^.*\/\([^/][^/]*\)\/*$/{
+ s//\1/
+ q
+ }
+ /^X\/\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\/\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
+
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in #(((((
+-n*)
+ case `echo 'xy\c'` in
+ *c*) ECHO_T=' ';; # ECHO_T is single tab character.
+ xy) ECHO_C='\c';;
+ *) echo `echo ksh88 bug on AIX 6.1` > /dev/null
+ ECHO_T=' ';;
+ esac;;
+*)
+ ECHO_N='-n';;
+esac
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+ rm -f conf$$.dir/conf$$.file
+else
+ rm -f conf$$.dir
+ mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+ if ln -s conf$$.file conf$$ 2>/dev/null; then
+ as_ln_s='ln -s'
+ # ... but there are two gotchas:
+ # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+ # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+ # In both cases, we have to default to `cp -pR'.
+ ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+ as_ln_s='cp -pR'
+ elif ln conf$$.file conf$$ 2>/dev/null; then
+ as_ln_s=ln
+ else
+ as_ln_s='cp -pR'
+ fi
+else
+ as_ln_s='cp -pR'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
+ case $as_dir in #(
+ -*) as_dir=./$as_dir;;
+ esac
+ test -d "$as_dir" || eval $as_mkdir_p || {
+ as_dirs=
+ while :; do
+ case $as_dir in #(
+ *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+ *) as_qdir=$as_dir;;
+ esac
+ as_dirs="'$as_qdir' $as_dirs"
+ as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$as_dir" : 'X\(//\)[^/]' \| \
+ X"$as_dir" : 'X\(//\)$' \| \
+ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)[^/].*/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
+ test -d "$as_dir" && break
+ done
+ test -z "$as_dirs" || eval "mkdir $as_dirs"
+ } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+if mkdir -p . 2>/dev/null; then
+ as_mkdir_p='mkdir -p "$as_dir"'
+else
+ test -d ./-p && rmdir ./-p
+ as_mkdir_p=false
+fi
+
+
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+ test -f "$1" && test -x "$1"
+} # as_fn_executable_p
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+exec 6>&1
+## ----------------------------------- ##
+## Main body of $CONFIG_STATUS script. ##
+## ----------------------------------- ##
+_ASEOF
+test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# Save the log message, to keep $0 and so on meaningful, and to
+# report actual input values of CONFIG_FILES etc. instead of their
+# values after options handling.
+ac_log="
+This file was extended by $as_me, which was
+generated by GNU Autoconf 2.69. Invocation command line was
+
+ CONFIG_FILES = $CONFIG_FILES
+ CONFIG_HEADERS = $CONFIG_HEADERS
+ CONFIG_LINKS = $CONFIG_LINKS
+ CONFIG_COMMANDS = $CONFIG_COMMANDS
+ $ $0 $@
+
+on `(hostname || uname -n) 2>/dev/null | sed 1q`
+"
+
+_ACEOF
+
+case $ac_config_files in *"
+"*) set x $ac_config_files; shift; ac_config_files=$*;;
+esac
+
+case $ac_config_headers in *"
+"*) set x $ac_config_headers; shift; ac_config_headers=$*;;
+esac
+
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+# Files that config.status was made for.
+config_files="$ac_config_files"
+config_headers="$ac_config_headers"
+config_commands="$ac_config_commands"
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+ac_cs_usage="\
+\`$as_me' instantiates files and other configuration actions
+from templates according to the current configuration. Unless the files
+and actions are specified as TAGs, all are instantiated by default.
+
+Usage: $0 [OPTION]... [TAG]...
+
+ -h, --help print this help, then exit
+ -V, --version print version number and configuration settings, then exit
+ --config print configuration, then exit
+ -q, --quiet, --silent
+ do not print progress messages
+ -d, --debug don't remove temporary files
+ --recheck update $as_me by reconfiguring in the same conditions
+ --file=FILE[:TEMPLATE]
+ instantiate the configuration file FILE
+ --header=FILE[:TEMPLATE]
+ instantiate the configuration header FILE
+
+Configuration files:
+$config_files
+
+Configuration headers:
+$config_headers
+
+Configuration commands:
+$config_commands
+
+Report bugs to the package provider."
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
+ac_cs_version="\\
+config.status
+configured by $0, generated by GNU Autoconf 2.69,
+ with options \\"\$ac_cs_config\\"
+
+Copyright (C) 2012 Free Software Foundation, Inc.
+This config.status script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it."
+
+ac_pwd='$ac_pwd'
+srcdir='$srcdir'
+INSTALL='$INSTALL'
+AWK='$AWK'
+test -n "\$AWK" || AWK=awk
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# The default lists apply if the user does not specify any file.
+ac_need_defaults=:
+while test $# != 0
+do
+ case $1 in
+ --*=?*)
+ ac_option=`expr "X$1" : 'X\([^=]*\)='`
+ ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'`
+ ac_shift=:
+ ;;
+ --*=)
+ ac_option=`expr "X$1" : 'X\([^=]*\)='`
+ ac_optarg=
+ ac_shift=:
+ ;;
+ *)
+ ac_option=$1
+ ac_optarg=$2
+ ac_shift=shift
+ ;;
+ esac
+
+ case $ac_option in
+ # Handling of the options.
+ -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+ ac_cs_recheck=: ;;
+ --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
+ $as_echo "$ac_cs_version"; exit ;;
+ --config | --confi | --conf | --con | --co | --c )
+ $as_echo "$ac_cs_config"; exit ;;
+ --debug | --debu | --deb | --de | --d | -d )
+ debug=: ;;
+ --file | --fil | --fi | --f )
+ $ac_shift
+ case $ac_optarg in
+ *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+ '') as_fn_error $? "missing file argument" ;;
+ esac
+ as_fn_append CONFIG_FILES " '$ac_optarg'"
+ ac_need_defaults=false;;
+ --header | --heade | --head | --hea )
+ $ac_shift
+ case $ac_optarg in
+ *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+ esac
+ as_fn_append CONFIG_HEADERS " '$ac_optarg'"
+ ac_need_defaults=false;;
+ --he | --h)
+ # Conflict between --help and --header
+ as_fn_error $? "ambiguous option: \`$1'
+Try \`$0 --help' for more information.";;
+ --help | --hel | -h )
+ $as_echo "$ac_cs_usage"; exit ;;
+ -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+ | -silent | --silent | --silen | --sile | --sil | --si | --s)
+ ac_cs_silent=: ;;
+
+ # This is an error.
+ -*) as_fn_error $? "unrecognized option: \`$1'
+Try \`$0 --help' for more information." ;;
+
+ *) as_fn_append ac_config_targets " $1"
+ ac_need_defaults=false ;;
+
+ esac
+ shift
+done
+
+ac_configure_extra_args=
+
+if $ac_cs_silent; then
+ exec 6>/dev/null
+ ac_configure_extra_args="$ac_configure_extra_args --silent"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+if \$ac_cs_recheck; then
+ set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+ shift
+ \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
+ CONFIG_SHELL='$SHELL'
+ export CONFIG_SHELL
+ exec "\$@"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+exec 5>>config.log
+{
+ echo
+ sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
+## Running $as_me. ##
+_ASBOX
+ $as_echo "$ac_log"
+} >&5
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+
+# Handling of arguments.
+for ac_config_target in $ac_config_targets
+do
+ case $ac_config_target in
+ "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
+ "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
+ "doc/Makefile") CONFIG_FILES="$CONFIG_FILES doc/Makefile" ;;
+ "default") CONFIG_COMMANDS="$CONFIG_COMMANDS default" ;;
+
+ *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
+ esac
+done
+
+
+# If the user did not use the arguments to specify the items to instantiate,
+# then the envvar interface is used. Set only those that are not.
+# We use the long form for the default assignment because of an extremely
+# bizarre bug on SunOS 4.1.3.
+if $ac_need_defaults; then
+ test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
+ test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers
+ test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands
+fi
+
+# Have a temporary directory for convenience. Make it in the build tree
+# simply because there is no reason against having it here, and in addition,
+# creating and moving files from /tmp can sometimes cause problems.
+# Hook for its removal unless debugging.
+# Note that there is a small window in which the directory will not be cleaned:
+# after its creation but before its name has been assigned to `$tmp'.
+$debug ||
+{
+ tmp= ac_tmp=
+ trap 'exit_status=$?
+ : "${ac_tmp:=$tmp}"
+ { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status
+' 0
+ trap 'as_fn_exit 1' 1 2 13 15
+}
+# Create a (secure) tmp directory for tmp files.
+
+{
+ tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
+ test -d "$tmp"
+} ||
+{
+ tmp=./conf$$-$RANDOM
+ (umask 077 && mkdir "$tmp")
+} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
+ac_tmp=$tmp
+
+# Set up the scripts for CONFIG_FILES section.
+# No need to generate them if there are no CONFIG_FILES.
+# This happens for instance with `./config.status config.h'.
+if test -n "$CONFIG_FILES"; then
+
+
+ac_cr=`echo X | tr X '\015'`
+# On cygwin, bash can eat \r inside `` if the user requested igncr.
+# But we know of no other shell where ac_cr would be empty at this
+# point, so we can use a bashism as a fallback.
+if test "x$ac_cr" = x; then
+ eval ac_cr=\$\'\\r\'
+fi
+ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' </dev/null 2>/dev/null`
+if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then
+ ac_cs_awk_cr='\\r'
+else
+ ac_cs_awk_cr=$ac_cr
+fi
+
+echo 'BEGIN {' >"$ac_tmp/subs1.awk" &&
+_ACEOF
+
+
+{
+ echo "cat >conf$$subs.awk <<_ACEOF" &&
+ echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' &&
+ echo "_ACEOF"
+} >conf$$subs.sh ||
+ as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'`
+ac_delim='%!_!# '
+for ac_last_try in false false false false false :; do
+ . ./conf$$subs.sh ||
+ as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+
+ ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X`
+ if test $ac_delim_n = $ac_delim_num; then
+ break
+ elif $ac_last_try; then
+ as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+ else
+ ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+ fi
+done
+rm -f conf$$subs.sh
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK &&
+_ACEOF
+sed -n '
+h
+s/^/S["/; s/!.*/"]=/
+p
+g
+s/^[^!]*!//
+:repl
+t repl
+s/'"$ac_delim"'$//
+t delim
+:nl
+h
+s/\(.\{148\}\)..*/\1/
+t more1
+s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/
+p
+n
+b repl
+:more1
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t nl
+:delim
+h
+s/\(.\{148\}\)..*/\1/
+t more2
+s/["\\]/\\&/g; s/^/"/; s/$/"/
+p
+b
+:more2
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t delim
+' <conf$$subs.awk | sed '
+/^[^""]/{
+ N
+ s/\n//
+}
+' >>$CONFIG_STATUS || ac_write_fail=1
+rm -f conf$$subs.awk
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+_ACAWK
+cat >>"\$ac_tmp/subs1.awk" <<_ACAWK &&
+ for (key in S) S_is_set[key] = 1
+ FS = ""
+
+}
+{
+ line = $ 0
+ nfields = split(line, field, "@")
+ substed = 0
+ len = length(field[1])
+ for (i = 2; i < nfields; i++) {
+ key = field[i]
+ keylen = length(key)
+ if (S_is_set[key]) {
+ value = S[key]
+ line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3)
+ len += length(value) + length(field[++i])
+ substed = 1
+ } else
+ len += 1 + keylen
+ }
+
+ print line
+}
+
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then
+ sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g"
+else
+ cat
+fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \
+ || as_fn_error $? "could not setup config files machinery" "$LINENO" 5
+_ACEOF
+
+# VPATH may cause trouble with some makes, so we remove sole $(srcdir),
+# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and
+# trailing colons and then remove the whole line if VPATH becomes empty
+# (actually we leave an empty line to preserve line numbers).
+if test "x$srcdir" = x.; then
+ ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{
+h
+s///
+s/^/:/
+s/[ ]*$/:/
+s/:\$(srcdir):/:/g
+s/:\${srcdir}:/:/g
+s/:@srcdir@:/:/g
+s/^:*//
+s/:*$//
+x
+s/\(=[ ]*\).*/\1/
+G
+s/\n//
+s/^[^=]*=[ ]*$//
+}'
+fi
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+fi # test -n "$CONFIG_FILES"
+
+# Set up the scripts for CONFIG_HEADERS section.
+# No need to generate them if there are no CONFIG_HEADERS.
+# This happens for instance with `./config.status Makefile'.
+if test -n "$CONFIG_HEADERS"; then
+cat >"$ac_tmp/defines.awk" <<\_ACAWK ||
+BEGIN {
+_ACEOF
+
+# Transform confdefs.h into an awk script `defines.awk', embedded as
+# here-document in config.status, that substitutes the proper values into
+# config.h.in to produce config.h.
+
+# Create a delimiter string that does not exist in confdefs.h, to ease
+# handling of long lines.
+ac_delim='%!_!# '
+for ac_last_try in false false :; do
+ ac_tt=`sed -n "/$ac_delim/p" confdefs.h`
+ if test -z "$ac_tt"; then
+ break
+ elif $ac_last_try; then
+ as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5
+ else
+ ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+ fi
+done
+
+# For the awk script, D is an array of macro values keyed by name,
+# likewise P contains macro parameters if any. Preserve backslash
+# newline sequences.
+
+ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]*
+sed -n '
+s/.\{148\}/&'"$ac_delim"'/g
+t rset
+:rset
+s/^[ ]*#[ ]*define[ ][ ]*/ /
+t def
+d
+:def
+s/\\$//
+t bsnl
+s/["\\]/\\&/g
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\
+D["\1"]=" \3"/p
+s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p
+d
+:bsnl
+s/["\\]/\\&/g
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\
+D["\1"]=" \3\\\\\\n"\\/p
+t cont
+s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p
+t cont
+d
+:cont
+n
+s/.\{148\}/&'"$ac_delim"'/g
+t clear
+:clear
+s/\\$//
+t bsnlc
+s/["\\]/\\&/g; s/^/"/; s/$/"/p
+d
+:bsnlc
+s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p
+b cont
+' <confdefs.h | sed '
+s/'"$ac_delim"'/"\\\
+"/g' >>$CONFIG_STATUS || ac_write_fail=1
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ for (key in D) D_is_set[key] = 1
+ FS = ""
+}
+/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ {
+ line = \$ 0
+ split(line, arg, " ")
+ if (arg[1] == "#") {
+ defundef = arg[2]
+ mac1 = arg[3]
+ } else {
+ defundef = substr(arg[1], 2)
+ mac1 = arg[2]
+ }
+ split(mac1, mac2, "(") #)
+ macro = mac2[1]
+ prefix = substr(line, 1, index(line, defundef) - 1)
+ if (D_is_set[macro]) {
+ # Preserve the white space surrounding the "#".
+ print prefix "define", macro P[macro] D[macro]
+ next
+ } else {
+ # Replace #undef with comments. This is necessary, for example,
+ # in the case of _POSIX_SOURCE, which is predefined and required
+ # on some systems where configure will not decide to define it.
+ if (defundef == "undef") {
+ print "/*", prefix defundef, macro, "*/"
+ next
+ }
+ }
+}
+{ print }
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+ as_fn_error $? "could not setup config headers machinery" "$LINENO" 5
+fi # test -n "$CONFIG_HEADERS"
+
+
+eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS :C $CONFIG_COMMANDS"
+shift
+for ac_tag
+do
+ case $ac_tag in
+ :[FHLC]) ac_mode=$ac_tag; continue;;
+ esac
+ case $ac_mode$ac_tag in
+ :[FHL]*:*);;
+ :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;;
+ :[FH]-) ac_tag=-:-;;
+ :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
+ esac
+ ac_save_IFS=$IFS
+ IFS=:
+ set x $ac_tag
+ IFS=$ac_save_IFS
+ shift
+ ac_file=$1
+ shift
+
+ case $ac_mode in
+ :L) ac_source=$1;;
+ :[FH])
+ ac_file_inputs=
+ for ac_f
+ do
+ case $ac_f in
+ -) ac_f="$ac_tmp/stdin";;
+ *) # Look for the file first in the build tree, then in the source tree
+ # (if the path is not absolute). The absolute path cannot be DOS-style,
+ # because $ac_f cannot contain `:'.
+ test -f "$ac_f" ||
+ case $ac_f in
+ [\\/$]*) false;;
+ *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
+ esac ||
+ as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
+ esac
+ case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
+ as_fn_append ac_file_inputs " '$ac_f'"
+ done
+
+ # Let's still pretend it is `configure' which instantiates (i.e., don't
+ # use $as_me), people would be surprised to read:
+ # /* config.h. Generated by config.status. */
+ configure_input='Generated from '`
+ $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
+ `' by configure.'
+ if test x"$ac_file" != x-; then
+ configure_input="$ac_file. $configure_input"
+ { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
+$as_echo "$as_me: creating $ac_file" >&6;}
+ fi
+ # Neutralize special characters interpreted by sed in replacement strings.
+ case $configure_input in #(
+ *\&* | *\|* | *\\* )
+ ac_sed_conf_input=`$as_echo "$configure_input" |
+ sed 's/[\\\\&|]/\\\\&/g'`;; #(
+ *) ac_sed_conf_input=$configure_input;;
+ esac
+
+ case $ac_tag in
+ *:-:* | *:-) cat >"$ac_tmp/stdin" \
+ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;;
+ esac
+ ;;
+ esac
+
+ ac_dir=`$as_dirname -- "$ac_file" ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$ac_file" : 'X\(//\)[^/]' \| \
+ X"$ac_file" : 'X\(//\)$' \| \
+ X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$ac_file" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)[^/].*/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
+ as_dir="$ac_dir"; as_fn_mkdir_p
+ ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+ ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+ # A ".." for each directory in $ac_dir_suffix.
+ ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+ case $ac_top_builddir_sub in
+ "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+ *) ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+ esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+ .) # We are building in place.
+ ac_srcdir=.
+ ac_top_srcdir=$ac_top_builddir_sub
+ ac_abs_top_srcdir=$ac_pwd ;;
+ [\\/]* | ?:[\\/]* ) # Absolute name.
+ ac_srcdir=$srcdir$ac_dir_suffix;
+ ac_top_srcdir=$srcdir
+ ac_abs_top_srcdir=$srcdir ;;
+ *) # Relative name.
+ ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+ ac_top_srcdir=$ac_top_build_prefix$srcdir
+ ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+
+ case $ac_mode in
+ :F)
+ #
+ # CONFIG_FILE
+ #
+
+ case $INSTALL in
+ [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;;
+ *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;;
+ esac
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# If the template does not know about datarootdir, expand it.
+# FIXME: This hack should be removed a few years after 2.60.
+ac_datarootdir_hack=; ac_datarootdir_seen=
+ac_sed_dataroot='
+/datarootdir/ {
+ p
+ q
+}
+/@datadir@/p
+/@docdir@/p
+/@infodir@/p
+/@localedir@/p
+/@mandir@/p'
+case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in
+*datarootdir*) ac_datarootdir_seen=yes;;
+*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
+$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ ac_datarootdir_hack='
+ s&@datadir@&$datadir&g
+ s&@docdir@&$docdir&g
+ s&@infodir@&$infodir&g
+ s&@localedir@&$localedir&g
+ s&@mandir@&$mandir&g
+ s&\\\${datarootdir}&$datarootdir&g' ;;
+esac
+_ACEOF
+
+# Neutralize VPATH when `$srcdir' = `.'.
+# Shell code in configure.ac might set extrasub.
+# FIXME: do we really want to maintain this feature?
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_sed_extra="$ac_vpsub
+$extrasub
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+:t
+/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
+s|@configure_input@|$ac_sed_conf_input|;t t
+s&@top_builddir@&$ac_top_builddir_sub&;t t
+s&@top_build_prefix@&$ac_top_build_prefix&;t t
+s&@srcdir@&$ac_srcdir&;t t
+s&@abs_srcdir@&$ac_abs_srcdir&;t t
+s&@top_srcdir@&$ac_top_srcdir&;t t
+s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t
+s&@builddir@&$ac_builddir&;t t
+s&@abs_builddir@&$ac_abs_builddir&;t t
+s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
+s&@INSTALL@&$ac_INSTALL&;t t
+$ac_datarootdir_hack
+"
+eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \
+ >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+
+test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
+ { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } &&
+ { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \
+ "$ac_tmp/out"`; test -z "$ac_out"; } &&
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined. Please make sure it is defined" >&5
+$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined. Please make sure it is defined" >&2;}
+
+ rm -f "$ac_tmp/stdin"
+ case $ac_file in
+ -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";;
+ *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";;
+ esac \
+ || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+ ;;
+ :H)
+ #
+ # CONFIG_HEADER
+ #
+ if test x"$ac_file" != x-; then
+ {
+ $as_echo "/* $configure_input */" \
+ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs"
+ } >"$ac_tmp/config.h" \
+ || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+ if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5
+$as_echo "$as_me: $ac_file is unchanged" >&6;}
+ else
+ rm -f "$ac_file"
+ mv "$ac_tmp/config.h" "$ac_file" \
+ || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+ fi
+ else
+ $as_echo "/* $configure_input */" \
+ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \
+ || as_fn_error $? "could not create -" "$LINENO" 5
+ fi
+ ;;
+
+ :C) { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5
+$as_echo "$as_me: executing $ac_file commands" >&6;}
+ ;;
+ esac
+
+
+ case $ac_file$ac_mode in
+ "default":C)
+# a hook for preserving undef directive in config.h
+mv config.h conftest
+sed -e 's@^\(.*\)defin.\( .*\) .*/\*\(.*KEEP_UNDEF_HERE\)@\1undef\2 /\*\3@' < conftest > config.h
+rm -f conftest
+ ;;
+
+ esac
+done # for ac_tag
+
+
+as_fn_exit 0
+_ACEOF
+ac_clean_files=$ac_clean_files_save
+
+test $ac_write_fail = 0 ||
+ as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5
+
+
+# configure is writing to config.log, and then calls config.status.
+# config.status does its own redirection, appending to config.log.
+# Unfortunately, on DOS this fails, as config.log is still kept open
+# by configure, so config.status won't be able to write to it; its
+# output is simply discarded. So we exec the FD to /dev/null,
+# effectively closing config.log, so it can be properly (re)opened and
+# appended to by config.status. When coming back to configure, we
+# need to make the FD available again.
+if test "$no_create" != yes; then
+ ac_cs_success=:
+ ac_config_status_args=
+ test "$silent" = yes &&
+ ac_config_status_args="$ac_config_status_args --quiet"
+ exec 5>/dev/null
+ $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
+ exec 5>>config.log
+ # Use ||, not &&, to avoid exiting from the if with $? = 1, which
+ # would make configure fail if this is the last instruction.
+ $ac_cs_success || as_fn_exit 1
+fi
+if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
+$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
+fi
+
+
+echo ""
+if test -z "$AWK"; then
+echo "!!! Since you have no awk you must copy the files 'comm.h.dist'"
+echo "!!! and 'term.h.dist' to 'comm.h' and 'term.h'."
+echo "!!! Do _not_ change the user configuration section in config.h!"
+echo "Please check the pathnames in the Makefile."
+else
+echo "Now please check the pathnames in the Makefile and in the user"
+echo "configuration section in config.h."
+fi
+echo "Then type 'make' to make screen. Good luck."
+echo ""
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..28237f5
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,1302 @@
+dnl Process this file with autoconf to produce a configure script.
+dnl
+dnl $Id$ GNU
+dnl
+dnl Many thanks to David MacKenzie for writing autoconf and
+dnl providing a sample configure.in file for screen.
+dnl
+AC_REVISION($Revision$)dnl
+AC_INIT(screen.c)
+AC_CONFIG_HEADER(config.h)
+AC_PREREQ(2.60)
+
+dnl
+dnl Define some useful macros
+dnl
+AC_DEFUN([AC_PROGRAM_SOURCE],
+[AC_REQUIRE([AC_PROG_CPP])AC_PROVIDE([$0])cat > conftest.c <<EOF
+#include "confdefs.h"
+[$1]
+_CUT_HERE_
+[$2]
+EOF
+eval "$ac_cpp conftest.c 2>&5 | sed -e '1,/_CUT_HERE_/d' -e 's/ //g' > conftest.out"
+. ./conftest.out
+rm -f conftest*
+])dnl
+dnl
+define(AC_NOTE,
+[echo "$1" 1>&AC_FD_MSG
+])dnl
+
+dnl
+dnl Extract version from patchlevel.h
+dnl
+rev=`sed < ${srcdir}/patchlevel.h -n -e '/#define REV/s/#define REV *//p'`
+vers=`sed < ${srcdir}/patchlevel.h -n -e '/#define VERS/s/#define VERS *//p'`
+pat=`sed < ${srcdir}/patchlevel.h -n -e '/#define PATCHLEVEL/s/#define PATCHLEVEL *//p'`
+VERSION="$rev.$vers.$pat"
+AC_NOTE(this is screen version $VERSION)
+AC_SUBST(VERSION)
+AC_PREFIX_PROGRAM(screen)
+AC_PREFIX_PROGRAM(gzip)
+
+old_CFLAGS="$CFLAGS"
+AC_PROG_CC
+AC_PROG_CPP
+AC_PROG_GCC_TRADITIONAL
+AC_ISC_POSIX
+AC_USE_SYSTEM_EXTENSIONS
+
+AC_TRY_RUN(main(){exit(0);},,[
+if test $CC != cc ; then
+AC_NOTE(Your $CC failed - restarting with CC=cc)
+AC_NOTE()
+CC=cc
+export CC
+exec $0 $configure_args
+fi
+])
+
+AC_TRY_RUN(main(){exit(0);},,
+exec 5>&2
+eval $ac_link
+AC_NOTE(CC=$CC; CFLAGS=$CFLAGS; LIBS=$LIBS;)
+AC_NOTE($ac_compile)
+AC_MSG_ERROR(Can't run the compiler - sorry))
+
+AC_TRY_RUN([
+main()
+{
+ int __something_strange_();
+ __something_strange_(0);
+}
+],AC_MSG_ERROR(Your compiler does not set the exit status - sorry))
+
+AC_PROG_AWK
+
+AC_PROG_INSTALL
+
+if test -f etc/toolcheck; then
+AC_CHECKING(for buggy tools)
+sh etc/toolcheck 1>&AC_FD_MSG
+fi
+
+
+
+dnl SOCKDIR
+AC_MSG_CHECKING(if a system-wide socket dir should be used)
+AC_ARG_ENABLE(socket-dir,
+ [ --disable-socket-dir disable system wide socket-dir and use ~/.screen instead],
+ [
+ AC_MSG_RESULT(no. ~/.screen will be used instead.)
+ ],
+ [
+ AC_MSG_RESULT(yes)
+ AC_MSG_CHECKING(for the socket dir)
+ SOCKDIR="(eff_uid ? \"/tmp/uscreens\" : \"/tmp/screens\")"
+ AC_ARG_WITH(socket-dir, [ --with-socket-dir=path where to put the per-user sockets], [
+ case "${withval}" in
+ *\"*) SOCKDIR="${withval}" ;;
+ *) SOCKDIR="\"${withval}\"" ;;
+ esac
+ ])
+ AC_MSG_RESULT(${SOCKDIR})
+ AC_DEFINE_UNQUOTED(SOCKDIR, $SOCKDIR)
+ ]
+)
+
+
+dnl
+dnl **** special unix variants ****
+dnl
+if test -n "$ISC"; then
+ AC_DEFINE(ISC) LIBS="$LIBS -linet"
+fi
+
+dnl AC_CHECKING(for OSF1)
+dnl if test -f /bin/uname ; then
+dnl if test `/bin/uname` = OSF1 || test -f /osf_boot; then
+dnl AC_DEFINE(OSF1) # this disables MIPS again....
+dnl fi
+dnl fi
+
+if test -f /sysV68 ; then
+AC_DEFINE(sysV68)
+fi
+
+AC_CHECKING(for MIPS)
+if test -f /lib/libmld.a || test -f /usr/lib/libmld.a || test -f /usr/lib/cmplrs/cc/libmld.a; then
+oldlibs="$LIBS"
+test -f /bin/mx || LIBS="$LIBS -lmld" # for nlist. But not on alpha.
+dnl djm@eng.umd.edu: "... for one thing, it doubles the size of the executable"
+AC_CHECKING(mld library)
+AC_TRY_LINK(,,,LIBS="$oldlibs")
+dnl
+dnl
+if test -r /dev/ptc; then
+AC_DEFINE(MIPS)
+AC_CHECKING(wait3)
+AC_TRY_LINK(,[wait3();], ,
+AC_CHECKING(wait2)
+AC_TRY_LINK(,[wait2();],
+dnl John Rouillard (rouilj@sni-usa.com):
+dnl need -I/usr/include/bsd in RISCOS otherwise sockets are broken, no
+dnl job control etc.
+dnl Detect RISCOS if wait2 is present, but not wait3.
+AC_DEFINE(USE_WAIT2) LIBS="$LIBS -lbsd" ; CC="$CC -I/usr/include/bsd"
+))
+fi
+fi
+
+
+AC_CHECKING(for Ultrix)
+AC_EGREP_CPP(yes,
+[#if defined(ultrix) || defined(__ultrix)
+ yes;
+#endif
+], ULTRIX=1)
+
+if test -f /usr/lib/libpyr.a ; then
+oldlibs="$LIBS"
+LIBS="$LIBS -lpyr"
+AC_CHECKING(Pyramid OSX)
+AC_TRY_LINK(,[open_controlling_pty("")], AC_DEFINE(OSX), LIBS="$oldlibs")
+fi
+
+dnl ghazi@caip.rutgers.edu (Kaveh R. Ghazi):
+dnl BBN butterfly is not POSIX, but a MACH BSD system.
+dnl Do not define POSIX and TERMIO.
+AC_CHECKING(for butterfly)
+AC_EGREP_CPP(yes,
+[#if defined(butterfly)
+ yes;
+#endif
+], butterfly=1)
+
+if test -z "$butterfly"; then
+if test -n "$ULTRIX"; then
+ test -z "$GCC" && CC="$CC -YBSD"
+fi
+AC_CHECKING(for POSIX.1)
+AC_EGREP_CPP(yes,
+[#include <sys/types.h>
+#include <unistd.h>
+main () {
+#ifdef _POSIX_VERSION
+ yes;
+#endif
+], AC_NOTE(- you have a POSIX system) AC_DEFINE(POSIX) posix=1)
+fi
+
+AC_CHECKING(for System V)
+AC_TRY_COMPILE(
+[#include <sys/types.h>
+#include <signal.h>
+#include <fcntl.h>], [int x = SIGCHLD | FNDELAY;], , AC_DEFINE(SYSV))
+
+AC_CHECKING(for sequent/ptx)
+AC_EGREP_CPP(yes,
+[#ifdef _SEQUENT_
+ yes;
+#endif
+], LIBS="$LIBS -lsocket -linet";seqptx=1)
+
+oldlibs="$LIBS"
+LIBS="$LIBS -lelf"
+AC_CHECKING(SVR4)
+AC_TRY_LINK([#include <utmpx.h>
+],,
+[AC_CHECK_HEADER(dwarf.h, AC_DEFINE(SVR4) AC_DEFINE(BUGGYGETLOGIN),
+[AC_CHECK_HEADER(elf.h, AC_DEFINE(SVR4) AC_DEFINE(BUGGYGETLOGIN))])]
+,LIBS="$oldlibs")
+AC_CHECK_HEADERS([stropts.h string.h strings.h])
+
+AC_CHECKING(for Solaris 2.x)
+AC_EGREP_CPP(yes,
+[#if defined(SVR4) && defined(sun)
+ yes
+#endif
+], LIBS="$LIBS -lsocket -lnsl -lkstat")
+
+dnl
+dnl **** typedefs ****
+dnl
+dnl (currently not used)
+dnl
+dnl AC_CHECKING(for pid_t)
+dnl AC_EGREP_CPP(pid_t,[#include <sys/types.h>
+dnl ],AC_DEFINE(PID_T_DEFINED))
+dnl
+dnl AC_CHECKING(for sig_t)
+dnl AC_EGREP_CPP(sig_t,[#include <sys/types.h>
+dnl #include <signal.h>
+dnl ],AC_DEFINE(SIG_T_DEFINED))
+dnl
+dnl AC_CHECKING(for uid_t)
+dnl AC_EGREP_CPP(uid_t,[#include <sys/types.h>
+dnl ],AC_DEFINE(UID_T_DEFINED))
+dnl
+
+dnl
+dnl **** Job control ****
+dnl
+
+AC_CHECKING(BSD job jontrol)
+AC_TRY_LINK(
+[#include <sys/types.h>
+#include <sys/ioctl.h>
+], [
+#ifdef POSIX
+tcsetpgrp(0, 0);
+#else
+int x = TIOCSPGRP;
+#ifdef SYSV
+setpgrp();
+#else
+int y = TIOCNOTTY;
+#endif
+#endif
+], AC_NOTE(- you have jobcontrol) AC_DEFINE(BSDJOBS), AC_NOTE(- you don't have jobcontrol))
+
+dnl
+dnl **** setresuid(), setreuid(), seteuid() ****
+dnl
+AC_CHECKING(setresuid)
+AC_TRY_LINK(,[
+setresuid(0, 0, 0);
+], AC_DEFINE(HAVE_SETRESUID))
+AC_CHECKING(setreuid)
+AC_TRY_LINK(,[
+setreuid(0, 0);
+], AC_DEFINE(HAVE_SETREUID))
+dnl
+dnl seteuid() check:
+dnl linux seteuid was broken before V1.1.11
+dnl NeXT, AUX, ISC, and ultrix are still broken (no saved uid support)
+dnl Solaris seteuid doesn't change the saved uid, bad for
+dnl multiuser screen sessions
+AC_CHECKING(seteuid)
+AC_TRY_LINK(,[
+#if defined(linux) || defined(NeXT) || defined(_AUX_SOURCE) || defined(AUX) || defined(ultrix) || (defined(sun) && defined(SVR4)) || defined(ISC) || defined(sony_news)
+seteuid_is_broken(0);
+#else
+seteuid(0);
+#endif
+], AC_DEFINE(HAVE_SETEUID))
+
+dnl execvpe
+AC_CHECKING(execvpe)
+AC_TRY_LINK(,[
+ execvpe(0, 0, 0);
+], AC_DEFINE(HAVE_EXECVPE)
+CFLAGS="$CFLAGS -D_GNU_SOURCE")
+
+dnl
+dnl **** select() ****
+dnl
+
+AC_CHECKING(select)
+AC_TRY_LINK(,[select(0, 0, 0, 0, 0);],,
+LIBS="$LIBS -lnet -lnsl"
+AC_CHECKING(select with $LIBS)
+AC_TRY_LINK(,[select(0, 0, 0, 0, 0);],,
+AC_MSG_ERROR(!!! no select - no screen))
+)
+dnl
+dnl **** FIFO tests ****
+dnl
+
+AC_CHECKING(fifos)
+AC_TRY_RUN([
+/* For select - According to POSIX 1003.1-2001 */
+#include <sys/select.h>
+
+/* For select - According to earlier standards */
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#ifndef O_NONBLOCK
+#define O_NONBLOCK O_NDELAY
+#endif
+#ifndef S_IFIFO
+#define S_IFIFO 0010000
+#endif
+
+char *fin = "/tmp/conftest$$";
+
+main()
+{
+ struct stat stb;
+ fd_set f;
+
+ (void)alarm(5);
+ unlink(fin);
+#ifdef POSIX
+ if (mkfifo(fin, 0777))
+#else
+ if (mknod(fin, S_IFIFO|0777, 0))
+#endif
+ exit(1);
+ if (stat(fin, &stb) || (stb.st_mode & S_IFIFO) != S_IFIFO)
+ exit(1);
+ close(0);
+#ifdef __386BSD__
+ /*
+ * The next test fails under 386BSD, but screen works using fifos.
+ * Fifos in O_RDWR mode are only used for the BROKEN_PIPE case and for
+ * the select() configuration test.
+ */
+ exit(0);
+#endif
+ if (open(fin, O_RDONLY | O_NONBLOCK))
+ exit(1);
+ if (fork() == 0)
+ {
+ close(0);
+ if (open(fin, O_WRONLY | O_NONBLOCK))
+ exit(1);
+ close(0);
+ if (open(fin, O_WRONLY | O_NONBLOCK))
+ exit(1);
+ if (write(0, "TEST", 4) == -1)
+ exit(1);
+ exit(0);
+ }
+ FD_SET(0, &f);
+ if (select(1, &f, 0, 0, 0) == -1)
+ exit(1);
+ exit(0);
+}
+], AC_NOTE(- your fifos are usable) fifo=1,
+AC_NOTE(- your fifos are not usable))
+rm -f /tmp/conftest*
+
+if test -n "$fifo"; then
+AC_CHECKING(for broken fifo implementation)
+AC_TRY_RUN([
+/* For select - According to POSIX 1003.1-2001 */
+#include <sys/select.h>
+
+/* For select - According to earlier standards */
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#ifndef O_NONBLOCK
+#define O_NONBLOCK O_NDELAY
+#endif
+#ifndef S_IFIFO
+#define S_IFIFO 0010000
+#endif
+
+char *fin = "/tmp/conftest$$";
+
+main()
+{
+ struct timeval tv;
+ fd_set f;
+
+#ifdef POSIX
+ if (mkfifo(fin, 0600))
+#else
+ if (mknod(fin, S_IFIFO|0600, 0))
+#endif
+ exit(1);
+ close(0);
+ if (open(fin, O_RDONLY|O_NONBLOCK))
+ exit(1);
+ FD_SET(0, &f);
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ if (select(1, &f, 0, 0, &tv))
+ exit(1);
+ exit(0);
+}
+], AC_NOTE(- your implementation is ok),
+AC_NOTE(- you have a broken implementation) AC_DEFINE(BROKEN_PIPE) fifobr=1)
+rm -f /tmp/conftest*
+fi
+
+dnl
+dnl **** SOCKET tests ****
+dnl
+dnl may need LIBS="$LIBS -lsocket" here
+dnl
+
+AC_CHECKING(sockets)
+AC_TRY_RUN([
+/* For select - According to POSIX 1003.1-2001 */
+#include <sys/select.h>
+
+/* For select - According to earlier standards */
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+char *son = "/tmp/conftest$$";
+
+main()
+{
+ int s1, s2, l;
+ struct sockaddr_un a;
+ fd_set f;
+
+ (void)alarm(5);
+ if ((s1 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+ exit(1);
+ a.sun_family = AF_UNIX;
+ strcpy(a.sun_path, son);
+ (void) unlink(son);
+ if (bind(s1, (struct sockaddr *) &a, strlen(son)+2) == -1)
+ exit(1);
+ if (listen(s1, 2))
+ exit(1);
+ if (fork() == 0)
+ {
+ if ((s2 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+ kill(getppid(), 3);
+ (void)connect(s2, (struct sockaddr *)&a, strlen(son) + 2);
+ if (write(s2, "HELLO", 5) == -1)
+ kill(getppid(), 3);
+ exit(0);
+ }
+ l = sizeof(a);
+ close(0);
+ if (accept(s1, &a, &l))
+ exit(1);
+ FD_SET(0, &f);
+ if (select(1, &f, 0, 0, 0) == -1)
+ exit(1);
+ exit(0);
+}
+], AC_NOTE(- your sockets are usable) sock=1,
+AC_NOTE(- your sockets are not usable))
+rm -f /tmp/conftest*
+
+if test -n "$sock"; then
+AC_CHECKING(socket implementation)
+AC_TRY_RUN([
+/* For select - According to POSIX 1003.1-2001 */
+#include <sys/select.h>
+
+/* For select - According to earlier standards */
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+char *son = "/tmp/conftest$$";
+
+main()
+{
+ int s;
+ struct stat stb;
+ struct sockaddr_un a;
+ if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+ exit(0);
+ a.sun_family = AF_UNIX;
+ strcpy(a.sun_path, son);
+ (void) unlink(son);
+ if (bind(s, (struct sockaddr *) &a, strlen(son)+2) == -1)
+ exit(0);
+ if (stat(son, &stb))
+ exit(1);
+ close(s);
+ exit(0);
+}
+],AC_NOTE(- you are normal),
+AC_NOTE(- unix domain sockets are not kept in the filesystem)
+AC_DEFINE(SOCK_NOT_IN_FS) socknofs=1)
+rm -f /tmp/conftest*
+fi
+
+
+dnl
+dnl **** choose sockets or fifos ****
+dnl
+dnl **** check the select implementation ****
+dnl
+
+AC_TRY_RUN([
+/* For select - According to POSIX 1003.1-2001 */
+#include <sys/select.h>
+
+/* For select - According to earlier standards */
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+#include <fcntl.h>
+
+char *nam = "/tmp/conftest$$";
+
+#ifndef O_NONBLOCK
+#define O_NONBLOCK O_NDELAY
+#ifndef S_IFIFO
+#define S_IFIFO 0010000
+
+
+main()
+{
+ fd_set f;
+
+#ifdef __FreeBSD__
+/* From Andrew A. Chernov (ache@astral.msk.su):
+ * opening RDWR fifo fails in BSD 4.4, but select return values are
+ * right.
+ */
+ exit(0);
+#endif
+ (void)alarm(5);
+#ifdef POSIX
+ if (mkfifo(nam, 0777))
+#else
+ if (mknod(nam, S_IFIFO|0777, 0))
+#endif
+ exit(1);
+ close(0);
+ if (open(nam, O_RDWR | O_NONBLOCK))
+ exit(1);
+ if (write(0, "TEST", 4) == -1)
+ exit(1);
+
+#else
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+main()
+{
+ int s1, s2, l;
+ struct sockaddr_un a;
+ fd_set f;
+
+ (void)alarm(5);
+ if ((s1 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+ exit(1);
+ a.sun_family = AF_UNIX;
+ strcpy(a.sun_path, nam);
+ (void) unlink(nam);
+ if (bind(s1, (struct sockaddr *) &a, strlen(nam)+2) == -1)
+ exit(1);
+ if (listen(s1, 2))
+ exit(1);
+ if (fork() == 0)
+ {
+ if ((s2 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+ kill(getppid(), 3);
+ (void)connect(s2, (struct sockaddr *)&a, strlen(nam) + 2);
+ if (write(s2, "HELLO", 5) == -1)
+ kill(getppid(), 3);
+ exit(0);
+ }
+ l = sizeof(a);
+ close(0);
+ if (accept(s1, (struct sockaddr *)&a, &l))
+ exit(1);
+#endif
+
+
+ FD_SET(0, &f);
+ if (select(1, &f, 0, 0, 0) == -1)
+ exit(1);
+ if (select(1, &f, &f, 0, 0) != 2)
+ exit(1);
+ exit(0);
+}
+],AC_NOTE(- select is ok),
+AC_NOTE(- select can't count) AC_DEFINE(SELECT_BROKEN))
+
+dnl
+dnl **** termcap or terminfo ****
+dnl
+AC_CHECKING(for tgetent)
+AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
+olibs="$LIBS"
+LIBS="-lcurses $olibs"
+AC_CHECKING(libcurses)
+AC_TRY_LINK(,[
+#ifdef __hpux
+__sorry_hpux_libcurses_is_totally_broken_in_10_10();
+#else
+tgetent((char *)0, (char *)0);
+#endif
+],,
+LIBS="-ltermcap $olibs"
+AC_CHECKING(libtermcap)
+AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
+LIBS="-ltermlib $olibs"
+AC_CHECKING(libtermlib)
+AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
+LIBS="-lncursesw $olibs"
+AC_CHECKING(libncursesw)
+AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
+LIBS="-ltinfow $olibs"
+AC_CHECKING(libtinfow)
+AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
+LIBS="-lncurses $olibs"
+AC_CHECKING(libncurses)
+AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
+LIBS="-ltinfo $olibs"
+AC_CHECKING(libtinfo)
+AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
+AC_MSG_ERROR(!!! no tgetent - no screen)))))))))
+
+AC_TRY_RUN([
+main()
+{
+ exit(strcmp(tgoto("%p1%d", 0, 1), "1") ? 0 : 1);
+}], AC_NOTE(- you use the termcap database),
+AC_NOTE(- you use the terminfo database) AC_DEFINE(TERMINFO))
+AC_CHECKING(ospeed)
+AC_TRY_LINK(extern short ospeed;,ospeed=5;,,AC_DEFINE(NEED_OSPEED))
+
+dnl
+dnl **** PTY specific things ****
+dnl
+AC_CHECKING(for /dev/ptc)
+if test -r /dev/ptc; then
+AC_DEFINE(HAVE_DEV_PTC)
+fi
+
+AC_CHECKING(for SVR4 ptys)
+sysvr4ptys=
+if test -c /dev/ptmx ; then
+AC_TRY_LINK([],[ptsname(0);grantpt(0);unlockpt(0);],[AC_DEFINE(HAVE_SVR4_PTYS)
+sysvr4ptys=1])
+fi
+
+AC_CHECK_FUNCS(getpt)
+
+dnl check for openpty()
+if test -z "$sysvr4ptys"; then
+AC_CHECK_FUNCS(openpty,,
+[AC_CHECK_LIB(util,openpty, [AC_DEFINE(HAVE_OPENPTY)] [LIBS="$LIBS -lutil"])])
+fi
+
+AC_CHECKING(for ptyranges)
+if test -d /dev/ptym ; then
+pdir='/dev/ptym'
+else
+pdir='/dev'
+fi
+dnl SCO uses ptyp%d
+AC_EGREP_CPP(yes,
+[#ifdef M_UNIX
+ yes;
+#endif
+], ptys=`echo /dev/ptyp??`, ptys=`echo $pdir/pty??`)
+dnl if test -c /dev/ptyp19; then
+dnl ptys=`echo /dev/ptyp??`
+dnl else
+dnl ptys=`echo $pdir/pty??`
+dnl fi
+if test "$ptys" != "$pdir/pty??" ; then
+p0=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\).$/\1/g' | sort -u | tr -d '\012'`
+p1=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\)$/\1/g' | sort -u | tr -d '\012'`
+AC_DEFINE_UNQUOTED(PTYRANGE0,"$p0")
+AC_DEFINE_UNQUOTED(PTYRANGE1,"$p1")
+fi
+
+dnl **** pty mode/group handling ****
+dnl
+dnl support provided by Luke Mewburn <lm@rmit.edu.au>, 931222
+AC_ARG_WITH(pty-mode, [ --with-pty-mode=mode default mode for ptys], [ ptymode="${withval}" ])
+AC_ARG_WITH(pty-group, [ --with-pty-group=group default group for ptys], [ ptygrp="${withval}" ])
+test -n "$ptymode" || ptymode=0620
+if test -n "$ptygrp" ; then
+AC_DEFINE_UNQUOTED(PTYMODE, $ptymode)
+AC_DEFINE_UNQUOTED(PTYGROUP,$ptygrp)
+else
+
+AC_CHECKING(default tty permissions/group)
+rm -f conftest_grp
+AC_TRY_RUN([
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+main()
+{
+ struct stat sb;
+ char *x,*ttyname();
+ int om, m;
+ FILE *fp;
+
+ if (!(x = ttyname(0))) exit(1);
+ if (stat(x, &sb)) exit(1);
+ om = sb.st_mode;
+ if (om & 002) exit(0);
+ m = system("mesg y");
+ if (m == -1 || m == 127) exit(1);
+ if (stat(x, &sb)) exit(1);
+ m = sb.st_mode;
+ if (chmod(x, om)) exit(1);
+ if (m & 002) exit(0);
+ if (sb.st_gid == getgid()) exit(1);
+ if (!(fp=fopen("conftest_grp", "w")))
+ exit(1);
+ fprintf(fp, "%d\n", sb.st_gid);
+ fclose(fp);
+ exit(0);
+}
+],[
+ if test -f conftest_grp; then
+ ptygrp=`cat conftest_grp`
+ AC_NOTE([- pty mode: $ptymode, group: $ptygrp])
+ AC_DEFINE_UNQUOTED(PTYMODE, $ptymode)
+ AC_DEFINE_UNQUOTED(PTYGROUP,$ptygrp)
+ else
+ AC_NOTE(- ptys are world accessable)
+ fi
+],[
+ WRITEPATH=''
+ XTERMPATH=''
+ AC_PATH_PROG(WRITEPATH, write)
+ AC_PATH_PROG(XTERMPATH, xterm)
+ found=
+ if test -n "$WRITEPATH$XTERMPATH"; then
+ findfollow=
+ lsfollow=
+ found=`find $WRITEPATH $XTERMPATH -follow -print 2>/dev/null`
+ if test -n "$found"; then
+ findfollow=-follow
+ lsfollow=L
+ fi
+ if test -n "$XTERMPATH"; then
+ ptygrpn=`ls -l$lsfollow $XTERMPATH | sed -n -e 1p | $AWK '{print $4}'`
+ if test tty != "$ptygrpn"; then
+ XTERMPATH=
+ fi
+ fi
+ fi
+ if test -n "$WRITEPATH$XTERMPATH"; then
+ found=`find $WRITEPATH $XTERMPATH $findfollow -perm -2000 -print`
+ if test -n "$found"; then
+ ptygrp=`ls -ln$lsfollow $found | sed -n -e 1p | $AWK '{print $4}'`
+ AC_NOTE([- pty mode: $ptymode, group: $ptygrp])
+ AC_DEFINE_UNQUOTED(PTYMODE, $ptymode)
+ AC_DEFINE_UNQUOTED(PTYGROUP,$ptygrp)
+ else
+ AC_NOTE(- ptys are world accessable)
+ fi
+ else
+ AC_NOTE(- can't determine - assume ptys are world accessable)
+ fi
+ ]
+)
+rm -f conftest_grp
+fi
+
+dnl
+dnl **** utmp handling ****
+dnl
+AC_CHECKING(getutent)
+AC_TRY_LINK([
+#include <time.h> /* to get time_t on SCO */
+#include <sys/types.h>
+#if defined(SVR4) && !defined(DGUX)
+#include <utmpx.h>
+#define utmp utmpx
+#else
+#include <utmp.h>
+#endif
+#ifdef __hpux
+#define pututline _pututline
+#endif
+],
+[int x = DEAD_PROCESS; pututline((struct utmp *)0); getutent();], AC_DEFINE(GETUTENT),
+olibs="$LIBS"
+LIBS="$LIBS -lgen"
+AC_CHECKING(getutent with -lgen)
+AC_TRY_LINK([
+#include <time.h>
+#include <sys/types.h>
+#if defined(SVR4) && !defined(DGUX)
+#include <utmpx.h>
+#define utmp utmpx
+#else
+#include <utmp.h>
+#endif
+#ifdef __hpux
+#define pututline _pututline
+#endif
+],
+[int x = DEAD_PROCESS; pututline((struct utmp *)0); getutent();], AC_DEFINE(GETUTENT), LIBS="$olibs")
+)
+AC_CHECKING(ut_host)
+AC_TRY_COMPILE([
+#include <time.h>
+#include <sys/types.h>
+#if defined(SVR4) && !defined(DGUX)
+#include <utmpx.h>
+#define utmp utmpx
+#else
+#include <utmp.h>
+#endif
+],[struct utmp u; u.ut_host[0] = 0;], AC_DEFINE(UTHOST))
+AC_CHECK_HEADER(utempter.h, have_utempter=yes, have_utempter=no)
+if test "$have_utempter" = yes; then
+ AC_DEFINE(HAVE_UTEMPTER)
+ LIBS="$LIBS -lutempter"
+fi
+
+dnl
+dnl **** loadav ****
+dnl
+AC_CHECKING(for libutil(s))
+test -f /usr/lib/libutils.a && LIBS="$LIBS -lutils"
+test -f /usr/lib/libutil.a && LIBS="$LIBS -lutil"
+
+AC_CHECKING(getloadavg)
+AC_TRY_LINK(,[getloadavg((double *)0, 0);],
+AC_DEFINE(LOADAV_GETLOADAVG) load=1,
+if test -f /usr/lib/libkvm.a ; then
+olibs="$LIBS"
+LIBS="$LIBS -lkvm"
+AC_CHECKING(getloadavg with -lkvm)
+AC_TRY_LINK(,[getloadavg((double *)0, 0);],
+AC_DEFINE(LOADAV_GETLOADAVG) load=1, LIBS="$olibs")
+fi
+)
+
+if test -z "$load" ; then
+AC_EGREP_CPP(yes,
+[#if defined(NeXT) || defined(apollo) || defined(linux)
+ yes;
+#endif
+], load=1)
+fi
+if test -z "$load" ; then
+AC_CHECKING(for kernelfile)
+for core in /unix /vmunix /dynix /hp-ux /xelos /dev/ksyms /kernel/unix /kernel/genunix /unicos /mach /netbsd /386bsd /dgux /bsd /stand/vmunix; do
+ if test -f $core || test -c $core; then
+ break
+ fi
+done
+if test ! -f $core && test ! -c $core ; then
+ AC_NOTE(- no kernelfile found)
+else
+ AC_NOTE(- using kernelfile '$core')
+ if test -r $core ; then
+ AC_DEFINE_UNQUOTED(LOADAV_UNIX,"$core")
+ AC_CHECK_HEADER(nlist.h,
+ [AC_DEFINE(NLIST_STRUCT)
+ AC_CHECKING(n_un in struct nlist)
+ AC_TRY_COMPILE([#include <nlist.h>],
+ [struct nlist n; n.n_un.n_name = 0;],
+ AC_DEFINE(NLIST_NAME_UNION))])
+
+ AC_CHECKING(for nlist declaration)
+ AC_EGREP_CPP([nlist(( | )( | )*.*\(|\()],[
+#ifdef NLIST_STRUCT
+# include <nlist.h>
+#else
+# include <a.out.h>
+#endif
+],AC_DEFINE(NLIST_DECLARED))
+
+ AC_CHECKING(for avenrun symbol)
+ nlist64=
+ for av in avenrun _avenrun _Loadavg avenrun _avenrun _Loadavg; do
+ AC_TRY_RUN([
+#include <sys/types.h>
+#ifdef NLIST_STRUCT
+#include <nlist.h>
+#else
+#include <a.out.h>
+#endif
+
+$nlist64
+
+struct nlist nl[2];
+
+main()
+{
+#if !defined(_AUX_SOURCE) && !defined(AUX)
+# ifdef NLIST_NAME_UNION
+ nl[0].n_un.n_name = "$av";
+# else
+ nl[0].n_name = "$av";
+# endif
+#else
+ strncpy(nl[0].n_name, "$av", sizeof(nl[0].n_name));
+#endif
+ nlist(LOADAV_UNIX, nl);
+ if (nl[0].n_value == 0)
+ exit(1);
+ exit(0);
+}
+ ],avensym=$av;break)
+ if test "$av" = _Loadavg; then
+ nlist64='#define nlist nlist64'
+ fi
+ done
+ if test -z "$avensym" ; then
+ AC_NOTE(- no avenrun symbol found)
+ else
+ AC_NOTE(- using avenrun symbol '$avensym')
+ AC_DEFINE_UNQUOTED(LOADAV_AVENRUN,"$avensym")
+ if test -n "$nlist64"; then
+ AC_NOTE(- used nlist64 to find it)
+ AC_DEFINE(LOADAV_USE_NLIST64)
+ fi
+ load=1
+ fi
+ else
+ AC_NOTE( Can't configure the load average display feature)
+ AC_NOTE( because $core is not readable by you.)
+ AC_NOTE( To configure the load average display feature,)
+ AC_NOTE( re-run configure as root if possible.)
+ AC_NOTE( If you are not the system administrator then disregard)
+ AC_NOTE( this warning. You can still use screen without)
+ AC_NOTE( the load average display feature.)
+ fi
+fi
+fi
+
+AC_PROGRAM_SOURCE([
+#include <sys/types.h>
+#include <sys/param.h>
+],[
+#if !defined(LOADAV_GETLOADAVG) && ((defined(hp300) && !defined(__hpux)) || defined(sun) || (defined(ultrix) && defined(mips)) || defined(_SEQUENT_) || defined(sgi) || (defined(SVR4) && !defined(__hpux)) || defined(sony_news) || (!defined(__osf__) && defined(__alpha)) || defined(_IBMR2) || defined(_AUX_SOURCE) || defined(AUX) || defined(m88k))
+loadtype=long
+# if defined(apollo) || defined(_IBMR2) || defined(_AUX_SOURCE) || defined(AUX)
+loadscale=65536
+# else
+# if defined(FSCALE) && !defined(__osf__)
+# undef FSCALE
+loadscale=FSCALE
+# else
+# ifdef sgi
+loadtype=int
+loadscale=1024
+# else
+# if defined(MIPS) || defined(SVR4) || defined(m88k)
+loadscale=256
+# else /* not MIPS */
+loadscale=1000 /* our default value */
+# endif /* MIPS */
+# endif /* sgi */
+# endif /* not FSCALE */
+# endif /* not apollo */
+#else
+loadtype=double
+loadscale=1
+#endif
+#ifdef alliant
+loadnum=4
+#else
+loadnum=3
+#endif
+])
+
+if test -n "$load" ; then AC_DEFINE(LOADAV) fi
+if test -n "$loadtype" ; then AC_DEFINE_UNQUOTED(LOADAV_TYPE,$loadtype) fi
+if test -n "$loadnum" ; then AC_DEFINE_UNQUOTED(LOADAV_NUM,$loadnum) fi
+if test -n "$loadscale" ; then AC_DEFINE_UNQUOTED(LOADAV_SCALE,$loadscale) fi
+
+dnl
+dnl **** signal handling ****
+dnl
+if test -n "$posix" ; then
+
+dnl POSIX has reliable signals with void return type.
+AC_NOTE(assuming posix signal definition)
+AC_DEFINE(SIGVOID)
+
+else
+
+AC_CHECKING(return type of signal handlers)
+AC_TRY_COMPILE(
+[#include <sys/types.h>
+#include <signal.h>
+#ifdef signal
+#undef signal
+#endif
+extern void (*signal ()) ();], [int i;], AC_DEFINE(SIGVOID))
+AC_CHECKING(sigset)
+AC_TRY_LINK([
+#include <sys/types.h>
+#include <signal.h>
+],[
+#ifdef SIGVOID
+sigset(0, (void (*)())0);
+#else
+sigset(0, (int (*)())0);
+#endif
+], AC_DEFINE(USESIGSET))
+AC_CHECKING(signal implementation)
+AC_TRY_RUN([
+#include <sys/types.h>
+#include <signal.h>
+
+#ifndef SIGCLD
+#define SIGCLD SIGCHLD
+#endif
+#ifdef USESIGSET
+#define signal sigset
+#endif
+
+int got;
+
+#ifdef SIGVOID
+void
+#endif
+hand()
+{
+ got++;
+}
+
+main()
+{
+ /* on hpux we use sigvec to get bsd signals */
+#ifdef __hpux
+ (void)signal(SIGCLD, hand);
+ kill(getpid(), SIGCLD);
+ kill(getpid(), SIGCLD);
+ if (got < 2)
+ exit(1);
+#endif
+ exit(0);
+}
+],,AC_DEFINE(SYSVSIGS))
+
+fi
+
+dnl
+dnl **** libraries ****
+dnl
+
+AC_CHECKING(for crypt and sec libraries)
+test -f /lib/libcrypt_d.a || test -f /usr/lib/libcrypt_d.a && LIBS="$LIBS -lcrypt_d"
+oldlibs="$LIBS"
+LIBS="$LIBS -lcrypt"
+AC_CHECKING(crypt)
+AC_TRY_LINK(,,,LIBS="$oldlibs")
+test -f /lib/libsec.a || test -f /usr/lib/libsec.a && LIBS="$LIBS -lsec"
+test -f /lib/libshadow.a || test -f /usr/lib/libshadow.a && LIBS="$LIBS -lshadow"
+oldlibs="$LIBS"
+LIBS="$LIBS -lsun"
+AC_CHECKING(IRIX sun library)
+AC_TRY_LINK(,,,LIBS="$oldlibs")
+
+AC_CHECKING(syslog)
+AC_TRY_LINK(,[closelog();], , [oldlibs="$LIBS"
+LIBS="$LIBS -lbsd"
+AC_CHECKING(syslog in libbsd.a)
+AC_TRY_LINK(, [closelog();], AC_NOTE(- found.), [LIBS="$oldlibs"
+AC_NOTE(- bad news: syslog missing.) AC_DEFINE(NOSYSLOG)])])
+
+AC_EGREP_CPP(yes,
+[#ifdef M_UNIX
+ yes;
+#endif
+], LIBS="$LIBS -lsocket -lcrypt_i")
+
+dnl
+dnl **** misc things ****
+dnl
+AC_CHECKING(wait union)
+AC_TRY_COMPILE([#include <sys/types.h>
+#include <sys/wait.h>
+],[
+ union wait x;
+ int y;
+#ifdef WEXITSTATUS
+ y = WEXITSTATUS(x);
+#endif
+],AC_DEFINE(BSDWAIT))
+
+if test -z "$butterfly"; then
+AC_CHECKING(for termio or termios)
+AC_TRY_CPP([#include <termio.h>], AC_DEFINE(TERMIO),
+if test -n "$posix"; then
+AC_TRY_CPP([#include <termios.h>], AC_DEFINE(TERMIO))
+fi
+)
+fi
+
+dnl AC_CHECK_HEADER(shadow.h, AC_DEFINE(SHADOWPW))
+AC_CHECKING(getspnam)
+AC_TRY_LINK([#include <shadow.h>], [getspnam("x");],AC_DEFINE(SHADOWPW))
+
+AC_CHECKING(getttyent)
+AC_TRY_LINK(,[getttyent();], AC_DEFINE(GETTTYENT))
+
+AC_CHECKING(fdwalk)
+AC_TRY_LINK([#include <stdlib.h>], [fdwalk(NULL, NULL);],AC_DEFINE(HAVE_FDWALK))
+
+AC_CHECKING(whether memcpy/memmove/bcopy handles overlapping arguments)
+AC_TRY_RUN([
+main() {
+ char buf[10];
+ strcpy(buf, "abcdefghi");
+ bcopy(buf, buf + 2, 3);
+ if (strncmp(buf, "ababcf", 6))
+ exit(1);
+ strcpy(buf, "abcdefghi");
+ bcopy(buf + 2, buf, 3);
+ if (strncmp(buf, "cdedef", 6))
+ exit(1);
+ exit(0); /* libc version works properly. */
+}], AC_DEFINE(USEBCOPY))
+
+AC_TRY_RUN([
+#define bcopy(s,d,l) memmove(d,s,l)
+main() {
+ char buf[10];
+ strcpy(buf, "abcdefghi");
+ bcopy(buf, buf + 2, 3);
+ if (strncmp(buf, "ababcf", 6))
+ exit(1);
+ strcpy(buf, "abcdefghi");
+ bcopy(buf + 2, buf, 3);
+ if (strncmp(buf, "cdedef", 6))
+ exit(1);
+ exit(0); /* libc version works properly. */
+}], AC_DEFINE(USEMEMMOVE))
+
+
+AC_TRY_RUN([
+#define bcopy(s,d,l) memcpy(d,s,l)
+main() {
+ char buf[10];
+ strcpy(buf, "abcdefghi");
+ bcopy(buf, buf + 2, 3);
+ if (strncmp(buf, "ababcf", 6))
+ exit(1);
+ strcpy(buf, "abcdefghi");
+ bcopy(buf + 2, buf, 3);
+ if (strncmp(buf, "cdedef", 6))
+ exit(1);
+ exit(0); /* libc version works properly. */
+}], AC_DEFINE(USEMEMCPY))
+
+AC_SYS_LONG_FILE_NAMES
+
+AC_MSG_CHECKING(for vsprintf)
+AC_TRY_LINK([#include <stdarg.h>],[va_list valist; vsprintf(0,0,valist);], AC_MSG_RESULT(yes);AC_DEFINE(USEVARARGS), AC_MSG_RESULT(no))
+
+AC_HEADER_DIRENT
+
+AC_MSG_CHECKING(for setenv)
+if test -z "$ac_setenv_args"; then
+ AC_TRY_LINK(
+ [#include <stdlib.h>],
+ [
+ setenv((char *) 0, (char *) 0, 0);
+ ], ac_setenv_args=3)
+fi
+if test -z "$ac_setenv_args"; then
+ AC_TRY_LINK(
+ [#include <stdlib.h>],
+ [
+ setenv((char *) 0, (char *) 0);
+ ], ac_setenv_args=2)
+fi
+if test -n "$ac_setenv_args"; then
+ AC_DEFINE(USESETENV)
+ if test "$ac_setenv_args" = 3; then
+ AC_DEFINE(HAVE_SETENV_3)
+ elif test "$ac_setenv_args" = 2; then
+ AC_DEFINE(HAVE_SETENV_2)
+ fi
+else
+ AC_MSG_RESULT(no)
+ AC_MSG_CHECKING(for putenv)
+ AC_TRY_LINK(,[putenv((char *)0);unsetenv((char *)0);], AC_MSG_RESULT(yes) , AC_MSG_RESULT(no);AC_DEFINE(NEEDPUTENV))
+fi
+AC_MSG_CHECKING([for nl_langinfo(CODESET)])
+AC_TRY_LINK([
+#include <langinfo.h>
+],[nl_langinfo(CODESET);], AC_MSG_RESULT(yes);AC_DEFINE(HAVE_NL_LANGINFO), AC_MSG_RESULT(no))
+
+AC_SEARCH_LIBS(gethostname, nsl)
+
+AC_CHECK_FUNCS(rename fchmod fchown strerror lstat _exit utimes vsnprintf getcwd setlocale strftime)
+
+AC_ARG_ENABLE(pam, [ --enable-pam enable PAM support])
+if test "$enable_pam" = "yes"; then
+ AC_MSG_CHECKING(for PAM support)
+ oldlibs="$LIBS"
+ LIBS="$LIBS -lpam"
+ AC_TRY_LINK([#include <security/pam_appl.h>], [
+ pam_start(0, 0, 0, 0);
+ pam_authenticate(0, 0);
+ pam_end(0,0);
+ ], AC_MSG_RESULT(yes);AC_DEFINE(USE_PAM),
+ AC_MSG_RESULT(no);LIBS="$oldlibs")
+fi
+
+AC_ARG_ENABLE(use_locale, [ --enable-use-locale use localized month/day names])
+if test "$enable_use_locale" = "yes"; then
+ AC_DEFINE(USE_LOCALE)
+fi
+AC_ARG_ENABLE(telnet, [ --enable-telnet enable builtin telnet])
+if test "$enable_telnet" = "yes"; then
+ AC_DEFINE(BUILTIN_TELNET)
+fi
+AC_ARG_ENABLE(colors256, [ --enable-colors256 enable support for 256 colors])
+if test "$enable_colors256" = "yes"; then
+ AC_DEFINE(COLORS256)
+fi
+AC_ARG_ENABLE(rxvt_osc, [ --enable-rxvt_osc enable support for rxvt OSC codes])
+if test "$enable_rxvt_osc" = "yes"; then
+ AC_DEFINE(RXVT_OSC)
+fi
+
+dnl
+dnl **** the end ****
+dnl
+if test -z "$old_CFLAGS"; then
+ if test "x$CFLAGS" = "x-g"; then
+ CFLAGS="-O"
+ fi
+fi
+dnl Ptx bug workaround -- insert -lc after -ltermcap
+test -n "$seqptx" && LIBS="-ltermcap -lc -lsocket -linet -lnsl -lsec -lseq"
+
+AC_TRY_RUN(main(){exit(0);},,AC_MSG_ERROR(Can't run the compiler - internal error. Sorry.))
+
+ETCSCREENRC=
+AC_MSG_CHECKING(for the global screenrc file)
+AC_ARG_WITH(sys-screenrc, [ --with-sys-screenrc=path to the global screenrc file], [ ETCSCREENRC="${withval}" ])
+AC_SUBST(ETCSCREENRC)
+
+AC_OUTPUT(Makefile doc/Makefile, [[
+# a hook for preserving undef directive in config.h
+mv config.h conftest
+sed -e 's@^\(.*\)defin.\( .*\) .*/\*\(.*KEEP_UNDEF_HERE\)@\1undef\2 /\*\3@' < conftest > config.h
+rm -f conftest
+]])
+
+echo ""
+if test -z "$AWK"; then
+echo "!!! Since you have no awk you must copy the files 'comm.h.dist'"
+echo "!!! and 'term.h.dist' to 'comm.h' and 'term.h'."
+echo "!!! Do _not_ change the user configuration section in config.h!"
+echo "Please check the pathnames in the Makefile."
+else
+echo "Now please check the pathnames in the Makefile and in the user"
+echo "configuration section in config.h."
+fi
+echo "Then type 'make' to make screen. Good luck."
+echo ""
diff --git a/display.c b/display.c
new file mode 100644
index 0000000..f4bcf89
--- /dev/null
+++ b/display.c
@@ -0,0 +1,3820 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+#include <signal.h>
+#include <fcntl.h>
+#ifndef sun
+# include <sys/ioctl.h>
+#endif
+
+#include "config.h"
+#include "screen.h"
+#include "extern.h"
+#include "braille.h"
+#include "canvas.h"
+
+static int CountChars __P((int));
+static int DoAddChar __P((int));
+static int BlankResize __P((int, int));
+static int CallRewrite __P((int, int, int, int));
+static void disp_readev_fn __P((struct event *, char *));
+static void disp_writeev_fn __P((struct event *, char *));
+#ifdef linux
+static void disp_writeev_eagain __P((struct event *, char *));
+#endif
+static void disp_status_fn __P((struct event *, char *));
+static void disp_hstatus_fn __P((struct event *, char *));
+static void disp_blocked_fn __P((struct event *, char *));
+#ifdef MAPKEYS
+static void disp_map_fn __P((struct event *, char *));
+#endif
+static void disp_idle_fn __P((struct event *, char *));
+#ifdef BLANKER_PRG
+static void disp_blanker_fn __P((struct event *, char *));
+#endif
+static void WriteLP __P((int, int));
+static void INSERTCHAR __P((int));
+static void RAW_PUTCHAR __P((int));
+#ifdef COLOR
+static void SetBackColor __P((int));
+#endif
+static void RemoveStatusMinWait __P((void));
+
+
+extern struct layer *flayer;
+extern struct win *windows, *fore;
+extern struct LayFuncs WinLf;
+
+extern int use_hardstatus;
+extern int MsgWait, MsgMinWait;
+extern const int Z0width, Z1width;
+extern unsigned char *blank, *null;
+extern struct mline mline_blank, mline_null, mline_old;
+extern struct mchar mchar_null, mchar_blank, mchar_so;
+extern struct NewWindow nwin_default;
+extern struct action idleaction;
+
+/* XXX shouldn't be here */
+extern char *hstatusstring;
+extern char *captionstring;
+
+extern int pastefont;
+extern int idletimo;
+
+#ifdef BLANKER_PRG
+extern int pty_preopen;
+#if defined(TIOCSWINSZ) || defined(TIOCGWINSZ)
+extern struct winsize glwz;
+#endif
+extern char **NewEnv;
+extern int real_uid, real_gid;
+#endif
+
+/*
+ * tputs needs this to calculate the padding
+ */
+#ifndef NEED_OSPEED
+extern
+#endif /* NEED_OSPEED */
+short ospeed;
+
+
+struct display *display, *displays;
+#ifdef COLOR
+int attr2color[8][4];
+int nattr2color;
+#endif
+
+#ifndef MULTI
+struct display TheDisplay;
+#endif
+
+/*
+ * The default values
+ */
+int defobuflimit = OBUF_MAX;
+int defnonblock = -1;
+int defmousetrack = 0;
+#ifdef AUTO_NUKE
+int defautonuke = 0;
+#endif
+int captionalways;
+int hardstatusemu = HSTATUS_IGNORE;
+
+int focusminwidth, focusminheight;
+
+/*
+ * Default layer management
+ */
+
+void
+DefProcess(bufp, lenp)
+char **bufp;
+int *lenp;
+{
+ *bufp += *lenp;
+ *lenp = 0;
+}
+
+void
+DefRedisplayLine(y, xs, xe, isblank)
+int y, xs, xe, isblank;
+{
+ if (isblank == 0 && y >= 0)
+ DefClearLine(y, xs, xe, 0);
+}
+
+void
+DefClearLine(y, xs, xe, bce)
+int y, xs, xe, bce;
+{
+ LClearLine(flayer, y, xs, xe, bce, (struct mline *)0);
+}
+
+/*ARGSUSED*/
+int
+DefRewrite(y, xs, xe, rend, doit)
+int y, xs, xe, doit;
+struct mchar *rend;
+{
+ return EXPENSIVE;
+}
+
+/*ARGSUSED*/
+int
+DefResize(wi, he)
+int wi, he;
+{
+ return -1;
+}
+
+void
+DefRestore()
+{
+ LAY_DISPLAYS(flayer, InsertMode(0));
+ /* ChangeScrollRegion(0, D_height - 1); */
+ LKeypadMode(flayer, 0);
+ LCursorkeysMode(flayer, 0);
+ LCursorVisibility(flayer, 0);
+ LMouseMode(flayer, 0);
+ LSetRendition(flayer, &mchar_null);
+ LSetFlow(flayer, nwin_default.flowflag & FLOW_NOW);
+}
+
+/*
+ * Blank layer management
+ */
+
+struct LayFuncs BlankLf =
+{
+ DefProcess,
+ 0,
+ DefRedisplayLine,
+ DefClearLine,
+ DefRewrite,
+ BlankResize,
+ DefRestore,
+ 0
+};
+
+/*ARGSUSED*/
+static int
+BlankResize(wi, he)
+int wi, he;
+{
+ flayer->l_width = wi;
+ flayer->l_height = he;
+ return 0;
+}
+
+
+/*
+ * Generate new display, start with a blank layer.
+ * The termcap arrays are not initialised here.
+ * The new display is placed in the displays list.
+ */
+
+struct display *
+MakeDisplay(uname, utty, term, fd, pid, Mode)
+char *uname, *utty, *term;
+int fd, pid;
+struct mode *Mode;
+{
+ struct acluser **u;
+ struct baud_values *b;
+
+ if (!*(u = FindUserPtr(uname)) && UserAdd(uname, (char *)0, u))
+ return 0; /* could not find or add user */
+
+#ifdef MULTI
+ if ((display = (struct display *)calloc(1, sizeof(*display))) == 0)
+ return 0;
+#else
+ if (displays)
+ return 0;
+ bzero((char *)&TheDisplay, sizeof(TheDisplay));
+ display = &TheDisplay;
+#endif
+ display->d_next = displays;
+ displays = display;
+ D_flow = 1;
+ D_nonblock = defnonblock;
+ D_userfd = fd;
+ D_readev.fd = D_writeev.fd = fd;
+ D_readev.type = EV_READ;
+ D_writeev.type = EV_WRITE;
+ D_readev.data = D_writeev.data = (char *)display;
+ D_readev.handler = disp_readev_fn;
+ D_writeev.handler = disp_writeev_fn;
+ evenq(&D_readev);
+ D_writeev.condpos = &D_obuflen;
+ D_writeev.condneg = &D_obuffree;
+ evenq(&D_writeev);
+ D_statusev.type = EV_TIMEOUT;
+ D_statusev.data = (char *)display;
+ D_statusev.handler = disp_status_fn;
+ D_hstatusev.type = EV_TIMEOUT;
+ D_hstatusev.data = (char *)display;
+ D_hstatusev.handler = disp_hstatus_fn;
+ D_blockedev.type = EV_TIMEOUT;
+ D_blockedev.data = (char *)display;
+ D_blockedev.handler = disp_blocked_fn;
+ D_blockedev.condpos = &D_obuffree;
+ D_blockedev.condneg = &D_obuflenmax;
+ D_hstatusev.handler = disp_hstatus_fn;
+#ifdef MAPKEYS
+ D_mapev.type = EV_TIMEOUT;
+ D_mapev.data = (char *)display;
+ D_mapev.handler = disp_map_fn;
+#endif
+ D_idleev.type = EV_TIMEOUT;
+ D_idleev.data = (char *)display;
+ D_idleev.handler = disp_idle_fn;
+#ifdef BLANKER_PRG
+ D_blankerev.type = EV_READ;
+ D_blankerev.data = (char *)display;
+ D_blankerev.handler = disp_blanker_fn;
+ D_blankerev.fd = -1;
+#endif
+ D_OldMode = *Mode;
+ D_status_obuffree = -1;
+ Resize_obuf(); /* Allocate memory for buffer */
+ D_obufmax = defobuflimit;
+ D_obuflenmax = D_obuflen - D_obufmax;
+#ifdef AUTO_NUKE
+ D_auto_nuke = defautonuke;
+#endif
+ D_obufp = D_obuf;
+ D_printfd = -1;
+ D_userpid = pid;
+
+#ifdef POSIX
+ if ((b = lookup_baud((int)cfgetospeed(&D_OldMode.tio))))
+ D_dospeed = b->idx;
+#else
+# ifdef TERMIO
+ if ((b = lookup_baud(D_OldMode.tio.c_cflag & CBAUD)))
+ D_dospeed = b->idx;
+# else
+ D_dospeed = (short)D_OldMode.m_ttyb.sg_ospeed;
+# endif
+#endif
+ debug1("New displays ospeed = %d\n", D_dospeed);
+
+ strncpy(D_usertty, utty, sizeof(D_usertty) - 1);
+ D_usertty[sizeof(D_usertty) - 1] = 0;
+ strncpy(D_termname, term, MAXTERMLEN);
+ D_termname[MAXTERMLEN] = 0;
+ D_user = *u;
+ D_processinput = ProcessInput;
+ D_mousetrack = defmousetrack;
+ return display;
+}
+
+
+void
+FreeDisplay()
+{
+ struct win *p;
+#ifdef MULTI
+ struct display *d, **dp;
+#endif
+
+#ifdef FONT
+ FreeTransTable();
+#endif
+#ifdef BLANKER_PRG
+ KillBlanker();
+#endif
+ if (D_userfd >= 0)
+ {
+ Flush(3);
+ if (!display)
+ return;
+ SetTTY(D_userfd, &D_OldMode);
+ fcntl(D_userfd, F_SETFL, 0);
+ }
+ freetty();
+ if (D_tentry)
+ free(D_tentry);
+ D_tentry = 0;
+ if (D_processinputdata)
+ free(D_processinputdata);
+ D_processinputdata = 0;
+ D_tcinited = 0;
+ evdeq(&D_hstatusev);
+ evdeq(&D_statusev);
+ evdeq(&D_readev);
+ evdeq(&D_writeev);
+ evdeq(&D_blockedev);
+#ifdef MAPKEYS
+ evdeq(&D_mapev);
+ if (D_kmaps)
+ {
+ free(D_kmaps);
+ D_kmaps = 0;
+ D_aseqs = 0;
+ D_nseqs = 0;
+ D_seqp = 0;
+ D_seql = 0;
+ D_seqh = 0;
+ }
+#endif
+ evdeq(&D_idleev);
+#ifdef BLANKER_PRG
+ evdeq(&D_blankerev);
+#endif
+#ifdef HAVE_BRAILLE
+ if (bd.bd_dpy == display)
+ {
+ bd.bd_start_braille = 0;
+ StartBraille();
+ }
+#endif
+
+#ifdef MULTI
+ for (dp = &displays; (d = *dp) ; dp = &d->d_next)
+ if (d == display)
+ break;
+ ASSERT(d);
+ if (D_status_lastmsg)
+ free(D_status_lastmsg);
+ if (D_obuf)
+ free(D_obuf);
+ *dp = display->d_next;
+#else /* MULTI */
+ ASSERT(display == displays);
+ ASSERT(display == &TheDisplay);
+ displays = 0;
+#endif /* MULTI */
+
+ while (D_canvas.c_slperp)
+ FreeCanvas(D_canvas.c_slperp);
+ D_cvlist = 0;
+
+ for (p = windows; p; p = p->w_next)
+ {
+ if (p->w_pdisplay == display)
+ p->w_pdisplay = 0;
+ if (p->w_lastdisp == display)
+ p->w_lastdisp = 0;
+ if (p->w_readev.condneg == &D_status || p->w_readev.condneg == &D_obuflenmax)
+ p->w_readev.condpos = p->w_readev.condneg = 0;
+ }
+#ifdef ZMODEM
+ for (p = windows; p; p = p->w_next)
+ if (p->w_zdisplay == display)
+ zmodem_abort(p, 0);
+#endif
+ if (D_mousetrack)
+ {
+ D_mousetrack = 0;
+ MouseMode(0);
+ }
+#ifdef MULTI
+ free((char *)display);
+#endif
+ display = 0;
+}
+
+/*
+ * if the adaptflag is on, we keep the size of this display, else
+ * we may try to restore our old window sizes.
+ */
+void
+InitTerm(adapt)
+int adapt;
+{
+ ASSERT(display);
+ ASSERT(D_tcinited);
+ D_top = D_bot = -1;
+ AddCStr(D_IS);
+ AddCStr(D_TI);
+ /* Check for toggle */
+ if (D_IM && strcmp(D_IM, D_EI))
+ AddCStr(D_EI);
+ D_insert = 0;
+#ifdef MAPKEYS
+ AddCStr(D_KS);
+ AddCStr(D_CCS);
+#else
+ /* Check for toggle */
+ if (D_KS && strcmp(D_KS, D_KE))
+ AddCStr(D_KE);
+ if (D_CCS && strcmp(D_CCS, D_CCE))
+ AddCStr(D_CCE);
+#endif
+ D_keypad = 0;
+ D_cursorkeys = 0;
+ AddCStr(D_ME);
+ AddCStr(D_EA);
+ AddCStr(D_CE0);
+ D_rend = mchar_null;
+ D_atyp = 0;
+ if (adapt == 0)
+ ResizeDisplay(D_defwidth, D_defheight);
+ ChangeScrollRegion(0, D_height - 1);
+ D_x = D_y = 0;
+ Flush(3);
+ ClearAll();
+ debug1("we %swant to adapt all our windows to the display\n",
+ (adapt) ? "" : "don't ");
+ /* In case the size was changed by a init sequence */
+ CheckScreenSize((adapt) ? 2 : 0);
+}
+
+void
+FinitTerm()
+{
+ ASSERT(display);
+#ifdef BLANKER_PRG
+ KillBlanker();
+#endif
+ if (D_tcinited)
+ {
+ ResizeDisplay(D_defwidth, D_defheight);
+ InsertMode(0);
+ ChangeScrollRegion(0, D_height - 1);
+ KeypadMode(0);
+ CursorkeysMode(0);
+ CursorVisibility(0);
+ if (D_mousetrack)
+ D_mousetrack = 0;
+ MouseMode(0);
+ SetRendition(&mchar_null);
+ SetFlow(FLOW_NOW);
+#ifdef MAPKEYS
+ AddCStr(D_KE);
+ AddCStr(D_CCE);
+#endif
+ if (D_hstatus)
+ ShowHStatus((char *)0);
+#ifdef RXVT_OSC
+ ClearAllXtermOSC();
+#endif
+ D_x = D_y = -1;
+ GotoPos(0, D_height - 1);
+ AddChar('\r');
+ AddChar('\n');
+ AddCStr(D_TE);
+ }
+ Flush(3);
+}
+
+
+static void
+INSERTCHAR(c)
+int c;
+{
+ ASSERT(display);
+ if (!D_insert && D_x < D_width - 1)
+ {
+ if (D_IC || D_CIC)
+ {
+ if (D_IC)
+ AddCStr(D_IC);
+ else
+ AddCStr2(D_CIC, 1);
+ RAW_PUTCHAR(c);
+ return;
+ }
+ InsertMode(1);
+ if (!D_insert)
+ {
+ RefreshLine(D_y, D_x, D_width-1, 0);
+ return;
+ }
+ }
+ RAW_PUTCHAR(c);
+}
+
+void
+PUTCHAR(c)
+int c;
+{
+ ASSERT(display);
+ if (D_insert && D_x < D_width - 1)
+ InsertMode(0);
+ RAW_PUTCHAR(c);
+}
+
+void
+PUTCHARLP(c)
+int c;
+{
+ if (D_x < D_width - 1)
+ {
+ if (D_insert)
+ InsertMode(0);
+ RAW_PUTCHAR(c);
+ return;
+ }
+ if (D_CLP || D_y != D_bot)
+ {
+ int y = D_y;
+ RAW_PUTCHAR(c);
+ if (D_AM && !D_CLP)
+ GotoPos(D_width - 1, y);
+ return;
+ }
+ debug("PUTCHARLP: lp_missing!\n");
+ D_lp_missing = 1;
+ D_rend.image = c;
+ D_lpchar = D_rend;
+#ifdef DW_CHARS
+ /* XXX -> PutChar ? */
+ if (D_mbcs)
+ {
+ D_lpchar.mbcs = c;
+ D_lpchar.image = D_mbcs;
+ D_mbcs = 0;
+ D_x--;
+ }
+#endif
+}
+
+/*
+ * RAW_PUTCHAR() is for all text that will be displayed.
+ * NOTE: charset Nr. 0 has a conversion table, but c1, c2, ... don't.
+ */
+
+STATIC void
+RAW_PUTCHAR(c)
+int c;
+{
+ ASSERT(display);
+
+#ifdef FONT
+# ifdef UTF8
+ if (D_encoding == UTF8)
+ {
+ c = (c & 255) | (unsigned char)D_rend.font << 8 | (unsigned char)D_rend.fontx << 16;
+# ifdef DW_CHARS
+ if (D_mbcs)
+ {
+ c = D_mbcs;
+ if (D_x == D_width)
+ D_x += D_AM ? 1 : -1;
+ D_mbcs = 0;
+ }
+ else if (utf8_isdouble(c))
+ {
+ D_mbcs = c;
+ D_x++;
+ return;
+ }
+# endif
+ if (c < 32)
+ {
+ AddCStr2(D_CS0, '0');
+ AddChar(c + 0x5f);
+ AddCStr(D_CE0);
+ goto addedutf8;
+ }
+ if (c < 0x80)
+ {
+ if (D_xtable && D_xtable[(int)(unsigned char)D_rend.font] && D_xtable[(int)(unsigned char)D_rend.font][(int)(unsigned char)c])
+ AddStr(D_xtable[(int)(unsigned char)D_rend.font][(int)(unsigned char)c]);
+ else
+ AddChar(c);
+ }
+ else
+ AddUtf8(c);
+ goto addedutf8;
+ }
+# endif
+# ifdef DW_CHARS
+ if (is_dw_font(D_rend.font))
+ {
+ int t = c;
+ if (D_mbcs == 0)
+ {
+ D_mbcs = c;
+ D_x++;
+ return;
+ }
+ D_x--;
+ if (D_x == D_width - 1)
+ D_x += D_AM ? 1 : -1;
+ c = D_mbcs;
+ D_mbcs = t;
+ }
+# endif
+# if defined(ENCODINGS) && defined(DW_CHARS)
+ if (D_encoding)
+ c = PrepareEncodedChar(c);
+# endif
+# ifdef DW_CHARS
+ kanjiloop:
+# endif
+ if (D_xtable && D_xtable[(int)(unsigned char)D_rend.font] && D_xtable[(int)(unsigned char)D_rend.font][(int)(unsigned char)c])
+ AddStr(D_xtable[(int)(unsigned char)D_rend.font][(int)(unsigned char)c]);
+ else
+ AddChar(D_rend.font != '0' ? c : D_c0_tab[(int)(unsigned char)c]);
+#else /* FONT */
+ AddChar(c);
+#endif /* FONT */
+
+#ifdef UTF8
+addedutf8:
+#endif
+ if (++D_x >= D_width)
+ {
+ if (D_AM == 0)
+ D_x = D_width - 1;
+ else if (!D_CLP || D_x > D_width)
+ {
+ D_x -= D_width;
+ if (D_y < D_height-1 && D_y != D_bot)
+ D_y++;
+ }
+ }
+#ifdef DW_CHARS
+ if (D_mbcs)
+ {
+ c = D_mbcs;
+ D_mbcs = 0;
+ goto kanjiloop;
+ }
+#endif
+}
+
+static int
+DoAddChar(c)
+int c;
+{
+ /* this is for ESC-sequences only (AddChar is a macro) */
+ AddChar(c);
+ return c;
+}
+
+void
+AddCStr(s)
+char *s;
+{
+ if (display && s && *s)
+ {
+ ospeed = D_dospeed;
+ tputs(s, 1, DoAddChar);
+ }
+}
+
+void
+AddCStr2(s, c)
+char *s;
+int c;
+{
+ if (display && s && *s)
+ {
+ ospeed = D_dospeed;
+ tputs(tgoto(s, 0, c), 1, DoAddChar);
+ }
+}
+
+
+/* Insert mode is a toggle on some terminals, so we need this hack:
+ */
+void
+InsertMode(on)
+int on;
+{
+ if (display && on != D_insert && D_IM)
+ {
+ D_insert = on;
+ if (on)
+ AddCStr(D_IM);
+ else
+ AddCStr(D_EI);
+ }
+}
+
+/* ...and maybe keypad application mode is a toggle, too:
+ */
+void
+KeypadMode(on)
+int on;
+{
+#ifdef MAPKEYS
+ if (display)
+ D_keypad = on;
+#else
+ if (display && D_keypad != on && D_KS)
+ {
+ D_keypad = on;
+ if (on)
+ AddCStr(D_KS);
+ else
+ AddCStr(D_KE);
+ }
+#endif
+}
+
+void
+CursorkeysMode(on)
+int on;
+{
+#ifdef MAPKEYS
+ if (display)
+ D_cursorkeys = on;
+#else
+ if (display && D_cursorkeys != on && D_CCS)
+ {
+ D_cursorkeys = on;
+ if (on)
+ AddCStr(D_CCS);
+ else
+ AddCStr(D_CCE);
+ }
+#endif
+}
+
+void
+ReverseVideo(on)
+int on;
+{
+ if (display && D_revvid != on && D_CVR)
+ {
+ D_revvid = on;
+ if (D_revvid)
+ AddCStr(D_CVR);
+ else
+ AddCStr(D_CVN);
+ }
+}
+
+void
+CursorVisibility(v)
+int v;
+{
+ if (display && D_curvis != v)
+ {
+ if (D_curvis)
+ AddCStr(D_VE); /* do this always, just to be safe */
+ D_curvis = 0;
+ if (v == -1 && D_VI)
+ AddCStr(D_VI);
+ else if (v == 1 && D_VS)
+ AddCStr(D_VS);
+ else
+ return;
+ D_curvis = v;
+ }
+}
+
+void
+MouseMode(mode)
+int mode;
+{
+ if (!display)
+ return;
+
+ if (mode < D_mousetrack)
+ mode = D_mousetrack;
+
+ if (D_mouse != mode)
+ {
+ char mousebuf[20];
+ if (!D_CXT)
+ return;
+ if (D_mouse)
+ {
+ sprintf(mousebuf, "\033[?%dl", D_mouse);
+ AddStr(mousebuf);
+ }
+ if (mode)
+ {
+ sprintf(mousebuf, "\033[?%dh", mode);
+ AddStr(mousebuf);
+ }
+ D_mouse = mode;
+ }
+}
+
+static int StrCost;
+
+/* ARGSUSED */
+static int
+CountChars(c)
+int c;
+{
+ StrCost++;
+ return c;
+}
+
+int
+CalcCost(s)
+register char *s;
+{
+ ASSERT(display);
+ if (s)
+ {
+ StrCost = 0;
+ ospeed = D_dospeed;
+ tputs(s, 1, CountChars);
+ return StrCost;
+ }
+ else
+ return EXPENSIVE;
+}
+
+static int
+CallRewrite(y, xs, xe, doit)
+int y, xs, xe, doit;
+{
+ struct canvas *cv, *cvlist, *cvlnext;
+ struct viewport *vp;
+ struct layer *oldflayer;
+ int cost;
+
+ debug3("CallRewrite %d %d %d\n", y, xs, xe);
+ ASSERT(display);
+ ASSERT(xe >= xs);
+
+ vp = 0;
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ {
+ if (y < cv->c_ys || y > cv->c_ye || xe < cv->c_xs || xs > cv->c_xe)
+ continue;
+ for (vp = cv->c_vplist; vp; vp = vp->v_next)
+ if (y >= vp->v_ys && y <= vp->v_ye && xe >= vp->v_xs && xs <= vp->v_xe)
+ break;
+ if (vp)
+ break;
+ }
+ if (doit)
+ {
+ oldflayer = flayer;
+ flayer = cv->c_layer;
+ cvlist = flayer->l_cvlist;
+ cvlnext = cv->c_lnext;
+ flayer->l_cvlist = cv;
+ cv->c_lnext = 0;
+ LayRewrite(y - vp->v_yoff, xs - vp->v_xoff, xe - vp->v_xoff, &D_rend, 1);
+ flayer->l_cvlist = cvlist;
+ cv->c_lnext = cvlnext;
+ flayer = oldflayer;
+ return 0;
+ }
+ if (cv == 0 || cv->c_layer == 0)
+ return EXPENSIVE; /* not found or nothing on it */
+ if (xs < vp->v_xs || xe > vp->v_xe)
+ return EXPENSIVE; /* crosses viewport boundaries */
+ if (y - vp->v_yoff < 0 || y - vp->v_yoff >= cv->c_layer->l_height)
+ return EXPENSIVE; /* line not on layer */
+ if (xs - vp->v_xoff < 0 || xe - vp->v_xoff >= cv->c_layer->l_width)
+ return EXPENSIVE; /* line not on layer */
+#ifdef UTF8
+ if (D_encoding == UTF8)
+ D_rend.font = 0;
+#endif
+ oldflayer = flayer;
+ flayer = cv->c_layer;
+ debug3("Calling Rewrite %d %d %d\n", y - vp->v_yoff, xs - vp->v_xoff, xe - vp->v_xoff);
+ cost = LayRewrite(y - vp->v_yoff, xs - vp->v_xoff, xe - vp->v_xoff, &D_rend, 0);
+ flayer = oldflayer;
+ if (D_insert)
+ cost += D_EIcost + D_IMcost;
+ return cost;
+}
+
+
+void
+GotoPos(x2, y2)
+int x2, y2;
+{
+ register int dy, dx, x1, y1;
+ register int costx, costy;
+ register int m;
+ register char *s;
+ int CMcost;
+ enum move_t xm = M_NONE, ym = M_NONE;
+
+ if (!display)
+ return;
+
+ x1 = D_x;
+ y1 = D_y;
+
+ if (x1 == D_width)
+ {
+ if (D_CLP && D_AM)
+ x1 = -1; /* don't know how the terminal treats this */
+ else
+ x1--;
+ }
+ if (x2 == D_width)
+ x2--;
+ dx = x2 - x1;
+ dy = y2 - y1;
+ if (dy == 0 && dx == 0)
+ return;
+ debug2("GotoPos (%d,%d)", x1, y1);
+ debug2(" -> (%d,%d)\n", x2, y2);
+ if (!D_MS) /* Safe to move ? */
+ SetRendition(&mchar_null);
+ if (y1 < 0 /* don't know the y position */
+ || (y2 > D_bot && y1 <= D_bot) /* have to cross border */
+ || (y2 < D_top && y1 >= D_top)) /* of scrollregion ? */
+ {
+ DoCM:
+ if (D_HO && !x2 && !y2)
+ AddCStr(D_HO);
+ else
+ AddCStr(tgoto(D_CM, x2, y2));
+ D_x = x2;
+ D_y = y2;
+ return;
+ }
+
+ /* some scrollregion implementations don't allow movements
+ * away from the region. sigh.
+ */
+ if ((y1 > D_bot && y2 > y1) || (y1 < D_top && y2 < y1))
+ goto DoCM;
+
+ /* Calculate CMcost */
+ if (D_HO && !x2 && !y2)
+ s = D_HO;
+ else
+ s = tgoto(D_CM, x2, y2);
+ CMcost = CalcCost(s);
+
+ /* Calculate the cost to move the cursor to the right x position */
+ costx = EXPENSIVE;
+ if (x1 >= 0) /* relativ x positioning only if we know where we are */
+ {
+ if (dx > 0)
+ {
+ if (D_CRI && (dx > 1 || !D_ND))
+ {
+ costx = CalcCost(tgoto(D_CRI, 0, dx));
+ xm = M_CRI;
+ }
+ if ((m = D_NDcost * dx) < costx)
+ {
+ costx = m;
+ xm = M_RI;
+ }
+ /* Speedup: dx <= LayRewrite() */
+ if (dx < costx && (m = CallRewrite(y1, x1, x2 - 1, 0)) < costx)
+ {
+ costx = m;
+ xm = M_RW;
+ }
+ }
+ else if (dx < 0)
+ {
+ if (D_CLE && (dx < -1 || !D_BC))
+ {
+ costx = CalcCost(tgoto(D_CLE, 0, -dx));
+ xm = M_CLE;
+ }
+ if ((m = -dx * D_LEcost) < costx)
+ {
+ costx = m;
+ xm = M_LE;
+ }
+ }
+ else
+ costx = 0;
+ }
+ /* Speedup: LayRewrite() >= x2 */
+ if (x2 + D_CRcost < costx && (m = (x2 ? CallRewrite(y1, 0, x2 - 1, 0) : 0) + D_CRcost) < costx)
+ {
+ costx = m;
+ xm = M_CR;
+ }
+
+ /* Check if it is already cheaper to do CM */
+ if (costx >= CMcost)
+ goto DoCM;
+
+ /* Calculate the cost to move the cursor to the right y position */
+ costy = EXPENSIVE;
+ if (dy > 0)
+ {
+ if (D_CDO && dy > 1) /* DO & NL are always != 0 */
+ {
+ costy = CalcCost(tgoto(D_CDO, 0, dy));
+ ym = M_CDO;
+ }
+ if ((m = dy * ((x2 == 0) ? D_NLcost : D_DOcost)) < costy)
+ {
+ costy = m;
+ ym = M_DO;
+ }
+ }
+ else if (dy < 0)
+ {
+ if (D_CUP && (dy < -1 || !D_UP))
+ {
+ costy = CalcCost(tgoto(D_CUP, 0, -dy));
+ ym = M_CUP;
+ }
+ if ((m = -dy * D_UPcost) < costy)
+ {
+ costy = m;
+ ym = M_UP;
+ }
+ }
+ else
+ costy = 0;
+
+ /* Finally check if it is cheaper to do CM */
+ if (costx + costy >= CMcost)
+ goto DoCM;
+
+ switch (xm)
+ {
+ case M_LE:
+ while (dx++ < 0)
+ AddCStr(D_BC);
+ break;
+ case M_CLE:
+ AddCStr2(D_CLE, -dx);
+ break;
+ case M_RI:
+ while (dx-- > 0)
+ AddCStr(D_ND);
+ break;
+ case M_CRI:
+ AddCStr2(D_CRI, dx);
+ break;
+ case M_CR:
+ AddCStr(D_CR);
+ D_x = 0;
+ x1 = 0;
+ /* FALLTHROUGH */
+ case M_RW:
+ if (x1 < x2)
+ (void) CallRewrite(y1, x1, x2 - 1, 1);
+ break;
+ default:
+ break;
+ }
+
+ switch (ym)
+ {
+ case M_UP:
+ while (dy++ < 0)
+ AddCStr(D_UP);
+ break;
+ case M_CUP:
+ AddCStr2(D_CUP, -dy);
+ break;
+ case M_DO:
+ s = (x2 == 0) ? D_NL : D_DO;
+ while (dy-- > 0)
+ AddCStr(s);
+ break;
+ case M_CDO:
+ AddCStr2(D_CDO, dy);
+ break;
+ default:
+ break;
+ }
+ D_x = x2;
+ D_y = y2;
+}
+
+void
+ClearAll()
+{
+ ASSERT(display);
+ ClearArea(0, 0, 0, D_width - 1, D_width - 1, D_height - 1, 0, 0);
+}
+
+void
+ClearArea(x1, y1, xs, xe, x2, y2, bce, uselayfn)
+int x1, y1, xs, xe, x2, y2, bce, uselayfn;
+{
+ int y, xxe;
+ struct canvas *cv;
+ struct viewport *vp;
+
+ debug2("Clear %d,%d", x1, y1);
+ debug2(" %d-%d", xs, xe);
+ debug2(" %d,%d", x2, y2);
+ debug2(" uselayfn=%d bce=%d\n", uselayfn, bce);
+ ASSERT(display);
+ if (x1 == D_width)
+ x1--;
+ if (x2 == D_width)
+ x2--;
+ if (xs == -1)
+ xs = x1;
+ if (xe == -1)
+ xe = x2;
+ if (D_UT) /* Safe to erase ? */
+ SetRendition(&mchar_null);
+#ifdef COLOR
+ if (D_BE)
+ SetBackColor(bce);
+#endif
+ if (D_lp_missing && y1 <= D_bot && xe >= D_width - 1)
+ {
+ if (y2 > D_bot || (y2 == D_bot && x2 >= D_width - 1))
+ D_lp_missing = 0;
+ }
+ if (x2 == D_width - 1 && (xs == 0 || y1 == y2) && xe == D_width - 1 && y2 == D_height - 1 && (!bce || D_BE))
+ {
+#ifdef AUTO_NUKE
+ if (x1 == 0 && y1 == 0 && D_auto_nuke)
+ NukePending();
+#endif
+ if (x1 == 0 && y1 == 0 && D_CL)
+ {
+ AddCStr(D_CL);
+ D_y = D_x = 0;
+ return;
+ }
+ /*
+ * Workaround a hp700/22 terminal bug. Do not use CD where CE
+ * is also appropriate.
+ */
+ if (D_CD && (y1 < y2 || !D_CE))
+ {
+ GotoPos(x1, y1);
+ AddCStr(D_CD);
+ return;
+ }
+ }
+ if (x1 == 0 && xs == 0 && (xe == D_width - 1 || y1 == y2) && y1 == 0 && D_CCD && (!bce || D_BE))
+ {
+ GotoPos(x1, y1);
+ AddCStr(D_CCD);
+ return;
+ }
+ xxe = xe;
+ for (y = y1; y <= y2; y++, x1 = xs)
+ {
+ if (y == y2)
+ xxe = x2;
+ if (x1 == 0 && D_CB && (xxe != D_width - 1 || (D_x == xxe && D_y == y)) && (!bce || D_BE))
+ {
+ GotoPos(xxe, y);
+ AddCStr(D_CB);
+ continue;
+ }
+ if (xxe == D_width - 1 && D_CE && (!bce || D_BE))
+ {
+ GotoPos(x1, y);
+ AddCStr(D_CE);
+ continue;
+ }
+ if (uselayfn)
+ {
+ vp = 0;
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ {
+ if (y < cv->c_ys || y > cv->c_ye || xxe < cv->c_xs || x1 > cv->c_xe)
+ continue;
+ for (vp = cv->c_vplist; vp; vp = vp->v_next)
+ if (y >= vp->v_ys && y <= vp->v_ye && xxe >= vp->v_xs && x1 <= vp->v_xe)
+ break;
+ if (vp)
+ break;
+ }
+ if (cv && cv->c_layer && x1 >= vp->v_xs && xxe <= vp->v_xe &&
+ y - vp->v_yoff >= 0 && y - vp->v_yoff < cv->c_layer->l_height &&
+ xxe - vp->v_xoff >= 0 && x1 - vp->v_xoff < cv->c_layer->l_width)
+ {
+ struct layer *oldflayer = flayer;
+ struct canvas *cvlist, *cvlnext;
+ flayer = cv->c_layer;
+ cvlist = flayer->l_cvlist;
+ cvlnext = cv->c_lnext;
+ flayer->l_cvlist = cv;
+ cv->c_lnext = 0;
+ LayClearLine(y - vp->v_yoff, x1 - vp->v_xoff, xxe - vp->v_xoff, bce);
+ flayer->l_cvlist = cvlist;
+ cv->c_lnext = cvlnext;
+ flayer = oldflayer;
+ continue;
+ }
+ }
+ ClearLine((struct mline *)0, y, x1, xxe, bce);
+ }
+}
+
+
+/*
+ * if cur_only > 0, we only redisplay current line, as a full refresh is
+ * too expensive over a low baud line.
+ */
+void
+Redisplay(cur_only)
+int cur_only;
+{
+ ASSERT(display);
+
+ /* XXX do em all? */
+ InsertMode(0);
+ ChangeScrollRegion(0, D_height - 1);
+ KeypadMode(0);
+ CursorkeysMode(0);
+ CursorVisibility(0);
+ MouseMode(0);
+ SetRendition(&mchar_null);
+ SetFlow(FLOW_NOW);
+
+ ClearAll();
+#ifdef RXVT_OSC
+ RefreshXtermOSC();
+#endif
+ if (cur_only > 0 && D_fore)
+ RefreshArea(0, D_fore->w_y, D_width - 1, D_fore->w_y, 1);
+ else
+ RefreshAll(1);
+ RefreshHStatus();
+ CV_CALL(D_forecv, LayRestore();LaySetCursor());
+}
+
+void
+RedisplayDisplays(cur_only)
+int cur_only;
+{
+ struct display *olddisplay = display;
+ for (display = displays; display; display = display->d_next)
+ Redisplay(cur_only);
+ display = olddisplay;
+}
+
+
+/* XXX: use oml! */
+void
+ScrollH(y, xs, xe, n, bce, oml)
+int y, xs, xe, n, bce;
+struct mline *oml;
+{
+ int i;
+
+ if (n == 0)
+ return;
+ if (xe != D_width - 1)
+ {
+ RefreshLine(y, xs, xe, 0);
+ /* UpdateLine(oml, y, xs, xe); */
+ return;
+ }
+ GotoPos(xs, y);
+ if (D_UT)
+ SetRendition(&mchar_null);
+#ifdef COLOR
+ if (D_BE)
+ SetBackColor(bce);
+#endif
+ if (n > 0)
+ {
+ if (n >= xe - xs + 1)
+ n = xe - xs + 1;
+ if (D_CDC && !(n == 1 && D_DC))
+ AddCStr2(D_CDC, n);
+ else if (D_DC)
+ {
+ for (i = n; i--; )
+ AddCStr(D_DC);
+ }
+ else
+ {
+ RefreshLine(y, xs, xe, 0);
+ /* UpdateLine(oml, y, xs, xe); */
+ return;
+ }
+ }
+ else
+ {
+ if (-n >= xe - xs + 1)
+ n = -(xe - xs + 1);
+ if (!D_insert)
+ {
+ if (D_CIC && !(n == -1 && D_IC))
+ AddCStr2(D_CIC, -n);
+ else if (D_IC)
+ {
+ for (i = -n; i--; )
+ AddCStr(D_IC);
+ }
+ else if (D_IM)
+ {
+ InsertMode(1);
+ SetRendition(&mchar_null);
+#ifdef COLOR
+ SetBackColor(bce);
+#endif
+ for (i = -n; i--; )
+ INSERTCHAR(' ');
+ bce = 0; /* all done */
+ }
+ else
+ {
+ /* UpdateLine(oml, y, xs, xe); */
+ RefreshLine(y, xs, xe, 0);
+ return;
+ }
+ }
+ else
+ {
+ SetRendition(&mchar_null);
+#ifdef COLOR
+ SetBackColor(bce);
+#endif
+ for (i = -n; i--; )
+ INSERTCHAR(' ');
+ bce = 0; /* all done */
+ }
+ }
+ if (bce && !D_BE)
+ {
+ if (n > 0)
+ ClearLine((struct mline *)0, y, xe - n + 1, xe, bce);
+ else
+ ClearLine((struct mline *)0, y, xs, xs - n - 1, bce);
+ }
+ if (D_lp_missing && y == D_bot)
+ {
+ if (n > 0)
+ WriteLP(D_width - 1 - n, y);
+ D_lp_missing = 0;
+ }
+}
+
+void
+ScrollV(xs, ys, xe, ye, n, bce)
+int xs, ys, xe, ye, n, bce;
+{
+ int i;
+ int up;
+ int oldbot;
+ int alok, dlok, aldlfaster;
+ int missy = 0;
+
+ ASSERT(display);
+ if (n == 0)
+ return;
+ if (n >= ye - ys + 1 || -n >= ye - ys + 1)
+ {
+ ClearArea(xs, ys, xs, xe, xe, ye, bce, 0);
+ return;
+ }
+ if (xs > D_vpxmin || xe < D_vpxmax)
+ {
+ RefreshArea(xs, ys, xe, ye, 0);
+ return;
+ }
+
+ if (D_lp_missing)
+ {
+ if (D_bot > ye || D_bot < ys)
+ missy = D_bot;
+ else
+ {
+ missy = D_bot - n;
+ if (missy > ye || missy < ys)
+ D_lp_missing = 0;
+ }
+ }
+
+ up = 1;
+ if (n < 0)
+ {
+ up = 0;
+ n = -n;
+ }
+ if (n >= ye - ys + 1)
+ n = ye - ys + 1;
+
+ oldbot = D_bot;
+ if (ys < D_top || D_bot != ye)
+ ChangeScrollRegion(ys, ye);
+ alok = (D_AL || D_CAL || (ys >= D_top && ye == D_bot && up));
+ dlok = (D_DL || D_CDL || (ys >= D_top && ye == D_bot && !up));
+ if (D_top != ys && !(alok && dlok))
+ ChangeScrollRegion(ys, ye);
+
+ if (D_lp_missing &&
+ (oldbot != D_bot ||
+ (oldbot == D_bot && up && D_top == ys && D_bot == ye)))
+ {
+ WriteLP(D_width - 1, oldbot);
+ if (oldbot == D_bot) /* have scrolled */
+ {
+ if (--n == 0)
+ {
+/* XXX
+ ChangeScrollRegion(oldtop, oldbot);
+*/
+ if (bce && !D_BE)
+ ClearLine((struct mline *)0, ye, xs, xe, bce);
+ return;
+ }
+ }
+ }
+
+ if (D_UT)
+ SetRendition(&mchar_null);
+#ifdef COLOR
+ if (D_BE)
+ SetBackColor(bce);
+#endif
+
+ aldlfaster = (n > 1 && ys >= D_top && ye == D_bot && ((up && D_CDL) || (!up && D_CAL)));
+
+ if ((up || D_SR) && D_top == ys && D_bot == ye && !aldlfaster)
+ {
+ if (up)
+ {
+ GotoPos(0, ye);
+ for(i = n; i-- > 0; )
+ AddCStr(D_NL); /* was SF, I think NL is faster */
+ }
+ else
+ {
+ GotoPos(0, ys);
+ for(i = n; i-- > 0; )
+ AddCStr(D_SR);
+ }
+ }
+ else if (alok && dlok)
+ {
+ if (up || ye != D_bot)
+ {
+ GotoPos(0, up ? ys : ye+1-n);
+ if (D_CDL && !(n == 1 && D_DL))
+ AddCStr2(D_CDL, n);
+ else
+ for(i = n; i--; )
+ AddCStr(D_DL);
+ }
+ if (!up || ye != D_bot)
+ {
+ GotoPos(0, up ? ye+1-n : ys);
+ if (D_CAL && !(n == 1 && D_AL))
+ AddCStr2(D_CAL, n);
+ else
+ for(i = n; i--; )
+ AddCStr(D_AL);
+ }
+ }
+ else
+ {
+ RefreshArea(xs, ys, xe, ye, 0);
+ return;
+ }
+ if (bce && !D_BE)
+ {
+ if (up)
+ ClearArea(xs, ye - n + 1, xs, xe, xe, ye, bce, 0);
+ else
+ ClearArea(xs, ys, xs, xe, xe, ys + n - 1, bce, 0);
+ }
+ if (D_lp_missing && missy != D_bot)
+ WriteLP(D_width - 1, missy);
+/* XXX
+ ChangeScrollRegion(oldtop, oldbot);
+ if (D_lp_missing && missy != D_bot)
+ WriteLP(D_width - 1, missy);
+*/
+}
+
+void
+SetAttr(new)
+register int new;
+{
+ register int i, j, old, typ;
+
+ if (!display || (old = D_rend.attr) == new)
+ return;
+#ifdef COLORS16
+ D_col16change = (old ^ new) & (A_BFG | A_BBG);
+ new ^= D_col16change;
+ if (old == new)
+ return;
+#endif
+#if defined(TERMINFO) && defined(USE_SGR)
+ if (D_SA)
+ {
+ char *tparm();
+ SetFont(ASCII);
+ ospeed = D_dospeed;
+ tputs(tparm(D_SA, new & A_SO, new & A_US, new & A_RV, new & A_BL,
+ new & A_DI, new & A_BD, 0 , 0 ,
+ 0), 1, DoAddChar);
+ D_rend.attr = new;
+ D_atyp = 0;
+# ifdef COLOR
+ if (D_hascolor)
+ rend_setdefault(&D_rend);
+# endif
+ return;
+ }
+#endif
+ D_rend.attr = new;
+ typ = D_atyp;
+ if ((new & old) != old)
+ {
+ if ((typ & ATYP_U))
+ AddCStr(D_UE);
+ if ((typ & ATYP_S))
+ AddCStr(D_SE);
+ if ((typ & ATYP_M))
+ {
+ AddCStr(D_ME);
+#ifdef COLOR
+ /* ansi attrib handling: \E[m resets color, too */
+ if (D_hascolor)
+ rend_setdefault(&D_rend);
+#endif
+#ifdef FONT
+ if (!D_CG0)
+ {
+ /* D_ME may also reset the alternate charset */
+ D_rend.font = 0;
+# ifdef ENCODINGS
+ D_realfont = 0;
+# endif
+ }
+#endif
+ }
+ old = 0;
+ typ = 0;
+ }
+ old ^= new;
+ for (i = 0, j = 1; old && i < NATTR; i++, j <<= 1)
+ {
+ if ((old & j) == 0)
+ continue;
+ old ^= j;
+ if (D_attrtab[i])
+ {
+ AddCStr(D_attrtab[i]);
+ typ |= D_attrtyp[i];
+ }
+ }
+ D_atyp = typ;
+}
+
+#ifdef FONT
+void
+SetFont(new)
+int new;
+{
+ int old = D_rend.font;
+ if (!display || old == new)
+ return;
+ D_rend.font = new;
+#ifdef ENCODINGS
+ if (D_encoding && CanEncodeFont(D_encoding, new))
+ return;
+ if (new == D_realfont)
+ return;
+ D_realfont = new;
+#endif
+ if (D_xtable && D_xtable[(int)(unsigned char)new] &&
+ D_xtable[(int)(unsigned char)new][256])
+ {
+ AddCStr(D_xtable[(int)(unsigned char)new][256]);
+ return;
+ }
+
+ if (!D_CG0 && new != '0')
+ {
+ new = ASCII;
+ if (old == new)
+ return;
+ }
+
+ if (new == ASCII)
+ AddCStr(D_CE0);
+#ifdef DW_CHARS
+ else if (new < ' ')
+ {
+ AddStr("\033$");
+ if (new > 2)
+ AddChar('(');
+ AddChar(new + '@');
+ }
+#endif
+ else
+ AddCStr2(D_CS0, new);
+}
+#endif
+
+#ifdef COLOR
+
+int
+color256to16(jj)
+int jj;
+{
+ int min, max;
+ int r, g, b;
+
+ if (jj >= 232)
+ {
+ jj = (jj - 232) / 6;
+ jj = (jj & 1) << 3 | (jj & 2 ? 7 : 0);
+ }
+ else if (jj >= 16)
+ {
+ jj -= 16;
+ r = jj / 36;
+ g = (jj / 6) % 6;
+ b = jj % 6;
+ min = r < g ? (r < b ? r : b) : (g < b ? g : b);
+ max = r > g ? (r > b ? r : b) : (g > b ? g : b);
+ if (min == max)
+ jj = ((max + 1) & 2) << 2 | ((max + 1) & 4 ? 7 : 0);
+ else
+ jj = (b - min) / (max - min) << 2 | (g - min) / (max - min) << 1 | (r -
+min) / (max - min) | (max > 3 ? 8 : 0);
+ }
+ return jj;
+}
+
+#ifdef COLORS256
+int
+color256to88(jj)
+int jj;
+{
+ int r, g, b;
+
+ if (jj >= 232)
+ return (jj - 232) / 3 + 80;
+ if (jj >= 16)
+ {
+ jj -= 16;
+ r = jj / 36;
+ g = (jj / 6) % 6;
+ b = jj % 6;
+ return ((r + 1) / 2) * 16 + ((g + 1) / 2) * 4 + ((b + 1) / 2) + 16;
+ }
+ return jj;
+}
+#endif
+
+void
+SetColor(f, b)
+int f, b;
+{
+ int of, ob;
+ static unsigned char sftrans[8] = {0,4,2,6,1,5,3,7};
+
+ if (!display)
+ return;
+
+ of = rend_getfg(&D_rend);
+ ob = rend_getbg(&D_rend);
+
+#ifdef COLORS16
+ /* intense default not invented yet */
+ if (f == 0x100)
+ f = 0;
+ if (b == 0x100)
+ b = 0;
+#endif
+ debug2("SetColor %d %d", coli2e(of), coli2e(ob));
+ debug2(" -> %d %d\n", coli2e(f), coli2e(b));
+ debug2("(%d %d", of, ob);
+ debug2(" -> %d %d)\n", f, b);
+
+ if (!D_CAX && D_hascolor && ((f == 0 && f != of) || (b == 0 && b != ob)))
+ {
+ if (D_OP)
+ AddCStr(D_OP);
+ else
+ {
+ int oattr;
+ oattr = D_rend.attr;
+ AddCStr(D_ME ? D_ME : "\033[m");
+#ifdef FONT
+ if (D_ME && !D_CG0)
+ {
+ /* D_ME may also reset the alternate charset */
+ D_rend.font = 0;
+# ifdef ENCODINGS
+ D_realfont = 0;
+# endif
+ }
+#endif
+ D_atyp = 0;
+ D_rend.attr = 0;
+ SetAttr(oattr);
+ }
+ of = ob = 0;
+ }
+ rend_setfg(&D_rend, f);
+ rend_setbg(&D_rend, b);
+#ifdef COLORS16
+ D_col16change = 0;
+#endif
+ if (!D_hascolor)
+ return;
+ f = f ? coli2e(f) : -1;
+ b = b ? coli2e(b) : -1;
+ of = of ? coli2e(of) : -1;
+ ob = ob ? coli2e(ob) : -1;
+#ifdef COLORS256
+ if (f != of && f > 15 && D_CCO != 256)
+ f = D_CCO == 88 && D_CAF ? color256to88(f) : color256to16(f);
+ if (f != of && f > 15 && D_CAF)
+ {
+ AddCStr2(D_CAF, f);
+ of = f;
+ }
+ if (b != ob && b > 15 && D_CCO != 256)
+ b = D_CCO == 88 && D_CAB ? color256to88(b) : color256to16(b);
+ if (b != ob && b > 15 && D_CAB)
+ {
+ AddCStr2(D_CAB, b);
+ ob = b;
+ }
+#endif
+ if (f != of && f != (of | 8))
+ {
+ if (f == -1)
+ AddCStr("\033[39m"); /* works because AX is set */
+ else if (D_CAF)
+ AddCStr2(D_CAF, f & 7);
+ else if (D_CSF)
+ AddCStr2(D_CSF, sftrans[f & 7]);
+ }
+ if (b != ob && b != (ob | 8))
+ {
+ if (b == -1)
+ AddCStr("\033[49m"); /* works because AX is set */
+ else if (D_CAB)
+ AddCStr2(D_CAB, b & 7);
+ else if (D_CSB)
+ AddCStr2(D_CSB, sftrans[b & 7]);
+ }
+#ifdef COLORS16
+ if (f != of && D_CXT && (f & 8) != 0 && f != -1)
+ {
+# ifdef TERMINFO
+ AddCStr2("\033[9%p1%dm", f & 7);
+# else
+ AddCStr2("\033[9%dm", f & 7);
+# endif
+ }
+ if (b != ob && D_CXT && (b & 8) != 0 && b != -1)
+ {
+# ifdef TERMINFO
+ AddCStr2("\033[10%p1%dm", b & 7);
+# else
+ AddCStr2("\033[10%dm", b & 7);
+# endif
+ }
+#endif
+}
+
+static void
+SetBackColor(new)
+int new;
+{
+ if (!display)
+ return;
+ SetColor(rend_getfg(&D_rend), new);
+}
+#endif /* COLOR */
+
+void
+SetRendition(mc)
+struct mchar *mc;
+{
+ if (!display)
+ return;
+#ifdef COLOR
+ if (nattr2color && D_hascolor && (mc->attr & nattr2color) != 0)
+ {
+ static struct mchar mmc;
+ int i;
+ mmc = *mc;
+ for (i = 0; i < 8; i++)
+ if (attr2color[i] && (mc->attr & (1 << i)) != 0)
+ {
+ if (mc->color == 0 && attr2color[i][3])
+ ApplyAttrColor(attr2color[i][3], &mmc);
+ else if ((mc->color & 0x0f) == 0 && attr2color[i][2])
+ ApplyAttrColor(attr2color[i][2], &mmc);
+ else if ((mc->color & 0xf0) == 0 && attr2color[i][1])
+ ApplyAttrColor(attr2color[i][1], &mmc);
+ else
+ ApplyAttrColor(attr2color[i][0], &mmc);
+ }
+ mc = &mmc;
+ debug2("SetRendition: mapped to %02x %02x\n", (unsigned char)mc->attr, 0x99 - (unsigned char)mc->color);
+ }
+# ifdef COLORS16
+ if (D_hascolor && D_CC8 && (mc->attr & (A_BFG|A_BBG)))
+ {
+ int a = mc->attr;
+ if ((mc->attr & A_BFG) && D_MD)
+ a |= A_BD;
+ if ((mc->attr & A_BBG) && D_MB)
+ a |= A_BL;
+ if (D_rend.attr != a)
+ SetAttr(a);
+ }
+ else
+# endif /* COLORS16 */
+#endif /* COLOR */
+ if (D_rend.attr != mc->attr)
+ SetAttr(mc->attr);
+
+#ifdef COLOR
+ if (D_rend.color != mc->color
+# ifdef COLORS256
+ || D_rend.colorx != mc->colorx
+# endif
+# ifdef COLORS16
+ || D_col16change
+# endif
+ )
+ SetColor(rend_getfg(mc), rend_getbg(mc));
+#endif
+#ifdef FONT
+ if (D_rend.font != mc->font)
+ SetFont(mc->font);
+#ifdef UTF8
+ if (D_encoding == UTF8)
+ D_rend.fontx = mc->fontx;
+#endif
+#endif
+}
+
+void
+SetRenditionMline(ml, x)
+struct mline *ml;
+int x;
+{
+ if (!display)
+ return;
+#ifdef COLOR
+ if (nattr2color && D_hascolor && (ml->attr[x] & nattr2color) != 0)
+ {
+ struct mchar mc;
+ copy_mline2mchar(&mc, ml, x);
+ SetRendition(&mc);
+ return;
+ }
+# ifdef COLORS16
+ if (D_hascolor && D_CC8 && (ml->attr[x] & (A_BFG|A_BBG)))
+ {
+ int a = ml->attr[x];
+ if ((ml->attr[x] & A_BFG) && D_MD)
+ a |= A_BD;
+ if ((ml->attr[x] & A_BBG) && D_MB)
+ a |= A_BL;
+ if (D_rend.attr != a)
+ SetAttr(a);
+ }
+ else
+# endif /* COLORS16 */
+#endif /* COLOR */
+ if (D_rend.attr != ml->attr[x])
+ SetAttr(ml->attr[x]);
+#ifdef COLOR
+ if (D_rend.color != ml->color[x]
+# ifdef COLORS256
+ || D_rend.colorx != ml->colorx[x]
+# endif
+# ifdef COLORS16
+ || D_col16change
+# endif
+ )
+ {
+ struct mchar mc;
+ copy_mline2mchar(&mc, ml, x);
+ SetColor(rend_getfg(&mc), rend_getbg(&mc));
+ }
+#endif
+#ifdef FONT
+ if (D_rend.font != ml->font[x])
+ SetFont(ml->font[x]);
+#ifdef UTF8
+ if (D_encoding == UTF8)
+ D_rend.fontx = ml->fontx[x];
+#endif
+#endif
+}
+
+void
+MakeStatus(msg)
+char *msg;
+{
+ register char *s, *t;
+ register int max;
+
+ if (!display)
+ return;
+
+ if (D_blocked)
+ return;
+ if (!D_tcinited)
+ {
+ debug("tc not inited, just writing msg\n");
+ if (D_processinputdata)
+ return; /* XXX: better */
+ AddStr(msg);
+ AddStr("\r\n");
+ Flush(0);
+ return;
+ }
+ if (!use_hardstatus || !D_HS)
+ {
+ max = D_width;
+ if (D_CLP == 0)
+ max--;
+ }
+ else
+ max = D_WS > 0 ? D_WS : (D_width - !D_CLP);
+ if (D_status)
+ {
+ /* same message? */
+ if (strcmp(msg, D_status_lastmsg) == 0)
+ {
+ debug("same message - increase timeout");
+ if (!D_status_obufpos)
+ SetTimeout(&D_statusev, MsgWait);
+ return;
+ }
+ RemoveStatusMinWait();
+ }
+ for (s = t = msg; *s && t - msg < max; ++s)
+ if (*s == BELL)
+ AddCStr(D_BL);
+ else if ((unsigned char)*s >= ' ' && *s != 0177)
+ *t++ = *s;
+ *t = '\0';
+ if (t == msg)
+ return;
+ if (t - msg >= D_status_buflen)
+ {
+ char *buf;
+ if (D_status_lastmsg)
+ buf = realloc(D_status_lastmsg, t - msg + 1);
+ else
+ buf = malloc(t - msg + 1);
+ if (buf)
+ {
+ D_status_lastmsg = buf;
+ D_status_buflen = t - msg + 1;
+ }
+ }
+ if (t - msg < D_status_buflen)
+ strcpy(D_status_lastmsg, msg);
+ D_status_len = t - msg;
+ D_status_lastx = D_x;
+ D_status_lasty = D_y;
+ if (!use_hardstatus || D_has_hstatus == HSTATUS_IGNORE || D_has_hstatus == HSTATUS_MESSAGE)
+ {
+ D_status = STATUS_ON_WIN;
+ debug1("using STATLINE %d\n", STATLINE);
+ GotoPos(0, STATLINE);
+ SetRendition(&mchar_so);
+ InsertMode(0);
+ AddStr(msg);
+ if (D_status_len < max)
+ {
+ /* Wayne Davison: add extra space for readability */
+ D_status_len++;
+ SetRendition(&mchar_null);
+ AddChar(' ');
+ if (D_status_len < max)
+ {
+ D_status_len++;
+ AddChar(' ');
+ AddChar('\b');
+ }
+ AddChar('\b');
+ }
+ D_x = -1;
+ }
+ else
+ {
+ D_status = STATUS_ON_HS;
+ ShowHStatus(msg);
+ }
+
+ D_status_obufpos = D_obufp - D_obuf;
+ ASSERT(D_status_obufpos > 0);
+
+ if (D_status == STATUS_ON_WIN)
+ {
+ struct display *olddisplay = display;
+ struct layer *oldflayer = flayer;
+
+ /* this is copied over from RemoveStatus() */
+ D_status = 0;
+ GotoPos(0, STATLINE);
+ RefreshLine(STATLINE, 0, D_status_len - 1, 0);
+ GotoPos(D_status_lastx, D_status_lasty);
+ flayer = D_forecv ? D_forecv->c_layer : 0;
+ if (flayer)
+ LaySetCursor();
+ display = olddisplay;
+ flayer = oldflayer;
+ D_status = STATUS_ON_WIN;
+ }
+}
+
+void
+RemoveStatus()
+{
+ struct display *olddisplay;
+ struct layer *oldflayer;
+ int where;
+
+ if (!display)
+ return;
+ if (!(where = D_status))
+ return;
+
+ debug("RemoveStatus\n");
+ if (D_status_obuffree >= 0)
+ {
+ D_obuflen = D_status_obuflen;
+ D_obuffree = D_status_obuffree;
+ D_status_obuffree = -1;
+ }
+ D_status = 0;
+ D_status_obufpos = 0;
+ D_status_bell = 0;
+ evdeq(&D_statusev);
+ olddisplay = display;
+ oldflayer = flayer;
+ if (where == STATUS_ON_WIN)
+ {
+ if (captionalways || (D_canvas.c_slperp && D_canvas.c_slperp->c_slnext))
+ {
+ GotoPos(0, STATLINE);
+ RefreshLine(STATLINE, 0, D_status_len - 1, 0);
+ GotoPos(D_status_lastx, D_status_lasty);
+ }
+ }
+ else
+ RefreshHStatus();
+ flayer = D_forecv ? D_forecv->c_layer : 0;
+ if (flayer)
+ LaySetCursor();
+ display = olddisplay;
+ flayer = oldflayer;
+}
+
+/* Remove the status but make sure that it is seen for MsgMinWait ms */
+static void
+RemoveStatusMinWait()
+{
+ /* XXX: should flush output first if D_status_obufpos is set */
+ if (!D_status_bell && !D_status_obufpos)
+ {
+ struct timeval now;
+ int ti;
+ gettimeofday(&now, NULL);
+ ti = (now.tv_sec - D_status_time.tv_sec) * 1000 + (now.tv_usec - D_status_time.tv_usec) / 1000;
+ if (ti < MsgMinWait)
+ DisplaySleep1000(MsgMinWait - ti, 0);
+ }
+ RemoveStatus();
+}
+
+#ifdef UTF8
+static int
+strlen_onscreen(unsigned char *c, unsigned char *end)
+{
+ int len = 0;
+ while (*c && (!end || c < end))
+ {
+ int v, dec = 0;
+ do
+ {
+ v = FromUtf8(*c++, &dec);
+ if (v == -2)
+ c--;
+ }
+ while (v < 0 && (!end || c < end));
+ if (!utf8_iscomb(v))
+ {
+ if (utf8_isdouble(v))
+ len++;
+ len++;
+ }
+ }
+
+ return len;
+}
+
+static int
+PrePutWinMsg(s, start, max)
+char *s;
+int start, max;
+{
+ /* Avoid double-encoding problem for a UTF-8 message on a UTF-8 locale.
+ Ideally, this would not be necessary. But fixing it the Right Way will
+ probably take way more time. So this will have to do for now. */
+ if (D_encoding == UTF8)
+ {
+ int chars = strlen_onscreen((unsigned char *)(s + start), (unsigned char *)(s + max));
+ D_encoding = 0;
+ PutWinMsg(s, start, max + ((max - start) - chars)); /* Multibyte count */
+ D_encoding = UTF8;
+ D_x -= (max - chars); /* Yak! But this is necessary to count for
+ the fact that not every byte represents a
+ character. */
+ return start + chars;
+ }
+ else
+ {
+ PutWinMsg(s, start, max);
+ return max;
+ }
+}
+#else
+static int
+PrePutWinMsg(s, start, max)
+char *s;
+int start, max;
+{
+ PutWinMsg(s, start, max);
+ return max;
+}
+#endif
+
+/* refresh the display's hstatus line */
+void
+ShowHStatus(str)
+char *str;
+{
+ int l, ox, oy, max;
+
+ if (D_status == STATUS_ON_WIN && D_has_hstatus == HSTATUS_LASTLINE && STATLINE == D_height-1)
+ return; /* sorry, in use */
+ if (D_blocked)
+ return;
+
+ if (D_HS && D_has_hstatus == HSTATUS_HS)
+ {
+ if (!D_hstatus && (str == 0 || *str == 0))
+ return;
+ debug("ShowHStatus: using HS\n");
+ SetRendition(&mchar_null);
+ InsertMode(0);
+ if (D_hstatus)
+ AddCStr(D_DS);
+ D_hstatus = 0;
+ if (str == 0 || *str == 0)
+ return;
+ AddCStr2(D_TS, 0);
+ max = D_WS > 0 ? D_WS : (D_width - !D_CLP);
+ if ((int)strlen(str) > max)
+ AddStrn(str, max);
+ else
+ AddStr(str);
+ AddCStr(D_FS);
+ D_hstatus = 1;
+ }
+ else if (D_has_hstatus == HSTATUS_LASTLINE)
+ {
+ debug("ShowHStatus: using last line\n");
+ ox = D_x;
+ oy = D_y;
+ str = str ? str : "";
+ l = strlen(str);
+ if (l > D_width)
+ l = D_width;
+ GotoPos(0, D_height - 1);
+ SetRendition(captionalways || D_cvlist == 0 || D_cvlist->c_next ? &mchar_null: &mchar_so);
+ l = PrePutWinMsg(str, 0, l);
+ if (!captionalways && D_cvlist && !D_cvlist->c_next)
+ while (l++ < D_width)
+ PUTCHARLP(' ');
+ if (l < D_width)
+ ClearArea(l, D_height - 1, l, D_width - 1, D_width - 1, D_height - 1, 0, 0);
+ if (ox != -1 && oy != -1)
+ GotoPos(ox, oy);
+ D_hstatus = *str ? 1 : 0;
+ SetRendition(&mchar_null);
+ }
+ else if (D_has_hstatus == HSTATUS_FIRSTLINE)
+ {
+ debug("ShowHStatus: using first line\n");
+ ox = D_x;
+ oy = D_y;
+ str = str ? str : "";
+ l = strlen(str);
+ if (l > D_width)
+ l = D_width;
+ GotoPos(0, 0);
+ SetRendition(captionalways || D_cvlist == 0 || D_cvlist->c_next ? &mchar_null: &mchar_so);
+ l = PrePutWinMsg(str, 0, l);
+ if (!captionalways || (D_cvlist && !D_cvlist->c_next))
+ while (l++ < D_width)
+ PUTCHARLP(' ');
+ if (l < D_width)
+ ClearArea(l, 0, l, D_width - 1, D_width - 1, 0, 0, 0);
+ if (ox != -1 && oy != -1)
+ GotoPos(ox, oy);
+ D_hstatus = *str ? 1 : 0;
+ SetRendition(&mchar_null);
+ }
+ else if (str && *str && D_has_hstatus == HSTATUS_MESSAGE)
+ {
+ debug("ShowHStatus: using message\n");
+ Msg(0, "%s", str);
+ }
+}
+
+
+/*
+ * Refreshes the harstatus of the fore window. Shouldn't be here...
+ */
+void
+RefreshHStatus()
+{
+ char *buf;
+#ifdef UTF8
+ int extrabytes = strlen(hstatusstring) - strlen_onscreen(hstatusstring, NULL);
+#else
+ int extrabytes = 0;
+#endif
+ evdeq(&D_hstatusev);
+ if (D_status == STATUS_ON_HS)
+ return;
+ buf = MakeWinMsgEv(hstatusstring, D_fore, '%', (D_HS && D_has_hstatus == HSTATUS_HS && D_WS > 0) ? D_WS : D_width - !D_CLP + extrabytes, &D_hstatusev, 0);
+ if (buf && *buf)
+ {
+ ShowHStatus(buf);
+ if (D_has_hstatus != HSTATUS_IGNORE && D_hstatusev.timeout.tv_sec)
+ evenq(&D_hstatusev);
+ }
+ else
+ ShowHStatus((char *)0);
+}
+
+/*********************************************************************/
+/*
+ * Here come the routines that refresh an arbitrary part of the screen.
+ */
+
+void
+RefreshAll(isblank)
+int isblank;
+{
+ struct canvas *cv;
+
+ ASSERT(display);
+ debug("Signalling full refresh!\n");
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ {
+ CV_CALL(cv, LayRedisplayLine(-1, -1, -1, isblank));
+ display = cv->c_display; /* just in case! */
+ }
+ RefreshArea(0, 0, D_width - 1, D_height - 1, isblank);
+}
+
+void
+RefreshArea(xs, ys, xe, ye, isblank)
+int xs, ys, xe, ye, isblank;
+{
+ int y;
+ ASSERT(display);
+ debug2("Refresh Area: %d,%d", xs, ys);
+ debug3(" - %d,%d (isblank=%d)\n", xe, ye, isblank);
+ if (!isblank && xs == 0 && xe == D_width - 1 && ye == D_height - 1 && (ys == 0 || D_CD))
+ {
+ ClearArea(xs, ys, xs, xe, xe, ye, 0, 0);
+ isblank = 1;
+ }
+ for (y = ys; y <= ye; y++)
+ RefreshLine(y, xs, xe, isblank);
+}
+
+void
+RefreshLine(y, from, to, isblank)
+int y, from, to, isblank;
+{
+ struct viewport *vp, *lvp;
+ struct canvas *cv, *lcv, *cvlist, *cvlnext;
+ struct layer *oldflayer;
+ int xx, yy, l;
+ char *buf;
+ struct win *p;
+
+ ASSERT(display);
+
+ debug2("RefreshLine %d %d", y, from);
+ debug2(" %d %d\n", to, isblank);
+
+ if (D_status == STATUS_ON_WIN && y == STATLINE)
+ {
+ if (to >= D_status_len)
+ D_status_len = to + 1;
+ return; /* can't refresh status */
+ }
+
+ if (isblank == 0 && D_CE && to == D_width - 1 && from < to && D_status != STATUS_ON_HS)
+ {
+ GotoPos(from, y);
+ if (D_UT || D_BE)
+ SetRendition(&mchar_null);
+ AddCStr(D_CE);
+ isblank = 1;
+ }
+
+ if ((y == D_height - 1 && D_has_hstatus == HSTATUS_LASTLINE) || (y == 0 && D_has_hstatus == HSTATUS_FIRSTLINE) )
+ {
+ RefreshHStatus();
+ return;
+ }
+
+ while (from <= to)
+ {
+ lcv = 0;
+ lvp = 0;
+ for (cv = display->d_cvlist; cv; cv = cv->c_next)
+ {
+ if (y == cv->c_ye + 1 && from >= cv->c_xs && from <= cv->c_xe)
+ {
+#ifdef UTF8
+ int extrabytes = strlen(captionstring) - strlen_onscreen(captionstring, NULL);
+#else
+ int extrabytes = 0;
+#endif
+ p = Layer2Window(cv->c_layer);
+ buf = MakeWinMsgEv(captionstring, p, '%', cv->c_xe - cv->c_xs + (cv->c_xe + 1 < D_width || D_CLP) + extrabytes, &cv->c_captev, 0);
+ if (cv->c_captev.timeout.tv_sec)
+ evenq(&cv->c_captev);
+ xx = to > cv->c_xe ? cv->c_xe : to;
+ l = strlen(buf);
+ GotoPos(from, y);
+ SetRendition(&mchar_so);
+ if (l > xx - cv->c_xs + 1)
+ l = xx - cv->c_xs + 1;
+ l = PrePutWinMsg(buf, from - cv->c_xs, l + extrabytes);
+ from = cv->c_xs + l;
+ for (; from <= xx; from++)
+ PUTCHARLP(' ');
+ break;
+ }
+ if (from == cv->c_xe + 1 && y >= cv->c_ys && y <= cv->c_ye + 1)
+ {
+ GotoPos(from, y);
+ SetRendition(&mchar_so);
+ PUTCHARLP(' ');
+ from++;
+ break;
+ }
+ if (y < cv->c_ys || y > cv->c_ye || to < cv->c_xs || from > cv->c_xe)
+ continue;
+ debug2("- canvas hit: %d %d", cv->c_xs, cv->c_ys);
+ debug2(" %d %d\n", cv->c_xe, cv->c_ye);
+ for (vp = cv->c_vplist; vp; vp = vp->v_next)
+ {
+ debug2(" - vp: %d %d", vp->v_xs, vp->v_ys);
+ debug2(" %d %d\n", vp->v_xe, vp->v_ye);
+ /* find leftmost overlapping vp */
+ if (y >= vp->v_ys && y <= vp->v_ye && from <= vp->v_xe && to >= vp->v_xs && (lvp == 0 || lvp->v_xs > vp->v_xs))
+ {
+ lcv = cv;
+ lvp = vp;
+ }
+ }
+ }
+ if (cv)
+ continue; /* we advanced from */
+ if (lvp == 0)
+ break;
+ if (from < lvp->v_xs)
+ {
+ if (!isblank)
+ DisplayLine(&mline_null, &mline_blank, y, from, lvp->v_xs - 1);
+ from = lvp->v_xs;
+ }
+
+ /* call LayRedisplayLine on canvas lcv viewport lvp */
+ yy = y - lvp->v_yoff;
+ xx = to < lvp->v_xe ? to : lvp->v_xe;
+
+ if (lcv->c_layer && lcv->c_xoff + lcv->c_layer->l_width == from)
+ {
+ GotoPos(from, y);
+ SetRendition(&mchar_blank);
+ PUTCHARLP('|');
+ from++;
+ }
+ if (lcv->c_layer && yy == lcv->c_layer->l_height)
+ {
+ GotoPos(from, y);
+ SetRendition(&mchar_blank);
+ while (from <= lvp->v_xe && from - lvp->v_xoff < lcv->c_layer->l_width)
+ {
+ PUTCHARLP('-');
+ from++;
+ }
+ if (from >= lvp->v_xe + 1)
+ continue;
+ }
+ if (lcv->c_layer == 0 || yy >= lcv->c_layer->l_height || from - lvp->v_xoff >= lcv->c_layer->l_width)
+ {
+ if (!isblank)
+ DisplayLine(&mline_null, &mline_blank, y, from, lvp->v_xe);
+ from = lvp->v_xe + 1;
+ continue;
+ }
+
+ if (xx - lvp->v_xoff >= lcv->c_layer->l_width)
+ xx = lcv->c_layer->l_width + lvp->v_xoff - 1;
+ oldflayer = flayer;
+ flayer = lcv->c_layer;
+ cvlist = flayer->l_cvlist;
+ cvlnext = lcv->c_lnext;
+ flayer->l_cvlist = lcv;
+ lcv->c_lnext = 0;
+ LayRedisplayLine(yy, from - lvp->v_xoff, xx - lvp->v_xoff, isblank);
+ flayer->l_cvlist = cvlist;
+ lcv->c_lnext = cvlnext;
+ flayer = oldflayer;
+
+ from = xx + 1;
+ }
+ if (!isblank && from <= to)
+ DisplayLine(&mline_null, &mline_blank, y, from, to);
+}
+
+/*********************************************************************/
+
+/* clear lp_missing by writing the char on the screen. The
+ * position must be safe.
+ */
+static void
+WriteLP(x2, y2)
+int x2, y2;
+{
+ struct mchar oldrend;
+
+ ASSERT(display);
+ ASSERT(D_lp_missing);
+ oldrend = D_rend;
+ debug2("WriteLP(%d,%d)\n", x2, y2);
+#ifdef DW_CHARS
+ if (D_lpchar.mbcs)
+ {
+ if (x2 > 0)
+ x2--;
+ else
+ D_lpchar = mchar_blank;
+ }
+#endif
+ /* Can't use PutChar */
+ GotoPos(x2, y2);
+ SetRendition(&D_lpchar);
+ PUTCHAR(D_lpchar.image);
+#ifdef DW_CHARS
+ if (D_lpchar.mbcs)
+ PUTCHAR(D_lpchar.mbcs);
+#endif
+ D_lp_missing = 0;
+ SetRendition(&oldrend);
+}
+
+void
+ClearLine(oml, y, from, to, bce)
+struct mline *oml;
+int from, to, y, bce;
+{
+ int x;
+#ifdef COLOR
+ struct mchar bcechar;
+#endif
+
+ debug3("ClearLine %d,%d-%d\n", y, from, to);
+ if (D_UT) /* Safe to erase ? */
+ SetRendition(&mchar_null);
+#ifdef COLOR
+ if (D_BE)
+ SetBackColor(bce);
+#endif
+ if (from == 0 && D_CB && (to != D_width - 1 || (D_x == to && D_y == y)) && (!bce || D_BE))
+ {
+ GotoPos(to, y);
+ AddCStr(D_CB);
+ return;
+ }
+ if (to == D_width - 1 && D_CE && (!bce || D_BE))
+ {
+ GotoPos(from, y);
+ AddCStr(D_CE);
+ return;
+ }
+ if (oml == 0)
+ oml = &mline_null;
+#ifdef COLOR
+ if (!bce)
+ {
+ DisplayLine(oml, &mline_blank, y, from, to);
+ return;
+ }
+ bcechar = mchar_null;
+ rend_setbg(&bcechar, bce);
+ for (x = from; x <= to; x++)
+ copy_mchar2mline(&bcechar, &mline_old, x);
+ DisplayLine(oml, &mline_old, y, from, to);
+#else
+ DisplayLine(oml, &mline_blank, y, from, to);
+#endif
+}
+
+void
+DisplayLine(oml, ml, y, from, to)
+struct mline *oml, *ml;
+int from, to, y;
+{
+ register int x;
+ int last2flag = 0, delete_lp = 0;
+
+ ASSERT(display);
+ ASSERT(y >= 0 && y < D_height);
+ ASSERT(from >= 0 && from < D_width);
+ ASSERT(to >= 0 && to < D_width);
+ if (!D_CLP && y == D_bot && to == D_width - 1)
+ {
+ if (D_lp_missing || !cmp_mline(oml, ml, to))
+ {
+#ifdef DW_CHARS
+ if ((D_IC || D_IM) && from < to && !dw_left(ml, to, D_encoding))
+#else
+ if ((D_IC || D_IM) && from < to)
+#endif
+ {
+ last2flag = 1;
+ D_lp_missing = 0;
+ to--;
+ }
+ else
+ {
+ delete_lp = !cmp_mchar_mline(&mchar_blank, oml, to) && (D_CE || D_DC || D_CDC);
+ D_lp_missing = !cmp_mchar_mline(&mchar_blank, ml, to);
+ copy_mline2mchar(&D_lpchar, ml, to);
+ }
+ }
+ to--;
+ }
+#ifdef DW_CHARS
+ if (D_mbcs)
+ {
+ /* finish dw-char (can happen after a wrap) */
+ debug("DisplayLine finishing kanji\n");
+ SetRenditionMline(ml, from);
+ PUTCHAR(ml->image[from]);
+ from++;
+ }
+#endif
+ for (x = from; x <= to; x++)
+ {
+#if 0 /* no longer needed */
+ if (x || D_x != D_width || D_y != y - 1)
+#endif
+ {
+ if (ml != NULL && (x < to || x != D_width - 1 || ml->image[x + 1]))
+ if (cmp_mline(oml, ml, x))
+ continue;
+ GotoPos(x, y);
+ }
+#ifdef DW_CHARS
+ if (dw_right(ml, x, D_encoding))
+ {
+ x--;
+ debug1("DisplayLine on right side of dw char- x now %d\n", x);
+ GotoPos(x, y);
+ }
+ if (x == to && dw_left(ml, x, D_encoding))
+ break; /* don't start new kanji */
+#endif
+ SetRenditionMline(ml, x);
+ PUTCHAR(ml->image[x]);
+#ifdef DW_CHARS
+ if (dw_left(ml, x, D_encoding))
+ PUTCHAR(ml->image[++x]);
+#endif
+ }
+#if 0 /* not needed any longer */
+ /* compare != 0 because ' ' can happen when clipping occures */
+ if (to == D_width - 1 && y < D_height - 1 && D_x == D_width && ml->image[to + 1])
+ GotoPos(0, y + 1);
+#endif
+ if (last2flag)
+ {
+ GotoPos(x, y);
+ SetRenditionMline(ml, x + 1);
+ PUTCHAR(ml->image[x + 1]);
+ GotoPos(x, y);
+ SetRenditionMline(ml, x);
+ INSERTCHAR(ml->image[x]);
+ }
+ else if (delete_lp)
+ {
+ if (D_UT)
+ SetRendition(&mchar_null);
+ if (D_DC)
+ AddCStr(D_DC);
+ else if (D_CDC)
+ AddCStr2(D_CDC, 1);
+ else if (D_CE)
+ AddCStr(D_CE);
+ }
+}
+
+void
+PutChar(c, x, y)
+struct mchar *c;
+int x, y;
+{
+ GotoPos(x, y);
+ SetRendition(c);
+ PUTCHARLP(c->image);
+#ifdef DW_CHARS
+ if (c->mbcs)
+ {
+# ifdef UTF8
+ if (D_encoding == UTF8)
+ D_rend.font = 0;
+# endif
+ PUTCHARLP(c->mbcs);
+ }
+#endif
+}
+
+void
+InsChar(c, x, xe, y, oml)
+struct mchar *c;
+int x, xe, y;
+struct mline *oml;
+{
+ GotoPos(x, y);
+ if (y == D_bot && !D_CLP)
+ {
+ if (x == D_width - 1)
+ {
+ D_lp_missing = 1;
+ D_lpchar = *c;
+ return;
+ }
+ if (xe == D_width - 1)
+ D_lp_missing = 0;
+ }
+ if (x == xe)
+ {
+ SetRendition(c);
+ PUTCHARLP(c->image);
+ return;
+ }
+ if (!(D_IC || D_CIC || D_IM) || xe != D_width - 1)
+ {
+ RefreshLine(y, x, xe, 0);
+ GotoPos(x + 1, y);
+ /* UpdateLine(oml, y, x, xe); */
+ return;
+ }
+ InsertMode(1);
+ if (!D_insert)
+ {
+#ifdef DW_CHARS
+ if (c->mbcs && D_IC)
+ AddCStr(D_IC);
+ if (D_IC)
+ AddCStr(D_IC);
+ else
+ AddCStr2(D_CIC, c->mbcs ? 2 : 1);
+#else
+ if (D_IC)
+ AddCStr(D_IC);
+ else
+ AddCStr2(D_CIC, 1);
+#endif
+ }
+ SetRendition(c);
+ RAW_PUTCHAR(c->image);
+#ifdef DW_CHARS
+ if (c->mbcs)
+ {
+# ifdef UTF8
+ if (D_encoding == UTF8)
+ D_rend.font = 0;
+# endif
+ if (D_x == D_width - 1)
+ PUTCHARLP(c->mbcs);
+ else
+ RAW_PUTCHAR(c->mbcs);
+ }
+#endif
+}
+
+void
+WrapChar(c, x, y, xs, ys, xe, ye, ins)
+struct mchar *c;
+int x, y;
+int xs, ys, xe, ye;
+int ins;
+{
+ int bce;
+
+#ifdef COLOR
+ bce = rend_getbg(c);
+#else
+ bce = 0;
+#endif
+ debug("WrapChar:");
+ debug2(" x %d y %d", x, y);
+ debug2(" Dx %d Dy %d", D_x, D_y);
+ debug2(" xs %d ys %d", xs, ys);
+ debug3(" xe %d ye %d ins %d\n", xe, ye, ins);
+ if (xs != 0 || x != D_width || !D_AM)
+ {
+ if (y == ye)
+ ScrollV(xs, ys, xe, ye, 1, bce);
+ else if (y < D_height - 1)
+ y++;
+ if (ins)
+ InsChar(c, xs, xe, y, 0);
+ else
+ PutChar(c, xs, y);
+ return;
+ }
+ if (y == ye) /* we have to scroll */
+ {
+ debug("- scrolling\n");
+ ChangeScrollRegion(ys, ye);
+ if (D_bot != y || D_x != D_width || (!bce && !D_BE))
+ {
+ debug("- have to call ScrollV\n");
+ ScrollV(xs, ys, xe, ye, 1, bce);
+ y--;
+ }
+ }
+ else if (y == D_bot) /* remove unusable region? */
+ ChangeScrollRegion(0, D_height - 1);
+ if (D_x != D_width || D_y != y)
+ {
+ if (D_CLP && y >= 0) /* don't even try if !LP */
+ RefreshLine(y, D_width - 1, D_width - 1, 0);
+ debug2("- refresh last char -> x,y now %d,%d\n", D_x, D_y);
+ if (D_x != D_width || D_y != y) /* sorry, no bonus */
+ {
+ if (y == ye)
+ ScrollV(xs, ys, xe, ye, 1, bce);
+ GotoPos(xs, y == ye || y == D_height - 1 ? y : y + 1);
+ }
+ }
+ debug("- writeing new char");
+ if (y != ye && y < D_height - 1)
+ y++;
+ if (ins != D_insert)
+ InsertMode(ins);
+ if (ins && !D_insert)
+ {
+ InsChar(c, 0, xe, y, 0);
+ debug2(" -> done with insert (%d,%d)\n", D_x, D_y);
+ return;
+ }
+ D_y = y;
+ D_x = 0;
+ SetRendition(c);
+ RAW_PUTCHAR(c->image);
+#ifdef DW_CHARS
+ if (c->mbcs)
+ {
+# ifdef UTF8
+ if (D_encoding == UTF8)
+ D_rend.font = 0;
+# endif
+ RAW_PUTCHAR(c->mbcs);
+ }
+#endif
+ debug2(" -> done (%d,%d)\n", D_x, D_y);
+}
+
+int
+ResizeDisplay(wi, he)
+int wi, he;
+{
+ ASSERT(display);
+ debug2("ResizeDisplay: to (%d,%d).\n", wi, he);
+ if (D_width == wi && D_height == he)
+ {
+ debug("ResizeDisplay: No change\n");
+ return 0;
+ }
+ if (D_width != wi && (D_height == he || !D_CWS) && D_CZ0 && (wi == Z0width || wi == Z1width))
+ {
+ debug("ResizeDisplay: using Z0/Z1\n");
+ AddCStr(wi == Z0width ? D_CZ0 : D_CZ1);
+ ChangeScreenSize(wi, D_height, 0);
+ return (he == D_height) ? 0 : -1;
+ }
+ if (D_CWS)
+ {
+ debug("ResizeDisplay: using WS\n");
+ AddCStr(tgoto(D_CWS, wi, he));
+ ChangeScreenSize(wi, he, 0);
+ return 0;
+ }
+ return -1;
+}
+
+void
+ChangeScrollRegion(newtop, newbot)
+int newtop, newbot;
+{
+ if (display == 0)
+ return;
+ if (newtop == newbot)
+ return; /* xterm etc can't do it */
+ if (newtop == -1)
+ newtop = 0;
+ if (newbot == -1)
+ newbot = D_height - 1;
+ if (D_CS == 0)
+ {
+ D_top = 0;
+ D_bot = D_height - 1;
+ return;
+ }
+ if (D_top == newtop && D_bot == newbot)
+ return;
+ debug2("ChangeScrollRegion: (%d - %d)\n", newtop, newbot);
+ AddCStr(tgoto(D_CS, newbot, newtop));
+ D_top = newtop;
+ D_bot = newbot;
+ D_y = D_x = -1; /* Just in case... */
+}
+
+#ifdef RXVT_OSC
+#define WT_FLAG "2" /* change to "0" to set both title and icon */
+
+void
+SetXtermOSC(i, s)
+int i;
+char *s;
+{
+ static char *oscs[][2] = {
+ { WT_FLAG ";", "screen" }, /* set window title */
+ { "20;", "" }, /* background */
+ { "39;", "black" }, /* default foreground (black?) */
+ { "49;", "white" } /* default background (white?) */
+ };
+
+ ASSERT(display);
+ if (!D_CXT)
+ return;
+ if (!s)
+ s = "";
+ if (!D_xtermosc[i] && !*s)
+ return;
+ if (i == 0 && !D_xtermosc[0])
+ AddStr("\033[22;" WT_FLAG "t"); /* stack titles (xterm patch #251) */
+ if (!*s)
+ s = oscs[i][1];
+ D_xtermosc[i] = 1;
+ AddStr("\033]");
+ AddStr(oscs[i][0]);
+ AddStr(s);
+ AddChar(7);
+}
+
+void
+ClearAllXtermOSC()
+{
+ int i;
+ for (i = 3; i >= 0; i--)
+ SetXtermOSC(i, 0);
+ if (D_xtermosc[0])
+ AddStr("\033[23;" WT_FLAG "t"); /* unstack titles (xterm patch #251) */
+}
+#undef WT_FLAG
+#endif
+
+/*
+ * Output buffering routines
+ */
+
+void
+AddStr(str)
+char *str;
+{
+ register char c;
+
+ ASSERT(display);
+
+#ifdef UTF8
+ if (D_encoding == UTF8)
+ {
+ while ((c = *str++))
+ AddUtf8((unsigned char)c);
+ return;
+ }
+#endif
+ while ((c = *str++))
+ AddChar(c);
+}
+
+void
+AddStrn(str, n)
+char *str;
+int n;
+{
+ register char c;
+
+ ASSERT(display);
+#ifdef UTF8
+ if (D_encoding == UTF8)
+ {
+ while ((c = *str++) && n-- > 0)
+ AddUtf8((unsigned char)c);
+ }
+ else
+#endif
+ while ((c = *str++) && n-- > 0)
+ AddChar(c);
+ while (n-- > 0)
+ AddChar(' ');
+}
+
+void
+Flush(progress)
+int progress;
+{
+ register int l;
+ int wr;
+ register char *p;
+
+ ASSERT(display);
+ l = D_obufp - D_obuf;
+ debug1("Flush(): %d\n", l);
+ if (l == 0)
+ return;
+ ASSERT(l + D_obuffree == D_obuflen);
+ if (D_userfd < 0)
+ {
+ D_obuffree += l;
+ D_obufp = D_obuf;
+ return;
+ }
+ p = D_obuf;
+ if (!progress)
+ {
+ if (fcntl(D_userfd, F_SETFL, 0))
+ debug1("Warning: BLOCK fcntl failed: %d\n", errno);
+ }
+ while (l)
+ {
+ if (progress)
+ {
+ fd_set w;
+ FD_ZERO(&w);
+ FD_SET(D_userfd, &w);
+ struct timeval t;
+ t.tv_sec = progress;
+ t.tv_usec = 0;
+ wr = select(FD_SETSIZE, (fd_set *)0, &w, (fd_set *)0, &t);
+ if (wr == -1)
+ {
+ if (errno == EINTR)
+ continue;
+ debug1("Warning: select failed: %d\n", errno);
+ break;
+ }
+ if (wr == 0)
+ {
+ /* no progress after 3 seconds. sorry. */
+ debug1("Warning: no progress after %d seconds\n", progress);
+ break;
+ }
+ }
+ wr = write(D_userfd, p, l);
+ if (wr <= 0)
+ {
+ if (errno == EINTR)
+ continue;
+ debug1("Writing to display: %d\n", errno);
+ break;
+ }
+ D_obuffree += wr;
+ p += wr;
+ l -= wr;
+ }
+ if (l)
+ debug1("Warning: Flush could not write %d bytes\n", l);
+ D_obuffree += l;
+ D_obufp = D_obuf;
+ if (!progress)
+ {
+ if (fcntl(D_userfd, F_SETFL, FNBLOCK))
+ debug1("Warning: NBLOCK fcntl failed: %d\n", errno);
+ }
+ if (D_blocked == 1)
+ D_blocked = 0;
+ D_blocked_fuzz = 0;
+}
+
+void
+freetty()
+{
+ if (D_userfd >= 0)
+ close(D_userfd);
+ debug1("did freetty %d\n", D_userfd);
+ D_userfd = -1;
+ D_obufp = 0;
+ D_obuffree = 0;
+ if (D_obuf)
+ free(D_obuf);
+ D_obuf = 0;
+ D_obuflen = 0;
+ D_obuflenmax = -D_obufmax;
+ D_blocked = 0;
+ D_blocked_fuzz = 0;
+}
+
+/*
+ * Asynchronous output routines by
+ * Tim MacKenzie (tym@dibbler.cs.monash.edu.au)
+ */
+
+void
+Resize_obuf()
+{
+ register int ind;
+
+ ASSERT(display);
+ if (D_status_obuffree >= 0)
+ {
+ ASSERT(D_obuffree == -1);
+ RemoveStatusMinWait();
+ if (--D_obuffree > 0) /* redo AddChar decrement */
+ return;
+ }
+ if (D_obuflen && D_obuf)
+ {
+ ind = D_obufp - D_obuf;
+ D_obuflen += GRAIN;
+ D_obuffree += GRAIN;
+ D_obuf = realloc(D_obuf, D_obuflen);
+ }
+ else
+ {
+ ind = 0;
+ D_obuflen = GRAIN;
+ D_obuffree = GRAIN;
+ D_obuf = malloc(D_obuflen);
+ }
+ if (!D_obuf)
+ Panic(0, "Out of memory");
+ D_obufp = D_obuf + ind;
+ D_obuflenmax = D_obuflen - D_obufmax;
+ debug1("ResizeObuf: resized to %d\n", D_obuflen);
+}
+
+void
+DisplaySleep1000(n, eat)
+int n;
+int eat;
+{
+ char buf;
+ fd_set r;
+ struct timeval t;
+
+ if (n <= 0)
+ return;
+ if (!display)
+ {
+ debug("DisplaySleep has no display sigh\n");
+ sleep1000(n);
+ return;
+ }
+ t.tv_usec = (n % 1000) * 1000;
+ t.tv_sec = n / 1000;
+ FD_ZERO(&r);
+ FD_SET(D_userfd, &r);
+ if (select(FD_SETSIZE, &r, (fd_set *)0, (fd_set *)0, &t) > 0)
+ {
+ debug("display activity stopped sleep\n");
+ if (eat)
+ read(D_userfd, &buf, 1);
+ }
+ debug2("DisplaySleep(%d) ending, eat was %d\n", n, eat);
+}
+
+#ifdef AUTO_NUKE
+void
+NukePending()
+{/* Nuke pending output in current display, clear screen */
+ register int len;
+ int oldtop = D_top, oldbot = D_bot;
+ struct mchar oldrend;
+ int oldkeypad = D_keypad, oldcursorkeys = D_cursorkeys;
+ int oldcurvis = D_curvis;
+ int oldmouse = D_mouse;
+
+ oldrend = D_rend;
+ len = D_obufp - D_obuf;
+ debug1("NukePending: nuking %d chars\n", len);
+
+ /* Throw away any output that we can... */
+# ifdef POSIX
+ tcflush(D_userfd, TCOFLUSH);
+# else
+# ifdef TCFLSH
+ (void) ioctl(D_userfd, TCFLSH, (char *) 1);
+# endif
+# endif
+
+ D_obufp = D_obuf;
+ D_obuffree += len;
+ D_top = D_bot = -1;
+ AddCStr(D_IS);
+ AddCStr(D_TI);
+ /* Turn off all attributes. (Tim MacKenzie) */
+ if (D_ME)
+ AddCStr(D_ME);
+ else
+ {
+#ifdef COLOR
+ if (D_hascolor)
+ AddStr("\033[m"); /* why is D_ME not set? */
+#endif
+ AddCStr(D_SE);
+ AddCStr(D_UE);
+ }
+ /* Check for toggle */
+ if (D_IM && strcmp(D_IM, D_EI))
+ AddCStr(D_EI);
+ D_insert = 0;
+ /* Check for toggle */
+#ifdef MAPKEYS
+ if (D_KS && strcmp(D_KS, D_KE))
+ AddCStr(D_KS);
+ if (D_CCS && strcmp(D_CCS, D_CCE))
+ AddCStr(D_CCS);
+#else
+ if (D_KS && strcmp(D_KS, D_KE))
+ AddCStr(D_KE);
+ D_keypad = 0;
+ if (D_CCS && strcmp(D_CCS, D_CCE))
+ AddCStr(D_CCE);
+ D_cursorkeys = 0;
+#endif
+ AddCStr(D_CE0);
+ D_rend = mchar_null;
+ D_atyp = 0;
+ AddCStr(D_DS);
+ D_hstatus = 0;
+ AddCStr(D_VE);
+ D_curvis = 0;
+ ChangeScrollRegion(oldtop, oldbot);
+ SetRendition(&oldrend);
+ KeypadMode(oldkeypad);
+ CursorkeysMode(oldcursorkeys);
+ CursorVisibility(oldcurvis);
+ MouseMode(oldmouse);
+ if (D_CWS)
+ {
+ debug("ResizeDisplay: using WS\n");
+ AddCStr(tgoto(D_CWS, D_width, D_height));
+ }
+ else if (D_CZ0 && (D_width == Z0width || D_width == Z1width))
+ {
+ debug("ResizeDisplay: using Z0/Z1\n");
+ AddCStr(D_width == Z0width ? D_CZ0 : D_CZ1);
+ }
+}
+#endif /* AUTO_NUKE */
+
+#ifdef linux
+/* linux' select can't handle flow control, so wait 100ms if
+ * we get EAGAIN
+ */
+static void
+disp_writeev_eagain(ev, data)
+struct event *ev;
+char *data;
+{
+ display = (struct display *)data;
+ evdeq(&D_writeev);
+ D_writeev.type = EV_WRITE;
+ D_writeev.handler = disp_writeev_fn;
+ evenq(&D_writeev);
+}
+#endif
+
+static void
+disp_writeev_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ int len, size = OUTPUT_BLOCK_SIZE;
+
+ display = (struct display *)data;
+ len = D_obufp - D_obuf;
+ if (len < size)
+ size = len;
+ if (D_status_obufpos && size > D_status_obufpos)
+ size = D_status_obufpos;
+ ASSERT(len >= 0);
+ size = write(D_userfd, D_obuf, size);
+ if (size >= 0)
+ {
+ len -= size;
+ if (len)
+ {
+ bcopy(D_obuf + size, D_obuf, len);
+ debug2("ASYNC: wrote %d - remaining %d\n", size, len);
+ }
+ D_obufp -= size;
+ D_obuffree += size;
+ if (D_status_obufpos)
+ {
+ D_status_obufpos -= size;
+ if (!D_status_obufpos)
+ {
+ debug("finished writing the status message\n");
+ /* we're finished displaying the message! */
+ if (D_status == STATUS_ON_WIN)
+ {
+ /* setup continue trigger */
+ D_status_obuflen = D_obuflen;
+ D_status_obuffree = D_obuffree;
+ /* setting obbuffree to 0 will make AddChar call
+ * ResizeObuf */
+ D_obuffree = D_obuflen = 0;
+ }
+ gettimeofday(&D_status_time, NULL);
+ SetTimeout(&D_statusev, MsgWait);
+ evenq(&D_statusev);
+#ifdef HAVE_BRAILLE
+ RefreshBraille(); /* let user see multiple Msg()s */
+#endif
+ }
+ }
+ if (D_blocked_fuzz)
+ {
+ D_blocked_fuzz -= size;
+ if (D_blocked_fuzz < 0)
+ D_blocked_fuzz = 0;
+ }
+ if (D_blockedev.queued)
+ {
+ if (D_obufp - D_obuf > D_obufmax / 2)
+ {
+ debug2("%s: resetting timeout to %g secs\n", D_usertty, D_nonblock/1000.);
+ SetTimeout(&D_blockedev, D_nonblock);
+ }
+ else
+ {
+ debug1("%s: deleting blocked timeout\n", D_usertty);
+ evdeq(&D_blockedev);
+ }
+ }
+ if (D_blocked == 1 && D_obuf == D_obufp)
+ {
+ /* empty again, restart output */
+ debug1("%s: buffer empty, unblocking\n", D_usertty);
+ D_blocked = 0;
+ Activate(D_fore ? D_fore->w_norefresh : 0);
+ D_blocked_fuzz = D_obufp - D_obuf;
+ }
+ }
+ else
+ {
+#ifdef linux
+ /* linux flow control is badly broken */
+ if (errno == EAGAIN)
+ {
+ evdeq(&D_writeev);
+ D_writeev.type = EV_TIMEOUT;
+ D_writeev.handler = disp_writeev_eagain;
+ SetTimeout(&D_writeev, 100);
+ evenq(&D_writeev);
+ }
+#endif
+ if (errno != EINTR && errno != EAGAIN)
+#if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
+ if (errno != EWOULDBLOCK)
+#endif
+ Msg(errno, "Error writing output to display");
+ }
+}
+
+static void
+disp_readev_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ int size;
+ char buf[IOSIZE];
+ struct canvas *cv;
+
+ display = (struct display *)data;
+
+ /* Hmmmm... a bit ugly... */
+ if (D_forecv)
+ for (cv = D_forecv->c_layer->l_cvlist; cv; cv = cv->c_lnext)
+ {
+ display = cv->c_display;
+ if (D_status == STATUS_ON_WIN)
+ RemoveStatus();
+ }
+
+ display = (struct display *)data;
+ if (D_fore == 0)
+ size = IOSIZE;
+ else
+ {
+#ifdef PSEUDOS
+ if (W_UWP(D_fore))
+ size = sizeof(D_fore->w_pwin->p_inbuf) - D_fore->w_pwin->p_inlen;
+ else
+#endif
+ size = sizeof(D_fore->w_inbuf) - D_fore->w_inlen;
+ }
+
+ if (size > IOSIZE)
+ size = IOSIZE;
+ if (size <= 0)
+ size = 1; /* Always allow one char for command keys */
+
+ size = read(D_userfd, buf, size);
+ if (size < 0)
+ {
+ if (errno == EINTR || errno == EAGAIN)
+ return;
+#if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
+ if (errno == EWOULDBLOCK)
+ return;
+#endif
+ debug1("Read error: %d - hangup!\n", errno);
+ Hangup();
+ sleep(1);
+ return;
+ }
+ else if (size == 0)
+ {
+ debug("Found EOF - hangup!\n");
+ Hangup();
+ sleep(1);
+ return;
+ }
+ if (D_blocked == 4)
+ {
+ D_blocked = 0;
+#ifdef BLANKER_PRG
+ KillBlanker();
+#endif
+ Activate(D_fore ? D_fore->w_norefresh : 0);
+ ResetIdle();
+ return;
+ }
+#ifdef ZMODEM
+ if (D_blocked > 1) /* 2, 3 */
+ {
+ char *bufp;
+ struct win *p;
+
+ flayer = 0;
+ for (p = windows; p ; p = p->w_next)
+ if (p->w_zdisplay == display)
+ {
+ flayer = &p->w_layer;
+ bufp = buf;
+ while (size > 0)
+ LayProcess(&bufp, &size);
+ return;
+ }
+ debug("zmodem window gone, deblocking display");
+ zmodem_abort(0, display);
+ }
+#endif
+ if (idletimo > 0)
+ ResetIdle();
+ if (D_fore)
+ D_fore->w_lastdisp = display;
+ if (D_mouse && D_forecv)
+ {
+ unsigned char *bp = (unsigned char *)buf;
+ int x, y, i;
+
+ /* XXX this assumes that the string is read in as a whole... */
+ for (i = size; i > 0; i--, bp++)
+ {
+ if (i > 5 && bp[0] == 033 && bp[1] == '[' && bp[2] == 'M')
+ {
+ bp++;
+ i--;
+ }
+ else if (i < 5 || bp[0] != 0233 || bp[1] != 'M')
+ continue;
+ x = bp[3] - 33;
+ y = bp[4] - 33;
+ if (x >= D_forecv->c_xs && x <= D_forecv->c_xe && y >= D_forecv->c_ys && y <= D_forecv->c_ye)
+ {
+ if ((D_fore && D_fore->w_mouse) || (D_mousetrack && D_forecv->c_layer->l_mode == 1))
+ {
+ /* Send clicks only if the window is expecting clicks */
+ x -= D_forecv->c_xoff;
+ y -= D_forecv->c_yoff;
+ if (x >= 0 && x < D_forecv->c_layer->l_width && y >= 0 && y < D_forecv->c_layer->l_height)
+ {
+ bp[3] = x + 33;
+ bp[4] = y + 33;
+ i -= 4;
+ bp += 4;
+ continue;
+ }
+ }
+ }
+ else if (D_mousetrack && bp[2] == '#')
+ {
+ /* 'focus' to the clicked region, only on mouse up */
+ struct canvas *cv = FindCanvas(x, y);
+ if (cv)
+ {
+ SetForeCanvas(display, cv);
+ /* XXX: Do we want to reset the input buffer? */
+ }
+ }
+ if (bp[0] == '[')
+ {
+ bcopy((char *)bp + 1, (char *)bp, i);
+ bp--;
+ size--;
+ }
+ if (i > 5)
+ bcopy((char *)bp + 5, (char *)bp, i - 5);
+ bp--;
+ i -= 4;
+ size -= 5;
+ }
+ }
+#ifdef ENCODINGS
+ if (D_encoding != (D_forecv ? D_forecv->c_layer->l_encoding : 0))
+ {
+ int i, j, c, enc;
+ char buf2[IOSIZE * 2 + 10];
+ enc = D_forecv ? D_forecv->c_layer->l_encoding : 0;
+ for (i = j = 0; i < size; i++)
+ {
+ c = ((unsigned char *)buf)[i];
+ c = DecodeChar(c, D_encoding, &D_decodestate);
+ if (c == -2)
+ i--; /* try char again */
+ if (c < 0)
+ continue;
+ if (pastefont)
+ {
+ int font = 0;
+ j += EncodeChar(buf2 + j, c, enc, &font);
+ j += EncodeChar(buf2 + j, -1, enc, &font);
+ }
+ else
+ j += EncodeChar(buf2 + j, c, enc, 0);
+ if (j > (int)sizeof(buf2) - 10) /* just in case... */
+ break;
+ }
+ (*D_processinput)(buf2, j);
+ return;
+ }
+#endif
+ (*D_processinput)(buf, size);
+}
+
+static void
+disp_status_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ display = (struct display *)data;
+ debug1("disp_status_fn for display %x\n", (int)display);
+ if (D_status)
+ RemoveStatus();
+}
+
+static void
+disp_hstatus_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ display = (struct display *)data;
+ if (D_status == STATUS_ON_HS)
+ {
+ SetTimeout(ev, 1);
+ evenq(ev);
+ return;
+ }
+ RefreshHStatus();
+}
+
+static void
+disp_blocked_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ struct win *p;
+
+ display = (struct display *)data;
+ debug1("blocked timeout %s\n", D_usertty);
+ if (D_obufp - D_obuf > D_obufmax + D_blocked_fuzz)
+ {
+ debug("stopping output to display\n");
+ D_blocked = 1;
+ /* re-enable all windows */
+ for (p = windows; p; p = p->w_next)
+ if (p->w_readev.condneg == &D_obuflenmax)
+ {
+ debug1("freeing window #%d\n", p->w_number);
+ p->w_readev.condpos = p->w_readev.condneg = 0;
+ }
+ }
+}
+
+#ifdef MAPKEYS
+static void
+disp_map_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ char *p;
+ int l, i;
+ unsigned char *q;
+ display = (struct display *)data;
+ debug("Flushing map sequence\n");
+ if (!(l = D_seql))
+ return;
+ p = (char *)D_seqp - l;
+ D_seqp = D_kmaps + 3;
+ D_seql = 0;
+ if ((q = D_seqh) != 0)
+ {
+ D_seqh = 0;
+ i = q[0] << 8 | q[1];
+ i &= ~KMAP_NOTIMEOUT;
+ debug1("Mapping former hit #%d - ", i);
+ debug2("%d(%s) - ", q[2], q + 3);
+ if (StuffKey(i))
+ ProcessInput2((char *)q + 3, q[2]);
+ if (display == 0)
+ return;
+ l -= q[2];
+ p += q[2];
+ }
+ else
+ D_dontmap = 1;
+ ProcessInput(p, l);
+}
+#endif
+
+static void
+disp_idle_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ struct display *olddisplay;
+ display = (struct display *)data;
+ debug("idle timeout\n");
+ if (idletimo <= 0 || idleaction.nr == RC_ILLEGAL)
+ return;
+ olddisplay = display;
+ flayer = D_forecv->c_layer;
+ fore = D_fore;
+ DoAction(&idleaction, -1);
+ if (idleaction.nr == RC_BLANKER)
+ return;
+ for (display = displays; display; display = display->d_next)
+ if (olddisplay == display)
+ break;
+ if (display)
+ ResetIdle();
+}
+
+void
+ResetIdle()
+{
+ if (idletimo > 0)
+ {
+ SetTimeout(&D_idleev, idletimo);
+ if (!D_idleev.queued)
+ evenq(&D_idleev);
+ }
+ else
+ evdeq(&D_idleev);
+}
+
+
+#ifdef BLANKER_PRG
+
+static void
+disp_blanker_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ char buf[IOSIZE], *b;
+ int size;
+
+ display = (struct display *)data;
+ size = read(D_blankerev.fd, buf, IOSIZE);
+ if (size <= 0)
+ {
+ evdeq(&D_blankerev);
+ close(D_blankerev.fd);
+ D_blankerev.fd = -1;
+ return;
+ }
+ for (b = buf; size; size--)
+ AddChar(*b++);
+}
+
+void
+KillBlanker()
+{
+ int oldtop = D_top, oldbot = D_bot;
+ struct mchar oldrend;
+
+ if (D_blankerev.fd == -1)
+ return;
+ if (D_blocked == 4)
+ D_blocked = 0;
+ evdeq(&D_blankerev);
+ close(D_blankerev.fd);
+ D_blankerev.fd = -1;
+ Kill(D_blankerpid, SIGHUP);
+ D_top = D_bot = -1;
+ oldrend = D_rend;
+ if (D_ME)
+ {
+ AddCStr(D_ME);
+ AddCStr(D_ME);
+ }
+ else
+ {
+#ifdef COLOR
+ if (D_hascolor)
+ AddStr("\033[m\033[m"); /* why is D_ME not set? */
+#endif
+ AddCStr(D_SE);
+ AddCStr(D_UE);
+ }
+ AddCStr(D_VE);
+ AddCStr(D_CE0);
+ D_rend = mchar_null;
+ D_atyp = 0;
+ D_curvis = 0;
+ D_x = D_y = -1;
+ ChangeScrollRegion(oldtop, oldbot);
+ SetRendition(&oldrend);
+ ClearAll();
+}
+
+void
+RunBlanker(cmdv)
+char **cmdv;
+{
+ char *m;
+ int pid;
+ int slave = -1;
+ char termname[MAXTERMLEN + 6];
+#ifndef TIOCSWINSZ
+ char libuf[20], cobuf[20];
+#endif
+ char **np;
+
+ strcpy(termname, "TERM=");
+ strncpy(termname + 5, D_termname, MAXTERMLEN - 6);
+ termname[sizeof(termname) - 1] = 0;
+ KillBlanker();
+ D_blankerpid = -1;
+ if ((D_blankerev.fd = OpenPTY(&m)) == -1)
+ {
+ Msg(0, "OpenPty failed");
+ return;
+ }
+#ifdef O_NOCTTY
+ if (pty_preopen)
+ {
+ if ((slave = open(m, O_RDWR|O_NOCTTY)) == -1)
+ {
+ Msg(errno, "%s", m);
+ close(D_blankerev.fd);
+ D_blankerev.fd = -1;
+ return;
+ }
+ }
+#endif
+ switch (pid = (int)fork())
+ {
+ case -1:
+ Msg(errno, "fork");
+ close(D_blankerev.fd);
+ D_blankerev.fd = -1;
+ close(slave);
+ return;
+ case 0:
+ displays = 0;
+#ifdef DEBUG
+ if (dfp && dfp != stderr)
+ {
+ fclose(dfp);
+ dfp = 0;
+ }
+#endif
+ if (setgid(real_gid) || setuid(real_uid))
+ Panic(errno, "setuid/setgid");
+ brktty(D_userfd);
+ freetty();
+ close(0);
+ close(1);
+ close(2);
+ closeallfiles(slave);
+ if (open(m, O_RDWR))
+ Panic(errno, "Cannot open %s", m);
+ dup(0);
+ dup(0);
+ if (slave != -1)
+ close(slave);
+ InitPTY(0);
+ fgtty(0);
+ SetTTY(0, &D_OldMode);
+ np = NewEnv + 3;
+ *np++ = NewEnv[0];
+ *np++ = termname;
+#ifdef TIOCSWINSZ
+ glwz.ws_col = D_width;
+ glwz.ws_row = D_height;
+ (void)ioctl(0, TIOCSWINSZ, (char *)&glwz);
+#else
+ sprintf(libuf, "LINES=%d", D_height);
+ sprintf(cobuf, "COLUMNS=%d", D_width);
+ *np++ = libuf;
+ *np++ = cobuf;
+#endif
+#ifdef SIGPIPE
+ signal(SIGPIPE, SIG_DFL);
+#endif
+ display = 0;
+ execvpe(*cmdv, cmdv, NewEnv + 3);
+ Panic(errno, "%s", *cmdv);
+ default:
+ break;
+ }
+ D_blankerpid = pid;
+ evenq(&D_blankerev);
+ D_blocked = 4;
+ ClearAll();
+ close(slave);
+}
+
+#endif /* BLANKER_PRG */
+
+
diff --git a/display.h b/display.h
new file mode 100644
index 0000000..19dded7
--- /dev/null
+++ b/display.h
@@ -0,0 +1,327 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+#ifndef SCREEN_DISPLAY_H
+#define SCREEN_DISPLAY_H
+
+#include "layout.h"
+#include "canvas.h"
+#include "viewport.h"
+
+#ifdef MAPKEYS
+
+#define KMAP_KEYS (T_OCAPS-T_CAPS)
+#define KMAP_AKEYS (T_OCAPS-T_CURSOR)
+
+#define KMAP_NOTIMEOUT 0x4000
+
+struct kmap_ext
+{
+ char *str;
+ int fl;
+ struct action um;
+ struct action dm;
+ struct action mm;
+};
+
+#else
+
+#define KMAP_KEYS 0
+
+#endif
+
+struct win; /* forward declaration */
+
+struct display
+{
+ struct display *d_next; /* linked list */
+ struct acluser *d_user; /* user who owns that display */
+ struct canvas d_canvas; /* our canvas slice */
+ struct canvas *d_cvlist; /* the canvases of this display */
+ struct canvas *d_forecv; /* current input focus */
+ struct layout *d_layout; /* layout we're using */
+ void (*d_processinput) __P((char *, int));
+ char *d_processinputdata; /* data for processinput */
+ int d_vpxmin, d_vpxmax; /* min/max used position on display */
+ struct win *d_fore; /* pointer to fore window */
+ struct win *d_other; /* pointer to other window */
+ int d_nonblock; /* -1 don't block if obufmax reached */
+ /* >0: block after nonblock secs */
+ char d_termname[MAXTERMLEN + 1]; /* $TERM */
+ char *d_tentry; /* buffer for tgetstr */
+ char d_tcinited; /* termcap inited flag */
+ int d_width, d_height; /* width/height of the screen */
+ int d_defwidth, d_defheight; /* default width/height of windows */
+ int d_top, d_bot; /* scrollregion start/end */
+ int d_x, d_y; /* cursor position */
+ struct mchar d_rend; /* current rendition */
+ int d_col16change; /* the 16col bits changed in attr */
+ char d_atyp; /* current attribute types */
+#ifdef DW_CHARS
+ int d_mbcs; /* saved char for multibytes charset */
+#endif
+#ifdef ENCODINGS
+ int d_encoding; /* what encoding type the display is */
+ int d_decodestate; /* state of our decoder */
+ int d_realfont; /* real font of terminal */
+#endif
+ int d_insert; /* insert mode flag */
+ int d_keypad; /* application keypad flag */
+ int d_cursorkeys; /* application cursorkeys flag */
+ int d_revvid; /* reverse video */
+ int d_curvis; /* cursor visibility */
+ int d_has_hstatus; /* display has hardstatus line */
+ int d_hstatus; /* hardstatus used */
+ int d_lp_missing; /* last character on bot line missing */
+ int d_mouse; /* mouse mode */
+ int d_mousetrack; /* set when user wants to use mouse even when the window
+ does not */
+#ifdef RXVT_OSC
+ int d_xtermosc[4]; /* osc used */
+#endif
+ struct mchar d_lpchar; /* missing char */
+ struct timeval d_status_time; /* time of status display */
+ int d_status; /* is status displayed? */
+ char d_status_bell; /* is it only a vbell? */
+ int d_status_len; /* length of status line */
+ char *d_status_lastmsg; /* last displayed message */
+ int d_status_buflen; /* last message buffer len */
+ int d_status_lastx; /* position of the cursor */
+ int d_status_lasty; /* before status was displayed */
+ int d_status_obuflen; /* saved obuflen */
+ int d_status_obuffree; /* saved obuffree */
+ int d_status_obufpos; /* end of status position in obuf */
+ struct event d_statusev; /* timeout event */
+ struct event d_hstatusev; /* hstatus changed event */
+ int d_kaablamm; /* display kaablamm msg */
+ struct action *d_ESCseen; /* Was the last char an ESC (^a) */
+ int d_userpid; /* pid of attacher */
+ char d_usertty[MAXPATHLEN]; /* tty we are attached to */
+ int d_userfd; /* fd of the tty */
+ struct event d_readev; /* userfd read event */
+ struct event d_writeev; /* userfd write event */
+ struct event d_blockedev; /* blocked timeout */
+ struct mode d_OldMode; /* tty mode when screen was started */
+ struct mode d_NewMode; /* New tty mode */
+ int d_flow; /* tty's flow control on/off flag*/
+ int d_intrc; /* current intr when flow is on */
+ char *d_obuf; /* output buffer */
+ int d_obuflen; /* len of buffer */
+ int d_obufmax; /* len where we are blocking the pty */
+ int d_obuflenmax; /* len - max */
+ char *d_obufp; /* pointer in buffer */
+ int d_obuffree; /* free bytes in buffer */
+#ifdef AUTO_NUKE
+ int d_auto_nuke; /* autonuke flag */
+#endif
+#ifdef MAPKEYS
+ int d_nseqs; /* number of valid mappings */
+ int d_aseqs; /* number of allocated mappings */
+ unsigned char *d_kmaps; /* keymaps */
+ unsigned char *d_seqp; /* pointer into keymap array */
+ int d_seql; /* number of parsed chars */
+ unsigned char *d_seqh; /* last hit */
+ struct event d_mapev; /* timeout event */
+ int d_dontmap; /* do not map next */
+ int d_mapdefault; /* do map next to default */
+#endif
+ union tcu d_tcs[T_N]; /* terminal capabilities */
+ char *d_attrtab[NATTR]; /* attrib emulation table */
+ char d_attrtyp[NATTR]; /* attrib group table */
+ int d_hascolor; /* do we support color */
+ short d_dospeed; /* baudrate of tty */
+#ifdef FONT
+ char d_c0_tab[256]; /* conversion for C0 */
+ char ***d_xtable; /* char translation table */
+#endif
+ int d_UPcost, d_DOcost, d_LEcost, d_NDcost;
+ int d_CRcost, d_IMcost, d_EIcost, d_NLcost;
+ int d_printfd; /* fd for vt100 print sequence */
+#ifdef UTMPOK
+ slot_t d_loginslot; /* offset, where utmp_logintty belongs */
+ struct utmp d_utmp_logintty; /* here the original utmp structure is stored */
+ int d_loginttymode;
+# ifdef _SEQUENT_
+ char d_loginhost[100+1];
+# endif /* _SEQUENT_ */
+#endif
+ int d_blocked;
+ int d_blocked_fuzz;
+ struct event d_idleev; /* screen blanker */
+#ifdef BLANKER_PRG
+ int d_blankerpid;
+ struct event d_blankerev;
+#endif
+};
+
+#ifdef MULTI
+# define DISPLAY(x) display->x
+#else
+extern struct display TheDisplay;
+# define DISPLAY(x) TheDisplay.x
+#endif
+
+#define D_user DISPLAY(d_user)
+#define D_username (DISPLAY(d_user) ? DISPLAY(d_user)->u_name : 0)
+#define D_canvas DISPLAY(d_canvas)
+#define D_cvlist DISPLAY(d_cvlist)
+#define D_layout DISPLAY(d_layout)
+#define D_forecv DISPLAY(d_forecv)
+#define D_processinput DISPLAY(d_processinput)
+#define D_processinputdata DISPLAY(d_processinputdata)
+#define D_vpxmin DISPLAY(d_vpxmin)
+#define D_vpxmax DISPLAY(d_vpxmax)
+#define D_fore DISPLAY(d_fore)
+#define D_other DISPLAY(d_other)
+#define D_nonblock DISPLAY(d_nonblock)
+#define D_termname DISPLAY(d_termname)
+#define D_tentry DISPLAY(d_tentry)
+#define D_tcinited DISPLAY(d_tcinited)
+#define D_width DISPLAY(d_width)
+#define D_height DISPLAY(d_height)
+#define D_defwidth DISPLAY(d_defwidth)
+#define D_defheight DISPLAY(d_defheight)
+#define D_top DISPLAY(d_top)
+#define D_bot DISPLAY(d_bot)
+#define D_x DISPLAY(d_x)
+#define D_y DISPLAY(d_y)
+#define D_rend DISPLAY(d_rend)
+#define D_col16change DISPLAY(d_col16change)
+#define D_atyp DISPLAY(d_atyp)
+#define D_mbcs DISPLAY(d_mbcs)
+#define D_encoding DISPLAY(d_encoding)
+#define D_decodestate DISPLAY(d_decodestate)
+#define D_realfont DISPLAY(d_realfont)
+#define D_insert DISPLAY(d_insert)
+#define D_keypad DISPLAY(d_keypad)
+#define D_cursorkeys DISPLAY(d_cursorkeys)
+#define D_revvid DISPLAY(d_revvid)
+#define D_curvis DISPLAY(d_curvis)
+#define D_has_hstatus DISPLAY(d_has_hstatus)
+#define D_hstatus DISPLAY(d_hstatus)
+#define D_lp_missing DISPLAY(d_lp_missing)
+#define D_mouse DISPLAY(d_mouse)
+#define D_mousetrack DISPLAY(d_mousetrack)
+#define D_xtermosc DISPLAY(d_xtermosc)
+#define D_lpchar DISPLAY(d_lpchar)
+#define D_status DISPLAY(d_status)
+#define D_status_time DISPLAY(d_status_time)
+#define D_status_bell DISPLAY(d_status_bell)
+#define D_status_len DISPLAY(d_status_len)
+#define D_status_lastmsg DISPLAY(d_status_lastmsg)
+#define D_status_buflen DISPLAY(d_status_buflen)
+#define D_status_lastx DISPLAY(d_status_lastx)
+#define D_status_lasty DISPLAY(d_status_lasty)
+#define D_status_obuflen DISPLAY(d_status_obuflen)
+#define D_status_obuffree DISPLAY(d_status_obuffree)
+#define D_status_obufpos DISPLAY(d_status_obufpos)
+#define D_statusev DISPLAY(d_statusev)
+#define D_hstatusev DISPLAY(d_hstatusev)
+#define D_kaablamm DISPLAY(d_kaablamm)
+#define D_ESCseen DISPLAY(d_ESCseen)
+#define D_userpid DISPLAY(d_userpid)
+#define D_usertty DISPLAY(d_usertty)
+#define D_userfd DISPLAY(d_userfd)
+#define D_OldMode DISPLAY(d_OldMode)
+#define D_NewMode DISPLAY(d_NewMode)
+#define D_flow DISPLAY(d_flow)
+#define D_intr DISPLAY(d_intr)
+#define D_obuf DISPLAY(d_obuf)
+#define D_obuflen DISPLAY(d_obuflen)
+#define D_obufmax DISPLAY(d_obufmax)
+#define D_obuflenmax DISPLAY(d_obuflenmax)
+#define D_obufp DISPLAY(d_obufp)
+#define D_obuffree DISPLAY(d_obuffree)
+#define D_auto_nuke DISPLAY(d_auto_nuke)
+#define D_nseqs DISPLAY(d_nseqs)
+#define D_aseqs DISPLAY(d_aseqs)
+#define D_seqp DISPLAY(d_seqp)
+#define D_seql DISPLAY(d_seql)
+#define D_seqh DISPLAY(d_seqh)
+#define D_dontmap DISPLAY(d_dontmap)
+#define D_mapdefault DISPLAY(d_mapdefault)
+#define D_kmaps DISPLAY(d_kmaps)
+#define D_tcs DISPLAY(d_tcs)
+#define D_attrtab DISPLAY(d_attrtab)
+#define D_attrtyp DISPLAY(d_attrtyp)
+#define D_hascolor DISPLAY(d_hascolor)
+#define D_dospeed DISPLAY(d_dospeed)
+#define D_c0_tab DISPLAY(d_c0_tab)
+#define D_xtable DISPLAY(d_xtable)
+#define D_UPcost DISPLAY(d_UPcost)
+#define D_DOcost DISPLAY(d_DOcost)
+#define D_LEcost DISPLAY(d_LEcost)
+#define D_NDcost DISPLAY(d_NDcost)
+#define D_CRcost DISPLAY(d_CRcost)
+#define D_IMcost DISPLAY(d_IMcost)
+#define D_EIcost DISPLAY(d_EIcost)
+#define D_NLcost DISPLAY(d_NLcost)
+#define D_printfd DISPLAY(d_printfd)
+#define D_loginslot DISPLAY(d_loginslot)
+#define D_utmp_logintty DISPLAY(d_utmp_logintty)
+#define D_loginttymode DISPLAY(d_loginttymode)
+#define D_loginhost DISPLAY(d_loginhost)
+#define D_readev DISPLAY(d_readev)
+#define D_writeev DISPLAY(d_writeev)
+#define D_blockedev DISPLAY(d_blockedev)
+#define D_mapev DISPLAY(d_mapev)
+#define D_blocked DISPLAY(d_blocked)
+#define D_blocked_fuzz DISPLAY(d_blocked_fuzz)
+#define D_idleev DISPLAY(d_idleev)
+#define D_blankerev DISPLAY(d_blankerev)
+#define D_blankerpid DISPLAY(d_blankerpid)
+
+
+#define GRAIN 4096 /* Allocation grain size for output buffer */
+#define OBUF_MAX 256 /* default for obuflimit */
+
+#define OUTPUT_BLOCK_SIZE 256 /* Block size of output to tty */
+
+#define AddChar(c) \
+do \
+ { \
+ if (--D_obuffree <= 0) \
+ Resize_obuf(); \
+ *D_obufp++ = (c); \
+ } \
+while (0)
+
+#define STATUS_OFF 0
+#define STATUS_ON_WIN 1
+#define STATUS_ON_HS 2
+
+#define HSTATUS_IGNORE 0
+#define HSTATUS_LASTLINE 1
+#define HSTATUS_MESSAGE 2
+#define HSTATUS_HS 3
+#define HSTATUS_FIRSTLINE 4
+#define HSTATUS_ALWAYS (1<<3)
+
+#endif /* SCREEN_DISPLAY_H */
+
diff --git a/doc/.gitignore b/doc/.gitignore
new file mode 100644
index 0000000..2681820
--- /dev/null
+++ b/doc/.gitignore
@@ -0,0 +1,2 @@
+Makefile
+screen.info*
diff --git a/doc/FAQ b/doc/FAQ
new file mode 100644
index 0000000..6c9c8af
--- /dev/null
+++ b/doc/FAQ
@@ -0,0 +1,253 @@
+ jw 21.10.93
+ 05.05.94
+
+ screen: frequently asked questions -- known problems -- unimplemented bugs
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+
+
+Q: Why is it impossible to download a file with Kermit/sz/rz when
+ screen is running? Do I need to set some special variables?
+
+A: Screen always interprets control-sequences sent by the
+ applications and translates/optimizes them for the current
+ terminal type. Screen always parses the user input for its
+ escape character (CTRL-A). Both are basic screen features and
+ cannot be switched off. Even if it were possible to switch
+ screen into a completely transparent mode, you could never switch
+ between windows, while kermit/sz/rz is downloading a file. You
+ must wait til the end as kermit/sz/rz will not transmit your
+ input during a file transfer and as kermit/sz/rz would be very
+ confused if screen switched away the window containing the
+ other kermit/sz/rz. Simply detach your screen session for each
+ file transfer and start the transfer program only from the shell
+ where you started screen.
+
+Q: I am using screen with a YYY terminal, which supports the XXX
+ graphic language. I am very happy with it, except one thing: I
+ cannot render graphics into screen windows.
+
+A: You are out of luck there. Screen provides a fixed set of escape
+ sequences in order to make it possible to switch terminal types.
+ Screen has to know exactly what the escape sequences do to the
+ terminal because it must hold an image in memory. Otherwise
+ screen could not restore the image if you switch to another
+ window. Because of this you have to change screens escape
+ sequence parser (ansi.c) to pass the XXX graphics sequences to
+ the terminal. Of course the graphics will be lost if you switch
+ to another window. Screen will only honour graphics sequences
+ that are demanded by an overwhelming majority.
+
+Q: For some unknown reason, the fifo in /tmp/screens/S-myname is
+ gone, and i can't resume my screen session. Is there a way to
+ recreate the fifo?
+
+A: Screen checks the fifo/socket whenever it receives a SIGCHLD
+ signal. If missing, the fifo/socket is recreated then. If screen
+ is running non set-uid the user can issue a 'kill -CHLD
+ screenpid' directly (it is -CHILD on some systems). Screenpid is
+ the process-id of the screen process found in a 'ps -x' listing.
+ But usually this won't work, as screen should be installed set-
+ uid root. In this case you will not be able to send it a signal,
+ but the kernel will. It does so, whenever a child of screen
+ changes its state. Find the process-id (shellpid below) of the
+ "least important" shell running inside screen. The try 'kill
+ -STOP shellpid'. If the fifo/socket does not reappear, destroy
+ the shell process. You sacrify one shell to save the rest. If
+ nothing works, please do not forget to remove all processes
+ running in the lost screen session.
+
+Q: When you start "screen" a page of text comes up to start you
+ off. Is there a way to get rid of this text as a command line
+ argument or by using a switch of some sort.
+
+A: Just put the following line in your ~/.screenrc:
+ startup_message off
+ Many peole ask this, although it is in the man page, too :-)
+
+Q: Start "screen emacs" and run emacs function suspend-emacs
+ (ctrl-z). The window containing emacs vanishes.
+
+A: This is a known bug. Unfortunatly there is no easy fix
+ because this is specified in the POSIX standard. When a new
+ window is created Screen opens up a new session because the
+ window has to get the pty as a controlling terminal (a
+ session can only have one controlling terminal). With the
+ setsid() call the process also creates a new process
+ group. This process group is orphaned, because there is no
+ process in the session which is not in the process
+ group. Now if the process group leader (i.e. your program)
+ gets a TTIN/TTOU/TSTP, POSIX states that the kernel must
+ send a KILL signal to the process group because there is no
+ one left to continue the process. Even if screen would
+ try to restart the program, that would be after it received the
+ KILL signal which cannot be caught or ignored.
+
+ tromey@klab.caltech.edu (Tom Tromey): I've noticed this exact
+ same problem. I put this in my .emacs file. It seems to work:
+
+ ;; If running under screen, disable C-z.
+ (if (and (getenv "STY") (not window-system))
+ (global-unset-key "\C-z"))
+
+Q: Screen gets the terminal size wrong and messes up.
+
+A: Before you start screen: Check with 'stty -a' what the terminal
+ driver thinks about rows and columns. Check the environment
+ variables LINES and COLUMNS. Then from within screen check with
+ the info command (CTRL-A i) what size screen thinks your terminal
+ is. If correcting tty driver setting and environment variables
+ does not help, look up the terminal capability definition. First
+ the TERMCAP environment variable. If this is not set, look up the
+ terminals name as defined in the environment variable TERM in
+ /etc/termcap or in the terminfo database with untic or infocmp.
+ There may be :li=...: and :co=...: or even :ll=...: entries
+ (cols#... and lines#... when it's terminfo) defined incorrectly.
+ Either construct your own TERMCAP environment variables with
+ correct settings, use screens terminfo/termcap command in your
+ .screenrc file or have the database corrected by the system
+ administrator.
+
+Q: Screen messes up the terminal output when I use my favourite ap-
+ plication. Setting the terminal size does not help.
+
+A: Probably you got the termcap/terminfo entries wrong. Fixing this
+ is a three stage procedure. First, find out if terminfo or
+ termcap is used. If your system only has /etc/termcap,
+ but not /usr/lib/terminfo/... then you are using termcap.
+ Easy. But if your system has both, then it depends how the appli-
+ cation and how screen were linked. Beware, if your applica-
+ tion runs on another host via rlogin, telnet or the like, you
+ should check the terminfo/termcap databases there. If you cannot
+ tell if terminfo or termcap is used (or you just want to be
+ save), the do all steps in stage 3 in parallel for both
+ systems (on all envolved hosts). Second: Understand the basic
+ rules how screen does its terminal emulation. When screen is
+ started or reattached, it relies on the TERM environment variable
+ to correctly reflect the terminal type you have physically
+ in front of you. And the entry should either exist in the system
+ terminfo/termcap database or be specified via the TERMCAP en-
+ vironment variable (if screen is using the termcap system). On
+ the other end, screen understands one set of control codes. It
+ relies on the application using these codes. This means applica-
+ tions that run under screen must be able to adapt their con-
+ trol codes to screen. The application should use the TERM vari-
+ able and termcap or terminfo library to find out how to drive
+ its terminal. When running under screen, the terminal is virtual
+ and is only defined by the set of control codes that screen
+ understands. The TERM variable is automatically set to
+ "screen" and the "screen"-entries should exist in the data-
+ bases. If your application uses hardcoded control codes rather
+ than a database, you are on your own. Hint: The codes under-
+ stood by screen are a superset of the very common definition
+ named "vt100". Look at the documentation of screen. The
+ codes are listed there. Third: Have the entry "screen" in-
+ stalled on all hosts or make sure you can live with "vt100".
+ Check the codes sent by your application, when the TERM variable
+ is set to "screen". Do not try to set the TERM variable inside
+ screen to anything other than "screen" or "vt100" or compati-
+ ble. Thus your application can drive screen correctly. Also take
+ care that a good entry is installed for your physical terminal
+ that screen has to drive. Even if the entry was good enough
+ for your application to drive the terminal directly, screen may
+ find flaws, as it tries to use other capabilities while op-
+ timizing the screen output. The screenrc commands
+ "termcap" and/or "terminfo" may help to fine-tune capabilities
+ without calling the supervisor to change the database.
+
+Q: I cannot configure screen. Sed does not work.
+
+A: The regular expressions used in our configure scrip are too
+ complicated for GNU sed version 2.03. In this regard it is bug
+ compatible with Ultrix 3.1 "sed": GNU sed version 2.03 dumps
+ core with our configure script. Try an older release. E.g. from
+ ftp.uni-erlangen.de:/pub/utilities/screen/sed-2.02b.tar.gz
+
+Q: When reattaching a session from a different Workstation, the
+ DISPLAY environment variable should be updated. Even ``CTLR-A
+ : setenv DISPLAY newhost:0'' does not work as expected.
+
+A: Under unix every process has its own environment. The environ-
+ ment of the SCREEN process can be changed with the `setenv' com-
+ mand. This however cannot affect the environment of the
+ shells or applications already running under screen. Subsequently
+ spawned processes will reflect the changes. One should be aware
+ of this problem when running applications from very old shells.
+ Screen is a means for keeping processes alive.
+
+Q: About once every 5 times I ran the program, rather than getting
+ a "screen," I got someone elses IRC output/input.
+
+A: What probably happened is that an IRC process was left running on
+ a pseudo tty in such a way that the kernel thought the tty was
+ available for reallocation. You can fix this behaviour by
+ applying the SunOS 4.1.x tty jumbo patch (100513-04).
+
+Q: Screen compiled on SunOS 5.3 cannot reattach a detached session.
+
+A: You are using /usr/ucb/cc, this compiler is wrong. Actually it
+ links with a C-library that mis-interprets dirent. Try again
+ with /opt/SUNWspro/bin/cc!
+
+Q: The "talk" command does not work when Screen is active.
+
+A: Talk and several other programs rely on entries in the Utmp-
+ Database (/etc/utmp). On some systems this Database is world
+ writable, on others it is not. If it is not, screen must be
+ installed with the appropriate permissions (user or group s-bit)
+ just like any program that uses PTYs (rlogin, xterm, ...). When
+ screen cannot write to utmp, you will see messages on you display
+ which do not belong to any screen window.
+ When screen can update utmp, it is not guaranteed that it does as
+ you expect. First this depends on the config.h file defining
+ UTMPOK, LOGINDEFAULT, and perhaps CAREFULUTMP. Second it depends
+ on the screenrc files (system wide and per user), if utmp entries
+ are done. Third, you can control whether windows are logged in
+ with screens ``login'' command.
+
+Q: Seteuid() does not work as expected in AIX. Attempting a multi-
+ user-attach results in a screen-panic: "seteuid: not owner".
+
+A: This is not a screen problem. According to Kay Nettle
+ (pkn@cs.utexas.edu) you need the AIX patch PTF 423674.
+
+Q: When I type cd directory (any directory or just blank) from
+ within one of the windows in screen, the whole thing just freezes
+ up.
+
+A: You display the current working directory in xterm's title bar,
+ This may be caused by hardcoded ESC-sequences in the shell prompt
+ or in an cd alias. In Xterm the coding is
+ ESC ] n ; string_to_display ^G
+ where n = 1, 2, 3 selects the location of the displayed string.
+ Screen misinterprets this as the ansi operating system comment
+ sequence:
+ ESC ] osc_string
+ and waits (according to ansi) for the string terminator
+ ESC \
+ Screen versions after 3.5.12 may provide a workaround.
+
+Q: Mesg or biff cannot be turned on or off while running screen.
+
+A: Screen failed to change the owner of the pty it uses. You need to
+ install screen setuid-root. See the file INSTALL for details.
+
+Q: The cursor left key deletes the characters instead of just moving the
+ cursor. A redisplay (^Al) brings everything back.
+
+A: Your terminal emulator treats the backspace as "destructive". You
+ can probably change this somewhere in the setup. We can't think
+ of a reason why anybody would want a destructive backspace, but
+ if you really must have it, add the lines
+ termcap <TERM> 'bc@:bs@'
+ terminfo <TERM> 'bc@:bs@'
+ to your ~/.screenrc (replace <TERM> with the terminal type your
+ emulator uses).
+
+Q: I have an old SysV OS (like Motorola SysV68) and sometimes screen
+ doesn't reset the attributes correctly. A redisplay (^Al) doesn't
+ make things better.
+
+A: The libcurses library has a bug if attributes are cleared with
+ the special ue/se capabilities. As a workaround (other than upgrading
+ your system) modify 'rmul' (and 'rmso'?) in screen's terminfo entry:
+ rmul=\E[m, rmso=\E[m
diff --git a/doc/Makefile.in b/doc/Makefile.in
new file mode 100644
index 0000000..f7c7db7
--- /dev/null
+++ b/doc/Makefile.in
@@ -0,0 +1,62 @@
+# Makefile for Screen documentation
+
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+DESTDIR =
+
+prefix = @prefix@
+datarootdir = @datarootdir@
+mandir = @mandir@
+infodir = @infodir@
+
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+MAKEINFO = makeinfo
+TEXI2DVI = texi2dvi
+TEXI2PDF = texi2pdf
+
+SHELL = /bin/sh
+
+all: screen.info
+
+dvi screen.dvi: screen.texinfo mostlyclean
+ $(TEXI2DVI) $(srcdir)/screen.texinfo
+
+pdf screen.pdf: screen.texinfo mostlyclean
+ $(TEXI2PDF) $(srcdir)/screen.texinfo
+
+info screen.info: screen.texinfo
+ @rm -f screen.info*
+ $(MAKEINFO) $(srcdir)/screen.texinfo -o screen.info
+
+install: installdirs
+ $(INSTALL_DATA) $(srcdir)/screen.1 $(DESTDIR)$(mandir)/man1/screen.1
+ -$(MAKE) screen.info
+ -if test -f screen.info; then d=.; else d=$(srcdir); fi; \
+ if test -f $$d/screen.info; then \
+ for f in $$d/screen.info*; do $(INSTALL_DATA) $$f $(DESTDIR)$(infodir);done; \
+ if $(SHELL) -c 'install-info --version' >/dev/null 2>&1; then \
+ install-info --info-dir=$(DESTDIR)$(infodir) $$d/screen.info; \
+ else true; fi; \
+ fi
+
+uninstall:
+ rm -f $(DESTDIR)$(mandir)/man1/screen.1
+ rm -f $(DESTDIR)$(infodir)/screen.info*
+
+installdirs:
+ $(srcdir)/../etc/mkinstalldirs $(DESTDIR)$(mandir)/man1 $(DESTDIR)$(infodir)
+
+mostlyclean:
+ -rm -f *.cp *.cps *.fn *.fns *.ky *.kys *.pg *.tp *.vr
+ -rm -f *.log *.aux *.toc *~
+
+clean distclean clobber: mostlyclean
+ -rm -f *.dvi
+
+realclean: clean
+ -rm -f *.info*
+
+check installcheck:
+
diff --git a/doc/README.DOTSCREEN b/doc/README.DOTSCREEN
new file mode 100644
index 0000000..f17fa37
--- /dev/null
+++ b/doc/README.DOTSCREEN
@@ -0,0 +1,151 @@
+From bargi@dots.physics.orst.edu Thu Aug 31 23:42 MET 1995
+Received: from faui45.informatik.uni-erlangen.de (root@faui45.informatik.uni-erlangen.de [131.188.34.45]) by immd4.informatik.uni-erlangen.de with ESMTP
+ id XAA14775 (8.6.12/7.4f-FAU);; Thu, 31 Aug 1995 23:42:15 +0200
+Received: from dots.physics.orst.edu (bargi@dots.PHYSICS.ORST.EDU [128.193.96.106]) by uni-erlangen.de with ESMTP
+ id XAA03048 (8.6.12/7.4f-FAU); for <screen@uni-erlangen.de>; Thu, 31 Aug 1995 23:42:03 +0200
+Received: (from bargi@localhost) by dots.physics.orst.edu (8.6.11/8.6.9) id OAA15627; Thu, 31 Aug 1995 14:41:47 -0700
+From: Hadi Bargi Rangin <bargi@dots.physics.orst.edu>
+Message-Id: <199508312141.OAA15627@dots.physics.orst.edu>
+Subject: README.DOTSCREEN
+To: screen@uni-erlangen.de
+Date: Thu, 31 Aug 1995 14:41:47 -0700 (PDT)
+Cc: bargi@dots.physics.orst.edu (Hadi Bargi Rangin)
+X-Mailer: ELM [version 2.4 PL24]
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: text/plain; charset=US-ASCII
+Content-Length: 5423
+Status: RO
+
+Hallo,
+
+ leider war readme file fuer dotscreen nicht in unserem dotscreen-Packet,
+deshalb schicke ich es Euch nachtraeglich. Nachdem Ihr unseren packet
+getestet habt, koennen wir Euch anrufen und vielleicht mehr ueber die
+Einzelnheiten sprechen, ob wir unsere Weiterentwicklung koordinieren
+wollen.
+
+Danke,
+
+Gruss,
+Hadi
+
+===============================================================================
+Quick introduction to dotscreen
+-------------------------------
+
+1. Introduction
+2. Is dotscreen different as screen?
+3. Installation instructions
+4. Functions description
+5. Further development
+
+
+1. Introduction
+===============
+
+Dotscreen, is a system which allow a person direct access to unix via
+a braille display. The emphasis is on direct, because the braille
+display is connected directly to the serial port on the unix
+machine. You no longer must use a dos machine running a terminal
+emulation logged into a unix machine. Dotscreen is built on top of
+screen, a powerful full-screen window manager for unix tty terminals.
+Screen keeps track of what is being displayed in each window that it
+is managing so that it can easily switch back and forth between these
+windows. Dotscreen makes this stored window information available via
+a braille display. Dotscreen only allows access to tty terminal
+sessions, it does not allow access to X-Windows, however, it will run
+in an xterm window. Currently, it works with the TSI Navigator 40 and
+the TSI PowerBraille 40 braille displays. We plan to support other
+displays as demand and information about other displays is made
+available to us
+
+2. Is dotscreen different than screen?
+======================================
+
+All of screens functions still work in dotscreen. A few of the
+functions are not accessible via braille, but we expect to remedy that
+in future releases.
+
+3. Installation instructions
+============================
+
+Please read the INSTALL file for full installation instructions.
+In addition to those instructions, note that you must create
+a .screenrc file and that file must contain the type of braille
+display that you are using and the serial device that the display
+is connected to. A minimal .screenrc file should contain something
+like the following four lines, (these are only examples, please
+customize them for your configuration)
+
+
+# example of .screenrc when using braille display
+bd_start_braille on
+bd_type powerbraille_40
+bd_port /dev/ttyS0
+bd_braille_table /home/gardner/us-braille.tbl
+# end of example
+
+
+4. Functions description
+========================
+
+The basic operation of screen is described in README. The braille
+navigation commands are similar to commands usually found on dos
+braille screenreaders. Also, because dotscreen is built on top of
+screen, the user can switch back and forth easily between many running
+applications. The braille commands can be changed any time after
+starting screen using the internal screen "C-a :" command line. All
+braille commands begin with "bd_"; following is the list of braille
+commands:
+
+bd_start_braille on/off # Starts/stops using braille features on screen
+bd_link on/off # links/unlinks braille cursor to/from screen cursor
+bd_bell on/off # turn on/off sending bell-signal to terminal
+bd_scroll on/off # enables/disables scrolling
+bd_skip on/off # skip/don't skip balnk lines
+bd_width <integer-value> # number of braille cells that user want to use,
+ # this value is always <= total number of cells
+bd_ncrc <interger-value> # number of cells displayed on the right side
+ # of physical cursor (default = 1)
+bd_info <integer-value> # displays braille/screen cursor position
+ # depending on its value, (no info: 0, only
+ # bc-info: 1, only sc-info: 2, bc- and sc-info: 3
+bd_port <serial-device> # serial port which braille display is connected to
+bd_braille_table <bl-table> # braille table to be used. German, US and GS
+ # braille tables are provided
+bd_type <braille-display-type>
+ # braille display type being used
+
+Note: currently valid value for some parameters:
+bd_type:
+ 1. navigator_40
+ 2. powerbraille_40.
+
+bd_braille_table:
+ 1. gr-braille.tbl German braille code
+ 2. us-braille.tbl US computer braille code
+ 3. gs-braille.tbl GS braille code
+
+Since the braille tables are in files, you should give the full
+pathnames of the files either in .screenrc or using the
+internal screen "C-a :" command line.
+
+5. Further development
+======================
+
+As mentioned above, currently Dotscreen works with Telesensory braille
+displays the PowerBraille and the Navigator because Telesensory has
+given us the information needed to program their braille display. We
+plan to add support for other braille displays when and if we get the
+requisite information from the braille display manufacturer.
+Also some things such as cursor navigation from the braille display
+have not been implemented. If you find a feature missing that
+you wish to have, please contact us.
+
+This software has been developed within the Science Access Project at
+Oregon State University under the direction of John Gardner.
+
+Authors: Hadi Bargi Rangin (bargi@dots.physics.orst.edu)
+ Bill Barry (barryb@dots.physics.orst.edu)
+
diff --git a/doc/fdpat.ps b/doc/fdpat.ps
new file mode 100644
index 0000000..6b10099
--- /dev/null
+++ b/doc/fdpat.ps
@@ -0,0 +1,6501 @@
+%!PS-Adobe-2.0 EPSF-1.2
+%%DocumentFonts: Courier Helvetica-Bold Times-Roman
+%%Pages: 1
+%%BoundingBox: 5 34 589 773
+%%EndComments
+
+/arrowHeight 10 def
+/arrowWidth 5 def
+
+/IdrawDict 53 dict def
+IdrawDict begin
+
+/reencodeISO {
+dup dup findfont dup length dict begin
+{ 1 index /FID ne { def }{ pop pop } ifelse } forall
+/Encoding ISOLatin1Encoding def
+currentdict end definefont
+} def
+
+/ISOLatin1Encoding [
+/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright
+/parenleft/parenright/asterisk/plus/comma/minus/period/slash
+/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon
+/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N
+/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright
+/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m
+/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde
+/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve
+/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut
+/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar
+/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot
+/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior
+/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine
+/guillemotright/onequarter/onehalf/threequarters/questiondown
+/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla
+/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex
+/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis
+/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute
+/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis
+/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave
+/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex
+/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis
+/yacute/thorn/ydieresis
+] def
+/Courier reencodeISO def
+/Helvetica-Bold reencodeISO def
+/Times-Roman reencodeISO def
+
+/none null def
+/numGraphicParameters 17 def
+/stringLimit 65535 def
+
+/Begin {
+save
+numGraphicParameters dict begin
+} def
+
+/End {
+end
+restore
+} def
+
+/SetB {
+dup type /nulltype eq {
+pop
+false /brushRightArrow idef
+false /brushLeftArrow idef
+true /brushNone idef
+} {
+/brushDashOffset idef
+/brushDashArray idef
+0 ne /brushRightArrow idef
+0 ne /brushLeftArrow idef
+/brushWidth idef
+false /brushNone idef
+} ifelse
+} def
+
+/SetCFg {
+/fgblue idef
+/fggreen idef
+/fgred idef
+} def
+
+/SetCBg {
+/bgblue idef
+/bggreen idef
+/bgred idef
+} def
+
+/SetF {
+/printSize idef
+/printFont idef
+} def
+
+/SetP {
+dup type /nulltype eq {
+pop true /patternNone idef
+} {
+dup -1 eq {
+/patternGrayLevel idef
+/patternString idef
+} {
+/patternGrayLevel idef
+} ifelse
+false /patternNone idef
+} ifelse
+} def
+
+/BSpl {
+0 begin
+storexyn
+newpath
+n 1 gt {
+0 0 0 0 0 0 1 1 true subspline
+n 2 gt {
+0 0 0 0 1 1 2 2 false subspline
+1 1 n 3 sub {
+/i exch def
+i 1 sub dup i dup i 1 add dup i 2 add dup false subspline
+} for
+n 3 sub dup n 2 sub dup n 1 sub dup 2 copy false subspline
+} if
+n 2 sub dup n 1 sub dup 2 copy 2 copy false subspline
+patternNone not brushLeftArrow not brushRightArrow not and and { ifill } if
+brushNone not { istroke } if
+0 0 1 1 leftarrow
+n 2 sub dup n 1 sub dup rightarrow
+} if
+end
+} dup 0 4 dict put def
+
+/Circ {
+newpath
+0 360 arc
+patternNone not { ifill } if
+brushNone not { istroke } if
+} def
+
+/CBSpl {
+0 begin
+dup 2 gt {
+storexyn
+newpath
+n 1 sub dup 0 0 1 1 2 2 true subspline
+1 1 n 3 sub {
+/i exch def
+i 1 sub dup i dup i 1 add dup i 2 add dup false subspline
+} for
+n 3 sub dup n 2 sub dup n 1 sub dup 0 0 false subspline
+n 2 sub dup n 1 sub dup 0 0 1 1 false subspline
+patternNone not { ifill } if
+brushNone not { istroke } if
+} {
+Poly
+} ifelse
+end
+} dup 0 4 dict put def
+
+/Elli {
+0 begin
+newpath
+4 2 roll
+translate
+scale
+0 0 1 0 360 arc
+patternNone not { ifill } if
+brushNone not { istroke } if
+end
+} dup 0 1 dict put def
+
+/Line {
+0 begin
+2 storexyn
+newpath
+x 0 get y 0 get moveto
+x 1 get y 1 get lineto
+brushNone not { istroke } if
+0 0 1 1 leftarrow
+0 0 1 1 rightarrow
+end
+} dup 0 4 dict put def
+
+/MLine {
+0 begin
+storexyn
+newpath
+n 1 gt {
+x 0 get y 0 get moveto
+1 1 n 1 sub {
+/i exch def
+x i get y i get lineto
+} for
+patternNone not brushLeftArrow not brushRightArrow not and and { ifill } if
+brushNone not { istroke } if
+0 0 1 1 leftarrow
+n 2 sub dup n 1 sub dup rightarrow
+} if
+end
+} dup 0 4 dict put def
+
+/Poly {
+3 1 roll
+newpath
+moveto
+-1 add
+{ lineto } repeat
+closepath
+patternNone not { ifill } if
+brushNone not { istroke } if
+} def
+
+/Rect {
+0 begin
+/t exch def
+/r exch def
+/b exch def
+/l exch def
+newpath
+l b moveto
+l t lineto
+r t lineto
+r b lineto
+closepath
+patternNone not { ifill } if
+brushNone not { istroke } if
+end
+} dup 0 4 dict put def
+
+/Text {
+ishow
+} def
+
+/idef {
+dup where { pop pop pop } { exch def } ifelse
+} def
+
+/ifill {
+0 begin
+gsave
+patternGrayLevel -1 ne {
+fgred bgred fgred sub patternGrayLevel mul add
+fggreen bggreen fggreen sub patternGrayLevel mul add
+fgblue bgblue fgblue sub patternGrayLevel mul add setrgbcolor
+eofill
+} {
+eoclip
+originalCTM setmatrix
+pathbbox /t exch def /r exch def /b exch def /l exch def
+/w r l sub ceiling cvi def
+/h t b sub ceiling cvi def
+/imageByteWidth w 8 div ceiling cvi def
+/imageHeight h def
+bgred bggreen bgblue setrgbcolor
+eofill
+fgred fggreen fgblue setrgbcolor
+w 0 gt h 0 gt and {
+l b translate w h scale
+w h true [w 0 0 h neg 0 h] { patternproc } imagemask
+} if
+} ifelse
+grestore
+end
+} dup 0 8 dict put def
+
+/istroke {
+gsave
+brushDashOffset -1 eq {
+[] 0 setdash
+1 setgray
+} {
+brushDashArray brushDashOffset setdash
+fgred fggreen fgblue setrgbcolor
+} ifelse
+brushWidth setlinewidth
+originalCTM setmatrix
+stroke
+grestore
+} def
+
+/ishow {
+0 begin
+gsave
+fgred fggreen fgblue setrgbcolor
+printFont printSize scalefont setfont
+/descender 0 printFont /FontBBox get 1 get printFont /FontMatrix
+get transform exch pop def
+/vertoffset 1 printSize sub descender sub def {
+0 vertoffset moveto show
+/vertoffset vertoffset printSize sub def
+} forall
+grestore
+end
+} dup 0 2 dict put def
+
+/patternproc {
+0 begin
+/patternByteLength patternString length def
+/patternHeight patternByteLength 8 mul sqrt cvi def
+/patternWidth patternHeight def
+/patternByteWidth patternWidth 8 idiv def
+/imageByteMaxLength imageByteWidth imageHeight mul
+stringLimit patternByteWidth sub min def
+/imageMaxHeight imageByteMaxLength imageByteWidth idiv patternHeight idiv
+patternHeight mul patternHeight max def
+/imageHeight imageHeight imageMaxHeight sub store
+/imageString imageByteWidth imageMaxHeight mul patternByteWidth add string def
+0 1 imageMaxHeight 1 sub {
+/y exch def
+/patternRow y patternByteWidth mul patternByteLength mod def
+/patternRowString patternString patternRow patternByteWidth getinterval def
+/imageRow y imageByteWidth mul def
+0 patternByteWidth imageByteWidth 1 sub {
+/x exch def
+imageString imageRow x add patternRowString putinterval
+} for
+} for
+imageString
+end
+} dup 0 12 dict put def
+
+/min {
+dup 3 2 roll dup 4 3 roll lt { exch } if pop
+} def
+
+/max {
+dup 3 2 roll dup 4 3 roll gt { exch } if pop
+} def
+
+/midpoint {
+0 begin
+/y1 exch def
+/x1 exch def
+/y0 exch def
+/x0 exch def
+x0 x1 add 2 div
+y0 y1 add 2 div
+end
+} dup 0 4 dict put def
+
+/thirdpoint {
+0 begin
+/y1 exch def
+/x1 exch def
+/y0 exch def
+/x0 exch def
+x0 2 mul x1 add 3 div
+y0 2 mul y1 add 3 div
+end
+} dup 0 4 dict put def
+
+/subspline {
+0 begin
+/movetoNeeded exch def
+y exch get /y3 exch def
+x exch get /x3 exch def
+y exch get /y2 exch def
+x exch get /x2 exch def
+y exch get /y1 exch def
+x exch get /x1 exch def
+y exch get /y0 exch def
+x exch get /x0 exch def
+x1 y1 x2 y2 thirdpoint
+/p1y exch def
+/p1x exch def
+x2 y2 x1 y1 thirdpoint
+/p2y exch def
+/p2x exch def
+x1 y1 x0 y0 thirdpoint
+p1x p1y midpoint
+/p0y exch def
+/p0x exch def
+x2 y2 x3 y3 thirdpoint
+p2x p2y midpoint
+/p3y exch def
+/p3x exch def
+movetoNeeded { p0x p0y moveto } if
+p1x p1y p2x p2y p3x p3y curveto
+end
+} dup 0 17 dict put def
+
+/storexyn {
+/n exch def
+/y n array def
+/x n array def
+n 1 sub -1 0 {
+/i exch def
+y i 3 2 roll put
+x i 3 2 roll put
+} for
+} def
+
+%%EndProlog
+
+%%BeginIdrawPrologue
+/arrowhead {
+0 begin
+transform originalCTM itransform
+/taily exch def
+/tailx exch def
+transform originalCTM itransform
+/tipy exch def
+/tipx exch def
+/dy tipy taily sub def
+/dx tipx tailx sub def
+/angle dx 0 ne dy 0 ne or { dy dx atan } { 90 } ifelse def
+gsave
+originalCTM setmatrix
+tipx tipy translate
+angle rotate
+newpath
+arrowHeight neg arrowWidth 2 div moveto
+0 0 lineto
+arrowHeight neg arrowWidth 2 div neg lineto
+patternNone not {
+originalCTM setmatrix
+/padtip arrowHeight 2 exp 0.25 arrowWidth 2 exp mul add sqrt brushWidth mul
+arrowWidth div def
+/padtail brushWidth 2 div def
+tipx tipy translate
+angle rotate
+padtip 0 translate
+arrowHeight padtip add padtail add arrowHeight div dup scale
+arrowheadpath
+ifill
+} if
+brushNone not {
+originalCTM setmatrix
+tipx tipy translate
+angle rotate
+arrowheadpath
+istroke
+} if
+grestore
+end
+} dup 0 9 dict put def
+
+/arrowheadpath {
+newpath
+arrowHeight neg arrowWidth 2 div moveto
+0 0 lineto
+arrowHeight neg arrowWidth 2 div neg lineto
+} def
+
+/leftarrow {
+0 begin
+y exch get /taily exch def
+x exch get /tailx exch def
+y exch get /tipy exch def
+x exch get /tipx exch def
+brushLeftArrow { tipx tipy tailx taily arrowhead } if
+end
+} dup 0 4 dict put def
+
+/rightarrow {
+0 begin
+y exch get /tipy exch def
+x exch get /tipx exch def
+y exch get /taily exch def
+x exch get /tailx exch def
+brushRightArrow { tipx tipy tailx taily arrowhead } if
+end
+} dup 0 4 dict put def
+
+%%EndIdrawPrologue
+
+%I Idraw 10 Grid 8.86154 8.86154
+
+%%Page: 1 1
+
+Begin
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ .959646 0 0 .959646 0 0 ] concat
+/originalCTM matrix currentmatrix def
+
+Begin %I Line
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ .833333 -0 -0 .833333 -23.3333 378.333 ] concat
+%I
+37 397 764 397 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ .833333 -0 -0 .833333 -23.3333 282.5 ] concat
+%I
+37 397 764 397 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ .833333 -0 -0 .833333 -24.1667 185.833 ] concat
+%I
+37 397 764 397 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -5.83331 ] concat
+%I
+37 397 764 397 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -101.667 ] concat
+%I
+37 397 764 397 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -197.5 ] concat
+%I
+37 397 764 397 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ .833333 -0 -0 .833333 -23.3333 392.5 ] concat
+%I
+37 34 764 34 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ .833333 -0 -0 .833333 -15.8333 2.5 ] concat
+%I
+258 963 258 41 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ .833333 -0 -0 .833333 198.833 3 ] concat
+%I
+258 963 258 41 Line
+%I 1
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 213.667 797 ] concat
+%I
+[
+(Subshell, error back)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 428 797 ] concat
+%I
+[
+(Input echo filter)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 22.8333 704.333 ] concat
+%I
+[
+(Input filter)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 214.833 704.333 ] concat
+%I
+[
+(Input Filter, error back)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 428.833 704.333 ] concat
+%I
+[
+(input filter, error echo)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 214 607.5 ] concat
+%I
+[
+(Output filter)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 428 607.5 ] concat
+%I
+[
+(Error robot)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 15 729.966 ] concat
+%I
+[
+(...)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 15 57.4667 ] concat
+%I
+[
+(...)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 214.167 57.4667 ] concat
+%I
+[
+(...)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 428.333 57.4667 ] concat
+%I
+[
+(...)
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190.833 45.8332 ] concat
+%I 5
+161 743
+179 743
+205 743
+205 716
+205 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 45.8332 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190.833 45.8332 ] concat
+%I 2
+55 743
+143 743
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -50.0001 ] concat
+%I 5
+196 707
+196 716
+196 734
+179 734
+161 734
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -50.0001 ] concat
+%I 5
+161 743
+179 743
+205 743
+205 716
+205 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -57.5001 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -50.0001 ] concat
+%I 2
+55 743
+143 743
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -50.0001 ] concat
+%I 2
+143 734
+55 734
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -50.0001 ] concat
+%I 5
+489 760
+471 760
+462 760
+462 752
+462 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 5
+188 707
+188 716
+188 725
+179 725
+161 725
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 5
+196 707
+196 716
+196 734
+179 734
+161 734
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 5
+161 743
+179 743
+205 743
+205 716
+205 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 134.167 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 2
+55 743
+143 743
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 2
+143 734
+55 734
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -145.833 ] concat
+%I 5
+188 707
+188 716
+188 725
+179 725
+161 725
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -153.333 ] concat
+%I 2
+143 734
+55 734
+2 BSpl
+%I 1
+End
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 0 -671.666 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 -214.167 -671.666 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 199.166 -671.666 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 5
+444 707
+444 760
+444 778
+471 778
+489 778
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190.833 141.667 ] concat
+%I 5
+196 707
+196 716
+196 734
+179 734
+161 734
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190.833 141.667 ] concat
+%I 5
+161 743
+179 743
+205 743
+205 716
+205 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190.833 134.167 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190.833 141.667 ] concat
+%I 2
+55 743
+143 743
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190.833 141.667 ] concat
+%I 2
+143 734
+55 734
+2 BSpl
+%I 1
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 428.333 729.966 ] concat
+%I
+[
+(..: .:. .::)
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 45.8332 ] concat
+%I 2
+55 743
+143 743
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190.833 30.8334 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 45 ] concat
+%I 5
+444 707
+444 760
+444 778
+471 778
+489 778
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 141.667 ] concat
+%I 5
+196 707
+196 716
+196 734
+179 734
+161 734
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 141.667 ] concat
+%I 5
+161 743
+179 743
+205 743
+205 716
+205 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 141.667 ] concat
+%I 2
+55 743
+143 743
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 141.667 ] concat
+%I 2
+143 734
+55 734
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 134.167 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 175.833 237.5 ] concat
+%I 6
+400 619
+391 619
+365 619
+365 645
+391 645
+489 645
+6 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 141.667 ] concat
+%I 5
+188 707
+188 716
+188 725
+179 725
+161 725
+5 BSpl
+%I 1
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 15 633.3 ] concat
+%I
+[
+(.!.)
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 45.8333 ] concat
+%I 5
+188 707
+188 716
+188 725
+179 725
+161 725
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 38.3334 ] concat
+%I 2
+143 734
+55 734
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -237.5 45.8332 ] concat
+%I 5
+453 707
+453 752
+453 769
+471 769
+489 769
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 45.8333 ] concat
+%I 5
+161 743
+179 743
+205 743
+205 716
+205 707
+5 BSpl
+%I 1
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 214.167 633.3 ] concat
+%I
+[
+(.!!)
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 45.8332 ] concat
+%I 5
+453 707
+453 752
+453 769
+471 769
+489 769
+5 BSpl
+%I 1
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 214.167 729.966 ] concat
+%I
+[
+(..!)
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 45.8332 ] concat
+%I 5
+161 743
+179 743
+205 743
+205 716
+205 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 45.8332 ] concat
+%I 2
+55 743
+143 743
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 45.8334 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 175.833 45.8332 ] concat
+%I 5
+453 707
+453 752
+453 769
+471 769
+489 769
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 175.833 141.667 ] concat
+%I 6
+400 619
+391 619
+365 619
+365 645
+391 645
+489 645
+6 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 45.8333 ] concat
+%I 2
+143 734
+55 734
+2 BSpl
+%I 1
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 428.333 633.3 ] concat
+%I
+[
+(.!:)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 15 537.466 ] concat
+%I
+[
+(.:!)
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -236.667 -50.8333 ] concat
+%I 5
+444 707
+444 760
+444 778
+471 778
+489 778
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -237.5 45.8333 ] concat
+%I 6
+400 619
+391 619
+365 619
+365 645
+391 645
+489 645
+6 BSpl
+%I 1
+End
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t u
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 -214.167 6.10352e-05 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 199.166 7.62939e-05 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 0 -95.8334 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 -214.167 -95.8333 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 199.166 -95.8333 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 214.167 537.466 ] concat
+%I
+[
+(!..)
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 189.167 -50 ] concat
+%I 5
+188 707
+188 716
+188 725
+179 725
+161 725
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 1 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190.833 -57.5 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190.833 -50.8333 ] concat
+%I 2
+143 734
+55 734
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 175.833 -50.0001 ] concat
+%I 5
+489 760
+471 760
+462 760
+462 752
+462 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 -50 ] concat
+%I 5
+196 707
+196 716
+196 734
+179 734
+161 734
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 1 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 -57.5 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 -50.8333 ] concat
+%I 2
+143 734
+55 734
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 176.667 -50 ] concat
+%I 5
+444 707
+444 760
+444 778
+471 778
+489 778
+5 BSpl
+%I 1
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 428.333 537.466 ] concat
+%I
+[
+(!.!)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 22 607.5 ] concat
+%I
+[
+(Input echo filter, error back)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 21.1667 510.833 ] concat
+%I
+[
+(Robot)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 15 441.633 ] concat
+%I
+[
+(!!.)
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -237.5 -145.833 ] concat
+%I 5
+489 760
+471 760
+462 760
+462 752
+462 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -237.5 -145.833 ] concat
+%I 5
+453 707
+453 752
+453 769
+471 769
+489 769
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -145.833 ] concat
+%I 5
+489 760
+471 760
+462 760
+462 752
+462 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -145.833 ] concat
+%I 5
+453 707
+453 752
+453 769
+471 769
+489 769
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -145.833 ] concat
+%I 5
+444 707
+444 760
+444 778
+471 778
+489 778
+5 BSpl
+%I 1
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 214.167 441.633 ] concat
+%I
+[
+(!!!)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 427.167 510.833 ] concat
+%I
+[
+(Full robot, error echo)
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 175.833 -145.833 ] concat
+%I 5
+489 760
+471 760
+462 760
+462 752
+462 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 175.833 -145.833 ] concat
+%I 5
+453 707
+453 752
+453 769
+471 769
+489 769
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 -146.667 ] concat
+%I 2
+143 734
+55 734
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 6
+639 388
+630 388
+586 388
+586 433
+631 433
+728 433
+6 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 5
+684 361
+684 379
+684 388
+675 388
+657 388
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 334.167 ] concat
+%I 5
+684 361
+684 379
+684 388
+675 388
+657 388
+5 BSpl
+%I 1
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 428.333 441.633 ] concat
+%I
+[
+(!!:)
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -237.5 -241.667 ] concat
+%I 5
+489 760
+471 760
+462 760
+462 752
+462 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -242.5 ] concat
+%I 2
+143 734
+55 734
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 6
+143 273
+134 273
+99 273
+99 309
+134 309
+232 309
+6 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -242.5 ] concat
+%I 5
+196 707
+196 716
+196 734
+179 734
+161 734
+5 BSpl
+%I 1
+End
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 -214.167 -191.667 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 0 -191.667 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 199.166 -191.667 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 15 345.8 ] concat
+%I
+[
+(!:!)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 213.167 510.833 ] concat
+%I
+[
+(Full robot)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 214.167 345.8 ] concat
+%I
+[
+(!:: !:. !.:)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 213.167 415 ] concat
+%I
+[
+(Full robot, out & error echo)
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -241.667 ] concat
+%I 5
+489 760
+471 760
+462 760
+462 752
+462 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190.833 -242.5 ] concat
+%I 2
+143 734
+55 734
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190.833 141.667 ] concat
+%I 6
+143 273
+134 273
+99 273
+99 309
+134 309
+232 309
+6 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190.833 -242.5 ] concat
+%I 5
+196 707
+196 716
+196 734
+179 734
+161 734
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -38.3333 -4.16667 ] concat
+%I 5
+471 652
+471 661
+471 679
+454 679
+436 679
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 189.167 -242.5 ] concat
+%I 5
+188 707
+188 716
+188 725
+179 725
+161 725
+5 BSpl
+%I 1
+End
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 199.166 -287.5 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 0 -287.5 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 -214.167 -287.5 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 428.333 345.8 ] concat
+%I
+[
+(:..)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 427.167 415 ] concat
+%I
+[
+(Output echo filter)
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 -242.5 ] concat
+%I 5
+188 707
+188 716
+188 725
+179 725
+161 725
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 -242.5 ] concat
+%I 5
+196 707
+196 716
+196 734
+179 734
+161 734
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 -242.5 ] concat
+%I 5
+161 743
+179 743
+205 743
+205 716
+205 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 1 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 -242.5 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 -249.167 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 -242.5 ] concat
+%I 2
+143 734
+55 734
+2 BSpl
+%I 1
+End
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 199.166 -383.333 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 0 -383.333 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 -214.167 -383.333 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -38.3333 -4.16667 ] concat
+%I 6
+657 484
+649 484
+622 484
+622 457
+649 457
+657 457
+6 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -339.167 ] concat
+%I 5
+196 707
+196 716
+196 734
+179 734
+161 734
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -339.167 ] concat
+%I 5
+161 743
+179 743
+205 743
+205 716
+205 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -345.833 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -339.167 ] concat
+%I 2
+143 734
+55 734
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -451.667 -100.833 ] concat
+%I 6
+657 484
+649 484
+622 484
+622 457
+649 457
+657 457
+6 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -236.667 -338.333 ] concat
+%I 5
+444 707
+444 752
+444 778
+471 778
+489 778
+5 BSpl
+%I 1
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 21.1667 415 ] concat
+%I
+[
+(Full Robot, output echo)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 21.1667 319.167 ] concat
+%I
+[
+(Output echo filter, error back)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 15 249.967 ] concat
+%I
+[
+(:.!)
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190 -339.167 ] concat
+%I 5
+196 707
+196 716
+196 734
+179 734
+161 734
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190 -339.167 ] concat
+%I 5
+161 743
+179 743
+205 743
+205 716
+205 707
+5 BSpl
+%I 1
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 427.167 319.167 ] concat
+%I
+[
+(Robot, input echo)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 21.1667 223.333 ] concat
+%I
+[
+(Full robot, input echo)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 427.167 223.333 ] concat
+%I
+[
+(Full robot, input & output echo)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 213.167 223.333 ] concat
+%I
+[
+(Full robot, input & error echo)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 213.167 319.167 ] concat
+%I
+[
+(Full robot, full echo)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 214.167 249.967 ] concat
+%I
+[
+(::: ::. :.:)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 428.333 249.967 ] concat
+%I
+[
+(:!.)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 15 154.133 ] concat
+%I
+[
+(:!!)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 214.167 154.133 ] concat
+%I
+[
+(:!:)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-helvetica-bold-r-*-140-*
+Helvetica-Bold 14 SetF
+%I t
+[ 1.6 0 0 1.6 428.333 154.133 ] concat
+%I
+[
+(::!)
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190 -338.333 ] concat
+%I 5
+188 707
+188 716
+188 725
+179 725
+161 725
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -15.8333 .833333 ] concat
+%I 6
+391 353
+382 353
+365 353
+365 336
+382 336
+391 336
+6 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 .833333 ] concat
+%I 6
+400 327
+391 327
+356 327
+356 363
+391 363
+489 362
+6 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 .833364 ] concat
+%I 2
+489 353
+312 353
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 .833364 ] concat
+%I 2
+400 327
+312 327
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 -339.167 ] concat
+%I 5
+161 743
+179 743
+205 743
+205 716
+205 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 -338.333 ] concat
+%I 5
+188 707
+188 716
+188 725
+179 725
+161 725
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 184.167 .833333 ] concat
+%I 6
+391 353
+382 353
+365 353
+365 336
+382 336
+391 336
+6 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 176.667 .833364 ] concat
+%I 2
+489 353
+312 353
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 175.833 -337.5 ] concat
+%I 5
+453 707
+453 752
+453 769
+471 769
+489 769
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 -345.833 ] concat
+%I 2
+143 734
+55 734
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -435 ] concat
+%I 5
+161 743
+179 743
+205 743
+205 716
+205 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -229.167 -95 ] concat
+%I 6
+391 353
+382 353
+365 353
+365 336
+382 336
+391 336
+6 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -236.667 -94.9999 ] concat
+%I 2
+489 353
+312 353
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -237.5 -433.333 ] concat
+%I 5
+453 707
+453 752
+453 769
+471 769
+489 769
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3332 -441.667 ] concat
+%I 2
+143 734
+55 734
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -236.667 -434.166 ] concat
+%I 5
+444 707
+444 752
+444 778
+471 778
+489 778
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190 -435 ] concat
+%I 5
+161 743
+179 743
+205 743
+205 716
+205 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190 -434.167 ] concat
+%I 5
+188 707
+188 716
+188 725
+179 725
+161 725
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -15.8333 -95 ] concat
+%I 6
+391 353
+382 353
+365 353
+365 336
+382 336
+391 336
+6 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -94.9999 ] concat
+%I 2
+489 353
+312 353
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 -94.9999 ] concat
+%I 2
+400 327
+312 327
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -24.1669 -434.166 ] concat
+%I 5
+453 707
+453 752
+453 769
+471 769
+489 769
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 .833333 ] concat
+%I 5
+188 415
+188 460
+188 486
+214 486
+233 486
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 1 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190.833 -338.333 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 1 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190.833 -242.5 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 1 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3332 -145.833 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 1 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3332 -353.333 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 1 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 -338.333 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 1 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3332 -434.167 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 1 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3332 -249.167 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 1 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 190.833 -145.833 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 1 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390.833 -145.833 ] concat
+%I 2
+232 778
+55 778
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 389.167 -435 ] concat
+%I 5
+161 743
+179 743
+205 743
+205 716
+205 707
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 183.333 -95 ] concat
+%I 6
+391 353
+382 353
+365 353
+365 336
+382 336
+391 336
+6 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 175.833 -94.9999 ] concat
+%I 2
+489 353
+312 353
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 175.833 -94.9999 ] concat
+%I 2
+400 327
+312 327
+2 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 390 -434.167 ] concat
+%I 5
+196 707
+196 716
+196 734
+179 734
+161 734
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 176.667 -434.167 ] concat
+%I 5
+444 707
+444 760
+444 778
+471 778
+489 778
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 1 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 .833333 ] concat
+%I 2
+728 247
+551 247
+2 BSpl
+%I 1
+End
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 -214.167 -480 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 0 -480 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 199.166 -480 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 199.166 -575.833 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 -0.000432014 -575.833 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 -214.167 -575.833 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 214.167 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+143 716
+161 716
+161 752
+143 752
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 99.8333 758.833 ] concat
+%I
+[
+(P)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 221.667 -0.000366211 ] concat
+
+Begin %I Poly
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 -23.3333 141.667 ] concat
+%I 4
+223 752
+241 752
+241 787
+223 787
+4 Poly
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 164 788.416 ] concat
+%I
+[
+(W)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f *-times-medium-r-*-140-*
+Times-Roman 14 SetF
+%I t
+[ 1 0 0 1 344.333 725.833 ] concat
+%I
+[
+(210)
+] Text
+End
+
+End %I eop
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 125 181.667 ] concat
+%I 6
+222 -5
+213 -5
+169 -5
+169 39
+240 39
+311 39
+6 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 1 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ .833333 -0 -0 .833333 125 181.667 ] concat
+%I 2
+222 39
+134 39
+2 BSpl
+%I 1
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-8-*-*-*-*-*-*-*
+Courier 8 SetF
+%I t
+[ 1 0 0 1 22 797 ] concat
+%I
+[
+(Subshell)
+] Text
+End
+
+End %I eop
+
+showpage
+
+%%Trailer
+
+end
diff --git a/doc/install.sh b/doc/install.sh
new file mode 120000
index 0000000..3f44f99
--- /dev/null
+++ b/doc/install.sh
@@ -0,0 +1 @@
+../install.sh \ No newline at end of file
diff --git a/doc/make.help b/doc/make.help
new file mode 100644
index 0000000..5871773
--- /dev/null
+++ b/doc/make.help
@@ -0,0 +1,51 @@
+######
+######
+###### The following lines should be obsolete because of the 'configure' script.
+###### It is here only for reference if 'configure' needs human help.
+######
+
+
+### If you choose to compile with the tried and true:
+#CC= cc
+#CFLAGS= -O
+#CFLAGS= -g
+### gcc specific CFLAGS:
+#CC= gcc
+# If your system include files are bad, don't use -Wall
+#CFLAGS= -O6 -g #-Wall
+#CFLAGS = -g -fstrength-reduce -fcombine-regs -finline-functions #-Wall
+
+### On some machines special CFLAGS are required:
+#M_CFLAGS=
+#M_CFLAGS= -D__NetBSD__ # NetBsd Machines like this (a.kalb@rrze)
+#M_CFLAGS= -Dapollo -A cpu,mathchip -A nansi # Apollo DN3000/4000/4500
+#M_CFLAGS= -DISC -D_POSIX_SOURCE # isc
+#M_CFLAGS= -systype bsd43 -DMIPS # mips
+#M_CFLAGS= -fforce-mem -fforce-addr\
+# -fomit-frame-pointer -finline-functions -bsd # NeXT
+#M_CFLAGS= -qlanglvl=ansi # RS6000/AIX
+#M_CFLAGS= -qlanglvl=ansi -D_AIX32 # RS6000/AIX 3.2
+#M_CFLAGS= -ansi # sgi/IRIX 3.x ansi
+#M_CFLAGS= -xansi # sgi/IRIX 4.x ext ansi
+#M_CFLAGS= -YBSD # Ultrix 4.x
+#M_CFLAGS= -DSVR4=1 # Bob Kline rvk@blink.att.com 80386 Unix SVR4.0
+#M_CFLAGS= -D_CX_UX # Ken Beal kbeal@amber.ssd.csd.harris.com Harris CX/UX
+#M_CFLAGS= -K pentium # Thanh Ma tma@encore.com Unixware, SVR4-2
+
+### Choose one of the LIBS setting below:
+#LIBS= -ltermcap -lc -lsocket -linet -lsec -lseq # Sequent/ptx
+#LIBS= -lcurses -lelf -lcrypt -lsocket -lnsl # Solaris, when it sucks
+#LIBS= -ltermcap # SunOS, Linux, Apollo,
+# gould_np1, NeXT, Ultrix
+#LIBS= -ltermcap -lelf # SVR4
+#LIBS= -ltermlib -linet -lcposix # isc
+#LIBS= -ltermcap -lmld # mips (nlist is in mld)
+#LIBS= -ltermlib -lsun -lmld #-lc_s # sgi/IRIX
+#LIBS= -lcurses # RS6000/AIX
+#LIBS= -lcrypt_d -ltinfo # sco32
+#LIBS= -lcrypt_i -ltinfo # sco32
+#LIBS= -lcrypt -lsec # sco322 (msilano@sra.com)
+#LIBS= -ltermcap -lcrypt.o -ldir -lx # SCO XENIX 2.3.4
+#LIBS= -ltermcap -lcrypt -ldir -l2.3 -lx # SCO UNIX XENIX cross dev.
+#LIBS= -ltermcap -lelf -lcrypt -lsocket -lnet -lnsl # Bob Kline SVR4
+#LIBS= -lcurses -lelf -lcrypt -lgen # Thanh Ma, Unixware, SVR4-2
diff --git a/doc/screen.1 b/doc/screen.1
new file mode 100644
index 0000000..29359e5
--- /dev/null
+++ b/doc/screen.1
@@ -0,0 +1,5273 @@
+.\" vi:set wm=5
+.TH SCREEN 1 "Oct 2017"
+.if n .ds Q \&"
+.if n .ds U \&"
+.if t .ds Q ``
+.if t .ds U ''
+.UC 4
+.SH NAME
+screen \- screen manager with VT100/ANSI terminal emulation
+
+
+.SH SYNOPSIS
+.B screen
+[
+.B \-\fIoptions\fP
+] [
+.B \fIcmd\fP
+[
+.B \fIargs\fP
+] ]
+.br
+.B screen \-r
+[[\fIpid\fP\fB.\fP]\fItty\fP[\fB.\fP\fIhost\fP]]
+.br
+.B screen \-r
+\fIsessionowner\fP\fB/\fP[[\fIpid\fP\fB.\fP]\fItty\fP[\fB.\fP\fIhost\fP]]
+.ta .5i 1.8i
+
+
+.SH DESCRIPTION
+.I Screen
+is a full-screen window manager that
+multiplexes a physical terminal between several processes (typically
+interactive shells).
+Each virtual terminal provides the functions
+of a DEC VT100 terminal and, in addition, several control functions
+from the ISO 6429 (ECMA 48, ANSI X3.64) and ISO 2022 standards
+(e.\|g. insert/delete line and support for multiple character sets).
+There is a scrollback history buffer for each virtual terminal and a
+copy-and-paste mechanism that allows moving text regions between
+windows.
+.PP
+When
+.I screen
+is called, it creates a single window with a shell in it (or the specified
+command) and then gets out of your way so that you can use the program as you
+normally would.
+Then, at any time, you can create new (full-screen) windows with other programs
+in them (including more shells), kill existing windows, view a list of
+windows, turn output logging on and off, copy-and-paste text between
+windows, view the scrollback history, switch between windows
+in whatever manner you wish, etc. All windows run their programs completely
+independent of each other. Programs continue to run when their window
+is currently not visible and even when the whole
+.I screen
+session is detached from the user's terminal. When a program terminates,
+.I screen
+(per default) kills the window that contained it.
+If this window was in the foreground, the display switches to the previous
+window; if none are left,
+.I screen
+exits. Shells usually distinguish between running as login-shell or sub-shell.
+Screen runs them as sub-shells, unless told otherwise (See \*Qshell\*U .screenrc command).
+.PP
+Everything you type is sent to the program running in the current window.
+The only exception to this is the one keystroke that is used to initiate
+a command to the window manager.
+By default, each command begins with a control-a (abbreviated C-a from
+now on), and is followed by one other keystroke.
+The command character and all the key bindings can be fully customized
+to be anything you like, though they are always two characters in length.
+.PP
+.I Screen
+does not understand the prefix \*QC-\*U to mean control, although this notation is
+used in this manual for readability.
+Please use the caret notation (\*Q^A\*U instead of \*QC-a\*U) as arguments
+to e.g. the
+.I escape
+command or the \fI-e\fP option.
+.I Screen
+will also print out control characters in caret notation.
+.PP
+The standard way to create a new window is to type \*QC-a c\*U.
+This creates a new window running a shell and switches to that
+window immediately, regardless of the state of the process running
+in the current window.
+Similarly, you can create a new window with a custom command in it by
+first binding the command to a keystroke (in your .screenrc file or at the
+\*QC-a :\*U command line) and
+then using it just like the \*QC-a c\*U command.
+In addition, new windows can be created by running a command like:
+.IP
+screen emacs prog.c
+.PP
+from a shell prompt within a previously created window.
+This will not run another copy of
+.IR screen ,
+but will instead supply the command name and its arguments to the window
+manager (specified in the $STY environment variable) who will use it to
+create the new window.
+The above example would start the emacs editor (editing prog.c) and switch
+to its window. - Note that you cannot transport environment variables from
+the invoking shell to the application (emacs in this case), because it is
+forked from the parent screen process, not from the invoking shell.
+.PP
+If \*Q/etc/utmp\*U is writable by
+.IR screen ,
+an appropriate record will be written to this file for each window, and
+removed when the window is terminated.
+This is useful for working with \*Qtalk\*U, \*Qscript\*U, \*Qshutdown\*U,
+\*Qrsend\*U, \*Qsccs\*U and other similar programs that use the utmp
+file to determine who you are. As long as
+.I screen
+is active on your terminal,
+the terminal's own record is removed from the utmp file. See also \*QC-a L\*U.
+
+
+.SH GETTING STARTED
+Before you begin to use
+.I screen
+you'll need to make sure you have correctly selected your terminal type,
+just as you would for any other termcap/terminfo program.
+(You can do this by using
+.IR tset
+for example.)
+.PP
+If you're impatient and want to get started without doing a lot more reading,
+you should remember this one command: \*QC-a ?\*U.
+Typing these two characters will display a list of the available
+.I screen
+commands and their bindings. Each keystroke is discussed in
+the section \*QDEFAULT KEY BINDINGS\*U. The manual section \*QCUSTOMIZATION\*U
+deals with the contents of your .screenrc.
+.PP
+If your terminal is a \*Qtrue\*U auto-margin terminal (it doesn't allow
+the last position on the screen to be updated without scrolling the
+screen) consider using a version of your terminal's termcap that has
+automatic margins turned \fIoff\fP. This will ensure an accurate and
+optimal update of the screen in all circumstances. Most terminals
+nowadays have \*Qmagic\*U margins (automatic margins plus usable last
+column). This is the VT100 style type and perfectly suited for
+.IR screen .
+If all you've got is a \*Qtrue\*U auto-margin terminal
+.I screen
+will be content to use it, but updating a character put into the last
+position on the screen may not be possible until the screen scrolls or
+the character is moved into a safe position in some other way. This
+delay can be shortened by using a terminal with insert-character
+capability.
+
+
+.SH "COMMAND-LINE OPTIONS"
+Screen has the following command-line options:
+.TP 5
+.B \-a
+include \fIall\fP capabilities (with some minor exceptions) in each
+window's termcap, even if
+.I screen
+must redraw parts of the display in order to implement a function.
+.TP 5
+.B \-A
+Adapt the sizes of all windows to the size of the current terminal.
+By default,
+.I screen
+tries to restore its old window sizes when attaching to resizable terminals
+(those with \*QWS\*U in its description, e.g. suncmd or some xterm).
+.TP 5
+.BI "\-c " file
+override the default configuration file from \*Q$HOME/.screenrc\*U
+to \fIfile\fP.
+.TP 5
+.BR \-d | \-D " [" \fIpid.tty.host ]
+does not start
+.IR screen ,
+but detaches the elsewhere running
+.I screen
+session. It has the same effect as typing \*QC-a d\*U from
+.IR screen 's
+controlling terminal. \fB\-D\fP is the equivalent to the power detach key.
+If no session can be detached, this option is ignored. In combination with the
+\fB\-r\fP/\fB\-R\fP option more powerful effects can be achieved:
+.TP 8
+.B \-d \-r
+Reattach a session and if necessary detach it first.
+.TP 8
+.B \-d \-R
+Reattach a session and if necessary detach or even create it first.
+.TP 8
+.B \-d \-RR
+Reattach a session and if necessary detach or create it. Use the first
+session if more than one session is available.
+.TP 8
+.B \-D \-r
+Reattach a session. If necessary detach and logout remotely first.
+.TP 8
+.B \-D \-R
+Attach here and now. In detail this means: If a session is running, then
+reattach. If necessary detach and logout remotely first.
+If it was not running create it and notify the user. This is the
+author's favorite.
+.TP 8
+.B \-D \-RR
+Attach here and now. Whatever that means, just do it.
+.IP "" 5
+Note: It is always a good idea to check the status of your sessions by means of
+\*Qscreen \-list\*U.
+.TP 5
+.BI "\-e " xy
+specifies the command character to be \fIx\fP and the character generating a
+literal command character to \fIy\fP (when typed after the command character).
+The default is \*QC-a\*U and `a', which can be specified as \*Q-e^Aa\*U.
+When creating a
+.I screen
+session, this option sets the default command character. In a multiuser
+session all users added will start off with this command character. But
+when attaching to an already running session, this option changes only
+the command character of the attaching user.
+This option is equivalent to either the commands \*Qdefescape\*U or
+\*Qescape\*U respectively.
+.TP 5
+.BR \-f\fP ", " \-fn ", and " \-fa
+turns flow-control on, off, or \*Qautomatic switching mode\*U.
+This can also be defined through the \*Qdefflow\*U .screenrc command.
+.TP 5
+.BI "\-h " num
+Specifies the history scrollback buffer to be \fInum\fP lines high.
+.TP 5
+.B \-i
+will cause the interrupt key (usually C-c) to interrupt the display
+immediately when flow-control is on.
+See the \*Qdefflow\*U .screenrc command for details.
+The use of this option is discouraged.
+.TP 5
+.BR \-l " and " \-ln
+turns login mode on or off (for /etc/utmp updating).
+This can also be defined through the \*Qdeflogin\*U .screenrc command.
+.TP 5
+.BR \-ls " [" \fImatch ]
+.PD 0
+.TP 5
+.BR \-list " [" \fImatch ]
+.PD
+does not start
+.IR screen ,
+but prints a list of
+.I pid.tty.host
+strings identifying your
+.I screen
+sessions.
+Sessions marked `detached' can be resumed with \*Qscreen \-r\*U. Those marked
+`attached' are running and have a controlling terminal. If the session runs in
+multiuser mode, it is marked `multi'. Sessions marked as `unreachable' either
+live on a different host or are `dead'.
+An unreachable session is considered dead, when its name
+matches either the name of the local host, or the specified parameter, if any.
+See the \fB-r\fP flag for a description how to construct matches.
+Sessions marked as `dead' should be thoroughly checked and removed.
+Ask your system administrator if you are not sure. Remove sessions with the
+\fB-wipe\fP option.
+.TP 5
+.B \-L
+tells
+.I screen
+to turn on automatic output logging for the windows.
+.TP 5
+.BI "\-Logfile " file
+By default logfile name is \*Qscreenlog.0\*Q. You can set new logfile name
+with the \*Q-Logfile\*Q option.
+.TP 5
+.B \-m
+causes
+.I screen
+to ignore the $STY environment variable. With \*Qscreen \-m\*U creation of
+a new session is enforced, regardless whether
+.I screen
+is called from within another
+.I screen
+session or not. This flag has a special meaning in connection
+with the `\-d' option:
+.TP 8
+.B \-d \-m
+Start
+.I screen
+in \*Qdetached\*U mode. This creates a new session but doesn't
+attach to it. This is useful for system startup scripts.
+.TP 8
+.B \-D \-m
+This also starts screen in \*Qdetached\*U mode, but doesn't fork
+a new process. The command exits if the session terminates.
+.TP 5
+.B \-O
+selects a more optimal output mode for your terminal rather than true VT100
+emulation (only affects auto-margin terminals without `LP').
+This can also be set in your .screenrc by specifying `OP' in a \*Qtermcap\*U
+command.
+.TP 5
+.BI "\-p " number_or_name|-|=|+
+Preselect a window. This is useful when you want to reattach to a
+specific window or you want to send a command via the \*Q-X\*U
+option to a specific window. As with screen's select command, \*Q-\*U
+selects the blank window. As a special case for reattach, \*Q=\*U
+brings up the windowlist on the blank window, while a \*Q+\*U
+will create a new window. The command will not be
+executed if the specified window could not be found.
+.TP 5
+.B \-q
+Suppress printing of error messages. In combination with \*Q-ls\*U the exit
+value is as follows: 9 indicates a directory without sessions. 10
+indicates a directory with running but not attachable sessions. 11 (or more)
+indicates 1 (or more) usable sessions.
+In combination with \*Q-r\*U the exit value is as follows: 10 indicates that
+there is no session to resume. 12 (or more) indicates that there are 2 (or
+more) sessions to resume and you should specify which one to choose.
+In all other cases \*Q-q\*U has no effect.
+.TP 5
+.B \-Q
+Some commands now can be queried from a remote session using this
+flag, e.g. \*Qscreen \-Q windows\*U. The commands will send the
+response to the stdout of the querying process. If there was an
+error in the command, then the querying process will exit with
+a non-zero status.
+
+The commands that can be queried now are:
+ \fBecho\fP
+ \fBinfo\fP
+ \fBlastmsg\fP
+ \fBnumber\fP
+ \fBselect\fP
+ \fBtime\fP
+ \fBtitle\fP
+ \fBwindows\fP
+.TP 5
+.BR \-r " [" \fIpid.tty.host ]
+.PD 0
+.TP 5
+.BR \-r " \fIsessionowner/[" \fIpid.tty.host ]
+.PD
+resumes a detached
+.I screen
+session. No other options (except combinations with \fB\-d\fP/\fB\-D\fP) may
+be specified, though an optional prefix of [\fIpid.\fP]\fItty.host\fP
+may be needed to distinguish between multiple detached
+.I screen
+sessions. The second form is used to connect to another user's screen session
+which runs in multiuser mode. This indicates that screen should look for
+sessions in another user's directory. This requires setuid-root.
+.TP 5
+.B \-R
+resumes screen only when it's unambiguous which one to attach, usually
+when only one
+.I screen
+is detached. Otherwise lists available sessions.
+.B \-RR
+attempts to resume the first detached
+.I screen
+session it finds. If successful, all other command-line options are ignored.
+If no detached session exists, starts a new session using the specified
+options, just as if
+.B \-R
+had not been specified. The option is set by default if
+.I screen
+is run as a login-shell (actually screen uses \*Q\-xRR\*U in that case).
+For combinations with the \fB\-d\fP/\fB\-D\fP option see there.
+.TP 5
+.BI "\-s " program
+sets the default shell to the program specified, instead of the value
+in the environment variable $SHELL (or \*Q/bin/sh\*U if not defined).
+This can also be defined through the \*Qshell\*U .screenrc command.
+See also there.
+.TP 5
+.BI "\-S " sessionname
+When creating a new session, this option can be used to specify a
+meaningful name for the session. This name identifies the session for
+\*Qscreen \-list\*U and \*Qscreen \-r\*U actions. It substitutes the
+default [\fItty.host\fP] suffix.
+.TP 5
+.BI "\-t " name
+sets the title (a.\|k.\|a.) for the default shell or specified program.
+See also the \*Qshelltitle\*U .screenrc command.
+.TP 5
+.BI "\-T " term
+Set the $TERM environment variable using the specified term as
+opposed to the default setting of \fBscreen\fP.
+.TP 5
+.B \-U
+Run screen in UTF-8 mode. This option tells screen that your terminal
+sends and understands UTF-8 encoded characters. It also sets the default
+encoding for new windows to `utf8'.
+.TP 5
+.B \-v
+Print version number.
+.TP 5
+.BR \-wipe " [" \fImatch ]
+does the same as \*Qscreen \-ls\*U, but removes destroyed sessions instead of
+marking them as `dead'.
+An unreachable session is considered dead, when its name matches either
+the name of the local host, or the explicitly given parameter, if any.
+See the \fB-r\fP flag for a description how to construct matches.
+.TP 5
+.B \-x
+Attach to a not detached
+.I screen
+session. (Multi display mode).
+.I Screen
+refuses to attach from within itself.
+But when cascading multiple screens, loops are not detected; take care.
+.TP 5
+.B \-X
+Send the specified command to a running screen session. You may
+use the \fB-S\fP option to specify the screen session if you have
+several screen sessions running. You can use the \fB-d\fP or
+\fB-r\fP option to tell screen to look only for attached or
+detached screen sessions. Note that this command doesn't work if
+the session is password protected.
+
+.TP 5
+.B \-4
+Resolve hostnames only to IPv4 addresses.
+.TP 5
+.B \-6
+Resolve hostnames only to IPv6 addresses.
+.SH "DEFAULT KEY BINDINGS"
+.ta 12n 26n
+As mentioned, each
+.I screen
+command consists of a
+\*QC-a\*U followed by one other character.
+For your convenience, all commands that are bound to lower-case letters are
+also bound to their control character counterparts (with the exception
+of \*QC-a a\*U; see below), thus, \*QC-a c\*U as well as \*QC-a C-c\*U can
+be used to create a window. See section \*QCUSTOMIZATION\*U for a description
+of the command.
+.PP
+The following table shows the default key bindings. The trailiing
+commas in boxes with multiple keystroke entries are separators,
+not part of the bindings.
+.TS
+allbox tab(;);
+lb l l.
+C-a ';(select);T{
+Prompt for a window name or number to switch to.
+T}
+C-a \[dq];(windowlist -b);T{
+Present a list of all windows for selection.
+T}
+C-a \fIdigit\fP;(select 0-9);T{
+Switch to window number 0 \- 9
+T}
+C-a -;(select -);T{
+Switch to window number 0 \- 9, or to the blank window.
+T}
+C-a tab;(focus);T{
+Switch the input focus to the next region.
+See also \fIsplit, remove, only\fP.
+T}
+C-a C-a;(other);T{
+Toggle to the window displayed previously.
+Note that this binding defaults to the command character typed twice,
+unless overridden. For instance, if you use the option \*Q\fB\-e]x\fP\*U,
+this command becomes \*Q]]\*U.
+T}
+C-a a ;(meta);T{
+Send the command character (C-a) to window. See \fIescape\fP command.
+T}
+C-a A;(title);T{
+Allow the user to enter a name for the current window.
+T}
+T{
+C-a b,
+.br
+C-a C-b
+T};(break);T{
+Send a break to window.
+T}
+C-a B;(pow_break);T{
+Reopen the terminal line and send a break.
+T}
+T{
+C-a c,
+.br
+C-a C-c
+T};(screen);T{
+Create a new window with a shell and switch to that window.
+T}
+C-a C\fP;(clear);T{
+Clear the screen.
+T}
+T{
+C-a d,
+.br
+C-a C-d
+T};(detach);T{
+Detach
+.I screen
+from this terminal.
+T}
+C-a D D;(pow_detach);T{
+Detach and logout.
+T}
+T{
+C-a f,
+.br
+C-a C-f\fP
+T};(flow);T{
+Toggle flow \fIon\fP, \fIoff\fP or \fIauto\fP.
+T}
+C-a F;(fit);T{
+Resize the window to the current region size.
+T}
+C-a C-g;(vbell);T{
+Toggles
+.I screen's
+visual bell mode.
+T}
+C-a h;(hardcopy);T{
+Write a hardcopy of the current window to the file \*Qhardcopy.\fIn\fP\*U.
+T}
+C-a H;(log);T{
+Begins/ends logging of the current window to the file \*Qscreenlog.\fIn\fP\*U.
+T}
+T{
+C-a i,
+.br
+C-a C-i
+T};(info);T{
+Show info about this window.
+T}
+T{
+C-a k,
+.br
+C-a C-k
+T};(kill);T{
+Destroy current window.
+T}
+T{
+C-a l,
+.br
+C-a C-l
+T};(redisplay);T{
+Fully refresh current window.
+T}
+C-a L;(login);T{
+Toggle this windows login slot. Available only if
+.I screen
+is configured to update the utmp database.
+T{
+C-a m,
+.br
+C-a C-m
+T};(lastmsg);T{
+Repeat the last message displayed in the message line.
+T}
+C-a M;(monitor);T{
+Toggles monitoring of the current window.
+T}
+T{
+C-a space,
+.br
+C-a n,
+.br
+C-a C-n
+T};(next);T{
+Switch to the next window.
+T}
+C-a N;(number);T{
+Show the number (and title) of the current window.
+T}
+T{
+C-a backspace,
+.br
+C-a C-h,
+.br
+C-a p,
+.br
+C-a C-p
+T};(prev);T{
+Switch to the previous window (opposite of \fBC-a n\fP).
+T}
+T{
+C-a q,
+.br
+C-a C-q
+T};(xon);T{
+Send a control-q to the current window.
+T}
+C-a Q;(only);T{
+Delete all regions but the current one.
+See also \fIsplit, remove, focus\fP.
+T}
+T{
+C-a r,
+.br
+C-a C-r
+T};(wrap);T{
+Toggle the current window's line-wrap setting (turn the current window's
+automatic margins on and off).
+T}
+T{
+C-a s,
+.br
+C-a C-s;
+T};(xoff);T{
+Send a control-s to the current window.
+T}
+C-a S;(split);T{
+Split the current region horizontally into two new ones.
+See also \fIonly, remove, focus\fP.
+T}
+T{
+C-a t,
+.br
+C-a C-t
+T};(time);T{
+Show system information.
+T}
+C-a v;(version);T{
+Display the version and compilation date.
+T}
+C-a C-v;(digraph);T{
+Enter digraph.
+T}
+T{
+C-a w,
+.br
+C-a C-w
+T};(windows);T{
+Show a list of window.
+T}
+C-a W;(width);T{
+Toggle 80/132 columns.
+T}
+C-a x \fRor\fP C-a C-x;(lockscreen);T{
+Lock this terminal.
+T}
+C-a X\fP ;(remove);T{
+Kill the current region.
+See also \fIsplit, only, focus\fP.
+T}
+T{
+C-a z,
+.br
+C-a C-z
+T};(suspend);T{
+Suspend
+.IR screen .
+Your system must support BSD-style job-control.
+T}
+C-a Z;(reset);T{
+Reset the virtual terminal to its \*Qpower-on\*U values.
+T}
+C-a .;(dumptermcap);T{
+Write out a \*Q.termcap\*U file.
+T}
+C-a ?;(help);T{
+Show key bindings.
+T}
+C-a \e;(quit);T{
+Kill all windows and terminate
+.IR screen .
+T}
+C-a :;(colon);T{
+Enter command line mode.
+T}
+T{
+C-a [,
+.br
+C-a C-[\fP,
+.br
+C-a esc
+T};(copy);T{
+Enter copy/scrollback mode.
+T}
+T{
+C-a C-],
+.br
+C-a ]
+T};(paste .);T{
+Write the contents of the paste buffer to the stdin queue of the
+current window.
+T}
+T{
+C-a {\fP,
+.br
+C-a }
+T};(history);T{
+Copy and paste a previous (command) line.
+T}
+C-a >;(writebuf);T{
+Write paste buffer to a file.
+T}
+C-a <;(readbuf);T{
+Reads the screen-exchange file into the paste buffer.
+T}
+C-a =;(removebuf);T{
+Removes the file used by \fBC-a <\fP and \fPC-a >\fP.
+T}
+C-a ,;(license);T{
+Shows where
+.I screen
+comes from, where it went to and why you can use it.
+T}
+C-a _;(silence);T{
+Start/stop monitoring the current window for inactivity.
+T}
+C-a |;(split -v);T{
+Split the current region vertically into two new ones.
+T}
+C-a *;(displays);T{
+Show a listing of all currently attached displays.
+T}
+.TE
+
+.SH CUSTOMIZATION
+The \*Qsocket directory\*U defaults either to $HOME/.screen or simply to
+/tmp/screens or preferably to /usr/local/screens chosen at compile-time. If
+.I screen
+is installed setuid-root, then the administrator
+should compile
+.I screen
+with an adequate (not NFS mounted) socket directory. If
+.I screen
+is not running setuid-root, the user can specify any mode 700 directory
+in the environment variable $SCREENDIR.
+.PP
+When
+.I screen
+is invoked, it executes initialization commands from the files
+\*Q/usr/local/etc/screenrc\*U and
+\*Q.screenrc\*U in the user's home directory. These are the \*Qprogrammer's
+defaults\*U that can be overridden in the following ways: for the
+global screenrc file
+.I screen
+searches for the environment variable $SYSSCREENRC (this override feature
+may be disabled at compile-time). The user specific
+screenrc file is searched in $SCREENRC, then $HOME/.screenrc.
+The command line option \fB\-c\fP takes
+precedence over the above user screenrc files.
+.PP
+Commands in these files are used to set options, bind functions to
+keys, and to automatically establish one or more windows at the
+beginning of your
+.I screen
+session.
+Commands are listed one per line, with empty lines being ignored.
+A command's arguments are separated by tabs or spaces, and may be
+surrounded by single or double quotes.
+A `#' turns the rest of the line into a comment, except in quotes.
+Unintelligible lines are warned about and ignored.
+Commands may contain references to environment variables. The
+syntax is the shell-like "$VAR " or "${VAR}". Note that this causes
+incompatibility with previous
+.I screen
+versions, as now the '$'-character has to be protected with '\e' if no
+variable substitution shall be performed. A string in single-quotes is also
+protected from variable substitution.
+.PP
+Two configuration files are shipped as examples with your screen distribution:
+\*Qetc/screenrc\*U and \*Qetc/etcscreenrc\*U. They contain a number of
+useful examples for various commands.
+.PP
+Customization can also be done 'on-line'. To enter the command mode type
+`C-a :'. Note that commands starting with \*Qdef\*U change default values,
+while others change current settings.
+.PP
+The following commands are available:
+.TP
+.BI acladd " usernames " \fR[\fP crypted-pw \fR]\fR
+.TP
+.BI addacl " usernames"
+.RS 0
+.PP
+Enable users to fully access this screen session. \fIUsernames\fP can be one
+user or a comma separated list of users. This command enables to attach to the
+.I screen
+session and performs the equivalent of `aclchg \fIusernames\fP +rwx \&"#?\&"'.
+executed. To add a user with restricted access, use the `aclchg' command below.
+If an optional second parameter is supplied, it should be a crypted password
+for the named user(s). `Addacl' is a synonym to `acladd'.
+Multi user mode only.
+.RE
+.TP
+.BI aclchg " usernames permbits list"
+.TP
+.BI chacl " usernames permbits list"
+.RS 0
+.PP
+Change permissions for a comma separated list of users. Permission bits are
+represented as `r', `w' and `x'. Prefixing `+' grants the permission, `\-'
+removes it. The third parameter is a comma separated list of commands and/or
+windows (specified either by number or title). The special list `#' refers to
+all windows, `?' to all commands. if \fIusernames\fP consists of a single `*',
+all known users are affected.
+.PP
+A command can be executed when the user has the `x' bit for it.
+The user can type input to a window when he has its `w' bit set and no other
+user obtains a writelock for this window.
+Other bits are currently ignored.
+To withdraw the writelock from another user in window 2:
+`aclchg \fIusername\fP \-w+w 2'.
+To allow read-only access to the session: `aclchg \fIusername\fP
+\-w \&"#\&"'. As soon as a user's name is known to
+.I screen
+he can attach to the session and (per default) has full permissions for all
+command and windows. Execution permission for the acl commands, `at' and others
+should also be removed or the user may be able to regain write permission.
+Rights of the special username
+.B nobody
+cannot be changed (see the \*Qsu\*U command).
+`Chacl' is a synonym to `aclchg'.
+Multi user mode only.
+.RE
+.TP
+.BI acldel " username"
+.RS 0
+.PP
+Remove a user from
+.IR screen 's
+access control list. If currently attached, all the
+user's displays are detached from the session. He cannot attach again.
+Multi user mode only.
+.RE
+.TP
+.BI aclgrp " username " \fR[\fP groupname \fR]\fP
+.RS 0
+.PP
+Creates groups of users that share common access rights. The name of the
+group is the username of the group leader. Each member of the group inherits
+the permissions that are granted to the group leader. That means, if a user
+fails an access check, another check is made for the group leader.
+A user is removed from all groups the special value \*Qnone\*U is used for
+.IR groupname .
+If the second parameter is omitted all groups the user is in are listed.
+.RE
+.TP
+\fBaclumask\fP [[ \fIusers\fP ] \fI+bits\fP | [ \fIusers\fR ] \fI-bits...\fP ]
+.TP
+\fBumask\fP [[ \fIusers\fP ] \fI+bits\fP | [ \fIusers\fR ] \fI-bits...\fP ]
+.RS 0
+.PP
+This specifies the access other users have to windows that will be created by
+the caller of the command.
+.I Users
+may be no, one or a comma separated list of known usernames. If no users are
+specified, a list of all currently known users is assumed.
+.I Bits
+is any combination of access control bits allowed defined with the
+\*Qaclchg\*U command. The special username \*Q?\*U predefines the access
+that not yet known users will be granted to any window initially.
+The special username \*Q??\*U predefines the access that not yet known
+users are granted to any command.
+Rights of the special username
+.B nobody
+cannot be changed (see the \*Qsu\*U command).
+`Umask' is a synonym to `aclumask'.
+.RE
+.TP
+.BI activity " message"
+.RS 0
+.PP
+When any activity occurs in a background window that is being monitored,
+.I screen
+displays a notification in the message line.
+The notification message can be re-defined by means of the \*Qactivity\*U
+command.
+Each occurrence of `%' in \fImessage\fP is replaced by
+the number of the window in which activity has occurred,
+and each occurrence of `^G' is replaced by the definition for bell
+in your termcap (usually an audible bell).
+The default message is
+.sp
+ 'Activity in window %n'
+.sp
+Note that monitoring is off for all windows by default, but can be altered
+by use of the \*Qmonitor\*U command (C-a M).
+.RE
+.TP
+.BR "allpartial on" | off
+.RS 0
+.PP
+If set to on, only the current cursor line is refreshed on window change.
+This affects all windows and is useful for slow terminal lines. The
+previous setting of full/partial refresh for each window is restored
+with \*Qallpartial off\*U. This is a global flag that immediately takes effect
+on all windows overriding the \*Qpartial\*U settings. It does not change the
+default redraw behavior of newly created windows.
+.RE
+.TP
+.BR "altscreen on" | off
+.RS 0
+.PP
+If set to on, "alternate screen" support is enabled in virtual terminals,
+just like in xterm. Initial setting is `off'.
+.RE
+.TP
+.BR "at " "[\fIidentifier\fP][" "#\fP|\fP*\fP|\fP%\fP] " "command " [ \fIargs\fP " … ]"
+.RS 0
+.PP
+Execute a command at other displays or windows as if it had been entered there.
+\*QAt\*U changes the context (the `current window' or `current display'
+setting) of the command. If the first parameter describes a
+non-unique context, the command will be executed multiple times. If the first
+parameter is of the form `\fIidentifier\fP*' then identifier is matched against
+user names. The command is executed once for each display of the selected
+user(s). If the first parameter is of the form `\fIidentifier\fP%' identifier
+is matched against displays. Displays are named after the ttys they
+attach. The prefix `/dev/' or `/dev/tty' may be omitted from the identifier.
+If \fIidentifier\fP has a `#' or nothing appended it is matched against
+window numbers and titles. Omitting an identifier in front of the `#', `*' or
+`%'-character selects all users, displays or windows because a prefix-match is
+performed. Note that on the affected display(s) a short message will describe
+what happened. Permission is checked for initiator of the \*Qat\*U command,
+not for the owners of the affected display(s).
+Note that the '#' character works as a comment introducer when it is preceded by
+whitespace. This can be escaped by prefixing a '\e'.
+Permission is checked for the initiator of the \*Qat\*U command, not for the
+owners of the affected display(s).
+.PP
+Caveat:
+When matching against windows, the command is executed at least
+once per window. Commands that change the internal arrangement of windows
+(like \*Qother\*U) may be called again. In shared windows the command will
+be repeated for each attached display. Beware, when issuing toggle commands
+like \*Qlogin\*U!
+Some commands (e.g. \*Qprocess\*U) require that
+a display is associated with the target windows. These commands may not work
+correctly under \*Qat\*U looping over windows.
+.RE
+.TP
+.BI "attrcolor " "attrib " \fR[\fP "attribute/color-modifier" \fR]\fP
+.RS 0
+.PP
+This command can be used to highlight attributes by changing the color of
+the text. If the attribute
+.I attrib
+is in use, the specified attribute/color modifier is also applied. If no
+modifier is given, the current one is deleted. See the \*QSTRING ESCAPES\*U
+chapter for the syntax of the modifier. Screen understands two
+pseudo-attributes, \*Qi\*U stands for high-intensity foreground
+color and \*QI\*U for high-intensity background color.
+.sp
+Examples:
+.IP
+attrcolor b "R"
+.PP
+Change the color to bright red if bold text is to be printed.
+.IP
+attrcolor u "\-u b"
+.PP
+Use blue text instead of underline.
+.IP
+attrcolor b ".I"
+.PP
+Use bright colors for bold text. Most terminal emulators do this
+already.
+.IP
+attrcolor i "+b"
+.PP
+Make bright colored text also bold.
+.RE
+.TP
+.BR "autodetach on" | off
+.RS 0
+.PP
+Sets whether
+.I screen
+will automatically detach upon hangup, which
+saves all your running programs until they are resumed with a
+.B "screen \-r"
+command.
+When turned off, a hangup signal will terminate
+.I screen
+and all the processes it contains. Autodetach is on by default.
+.RE
+.TP
+.BR "autonuke on" | off
+.RS 0
+.PP
+Sets whether a clear screen sequence should nuke all the output
+that has not been written to the terminal. See also
+\*Qobuflimit\*U.
+.RE
+.TP
+.BI "backtick " "id lifespan autorefresh cmd args…"
+.TP
+.BI "backtick " id
+.RS 0
+.PP
+Program the backtick command with the numerical id \fIid\fP.
+The output of such a command is used for substitution of the
+\*Q%`\*U string escape. The specified \fIlifespan\fP is the number
+of seconds the output is considered valid. After this time, the
+command is run again if a corresponding string escape is encountered.
+The \fIautorefresh\fP parameter triggers an
+automatic refresh for caption and hardstatus strings after the
+specified number of seconds. Only the last line of output is used
+for substitution.
+.PP
+If both the \fIlifespan\fP and the \fIautorefresh\fP parameters
+are zero, the backtick program is expected to stay in the
+background and generate output once in a while.
+In this case, the command is executed right away and screen stores
+the last line of output. If a new line gets printed screen will
+automatically refresh the hardstatus or the captions.
+.PP
+The second form of the command deletes the backtick command
+with the numerical id \fIid\fP.
+.RE
+.TP
+.BR "bce " [ on | off ]
+.RS 0
+.PP
+Change background-color-erase setting. If \*Qbce\*U is set to on, all
+characters cleared by an erase/insert/scroll/clear operation
+will be displayed in the current background color. Otherwise
+the default background color is used.
+.RE
+.TP
+.BR "bell_msg " [ \fImessage\fP ]
+.RS 0
+.PP
+When a bell character is sent to a background window,
+.I screen
+displays a notification in the message line.
+The notification message can be re-defined by this command.
+Each occurrence of `%' in \fImessage\fP is replaced by
+the number of the window to which a bell has been sent,
+and each occurrence of `^G' is replaced by the definition for bell
+in your termcap (usually an audible bell).
+The default message is
+.sp
+.RS
+ 'Bell in window %n'
+.RE
+.sp
+An empty message can be supplied to the \*Qbell_msg\*U command to suppress
+output of a message line (bell_msg "").
+Without parameter, the current message is shown.
+.RE
+.TP
+.BR "bind " [ \fIclass\fP ] " \fIkey\fP " [ \fIcommand\fP " [" \fIargs\fP ]]
+.RS 0
+.PP
+Bind a command to a key.
+By default, most of the commands provided by
+.I screen
+are bound to one or more keys as indicated in the \*QDEFAULT KEY BINDINGS\*U
+section, e.\|g. the
+command to create a new window is bound to \*QC-c\*U and \*Qc\*U.
+The \*Qbind\*U command can be used to redefine the key bindings and to
+define new bindings.
+The \fIkey\fP argument is either a single character, a two-character sequence
+of the form \*Q^x\*U (meaning \*QC-x\*U), a backslash followed by an octal
+number (specifying the ASCII code of the character), or a backslash followed
+by a second character, such as \*Q\e^\*U or \*Q\e\e\*U.
+The argument can also be quoted, if you like.
+If no further argument is given, any previously established binding
+for this key is removed.
+The \fIcommand\fP argument can be any command listed in this section.
+.PP
+If a command class is specified via the \*Q\-c\*U option, the key
+is bound for the specified class. Use the \*Qcommand\*U command
+to activate a class. Command classes can be used to create multiple
+command keys or multi-character bindings.
+.PP
+Some examples:
+.PP
+.nf
+ bind ' ' windows
+ bind ^k
+ bind k
+ bind K kill
+ bind ^f screen telnet foobar
+ bind \e033 screen \-ln \-t root \-h 1000 9 su
+.fi
+.PP
+would bind the space key to the command that displays a list
+of windows (so that the command usually invoked by \*QC-a C-w\*U
+would also be available as \*QC-a space\*U). The next three lines
+remove the default kill binding from \*QC-a C-k\*U and \*QC-a k\*U.
+\*QC-a K\*U is then bound to the kill command. Then it
+binds \*QC-f\*U to the command \*Qcreate a window with a TELNET
+connection to foobar\*U, and bind \*Qescape\*U to the command
+that creates an non-login window with a.\|k.\|a. \*Qroot\*U in slot #9, with
+a superuser shell and a scrollback buffer of 1000 lines.
+.PP
+.nf
+ bind \-c demo1 0 select 10
+ bind \-c demo1 1 select 11
+ bind \-c demo1 2 select 12
+ bindkey "^B" command \-c demo1
+.fi
+.PP
+makes \*QC-b 0\*U select window 10, \*QC-b 1\*U window 11, etc.
+.PP
+.nf
+ bind \-c demo2 0 select 10
+ bind \-c demo2 1 select 11
+ bind \-c demo2 2 select 12
+ bind \- command \-c demo2
+.fi
+.PP
+makes \*QC-a \- 0\*U select window 10, \*QC-a \- 1\*U window 11, etc.
+.RE
+.TP
+.BR "bindkey " [ \-d "] [" \-m "] [" \-a "] [[" \-k | \-t ] " \fIstring\fR " [ "\fIcmd-args\fP" ]]
+.RS 0
+.PP
+This command manages screen's input translation tables. Every
+entry in one of the tables tells screen how to react if a certain
+sequence of characters is encountered. There are three tables:
+one that should contain actions programmed by the user, one for
+the default actions used for terminal emulation and one for
+screen's copy mode to do cursor movement. See section
+\*QINPUT TRANSLATION\*U for a list of default key bindings.
+.PP
+If the
+.B \-d
+option is given, bindkey modifies the default table,
+.B \-m
+changes the copy mode table
+and with neither option the user table is selected.
+The argument
+.I string
+is the sequence of characters to which an action is bound. This
+can either be a fixed string or a termcap keyboard capability
+name (selectable with the
+.B \-k
+option).
+.PP
+Some keys on a VT100 terminal can send a different
+string if application mode is turned on (e.g the cursor keys).
+Such keys have two entries in the translation table. You can
+select the application mode entry by specifying the
+.B \-a
+option.
+.PP
+The
+.B \-t
+option tells screen not to do inter-character timing. One cannot
+turn off the timing if a termcap capability is used.
+.PP
+.I Cmd
+can be any of screen's commands with an arbitrary number of
+.IR args .
+If
+.I cmd
+is omitted the key-binding is removed from the table.
+.PP
+Here are some examples of keyboard bindings:
+.sp
+.nf
+ bindkey \-d
+.fi
+Show all of the default key bindings. The application mode entries
+are marked with [A].
+.sp
+.nf
+ bindkey \-k k1 select 1
+.fi
+Make the "F1" key switch to window one.
+.sp
+.nf
+ bindkey \-t foo stuff barfoo
+.fi
+Make "foo" an abbreviation of the word "barfoo". Timeout is disabled
+so that users can type slowly.
+.sp
+.nf
+ bindkey "\e024" mapdefault
+.fi
+This key-binding makes \*Q^T\*U an escape character for key-bindings. If
+you did the above \*Qstuff barfoo\*U binding, you can enter the word
+\*Qfoo\*U by typing \*Q^Tfoo\*U. If you want to insert a \*Q^T\*U
+you have to press the key twice (i.e., escape the escape binding).
+.sp
+.nf
+ bindkey \-k F1 command
+.fi
+Make the F11 (not F1!) key an alternative screen
+escape (besides ^A).
+.RE
+.TP
+.BR break [ \fIduration\fR ]
+.RS 0
+.PP
+Send a break signal for \fIduration\fP*0.25 seconds to this window.
+For non-Posix systems the time interval may be rounded up to full seconds.
+Most useful if a character device is attached to the window rather than
+a shell process (See also chapter \*QWINDOW TYPES\*U). The maximum duration of
+a break signal is limited to 15 seconds.
+.RE
+.TP
+.B blanker
+.RS 0
+.PP
+Activate the screen blanker. First the screen is cleared. If no blanker
+program is defined, the cursor is turned off, otherwise, the
+program is started and it's output is written to the screen.
+The screen blanker is killed with the first keypress, the read key
+is discarded.
+.PP
+This command is normally used together with the \*Qidle\*U command.
+.RE
+.TP
+.IR "\fBblankerprg\fR " [ "program-args" ]
+.RS 0
+.PP
+Defines a blanker program. Disables the blanker program if an
+empty argument is given. Shows the currently set blanker program if no
+arguments are given.
+.RE
+.TP
+.IR "\fBbreaktype\fP " [ tcsendbreak | TIOCSBRK | TCSBRK ]
+.RS 0
+.PP
+Choose one of the available methods of generating a break signal for
+terminal devices. This command should affect the current window only.
+But it still behaves identical to \*Qdefbreaktype\*U. This will be changed in
+the future.
+Calling \*Qbreaktype\*U with no parameter displays the break method for the
+current window.
+.RE
+.TP
+.IR "\fBbufferfile\fP " [ exchange-file ]
+.RS 0
+.PP
+Change the filename used for reading and writing with the paste buffer.
+If the optional argument to the \*Qbufferfile\*U command is omitted,
+the default setting (\*Q/tmp/screen\-exchange\*U) is reactivated.
+The following example will paste the system's password file into
+the
+.I screen
+window (using the paste buffer, where a copy remains):
+.PP
+.nf
+ C-a : bufferfile /etc/passwd
+ C-a < C-a ]
+ C-a : bufferfile
+.fi
+.sp
+.ne 3
+.BR bumpleft
+.PP
+Swaps window with previous one on window list.
+.RE
+.TP
+.BR bumpright
+.RS 0
+.PP
+Swaps window with next one on window list.
+.RE
+.TP
+.BR "c1 " [ on | off ]
+.RS 0
+.PP
+Change c1 code processing. \*QC1 on\*U tells screen to treat
+the input characters between 128 and 159 as control functions.
+Such an 8-bit code is normally the same as ESC followed by the
+corresponding 7-bit code. The default setting is to process c1
+codes and can be changed with the \*Qdefc1\*U command.
+Users with fonts that have usable characters in the
+c1 positions may want to turn this off.
+.RE
+.TP
+.BR "caption [ top | bottom ] always" | splitonly [ string ]
+.TP
+.IR "\fBcaption string\fP " [ string ]
+.RS 0
+.PP
+This command controls the display of the window captions. Normally
+a caption is only used if more than one window is shown on the
+display (split screen mode). But if the type is set to
+.B always
+screen shows a caption even if only one window is displayed. The default
+is
+.BR splitonly .
+.P
+The second form changes the text used for the caption. You can use
+all escapes from the \*QSTRING ESCAPES\*U chapter. Screen uses
+a default of `%3n %t'.
+.P
+You can mix both forms by providing a string as an additional argument.
+.P
+You can have the caption displayed either at the top or bottom of the window.
+The default is
+.BR bottom .
+.RE
+.TP
+.BI "charset " set
+.RS 0
+.PP
+Change the current character set slot designation and charset
+mapping. The first four character of
+.I set
+are treated as charset designators while the fifth and sixth
+character must be in range '0' to '3' and set the GL/GR charset
+mapping. On every position a '.' may be used to indicate that
+the corresponding charset/mapping should not be changed
+(\fIset\fP is padded to six characters internally by appending '.'
+chars). New windows have "BBBB02" as default charset, unless a
+\*Qencoding\*U command is active.
+.br
+The current setting can be viewed with the \*Qinfo\*U command.
+.RE
+.TP
+.IR "\fBchdir\fP " [ directory ]
+.RS 0
+.PP
+Change the \fIcurrent directory\fP of
+.I screen
+to the specified directory or, if called without an argument,
+to your home directory (the value of the environment variable $HOME).
+All windows that are created by means of the \*Qscreen\*U command
+from within \*Q.screenrc\*U or by means of \*QC-a : screen …\*U
+or \*QC-a c\*U use this as their default directory.
+Without a chdir command, this would be the directory from which
+.I screen
+was invoked.
+.PP
+Hardcopy and log files are always written to the \fIwindow's\fP default
+directory, \fInot\fP the current directory of the process running in the
+window.
+You can use this command multiple times in your .screenrc to start various
+windows in different default directories, but the last chdir value will
+affect all the windows you create interactively.
+.RE
+.TP
+.B cjkwidth [ on | off ]
+.RS 0
+.PP
+Treat ambiguous width characters as full/half width.
+.RE
+.TP
+.B clear
+.RS 0
+.PP
+Clears the current window and saves its image to the scrollback buffer.
+.RE
+.TP
+.B collapse
+.RS 0
+.PP
+Reorders window on window list, removing number gaps between them.
+.RE
+.TP
+.IR "\fBcolon " [ prefix ]
+.RS 0
+.PP
+Allows you to enter \*Q.screenrc\*U command lines. Useful
+for on-the-fly modification of key bindings,
+specific window creation and changing settings. Note that the \*Qset\*U
+keyword no longer exists! Usually commands affect the current window rather
+than default settings for future windows. Change defaults with commands
+starting with 'def…'.
+.PP
+If you consider this as the `Ex command mode' of
+.IR screen ,
+you may regard \*QC-a esc\*U (copy mode) as its `Vi command mode'.
+.RE
+.TP
+.BR "command " [ \-c " \fIclass\fP" ]
+.RS 0
+.PP
+This command has the same effect as typing the screen escape
+character (^A). It is probably only useful for key bindings.
+If the \*Q\-c\*U option is given, select the specified command
+class. See also \*Qbind\*U and \*Qbindkey\*U.
+.RE
+.TP
+.BR "compacthist " [ on | off ]
+.RS 0
+.PP
+This tells screen whether to suppress trailing blank lines when
+scrolling up text into the history buffer.
+.RE
+.TP
+.BR "console " [ on | off ]
+.RS 0
+.PP
+Grabs or un-grabs the machines console output to a window.
+.IR Note :
+Only the owner of /dev/console can grab the console output.
+This command is only available if the machine supports the ioctl TIOCCONS.
+.RE
+.TP
+.B copy
+.RS 0
+.PP
+Enter copy/scrollback mode. This allows you to copy text from the current
+window and its history into the paste buffer. In this mode a vi-like
+`full screen editor' is active:
+.br
+The editor's movement keys are:
+
+.TS
+allbox tab(@);
+l l.
+T{
+\fBh\fP, \fBC-h\fP,
+.br
+\fBleft arrow\fP
+T}@move the cursor left.
+T{
+\fBj\fP, \fBC-n\fP,
+.br
+\fBdown arrow\fP
+T}@move the cursor down.
+T{
+\fBk\fP, \fBC-p\fP,
+.br
+\fBup arrow\fP
+T}@move the cursor up.
+T{
+\fBl\fP ('el'),
+.br
+\fBright arrow\fP
+T}@move the cursor right.
+\fB0\fP (zero) \fBC-a\fP@move to the leftmost column.
+\fB+\fP and \fB\-\fP@positions one line up and down.
+\fBH\fP, \fBM\fP and \fBL\fP@T{
+move the cursor to the leftmost column
+of the top, center or bottom line of the window.
+T}
+\fB|\fP@moves to the specified absolute column.
+\fBg\fP or \fBhome\fP@moves to the beginning of the buffer.
+\fBG\fP or \fBend\fP@T{
+moves to the specified absolute line (default: end of buffer).
+T}
+\fB%\fP@jumps to the specified percentage of the buffer.
+\fB^\fP or \fB$\fP@T{
+move to the leftmost column, to the first or last
+non-whitespace character on the line.
+T}
+\fBw\fP, \fBb\fP, and \fBe\fP@move the cursor word by word.
+\fBB\fP, \fBE\fP@move the cursor WORD by WORD (as in vi).
+\fBf/F\fP, \fBt/T\fP@T{
+move the cursor forward/backward to the next occurence of the
+target. (eg, '3fy' will move the cursor to the 3rd 'y' to the right.)
+T}
+\fB;\fP and \fB,\fP@T{
+Repeat the last f/F/t/T command in the same/opposite direction.
+T}
+\fBC-e\fP and \fBC-y\fP@T{
+scroll the display up/down by one line
+while preserving the cursor position.
+T}
+\fBC-u\fP and \fBC-d\fP@T{
+scroll the display up/down by the specified amount of
+lines while preserving the cursor position. (Default: half screen-full).
+T}
+\fBC-b\fP and \fBC-f\fP@scroll the display up/down a full screen.
+.TE
+.\"\fBf\fP,\fBt\fP, \fBF\fP, \fBT\fP@T{
+.\"move the cursor forward/backward to the next occurence of the target.
+.\"T}
+
+.PP
+Note: Emacs style movement keys can be customized by a .screenrc
+command. (E.\|g. markkeys "h=^B:l=^F:$=^E") There is no simple method
+for a full emacs-style keymap, as this involves multi-character codes.
+.PP
+Some keys are defined to do mark and replace operations.
+.PP
+The copy range is specified by setting two marks. The text between these marks
+will be highlighted. Press:
+.IP
+\fBspace\fP or \fBenter\fP to set the first or second mark
+respectively. If \fBmousetrack\fP is set to `on', marks can also be set using
+\fPleft mouse click\fP.
+.PP
+.IP
+\fBY\fP and \fBy\fP used to mark one whole line or to mark from
+start of line.
+.IP
+\fBW\fP marks exactly one word.
+.PP
+Any of these commands can be prefixed with a repeat count number by pressing
+digits
+.IP
+\fB0\fP..\fB9\fP which
+is taken as a repeat count.
+.PP
+Example: \*QC-a C-[ H 10 j 5 Y\*U will copy lines
+11 to 15 into the paste buffer.
+.PP
+The folllowing search keys are defined:
+.IP
+\fB/\fP \fIVi\fP-like search forward.
+.IP
+\fB?\fP \fIVi\fP-like search backward.
+.IP
+\fBC-a s\fP \fIEmacs\fP style incremental search forward.
+.IP
+\fBC-r\fP \fIEmacs\fP style reverse i-search.
+.IP
+\fBn\fP Find next search pattern.
+.IP
+\fBN\fP Find previous search pattern.
+
+.PP
+There are however some keys that act differently than in
+.IR vi .
+.I Vi
+does not allow one to yank rectangular blocks of text, but
+.I screen
+does. Press: \fBc\fP or \fBC\fP to set the left or right margin
+respectively. If no repeat count is given, both default to the current
+cursor position.
+.PP
+Example: Try this on a rather full text screen:
+.sp 1
+.RS
+\*QC-a [ M 20 l SPACE c 10 l 5 j C SPACE\*U.
+.RE
+.sp 1
+This moves one to the middle line of the screen, moves in 20 columns left,
+marks the beginning of the paste buffer, sets the left column, moves 5 columns
+down, sets the right column, and then marks the end of
+the paste buffer. Now try:
+.sp 1
+.RS
+\*QC-a [ M 20 l SPACE 10 l 5 j SPACE\*U
+.RE
+.sp 1
+and notice the difference in the amount of text copied.
+.PP
+\fBJ\fP joins lines. It toggles between 4 modes: lines separated by a
+newline character (012), lines glued seamless, lines separated by a single
+whitespace and comma separated lines. Note that you can prepend the newline
+character with a carriage return character, by issuing a \*Qcrlf on\*U.
+.PP
+\fBv\fP or \fBV\fP is for all the
+.I vi
+users with \*Q:set numbers\*U \- it toggles the left margin between column 9
+and 1. Press
+.PP
+\fBa\fP before the final space key to toggle in append mode. Thus
+the contents of the paste buffer will not be overwritten, but is appended to.
+.PP
+\fBA\fP toggles in append mode and sets a (second) mark.
+.PP
+\fB>\fP sets the (second) mark and writes the contents of the paste buffer to
+the screen-exchange file (/tmp/screen\-exchange per default) once copy-mode is
+finished.
+.PP
+This example demonstrates how to dump the whole scrollback buffer
+to that file: \*QC-A [ g SPACE G $ >\*U.
+.PP
+\fBC-g\fP gives information about the current line and column.
+.PP
+\fBx\fP or \fBo\fP exchanges the first mark and the current cursor position. You
+can use this to adjust an already placed mark.
+.PP
+\fBC-l\fP ('el') will redraw the screen.
+.PP
+\fB@\fP does nothing. Does not even exit copy mode.
+.PP
+All keys not described here exit copy mode.
+.RE
+.TP
+.IR "\fBcopy_reg " [ key ]
+.RS 0
+.PP
+No longer exists, use \*Qreadreg\*U instead.
+.RE
+.TP
+.BR "crlf " [ on | off ]
+.RS 0
+.PP
+This affects the copying of text regions with the `C-a [' command. If it is set
+to `on', lines will be separated by the two character sequence `CR' - `LF'.
+Otherwise (default) only `LF' is used.
+When no parameter is given, the state is toggled.
+.RE
+.TP
+.BR "debug on" | off
+.RS 0
+.PP
+Turns runtime debugging on or off. If
+.I screen
+has been compiled with option \-DDEBUG debugging available and is turned on per
+default. Note that this command only affects debugging output from the main
+\*QSCREEN\*U process correctly. Debug output from attacher processes can only
+be turned off once and forever.
+.RE
+.TP
+.BR "defc1 on" | off
+.RS 0
+.PP
+Same as the \fBc1\fP command except that the default setting for new
+windows is changed. Initial setting is `on'.
+.RE
+.TP
+.BR "defautonuke on" | off
+.RS 0
+.PP
+Same as the \fBautonuke\fP command except that the default setting for new displays is changed. Initial setting is `off'.
+Note that you can use the special `AN' terminal capability if you
+want to have a dependency on the terminal type.
+.RE
+.TP
+.BR "defbce on" | off
+.RS 0
+.PP
+Same as the \fBbce\fP command except that the default setting for new
+windows is changed. Initial setting is `off'.
+.RE
+.TP
+.IR "\fBdefbreaktype\fP " [ tcsendbreak | TIOCSBRK | TCSBRK ]
+.RS 0
+.PP
+Choose one of the available methods of generating a break signal for
+terminal devices. The preferred methods are
+.IR tcsendbreak " and " TIOCSBRK .
+The third,
+.IR TCSBRK ,
+blocks the complete
+.I screen
+session for the duration
+of the break, but it may be the only way to generate long breaks.
+.IR Tcsendbreak " and " TIOCSBRK
+may or may not produce long breaks with spikes (e.g. 4 per
+second). This is not only system-dependent, this also differs between
+serial board drivers.
+Calling \*Qdefbreaktype\*U with no parameter displays the current setting.
+.RE
+.TP
+.BR "defcharset " [ \fIset ]
+.RS 0
+.PP
+Like the \fBcharset\fP command except that the default setting for
+new windows is changed. Shows current default if called without
+argument.
+.RE
+.TP
+.BR "defdynamictitle on" | off
+.RS 0
+.PP
+Set default behaviour for new windows regarding if screen should change window
+title when seeing proper escape sequence. See also "TITLES (naming windows)"
+section.
+.RE
+.TP
+.BI "defescape " xy
+.RS 0
+.PP
+Set the default command characters. This is equivalent to the
+\*Qescape\*U except that it is useful multiuser sessions only. In a
+multiuser session \*Qescape\*U changes the command character of the
+calling user, where \*Qdefescape\*U changes the default command
+characters for users that will be added later.
+.RE
+.TP
+.BR "defflow " on | off | "auto " [ interrupt ]
+.RS 0
+.PP
+Same as the \fBflow\fP command except that the default setting for new windows
+is changed. Initial setting is `auto'.
+Specifying \*Qdefflow auto interrupt\*U is the same as the command-line options
+.B \-fa
+and
+.BR \-i .
+.RE
+.TP
+.BR "defgr on" | off
+.RS 0
+.PP
+Same as the \fBgr\fP command except that the default setting for new
+windows is changed. Initial setting is `off'.
+.RE
+.TP
+.BR "defhstatus " [ \fIstatus ]
+.RS 0
+.PP
+The hardstatus line that all new windows will get is set to
+.I status\fR.
+This command is useful to make the hardstatus of every window
+display the window number or title or the like.
+.I Status
+may contain the same directives as in the window messages, but
+the directive escape character is '^E' (octal 005) instead of '%'.
+This was done to make a misinterpretation of program generated
+hardstatus lines impossible.
+If the parameter
+.I status
+is omitted, the current default string is displayed.
+Per default the hardstatus line of new windows is empty.
+.RE
+.TP
+.BI "defencoding " enc
+.RS 0
+.PP
+Same as the \fBencoding\fP command except that the default setting for new
+windows is changed. Initial setting is the encoding taken from the
+terminal.
+.RE
+.TP
+.BR "deflog on" | off
+.RS 0
+.PP
+Same as the \fBlog\fP command except that the default setting for new windows
+is changed. Initial setting is `off'.
+.RE
+.TP
+.BR "deflogin on" | off
+.RS 0
+.PP
+Same as the \fBlogin\fP command except that the default setting for new windows
+is changed. This is initialized with `on' as distributed (see config.h.in).
+.RE
+.TP
+.BI "defmode " mode
+.RS 0
+.PP
+The mode of each newly allocated pseudo-tty is set to \fImode\fP.
+\fIMode\fP is an octal number.
+When no \*Qdefmode\*U command is given, mode 0622 is used.
+.RE
+.TP
+.BR "defmonitor on" | off
+.RS 0
+.PP
+Same as the \fBmonitor\fP command except that the default setting for new
+windows is changed. Initial setting is `off'.
+.RE
+.TP
+.BR "defmousetrack on" | off
+.RS 0
+.PP
+Same as the \fBmousetrack\fP command except that the default setting for new
+windows is changed. Initial setting is `off'.
+.RE
+.TP
+.BR "defnonblock on" | off | \fInumsecs\fP
+.RS 0
+.PP
+Same as the \fBnonblock\fP command except that the default setting for
+displays is changed. Initial setting is `off'.
+.RE
+.TP
+.BI "defobuflimit " limit
+.RS 0
+.PP
+Same as the \fBobuflimit\fP command except that the default setting for new displays is changed. Initial setting is 256 bytes.
+Note that you can use the special 'OL' terminal capability if you
+want to have a dependency on the terminal type.
+.RE
+.TP
+.BI "defscrollback " num
+.RS 0
+.PP
+Same as the \fBscrollback\fP command except that the default setting for new
+windows is changed. Initial setting is 100.
+.RE
+.TP
+.BI "defshell " command
+.RS 0
+.PP
+Synonym to the \fBshell\fP .screenrc command. See there.
+.RE
+.TP
+.BR "defsilence on" | off
+.RS 0
+.PP
+Same as the \fBsilence\fP command except that the default setting for new
+windows is changed. Initial setting is `off'.
+.RE
+.TP
+.BI "defslowpaste " msec
+.RS 0
+.PP
+Same as the \fBslowpaste\fP command except that the default setting for new
+windows is changed. Initial setting is 0 milliseconds, meaning `off'.
+.RE
+.TP
+.BR "defutf8 on" | off
+.RS 0
+.PP
+Same as the \fButf8\fP command except that the default setting for new
+windows is changed. Initial setting is `on' if screen was started with
+\*Q\-U\*U, otherwise `off'.
+.RE
+.TP
+.BR "defwrap on" | off
+.RS 0
+.PP
+Same as the \fBwrap\fP command except that the default setting for new
+windows is changed. Initially line-wrap is on and can be toggled with the
+\*Qwrap\*U command (\*QC-a r\*U) or by means of "C-a : wrap on|off".
+.RE
+.TP
+.BR "defwritelock on" | off | auto
+.RS 0
+.PP
+Same as the \fBwritelock\fP command except that the default setting for new
+windows is changed. Initially writelocks will off.
+.RE
+.TP
+.BR "detach " [ \-h ]
+.RS 0
+.PP
+Detach the
+.I screen
+session (disconnect it from the terminal and put it into the background).
+This returns you to the shell where you invoked
+.IR screen .
+A detached
+.I screen
+can be resumed by invoking
+.I screen
+with the
+.B \-r
+option (see also section \*QCOMMAND-LINE OPTIONS\*U). The
+.B \-h
+option tells screen to immediately close the connection to the
+terminal (\*Qhangup\*U).
+.RE
+.TP
+.B dinfo
+.RS 0
+.PP
+Show what screen thinks about your terminal. Useful if you want to know
+why features like color or the alternate charset don't work.
+.RE
+.TP
+.B displays
+.RS 0
+.PP
+Shows a tabular listing of all currently connected user front-ends (displays).
+This is most useful for multiuser sessions.
+The following keys can be used in displays list:
+.PP
+.TS
+allbox tab(@);
+l l.
+\fBk\fP, \fBC-p\fP, or \fBup\fP@Move up one line.
+\fBj\fP, \fBC-n\fP, or \fBdown\fP@Move down one line.
+\fBC-a\fP or \fBhome\fP@Move to the first line.
+\fBC-e\fP or \fBend\fP@Move to the last line.
+\fBC-u\fP or \fBC-d\fP@Move one half page up or down.
+\fBC-b\fP or \fBC-f\fP@Move one full page up or down.
+\fBmouseclick\fP@T{
+Move to the selected line. Available
+when \*Qmousetrack\*U is set to on.
+T}
+\fBspace\fP@Refresh the list
+\fBd\fP@Detach that display
+\fBD\fP@Power detach that display
+\fBC-g\fP, \fBenter\fP, or \fBescape\fP@Exit the list
+.TE
+.PP
+The following is an example of what \*Qdisplays\*U could look like:
+.RS
+.nf
+xterm 80x42 jnweiger@/dev/ttyp4 0(m11) &rWx
+facit 80x24 mlschroe@/dev/ttyhf nb 11(tcsh) rwx
+xterm 80x42 jnhollma@/dev/ttyp5 0(m11) &R.x
+ (A) (B) (C) (D) (E) (F)(G) (H)(I)
+.fi
+.RE
+.PP
+The legend is as follows:
+.IP
+(A) The terminal type known by screen for this display.
+.PP
+(B) Displays geometry as width x height.
+.PP
+(C) Username who is logged in at the display.
+.PP
+(D) Device name of the display or the attached device
+.PP
+(E) Display is in blocking or nonblocking mode.
+The available modes are "nb", "NB", "Z<", "Z>", and "BL".
+.PP
+(F) Number of the window
+.PP
+(G) Name/title of window
+.PP
+(H) Whether the window is shared
+.PP
+(I) Window permissions. Made up of three characters:
+.PP
+.RS
+.nf
+ (1st character)
+ ‘\-’ : no read
+ ‘r’ : read
+ ‘R’ : read only due to foreign wlock
+ (2nd character)
+ ‘\-’ : no write
+ ‘.’ : write suppressed by foreign wlock
+ ‘w’ : write
+ ‘W’ : own wlock
+ (3rd character)
+ ‘\-’ : no execute
+ ‘x’ : execute
+.fi
+.RS
+\*QDisplays\*U needs a region size of at least 10 characters wide and 5 characters high in
+order to display.
+.RE
+.TP
+.IR "\fBdigraph\fR " [ preset [ unicode-value ]]
+.RS 0
+.PP
+This command prompts the user for a digraph sequence. The next
+two characters typed are looked up in a builtin table and the
+resulting character is inserted in the input stream. For example,
+if the user enters 'a"', an a-umlaut will be inserted. If the
+first character entered is a 0 (zero),
+.I screen
+will treat the following characters (up to three) as an octal
+number instead. The optional argument
+.I preset
+is treated as user input, thus one can create an \*Qumlaut\*U key.
+For example the command "bindkey ^K digraph '"'" enables the user
+to generate an a-umlaut by typing CTRL-K a.
+When a non-zero
+.I unicode-value
+is specified, a new digraph is created with the specified preset. The digraph is unset
+if a zero value is provided for the
+.I unicode-value.
+.RE
+.TP
+.B dumptermcap
+.RS 0
+.PP
+Write the termcap entry for the virtual terminal optimized for the currently
+active window to the file \*Q.termcap\*U in the user's
+\*Q$HOME/.screen\*U directory (or wherever
+.I screen
+stores its sockets. See the \*QFILES\*U section below).
+This termcap entry is identical to the value of the environment variable
+$TERMCAP that is set up by
+.I screen
+for each window. For terminfo based systems you will need to run a converter
+like
+.IR captoinfo
+and then compile the entry with
+.IR tic .
+.RE
+.TP
+.BR "dynamictitle on" | off
+.RS 0
+.PP
+Change behaviour for windows regarding if screen should change window title
+when seeing proper escape sequence. See also "TITLES (naming windows)" section.
+.RE
+.TP
+.BR "echo " [ \-n ] " \fImessage\fP"
+.RS 0
+.PP
+The echo command may be used to annoy
+.I screen
+users with a 'message of the
+day'. Typically installed in a global /local/etc/screenrc.
+The option \*Q\-n\*U may be used to suppress the line feed.
+See also \*Qsleep\*U.
+Echo is also useful for online checking of environment variables.
+.RE
+.TP
+.BI "encoding " "enc " \fR[\fP enc \fR]\fP
+.RS 0
+.PP
+Tell
+.I screen
+how to interpret the input/output. The first argument
+sets the encoding of the current window. Each window can emulate
+a different encoding. The optional second parameter overwrites
+the encoding of the connected terminal. It should never be
+needed as screen uses the locale setting to detect the encoding.
+There is also a way to select a terminal encoding depending on
+the terminal type by using the \*QKJ\*U termcap entry.
+.PP
+Supported encodings are eucJP, SJIS, eucKR, eucCN, Big5, GBK,
+KOI8-R, KOI8-U, CP1251, UTF-8,
+ISO8859-2, ISO8859-3, ISO8859-4, ISO8859-5, ISO8859-6,
+ISO8859-7, ISO8859-8, ISO8859-9, ISO8859-10, ISO8859-15, jis.
+.PP
+See also \*Qdefencoding\*U, which changes the default setting of a new
+window.
+.RE
+.TP
+.BI "escape " xy
+.RS 0
+.PP
+Set the command character to \fIx\fP and the character generating a literal
+command character (by triggering the \*Qmeta\*U command) to \fIy\fP (similar
+to the \-e option).
+Each argument is either a single character, a two-character sequence
+of the form \*Q^x\*U (meaning \*QC-x\*U), a backslash followed by an octal
+number (specifying the ASCII code of the character), or a backslash followed
+by a second character, such as \*Q\e^\*U or \*Q\e\e\*U.
+The default is \*Q^Aa\*U.
+.RE
+.TP
+.RI "\fBeval\fP " command1 [ "command2 …" ]
+.RS 0
+.PP
+Parses and executes each argument as separate command.
+.RE
+.TP
+.IR "\fBexec\fP " [[ fdpat ] "newcommand " [ "args …" ]]
+.RS 0
+.PP
+Run a unix subprocess (specified by an executable path \fInewcommand\fP and its
+optional arguments) in the current window. The flow of data between
+newcommands stdin/stdout/stderr, the process originally started in the window
+(let us call it "application-process") and screen itself (window) is
+controlled by the file descriptor pattern fdpat.
+This pattern is basically a three character sequence representing stdin, stdout
+and stderr of newcommand. A dot (.) connects the file descriptor
+to
+.IR screen .
+An exclamation mark (!) causes the file
+descriptor to be connected to the application-process. A colon (:) combines
+both.
+User input will go to newcommand unless newcommand receives the
+application-process'
+output (fdpats first character is `!' or `:') or a pipe symbol (|) is added
+(as a fourth character) to the end of fdpat.
+.PP
+Invoking `exec' without arguments shows name and arguments of the currently
+running subprocess in this window. Only one subprocess a time can be running
+in each window.
+.PP
+When a subprocess is running the `kill' command will affect it instead of the
+windows process.
+.PP
+Refer to the postscript file `doc/fdpat.ps' for a confusing illustration
+of all 21 possible combinations. Each drawing shows the digits 2,1,0
+representing the three file descriptors of newcommand. The box marked
+`W' is the usual pty that has the application-process on its slave side.
+The box marked `P' is the secondary pty that now has
+.I screen
+at its master side.
+.PP
+Abbreviations: Whitespace between the word `exec' and fdpat and the
+command can be omitted. Trailing dots and a fdpat consisting only of
+dots can be omitted. A simple `|' is synonymous for the pattern
+`!..|'; the word exec can be omitted here and can always be replaced
+by `!'.
+.PP
+Examples:
+.RS
+.TP
+exec … /bin/sh
+.TP
+exec /bin/sh
+.TP
+!/bin/sh
+.sp
+Creates another shell in the same window, while the original shell is still
+running. Output of both shells is displayed and user input is sent to the new
+/bin/sh.
+.TP
+exec !.. stty 19200
+.TP
+exec ! stty 19200
+.TP
+!!stty 19200
+.sp 1
+Set the speed of the window's tty. If your stty command operates on stdout,
+then add another `!'.
+.TP
+exec !..| less
+.TP
+|less
+.sp 1
+This adds a pager to the window output. The special character `|' is needed to
+give the user control over the pager although it gets its input from the
+window's process. This works, because
+.I less
+listens on stderr (a behavior that
+.I screen
+would not expect without the `|')
+when its stdin is not a tty.
+.I Less
+versions newer than 177 fail miserably here; good old
+.I pg
+still works.
+.TP
+!:sed \-n s/.*Error.*/\e007/p
+.sp 1
+Sends window output to both, the user and the sed command. The sed inserts an
+additional bell character (oct. 007) to the window output seen by
+.IR screen .
+This will cause "Bell in window x" messages, whenever the string "Error"
+appears in the window.
+.RE
+.RE
+.TP
+.B fit
+.RS 0
+.PP
+Change the window size to the size of the current region. This
+command is needed because screen doesn't adapt the window size
+automatically if the window is displayed more than once.
+.RE
+.TP
+.B flow
+.RB [ on | off | "auto\fR]\fP"
+.RS 0
+.PP
+Sets the flow-control mode for this window.
+Without parameters it cycles the current window's flow-control setting from
+"automatic" to "on" to "off".
+See the discussion on \*QFLOW-CONTROL\*U later on in this document for full
+details and note, that this is subject to change in future releases.
+Default is set by `defflow'.
+.RE
+.TP
+.BR "focus " [ next|prev|up|down|left|right|top|bottom ]
+.RS 0
+.PP
+Move the input focus to the next region. This is done in a cyclic
+way so that the top left region is selected after the bottom right
+one. If no option is given it defaults to `next'. The next
+region to be selected is determined by how the regions are layered.
+Normally, the next region in the same layer would be selected.
+However, if that next region contains one or more layers, the first
+region in the highest layer is selected first. If you are at the
+last region of the current layer, `next' will move the focus
+to the next region in the lower layer (if there is a lower layer).
+`Prev' cycles in the opposite order. See \*Qsplit\*U for more
+information about layers.
+
+The rest of the options (`up', `down', `left',
+`right', `top', and `bottom') are more indifferent
+to layers. The option `up' will move the focus upward to the
+region that is touching the upper left corner of the current region.
+`Down' will move downward to the region that is touching the
+lower left corner of the current region. The option `left'
+will move the focus leftward to the region that is touching the
+upper left corner of the current region, while `right' will
+move rightward to the region that is touching the upper right corner
+of the current region. Moving left from a left most region or moving
+right from a right most region will result in no action.
+
+The option `top' will move the focus to the very first region
+in the upper list corner of the screen, and `bottom' will move
+to the region in the bottom right corner of the screen. Moving up from
+a top most region or moving down from a bottom most region will result
+in no action.
+
+Useful bindings are (h, j, k, and l as in vi)
+.nf
+ bind h focus left
+ bind j focus down
+ bind k focus up
+ bind l focus right
+ bind t focus top
+ bind b focus bottom
+.fi
+Note that \fBk\fP is traditionally bound to the \fIkill\fP command.
+.RE
+.TP
+.BI "focusminsize [ ( " width "|max|_ ) ( " height "|max|_ ) ]"
+.RS 0
+.PP
+This forces any currently selected region to be automatically
+resized at least a certain \fIwidth\fP and \fIheight\fP. All
+other surrounding regions will be resized in order to accommodate.
+This constraint follows everytime the \*Qfocus\*U command is
+used. The \*Qresize\*U command can be used to increase either
+dimension of a region, but never below what is set with
+\*Qfocusminsize\*U. The underscore `_' is a synonym for
+\fBmax\fP. Setting a \fIwidth\fP and \fIheight\fP of `0 0'
+(zero zero) will undo any constraints and allow for manual resizing.
+Without any parameters, the minimum width and height is shown.
+.RE
+.TP
+.BR "gr " [ on | off ]
+.RS 0
+.PP
+Turn GR charset switching on/off. Whenever screen sees an input
+character with the 8th bit set, it will use the charset stored in the
+GR slot and print the character with the 8th bit stripped. The
+default (see also \*Qdefgr\*U) is not to process GR switching because
+otherwise the ISO88591 charset would not work.
+.RE
+.TP
+.IR "\fBgroup\fP " [ grouptitle ]
+.RS 0
+.PP
+Change or show the group the current window belongs to. Windows can
+be moved around between different groups by specifying the name of
+the destination group. Without specifying a group, the title of the
+current group is displayed.
+.RE
+.TP
+.IR "\fBhardcopy\fP " [ \-h "] [" file ]
+.RS 0
+.PP
+Writes out the currently displayed image to the file \fIfile\fP,
+or, if no filename is specified, to \fIhardcopy.n\fP in the
+default directory, where \fIn\fP is the number of the current window.
+This either appends or overwrites the file if it exists. See below.
+If the option \fB\-h\fP is specified, dump also the contents of the
+scrollback buffer.
+.RE
+.TP
+.BR "hardcopy_append on" | off
+.RS 0
+.PP
+If set to "on",
+.I screen
+will append to the "hardcopy.n" files created by the command \*QC-a h\*U,
+otherwise these files are overwritten each time.
+Default is `off'.
+.RE
+.TP
+.BI "hardcopydir "directory
+.RS 0
+.PP
+Defines a directory where hardcopy files will be placed. If unset, hardcopys
+are dumped in
+.IR screen 's
+current working directory.
+.RE
+.TP
+.BR "hardstatus " [ on | off ]
+.TP
+.BR "hardstatus \fR[\fBalways\fR]\fBfirstline" | lastline | message | ignore [ \fIstring\fR ]
+.TP
+.BR "hardstatus string" [ \fIstring\fR ]
+.RS 0
+.PP
+This command configures the use and emulation of the terminal's
+hardstatus line. The first form
+toggles whether
+.I screen
+will use the hardware status line to display messages. If the
+flag is set to `off', these messages
+are overlaid in reverse video mode at the display line. The default
+setting is `on'.
+.P
+The second form tells
+.I screen
+what to do if the terminal doesn't
+have a hardstatus line (i.e. the termcap/terminfo capabilities
+"hs", "ts", "fs" and "ds" are not set).
+When \*Qfirstline/lastline\*U is used,
+.I screen
+will reserve the first/last line of the display for
+the hardstatus. \*Qmessage\*U uses
+.I screen's
+message mechanism and
+\*Qignore\*U tells
+.I screen
+never to display the hardstatus.
+If you prepend the word \*Qalways\*U to the type (e.g., \*Qalwayslastline\*U),
+.I screen
+will use the type even if the terminal supports a hardstatus.
+.P
+The third form specifies the contents of the hardstatus line. '%h' is
+used as default string, i.e., the stored hardstatus of the current
+window (settable via \*QESC]0;<string>^G\*U or \*QESC_<string>ESC\e\*U)
+is displayed. You can customize this to any string you like including
+the escapes from the \*QSTRING ESCAPES\*U chapter. If you leave out
+the argument
+.IR string ,
+the current string is displayed.
+.P
+You can mix the second and third form by providing the string as
+additional argument.
+.RE
+.TP
+.BR "height " [ \-w | \-d "] [" \fIlines\fR " [" \fIcols\fR ]]
+.RS 0
+.PP
+Set the display height to a specified number of lines. When no argument
+is given it toggles between 24 and 42 lines display. You can also
+specify a width if you want to change both values.
+The
+.B \-w
+option tells screen to leave the display size unchanged and just set
+the window size,
+.B \-d
+vice versa.
+.RE
+.TP
+.BR help [ \fIclass\fP ]
+.RS 0
+.PP
+Not really a online help, but
+displays a help
+.I screen
+showing you all the key bindings.
+The first pages list all the internal commands followed by their current
+bindings.
+Subsequent pages will display the custom commands, one command per key.
+Press space when you're done reading each page, or return to exit early.
+All other characters are ignored. If the \*Q\-c\*U option is given,
+display all bound commands for the specified command class.
+See also \*QDEFAULT KEY BINDINGS\*U section.
+.RE
+.TP
+.B history
+.RS 0
+.PP
+Usually users work with a shell that allows easy access to previous commands.
+For example csh has the command \*Q!!\*U to repeat the last command executed.
+.I Screen
+allows you to have a primitive way of re-calling \*Qthe command that
+started …\*U: You just type the first letter of that command, then hit
+`C-a {' and
+.I screen
+tries to find a previous line that matches with the `prompt character'
+to the left of the cursor. This line is pasted into this window's input queue.
+Thus you have a crude command history (made up by the visible window and its
+scrollback buffer).
+.RE
+.TP
+.BI "hstatus " status
+.RS 0
+.PP
+Change the window's hardstatus line to the string \fIstatus\fP.
+.RE
+.TP
+.IR "\fBidle\fR " [ timeout [ "cmd-args" ]]
+.RS 0
+.PP
+Sets a command that is run after the specified number of seconds
+inactivity is reached. This command will normally be the \*Qblanker\*U
+command to create a screen blanker, but it can be any screen command.
+If no command is specified, only the timeout is set. A timeout of
+zero (or the special timeout \fBoff\fP) disables the timer.
+If no arguments are given, the current settings are displayed.
+.RE
+.TP
+.BR "ignorecase " [ on | off ]
+.RS 0
+.PP
+Tell screen to ignore the case of characters in searches. Default is
+`off'. Without any options, the state of ignorecase is toggled.
+.RE
+.TP
+.B info
+.RS 0
+.PP
+Uses the message line to display some information about the current window:
+the cursor position in the form \*Q(column,row)\*U starting with \*Q(1,1)\*U,
+the terminal width and height plus the size of the scrollback buffer in lines,
+like in \*Q(80,24)+50\*U, the current state of window XON/XOFF flow control
+is shown like this (See also section FLOW CONTROL):
+
+.nf
+ +flow automatic flow control, currently on.
+ \-flow automatic flow control, currently off.
+ +(+)flow flow control enabled. Agrees with automatic control.
+ \-(+)flow flow control disabled. Disagrees with automatic control.
+ +(\-)flow flow control enabled. Disagrees with automatic control.
+ \-(\-)flow flow control disabled. Agrees with automatic control.
+.fi
+
+The current line wrap setting (`+wrap' indicates enabled, `\-wrap' not) is
+also shown. The flags `ins', `org', `app', `log', `mon' or `nored' are
+displayed when the window is in insert mode, origin mode,
+application-keypad mode, has output logging,
+activity monitoring or partial redraw enabled.
+
+The currently active character set (\fIG0\fP, \fIG1\fP, \fIG2\fP,
+or \fIG3\fP) and in square brackets the terminal character sets that are
+currently designated as \fIG0\fP through \fIG3\fP is shown. If the window
+is in UTF-8 mode, the string \*QUTF-8\*U is shown instead.
+
+Additional modes depending on the type of the window are displayed at the end of the status line (See also chapter \*QWINDOW TYPES\*U).
+.PP
+If the state machine of the terminal emulator is in a non-default state,
+the info line is started with a string identifying the current state.
+.PP
+For system information use the \*Qtime\*U command.
+.RE
+.TP
+.BR ins_reg " [" \fIkey ]
+.RS 0
+.PP
+No longer exists, use \*Qpaste\*U instead.
+.RE
+.TP
+.B kill
+.RS 0
+.PP
+Kill current window.
+.PP
+If there is an `exec' command running then it is killed. Otherwise the process
+(shell) running in the window receives a HANGUP condition,
+the window structure is removed and
+.I screen
+(your display) switches to another
+window. When the last window is destroyed,
+.I screen
+exits.
+After a kill
+.I screen
+switches to the previously displayed window.
+.PP
+Note:
+.I Emacs
+users should keep this command in mind, when killing a line.
+It is recommended not to use \*QC-a\*U as the
+.I screen
+escape key or to rebind kill to \*QC-a K\*U.
+.RE
+.TP
+.B lastmsg
+.RS 0
+.PP
+Redisplay the last contents of the message/status line.
+Useful if you're typing when a message appears, because the message goes
+away when you press a key (unless your terminal has a hardware status line).
+Refer to the commands \*Qmsgwait\*U and \*Qmsgminwait\*U for fine tuning.
+.RE
+.TP
+.BR "layout new " [\fItitle\fP]
+.RS 0
+.PP
+Create a new layout. The screen will change to one whole region
+and be switched to the blank window. From here, you build the
+regions and the windows they show as you desire. The new layout
+will be numbered with the smallest available integer, starting
+with zero. You can optionally give a title to your new layout.
+Otherwise, it will have a default title of \*Qlayout\*U. You
+can always change the title later by using the command
+\fBlayout title\fP.
+.RE
+.TP
+.BR "layout remove " [\fIn|title\fP]
+.RS 0
+.PP
+Remove, or in other words, delete the specified layout. Either
+the number or the title can be specified. Without either
+specification, \fIscreen\fP will remove the current layout.
+
+Removing a layout does not affect your set windows or regions.
+.RE
+.TP
+.B layout next
+.RS 0
+.PP
+Switch to the next layout available
+.RE
+.TP
+.B layout prev
+.RS 0
+.PP
+Switch to the previous layout available
+.RE
+.TP
+.BR "layout select " [\fIn|title\fP]
+.RS 0
+.PP
+Select the desired layout. Either the number or the title can
+be specified. Without either specification, \fIscreen\fP will
+prompt and ask which screen is desired. To see which layouts are
+available, use the \fBlayout show\fP command.
+.RE
+.TP
+.B layout show
+.RS 0
+.PP
+List on the message line the number(s) and title(s) of the available
+layout(s). The current layout is flagged.
+.RE
+.TP
+.BR "layout title " [\fItitle\fP]
+.RS 0
+.PP
+Change or display the title of the current layout. A string given
+will be used to name the layout. Without any options, the current
+title and number is displayed on the message line.
+.RE
+.TP
+.BR "layout number " [\fIn\fP]
+.RS 0
+.PP
+Change or display the number of the current layout. An integer given
+will be used to number the layout. Without any options, the current
+number and title is displayed on the message line.
+.RE
+.TP
+.BR "layout attach " [\fItitle\fP|\fB:last\fP]
+.RS 0
+.PP
+Change or display which layout to reattach back to. The default is
+\fB:last\fP, which tells \fIscreen\fP to reattach back to the last
+used layout just before detachment. By supplying a title, You can
+instruct \fIscreen\fP to reattach to a particular layout regardless
+which one was used at the time of detachment. Without any options,
+the layout to reattach to will be shown in the message line.
+.RE
+.TP
+.BR "layout save " [\fIn|title\fP]
+.RS 0
+.PP
+Remember the current arrangement of regions. When used, \fIscreen\fP
+will remember the arrangement of vertically and horizontally split
+regions. This arrangement is restored when a \fIscreen\fP session
+is reattached or switched back from a different layout. If the
+session ends or the \fIscreen\fP process dies, the layout
+arrangements are lost. The \fBlayout dump\fP command should help
+in this siutation. If a number
+or title is supplied, \fIscreen\fP will remember the arrangement of
+that particular layout. Without any options, \fIscreen\fP will
+remember the current layout.
+
+Saving your regions can be done automatically by using the
+\fBlayout autosave\fP command.
+.RE
+.TP
+.BR "layout autosave " [\fBon|off\fP]
+.RS 0
+.PP
+Change or display the status of automatcally saving layouts. The
+default is \fBon\fP, meaning when \fIscreen\fP is detached or
+changed to a different layout, the arrangement of regions and windows
+will be remembered at the time of change and restored upon return.
+If autosave is set to \fBoff\fP, that arrangement will only be
+restored to either to the last manual save, using \fBlayout save\fP,
+or to when the layout was first created, to a single region with
+a single window. Without either an \fBon\fP or \fBoff\fP, the
+current status is displayed on the message line.
+.RE
+.TP
+.BR "layout dump " [\fIfilename\fP]
+.RS 0
+.PP
+Write to a file the order of splits made in the current layout. This
+is useful to recreate the order of your regions used in your current
+layout. Only the current layout is recorded. While the order of the
+regions are recorded, the sizes of those regions and which windows
+correspond to which regions are not. If no filename is specified,
+the default is \fIlayout-dump\fP, saved in the directory that the
+\fIscreen\fP process was started in. If the file already exists,
+\fBlayout dump\fP will append to that file. As an example:
+.PP
+.nf
+ C-a : layout dump /home/user/.screenrc
+.fi
+.PP
+will save or append the layout to the user's \fI.screenrc\fP file.
+.RE
+.TP
+.B license
+.RS 0
+.PP
+Display the disclaimer page. This is done whenever
+.I screen
+is started without options, which should be often enough. See also
+the \*Qstartup_message\*U command.
+.RE
+.TP
+.B lockscreen
+.RS 0
+.PP
+Lock this display.
+Call a screenlock program (/local/bin/lck or /usr/bin/lock or a builtin if no
+other is available). Screen does not accept any command keys until this program
+terminates. Meanwhile processes in the windows may continue, as the windows
+are in the `detached' state. The screenlock program may be changed through the
+environment variable $LOCKPRG (which must be set in the shell from which
+.I screen
+is started) and is executed with the user's uid and gid.
+.PP
+Warning:
+When you leave other shells unlocked and you have no password set on
+.IR screen ,
+the lock is void: One could easily re-attach from an unlocked
+shell. This feature should rather be called `lockterminal'.
+.RE
+.TP
+.BR "log " [ on | off ]
+.RS 0
+.PP
+Start/stop writing output of the current window to a file
+\*Qscreenlog.\fIn\fP\*U in the window's default directory, where \fIn\fP
+is the number of the current window. This filename can be changed with
+the `logfile' command. If no parameter is given, the state
+of logging is toggled. The session log is appended to the previous contents
+of the file if it already exists. The current contents and the contents
+of the scrollback history are not included in the session log.
+Default is `off'.
+.RE
+.TP
+.BI "logfile " filename
+.TP
+.BI "logfile flush " secs
+.RS 0
+.PP
+Defines the name the log files will get. The default is
+\*Qscreenlog.%n\*U. The second form changes the number of seconds
+.I screen
+will wait before flushing the logfile buffer to the file-system. The
+default value is 10 seconds.
+.RE
+.TP
+.BR "login " [ on | off ]
+.RS 0
+.PP
+Adds or removes the entry in the utmp database file for the current window.
+This controls if the window is `logged in'.
+When no parameter is given, the login state of the window is toggled.
+Additionally to that toggle, it is convenient having a `log in' and a `log out'
+key. E.\|g. `bind I login on' and `bind O login off' will map these
+keys to be C-a I and C-a O.
+The default setting (in config.h.in) should be \*Qon\*U for a
+.I screen
+that runs under suid-root.
+Use the \*Qdeflogin\*U command to change the default login state for new
+windows. Both commands are only present when
+.I screen
+has been compiled with utmp support.
+.RE
+.TP
+.BR "logtstamp " [ on | off ]
+.TP
+.IR "\fBlogtstamp after\fR " [ secs ]
+.TP
+.B "logtstamp string"
+.RS 0
+.RI [ string ]
+.PP
+This command controls logfile time-stamp mechanism of
+.I screen.
+If
+time-stamps are turned \*Qon\*U,
+.I screen
+adds a string containing
+the current time to the logfile after two minutes of inactivity.
+When output continues and more than another two minutes have passed,
+a second time-stamp is added to document the restart of the
+output. You can change this timeout with the second form
+of the command. The third form is used for customizing the time-stamp
+string (`\-\- %n:%t \-\- time-stamp \-\- %M/%d/%y %c:%s \-\-\\n' by
+default).
+.RE
+.TP
+.B mapdefault
+.RS 0
+.PP
+Tell
+.I screen
+that the next input character should only be looked up
+in the default bindkey table. See also \*Qbindkey\*U.
+.RE
+.TP
+.B mapnotnext
+.RS 0
+.PP
+Like mapdefault, but don't even look in the default bindkey table.
+.RE
+.TP
+.IR "\fImaptimeout\fR " [ timeout ]
+.RS 0
+.PP
+Set the inter-character timer for input sequence detection to a timeout
+of
+.I timeout
+ms. The default timeout is 300ms. Maptimeout with no arguments shows
+the current setting.
+See also \*Qbindkey\*U.
+.RE
+.TP
+.BI "markkeys " string
+.RS 0
+.PP
+This is a method of changing the keymap used for copy/history mode.
+The string is made up of \fIoldchar\fP=\fInewchar\fP pairs which are
+separated by `:'. Example: The string \*QB=^B:F=^F\*U will change the
+keys `C-b' and `C-f' to the vi style binding (scroll up/down fill page).
+This happens to be the default binding for `B' and `F'.
+The command \*Qmarkkeys h=^B:l=^F:$=^E\*U would set the mode for an emacs-style
+binding.
+If your terminal sends characters, that cause you to abort copy mode,
+then this command may help by binding these characters to do nothing.
+The no-op character is `@' and is used like this: \*Qmarkkeys
+@=L=H\*U if you do not want to use the `H' or `L' commands any longer.
+As shown in this example, multiple keys can be assigned to one function in a
+single statement.
+.RE
+.TP
+.BI "maxwin " num
+.RS 0
+.PP
+Set the maximum window number screen will create. Doesn't affect
+already existing windows. The number can be increased only when there are no
+existing windows.
+.RE
+.TP
+.B meta
+.RS 0
+.PP
+Insert the command character (C-a) in the current window's input stream.
+.RE
+.TP
+.BR "monitor " [ on | off ]
+.RS 0
+.PP
+Toggles activity monitoring of windows.
+When monitoring is turned on and an affected window is switched into the
+background, you will receive the activity notification message in the
+status line at the first sign of output and the window will also be marked
+with an `@' in the window-status display.
+Monitoring is initially off for all windows.
+.RE
+.TP
+.BR "mousetrack " [ on | off ]
+.RS 0
+.PP
+This command determines whether
+.I screen
+will watch for
+mouse clicks. When this command is enabled, regions that have
+been split in various ways can be selected by pointing to them
+with a mouse and left-clicking them. Without specifying \fBon\fP
+or \fBoff\fP, the current state is displayed. The default state
+is determined by the \*Qdefmousetrack\*U command.
+.RE
+.TP
+.BI "msgminwait " sec
+.RS 0
+.PP
+Defines the time
+.I screen
+delays a new message when one message is currently displayed.
+The default is 1 second.
+.RE
+.TP
+.BI "msgwait " sec
+.RS 0
+.PP
+Defines the time a message is displayed if
+.I screen
+is not disturbed by other activity. The default is 5 seconds.
+.RE
+.TP
+.BR "multiuser on" | off
+.RS 0
+.PP
+Switch between singleuser and multiuser mode. Standard
+.I screen
+operation is singleuser. In multiuser mode the commands `acladd',
+`aclchg', `aclgrp' and `acldel'
+can be used to enable (and disable) other users accessing this
+.I screen
+session.
+.RE
+.TP
+.BR "nethack on" | off
+.RS 0
+.PP
+Changes the kind of error messages used by
+.IR screen .
+When you are familiar with the game \*Qnethack\*U, you may enjoy the
+nethack-style messages which will often blur the facts a little, but are
+much funnier to read. Anyway, standard messages often tend to be unclear as
+well.
+.br
+This option is only
+available if
+.I screen
+was compiled with the NETHACK flag defined. The
+default setting is then determined by the presence of the environment
+variable $NETHACKOPTIONS and the file ~/.nethackrc - if either one is present,
+the default is \fBon\fP.
+.RE
+.TP
+.B next
+.RS 0
+.PP
+Switch to the next window.
+This command can be used repeatedly to cycle through the list of windows.
+.RE
+.TP
+.B nonblock
+.RB [ on | off | \fInumsecs ]
+.RS 0
+.PP
+Tell screen how to deal with user interfaces (displays) that cease to
+accept output. This can happen if a user presses ^S or a TCP/modem
+connection gets cut but no hangup is received. If nonblock is
+\fBoff\fP (this is the default) screen waits until the display
+restarts to accept the output. If nonblock is \fBon\fP, screen
+waits until the timeout is reached (\fBon\fP is treated as 1s). If the
+display still doesn't receive characters, screen will consider
+it \*Qblocked\*U and stop sending characters to it. If at
+some time it restarts to accept characters, screen will unblock
+the display and redisplay the updated window contents.
+.RE
+.TP
+.BR "number " [[+|\-] \fIn ]
+.RS 0
+.PP
+Change the current window's number. If the given number \fIn\fP is already
+used by another window, both windows exchange their numbers. If no argument is
+specified, the current window number (and title) is shown. Using `+' or `\-'
+will change the window's number by the relative amount specified.
+.RE
+.TP
+.BR "obuflimit " [ \fIlimit ]
+.RS 0
+.PP
+If the output buffer contains more bytes than the specified limit, no
+more data will be
+read from the windows. The default value is 256. If you have a fast
+display (like xterm), you can set it to some higher value. If no
+argument is specified, the current setting is displayed.
+.RE
+.TP
+.B only
+.RS 0
+.PP
+Kill all regions but the current one.
+.RE
+.TP
+.B other
+.RS 0
+.PP
+Switch to the window displayed previously. If this window does no longer exist,
+\fIother\fP has the same effect as \fInext\fP.
+.RE
+.TP
+.BR "partial on" | off
+.RS 0
+.PP
+Defines whether the display should be refreshed (as with \fIredisplay\fP) after
+switching to the current window. This command only affects the current window.
+To immediately affect all windows use the \fIallpartial\fP command.
+Default is `off', of course. This default is fixed, as there is currently no
+\fIdefpartial\fP command.
+.RE
+.TP
+.BR "password " [ \fIcrypted_pw ]
+.RS 0
+.PP
+Present a crypted password in your \*Q.screenrc\*U file and
+.I screen
+will ask
+for it, whenever someone attempts to resume a detached. This is useful
+if you have privileged programs running under
+.I screen
+and you want to protect your session from reattach attempts by another user
+masquerading as your uid (i.e. any superuser.)
+If no crypted password is specified,
+.I screen
+prompts twice for typing a
+password and places its encryption in the paste buffer.
+Default is `none', this disables password checking.
+.RE
+.TP
+.IR "\fBpaste\fR " [ registers " [" dest_reg ]]
+.RS 0
+.PP
+Write the (concatenated) contents of the specified registers to the stdin queue
+of the current window. The register '.' is treated as the
+paste buffer. If no parameter is given the user is prompted for a single
+register to paste.
+The paste buffer can be filled with the \fIcopy\fP, \fIhistory\fP and
+\fIreadbuf\fP commands.
+Other registers can be filled with the \fIregister\fP, \fIreadreg\fP and
+\fIpaste\fP commands.
+If \fIpaste\fP is called with a second argument, the contents of the specified
+registers is pasted into the named destination register rather than
+the window. If '.' is used as the second argument, the displays paste buffer is
+the destination.
+Note, that \*Qpaste\*U uses a wide variety of resources: Whenever a second
+argument is specified no current window is needed. When the source specification
+only contains registers (not the paste buffer) then there need not be a current
+display (terminal attached), as the registers are a global resource. The
+paste buffer exists once for every user.
+.RE
+.TP
+.BR "pastefont " [ on | off ]
+.RS 0
+.PP
+Tell
+.I screen
+to include font information in the paste buffer. The
+default is not to do so. This command is especially useful for
+multi character fonts like kanji.
+.RE
+.TP
+.B pow_break
+.RS 0
+.PP
+Reopen the window's terminal line and send a break condition. See `break'.
+.RE
+.TP
+.B pow_detach
+.RS 0
+.PP
+Power detach.
+Mainly the same as \fIdetach\fP, but also sends a HANGUP signal to
+the parent process of
+.IR screen .
+CAUTION: This will result in a logout, when
+.I screen
+was started from your login-shell.
+.RE
+.TP
+.IR "\fBpow_detach_msg\fP " [ message ]
+.RS 0
+.PP
+The \fImessage\fP specified here is output whenever a `Power detach' was
+performed. It may be used as a replacement for a logout message or to reset
+baud rate, etc.
+Without parameter, the current message is shown.
+.RE
+.TP
+.B prev
+.RS 0
+.PP
+Switch to the window with the next lower number.
+This command can be used repeatedly to cycle through the list of windows.
+.RE
+.TP
+.IR "\fBprintcmd\fP " [ cmd ]
+.RS 0
+.PP
+If
+.I cmd
+is not an empty string,
+.I screen
+will not use the terminal capabilities
+\*Qpo/pf\*U if it detects an ansi print sequence
+.BR "ESC [ 5 i" ,
+but pipe the output into
+.IR cmd .
+This should normally be a command like \*Qlpr\*U or
+\*Q'cat > /tmp/scrprint'\*U.
+.B printcmd
+without a command displays the current setting.
+The ansi sequence
+.B "ESC \e"
+ends printing and closes the pipe.
+.PP
+Warning: Be careful with this command! If other user have write
+access to your terminal, they will be able to fire off print commands.
+.RE
+.TP
+.BR process " [" \fIkey ]
+.RS 0
+.PP
+Stuff the contents of the specified register into
+.IR screen 's
+input queue. If no argument is given you are prompted for a
+register name. The text is parsed as if it had been typed in from the user's
+keyboard. This command can be used to bind multiple actions to a single key.
+.RE
+.TP
+.B quit
+.RS 0
+.PP
+Kill all windows and terminate
+.IR screen .
+Note that on VT100-style terminals the keys C-4 and C-\e are identical.
+This makes the default bindings dangerous:
+Be careful not to type C-a C-4 when selecting window no. 4.
+Use the empty bind command (as in \*Qbind '^\e'\*U) to remove a key binding.
+.RE
+.TP
+.IR "\fBreadbuf\fP " [ encoding "] [" filename ]
+.RS 0
+.PP
+Reads the contents of the specified file into the paste buffer.
+You can tell screen the encoding of the file via the \fB\-e\fP option.
+If no file is specified, the screen-exchange filename is used.
+See also \*Qbufferfile\*U command.
+.RE
+.TP
+.IR "\fBreadreg\fP " [ encoding "] [" register " [" filename ]]
+.RS 0
+.PP
+Does one of two things, dependent on number of arguments: with zero or one
+arguments it it duplicates the paste buffer contents into the register specified
+or entered at the prompt. With two arguments it reads the contents of the named
+file into the register, just as \fIreadbuf\fP reads the screen-exchange file
+into the paste buffer.
+You can tell screen the encoding of the file via the \fB\-e\fP option.
+The following example will paste the system's password file into
+the
+.I screen
+window (using register p, where a copy remains):
+.PP
+.nf
+ C-a : readreg p /etc/passwd
+C-a : paste p
+.fi
+.RE
+.TP
+.B redisplay
+.RS 0
+.PP
+Redisplay the current window. Needed to get a full redisplay when in
+partial redraw mode.
+.RE
+.TP
+.RI "\fBregister\fP " \fR[\fP \fB\-e\fR encoding ] key-string
+.RS 0
+.PP
+Save the specified \fIstring\fP to the register \fIkey\fP.
+The encoding of the string can be specified via the \fB\-e\fP option.
+See also the \*Qpaste\*U command.
+.RE
+.TP
+.B "remove"
+.RS 0
+.PP
+Kill the current region. This is a no-op if there is only one region.
+.RE
+.TP
+.B "removebuf"
+.RS 0
+.PP
+Unlinks the screen-exchange file used by the commands \*Qwritebuf\*U and
+\*Qreadbuf\*U.
+.RE
+.TP
+.B "rendition bell" | monitor | silence | so " \fIattr\fR " \fR[\fP \fIcolor\fP \fR]\fP
+.RS 0
+.PP
+Change the way
+.I screen
+renders the titles of windows that have monitor or bell flags set in caption or hardstatus or windowlist. See the \*QSTRING ESCAPES\*U chapter for the syntax of the modifiers.
+The default for monitor is currently \*Q=b \*U (bold, active colors), for bell \*Q=ub \*U (underline, bold and active colors), and \*Q=u \*U for silence.
+.RE
+.TP
+.B "reset"
+.RS 0
+.PP
+Reset the virtual terminal to its \*Qpower-on\*U values. Useful when strange
+settings (like scroll regions or graphics character set) are left over from
+an application.
+.RE
+.TP
+.B "resize"
+.RB [ -h | -v | -b | -l | -p ]
+.RB [[ + | - ]
+.IR n "[%]"
+.RB | = | max | min | _ | 0 ]
+.RS 0
+.PP
+Resize the current region. The space will be removed from or added to
+the surrounding regions depending on the order of the splits.
+The available options for resizing are `-h'(horizontal),
+`-v'(vertical), `-b'(both), `-l'(local to layer),
+and `-p'(perpendicular). Horizontal resizes will add or remove width
+to a region, vertical will add or remove height, and both will add or
+remove size from both dimensions. Local and perpendicular are similar to
+horizontal and vertical, but they take in account of how a region was split.
+If a region's last split was horizontal, a local resize will work like a
+vertical resize. If a region's last split was vertical, a local resize will
+work like a horizontal resize. Perpendicular resizes work in opposite of
+local resizes. If no option is specified, local is the default.
+
+The amount of lines to add or remove can be expressed a couple of different
+ways. By specifying a number \fIn\fP by itself will resize the region by
+that absolute amount. You can specify a relative amount by prefixing a
+plus `+' or minus `-' to the amount, such as adding +\fIn\fP lines
+or removing -\fIn\fP lines. Resizing can also be expressed as an absolute
+or relative percentage by postfixing a percent sign `%'. Using zero
+`0' is a synonym for `min' and using an underscore `_' is a
+synonym for `max'.
+
+Some examples are:
+.TP
+resize +N
+increase current region by N
+.TP
+resize \-N
+decrease current region by N
+.TP
+resize N
+set current region to N
+.TP
+resize 20%
+set current region to 20% of original size
+.TP
+resize +20%
+increase current region by 20%
+.TP
+resize -b =
+make all windows equally
+.TP
+resize max
+maximize current region
+.TP
+resize min
+minimize current region
+.PP
+Without any arguments,
+.I screen
+will prompt for how you would like to resize the current region.
+
+See \*Qfocusminsize\*U if you want to restrict the minimun size a region
+can have.
+.RE
+.RE
+.TP
+.B "screen \fP[\fI\-opts\fP] [\fIn\fP] [\fIcmd\fP [\fIargs\fP]|\fB//group\fP]"
+.RS 0
+.PP
+Establish a new window.
+The flow-control options (\fB\-f\fP, \fB\-fn\fP and \fB\-fa\fP),
+title (a.\|k.\|a.) option (\fB\-t\fP), login options (\fB\-l\fP and \fB\-ln\fP)
+, terminal type option (\fB\-T\fP <term>), the all-capability-flag (\fB\-a\fP)
+and scrollback option (\fB\-h\fP <num>) may be specified with each command.
+The option (\fB\-M\fP) turns monitoring on for this window.
+The option (\fB\-L\fP) turns output logging on for this window.
+If an optional number \fIn\fP in the range 0..MAXWIN-1 is given,
+the window number \fIn\fP is assigned to the newly created window
+(or, if this number is already in-use, the next available number).
+If a command is specified after \*Qscreen\*U, this command (with the given
+arguments) is started in the window; otherwise, a shell is created.
+If \fB//group\fP is supplied, a container-type window is created in
+which other windows may be created inside it.
+.PP
+Thus, if your \*Q.screenrc\*U contains the lines
+.sp
+.nf
+ # example for .screenrc:
+ screen 1
+ screen \-fn \-t foobar \-L 2 telnet foobar
+.fi
+.sp
+.I screen
+creates a shell window (in window #1) and a window with a TELNET connection
+to the machine foobar (with no flow-control using the title \*Qfoobar\*U
+in window #2) and will write a logfile (\*Qscreenlog.2\*U) of the telnet
+session.
+Note, that unlike previous versions of
+.I screen
+no additional default window is created when \*Qscreen\*U commands are
+included in your \*Q.screenrc\*U file. When the initialization is completed,
+.I screen
+switches to the last window specified in your .screenrc file or, if none,
+opens a default window #0.
+.PP
+Screen has built in some functionality of \*Qcu\*U and \*Qtelnet\*U.
+See also chapter \*QWINDOW TYPES\*U.
+.RE
+.TP
+.B "scrollback \fP\fInum\fP"
+.RS 0
+.PP
+Set the size of the scrollback buffer for the current windows to \fInum\fP
+lines. The default scrollback is 100 lines.
+See also the \*Qdefscrollback\*U command and use \*Qinfo\*U to view the
+current setting. To access and use the contents in the scrollback buffer,
+use the \*Qcopy\*U command.
+.RE
+.TP
+.BR "select " [ \fIWindowID ]
+.RS 0
+.PP
+Switch to the window identified by \fIWindowID\fP.
+This can be a prefix of a window title (alphanumeric window name) or a
+window number.
+The parameter is optional and if omitted, you get prompted for an identifier.
+When a new window is established, the first available number
+is assigned to this window.
+Thus, the first window can be activated by \*Qselect 0\*U.
+The number of windows is limited at compile-time by the MAXWIN
+configuration parameter (which defaults to 40).
+There are two special WindowIDs, \*Q\-\*U selects the
+internal blank window and \*Q.\*U selects the current window. The
+latter is useful if used with screen's \*Q\-X\*U option.
+.RE
+.TP
+.BR "sessionname " [ \fIname ]
+.RS 0
+.PP
+Rename the current session. Note, that for \*Qscreen \-list\*U the
+name shows up with the process-id prepended. If the argument \*Qname\*U
+is omitted, the name of this session is displayed. Caution: The $STY
+environment variables will still reflect the old name in pre-existing
+shells. This may result in confusion. Use of this command is generally
+discouraged. Use the \*Q\-S\*U command-line option if you want to
+name a new session.
+The default is constructed from the tty and host names.
+.RE
+.TP
+.IR "\fBsetenv\fR " [ var " [" string ]]
+.RS 0
+.PP
+Set the environment variable \fIvar\fP to value \fIstring\fP.
+If only \fIvar\fP is specified, the user will be prompted to enter a value.
+If no parameters are specified, the user will be prompted for both variable
+and value. The environment is inherited by all subsequently forked shells.
+.RE
+.TP
+.BR "setsid " [ on | off ]
+.RS 0
+.PP
+Normally screen uses different sessions and process groups for
+the windows. If setsid is turned \fIoff\fP, this is not done
+anymore and all windows will be in the same process group as the
+screen backend process. This also breaks job-control, so be careful.
+The default is \fIon\fP, of course. This command is probably useful
+only in rare circumstances.
+.RE
+.TP
+.B "shell \fIcommand\fP"
+.RS 0
+.PP
+Set the command to be used to create a new shell.
+This overrides the value of the environment variable $SHELL.
+This is useful if you'd like to run a tty-enhancer which is expecting to
+execute the program specified in $SHELL.
+If the command begins with a '\-' character, the shell will be started as a
+login-shell. Typical shells do only minimal initialization when not started as a login-shell.
+E.g. Bash will not read your \*Q~/.bashrc\*U unless it is a login-shell.
+.RE
+.TP
+.B "shelltitle \fItitle\fP"
+.RS 0
+.PP
+Set the title for all shells created during startup or by
+the C-A C-c command.
+For details about what a title is, see the discussion
+entitled \*QTITLES (naming windows)\*U.
+.RE
+.TP
+.BR "silence " [ on | off "|\fIsec\fP]"
+.RS 0
+.PP
+Toggles silence monitoring of windows.
+When silence is turned on and an affected window is switched into the
+background, you will receive the silence notification message in the
+status line after a specified period of inactivity (silence). The default
+timeout can be changed with the `silencewait' command or by specifying a
+number of seconds instead of `on' or `off'.
+Silence is initially off for all windows.
+.RE
+.TP
+.BI "silencewait " sec
+.RS 0
+.PP
+Define the time that all windows monitored for silence should wait before
+displaying a message. Default 30 seconds.
+.sp
+.ne
+.B "sleep \fP\fInum\fP"
+.RS 0
+.PP
+This command will pause the execution of a .screenrc file for \fInum\fP seconds.
+Keyboard activity will end the sleep.
+It may be used to give users a chance to read the messages output by \*Qecho\*U.
+.RE
+.TP
+.B "slowpaste \fImsec\fP"
+.RS 0
+.PP
+Define the speed at which text is inserted into the current window by the
+paste ("C-a ]") command.
+If the slowpaste value is nonzero text is written character by character.
+.I screen
+will make a pause of \fImsec\fP milliseconds after each single character write
+to allow the application to process its input. Only use slowpaste if your
+underlying system exposes flow control problems while pasting large amounts of
+text.
+.RE
+.TP
+.B sort
+.RS 0
+.PP
+Sort the windows in alphabetical order of the window tiles.
+.RE
+.TP
+.BI "source " file
+.RS 0
+.PP
+Read and execute commands from file \fIfile\fP. Source commands may
+be nested to a maximum recursion level of ten. If file is not an
+absolute path and screen is already processing a source command, the
+parent directory of the running source command file is used to search
+for the new command file before screen's current directory.
+
+Note that termcap/terminfo/termcapinfo commands only work at
+startup and reattach time, so they must be reached via the
+default screenrc files to have an effect.
+.RE
+.TP
+.IR "\fBsorendition\fR " [ attr [ color ]]
+.RS 0
+.PP
+This command is deprecated. See "rendition so" instead.
+.RE
+.TP
+.BR split [ \-v ]
+.RS 0
+.PP
+Split the current region into two new ones. All regions on the
+display are resized to make room for the new region. The blank
+window is displayed in the new region. The default is to create
+a horizontal split, putting the new regions on the top and
+bottom of each other. Using `-v' will create a vertical split,
+causing the new regions to appear side by side of each other.
+Use the \*Qremove\*U or the \*Qonly\*U command to delete regions.
+Use \*Qfocus\*U to toggle between regions.
+
+When a region is split opposite of how it was previously split
+(that is, vertical then horizontal or horizontal then vertical),
+a new layer is created. The layer is used to group together the
+regions that are split the same. Normally, as a user, you should
+not see nor have to worry about layers, but they will affect how
+some commands (\*Qfocus\*U and \*Qresize\*U) behave.
+
+With this current implementation of screen, scrolling data
+will appear much slower in a vertically split region than one
+that is not. This should be taken into consideration if you need
+to use system commands such as \*Qcat\*U or \*Qtail -f\*U.
+.RE
+.TP
+.B "startup_message on\fP|\fBoff"
+.RS 0
+.PP
+Select whether you want to see the copyright notice during startup.
+Default is `on', as you probably noticed.
+.RE
+.TP
+.BR "status " [ top | up | down | bottom ]
+.RB [ left | right ]
+.RS 0
+.PP
+The status window by default is in bottom-left corner. This command can move
+status messages to any corner of the screen. \fBtop\fR is the same as \fBup\fR,
+\fBdown\fR is the same as \fBbottom\fR.
+.RE
+.TP
+.BR "stuff " [ "\fIstring\fR" ]
+.RS 0
+.PP
+Stuff the string
+.I string
+in the input buffer of the current window.
+This is like the \*Qpaste\*U command but with much less overhead.
+Without a parameter, screen will prompt for a string to stuff.
+You cannot paste
+large buffers with the \*Qstuff\*U command. It is most useful for key
+bindings. See also \*Qbindkey\*U.
+.RE
+.TP
+.IR "\fBsu \fR" [ username " [" password " [" password2 ]]]
+.RS 0
+.PP
+Substitute the user of a display. The command prompts for all parameters that
+are omitted. If passwords are specified as parameters, they have to be
+specified un-crypted. The first password is matched against the systems
+passwd database, the second password is matched against the
+.I screen
+password as set with the commands \*Qacladd\*U or \*Qpassword\*U.
+\*QSu\*U may be useful for the
+.I screen
+administrator to test multiuser setups.
+.\" XXX removed in 3.8.0 XXX
+.\" but it is mainly used implicitly
+.\" by the \*Qconnect\*U command to identify users that access a remote session.
+When the identification fails, the user has access to the commands available
+for user
+.BR nobody .
+These are \*Qdetach\*U, \*Qlicense\*U, \*Qversion\*U, \*Qhelp\*U and
+\*Qdisplays\*U.
+.RE
+.TP
+.B "suspend"
+.RS 0
+.PP
+Suspend
+.IR screen .
+The windows are in the `detached' state, while
+.I screen
+is suspended. This feature relies on the shell being able to do job control.
+.RE
+.TP
+.B "term \fIterm\fP"
+.RS 0
+.PP
+In each window's environment
+.I screen
+opens, the $TERM variable is set to \*Qscreen\*U by default.
+But when no description for \*Qscreen\*U is installed in the local termcap
+or terminfo data base, you set $TERM to \- say \-
+\*Qvt100\*U. This won't do much harm, as
+.I screen
+is VT100/ANSI compatible.
+The use of the \*Qterm\*U command is discouraged for non-default purpose.
+That is, one may want to specify special $TERM settings (e.g. vt100) for the
+next \*Qscreen rlogin othermachine\*U command. Use the command \*Qscreen \-T vt100
+rlogin othermachine\*U rather than setting and resetting the default.
+.RE
+.TP
+.BI termcap " term terminal\-tweaks" \fR[\fP \fIwindow-tweaks\fR \fI]\fR
+.TP
+.BI terminfo " term terminal\-tweaks" \fR[\fP \fIwindow-tweaks\fR \fI]\fR
+.TP
+.BI termcapinfo " term terminal\-tweaks" \fR[\fP \fIwindow-tweaks\fR \fI]\fR
+.RS 0
+.PP
+Use this command to modify your terminal's termcap entry without going
+through all the hassles involved in creating a custom termcap entry.
+Plus, you can optionally customize the termcap generated for the windows.
+You have to place these commands in one of the screenrc startup files, as
+they are meaningless once the terminal emulator is booted.
+.PP
+If your system works uses the terminfo database rather than termcap,
+.I screen
+will understand the `terminfo' command, which has the same effects as the
+`termcap' command. Two separate commands are provided, as there are subtle
+syntactic differences, e.g. when parameter interpolation (using `%') is
+required. Note that termcap names of the capabilities have to be used
+with the `terminfo' command.
+.PP
+In many cases, where the arguments are valid in both terminfo and termcap
+syntax, you can use the command `termcapinfo', which is just a shorthand
+for a pair of `termcap' and `terminfo' commands with identical arguments.
+.PP
+The first argument specifies which terminal(s) should be affected by this
+definition.
+You can specify multiple terminal names by separating them with `|'s.
+Use `*' to match all terminals and `vt*' to match all terminals that begin
+with \*Qvt\*U.
+.PP
+Each \fItweak\fP argument contains one or more termcap defines (separated
+by `:'s) to be inserted at the start of the appropriate termcap entry,
+enhancing it or overriding existing values.
+The first tweak modifies your terminal's termcap, and contains definitions
+that your terminal uses to perform certain functions.
+Specify a null string to leave this unchanged (e.\|g. '').
+The second (optional) tweak modifies all the window termcaps, and should
+contain definitions that
+.I screen
+understands (see the \*QVIRTUAL TERMINAL\*U
+section).
+.PP
+Some examples:
+.IP
+termcap xterm* LP:hs@
+.PP
+Informs
+.I screen
+that all terminals that begin with `xterm' have firm auto-margins that
+allow the last position on the screen to be updated (LP), but they don't
+really have a status line (no 'hs' \- append `@' to turn entries off).
+Note that we assume `LP' for all terminal names that start with \*Qvt\*U,
+but only if you don't specify a termcap command for that terminal.
+.RS
+.nf
+termcap vt* LP
+.fi
+.RE
+.sp 1
+termcap vt102|vt220 Z0=\eE[?3h:Z1=\eE[?3l
+.PP
+Specifies the firm-margined `LP' capability for all terminals that begin with
+`vt', and the second line will also add the escape-sequences to switch
+into (Z0) and back out of (Z1) 132-character-per-line mode if this is
+a VT102 or VT220.
+(You must specify Z0 and Z1 in your termcap to use the width-changing
+commands.)
+.IP
+termcap vt100 "" l0=PF1:l1=PF2:l2=PF3:l3=PF4
+.PP
+This leaves your vt100 termcap alone and adds the function key labels to
+each window's termcap entry.
+.IP
+termcap h19|z19 am@:im=\eE@:ei=\eEO dc=\eE[P
+.PP
+Takes a h19 or z19 termcap and turns off auto-margins (am@) and enables the
+insert mode (im) and end-insert (ei) capabilities (the `@' in the `im'
+string is after the `=', so it is part of the string).
+Having the `im' and `ei' definitions put into your terminal's termcap will
+cause
+.I screen
+to automatically advertise the character-insert capability in
+each window's termcap.
+Each window will also get the delete-character capability (dc) added to its
+termcap, which
+.I screen
+will translate into a line-update for the terminal
+(we're pretending it doesn't support character deletion).
+.PP
+If you would like to fully specify each window's termcap entry, you should
+instead set the $SCREENCAP variable prior to running
+.IR screen .
+See the discussion on the \*QVIRTUAL TERMINAL\*U in this manual, and the termcap(5)
+man page for more information on termcap definitions.
+.RE
+.TP
+.B time
+.RI [ string ]
+.RS 0
+.PP
+Uses the message line to display the time of day, the host name, and the load
+averages over 1, 5, and 15 minutes (if this is available on your system).
+For window specific information, use \*Qinfo\*U.
+
+If a string is specified, it changes the format of the time report like it is
+described in the \*QSTRING ESCAPES\*U chapter. Screen uses a default of
+"%c:%s %M %d %H%? %l%?".
+.RE
+.TP
+.BR "title " [ \fIwindowtitle ]
+.RS 0
+.PP
+Set the name of the current window to \fIwindowtitle\fP. If no name is
+specified,
+.I screen
+prompts for one. This command was known as `aka' in previous
+releases.
+.RE
+.TP
+.BR "truecolor " [ on | off ]
+.RS 0
+.PP
+Enables truecolor support. Currently autodetection of truecolor support cannot
+be done reliably, as such it's left to user to enable. Default is off.
+Known terminals that may support it are: iTerm2, Konsole, st.
+Xterm includes support for truecolor escapes but converts them back to indexed
+256 color space.
+.RE
+.TP
+.BI "unbindall "
+.RS 0
+.PP
+Unbind all the bindings. This can be useful when
+screen is used solely for its detaching abilities, such as when
+letting a console application run as a daemon. If, for some reason,
+it is necessary to bind commands after this, use 'screen \-X'.
+.RE
+.TP
+.BI "unsetenv " var
+.RS 0
+.PP
+Unset an environment variable.
+.RE
+.TP
+.BR "utf8 " [ on | off [ on | off ]]
+.RS 0
+.PP
+Change the encoding used in the current window. If utf8 is enabled, the
+strings sent to the window will be UTF-8 encoded and vice versa. Omitting the
+parameter toggles the setting. If a second parameter is given, the display's
+encoding is also changed (this should rather be done with screen's \*Q\-U\*U
+option).
+See also \*Qdefutf8\*U, which changes the default setting of a new
+window.
+.RE
+.TP
+.BR "vbell " [ on | off ]
+.RS 0
+.PP
+Sets the visual bell setting for this window. Omitting the parameter
+toggles the setting. If vbell is switched on, but your terminal does not
+support a visual bell, a `vbell-message' is displayed in the status line when
+the bell character (^G) is received.
+Visual bell support of a terminal is defined by the termcap variable `vb'
+(terminfo: 'flash').
+.PP
+Per default, vbell is off, thus the audible bell is used.
+See also `bell_msg'.
+.RE
+.TP
+.IR "\fBvbell_msg\fR " [ message ]
+.RS 0
+.PP
+Sets the visual bell message. \fImessage\fP is printed to the status line if
+the window receives a bell character (^G), vbell is set to \*Qon\*U, but the
+terminal does not support a visual bell.
+The default message is \*QWuff, Wuff!!\*U.
+Without a parameter, the current message is shown.
+.RE
+.TP
+.BI "vbellwait " sec
+.RS 0
+.PP
+Define a delay in seconds after each display of
+.IR screen 's
+visual bell message. The default is 1 second.
+.RE
+.TP
+.BR "verbose " [ on | off ]
+.RS 0
+.PP
+If verbose is switched on, the command name is echoed, whenever a window
+is created (or resurrected from zombie state). Default is off.
+Without a parameter, the current setting is shown.
+.RE
+.TP
+.B version
+.RS 0
+.PP
+Print the current version and the compile date in the status line.
+.RE
+.TP
+.BI "wall " "message"
+.RS 0
+.PP
+Write a message to all displays. The message will appear in the terminal's
+status line.
+.RE
+.TP
+.BR "width " [ \-w | \-d "] [" "\fIcols\fR " [ \fIlines\fR ]]
+.RS 0
+.PP
+Toggle the window width between 80 and 132 columns or set it to \fIcols\fP
+columns if an argument is specified.
+This requires a capable terminal and the termcap entries \*QZ0\*U and \*QZ1\*U.
+See the \*Qtermcap\*U command for more information. You can also specify
+a new height if you want to change both values.
+The
+.B \-w
+option tells screen to leave the display size unchanged and just set
+the window size,
+.B \-d
+vice versa.
+.RE
+.TP
+.BR "windowlist " [ \-b "] [" \-m "] [" \-g ]
+.TP
+.IR "\fBwindowlist string\fR " [ string ]
+.TP
+.IR "\fBwindowlist title\fR " [ title ]
+.RS 0
+.PP
+Display all windows in a table for visual window selection.
+If screen was in a window group, screen will
+back out of the group and then display the windows in that group.
+If the
+.B \-b
+option is given, screen will switch to the blank window before
+presenting the list, so that the current window is also selectable.
+The
+.B \-m
+option changes the order of the windows, instead of sorting by
+window numbers screen uses its internal most-recently-used list.
+The
+.B \-g
+option will show the windows inside any groups in that level
+and downwards.
+.PP
+The following keys are used to navigate in \*Qwindowlist\*U:
+
+.TS
+allbox tab(@);
+l l.
+\fBk\fP, \fBC-p\fP, or \fBup\fP@Move up one line.
+\fBj\fP, \fBC-n\fP, or \fBdown\fP@Move down one line.
+\fBC-g\fP or \fBescape\fP@Exit windowlist.
+\fBC-a\fP or \fBhome\fP@Move to the first line.
+\fBC-e\fP or \fBend\fP@Move to the last line.
+\fBC-u\fP or \fBC-d\fP@Move one half page up or down.
+\fBC-b\fP or \fBC-f\fP@Move one full page up or down.
+\fB0..9\fP@Using the number keys, move to the selected line.
+\fBmouseclick\fP@T{
+Move to the selected line. Available when
+\*Qmousetrack\*U is set to \*Qon\*U
+T}
+\fB/\fP@Search.
+\fBn\fP@Repeat search in the forward direction.
+\fBN\fP@Repeat search in the backward direction.
+\fBm\fP@Toggle MRU.
+\fBg\fP@Toggle group nesting.
+\fBa\fP@All window view.
+\fBC-h\fP or backspace@Back out the group.
+\fB,\fP@Switch numbers with the previous window.
+\fB.\fP@Switch numbers with the next window.
+\fBK\fP@Kill that window.
+\fBspace\fP or \fBenter\fP@Select that window.
+.TE
+.sp 1
+The table format can be changed with the \fBstring\fP and
+\fBtitle\fP option, the title is displayed as table heading, while
+the lines are made by using the string setting. The default
+setting is \*QNum Name%=Flags\*U for the title and \*Q%3n %t%=%f\*U
+for the lines.
+See the \*QSTRING ESCAPES\*U chapter for more codes (e.g. color
+settings).
+
+\*QWindowlist\*U needs a region size of at least 10 characters wide
+and 6 characters high in order to display.
+.RE
+.TP
+.B windows [ string ]
+.RS 0
+.PP
+Uses the message line to display a list of all the windows.
+Each window is listed by number with the name of process that has been
+started in the window (or its title);
+the current window is marked with a `*';
+the previous window is marked with a `\-';
+all the windows that are \*Qlogged in\*U are marked with a `$';
+a background window that has received a bell is marked with a `!';
+a background window that is being monitored and has had activity occur
+is marked with an `@';
+a window which has output logging turned on is marked with `(L)';
+windows occupied by other users are marked with `&';
+windows in the zombie state are marked with `Z'.
+If this list is too long to fit on the terminal's status line only the
+portion around the current window is displayed.
+The optional string parameter follows the \*QSTRING ESCAPES\*U format.
+If string parameter is passed, the output size is unlimited.
+The default command without any parameter is limited to a size of 1024 bytes.
+.RE
+.TP
+.BR "wrap " [ on | off ]
+.RS 0
+.PP
+Sets the line-wrap setting for the current window.
+When line-wrap is on, the second consecutive printable character output at
+the last column of a line will wrap to the start of the following line.
+As an added feature, backspace (^H) will also wrap through the left margin
+to the previous line.
+Default is `on'. Without any options, the state of wrap is toggled.
+.RE
+.TP
+.BR "writebuf " [ \-e " \fIencoding\fP" "" "] [" \fIfilename\fR ]
+.RS 0
+.PP
+Writes the contents of the paste buffer to the specified file, or the public accessible screen\-exchange
+file if no filename is given. This is thought of as a primitive means of communication between
+.I screen
+users on the same host. If an encoding is specified the paste buffer
+is recoded on the fly to match the encoding.
+The filename can be set with the \fIbufferfile\fP
+command and defaults to \*Q/tmp/screen\-exchange\*U.
+.RE
+.TP
+.BR "writelock " [ on | "off\fR|\fBauto\fR]"
+.RS 0
+.PP
+In addition to access control lists, not all users may be able to write to
+the same window at once. Per default, writelock is in `auto' mode and
+grants exclusive input permission to the user who is the first to switch
+to the particular window. When he leaves the window, other users may obtain
+the writelock (automatically). The writelock of the current window is disabled
+by the command \*Qwritelock off\*U. If the user issues the command
+\*Qwritelock on\*U he keeps the exclusive write permission while switching
+to other windows.
+.RE
+.TP
+.B xoff
+.TP
+.B xon
+.RS 0
+.PP
+Insert a CTRL-s / CTRL-q character to the stdin queue of the
+current window.
+.RE
+.TP
+.BR "zmodem " [ off\fR|\fPauto\fR|\fPcatch\fR|\fPpass ]
+.TP
+.IR "\fBzmodem sendcmd\fR " [ string ]
+.TP
+.IR "\fBzmodem recvcmd\fR " [ string ]
+.RS 0
+.PP
+Define zmodem support for screen. Screen understands two different
+modes when it detects a zmodem request: \*Qpass\*U and \*Qcatch\*U.
+If the mode is set to \*Qpass\*U, screen will relay all data
+to the attacher until the end of the transmission is reached.
+In \*Qcatch\*U mode screen acts as a zmodem endpoint and starts
+the corresponding rz/sz commands. If the mode is set to \*Qauto\*U,
+screen will use \*Qcatch\*U if the window is a tty (e.g. a serial line),
+otherwise it will use \*Qpass\*U.
+.PP
+You can define the templates screen uses in \*Qcatch\*U mode
+via the second and the third form.
+.PP
+Note also that this is an experimental feature.
+.RE
+.TP
+.BR "zombie " [\fIkeys\fP [ onerror ] ]
+.RS 0
+.PP
+Per default
+.I screen
+windows are removed from the window list as soon as
+the windows process (e.g. shell) exits. When a string of two keys is
+specified to the zombie command, `dead' windows will remain in the list.
+The \fBkill\fP command may be used to remove such a window. Pressing the
+first key in the dead window has the same effect. When pressing the second
+key,
+.I screen
+will attempt to resurrect the window. The process that was
+initially running in the window will be launched again. Calling \fBzombie\fP
+without parameters will clear the zombie setting, thus making windows disappear
+when their process exits.
+
+As the zombie-setting is manipulated globally for all windows, this command
+should probably be called \fBdefzombie\fP, but it isn't.
+
+Optionally you can put the word \*Qonerror\*U after the keys. This will cause screen
+to monitor exit status of the process running in the window. If it exits normally ('0'),
+the window disappears. Any other exit value causes the window to become a zombie.
+.RE
+.TP
+.BR "zombie_timeout" [\fIseconds\fP]
+.RS 0
+.PP
+Per default
+.I screen
+windows are removed from the window list as soon as
+the windows process (e.g. shell) exits. If \fBzombie\fP keys are defined
+(compare with above \fBzombie\fP command), it is possible to also set a
+timeout when screen tries to automatically reconnect a dead screen window.
+.RE
+
+.SH "THE MESSAGE LINE"
+.I Screen
+displays informational messages and other diagnostics in a \fImessage line\fP.
+While this line is distributed to appear at the bottom of the screen,
+it can be defined to appear at the top of the screen during compilation.
+If your terminal has a status line defined in its termcap,
+.I screen
+will use this for displaying its messages, otherwise a line of the
+current screen will
+be temporarily overwritten and output will be momentarily interrupted. The
+message line is automatically removed after a few seconds delay, but it
+can also be removed early (on terminals without a status line) by beginning
+to type.
+.PP
+The message line facility can be used by an application running in
+the current window by means of the ANSI \fIPrivacy message\fP
+control sequence.
+For instance, from within the shell, try something like:
+.IP
+echo '<esc>^Hello world from window '$WINDOW'<esc>\e\e'
+.PP
+where '<esc>' is an \fIescape\fP, '^' is a literal up-arrow,
+and '\e\e' turns into a single backslash.
+
+.SH "WINDOW TYPES"
+Screen provides three different window types. New windows are created with
+.IR screen 's
+.B screen
+command (see also the entry in chapter \*QCUSTOMIZATION\*U). The first
+parameter to the
+.B screen
+command defines which type of window is created. The different window types are
+all special cases of the normal type. They have been added in order
+to allow
+.I screen
+to be used efficiently as a console multiplexer with 100 or more windows.
+
+.IP \(bu 3
+The normal window contains a shell (default, if no parameter is given) or any
+other system command that could be executed from a shell (e.g.
+.BR slogin ,
+etc…)
+
+.IP \(bu
+If a tty (character special device) name (e.g. \*Q/dev/ttya\*U)
+is specified as the first parameter, then the window is directly connected to
+this device.
+This window type is similar to \*Qscreen cu \-l /dev/ttya\*U.
+Read and write access is required on the device node, an exclusive open is
+attempted on the node to mark the connection line as busy.
+An optional parameter is allowed consisting of a comma separated list of flags
+in the notation used by stty(1):
+.RS
+.IP <baud_rate>
+Usually 300, 1200, 9600 or 19200. This affects transmission as well as receive speed.
+.IP "cs8 or cs7"
+Specify the transmission of eight (or seven) bits per byte.
+.IP "ixon or \-ixon"
+Enables (or disables) software flow-control (CTRL-S/CTRL-Q) for sending data.
+.IP "ixoff or \-ixoff"
+Enables (or disables) software flow-control for receiving data.
+.IP "istrip or \-istrip"
+Clear (or keep) the eight bit in each received byte.
+.PP
+You may want to specify as many of these options as applicable. Unspecified
+options cause the terminal driver to make up the parameter values of the
+connection. These values are system dependent and may be in defaults or values
+saved from a previous connection.
+.PP
+For tty windows, the
+.B info
+command shows some of the modem control lines
+in the status line. These may include `RTS', `CTS', 'DTR', `DSR', `CD' and more.
+This depends on the available ioctl()'s and system header files as well as the
+on the physical capabilities of the serial board.
+Signals that are logical low (inactive) have their name preceded by
+an exclamation mark (!), otherwise the signal is logical high (active).
+Signals not supported by the hardware but available to the ioctl() interface
+are usually shown low.
+.PP
+When the CLOCAL status bit is true, the whole set of modem signals is placed
+inside curly braces ({ and }).
+When the CRTSCTS or TIOCSOFTCAR bit is set, the signals `CTS' or `CD'
+are shown in parenthesis, respectively.
+.PP
+For tty windows, the command
+.B break
+causes the Data transmission line (TxD) to go low for a specified period of
+time. This is expected to be interpreted as break signal on the other side.
+No data is sent and no modem control line is changed when a
+.B break
+is issued.
+.RE
+
+.IP \(bu
+If the first parameter is \*Q//telnet\*U, the second parameter is expected to
+be a host name, and an optional third parameter may specify a TCP port number
+(default decimal 23). Screen will connect to a server listening on the remote
+host and use the telnet protocol to communicate with that server.
+.PP
+For telnet windows, the command
+.B info
+shows details about the connection in square brackets ([ and ]) at the end of
+the status line.
+.RS
+.IP b
+BINARY. The connection is in binary mode.
+.IP e
+ECHO. Local echo is disabled.
+.IP c
+SGA. The connection is in `character mode' (default: `line mode').
+.IP t
+TTYPE. The terminal type has been requested by the remote host.
+Screen sends the name \*Qscreen\*U unless instructed otherwise (see also
+the command `term').
+.IP w
+NAWS. The remote site is notified about window size changes.
+.IP f
+LFLOW. The remote host will send flow control information.
+(Ignored at the moment.)
+.PP
+Additional flags for debugging are x, t and n (XDISPLOC, TSPEED and
+NEWENV).
+.PP
+For telnet windows, the command
+.B break
+sends the telnet code IAC BREAK (decimal 243) to the remote host.
+
+
+This window type is only available if
+.I screen
+was compiled with the ENABLE_TELNET option defined.
+.RE
+
+
+.SH "STRING ESCAPES"
+Screen provides an escape mechanism to insert information like the
+current time into messages or file names. The escape character
+is '%' with one exception: inside of a window's hardstatus '^%' ('^E')
+is used instead.
+
+Here is the full list of supported escapes:
+.IP %
+the escape character itself
+.IP E
+sets %? to true if the escape character has been pressed.
+.IP f
+flags of the window, see \*Qwindows\*U for meanings of the various flags
+.IP F
+sets %? to true if the window has the focus
+.IP h
+hardstatus of the window
+.IP H
+hostname of the system
+.IP n
+window number
+.IP P
+sets %? to true if the current region is in copy/paste mode
+.IP S
+session name
+.IP s
+window size
+.IP t
+window title
+.IP u
+all other users on this window
+.IP w
+all window numbers and names. With '\-' qualifier: up to the current
+window; with '+' qualifier: starting with the window after the current
+one.
+.IP W
+all window numbers and names except the current one
+.IP x
+the executed command including arguments running in this windows
+.IP X
+the executed command without arguments running in this windows
+.IP ?
+the part to the next '%?' is displayed only if a '%' escape
+inside the part expands to a non-empty string
+.IP :
+else part of '%?'
+.IP =
+pad the string to the display's width (like TeX's hfill). If a
+number is specified, pad to the percentage of the window's width.
+A '0' qualifier tells screen to treat the number as absolute position.
+You can specify to pad relative to the last absolute pad position
+by adding a '+' qualifier or to pad relative to the right margin
+by using '\-'. The padding truncates the string if the specified
+position lies before the current position. Add the 'L' qualifier
+to change this.
+.IP <
+same as '%=' but just do truncation, do not fill with spaces
+.IP >
+mark the current text position for the next truncation. When
+screen needs to do truncation, it tries to do it in a way that
+the marked position gets moved to the specified percentage of
+the output area. (The area starts from the last absolute pad
+position and ends with the position specified by the truncation
+operator.) The 'L' qualifier tells screen to mark the truncated
+parts with '…'.
+.IP {
+attribute/color modifier string terminated by the next \*Q}\*U
+.IP `
+Substitute with the output of a 'backtick' command. The length
+qualifier is misused to identify one of the commands.
+.P
+The 'c' and 'C' escape may be qualified with a '0' to make
+.I screen
+use zero instead of space as fill character. The '0' qualifier
+also makes the '=' escape use absolute positions. The 'n' and '='
+escapes understand
+a length qualifier (e.g. '%3n'), 'D' and 'M' can be prefixed with 'L'
+to generate long names, 'w' and 'W' also show the window flags
+if 'L' is given.
+.PP
+An attribute/color modifier is is used to change the attributes or the
+color settings. Its format
+is \*Q[attribute modifier] [color description]\*U. The attribute modifier
+must be prefixed by a change type indicator if it can be confused with
+a color description. The following change types are known:
+.IP +
+add the specified set to the current attributes
+.IP \-
+remove the set from the current attributes
+.IP !
+invert the set in the current attributes
+.IP =
+change the current attributes to the specified set
+.PP
+The attribute set can either be specified as a hexadecimal number or
+a combination of the following letters:
+.IP d
+dim
+.PD 0
+.IP u
+underline
+.IP b
+bold
+.IP r
+reverse
+.IP s
+standout
+.IP B
+blinking
+.PD
+.PP
+Colors are coded either as a hexadecimal number or two letters specifying
+the desired background and foreground color (in that order). The following
+colors are known:
+.IP k
+black
+.PD 0
+.IP r
+red
+.IP g
+green
+.IP y
+yellow
+.IP b
+blue
+.IP m
+magenta
+.IP c
+cyan
+.IP w
+white
+.IP d
+default color
+.IP .
+leave color unchanged
+.PD
+.PP
+The capitalized versions of the letter specify bright colors. You can also
+use the pseudo-color 'i' to set just the brightness and leave the color
+unchanged.
+.br
+A one digit/letter color description is treated as foreground or
+background color dependent on the current attributes: if reverse mode is
+set, the background color is changed instead of the foreground color.
+If you don't like this, prefix the color with a \*Q.\*U. If you want
+the same behavior for two-letter color descriptions, also prefix them
+with a \*Q.\*U.
+.br
+As a special case, \*Q%{\-}\*U restores the attributes and colors that
+were set before the last change was made (i.e., pops one level of the
+color-change stack).
+.PP
+Examples:
+.IP "\*QG\*U"
+set color to bright green
+.IP "\*Q+b r\*U"
+use bold red
+.IP "\*Q= yd\*U"
+clear all attributes, write in default color on yellow background.
+.IP "%\-Lw%{= BW}%50>%n%f* %t%{\-}%+Lw%<"
+The available windows centered at the current window and truncated to
+the available width. The current window is displayed white on blue.
+This can be used with \*Qhardstatus alwayslastline\*U.
+.IP "%?%F%{.R.}%?%3n %t%? [%h]%?"
+The window number and title and the window's hardstatus, if one is set.
+Also use a red background if this is the active focus. Useful for
+\*Qcaption string\*U.
+.SH "FLOW-CONTROL"
+Each window has a flow-control setting that determines how
+.I screen
+deals with
+the XON and XOFF characters (and perhaps the interrupt character).
+When flow-control is turned off,
+.I screen
+ignores the XON and XOFF characters,
+which allows the user to send them to the current program by simply typing
+them (useful for the \fIemacs\fP editor, for instance).
+The trade-off is that it will take longer for output from a \*Qnormal\*U
+program to pause in response to an XOFF.
+With flow-control turned on, XON and XOFF characters are used to immediately
+pause the output of the current window.
+You can still send these characters to the current program, but you must use
+the appropriate two-character
+.I screen
+commands (typically \*QC-a q\*U (xon)
+and \*QC-a s\*U (xoff)).
+The xon/xoff commands are also useful for typing C-s and C-q past a terminal
+that intercepts these characters.
+.PP
+Each window has an initial flow-control value set with either the
+.B \-f
+option or the \*Qdefflow\*U .screenrc command. Per default the windows
+are set to automatic flow-switching.
+It can then be toggled between the three states 'fixed on', 'fixed off'
+and 'automatic' interactively with the \*Qflow\*U command bound to "C-a f".
+.PP
+The automatic flow-switching mode deals with
+flow control using the TIOCPKT mode (like \*Qrlogin\*U does). If
+the tty driver does not support TIOCPKT,
+.I screen
+tries to find out
+the right mode based on the current setting of the application
+keypad \- when it is enabled, flow-control is turned off and visa versa.
+Of course, you can still manipulate flow-control manually when needed.
+.PP
+If you're running with flow-control enabled and find that pressing the
+interrupt key (usually C-c) does not interrupt the display until another
+6-8 lines have scrolled by, try running
+.I screen
+with the \*Qinterrupt\*U
+option (add the \*Qinterrupt\*U flag to the \*Qflow\*U command in
+your .screenrc, or use the
+.B \-i
+command-line option).
+This causes the output that
+.I screen
+has accumulated from the interrupted program to be flushed.
+One disadvantage is that the virtual terminal's memory contains the
+non-flushed version of the output, which in rare cases can cause
+minor inaccuracies in the output.
+For example, if you switch screens and return, or update the screen
+with \*QC-a l\*U you would see the version of the output you would
+have gotten without \*Qinterrupt\*U being on.
+Also, you might need to turn off flow-control (or use auto-flow mode to turn
+it off automatically) when running a program that expects you to type the
+interrupt character as input, as it is possible to interrupt
+the output of the virtual terminal to your physical terminal when flow-control
+is enabled.
+If this happens, a simple refresh of the screen with \*QC-a l\*U will
+restore it.
+Give each mode a try, and use whichever mode you find more comfortable.
+
+
+.SH "TITLES (naming windows)"
+You can customize each window's name in the window display (viewed with the
+\*Qwindows\*U command (C-a w)) by setting it with one of
+the title commands.
+Normally the name displayed is the actual command name of the program
+created in the window.
+However, it is sometimes useful to distinguish various programs of the same
+name or to change the name on-the-fly to reflect the current state of
+the window.
+.PP
+The default name for all shell windows can be set with the \*Qshelltitle\*U
+command in the .screenrc file, while all other windows are created with
+a \*Qscreen\*U command and thus can have their name set with the
+.B \-t
+option.
+Interactively, there is the title-string escape-sequence
+(<esc>k\fIname\fP<esc>\e) and the \*Qtitle\*U command (C-a A).
+The former can be output from an application to control the window's name
+under software control, and the latter will prompt for a name when typed.
+You can also bind pre-defined names to keys with the \*Qtitle\*U command
+to set things quickly without prompting. Changing title bythis escape sequence
+can be controlled by \fBdefdynamictitle\fp and \fBdynamictitle\fP commands.
+.PP
+Finally,
+.I screen
+has a shell-specific heuristic that is enabled by setting the window's name
+to \*Q\fIsearch|name\fP\*U and arranging to have a null title escape-sequence
+output as a part of your prompt.
+The \fIsearch\fP portion specifies an end-of-prompt search string, while
+the \fIname\fP portion specifies the default shell name for the window.
+If the \fIname\fP ends in a `:'
+.I screen
+will add what it believes to be the current command running in the window
+to the end of the window's shell name (e.\|g. \*Q\fIname:cmd\fP\*U).
+Otherwise the current command name supersedes the shell name while it is
+running.
+.PP
+Here's how it works: you must modify your shell prompt to output a null
+title-escape-sequence (<esc>k<esc>\e) as a part of your prompt.
+The last part of your prompt must be the same as the string you specified
+for the \fIsearch\fP portion of the title.
+Once this is set up,
+.I screen
+will use the title-escape-sequence to clear the previous command name and
+get ready for the next command.
+Then, when a newline is received from the shell, a search is made for the
+end of the prompt.
+If found, it will grab the first word after the matched string and use it
+as the command name.
+If the command name begins with either '!', '%', or '^'
+.I screen
+will use the first word on the following line (if found) in preference to
+the just-found name.
+This helps csh users get better command names when using job control or
+history recall commands.
+.PP
+Here's some .screenrc examples:
+.IP
+screen \-t top 2 nice top
+.PP
+Adding this line to your .screenrc would start a nice-d version of the
+\*Qtop\*U command in window 2 named \*Qtop\*U rather than \*Qnice\*U.
+.sp
+.nf
+ shelltitle '> |csh'
+ screen 1
+.fi
+.sp
+These commands would start a shell with the given shelltitle.
+The title specified is an auto-title that would expect the prompt and
+the typed command to look something like the following:
+.IP
+/usr/joe/src/dir> trn
+.PP
+(it looks after the '> ' for the command name).
+The window status would show the name \*Qtrn\*U while the command was
+running, and revert to \*Qcsh\*U upon completion.
+.IP
+bind R screen \-t '% |root:' su
+.PP
+Having this command in your .screenrc would bind the key
+sequence \*QC-a R\*U to the \*Qsu\*U command and give it an
+auto-title name of \*Qroot:\*U.
+For this auto-title to work, the screen could look something
+like this:
+.sp
+.nf
+ % !em
+ emacs file.c
+.fi
+.sp
+Here the user typed the csh history command \*Q!em\*U which ran the
+previously entered \*Qemacs\*U command.
+The window status would show \*Qroot:emacs\*U during the execution
+of the command, and revert to simply \*Qroot:\*U at its completion.
+.PP
+.nf
+ bind o title
+ bind E title ""
+ bind u title (unknown)
+.fi
+.sp
+The first binding doesn't have any arguments, so it would prompt you
+for a title. when you type \*QC-a o\*U.
+The second binding would clear an auto-title's current setting (C-a E).
+The third binding would set the current window's title to \*Q(unknown)\*U
+(C-a u).
+.PP
+One thing to keep in mind when adding a null title-escape-sequence to
+your prompt is that some shells (like the csh) count all the non-control
+characters as part of the prompt's length.
+If these invisible characters aren't a multiple of 8 then backspacing over
+a tab will result in an incorrect display.
+One way to get around this is to use a prompt like this:
+.IP
+set prompt='^[[0000m^[k^[\e% '
+.PP
+The escape-sequence \*Q<esc>[0000m\*U not only normalizes the character
+attributes, but all the zeros round the length of the invisible characters
+up to 8.
+Bash users will probably want to echo the escape sequence in the
+PROMPT_COMMAND:
+.IP
+PROMPT_COMMAND='printf "\e033k\e033\e134"'
+.PP
+(I used \*Q\e134\*U to output a `\e' because of a bug in bash v1.04).
+
+
+.SH "THE VIRTUAL TERMINAL"
+Each window in a
+.I screen
+session emulates a VT100 terminal, with some extra functions added. The
+VT100 emulator is hard-coded, no other terminal types can be emulated.
+.br
+Usually
+.I screen
+tries to emulate as much of the VT100/ANSI standard
+as possible. But if your terminal lacks certain capabilities,
+the emulation may not be complete. In these cases
+.I screen
+has to tell the applications that some of the features
+are missing. This is no problem on machines using termcap,
+because
+.I screen
+can use the $TERMCAP variable to
+customize the standard
+.I screen
+termcap.
+.PP
+But if you do a
+rlogin on another machine or your machine supports only
+terminfo this method fails. Because of this,
+.I screen
+offers a way to deal with these cases.
+Here is how it works:
+.PP
+When
+.I screen
+tries to figure out a terminal name for itself,
+it first looks
+for an entry named \*Qscreen.<term>\*U, where <term> is
+the contents of your $TERM variable.
+If no such entry exists,
+.I screen
+tries \*Qscreen\*U (or \*Qscreen\-w\*U if the terminal is wide
+(132 cols or more)).
+If even this entry cannot be found, \*Qvt100\*U is used as a
+substitute.
+.PP
+The idea is that if you have a terminal which doesn't
+support an important feature (e.g. delete char or clear to EOS)
+you can build a new termcap/terminfo entry for
+.I screen
+(named \*Qscreen.<dumbterm>\*U) in which this capability
+has been disabled. If this entry is installed on your
+machines you are able to do
+a rlogin and still keep the correct termcap/terminfo entry.
+The terminal name is put in the $TERM variable
+of all new windows.
+.I Screen
+also sets the $TERMCAP variable reflecting the capabilities
+of the virtual terminal emulated. Notice that, however, on machines
+using the terminfo database this variable has no effect.
+Furthermore, the variable $WINDOW is set to the window number
+of each window.
+.PP
+The actual set of capabilities supported by the virtual terminal
+depends on the capabilities supported by the physical terminal.
+If, for instance, the physical terminal does not support underscore mode,
+.I screen
+does not put the `us' and `ue' capabilities into the window's $TERMCAP
+variable, accordingly.
+However, a minimum number of capabilities must be supported by a
+terminal in order to run
+.IR screen ;
+namely scrolling, clear screen, and direct cursor addressing
+(in addition,
+.I screen
+does not run on hardcopy terminals or on terminals that over-strike).
+.PP
+Also, you can customize the $TERMCAP value used by
+.I screen
+by using the \*Qtermcap\*U .screenrc command, or
+by defining the variable $SCREENCAP prior to startup.
+When the is latter defined, its value will be copied verbatim into each
+window's $TERMCAP variable.
+This can either be the full terminal definition, or a filename where the
+terminal \*Qscreen\*U (and/or \*Qscreen\-w\*U) is defined.
+.PP
+Note that
+.I screen
+honors the \*Qterminfo\*U .screenrc command if the system uses the
+terminfo database rather than termcap.
+.PP
+When the boolean `G0' capability is present in the termcap entry
+for the terminal on which
+.I screen
+has been called, the terminal emulation of
+.I screen
+supports multiple character sets.
+This allows an application to make use of, for instance,
+the VT100 graphics character set or national character sets.
+The following control functions from ISO 2022 are supported:
+\fIlock shift G0\fP (\fISI\fP), \fIlock shift G1\fP (\fISO\fP),
+\fIlock shift G2\fP, \fIlock shift G3\fP, \fIsingle shift G2\fP,
+and \fIsingle shift G3\fP.
+When a virtual terminal is created or reset, the ASCII character
+set is designated as \fIG0\fP through \fIG3\fP.
+When the `G0' capability is present,
+.I screen
+evaluates the capabilities
+`S0', `E0', and `C0' if present. `S0' is the sequence the terminal uses
+to enable and start the graphics character set rather than \fISI\fP.
+`E0' is the corresponding replacement for \fISO\fP. `C0' gives a character
+by character translation string that is used during semi-graphics mode. This
+string is built like the `acsc' terminfo capability.
+.PP
+When the `po' and `pf' capabilities are present in the terminal's
+termcap entry, applications running in a
+.I screen
+window can send output to the printer port of the terminal.
+This allows a user to have an application in one window
+sending output to a printer connected to the terminal, while all
+other windows are still active (the printer port is enabled
+and disabled again for each chunk of output).
+As a side-effect, programs running in different windows can
+send output to the printer simultaneously.
+Data sent to the printer is not displayed in the window. The
+.I info
+command displays a line starting `PRIN' while the printer is active.
+.PP
+.I Screen
+maintains a hardstatus line for every window. If a window
+gets selected, the display's hardstatus will be updated to match
+the window's hardstatus line. If the display has no hardstatus
+the line will be displayed as a standard
+.I screen
+message.
+The hardstatus line can be changed with the ANSI Application
+Program Command (APC): \*QESC_<string>ESC\e\*U. As a convenience
+for xterm users the sequence \*QESC]0..2;<string>^G\*U is
+also accepted.
+.PP
+Some capabilities are only put into the $TERMCAP
+variable of the virtual terminal if they can be efficiently
+implemented by the physical terminal.
+For instance, `dl' (delete line) is only put into the $TERMCAP
+variable if the terminal supports either delete line itself or
+scrolling regions. Note that this may provoke confusion, when
+the session is reattached on a different terminal, as the value
+of $TERMCAP cannot be modified by parent processes.
+.PP
+The "alternate screen" capability is not enabled by default.
+Set the \fBaltscreen\fP .screenrc command to enable it.
+.PP
+The following is a list of control sequences recognized by
+.IR screen .
+\*Q(V)\*U and \*Q(A)\*U indicate VT100-specific and ANSI- or
+ISO-specific functions, respectively.
+.PP
+.ta 22n
+.TP 27
+.B "ESC E"
+Next Line
+.TP 27
+.B "ESC D"
+Index
+.TP 27
+.B "ESC M"
+Reverse Index
+.TP 27
+.B "ESC H"
+Horizontal Tab Set
+.TP 27
+.B "ESC Z"
+Send VT100 Identification String
+.TP 27
+.BR "ESC 7" " (V)"
+Save Cursor and Attributes
+.TP 27
+.BR "ESC 8" " (V)"
+Restore Cursor and Attributes
+.TP 27
+.BR "ESC [s" " (A)"
+Save Cursor and Attributes
+.TP 27
+.BR "ESC [u" " (A)"
+Restore Cursor and Attributes
+.TP 27
+.B "ESC c"
+Reset to Initial State
+.TP 27
+.B "ESC g"
+Visual Bell
+.TP 27
+.B "ESC \fPPn\fB p"
+Cursor Visibility (97801)
+.RS
+.TP 27
+Pn = \fB6\fP
+Invisible
+.TP 27
+Pn = \fB7\fP
+Visible
+.RE
+.TP 27
+.BR "ESC =" " (V)"
+Application Keypad Mode
+.TP 27
+.BR "ESC >" " (V)"
+Numeric Keypad Mode
+.TP 27
+.BR "ESC # 8" " (V)"
+Fill Screen with E's
+.TP 27
+.BR "ESC \e" " (A)"
+String Terminator
+.TP 27
+.BR "ESC ^" " (A)"
+Privacy Message String (Message Line)
+.TP 27
+.B "ESC !"
+Global Message String (Message Line)
+.TP 27
+.B "ESC k"
+A.\|k.\|a. Definition String
+.TP 27
+.BR "ESC P" " (A)"
+Device Control String.
+Outputs a string directly to the host
+terminal without interpretation.
+.TP 27
+.BR "ESC _" " (A)"
+Application Program Command (Hardstatus)
+.TP 27
+.BR "ESC ] 0 ; string ^G" " (A)"
+Operating System Command (Hardstatus, xterm title hack)
+.TP 27
+.BR "ESC ] 83 ; cmd ^G" " (A)"
+Execute screen command. This only works if multi-user support is
+compiled into screen. The pseudo-user \*Q:window:\*U is used to
+check the access control list. Use \*Qaddacl :window: \-rwx #?\*U to
+create a user with no rights and allow only the needed commands.
+.TP 27
+.BR "Control-N" " (A)"
+Lock Shift G1 (SO)
+.TP 27
+.BR "Control-O" " (A)"
+Lock Shift G0 (SI)
+.TP 27
+.BR "ESC n" " (A)"
+Lock Shift G2
+.TP 27
+.BR "ESC o" " (A)"
+Lock Shift G3
+.TP 27
+.BR "ESC N" " (A)"
+Single Shift G2
+.TP 27
+.BR "ESC O" " (A)"
+Single Shift G3
+.TP 27
+.BR "ESC ( \fPPcs" " (A)"
+Designate character set as G0
+.TP 27
+.BR "ESC ) \fPPcs" " (A)"
+Designate character set as G1
+.TP 27
+.BR "ESC * \fPPcs" " (A)"
+Designate character set as G2
+.TP 27
+.BR "ESC + \fPPcs" " (A)"
+Designate character set as G3
+.TP 27
+.B "ESC [ \fPPn\fB ; \fPPn\fB H"
+Direct Cursor Addressing
+.TP 27
+.B "ESC [ \fPPn\fB ; \fPPn\fB f"
+same as above
+.TP 27
+.B "ESC [ \fPPn\fB J"
+Erase in Display
+.RS
+.TP 27
+Pn = None or \fB0\fP
+From Cursor to End of Screen
+.TP 27
+Pn = \fB1\fP
+From Beginning of Screen to Cursor
+.TP 27
+Pn = \fB2\fP
+Entire Screen
+.RE
+.TP 27
+.B "ESC [ \fPPn\fB K"
+Erase in Line
+.RS
+.TP 27
+Pn = None or \fB0\fP
+From Cursor to End of Line
+.TP 27
+Pn = \fB1\fP
+From Beginning of Line to Cursor
+.TP 27
+Pn = \fB2\fP
+Entire Line
+.RE
+.TP 27
+.B "ESC [ \fPPn\fB X"
+Erase character
+.TP 27
+.B "ESC [ \fPPn\fB A"
+Cursor Up
+.TP 27
+.B "ESC [ \fPPn\fB B"
+Cursor Down
+.TP 27
+.B "ESC [ \fPPn\fB C"
+Cursor Right
+.TP 27
+.B "ESC [ \fPPn\fB D"
+Cursor Left
+.TP 27
+.B "ESC [ \fPPn\fB E"
+Cursor next line
+.TP 27
+.B "ESC [ \fPPn\fB F"
+Cursor previous line
+.TP 27
+.B "ESC [ \fPPn\fB G"
+Cursor horizontal position
+.TP 27
+.B "ESC [ \fPPn\fB `"
+same as above
+.TP 27
+.B "ESC [ \fPPn\fB d"
+Cursor vertical position
+.TP 27
+.B "ESC [ \fPPs\fB ;\fP…\fB; \fPPs\fB m"
+Select Graphic Rendition
+.RS
+.TP 27
+Ps = None or \fB0\fP
+Default Rendition
+.TP 27
+Ps = \fB1\fP
+Bold
+.TP 27
+Ps = \fB2\fP (A)
+Faint
+.TP 27
+Ps = \fB3\fP (A)
+\fIStandout\fP Mode (ANSI: Italicized)
+.TP 27
+Ps = \fB4\fP
+Underlined
+.TP 27
+Ps = \fB5\fP
+Blinking
+.TP 27
+Ps = \fB7\fP
+Negative Image
+.TP 27
+Ps = \fB22\fP (A)
+Normal Intensity
+.TP 27
+Ps = \fB23\fP (A)
+\fIStandout\fP Mode off (ANSI: Italicized off)
+.TP 27
+Ps = \fB24\fP (A)
+Not Underlined
+.TP 27
+Ps = \fB25\fP (A)
+Not Blinking
+.TP 27
+Ps = \fB27\fP (A)
+Positive Image
+.TP 27
+Ps = \fB30\fP (A)
+Foreground Black
+.TP 27
+Ps = \fB31\fP (A)
+Foreground Red
+.TP 27
+Ps = \fB32\fP (A)
+Foreground Green
+.TP 27
+Ps = \fB33\fP (A)
+Foreground Yellow
+.TP 27
+Ps = \fB34\fP (A)
+Foreground Blue
+.TP 27
+Ps = \fB35\fP (A)
+Foreground Magenta
+.TP 27
+Ps = \fB36\fP (A)
+Foreground Cyan
+.TP 27
+Ps = \fB37\fP (A)
+Foreground White
+.TP 27
+Ps = \fB39\fP (A)
+Foreground Default
+.TP 27
+Ps = \fB40\fP (A)
+Background Black
+.TP 27
+Ps = \fB…\fP
+…
+.TP 27
+Ps = \fB49\fP (A)
+Background Default
+.RE
+.TP 27
+.B "ESC [ \fPPn\fB g"
+Tab Clear
+.RS
+.TP 27
+Pn = None or \fB0\fP
+Clear Tab at Current Position
+.TP 27
+Pn = \fB3\fP
+Clear All Tabs
+.RE
+.TP 27
+.BR "ESC [ \fPPn\fB ; \fPPn\fB r" " (V)"
+Set Scrolling Region
+.TP 27
+.BR "ESC [ \fPPn\fB I" " (A)"
+Horizontal Tab
+.TP 27
+.BR "ESC [ \fPPn\fB Z" " (A)"
+Backward Tab
+.TP 27
+.BR "ESC [ \fPPn\fB L" " (A)"
+Insert Line
+.TP 27
+.BR "ESC [ \fPPn\fB M" " (A)"
+Delete Line
+.TP 27
+.BR "ESC [ \fPPn\fB @" " (A)"
+Insert Character
+.TP 27
+.BR "ESC [ \fPPn\fB P" " (A)"
+Delete Character
+.TP 27
+.B "ESC [ \fPPn\fB S"
+Scroll Scrolling Region Up
+.TP 27
+.B "ESC [ \fPPn\fB T"
+Scroll Scrolling Region Down
+.TP 27
+.B "ESC [ \fPPn\fB ^"
+same as above
+.TP 27
+.B "ESC [ \fPPs\fB ;\fP…\fB; \fPPs\fB h"
+Set Mode
+.TP 27
+.B "ESC [ \fPPs\fB ;\fP…\fB; \fPPs\fB l"
+Reset Mode
+.RS
+.TP 27
+Ps = \fB4\fP (A)
+Insert Mode
+.TP 27
+Ps = \fB20\fP (A)
+\fIAutomatic Linefeed\fP Mode
+.TP 27
+Ps = \fB34\fP
+Normal Cursor Visibility
+.TP 27
+Ps = \fB?1\fP (V)
+Application Cursor Keys
+.TP 27
+Ps = \fB?3\fP (V)
+Change Terminal Width to 132 columns
+.TP 27
+Ps = \fB?5\fP (V)
+Reverse Video
+.TP 27
+Ps = \fB?6\fP (V)
+\fIOrigin\fP Mode
+.TP 27
+Ps = \fB?7\fP (V)
+\fIWrap\fP Mode
+.TP 27
+Ps = \fB?9\fP
+X10 mouse tracking
+.TP 27
+Ps = \fB?25\fP (V)
+Visible Cursor
+.TP 27
+Ps = \fB?47\fP
+Alternate Screen (old xterm code)
+.TP 27
+Ps = \fB?1000\fP (V)
+VT200 mouse tracking
+.TP 27
+Ps = \fB?1047\fP
+Alternate Screen (new xterm code)
+.TP 27
+Ps = \fB?1049\fP
+Alternate Screen (new xterm code)
+.RE
+.TP 27
+.BR "ESC [ 5 i" " (A)"
+Start relay to printer (ANSI Media Copy)
+.TP 27
+.BR "ESC [ 4 i" " (A)"
+Stop relay to printer (ANSI Media Copy)
+.TP 27
+.B "ESC [ 8 ; \fPPh\fB ; \fPPw\fB t"
+Resize the window to `Ph' lines and `Pw' columns (SunView special)
+.TP 27
+.B "ESC [ c"
+Send VT100 Identification String
+.TP 27
+.B "ESC [ x"
+Send Terminal Parameter Report
+.TP 27
+.B "ESC [ > c"
+Send VT220 Secondary Device Attributes String
+.TP 27
+.B "ESC [ 6 n"
+Send Cursor Position Report
+
+
+.SH "INPUT TRANSLATION"
+In order to do a full VT100 emulation
+.I screen
+has to detect
+that a sequence of characters in the input stream was generated
+by a keypress on the user's keyboard and insert the VT100
+style escape sequence. \fIScreen\fP has a very flexible way of doing
+this by making it possible to map arbitrary commands on arbitrary
+sequences of characters. For standard VT100 emulation the command
+will always insert a string in the input buffer of the window
+(see also command \fBstuff\fP in the command table).
+Because the sequences generated by a keypress can
+change after a reattach from a different terminal type, it is
+possible to bind commands to the termcap name of the keys.
+\fIScreen\fP will insert the correct binding after each
+reattach. See the \fBbindkey\fP command for further details on the
+syntax and examples.
+.PP
+Here is the table of the default key bindings. The fourth is what
+command is executed if the keyboard is switched into application
+mode.
+.PP
+.TS
+allbox;
+l l l l.
+Key name Termcap name Command App mode
+Cursor up ku \e033[A \e033OA
+Cursor down kd \e033[B \e033OB
+Cursor right kr \e033[C \e033OC
+Cursor left kl \e033[D \e033OD
+Function key 0 k0 \e033[10~
+Function key 1 k1 \e033OP
+Function key 2 k2 \e033OQ
+Function key 3 k3 \e033OR
+Function key 4 k4 \e033OS
+Function key 5 k5 \e033[15~
+Function key 6 k6 \e033[17~
+Function key 7 k7 \e033[18~
+Function key 8 k8 \e033[19~
+Function key 9 k9 \e033[20~
+Function key 10 k; \e033[21~
+Function key 11 F1 \e033[23~
+Function key 12 F2 \e033[24~
+Home kh \e033[1~
+End kH \e033[4~
+Insert kI \e033[2~
+Delete kD \e033[3~
+Page up kP \e033[5~
+Page down kN \e033[6~
+Keypad 0 f0 0 \e033Op
+Keypad 1 f1 1 \e033Oq
+Keypad 2 f2 2 \e033Or
+Keypad 3 f3 3 \e033Os
+Keypad 4 f4 4 \e033Ot
+Keypad 5 f5 5 \e033Ou
+Keypad 6 f6 6 \e033Ov
+Keypad 7 f7 7 \e033Ow
+Keypad 8 f8 8 \e033Ox
+Keypad 9 f9 9 \e033Oy
+Keypad + f+ + \e033Ok
+Keypad \- f\- \- \e033Om
+Keypad * f* * \e033Oj
+Keypad / f/ / \e033Oo
+Keypad = fq = \e033OX
+Keypad . f. . \e033On
+Keypad , f, , \e033Ol
+Keypad enter fe \e015 \e033OM
+.TE
+
+.SH SPECIAL TERMINAL CAPABILITIES
+The following table describes all terminal capabilities
+that are recognized by
+.I screen
+and are not in the termcap(5) manual.
+You can place these capabilities in your termcap entries (in
+`/etc/termcap') or use them with the commands `termcap', `terminfo' and
+`termcapinfo' in your screenrc files. It is often not possible to place
+these capabilities in the terminfo database.
+.PP
+.ta 5n
+.TP 13
+.BI LP " (bool)"
+Terminal has VT100 style margins (`magic margins'). Note that
+this capability is obsolete because
+.I screen
+uses the standard 'xn' instead.
+.TP 13
+.BI Z0 " (str)"
+Change width to 132 columns.
+.TP 13
+.BI Z1 " (str)"
+Change width to 80 columns.
+.TP 13
+.BI WS " (str)"
+Resize display. This capability has the desired width and height as
+arguments. \fISunView(tm)\fP example: '\eE[8;%d;%dt'.
+.TP 13
+.BI NF " (bool)"
+Terminal doesn't need flow control. Send ^S and ^Q direct to
+the application. Same as 'flow off'. The opposite of this
+capability is 'nx'.
+.TP 13
+.BI G0 " (bool)"
+Terminal can deal with ISO 2022 font selection sequences.
+.TP 13
+.BI S0 " (str)"
+Switch charset 'G0' to the specified charset. Default
+is '\eE(%.'.
+.TP 13
+.BI E0 " (str)"
+Switch charset 'G0' back to standard charset. Default
+is '\eE(B'.
+.TP 13
+.BI C0 " (str)"
+Use the string as a conversion table for font '0'. See
+the 'ac' capability for more details.
+.TP 13
+.BI CS " (str)"
+Switch cursor-keys to application mode.
+.TP 13
+.BI CE " (str)"
+Switch cursor-keys back to normal mode.
+.TP 13
+.BI AN " (bool)"
+Turn on autonuke. See the 'autonuke' command for more details.
+.TP 13
+.BI OL " (num)"
+Set the output buffer limit. See the 'obuflimit' command for more details.
+.TP 13
+.BI KJ " (str)"
+Set the encoding of the terminal. See the 'encoding' command for
+valid encodings.
+.TP 13
+.BI AF " (str)"
+Change character foreground color in an ANSI conform way. This
+capability will almost always be set to '\eE[3%dm' ('\eE[3%p1%dm'
+on terminfo machines).
+.TP 13
+.BI AB " (str)"
+Same as 'AF', but change background color.
+.TP 13
+.BI AX " (bool)"
+Does understand ANSI set default fg/bg color (\eE[39m / \eE[49m).
+.TP 13
+.BI XC " (str)"
+Describe a translation of characters to strings depending on the
+current font. More details follow in the next section.
+.TP 13
+.BI XT " (bool)"
+Terminal understands special xterm sequences (OSC, mouse tracking).
+.TP 13
+.BI C8 " (bool)"
+Terminal needs bold to display high-intensity colors (e.g. Eterm).
+.TP 13
+.BI TF " (bool)"
+Add missing capabilities to the termcap/info entry. (Set by default).
+
+.SH CHARACTER TRANSLATION
+\fIScreen\fP has a powerful mechanism to translate characters to arbitrary
+strings depending on the current font and terminal type.
+Use this feature if you want to work with a common standard character
+set (say ISO8851-latin1) even on terminals that scatter the more
+unusual characters over several national language font pages.
+
+Syntax:
+.nf
+ \fBXC=\fP\fI<charset-mapping>\fP{\fB,,\fP\fI<charset-mapping>\fP}
+ \fI<charset-mapping>\fP := \fI<designator><template>\fP{\fB,\fP\fI<mapping>\fP}
+ \fI<mapping>\fP := \fI<char-to-be-mapped><template-arg>\fP
+.fi
+
+The things in braces may be repeated any number of times.
+
+A \fI<charset-mapping>\fP tells
+.I screen
+how to map characters
+in font \fI<designator>\fP ('B': Ascii, 'A': UK, 'K': German, etc.)
+to strings. Every \fI<mapping>\fP describes to what string a single
+character will be translated. A template mechanism is used, as
+most of the time the codes have a lot in common (for example
+strings to switch to and from another charset). Each occurrence
+of '%' in \fI<template>\fP gets substituted with the \fI<template-arg>\fP
+specified together with the character. If your strings are not
+similar at all, then use '%' as a template and place the full
+string in \fI<template-arg>\fP. A quoting mechanism was added to make
+it possible to use a real '%'. The '\e' character quotes the
+special characters '\e', '%', and ','.
+
+Here is an example:
+
+ termcap hp700 'XC=B\eE(K%\eE(B,\e304[,\e326\e\e\e\e,\e334]'
+
+This tells
+.I screen
+how to translate ISOlatin1 (charset 'B')
+upper case umlaut characters on a hp700 terminal that has a
+German charset. '\e304' gets translated to '\eE(K[\eE(B' and so on.
+Note that this line gets parsed *three* times before the internal
+lookup table is built, therefore a lot of quoting is needed to
+create a single '\e'.
+
+Another extension was added to allow more emulation: If a mapping
+translates the unquoted '%' char, it will be sent to the terminal
+whenever
+.I screen
+switches to the corresponding \fI<designator>\fP. In this
+special case the template is assumed to be just '%' because
+the charset switch sequence and the character mappings normally
+haven't much in common.
+
+This example shows one use of the extension:
+
+ termcap xterm 'XC=K%,%\eE(B,[\e304,\e\e\e\e\e326,]\e334'
+
+Here, a part of the German ('K') charset is emulated on an xterm.
+If
+.I screen
+has to change to the 'K' charset, '\eE(B' will be sent
+to the terminal, i.e. the ASCII charset is used instead. The
+template is just '%', so the mapping is straightforward: '['
+to '\e304', '\e' to '\e326', and ']' to '\e334'.
+
+.SH ENVIRONMENT
+.PD 0
+.IP COLUMNS 15
+Number of columns on the terminal (overrides termcap entry).
+.IP HOME
+Directory in which to look for .screenrc.
+.IP LINES
+Number of lines on the terminal (overrides termcap entry).
+.IP LOCKPRG
+Screen lock program.
+.IP NETHACKOPTIONS
+Turns on nethack option.
+.IP PATH
+Used for locating programs to run.
+.IP SCREENCAP
+For customizing a terminal's TERMCAP value.
+.IP SCREENDIR
+Alternate socket directory.
+.IP SCREENRC
+Alternate user screenrc file.
+.IP SHELL
+Default shell program for opening windows (default \*Q/bin/sh\*U).
+See also \*Qshell\*U .screenrc command.
+.IP STY
+Alternate socket name.
+.IP SYSSCREENRC
+Alternate system screenrc file.
+.IP TERM
+Terminal name.
+.IP TERMCAP
+Terminal description.
+.IP WINDOW
+Window number of a window (at creation time).
+
+.SH FILES
+.PD 0
+.IP …/screen-4.?.??/etc/screenrc 34
+.IP …/screen-4.?.??/etc/etcscreenrc
+Examples in the
+.I screen
+distribution package for private and global initialization files.
+.IP $SYSSCREENRC
+.IP /usr/local/etc/screenrc
+.I screen
+initialization commands
+.IP $SCREENRC
+.IP $HOME/.screenrc
+Read in after /usr/local/etc/screenrc
+.IP $SCREENDIR/S\-<login>
+.IP /local/screens/S\-<login>
+Socket directories (default)
+.IP /usr/tmp/screens/S\-<login>
+Alternate socket directories.
+.IP "<socket directory>/.termcap"
+Written by the "termcap" output function
+.IP /usr/tmp/screens/screen\-exchange
+or
+.IP /tmp/screen\-exchange
+.I screen
+`interprocess communication buffer'
+.IP hardcopy.[0-9]
+Screen images created by the hardcopy function
+.IP screenlog.[0-9]
+Output log files created by the log function
+.IP /usr/lib/terminfo/?/*
+or
+.IP /etc/termcap
+Terminal capability databases
+.IP /etc/utmp
+Login records
+.IP $LOCKPRG
+Program that locks a terminal.
+
+
+.SH "SEE ALSO"
+termcap(5), utmp(5), vi(1), captoinfo(1), tic(1)
+
+
+.SH AUTHORS
+Originally created by Oliver Laumann. For a long time maintained
+and developed by Juergen Weigert, Michael Schroeder, Micah Cowan
+and Sadrul Habib Chowdhury. This latest version was produced by
+Amadeusz Slawinski <amade@asmblr.net>
+and Alexander Naumov <alexander_naumov@opensuse.org>.
+
+.SH COPYLEFT
+.nf
+Copyright (c) 2015-2017
+ Juergen Weigert <jnweiger@immd4.informatik.uni\-erlangen.de>
+ Alexander Naumov <alexander_naumov@opensuse.org>
+ Amadeusz Slawinski <amade@asmblr.net>
+Copyright (c) 2010-2015
+ Juergen Weigert <jnweiger@immd4.informatik.uni\-erlangen.de>
+ Sadrul Habib Chowdhury <sadrul@users.sourceforge.net>
+Copyright (c) 2008, 2009
+ Juergen Weigert <jnweiger@immd4.informatik.uni\-erlangen.de>
+ Michael Schroeder <mlschroe@immd4.informatik.uni\-erlangen.de>
+ Micah Cowan <micah@cowan.name>
+ Sadrul Habib Chowdhury <sadrul@users.sourceforge.net>
+Copyright (C) 1993-2003
+ Juergen Weigert <jnweiger@immd4.informatik.uni\-erlangen.de>
+ Michael Schroeder <mlschroe@immd4.informatik.uni\-erlangen.de>
+Copyright (C) 1987 Oliver Laumann
+.fi
+.PP
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+.PP
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+.PP
+You should have received a copy of the GNU General Public License
+along with this program (see the file COPYING); if not, write to the
+Free Software Foundation, Inc.,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+
+.SH CONTRIBUTORS
+.nf
+Eric S. Raymond <esr@thyrsus.com>,
+Thomas Renninger <treen@suse.com>,
+Axel Beckert <abe@deuxchevaux.org>,
+Ken Beal <kbeal@amber.ssd.csd.harris.com>,
+Rudolf Koenig <rfkoenig@immd4.informatik.uni\-erlangen.de>,
+Toerless Eckert <eckert@immd4.informatik.uni\-erlangen.de>,
+Wayne Davison <davison@borland.com>,
+Patrick Wolfe <pat@kai.com, kailand!pat>,
+Bart Schaefer <schaefer@cse.ogi.edu>,
+Nathan Glasser <nathan@brokaw.lcs.mit.edu>,
+Larry W. Virden <lvirden@cas.org>,
+Howard Chu <hyc@hanauma.jpl.nasa.gov>,
+Tim MacKenzie <tym@dibbler.cs.monash.edu.au>,
+Markku Jarvinen <mta@{cc,cs,ee}.tut.fi>,
+Marc Boucher <marc@CAM.ORG>,
+Doug Siebert <dsiebert@isca.uiowa.edu>,
+Ken Stillson <stillson@tsfsrv.mitre.org>,
+Ian Frechett <frechett@spot.Colorado.EDU>,
+Brian Koehmstedt <bpk@gnu.ai.mit.edu>,
+Don Smith <djs6015@ultb.isc.rit.edu>,
+Frank van der Linden <vdlinden@fwi.uva.nl>,
+Martin Schweikert <schweik@cpp.ob.open.de>,
+David Vrona <dave@sashimi.lcu.com>,
+E. Tye McQueen <tye%spillman.UUCP@uunet.uu.net>,
+Matthew Green <mrg@eterna.com.au>,
+Christopher Williams <cgw@pobox.com>,
+Matt Mosley <mattm@access.digex.net>,
+Gregory Neil Shapiro <gshapiro@wpi.WPI.EDU>,
+Johannes Zellner <johannes@zellner.org>,
+Pablo Averbuj <pablo@averbuj.com>.
+.fi
+
+.SH AVAILABILITY
+The latest official release of
+.I screen
+available via anonymous ftp from ftp.gnu.org/gnu/screen/ or any other
+.I GNU
+distribution site. The home site of
+.I screen
+is savannah.gnu.org/projects/screen/. If you want to help, send a note to
+screen-devel@gnu.org.
+
+.SH BUGS
+.PD
+.IP \(bu 3
+`dm' (delete mode) and `xs' are not handled
+correctly (they are ignored). `xn' is treated as a magic-margin
+indicator.
+.IP \(bu
+.I Screen
+has no clue about double-high or double-wide characters.
+But this is the only area where
+.I vttest
+is allowed to fail.
+.IP \(bu
+It is not possible to change the environment variable $TERMCAP when
+reattaching under a different terminal type.
+.IP \(bu
+The support of terminfo based systems is very limited. Adding extra
+capabilities to $TERMCAP may not have any effects.
+.IP \(bu
+.I Screen
+does not make use of hardware tabs.
+.IP \(bu
+.I Screen
+must be installed as set-uid with owner root on most systems in order
+to be able to correctly change the owner of the tty device file for
+each window.
+Special permission may also be required to write the file \*Q/etc/utmp\*U.
+.IP \(bu
+Entries in \*Q/etc/utmp\*U are not removed when
+.I screen
+is killed with SIGKILL.
+This will cause some programs (like "w" or "rwho")
+to advertise that a user is logged on who really isn't.
+.IP \(bu
+.I Screen
+may give a strange warning when your tty has no utmp entry.
+.IP \(bu
+When the modem line was hung up,
+.I screen
+may not automatically detach (or quit)
+unless the device driver is configured to send a HANGUP signal.
+To detach a
+.I screen
+session use the \-D or \-d command line option.
+.IP \(bu
+If a password is set, the command line options \-d and \-D still detach a
+session without asking.
+.IP \(bu
+Both \*Qbreaktype\*U and \*Qdefbreaktype\*U change the break generating
+method used by all terminal devices. The first should change a window
+specific setting, where the latter should change only the default for new
+windows.
+.IP \(bu
+When attaching to a multiuser session, the user's .screenrc file is not
+sourced. Each user's personal settings have to be included in the .screenrc
+file from which the session is booted, or have to be changed manually.
+.IP \(bu
+A weird imagination is most useful to gain full advantage of all the features.
+.IP \(bu
+Send bug-reports, fixes, enhancements, t-shirts, money, beer & pizza to
+.BR screen-devel@gnu.org .
+
diff --git a/doc/screen.texinfo b/doc/screen.texinfo
new file mode 100644
index 0000000..cb14aae
--- /dev/null
+++ b/doc/screen.texinfo
@@ -0,0 +1,6097 @@
+\input texinfo @c -*-texinfo-*-
+@c %**start of header
+@c vi:set wm=5
+@setfilename screen.info
+@settitle Screen User's Manual
+@dircategory General Commands
+@finalout
+@setchapternewpage odd
+@c %**end of header
+@set version 4.6.2
+
+@direntry
+* Screen: (screen). Full-screen window manager.
+@end direntry
+
+@c For examples, use a literal escape in info.
+@ifinfo
+@set esc ^[
+@end ifinfo
+@iftex
+@set esc <ESC>
+@end iftex
+
+@ifinfo
+This file documents the @code{Screen} virtual terminal manager.
+
+Copyright (c) 1993-2017 Free Software Foundation, Inc.
+
+Permission is granted to make and distribute verbatim copies of
+this manual provided the copyright notice and this permission notice
+are preserved on all copies.
+
+@ignore
+Permission is granted to process this file through TeX and print the
+results, provided the printed document carries copying permission
+notice identical to this one except for the removal of this paragraph
+(this paragraph not being relevant to the printed manual).
+
+@end ignore
+Permission is granted to copy and distribute modified versions of this
+manual under the conditions for verbatim copying, provided that the entire
+resulting derived work is distributed under the terms of a permission
+notice identical to this one.
+
+Permission is granted to copy and distribute translations of this manual
+into another language, under the above conditions for modified versions,
+except that this permission notice may be stated in a translation approved
+by the Foundation.
+@end ifinfo
+
+@titlepage
+@title Screen
+@subtitle The virtual terminal manager
+@subtitle for Version @value{version}
+@subtitle Feb 2017
+
+@page
+@vskip 0pt plus 1filll
+Copyright @copyright{} 1993-2017 Free Software Foundation, Inc.
+
+Permission is granted to make and distribute verbatim copies of
+this manual provided the copyright notice and this permission notice
+are preserved on all copies.
+
+Permission is granted to copy and distribute modified versions of this
+manual under the conditions for verbatim copying, provided that the entire
+resulting derived work is distributed under the terms of a permission
+notice identical to this one.
+
+Permission is granted to copy and distribute translations of this manual
+into another language, under the above conditions for modified versions,
+except that this permission notice may be stated in a translation approved
+by the Foundation.
+@end titlepage
+
+@shortcontents
+@contents
+
+@node Top, Overview, (dir), (dir)
+
+@ifinfo
+@top Screen
+This file documents the @code{Screen} virtual terminal manager, version
+@value{version}.
+@end ifinfo
+
+@menu
+* Overview:: Preliminary information.
+* Getting Started:: An introduction to @code{screen}.
+* Invoking Screen:: Command line options for @code{screen}.
+* Customization:: The @file{.screenrc} file.
+* Commands:: List all of the commands.
+* New Window:: Running a program in a new window.
+* Selecting:: Selecting a window to display.
+* Session Management:: Suspend/detach, grant access, connect sessions.
+* Regions:: Split-screen commands.
+* Window Settings:: Titles, logging, etc.
+* Virtual Terminal:: Controlling the @code{screen} VT100 emulation.
+* Copy and Paste:: Exchanging text between windows and sessions.
+* Subprocess Execution:: I/O filtering with @code{exec}.
+* Key Binding:: Binding commands to keys.
+* Flow Control:: Trap or pass flow control characters.
+* Termcap:: Tweaking your terminal's termcap entry.
+* Message Line:: The @code{screen} message line.
+* Logging:: Keeping a record of your session.
+* Startup:: Functions only useful at @code{screen} startup.
+* Miscellaneous:: Various other commands.
+* String Escapes:: Inserting current information into strings
+* Environment:: Environment variables used by @code{screen}.
+* Files:: Files used by @code{screen}.
+* Credits:: Who's who of @code{screen}.
+* Bugs:: What to do if you find a bug.
+* Installation:: Getting @code{screen} running on your system.
+* Concept Index:: Index of concepts.
+* Command Index:: Index of all @code{screen} commands.
+* Keystroke Index:: Index of default key bindings.
+@end menu
+
+@node Overview, Getting Started, Top, Top
+@chapter Overview
+@cindex overview
+
+Screen is a full-screen window manager that multiplexes a physical
+terminal between several processes, typically interactive shells. Each
+virtual terminal provides the functions of the DEC VT100 terminal and,
+in addition, several control functions from the ISO 6429 (ECMA 48, ANSI X3.64)
+and ISO 2022 standards (e.g. insert/delete line and support for multiple
+character sets). There is a scrollback history buffer for each virtual
+terminal and a copy-and-paste mechanism that allows the user to move
+text regions between windows.
+
+When @code{screen} is called, it creates a single window with a shell in
+it (or the specified command) and then gets out of your way so that you
+can use the program as you normally would. Then, at any time, you can
+create new (full-screen) windows with other programs in them (including
+more shells), kill the current window, view a list of the active
+windows, turn output logging on and off, copy text between windows, view
+the scrollback history, switch between windows, etc. All windows run
+their programs completely independent of each other. Programs continue
+to run when their window is currently not visible and even when the
+whole screen session is detached from the user's terminal.
+
+When a program terminates, @code{screen} (per default) kills the window
+that contained it. If this window was in the foreground, the display
+switches to the previously displayed window; if none are left,
+@code{screen} exits. Shells usually distinguish between running as login-shell or sub-shell.
+Screen runs them as sub-shells, unless told otherwise (See @code{shell} .screenrc command).
+
+Everything you type is sent to the program running in the current
+window. The only exception to this is the one keystroke that is used to
+initiate a command to the window manager. By default, each command
+begins with a control-a (abbreviated @kbd{C-a} from now on), and is
+followed by one other keystroke. The command character (@pxref{Command
+Character}) and all the key bindings (@pxref{Key Binding}) can be fully
+customized to be anything you like, though they are always two
+characters in length.
+
+@code{Screen} does not understand the prefix @kbd{C-} to mean control, although
+this notation is used in this manual for readability.
+Please use the caret notation (@kbd{^A} instead of @kbd{C-a}) as arguments
+to e.g. the @code{escape} command or the @code{-e} option. @code{Screen}
+will also print out control characters in caret notation.
+
+The standard way to create a new window is to type @kbd{C-a c}. This
+creates a new window running a shell and switches to that window
+immediately, regardless of the state of the process running in the
+current window. Similarly, you can create a new window with a custom
+command in it by first binding the command to a keystroke (in your
+@file{.screenrc} file or at the @kbd{C-a :} command line) and then using it
+just like the @kbd{C-a c} command. In addition, new windows can be created by
+running a command like:
+
+@example
+screen emacs prog.c
+@end example
+
+@noindent
+from a shell prompt within a previously created window. This will not
+run another copy of @code{screen}, but will instead supply the command
+name and its arguments to the window manager (specified in the $STY environment
+variable) who will use it to create the new window. The above example would
+start the @code{emacs} editor (editing @file{prog.c}) and switch to its window.
+- Note that you cannot transport environment variables from
+the invoking shell to the application (emacs in this case), because it is
+forked from the parent screen process, not from the invoking shell.
+
+If @file{/etc/utmp} is writable by @code{screen}, an appropriate record
+will be written to this file for each window, and removed when the
+window is closed. This is useful for working with @code{talk},
+@code{script}, @code{shutdown}, @code{rsend}, @code{sccs} and other
+similar programs that use the utmp file to determine who you are. As
+long as @code{screen} is active on your terminal, the terminal's own
+record is removed from the utmp file. @xref{Login}.
+
+@node Getting Started, Invoking Screen, Overview, Top
+@chapter Getting Started
+@cindex introduction
+
+Before you begin to use @code{screen} you'll need to make sure you have
+correctly selected your terminal type, just as you would for any other
+termcap/terminfo program. (You can do this by using @code{tset},
+@code{qterm}, or just @code{set term=mytermtype}, for example.)
+
+If you're impatient and want to get started without doing a lot more
+reading, you should remember this one command: @kbd{C-a ?} (@pxref{Key
+Binding}). Typing these two characters will display a list of the
+available @code{screen} commands and their bindings. Each keystroke is
+discussed in the section on keystrokes (@pxref{Default Key Bindings}).
+Another section (@pxref{Customization}) deals with the contents of your
+@file{.screenrc}.
+
+If your terminal is a ``true'' auto-margin terminal (it doesn't allow
+the last position on the screen to be updated without scrolling the
+screen) consider using a version of your terminal's termcap that has
+automatic margins turned @emph{off}. This will ensure an accurate
+and optimal update of the screen in all circumstances. Most terminals
+nowadays have ``magic'' margins (automatic margins plus usable last
+column). This is the VT100 style type and perfectly suited for
+@code{screen}.
+If all you've got is a ``true'' auto-margin terminal @code{screen}
+will be content to use it, but updating a character put into the last
+position on the screen may not be possible until the screen scrolls or
+the character is moved into a safe position in some other way. This
+delay can be shortened by using a terminal with insert-character
+capability.
+
+@xref{Special Capabilities}, for more information about telling
+@code{screen} what kind of terminal you have.
+
+@node Invoking Screen, Customization, Getting Started, Top
+@chapter Invoking @code{Screen}
+@cindex invoking
+@cindex options
+@cindex command line options
+
+Screen has the following command-line options:
+
+@table @samp
+@item -a
+Include @emph{all} capabilities (with some minor exceptions) in each
+window's termcap, even if @code{screen} must redraw parts of the display
+in order to implement a function.
+
+@item -A
+Adapt the sizes of all windows to the size of the display. By default,
+@code{screen} may try to restore its old window sizes when attaching to
+resizable terminals (those with @samp{WS} in their descriptions, e.g.
+@code{suncmd} or some varieties of @code{xterm}).
+
+@item -c @var{file}
+Use @var{file} as the user's configuration file instead of the default
+of @file{$HOME/.screenrc}.
+
+@item -d [@var{pid.sessionname}]
+@itemx -D [@var{pid.sessionname}]
+Do not start @code{screen}, but instead detach a @code{screen} session
+running elsewhere (@pxref{Detach}). @samp{-d} has the same effect as
+typing @kbd{C-a d} from the controlling terminal for the session.
+@samp{-D} is the equivalent to the power detach key. If no session can
+be detached, this option is ignored. In combination with the
+@code{-r}/@code{-R} option more powerful effects can be achieved:
+
+@table @code
+@item -d -r
+Reattach a session and if necessary detach it first.
+@item -d -R
+Reattach a session and if necessary detach or even create it first.
+@item -d -RR
+Reattach a session and if necessary detach or create it.
+Use the first session if more than one session is available.
+@item -D -r
+Reattach a session. If necessary detach and logout remotely first.
+@item -D -R
+Attach here and now. In detail this means: If a session is running,
+then reattach. If necessary detach and logout remotely first. If it
+was not running create it and notify the user.
+This is the author's favorite.
+@item -D -RR
+Attach here and now. Whatever that means, just do it.
+@end table
+
+@emph{Note}: It is a good idea to check the status of your sessions
+with @code{screen -list} before using this option.
+
+@item -e @var{xy}
+Set the command character to @var{x}, and the character generating a
+literal command character (when typed after the command character) to
+@var{y}. The defaults are @kbd{C-a} and @kbd{a}, which can be specified
+as @samp{-e^Aa}. When creating a @code{screen} session, this option
+sets the default command character. In a multiuser session all users
+added will start off with this command character. But when attaching
+to an already running session, this option only changes the command
+character of the attaching user.
+This option is equivalent to the commands @code{defescape} or
+@code{escape} respectively. (@pxref{Command Character}).
+
+@item -f
+@itemx -fn
+@itemx -fa
+Set flow-control to on, off, or automatic switching mode, respectively.
+This option is equivalent to the @code{defflow} command (@pxref{Flow
+Control}).
+
+@item -h @var{num}
+Set the history scrollback buffer to be @var{num} lines high.
+Equivalent to the @code{defscrollback} command (@pxref{Copy}).
+
+@item -i
+Cause the interrupt key (usually @kbd{C-c}) to interrupt the display
+immediately when flow control is on. This option is equivalent to the
+@code{interrupt} argument to the @code{defflow} command (@pxref{Flow
+Control}). Its use is discouraged.
+
+@item -l
+@itemx -ln
+Turn login mode on or off (for @file{/etc/utmp} updating). This option
+is equivalent to the @code{deflogin} command (@pxref{Login}).
+
+@item -ls [@var{match}]
+@itemx -list [@var{match}]
+Do not start @code{screen}, but instead print a list of session
+identification strings (usually of the form @var{pid.tty.host};
+@pxref{Session Name}). Sessions marked @samp{detached} can be resumed
+with @code{screen -r}. Those marked @samp{attached} are running and
+have a controlling terminal. If the session runs in multiuser mode,
+it is marked @samp{multi}. Sessions marked as @samp{unreachable} either
+live on a different host or are dead.
+An unreachable session is considered dead, when its name matches either the
+name of the local host, or the specified parameter, if any.
+See the @code{-r} flag for a description how to construct matches.
+Sessions marked as @samp{dead} should be thoroughly checked and removed.
+Ask your system administrator if you are not sure.
+Remove sessions with the @samp{-wipe} option.
+
+@item -L
+Tell @code{screen} to turn on automatic output logging for the
+windows.
+
+@item -Logfile "file"
+By default logfile name is "screenlog.0". You can set new logfile name
+with the @code{-Logfile} option.
+
+@item -m
+Tell @code{screen} to ignore the @code{$STY} environment variable. When
+this option is used, a new session will always be created, regardless of
+whether @code{screen} is being called from within another @code{screen}
+session or not. This flag has a special meaning in connection
+with the @samp{-d} option:
+@table @code
+@item -d -m
+Start @code{screen} in @emph{detached} mode. This creates a new
+session but doesn't attach to it. This is useful for system startup
+scripts.
+@item -D -m
+This also starts @code{screen} in @emph{detached} mode, but doesn't fork
+a new process. The command exits if the session terminates.
+@end table
+
+@item -O
+Select a more optimal output mode for your terminal rather than true VT100
+emulation (only affects auto-margin terminals without @samp{LP}). This
+can also be set in your @file{.screenrc} by specifying @samp{OP} in the
+@code{termcap} command.
+
+@item -p @var{name_or_number}|-|=|+
+Preselect a window. This is useful when you want to reattach to a
+specific window or you want to send a command via the @samp{-X}
+option to a specific window. As with screen's select command, @samp{-}
+selects the blank window. As a special case for reattach, @samp{=}
+brings up the windowlist on the blank window, while a @samp{+} will
+create new window. The command will not be executed if the specified
+window could not be found.
+
+@item -q
+Suppress printing of error messages. In combination with @samp{-ls} the exit
+value is set as follows: 9 indicates a directory without sessions. 10
+indicates a directory with running but not attachable sessions. 11 (or more)
+indicates 1 (or more) usable sessions.
+In combination with @samp{-r} the exit value is as follows: 10 indicates that
+there is no session to resume. 12 (or more) indicates that there are 2 (or
+more) sessions to resume and you should specify which one to choose.
+In all other cases @samp{-q} has no effect.
+
+@item -Q
+Some commands now can be queried from a remote session using this
+flag, e.g. 'screen -Q windows'. The commands will send the
+response to the stdout of the querying process. If there was an
+error in the command, then the querying process will exit with
+a non-zero status.
+
+The commands that can be queried now are:
+ @code{echo}
+ @code{info}
+ @code{lastmsg}
+ @code{number}
+ @code{select}
+ @code{time}
+ @code{title}
+ @code{windows}
+
+@item -r [@var{pid.sessionname}]
+@itemx -r @var{sessionowner}/[@var{pid.sessionname}]
+Resume a detached @code{screen} session. No other options (except
+combinations with @samp{-d} or @samp{-D}) may be specified, though
+the session name
+(@pxref{Session Name}) may be needed to distinguish between multiple
+detached @code{screen} sessions.
+The second form is used to connect to another user's screen session which
+runs in multiuser mode. This indicates that screen should look for
+sessions in another user's directory. This requires setuid-root.
+
+@item -R
+resumes screen only when it's unambiguous which one to attach, usually
+when only one @code{screen} is detached. Otherwise lists available sessions.
+
+@item -RR
+Resume the first appropriate detached @code{screen} session. If
+successful, all other command-line options are ignored. If no detached
+session exists, start a new session using the specified options, just as
+if @samp{-R} had not been specified. This option is set by default if
+screen is run as a login-shell (actually screen uses @samp{-xRR} in
+that case).
+For combinations with the
+@samp{-D}/@samp{-d} option see there.
+
+@item -s @var{program}
+Set the default shell to be @var{program}. By default, @code{screen}
+uses the value of the environment variable @code{$SHELL}, or
+@file{/bin/sh} if it is not defined. This option is equivalent to the
+@code{shell} command (@pxref{Shell}). See also there.
+
+@item -S @var{sessionname}
+Set the name of the new session to @var{sessionname}. This option can
+be used to specify a meaningful name for the session in place of the
+default @var{tty.host} suffix. This name identifies the session for the
+@code{screen -list} and @code{screen -r} commands. This option is
+equivalent to the @code{sessionname} command (@pxref{Session Name}).
+
+@item -t @var{name}
+Set the title (name) for the default shell or specified program.
+This option is equivalent to the @code{shelltitle} command
+(@pxref{Shell}).
+
+@item -T @var{term}
+Set the $TERM enviroment variable using the specified @emph{term} as
+opposed to the default setting of @code{screen}.
+
+@item -U
+Run screen in UTF-8 mode. This option tells screen that your terminal
+sends and understands UTF-8 encoded characters. It also sets the default
+encoding for new windows to @samp{utf8}.
+
+@item -v
+Print the version number.
+
+@item -wipe [@var{match}]
+List available screens like @code{screen -ls}, but remove destroyed
+sessions instead of marking them as @samp{dead}.
+An unreachable session is considered dead, when its name matches either
+the name of the local host, or the explicitly given parameter, if any.
+See the @code{-r} flag for a description how to construct matches.
+
+@item -x
+Attach to a session which is already attached elsewhere (multi-display
+mode).
+@code{Screen} refuses to attach from within itself.
+But when cascading multiple screens, loops are not detected; take care.
+
+
+@item -X
+Send the specified command to a running screen session. You may use
+the @code{-S} option to specify the screen session if you have several
+running. You can use the @code{-d} or @code{-r} option to tell screen
+to look only for attached or detached screen sessions. Note that this
+command doesn't work if the session is password protected.
+
+@end table
+
+@node Customization, Commands, Invoking Screen, Top
+@chapter Customizing @code{Screen}
+@cindex customization
+
+You can modify the default settings for @code{screen} to fit your tastes
+either through a personal @file{.screenrc} file which contains commands
+to be executed at startup, or on the fly using the @code{colon} command.
+
+@menu
+* Startup Files:: The @file{.screenrc} file.
+* Source:: Read commands from a file.
+* Colon:: Entering customization commands interactively.
+@end menu
+
+@node Startup Files, Source, , Customization
+@section The @file{.screenrc} file
+@cindex .screenrc
+@cindex screenrc
+When @code{screen} is invoked, it executes initialization commands from
+the files @file{.screenrc} in the user's home directory and
+@file{/usr/local/etc/screenrc}. These defaults can be overridden in the
+following ways:
+For the global screenrc file @code{screen} searches for the environment
+variable @code{$SYSSCREENRC} (this override feature may be disabled at
+compile-time). The user specific screenrc file is
+searched for in @code{$SCREENRC}, then
+@file{@code{$HOME}/.screenrc}. The command line option @samp{-c}
+specifies which file to use (@pxref{Invoking Screen}. Commands in these
+files are used to set options, bind commands to keys, and to
+automatically establish one or more windows at the beginning of
+your @code{screen} session. Commands are listed one per line, with
+empty lines being ignored. A command's arguments are separated by tabs
+or spaces, and may be surrounded by single or double quotes. A @samp{#}
+turns the rest of the line into a comment, except in quotes.
+Unintelligible lines are warned about and ignored. Commands may contain
+references to environment variables. The syntax is the shell-like
+@code{$VAR} or @code{$@{VAR@}}. Note that this causes incompatibility
+with previous @code{screen} versions, as now the '$'-character has to be
+protected with '\' if no variable substitution is intended. A string in
+single-quotes is also protected from variable substitution.
+
+Two configuration files are shipped as examples with your screen
+distribution: @file{etc/screenrc} and @file{etc/etcscreenrc}. They
+contain a number of useful examples for various commands.
+
+@node Source, Colon, Startup Files, Customization
+@section Source
+@deffn Command source file
+(none)@*
+Read and execute commands from file @var{file}. Source commands
+may be nested to a maximum recursion level of ten. If @var{file}
+is not an absolute path and screen is already processing a
+source command, the parent directory of the running source
+command file is used to search for the new command file before
+screen's current directory.
+
+Note that termcap/terminfo/termcapinfo commands only work
+at startup and reattach time, so they must be reached via
+the default screenrc files to have an effect.
+@end deffn
+
+@node Colon, , Source, Customization
+@section Colon
+Customization can also be done online, with this command:
+
+@kindex :
+@deffn Command colon
+(@kbd{C-a :})@*
+Allows you to enter @file{.screenrc} command lines. Useful for
+on-the-fly modification of key bindings, specific window creation and
+changing settings. Note that the @code{set} keyword no longer exists,
+as of version 3.3. Change default settings with commands starting with
+@samp{def}. You might think of this as the @code{ex} command mode of
+@code{screen}, with @code{copy} as its @code{vi} command mode
+(@pxref{Copy and Paste}).
+@end deffn
+
+@node Commands, New Window, Customization, Top
+@chapter Commands
+
+A command in @code{screen} can either be bound to a key, invoked from a
+screenrc file, or called from the @code{colon} prompt
+(@pxref{Customization}). As of version 3.3, all commands can be bound
+to keys, although some may be less useful than others.
+For a number of real life working examples of the most important
+commands see the files @file{etc/screenrc} and @file{etc/etcscreenrc}
+of your screen distribution.
+
+In this manual, a command definition looks like this:
+
+@table @asis
+@item -- Command: command [-n] ARG1 [ARG2] @dots{}
+(@var{keybindings})@*
+This command does something, but I can't remember what.
+@end table
+
+An argument in square brackets (@samp{[]}) is optional. Many commands
+take an argument of @samp{on} or @samp{off}, which is indicated as
+@var{state} in the definition.
+
+@menu
+* Default Key Bindings:: @code{screen} keyboard commands.
+* Command Summary:: List of all commands.
+@end menu
+
+@node Default Key Bindings, Command Summary, , Commands
+@section Default Key Bindings
+
+As mentioned previously, each keyboard command consists of a
+@kbd{C-a} followed by one other character. For your convenience, all
+commands that are bound to lower-case letters are also bound to their
+control character counterparts (with the exception of @kbd{C-a a}; see
+below). Thus, both @kbd{C-a c} and @kbd{C-a C-c} can be used to create
+a window.
+
+The following table shows the default key bindings:
+
+@table @asis
+@item @kbd{C-a '}
+(select)@*
+Prompt for a window identifier and switch.
+@xref{Selecting}.
+
+@item @kbd{C-a "}
+(windowlist -b)@*
+Present a list of all windows for selection.
+@xref{Selecting}.
+
+@item @kbd{C-a 0@dots{}9, -}
+(select 0@dots{}select 9, select -)@*
+Switch to window number 0@dots{}9, or the blank window.
+@xref{Selecting}.
+
+@item @kbd{C-a @key{Tab}}
+(focus)@*
+Switch the input focus to the next region. @xref{Regions}.
+
+@item @kbd{C-a C-a}
+(other)@*
+Toggle to the window displayed previously. If this window does no
+longer exist, @code{other} has the same effect as @code{next}.
+@xref{Selecting}.
+
+@item @kbd{C-a a}
+(meta)@*
+Send the command character (C-a) to window. See @code{escape} command.
+@xref{Command Character}.
+
+@item @kbd{C-a A}
+(title)@*
+Allow the user to enter a title for the current window.
+@xref{Naming Windows}.
+
+@item @kbd{C-a b}
+@itemx @kbd{C-a C-b}
+(break)@*
+Send a break to the tty.
+@xref{Break}.
+
+@item @kbd{C-a B}
+(pow_break)@*
+Close and reopen the tty-line.
+@xref{Break}.
+
+@item @kbd{C-a c}
+@itemx @kbd{C-a C-c}
+(screen)@*
+Create a new window with a shell and switch to that window.
+@xref{Screen Command}.
+
+@item @kbd{C-a C}
+(clear)@*
+Clear the screen. @xref{Clear}.
+
+@item @kbd{C-a d}
+@itemx @kbd{C-a C-d}
+(detach)@*
+Detach @code{screen} from this terminal. @xref{Detach}.
+
+@item @kbd{C-a D D}
+(pow_detach)@*
+Detach and logout. @xref{Power Detach}.
+
+@item @kbd{C-a f}
+@itemx @kbd{C-a C-f}
+(flow)@*
+Cycle flow among @samp{on}, @samp{off} or @samp{auto}. @xref{Flow}.
+
+@item @kbd{C-a F}
+(fit)@*
+Resize the window to the current region size. @xref{Fit}.
+
+@item @kbd{C-a C-g}
+(vbell)@*
+Toggle visual bell mode. @xref{Bell}.
+
+@item @kbd{C-a h}
+(hardcopy)@*
+Write a hardcopy of the current window to the file ``hardcopy.@var{n}''.
+@xref{Hardcopy}.
+
+@item @kbd{C-a H}
+(log)@*
+Toggle logging of the current window to the file ``screenlog.@var{n}''.
+@xref{Log}.
+
+@item @kbd{C-a i}
+@itemx @kbd{C-a C-i}
+(info)@*
+Show info about the current window. @xref{Info}.
+
+@item @kbd{C-a k}
+@itemx @kbd{C-a C-k}
+(kill)@*
+Destroy the current window. @xref{Kill}.
+
+@item @kbd{C-a l}
+@itemx @kbd{C-a C-l}
+(redisplay)@*
+Fully refresh the current window. @xref{Redisplay}.
+
+@item @kbd{C-a L}
+(login)@*
+Toggle the current window's login state. @xref{Login}.
+
+@item @kbd{C-a m}
+@itemx @kbd{C-a C-m}
+(lastmsg)@*
+Repeat the last message displayed in the message line.
+@xref{Last Message}.
+
+@item @kbd{C-a M}
+(monitor)
+Toggle monitoring of the current window. @xref{Monitor}.
+
+@item @kbd{C-a @key{SPC}}
+@itemx @kbd{C-a n}
+@itemx @kbd{C-a C-n}
+(next)@*
+Switch to the next window. @xref{Selecting}.
+
+@item @kbd{C-a N}
+(number)@*
+Show the number (and title) of the current window. @xref{Number}.
+
+@item @kbd{C-a p}
+@itemx @kbd{C-a C-p}
+@itemx @kbd{C-a C-h}
+@itemx @kbd{C-a @key{BackSpace}}
+(prev)@*
+Switch to the previous window (opposite of @kbd{C-a n}).
+@xref{Selecting}.
+
+@item @kbd{C-a q}
+@itemx @kbd{C-a C-q}
+(xon)@*
+Send a ^Q (ASCII XON) to the current window. @xref{XON/XOFF}.
+
+@item @kbd{C-a Q}
+(only)@*
+Delete all regions but the current one. @xref{Regions}.
+
+@item @kbd{C-a r}
+@itemx @kbd{C-a C-r}
+(wrap)@*
+Toggle the current window's line-wrap setting (turn the current window's
+automatic margins on or off). @xref{Wrap}.
+
+@item @kbd{C-a s}
+@itemx @kbd{C-a C-s}
+(xoff)@*
+Send a ^S (ASCII XOFF) to the current window. @xref{XON/XOFF}.
+
+@item @kbd{C-a S}
+(split)@*
+Split the current region horizontally into two new ones. @xref{Regions}.
+
+@item @kbd{C-a t}
+@itemx @kbd{C-a C-t}
+(time)@*
+Show the load average and xref. @xref{Time}.
+
+@item @kbd{C-a v}
+(version)@*
+Display the version and compilation date. @xref{Version}.
+
+@item @kbd{C-a C-v}
+(digraph)@*
+Enter digraph. @xref{Digraph}.
+
+@item @kbd{C-a w}
+@itemx @kbd{C-a C-w}
+(windows)@*
+Show a list of active windows. @xref{Windows}.
+
+@item @kbd{C-a W}
+(width)@*
+Toggle between 80 and 132 columns. @xref{Window Size}.
+
+@item @kbd{C-a x}
+@itemx @kbd{C-a C-x}
+(lockscreen)@*
+Lock your terminal. @xref{Lock}.
+
+@item @kbd{C-a X}
+(remove)@*
+Kill the current region. @xref{Regions}.
+
+@item @kbd{C-a z}
+@itemx @kbd{C-a C-z}
+(suspend)@*
+Suspend @code{screen}. @xref{Suspend}.
+
+@item @kbd{C-a Z}
+(reset)@*
+Reset the virtual terminal to its ``power-on'' values.
+@xref{Reset}.
+
+@item @kbd{C-a .}
+(dumptermcap)@*
+Write out a @file{.termcap} file. @xref{Dump Termcap}.
+
+@item @kbd{C-a ?}
+(help)@*
+Show key bindings. @xref{Help}.
+
+@item @kbd{C-a \}
+(quit)@*
+Kill all windows and terminate @code{screen}. @xref{Quit}.
+
+@item @kbd{C-a :}
+(colon)@*
+Enter a command line. @xref{Colon}.
+
+@item @kbd{C-a [}
+@itemx @kbd{C-a C-[}
+@itemx @kbd{C-a @key{ESC}}
+(copy)@*
+Enter copy/scrollback mode. @xref{Copy}.
+
+@item @kbd{C-a ]}
+@itemx @kbd{C-a C-]}
+(paste .)@*
+Write the contents of the paste buffer to the stdin queue of the
+current window. @xref{Paste}.
+
+@item @kbd{C-a @{}
+@itemx @kbd{C-a @}}
+(history)@*
+Copy and paste a previous (command) line. @xref{History}.
+
+@item @kbd{C-a >}
+(writebuf)@*
+Write the paste buffer out to the screen-exchange file.
+@xref{Screen Exchange}.
+
+@item @kbd{C-a <}
+(readbuf)@*
+Read the screen-exchange file into the paste buffer.
+@xref{Screen Exchange}.
+
+@item @kbd{C-a =}
+(removebuf)@*
+Delete the screen-exchange file. @xref{Screen Exchange}.
+
+@item @kbd{C-a _}
+(silence)@*
+Start/stop monitoring the current window for inactivity. @xref{Monitor}.
+
+@item @kbd{C-a |}
+(split -v)@*
+Split the current region vertically into two new ones. @xref{Regions}.
+
+@item @kbd{C-a ,}
+(license)@*
+Show the copyright page. @xref{License}.
+
+@item @kbd{C-a *}
+(displays)@*
+Show the listing of attached displays. @xref{Displays}.
+@end table
+
+@node Command Summary, , Default Key Bindings, Commands
+@section Command Summary
+@cindex command summary
+
+@table @code
+@item acladd @var{usernames}
+Allow other users in this session. @xref{Multiuser Session}.
+@item aclchg @var{usernames permbits list}
+Change a user's permissions. @xref{Multiuser Session}.
+@item acldel @var{username}
+Disallow other user in this session. @xref{Multiuser Session}.
+@item aclgrp @var{usrname} [@var{groupname}]
+Inherit permissions granted to a group leader. @xref{Multiuser Session}.
+@item aclumask [@var{users}]+/-@var{bits} ...
+Predefine access to new windows. @xref{Umask}.
+@item activity @var{message}
+Set the activity notification message. @xref{Monitor}.
+@item addacl @var{usernames}
+Synonym to @code{acladd}. @xref{Multiuser Session}.
+@item allpartial @var{state}
+Set all windows to partial refresh. @xref{Redisplay}.
+@item altscreen @var{state}
+Enables support for the "alternate screen" terminal capability. @xref{Redisplay}.
+@item at [@var{ident}][@kbd{#}@var{|}@kbd{*}@var{|}@kbd{%}] @var{command} [@var{args}]
+Execute a command at other displays or windows. @xref{At}.
+@item attrcolor @var{attrib} [@var{attribute/color-modifier}]
+Map attributes to colors. @xref{Attrcolor}.
+@item autodetach @var{state}
+Automatically detach the session on SIGHUP. @xref{Detach}.
+@item autonuke @var{state}
+Enable a clear screen to discard unwritten output. @xref{Autonuke}.
+@item backtick @var{id} @var{lifespan} @var{autorefresh} @var{command} [@var{args}]
+Define a command for the backtick string escape. @xref{Backtick}.
+@item bce [@var{state}]
+Change background color erase. @xref{Character Processing}.
+@item bell_msg [@var{message}]
+Set the bell notification message. @xref{Bell}.
+@item bind [-c @var{class}] @var{key} [@var{command} [@var{args}]]
+Bind a command to a key. @xref{Bind}.
+@item bindkey [@var{opts}] [@var{string} [@var{cmd args}]]
+Bind a string to a series of keystrokes. @xref{Bindkey}.
+@item blanker
+Blank the screen. @xref{Screen Saver}.
+@item blankerprg
+Define a blanker program. @xref{Screen Saver}.
+@item break [@var{duration}]
+Send a break signal to the current window. @xref{Break}.
+@item breaktype [@var{tcsendbreak} | @var{TCSBRK} | @var{TIOCSBRK}]
+Specify how to generate breaks. @xref{Break}.
+@item bufferfile [@var{exchange-file}]
+Select a file for screen-exchange. @xref{Screen Exchange}.
+@item bumpleft
+Swaps window with previous one on window list. @xref{Bumpleft}.
+@item bumpright
+Swaps window with previous one on window list. @xref{Bumpright}.
+@item c1 [@var{state}]
+Change c1 code processing. @xref{Character Processing}.
+@item caption @var{mode} [@var{string}]
+Change caption mode and string. @xref{Regions}.
+@item chacl @var{usernames permbits list}
+Synonym to @code{aclchg}. @xref{Multiuser Session}.
+@item charset @var{set}
+Change character set slot designation. @xref{Character Processing}.
+@item chdir [@var{directory}]
+Change the current directory for future windows. @xref{Chdir}.
+@item cjkwidth
+Treat ambiguous width characters as full/half width. @xref{Character Processing}.
+@item clear
+Clear the window screen. @xref{Clear}.
+@item colon
+Enter a @code{screen} command. @xref{Colon}.
+@item collapse
+Reorders window on window list, removing number gaps between them. @xref{Collapse}.
+@item command [-c @var{class}]
+Simulate the screen escape key. @xref{Command Character}.
+@item compacthist [@var{state}]
+Selects compaction of trailing empty lines. @xref{Scrollback}.
+@item console [@var{state}]
+Grab or ungrab console output. @xref{Console}.
+@item copy
+Enter copy mode. @xref{Copy}.
+@item copy_reg [@var{key}]
+Removed. Use @code{paste} instead. @xref{Registers}.
+@item crlf @var{state}
+Select line break behavior for copying. @xref{Line Termination}.
+@item debug @var{state}
+Suppress/allow debugging output. @xref{Debug}.
+@item defautonuke @var{state}
+Select default autonuke behavior. @xref{Autonuke}.
+@item defbce @var{state}
+Select background color erase. @xref{Character Processing}.
+@item defbreaktype [@var{tcsendbreak} | @var{TCSBRK} | @var{TIOCSBRK}]
+Specify the default for generating breaks. @xref{Break}.
+@item defc1 @var{state}
+Select default c1 processing behavior. @xref{Character Processing}.
+@item defcharset [@var{set}]
+Change defaul character set slot designation. @xref{Character Processing}.
+@item defencoding @var{enc}
+Select default window encoding. @xref{Character Processing}.
+@item defescape @var{xy}
+Set the default command and @code{meta} characters. @xref{Command Character}.
+@item defflow @var{fstate}
+Select default flow control behavior. @xref{Flow}.
+@item defgr @var{state}
+Select default GR processing behavior. @xref{Character Processing}.
+@item defhstatus [@var{status}]
+Select default window hardstatus line. @xref{Hardstatus}.
+@item deflog @var{state}
+Select default window logging behavior. @xref{Log}.
+@item deflogin @var{state}
+Select default utmp logging behavior. @xref{Login}.
+@item defmode @var{mode}
+Select default file mode for ptys. @xref{Mode}.
+@item defmonitor @var{state}
+Select default activity monitoring behavior. @xref{Monitor}.
+@item defmousetrack @var{on}|@var{off}
+Select the default mouse tracking behavior. @xref{Mousetrack}.
+@item defnonblock @var{state}|@var{numsecs}
+Select default nonblock mode. @xref{Nonblock}.
+@item defobuflimit @var{limit}
+Select default output buffer limit. @xref{Obuflimit}.
+@item defscrollback @var{num}
+Set default lines of scrollback. @xref{Scrollback}.
+@item defshell @var{command}
+Set the default program for new windows. @xref{Shell}.
+@item defsilence @var{state}
+Select default idle monitoring behavior. @xref{Monitor}.
+@item defslowpaste @var{msec}
+Select the default inter-character timeout when pasting. @xref{Paste}.
+@item defutf8 @var{state}
+Select default character encoding. @xref{Character Processing}.
+@item defwrap @var{state}
+Set default line-wrapping behavior. @xref{Wrap}.
+@item defwritelock @var{on|off|auto}
+Set default writelock behavior. @xref{Multiuser Session}.
+@item zombie_timeout [@var{seconds}]
+Try to reconnect dead windows after timeout. @xref{Zombie}.
+@item detach [-h]
+Disconnect @code{screen} from the terminal. @xref{Detach}.
+@item digraph [@var{preset} [@var{unicode-value}]]
+Enter a digraph sequence. @xref{Digraph}.
+@item dinfo
+Display terminal information. @xref{Info}.
+@item displays
+List currently active user interfaces. @xref{Displays}.
+@item dumptermcap
+Write the window's termcap entry to a file. @xref{Dump Termcap}.
+@item echo [-n] @var{message}
+Display a message on startup. @xref{Startup}.
+@item encoding @var{enc} [@var{denc}]
+Set the encoding of a window. @xref{Character Processing}.
+@item escape @var{xy}
+Set the command and @code{meta} characters. @xref{Command Character}.
+@item eval @var{command1} [@var{command2} ...]
+Parse and execute each argument. @xref{Eval}.
+@item exec [[@var{fdpat}] @var{command} [@var{args} ...]]
+Run a subprocess (filter). @xref{Exec}.
+@item fit
+Change window size to current display size. @xref{Window Size}.
+@item flow [@var{fstate}]
+Set flow control behavior. @xref{Flow}.
+@item focus [@code{next}|@code{prev}|@code{up}|@code{down}|@code{left}|@code{right}|@code{top}|@code{bottom}]
+Move focus to next region. @xref{Regions}.
+@item focusminsize
+Force the current region to a certain size. @xref{Focusminsize}.
+@item gr [@var{state}]
+Change GR charset processing. @xref{Character Processing}.
+@item group [@var{grouptitle}]
+Change or show the group the current window belongs to. @xref{Window Groups}.
+@item hardcopy [-h] [@var{file}]
+Write out the contents of the current window. @xref{Hardcopy}.
+@item hardcopy_append @var{state}
+Append to hardcopy files. @xref{Hardcopy}.
+@item hardcopydir @var{directory}
+Place, where to dump hardcopy files. @xref{Hardcopy}.
+@item hardstatus [@var{state}]
+Use the hardware status line. @xref{Hardware Status Line}.
+@item height [@var{lines} [@var{cols}]]
+Set display height. @xref{Window Size}.
+@item help [-c @var{class}]
+Display current key bindings. @xref{Help}.
+@item history
+Find previous command beginning @dots{}. @xref{History}.
+@item hstatus @var{status}
+Change the window's hardstatus line. @xref{Hardstatus}.
+@item idle [@var{timeout} [@var{cmd} @var{args}]]
+Define a screen saver command. @xref{Screen Saver}.
+@item ignorecase [on|off]
+Ignore character case in searches. @xref{Searching}.
+@item info
+Display window settings. @xref{Info}.
+@item ins_reg [@var{key}]
+Removed, use @code{paste} instead. @xref{Registers}.
+@item kill
+Destroy the current window. @xref{Kill}.
+@item lastmsg
+Redisplay the last message. @xref{Last Message}.
+@item layout new [@var{title}]
+Create a layout. @xref{Layout}.
+@item layout remove [@var{n}|@var{title}]
+Delete a layout. @xref{Layout}.
+@item layout next
+Select the next layout. @xref{Layout}.
+@item layout prev
+Select the previous layout. @xref{Layout}.
+@item layout select [@var{n}|@var{title}]
+Jump to a layout. @xref{Layout}.
+@item layout show
+List the available layouts. @xref{Layout}.
+@item layout title [@var{title}]
+Show or set the title of a layout. @xref{Layout}.
+@item layout number [@var{n}]
+Show or set the number of a layout. @xref{Layout}.
+@item layout attach [@var{title}|:last]
+Show or set which layout to reattach to. @xref{Layout}.
+@item layout save [@var{n}|@var{title}]
+Remember the organization of a layout. @xref{Layout}.
+@item layout autosave [@var{on}|@var{off}]
+Show or set the status of layout saving. @xref{Layout}.
+@item layout dump [filename]
+Save the layout arrangement to a file. @xref{Layout}.
+@item license
+Display licensing information. @xref{Startup}.
+@item lockscreen
+Lock the controlling terminal. @xref{Lock}.
+@item log [@var{state}]
+Log all output in the current window. @xref{Log}.
+@item logfile @var{filename}
+Place where to collect logfiles. @xref{Log}.
+@item login [@var{state}]
+Log the window in @file{/etc/utmp}. @xref{Login}.
+@item logtstamp [@var{state}]
+Configure logfile time-stamps. @xref{Log}.
+@item mapdefault
+Use only the default mapping table for the next keystroke. @xref{Bindkey Control}.
+@item mapnotnext
+Don't try to do keymapping on the next keystroke. @xref{Bindkey Control}.
+@item maptimeout @var{n}
+Set the inter-character timeout used for keymapping. @xref{Bindkey Control}.
+@item markkeys @var{string}
+Rebind keys in copy mode. @xref{Copy Mode Keys}.
+@item maxwin @var{n}
+Set the maximum window number. @xref{Maxwin}.
+@item meta
+Insert the command character. @xref{Command Character}.
+@item monitor [@var{state}]
+Monitor activity in window. @xref{Monitor}.
+@item mousetrack [@var{on}|@var{off}]
+Enable selecting split regions with mouse clicks. @xref{Mousetrack}.
+@item msgminwait @var{sec}
+Set minimum message wait. @xref{Message Wait}.
+@item msgwait @var{sec}
+Set default message wait. @xref{Message Wait}.
+@item multiuser @var{state}
+Go into single or multi user mode. @xref{Multiuser Session}.
+@item nethack @var{state}
+Use @code{nethack}-like error messages. @xref{Nethack}.
+@item next
+Switch to the next window. @xref{Selecting}.
+@item nonblock [@var{state}|@var{numsecs}]
+Disable flow control to the current display. @xref{Nonblock}.|@var{numsecs}]
+@item number [@var{n}]
+Change/display the current window's number. @xref{Number}.
+@item obuflimit [@var{limit}]
+Select output buffer limit. @xref{Obuflimit}.
+@item only
+Kill all other regions. @xref{Regions}.
+@item other
+Switch to the window you were in last. @xref{Selecting}.
+@item partial @var{state}
+Set window to partial refresh. @xref{Redisplay}.
+@item password [@var{crypted_pw}]
+Set reattach password. @xref{Detach}.
+@item paste [@var{src_regs} [@var{dest_reg}]]
+Paste contents of paste buffer or registers somewhere. @xref{Paste}.
+@item pastefont [@var{state}]
+Include font information in the paste buffer. @xref{Paste}.
+@item pow_break
+Close and Reopen the window's terminal. @xref{Break}.
+@item pow_detach
+Detach and hang up. @xref{Power Detach}.
+@item pow_detach_msg [@var{message}]
+Set message displayed on @code{pow_detach}. @xref{Power Detach}.
+@item prev
+Switch to the previous window. @xref{Selecting}.
+@item printcmd [@var{cmd}]
+Set a command for VT100 printer port emulation. @xref{Printcmd}.
+@item process [@var{key}]
+Treat a register as input to @code{screen}. @xref{Registers}.
+@item quit
+Kill all windows and exit. @xref{Quit}.
+@item readbuf [-e @var{encoding}] [@var{filename}]
+Read the paste buffer from the screen-exchange file. @xref{Screen Exchange}.
+@item readreg [-e @var{encoding}] [@var{reg} [@var{file}]]
+Load a register from paste buffer or file. @xref{Registers}.
+@item redisplay
+Redisplay the current window. @xref{Redisplay}.
+@item register [-e @var{encoding}] @var{key} @var{string}
+Store a string to a register. @xref{Registers}.
+@item remove
+Kill current region. @xref{Regions}.
+@item removebuf
+Delete the screen-exchange file. @xref{Screen Exchange}.
+@item rendition bell | monitor | silence | so @var{attr} [@var{color}]
+Change text attributes in caption for flagged windows. @xref{Rendition}.
+@item reset
+Reset the terminal settings for the window. @xref{Reset}.
+@item resize [(+/-)lines]
+Grow or shrink a region. @xref{Resize}.
+@item screen [@var{opts}] [@var{n}] [@var{cmd} [@var{args}] | //group]
+Create a new window. @xref{Screen Command}.
+@item scrollback @var{num}
+Set size of scrollback buffer. @xref{Scrollback}.
+@item select [@var{n}|-|.]
+Switch to a specified window. @xref{Selecting}.
+@item sessionname [@var{name}]
+Name this session. @xref{Session Name}.
+@item setenv [@var{var} [@var{string}]]
+Set an environment variable for new windows. @xref{Setenv}.
+@item setsid @var{state}
+Controll process group creation for windows. @xref{Setsid}.
+@item shell @var{command}
+Set the default program for new windows. @xref{Shell}.
+@item shelltitle @var{title}
+Set the default name for new windows. @xref{Shell}.
+@item silence [@var{state}|@var{seconds}]
+Monitor a window for inactivity. @xref{Monitor}.
+@item silencewait @var{seconds}
+Default timeout to trigger an inactivity notify. @xref{Monitor}.
+@item sleep @var{num}
+Pause during startup. @xref{Startup}.
+@item slowpaste @var{msec}
+Slow down pasting in windows. @xref{Paste}.
+@item source @var{file}
+Run commands from a file. @xref{Source}.
+@item sorendition [@var{attr} [@var{color}]]
+Deprecated. Use @code{rendition so} instead. @xref{Rendition}.
+@item split
+Split region into two parts. @xref{Regions}.
+@item startup_message @var{state}
+Display copyright notice on startup. @xref{Startup}.
+@item stuff [@var{string}]
+Stuff a string in the input buffer of a window. @xref{Paste}.
+@item su [@var{username} [@var{password} [@var{password2}]]]
+Identify a user. @xref{Multiuser Session}.
+@item suspend
+Put session in background. @xref{Suspend}.
+@item term @var{term}
+Set @code{$TERM} for new windows. @xref{Term}.
+@item termcap @var{term} @var{terminal-tweaks} [@var{window-tweaks}]
+Tweak termcap entries for best performance. @xref{Termcap Syntax}.
+@item terminfo @var{term} @var{terminal-tweaks} [@var{window-tweaks}]
+Ditto, for terminfo systems. @xref{Termcap Syntax}.
+@item termcapinfo @var{term} @var{terminal-tweaks} [@var{window-tweaks}]
+Ditto, for both systems. @xref{Termcap Syntax}.
+@item time [@var{string}]
+Display time and load average. @xref{Time}.
+@item title [@var{windowtitle}]
+Set the name of the current window. @xref{Title Command}.
+@item umask [@var{users}]+/-@var{bits} ...
+Synonym to @code{aclumask}. @xref{Umask}.
+@item unbindall
+Unset all keybindings. @xref{Bind}.
+@item unsetenv @var{var}
+Unset environment variable for new windows. @xref{Setenv}.
+@item utf8 [@var{state} [@var{dstate}]]
+Select character encoding of the current window. @xref{Character Processing}.
+@item vbell [@var{state}]
+Use visual bell. @xref{Bell}.
+@item vbell_msg [@var{message}]
+Set vbell message. @xref{Bell}.
+@item vbellwait @var{sec}
+Set delay for vbell message. @xref{Bell}.
+@item version
+Display @code{screen} version. @xref{Version}.
+@item wall @var{message}
+Write a message to all displays. @xref{Multiuser Session}.
+@item width [@var{cols} [@var{lines}]]
+Set the width of the window. @xref{Window Size}.
+@item windowlist [[-b] [-m] [-g]] | string [@var{string}] | title [@var{title}]
+Present a list of all windows for selection. @xref{Windowlist}.
+@item windows
+List active windows. @xref{Windows}.
+@item wrap [ on | off ]
+Control line-wrap behavior. @xref{Wrap}.
+@item writebuf [-e @var{encoding}] [@var{filename}]
+Write paste buffer to screen-exchange file. @xref{Screen Exchange}.
+@item writelock @var{on}|@var{off}|@var{auto}
+Grant exclusive write permission. @xref{Multiuser Session}.
+@item xoff
+Send an XOFF character. @xref{XON/XOFF}.
+@item xon
+Send an XON character. @xref{XON/XOFF}.
+@item zmodem [off|auto|catch|pass]
+Define how screen treats zmodem requests. @xref{Zmodem}.
+@item zombie [@var{keys} [onerror] ]
+Keep dead windows. @xref{Zombie}.
+@end table
+
+@node New Window, Selecting, Commands, Top
+@chapter New Window
+
+This section describes the commands for creating a new window for
+running programs. When a new window is created, the first available
+number is assigned to it.
+The number of windows is limited at compile-time by the MAXWIN
+configuration parameter (which defaults to 40).
+
+@menu
+* Chdir:: Change the working directory for new windows.
+* Screen Command:: Create a new window.
+* Setenv:: Set environment variables for new windows.
+* Shell:: Parameters for shell windows.
+* Term:: Set the terminal type for new windows.
+* Window Types:: Creating different types of windows.
+* Window Groups:: Grouping windows together
+@end menu
+
+@node Chdir, Screen Command, , New Window
+@section Chdir
+@deffn Command chdir [directory]
+(none)@*
+Change the current directory of @code{screen} to the specified directory
+or, if called without an argument, to your home directory (the value of
+the environment variable @code{$HOME}). All windows that are created by means
+of the @code{screen} command from within @file{.screenrc} or by means of
+@kbd{C-a : screen @dots{}} or @kbd{C-a c} use this as their default
+directory. Without a @code{chdir} command, this would be the directory
+from which @code{screen} was invoked. Hardcopy and log files are always
+written to the @emph{window's} default directory, @emph{not} the current
+directory of the process running in the window. You can use this
+command multiple times in your @file{.screenrc} to start various windows
+in different default directories, but the last @code{chdir} value will
+affect all the windows you create interactively.
+@end deffn
+
+@node Screen Command, Setenv, Chdir, New Window
+@section Screen Command
+@kindex c
+@kindex C-c
+@deffn Command screen [opts] [n] [cmd [args] @var{| //group}]
+(@kbd{C-a c}, @kbd{C-a C-c})@*
+Establish a new window. The flow-control options (@samp{-f}, @samp{-fn}
+and @samp{-fa}), title option (@samp{-t}), login options
+(@samp{-l} and @samp{-ln}) , terminal type option (@samp{-T @var{term}}),
+the all-capability-flag (@samp{-a}) and scrollback option
+(@samp{-h @var{num}}) may be specified with each command.
+The option (@samp{-M}) turns monitoring on for this window.
+The option (@samp{-L}) turns output logging on for this window.
+If an optional number @var{n} in the range 0@dots{}MAXWIN-1 is given,
+the window number @var{n} is assigned to the newly created window (or,
+if this number is already in-use, the next available number). If a
+command is specified after @code{screen}, this command (with the given
+arguments) is started in the window; otherwise, a shell is created.
+If @samp{//group} is supplied, a container-type window is created in
+which other windows may be created inside it. @xref{Window Groups}.
+
+Screen has built in some functionality of @samp{cu} and @samp{telnet}.
+@xref{Window Types}.
+@end deffn
+
+Thus, if your @file{.screenrc} contains the lines
+
+@example
+# example for .screenrc:
+screen 1
+screen -fn -t foobar 2 -L telnet foobar
+@end example
+
+@noindent
+@code{screen} creates a shell window (in window #1) and a window with a
+TELNET connection to the machine foobar (with no flow-control using the
+title @samp{foobar} in window #2) and will write a logfile @samp{screenlog.2}
+of the telnet session. If you do not include any
+@code{screen} commands in your @file{.screenrc} file, then @code{screen}
+defaults to creating a single shell window, number zero. When the
+initialization is completed, @code{screen} switches to the last window
+specified in your .screenrc file or, if none, it opens default window
+#0.
+
+@node Setenv, Shell, Screen Command, New Window
+@section Setenv
+@deffn Command setenv var string
+(none)@*
+Set the environment variable @var{var} to value @var{string}.
+If only @var{var} is specified, the user will be prompted to enter a value.
+If no parameters are specified, the user will be prompted for both variable
+and value. The environment is inherited by all subsequently forked shells.
+@end deffn
+
+@deffn Command unsetenv var
+(none)@*
+Unset an environment variable.
+@end deffn
+
+@node Shell, Term, Setenv, New Window
+@section Shell
+@deffn Command shell command
+@deffnx Command defshell command
+(none)@*
+Set the command to be used to create a new shell. This overrides the
+value of the environment variable @code{$SHELL}. This is useful if
+you'd like to run a tty-enhancer which is expecting to execute the
+program specified in @code{$SHELL}.
+If the command begins with a @samp{-} character, the shell will be started as a
+login-shell. Typical shells do only minimal initialization when not started as a login-shell.
+E.g. Bash will not read your @file{~/.bashrc} unless it is a login-shell.
+
+@code{defshell} is currently a synonym to the @code{shell} .screenrc command.
+@end deffn
+
+@deffn Command shelltitle title
+(none)@*
+Set the title for all shells created during startup or by the C-a C-c
+command. @xref{Naming Windows}, for details about what titles are.
+@end deffn
+
+@node Term, Window Types , Shell, New Window
+@section Term
+@deffn Command term term
+(none)@*
+In each window @code{screen} opens, it sets the @code{$TERM}
+variable to @code{screen} by default, unless no description for
+@code{screen} is installed in the local termcap or terminfo data base.
+In that case it pretends that the terminal emulator is @samp{vt100}.
+This won't do much harm, as @code{screen} is VT100/ANSI compatible. The
+use of the @code{term} command is discouraged for non-default purpose.
+That is, one may want to specify special @code{$TERM} settings (e.g. vt100) for
+the next @code{screen rlogin othermachine} command. Use the command
+@code{screen -T vt100 rlogin othermachine} rather than setting
+and resetting the default.
+@end deffn
+
+@node Window Types, Window Groups, Term, New Window
+@section Window Types
+@cindex window types
+Screen provides three different window types. New windows are created
+with @code{screen}'s @samp{screen} command (@pxref{Screen Command}).
+The first parameter to the @samp{screen} command defines which
+type of window is created. The different window types are all
+special cases of the normal type. They have been added in order
+to allow @code{screen} to be used efficiently as a console
+with 100 or more windows.
+@itemize @bullet
+@item
+The normal window contains a shell (default, if no parameter is given)
+or any other system command that could be executed from a shell.
+(e.g. @samp{slogin}, etc...).
+
+@item
+If a tty (character special device) name (e.g. @samp{/dev/ttya})
+is specified as the first parameter, then the window is directly
+connected to this device.
+This window type is similar to @samp{screen cu -l /dev/ttya}.
+Read and write access is required on the device node,
+an exclusive open is attempted on the node to mark the connection line
+as busy.
+An optional parameter is allowed consisting of a comma separated
+list of flags in the notation used by @samp{stty(1)}:
+@table @code
+@item <baud_rate>
+Usually 300, 1200, 9600 or 19200. This affects transmission as well as
+receive speed.
+@item cs8 or cs7
+Specify the transmission of eight (or seven) bits per byte.
+@item ixon or -ixon
+Enables (or disables) software flow-control (CTRL-S/CTRL-Q) for sending
+data.
+@item ixoff or -ixoff
+Enables (or disables) software flow-control for receiving data.
+@item istrip or -istrip
+Clear (or keep) the eight bit in each received byte.
+@end table
+
+You may want to specify as many of these options as applicable.
+Unspecified options cause the terminal driver to make up the parameter
+values of the connection. These values are system-dependent and may be
+in defaults or values saved from a previous connection.
+
+For tty windows, the @code{info} command shows some of the modem
+control lines in the status line.
+These may include @samp{RTS}, @samp{CTS}, @samp{DTR}, @samp{CD} and
+more. This depends rather on on the available @code{ioctl()}'s and system
+header files than on the physical capabilities of the serial board.
+The name of a logical low (inactive) signal is preceded by an
+exclamation mark (@samp{!}), otherwise the signal is logical high (active).
+Unsupported but shown signals are usually shown low.
+When the @code{CLOCAL} status bit is true, the whole set of modem signals is
+placed inside curly braces (@samp{@{} and @samp{@}}).
+When the @code{CRTSCTS} or @code{TIOCSOFTCAR} bit is true, the signals
+@samp{CTS} or @samp{CD} are shown in parenthesis, respectively.
+
+For tty windows, the command @code{break} causes the Data transmission
+line (TxD) to go low for a specified period of time. This is expected
+to be interpreted as break signal on the other side.
+No data is sent and no modem control line is changed when a
+@code{break} is issued.
+
+@item
+If the first parameter is @code{//telnet}, the second parameter is
+expected to be a host name, and an optional third parameter may specify
+a TCP port number (default decimal 23). Screen will connect to a
+server listening on the remote host and use the telnet protocol to
+communicate with that server.
+
+For telnet windows, the command @code{info} shows details about
+the connection in square brackets (@samp{[} and @samp{]}) at the end of
+the status line.
+@table @code
+@item b
+BINARY. The connection is in binary mode.
+@item e
+ECHO. Local echo is disabled.
+@item c
+SGA. The connection is in `character mode' (default: `line mode').
+@item t
+TTYPE. The terminal type has been requested by the remote host. Screen
+sends the name @code{screen} unless instructed otherwise (see also the
+command @samp{term}).
+@item w
+NAWS. The remote site is notified about window size changes.
+@item f
+LFLOW. The remote host will send flow control information.
+(Ignored at the moment.)
+@end table
+Additional flags for debugging are @samp{x}, @samp{t} and @samp{n}
+(XDISPLOC, TSPEED and NEWENV).
+
+For telnet windows, the command @code{break} sends the telnet code
+@code{IAC BREAK} (decimal 243) to the remote host.
+
+@end itemize
+
+@node Window Groups, , Window Types, New Window
+@section Window Groups
+@cindex window groups
+Screen provides a method for grouping windows together. Windows can be
+organized in a hierarchical fashion, resembling a tree structure. New
+screens are created using the @code{screen} command while new groups
+are created using @code{screen //group}. @xref{Screen Command}.
+
+Once a new group is created, it will act as a container for windows
+and even other groups. When a group is selected, you will see the
+output of the @code{windowlist} command, allowing you to select a
+window inside. If there are no windows inside a group, use the
+@code{screen} command to create one. Once inside a group, using the
+commands @code{next} and @code{prev} will switch between windows only
+in that group. Using the @code{windowlist} command will give you the
+opportunity to leave the group you are in. @xref{Windowlist}.
+
+@deffn Command group [grouptitle]
+(none)@*
+Change or show the group the current window belongs to. Windows can
+be moved around between different groups by specifying the name of
+the destination group. Without specifying a group, the title of the
+current group is displayed.
+@end deffn
+
+Using groups in combination with layouts will help create a
+multi-desktop experience. One group can be assigned for each
+layout made. Windows can be made, split, and organized within each
+group as desired. Afterwhich, switching between groups can be as easy
+as switching layouts.
+
+@node Selecting, Session Management, New Window, Top
+@chapter Selecting a Window
+
+This section describes the commands for switching between windows in an
+@code{screen} session. The windows are numbered from 0 to 9, and are created
+in that order by default (@pxref{New Window}).
+
+@menu
+* Next and Previous:: Forward or back one window.
+* Other Window:: Switch back and forth between two windows.
+* Select:: Switch to a window (and to one after @code{kill}).
+* Windowlist:: Present a list of all windows for selection.
+@end menu
+
+@node Next and Previous, Other Window, , Selecting
+@section Moving Back and Forth
+@kindex SPC
+@kindex n
+@kindex C-n
+@deffn Command next
+(@kbd{C-a @key{SPC}}, @kbd{C-a n}, @kbd{C-a C-n})@*
+Switch to the next window. This command can be used repeatedly to
+cycle through the list of windows. (On some terminals, C-@key{SPC}
+generates a NUL character, so you must release the control key before
+pressing space.)
+@end deffn
+
+@kindex p
+@kindex C-p
+@kindex C-h
+@kindex Backspace
+@deffn Command prev
+(@kbd{C-a p}, @kbd{C-a C-p}, @kbd{C-a C-h}, @kbd{C-a @key{Backspace}})@*
+Switch to the previous window (the opposite of @kbd{C-a n}).
+@end deffn
+
+@node Other Window, Select, Next and Previous, Selecting
+@section Other Window
+@kindex C-a
+@deffn Command other
+(@kbd{C-a C-a})@*
+Switch to the last window displayed. Note that this command
+defaults to the command character typed twice, unless overridden.
+For instance, if you use the option @samp{-e]x},
+this command becomes @kbd{]]} (@pxref{Command Character}).
+@end deffn
+
+@node Select, Windowlist, Other Window, Selecting
+@section Select
+@kindex 0@dots{}9
+@kindex '
+@deffn Command select [n @var{|-|.}]
+(@kbd{C-a @var{n}}, @kbd{C-a '})@*
+Switch to the window with the number @var{n}.
+If no window number is specified, you get prompted for an
+identifier. This can be a window name (title) or a number.
+When a new window is established, the lowest available number
+is assigned to this window.
+Thus, the first window can be activated by @code{select 0}; there
+can be no more than 10 windows present simultaneously (unless screen is
+compiled with a higher MAXWIN setting).
+There are two special arguments, @code{select -} switches to the
+internal blank window and @code{select .} switches to the
+current window. The latter is useful if used with screen's
+@code{-X} option.
+
+@end deffn
+
+@node Windowlist, , Select, Selecting
+@section Windowlist
+@kindex "
+@deffn Command windowlist [-b] [-m] [-g]
+@deffnx Command windowlist string [@var{string}]
+@deffnx Command windowlist title [@var{title}]
+(@kbd{C-a "})@*
+Display all windows in a table for visual window selection.
+If screen was in a window group, screen will
+back out of the group and then display the windows in that
+group. If the @code{-b} option is given, screen will
+switch to the blank window before presenting the list, so
+that the current window is also selectable.
+The @code{-m} option changes the order of the windows, instead of
+sorting by window numbers screen uses its internal most-recently-used
+list. The @code{-g} option will show the windows inside any groups
+in that level and downwards.
+
+The following keys are used to navigate in @code{windowlist}:
+
+@noindent
+@kbd{k}, @kbd{C-p}, or @kbd{up} Move up one line.
+
+@noindent
+@kbd{j}, @kbd{C-n}, or @kbd{down} Move down one line.
+
+@noindent
+@kbd{C-g} or @kbd{escape} Exit windowlist.
+
+@noindent
+@kbd{C-a} or @kbd{home} Move to the first line.
+
+@noindent
+@kbd{C-e} or @kbd{end} Move to the last line.
+
+@noindent
+@kbd{C-u} or @kbd{C-d} Move one half page up or down.
+
+@noindent
+@kbd{C-b} or @kbd{C-f} Move one full page up or down.
+
+@indent
+@kbd{0..9} Using the number keys, move to the selected line.
+
+@noindent
+@kbd{mouseclick} Move to the selected line. Available when
+@code{mousetrack} is set to @code{on}.
+
+@noindent
+@kbd{/} Search.
+
+@noindent
+@kbd{n} Repeat search in the forward direction.
+
+@noindent
+@kbd{N} Repeat search in the backward direction.
+
+@noindent
+@kbd{m} Toggle MRU.
+
+@noindent
+@kbd{g} Toggle group nesting.
+
+@noindent
+@kbd{a} All window view.
+
+@noindent
+@kbd{C-h} or @kbd{backspace} Back out the group.
+
+@noindent
+@kbd{,} Switch numbers with the previous window.
+
+@noindent
+@kbd{.} Switch numbers with the next window.
+
+@noindent
+@kbd{K} Kill that window.
+
+@noindent
+@kbd{space} or @kbd{enter} Select that window.
+
+The table format can be changed with the string and title
+option, the title is displayed as table heading, while the
+lines are made by using the string setting. The default
+setting is @samp{Num Name%=Flags} for the title and
+@samp{%3n %t%=%f} for the lines. See the string escapes chapter
+(@pxref{String Escapes}) for more codes (e.g. color settings).
+
+@code{Windowlist} needs a region size of at least 10 characters
+wide and 6 characters high in order to display.
+@end deffn
+
+@node Session Management, Regions, Selecting, Top
+@chapter Session Management Commands
+
+Perhaps the most useful feature of @code{screen} is the way it allows
+the user to move a session between terminals, by detaching and
+reattaching. This also makes life easier for modem users who have to
+deal with unexpected loss of carrier.
+
+@menu
+* Detach:: Disconnect @code{screen} from your terminal.
+* Power Detach:: Detach and log out.
+* Lock:: Lock your terminal temporarily.
+* Multiuser Session:: Changing number of allowed users.
+* Session Name:: Rename your session for later reattachment.
+* Suspend:: Suspend your session.
+* Quit:: Terminate your session.
+@end menu
+
+@node Detach, Power Detach, , Session Management
+@section Detach
+
+@deffn Command autodetach state
+(none)@*
+Sets whether @code{screen} will automatically detach upon hangup, which
+saves all your running programs until they are resumed with a
+@code{screen -r} command. When turned off, a hangup signal will
+terminate @code{screen} and all the processes it contains. Autodetach is
+on by default.
+@end deffn
+
+@kindex d
+@kindex C-d
+@deffn Command detach
+(@kbd{C-a d}, @kbd{C-a C-d})@*
+Detach the @code{screen} session (disconnect it from the terminal and
+put it into the background). A detached @code{screen} can be resumed by
+invoking @code{screen} with the @code{-r} option (@pxref{Invoking
+Screen}).
+The @code{-h} option tells screen to immediately close the connection
+to the terminal (@samp{hangup}).
+@end deffn
+
+@deffn Command password [crypted_pw]
+(none)@*
+Present a crypted password in your @file{.screenrc} file and screen will
+ask for it, whenever someone attempts to resume a detached session. This
+is useful, if you have privileged programs running under @code{screen}
+and you want to protect your session from reattach attempts by users
+that managed to assume your uid. (I.e. any superuser.) If no crypted
+password is specified, screen prompts twice a password and places its
+encryption in the paste buffer. Default is `none', which disables
+password checking.
+@end deffn
+
+@node Power Detach, Lock, Detach, Session Management
+@section Power Detach
+
+@kindex D
+@deffn Command pow_detach
+(@kbd{C-a D D})@*
+Mainly the same as @code{detach}, but also sends a HANGUP signal
+to the parent process of @code{screen}.@*
+@emph{Caution}: This will result in a
+logout if @code{screen} was started from your login-shell.
+@end deffn
+
+@deffn Command pow_detach_msg [message]
+(none)@*
+The @var{message} specified here is output whenever a power detach is
+performed. It may be used as a replacement for a logout message or to reset
+baud rate, etc.
+Without a parameter, the current message is shown.
+@end deffn
+
+@node Lock, Multiuser Session, Power Detach, Session Management
+@section Lock
+@kindex x
+@kindex C-x
+@deffn Command lockscreen
+(@kbd{C-a x}, @kbd{C-a C-x})@*
+Call a screenlock program (@file{/local/bin/lck} or @file{/usr/bin/lock}
+or a builtin, if no other is available). Screen does not accept any
+command keys until this program terminates. Meanwhile processes in the
+windows may continue, as the windows are in the detached state.
+The screenlock program may be changed through the environment variable
+@code{$LOCKPRG} (which must be set in the shell from which @code{screen}
+is started) and is executed with the user's uid and gid.
+
+Warning: When you leave other shells unlocked and have no password set
+on @code{screen}, the lock is void: One could easily re-attach from an
+unlocked shell. This feature should rather be called
+@code{lockterminal}.
+@end deffn
+
+@node Multiuser Session, Session Name, Lock, Session Management
+@section Multiuser Session
+@cindex multiuser session
+
+These commands allow other users to gain access to one single @code{screen}
+session. When attaching to a multiuser @code{screen} the sessionname is
+specified as @code{username/sessionname} to the @code{-S} command line option.
+@code{Screen} must be compiled with multiuser support to enable features
+described here.
+
+@menu
+* Multiuser:: Enable / Disable multiuser mode.
+* Acladd:: Enable a specific user.
+* Aclchg:: Change a users permissions.
+* Acldel:: Disable a specific user.
+* Aclgrp:: Grant a user permissions to other users.
+* Displays:: List all active users at their displays.
+* Umask:: Predefine access to new windows.
+* Wall:: Write a message to all users.
+* Writelock:: Grant exclusive window access.
+* Su:: Substitute user.
+@end menu
+
+@node Multiuser, Acladd, , Multiuser Session
+@subsection Multiuser
+@deffn Command multiuser @var{state}
+(none)@*
+Switch between single-user and multi-user mode. Standard screen operation is
+single-user. In multi-user mode the commands @code{acladd}, @code{aclchg} and
+@code{acldel} can be used to enable (and disable) other users accessing this
+@code{screen}.
+@end deffn
+
+@node Acladd, Aclchg, Multiuser, Multiuser Session
+@subsection Acladd
+@deffn Command acladd @var{usernames}
+@deffnx Command addacl @var{usernames}
+(none)@*
+Enable users to fully access this screen session. @var{Usernames} can be one
+user or a comma separated list of users. This command enables to attach to
+the @code{screen} session and performs the equivalent of
+@code{aclchg @var{usernames} +rwx "#?"}. To add a user with restricted access,
+use the @code{aclchg} command below.
+@code{Addacl} is a synonym to @code{acladd}.
+Multi-user mode only.
+@end deffn
+
+@node Aclchg, Acldel, Acladd, Multiuser Session
+@subsection Aclchg
+@deffn Command aclchg @var{usernames permbits list}
+@deffnx Command chacl @var{usernames permbits list}
+(none)@*
+Change permissions for a comma separated list of users.
+Permission bits are represented as @samp{r}, @samp{w} and @samp{x}.
+Prefixing @samp{+} grants the permission, @samp{-} removes it. The third
+parameter is a comma separated list of commands or windows (specified either
+by number or title). The special list @samp{#} refers to all windows, @samp{?}
+to all commands. If @var{usernames} consists of a single @samp{*}, all
+known users are affected.
+A command can be executed when the user has the @samp{x} bit for it. The user
+can type input to a window when he has its @samp{w} bit set and no other
+user obtains a writelock for this window. Other bits are currently ignored.
+To withdraw the writelock from another user in e.g. window 2:
+@samp{aclchg @var{username} -w+w 2}. To allow read-only access
+to the session: @samp{aclchg @var{username} -w "#"}. As soon as a user's name
+is known to screen, he can attach to the session and (per default) has full
+permissions for all command and windows. Execution permission for the acl
+commands, @code{at} and others should also be removed or the user may be able
+to regain write permission.
+@code{Chacl} is a synonym to @code{aclchg}.
+Multi-user mode only.
+@end deffn
+
+@node Acldel, Aclgrp, Aclchg, Multiuser Session
+@subsection Acldel
+@deffn Command acldel @var{username}
+(none)@*
+Remove a user from screen's access control list. If currently attached, all the
+user's displays are detached from the session. He cannot attach again.
+Multi-user mode only.
+@end deffn
+
+@node Aclgrp, Displays, Acldel, Multiuser Session
+@subsection Aclgrp
+@deffn Command aclgrp @var{username} [@var{groupname}]
+(none)@*
+Creates groups of users that share common access rights. The
+name of the group is the username of the group leader. Each
+member of the group inherits the permissions that are
+granted to the group leader. That means, if a user fails an
+access check, another check is made for the group leader.
+A user is removed from all groups the special value @samp{none}
+is used for @var{groupname}. If the second parameter is omitted
+all groups the user is in are listed.
+@end deffn
+
+@node Displays, Umask, Aclgrp, Multiuser Session
+@subsection Displays
+@kindex *
+@deffn Command displays
+(@kbd{C-a *})@*
+Shows a tabular listing of all currently connected user
+front-ends (displays). This is most useful for multiuser
+sessions.
+
+The following keys can be used in @code{displays} list:
+
+@noindent
+@kbd{k}, @kbd{C-p}, or @kbd{up} Move up one line.
+
+@noindent
+@kbd{j}, @kbd{C-n}, or @kbd{down} Move down one line.
+
+@noindent
+@kbd{C-a} or @kbd{home} Move to the first line.
+
+@noindent
+@kbd{C-e} or @kbd{end} Move to the last line.
+
+@noindent
+@kbd{C-u} or @kbd{C-d} Move one half page up or down.
+
+@noindent
+@kbd{C-b} or @kbd{C-f} Move one full page up or down.
+
+@noindent
+@kbd{mouseclick} Move to the selected line. Available when
+@code{mousetrack} is set to @code{on}.
+
+@noindent
+@kbd{space} Refresh the list.
+
+@noindent
+@kbd{d} Detach the selected display.
+
+@noindent
+@kbd{D} Power detach the selected display.
+
+@noindent
+@kbd{C-g}, @kbd{enter}, or @kbd{escape} Exit the list.
+
+
+The following is an example of what @code{displays} could
+look like:
+
+@example
+xterm 80x42 jnweiger@@/dev/ttyp4 0(m11) &rWx
+facit 80x24 mlschroe@@/dev/ttyhf nb 11(tcsh) rwx
+xterm 80x42 jnhollma@@/dev/ttyp5 0(m11) &R.x
+ (A) (B) (C) (D) (E) (F)(G) (H)(I)
+@end example
+
+The legend is as follows:
+@*(A) The terminal type known by @code{screen} for this display.
+@*(B) Displays geometry as width x height.
+@*(C) Username who is logged in at the display.
+@*(D) Device name of the display or the attached device
+@*(E) Display is in blocking or nonblocking mode. The available
+ modes are "nb", "NB", "Z<", "Z>", and "BL".
+@*(F) Number of the window
+@*(G) Name/title of window
+@*(H) Whether the window is shared
+@*(I) Window permissions. Made up of three characters:
+@display
+(1st character)
+ @samp{-} : no read
+ @samp{r} : read
+ @samp{R} : read only due to foreign wlock
+(2nd character)
+ @samp{-} : no write
+ @samp{.} : write suppressed by foreign wlock
+ @samp{w} : write
+ @samp{W} : own wlock
+(3rd character)
+ @samp{-} : no execute
+ @samp{x} : execute
+@end display
+
+@code{Displays} needs a region size of at least 10 characters
+wide and 5 characters high in order to display.
+@end deffn
+
+@node Umask, Wall, Displays, Multiuser Session
+@subsection aclumask
+@deffn Command aclumask [@var{users}]+/-@var{bits} ...
+@deffnx Command umask [@var{users}]+/-@var{bits} ...
+(none)@*
+This specifies the access other users have to windows that
+will be created by the caller of the command. @var{Users} may be no,
+one or a comma separated list of known usernames. If no users are
+specified, a list of all currently known users is assumed.
+@var{Bits} is any combination of access control bits allowed
+defined with the @code{aclchg} command. The special username @samp{?}
+predefines the access that not yet known users will be
+granted to any window initially. The special username @samp{??}
+predefines the access that not yet known users are granted
+to any command. Rights of the special username nobody cannot
+be changed (see the @code{su} command).
+@code{Umask} is a synonym to @code{aclumask}.
+@end deffn
+
+
+@node Wall, Writelock, Umask, Multiuser Session
+@subsection Wall
+@deffn Command wall @var{message}
+(none)@*
+Write a message to all displays. The message will appear in the terminal's
+status line.
+@end deffn
+
+@node Writelock, Su , Wall, Multiuser Session
+@subsection Writelock
+@deffn Command writelock @var{on|off|auto}
+(none)@*
+In addition to access control lists, not all users may be able to write to
+the same window at once. Per default, writelock is in @samp{auto} mode and
+grants exclusive input permission to the user who is the first to switch
+to the particular window. When he leaves the window, other users may obtain
+the writelock (automatically). The writelock of the current window is disabled
+by the command @code{writelock off}. If the user issues the command
+@code{writelock on} he keeps the exclusive write permission while switching
+to other windows.
+@end deffn
+
+@deffn Command defwritelock @var{on|off|auto}
+(none)@*
+Sets the default writelock behavior for new windows. Initially all windows
+will be created with no writelocks.
+@end deffn
+
+@node Su, , Writelock, Multiuser Session
+@subsection Su
+@deffn Command su [@var{username} [@var{password} [@var{password2}]]]
+(none)@*
+Substitute the user of a display. The command prompts for
+all parameters that are omitted. If passwords are specified
+as parameters, they have to be specified un-crypted. The
+first password is matched against the systems passwd database,
+the second password is matched against the @code{screen}
+password as set with the commands @code{acladd} or @code{password}.
+@code{Su} may be useful for the @code{screen} administrator to test
+multiuser setups.
+When the identification fails, the user has
+access to the commands available for user @samp{nobody}. These are
+@code{detach}, @code{license}, @code{version}, @code{help} and
+@code{displays}.
+@end deffn
+
+@node Session Name, Suspend, Multiuser Session, Session Management
+@section Session Name
+@deffn Command sessionname [@var{name}]
+(none)@*
+Rename the current session. Note that for @code{screen -list} the name
+shows up with the process-id prepended. If the argument @var{name} is
+omitted, the name of this session is displayed.@*
+@emph{Caution}: The @code{$STY}
+environment variable will still reflect the old name in pre-existing
+shells. This may result in
+confusion. Use of this command is generally
+discouraged. Use the @code{-S} command-line option if you want to
+name a new session.The default is constructed from the tty and host names.
+@end deffn
+
+@node Suspend, Quit, Session Name, Session Management
+@section Suspend
+@kindex z
+@kindex C-z
+@deffn Command suspend
+(@kbd{C-a z}, @kbd{C-a C-z})@*
+Suspend @code{screen}. The windows are in the detached state while
+@code{screen} is suspended. This feature relies on the parent shell
+being able to do job control.
+@end deffn
+
+@node Quit, , Suspend, Session Management
+@section Quit
+@kindex \
+@deffn Command quit
+(@kbd{C-a \})@*
+Kill all windows and terminate @code{screen}.
+(@pxref{Key Binding}).
+@end deffn
+
+@node Regions, Window Settings, Session Management, Top
+@chapter Regions
+@cindex regions
+Screen has the ability to display more than one window on the
+user's display. This is done by splitting the screen in regions,
+which can contain different windows.
+
+@menu
+* Split:: Split a region into two
+* Focus:: Change to the next region
+* Only:: Delete all other regions
+* Remove:: Delete the current region
+* Resize:: Grow or shrink a region
+* Caption:: Control the window's caption
+* Fit:: Resize a window to fit the region
+* Focusminsize:: Force a minimum size on a current region
+* Layout:: Manage groups of regions
+@end menu
+
+@node Split, Focus, , Regions
+@section Split
+@kindex S
+@kindex |
+@deffn Command split [-v]
+(@kbd{C-a S}, @kbd{C-a |})@*
+Split the current region into two new ones. All regions on the
+display are resized to make room for the new region. The blank
+window is displayed in the new region. The default is to create
+a horizontal split, putting the new regions on the top and
+bottom of each other. Using @samp{-v} will create a vertical split,
+causing the new regions to appear side by side of each other.
+Use the @code{remove} or the @code{only} command to delete regions.
+Use @code{focus} to toggle between regions.
+
+When a region is split opposite of how it was previously split
+(that is, vertical then horizontal or horizontal then vertical),
+a new layer is created. The layer is used to group together the
+regions that are split the same. Normally, as a user, you should
+not see nor have to worry about layers, but they will affect how
+some commands (@code{focus} and @code{resize}) behave.
+
+With this current implementation of @code{screen}, scrolling data
+will appear much slower in a vertically split region than one
+that is not. This should be taken into consideration if you need
+to use system commands such as @code{cat} or @code{tail -f}.
+@end deffn
+
+@node Focus, Only, Split, Regions
+@section Focus
+@kindex TAB
+@deffn Command focus [ @code{next|prev|up|down|left|right|top|bottom} ]
+(@kbd{C-a @key{Tab}})@*
+Move the input focus to the next region. This is done in a cyclic
+way so that the top left region is selected after the bottom right
+one. If no option is given it defaults to @code{next}. The next
+region to be selected is determined by how the regions are layered.
+Normally, the next region in the same layer would be selected.
+However, if that next region contains one or more layers, the first
+region in the highest layer is selected first. If you are at the
+last region of the current layer, @code{next} will move the focus
+to the next region in the lower layer (if there is a lower layer).
+@code{Prev} cycles in the opposite order. @xref{Split} for more
+information about layers.
+
+The rest of the options (@code{up}, @code{down}, @code{left},
+@code{right}, @code{top}, and @code{bottom}) are more indifferent
+to layers. The option @code{up} will move the focus upward to the
+region that is touching the upper left corner of the current region.
+@code{Down} will move downward to the region that is touching the
+lower left corner of the current region. The option @code{left}
+will move the focus leftward to the region that is touching the
+upper left corner of the current region, while @code{right} will
+move rightward to the region that is touching the upper right corner
+of the current region. Moving left from a left most region or moving
+right from a right most region will result in no action.
+
+The option @code{top} will move the focus to the very first region
+in the upper list corner of the screen, and @code{bottom} will move
+to the region in the bottom right corner of the screen. Moving up from
+a top most region or moving down from a bottom most region will result
+in no action.
+
+Useful bindings are (h, j, k, and l as in vi):
+@example
+bind h focus left
+bind j focus down
+bind k focus up
+bind l focus right
+bind t focus top
+bind b focus bottom
+@end example
+
+Note that @samp{k} is traditionally bound to the @code{kill} command.
+@end deffn
+
+@node Only, Remove, Focus, Regions
+@section Only
+@kindex Q
+@deffn Command only
+(@kbd{C-a Q})@*
+Kill all regions but the current one.
+@end deffn
+
+@node Remove, Resize, Only, Regions
+@section Remove
+@kindex X
+@deffn Command remove
+(@kbd{C-a X})@*
+Kill the current region. This is a no-op if there is only one region.
+@end deffn
+
+@node Resize, Caption, Remove, Regions
+@section Resize
+@deffn Command resize [@code{-h|-v|-b|-l|-p}] [ [+|-]@var{n}[@code{%}] | @code{=} | @code{max} | @code{min} | @code{_} | @code{0} ]
+(none)@*
+Resize the current region. The space will be removed from or added to
+the surrounding regions depending on the order of the splits.
+The available options for resizing are @samp{-h}(horizontal),
+@samp{-v}(vertical), @samp{-b}(both), @samp{-l}(local to layer),
+and @samp{-p}(perpendicular). Horizontal resizes will add or remove width
+to a region, vertical will add or remove height, and both will add or
+remove size from both dimensions. Local and perpendicular are similar to
+horizontal and vertical, but they take in account of how a region was split.
+If a region's last split was horizontal, a local resize will work like a
+vertical resize. If a region's last split was vertical, a local resize will
+work like a horizontal resize. Perpendicular resizes work in opposite of
+local resizes. If no option is specified, local is the default.
+
+The amount of lines to add or remove can be expressed a couple of different
+ways. By specifying a number @var{n} by itself will resize the region by
+that absolute amount. You can specify a relative amount by prefixing a
+plus @samp{+} or minus @samp{-} to the amount, such as adding @code{+n} lines
+or removing @code{-n} lines. Resizing can also be expressed as an absolute
+or relative percentage by postfixing a percent sign @samp{%}. Using zero
+@samp{0} is a synonym for @code{min} and using an underscore @samp{_} is a
+synonym for @code{max}.
+
+Some examples are:
+@example
+resize +N increase current region by N
+resize -N decrease current region by N
+resize N set current region to N
+resize 20% set current region to 20% of original size
+resize +20% increase current region by 20%
+resize -b = make all windows equally
+resize max maximize current region
+resize min minimize current region
+@end example
+
+Without any arguments, @code{screen} will prompt for how you would
+like to resize the current region.
+
+See @code{focusminsize} if you want to restrict the minimun size a region can have.
+
+@end deffn
+
+@node Caption, Fit, Resize, Regions
+@section Caption
+@deffn Command caption @code{always}|@code{splitonly} [string]
+@deffnx Command caption @code{string} [string]
+(none)@*
+This command controls the display of the window captions. Normally
+a caption is only used if more than one window is shown on the
+display (split screen mode). But if the type is set to
+@code{always}, @code{screen} shows a caption
+even if only one window is displayed. The default
+is @samp{splitonly}.
+
+The second form changes the text used for the caption. You can use
+all string escapes (@pxref{String Escapes}). @code{Screen} uses
+a default of @samp{%3n %t}.
+
+You can mix both forms by providing the string as an additional
+argument.
+@end deffn
+
+@node Fit, Focusminsize, Caption, Regions
+@section Fit
+@kindex F
+@deffn Command fit
+(@kbd{C-a F})@*
+Change the window size to the size of the current region. This
+command is needed because screen doesn't adapt the window size
+automatically if the window is displayed more than once.
+@end deffn
+
+@node Focusminsize, Layout, Fit, Regions
+@section Focusminsize
+@deffn Command focusminsize [ (width|@code{max}|@code{_}) (height|@code{max}|@code{_}) ]
+(none)@*
+This forces any currently selected region to be automatically
+resized at least a certain @var{width} and @var{height}. All
+other surrounding regions will be resized in order to accommodate.
+This constraint follows every time the @code{focus} command is
+used. The @code{resize} command can be used to increase either
+dimension of a region, but never below what is set with
+@code{focusminsize}. The underscore @samp{_} is a synonym for
+@code{max}. Setting a @var{width} and @var{height} of @code{0 0}
+(zero zero) will undo any constraints and allow for manual resizing.
+Without any parameters, the minimum width and height is shown.
+@end deffn
+
+@node Layout, , Focusminsize, Regions
+@section Layout
+@cindex layout
+Using regions, and perhaps a large enough terminal, you can give
+@code{screen} more of a desktop feel. By being able to split
+regions horizontally or vertically, you can take advantage of the
+lesser used spaces of your terminal. The catch to these splits has
+been that they're not kept between screen detachments and reattachments.
+
+Layouts will help organize your regions. You can create one
+layout of four horizontal regions and then create a separate layout
+of regions in a two by two array. The regions could contain the same windows,
+but they don't have to. You can easily switch between layouts and keep
+them between detachments and reattachments.
+
+Note that there are several subcommands to @code{layout}.
+
+@deffn Command layout @code{new} [title]
+(none)@*
+Create a new layout. The screen will change to one whole region
+and be switched to the blank window. From here, you build the
+regions and the windows they show as you desire. The new layout
+will be numbered with the smallest available integer, starting
+with zero. You can optionally give a title to your new layout.
+Otherwise, it will have a default title of @code{layout}. You
+can always change the title later by using the command
+@code{layout title}.
+@end deffn
+
+@deffn Command layout @code{remove} [n|title]
+(none)@*
+Remove, or in other words, delete the specified layout. Either
+the number or the title can be specified. Without either
+specification, @code{screen} will remove the current layout.
+
+Removing a layout does not affect your set windows or regions.
+@end deffn
+
+@deffn Command layout @code{next}
+(none)@*
+Switch to the next layout available
+@end deffn
+
+@deffn Command layout @code{prev}
+(none)@*
+Switch to the previous layout available
+@end deffn
+
+@deffn Command layout @code{select} [n|title]
+(none)@*
+Select the desired layout. Either the number or the title can
+be specified. Without either specification, @code{screen} will
+prompt and ask which screen is desired. To see which layouts are
+available, use the @code{layout show} command.
+@end deffn
+
+@deffn Command layout @code{show}
+(none)@*
+List on the message line the number(s) and title(s) of the available
+layout(s). The current layout is flagged.
+@end deffn
+
+@deffn Command layout @code{title} [title]
+(none)@*
+Change or display the title of the current layout. A string given
+will be used to name the layout. Without any options, the current
+title and number is displayed on the message line.
+@end deffn
+
+@deffn Command layout @code{number} [n]
+(none)@*
+Change or display the number of the current layout. An integer given
+will be used to number the layout. Without any options, the current
+number and title is displayed on the message line.
+@end deffn
+
+@deffn Command layout @code{attach} [title|@code{:last}]
+(none)@*
+Change or display which layout to reattach back to. The default is
+@code{:last}, which tells @code{screen} to reattach back to the last
+used layout just before detachment. By supplying a title, You can
+instruct @code{screen} to reattach to a particular layout regardless
+which one was used at the time of detachment. Without any options,
+the layout to reattach to will be shown in the message line.
+@end deffn
+
+@deffn Command layout @code{save} [n|title]
+(none)@*
+Remember the current arrangement of regions. When used, @code{screen}
+will remember the arrangement of vertically and horizontally split
+regions. This arrangement is restored when a @code{screen} session
+is reattached or switched back from a different layout. If the
+session ends or the @code{screen} process dies, the layout
+arrangements are lost. The @code{layout dump} command should help
+in this siutation. If a number
+or title is supplied, @code{screen} will remember the arrangement of
+that particular layout. Without any options, @code{screen} will
+remember the current layout.
+
+Saving your regions can be done automatically by using the
+@code{layout autosave} command.
+@end deffn
+
+@deffn Command layout @code{autosave} [@code{on}|@code{off}]
+(none)@*
+Change or display the status of automatically saving layouts. The
+default is @code{on}, meaning when @code{screen} is detached or
+changed to a different layout, the arrangement of regions and windows
+will be remembered at the time of change and restored upon return.
+If autosave is set to @code{off}, that arrangement will only be
+restored to either to the last manual save, using @code{layout save},
+or to when the layout was first created, to a single region with
+a single window. Without either an @code{on} or an @code{off}, the
+current status is displayed on the message line.
+@end deffn
+
+@deffn Command layout @code{dump} [filename]
+(none)@*
+Write to a file the order of splits made in the current layout. This
+is useful to recreate the order of your regions used in your current
+layout. Only the current layout is recorded. While the order of the
+regions are recorded, the sizes of those regions and which windows
+correspond to which regions are not. If no filename is specified,
+the default is @file{layout-dump}, saved in the directory that the
+@code{screen} process was started in. If the file already exists,
+@code{layout dump} will append to that file. As an example:
+@example
+layout dump /home/user/.screenrc
+@end example
+will save or append the layout to the user's @file{.screenrc} file.
+@end deffn
+
+@node Window Settings, Virtual Terminal, Regions, Top
+@chapter Window Settings
+
+These commands control the way @code{screen} treats individual windows
+in a session. @xref{Virtual Terminal}, for commands to control the
+terminal emulation itself.
+
+@menu
+* Naming Windows:: Control the name of the window
+* Console:: See the host's console messages
+* Kill:: Destroy an unwanted window
+* Login:: Control @file{/etc/utmp} logging
+* Mode:: Control the file mode of the pty
+* Monitor:: Watch for activity or inactivity in a window
+* Windows:: List the active windows
+* Hardstatus:: Set a window's hardstatus line
+@end menu
+
+@node Naming Windows, Console, , Window Settings
+@section Naming Windows (Titles)
+@cindex title
+
+You can customize each window's name in the window display (viewed with
+the @code{windows} command (@pxref{Windows}) by setting it with
+one of the title commands. Normally the name displayed is the actual
+command name of the program created in the window. However, it is
+sometimes useful to distinguish various programs of the same name or to
+change the name on-the-fly to reflect the current state of the window.
+
+The default name for all shell windows can be set with the
+@code{shelltitle} command (@pxref{Shell}). You can specify the name you
+want for a window with the @samp{-t} option to the @code{screen} command
+when the window is created (@pxref{Screen Command}). To change the name after
+the window has been created you can use the title-string escape-sequence
+(@kbd{@key{ESC} k @var{name} @key{ESC} \}) and the @code{title} command
+(C-a A). The former can be output from an application to control the
+window's name under software control, and the latter will prompt for a
+name when typed. You can also bind predefined names to keys with the
+@code{title} command to set things quickly without prompting.
+
+@menu
+* Title Command:: The @code{title} command.
+* Dynamic Titles:: Make shell windows change titles dynamically.
+* Title Prompts:: Set up your shell prompt for dynamic Titles.
+* Title Screenrc:: Set up Titles in your @file{.screenrc}.
+@end menu
+
+@node Title Command, Dynamic Titles, , Naming Windows
+@subsection Title Command
+@kindex A
+@deffn Command title [windowtitle]
+(@kbd{C-a A})@*
+Set the name of the current window to @var{windowtitle}. If no name is
+specified, screen prompts for one.
+@end deffn
+
+@node Dynamic Titles, Title Prompts, Title Command, Naming Windows
+@subsection Dynamic Titles
+@code{screen} has a shell-specific heuristic that is enabled by
+setting the window's name to @var{search|name} and arranging to have a
+null title escape-sequence output as a part of your prompt. The
+@var{search} portion specifies an end-of-prompt search string, while the
+@var{name} portion specifies the default shell name for the window. If
+the @var{name} ends in a @samp{:} @code{screen} will add what it
+believes to be the current command running in the window to the end of
+the specified name (e.g. @var{name:cmd}). Otherwise the current
+command name supersedes the shell name while it is running.
+
+Here's how it works: you must modify your shell prompt to output a null
+title-escape-sequence (@key{ESC} k @key{ESC} \) as a part of your prompt.
+The last part of your prompt must be the same as the string you
+specified for the @var{search} portion of the title. Once this is set
+up, @code{screen} will use the title-escape-sequence to clear the previous
+command name and get ready for the next command. Then, when a newline
+is received from the shell, a search is made for the end of the prompt.
+If found, it will grab the first word after the matched string and use
+it as the command name. If the command name begins with @samp{!},
+@samp{%}, or @samp{^}, @code{screen} will use the first word on the
+following line (if found) in preference to the just-found name. This
+helps csh users get more accurate titles when using job control or
+history recall commands.
+
+@node Title Prompts, Title Screenrc, Dynamic Titles, Naming Windows
+@subsection Setting up your prompt for shell titles
+One thing to keep in mind when adding a null title-escape-sequence to your
+prompt is that some shells (like the csh) count all the non-control
+characters as part of the prompt's length. If these invisible
+characters aren't a multiple of 8 then backspacing over a tab will
+result in an incorrect display. One way to get around this is to use a
+prompt like this:
+
+@example
+set prompt='@value{esc}[0000m@value{esc}k@value{esc}\% '
+@end example
+
+The escape-sequence @samp{@value{esc}[0000m} not only normalizes the
+character attributes, but all the zeros round the length of the
+invisible characters up to 8.
+
+Tcsh handles escape codes in the prompt more intelligently, so you can
+specify your prompt like this:
+
+@example
+set prompt="%@{\ek\e\\%@}\% "
+@end example
+
+Bash users will probably want to echo the escape sequence in the
+PROMPT_COMMAND:
+
+@example
+PROMPT_COMMAND='printf "\033k\033\134"'
+@end example
+
+(I used @samp{\134} to output a @samp{\} because of a bug in v1.04).
+
+@node Title Screenrc, , Title Prompts, Naming Windows
+@subsection Setting up shell titles in your @file{.screenrc}
+Here are some .screenrc examples:
+
+@example
+screen -t top 2 nice top
+@end example
+
+Adding this line to your .screenrc would start a niced version of the
+@code{top} command in window 2 named @samp{top} rather than @samp{nice}.
+
+@example
+shelltitle '> |csh'
+screen 1
+@end example
+
+This file would start a shell using the given shelltitle. The title
+specified is an auto-title that would expect the prompt and the typed
+command to look something like the following:
+
+@example
+/usr/joe/src/dir> trn
+@end example
+
+(it looks after the '> ' for the command name).
+The window status would show the name @samp{trn} while the command was
+running, and revert to @samp{csh} upon completion.
+
+@example
+bind R screen -t '% |root:' su
+@end example
+
+Having this command in your .screenrc would bind the key sequence
+@kbd{C-a R} to the @code{su} command and give it an auto-title name of
+@samp{root:}. For this auto-title to work, the screen could look
+something like this:
+
+@example
+% !em
+emacs file.c
+@end example
+
+Here the user typed the csh history command @code{!em} which ran the
+previously entered @code{emacs} command. The window status would show
+@samp{root:emacs} during the execution of the command, and revert to
+simply @samp{root:} at its completion.
+
+@example
+bind o title
+bind E title ""
+bind u title (unknown)
+@end example
+
+The first binding doesn't have any arguments, so it would prompt you for
+a title when you type @kbd{C-a o}. The second binding would clear an
+auto-titles current setting (C-a E). The third binding would set the
+current window's title to @samp{(unknown)} (C-a u).
+
+@node Console, Kill, Naming Windows, Window Settings
+@section Console
+@deffn Command console [@var{state}]
+(none)@*
+Grabs or un-grabs the machines console output to a window. When the argument
+is omitted the current state is displayed.
+@emph{Note}: Only the owner of @file{/dev/console} can grab the console
+output. This command is only available if the host supports the ioctl
+@code{TIOCCONS}.
+@end deffn
+
+@node Kill, Login, Console, Window Settings
+@section Kill
+
+@kindex k
+@kindex C-k
+@deffn Command kill
+(@kbd{C-a k}, @kbd{C-a C-k})@*
+Kill the current window.@*
+If there is an @code{exec} command running (@pxref{Exec}) then it is killed.
+Otherwise the process (e.g. shell) running in the window receives a
+@code{HANGUP} condition,
+the window structure is removed and screen (your display) switches to another
+window. When the last window is destroyed, @code{screen} exits.
+After a kill screen switches to the previously displayed window.
+@*
+@emph{Caution}: @code{emacs} users may find themselves killing their
+@code{emacs} session when trying to delete the current line. For this
+reason, it is probably wise to use a different command character
+(@pxref{Command Character}) or rebind @code{kill} to another key
+sequence, such as @kbd{C-a K} (@pxref{Key Binding}).
+@end deffn
+
+@node Login, Mode, Kill, Window Settings
+@section Login
+
+@deffn Command deflogin state
+(none)@*
+Same as the @code{login} command except that the default setting for new
+windows is changed. This defaults to `on' unless otherwise specified at
+compile time (@pxref{Installation}). Both commands are only present when
+@code{screen} has been compiled with utmp support.
+@end deffn
+
+@kindex L
+@deffn Command login [state]
+(@kbd{C-a L})@*
+Adds or removes the entry in @file{/etc/utmp} for the current window.
+This controls whether or not the window is @dfn{logged in}. In addition
+to this toggle, it is convenient to have ``log in'' and ``log out''
+keys. For instance, @code{bind I login on} and @code{bind O
+login off} will map these keys to be @kbd{C-a I} and @kbd{C-a O}
+(@pxref{Key Binding}).
+@end deffn
+
+@node Mode, Monitor, Login, Window Settings
+@section Mode
+@deffn Command defmode mode
+(none)@*
+The mode of each newly allocated pseudo-tty is set to @var{mode}.
+@var{mode} is an octal number as used by chmod(1). Defaults to 0622 for
+windows which are logged in, 0600 for others (e.g. when @code{-ln} was
+specified for creation, @pxref{Screen Command}).
+@end deffn
+
+@node Monitor, Windows, Mode, Window Settings
+@section Monitoring
+
+@deffn Command activity message
+(none)@*
+When any activity occurs in a background window that is being monitored,
+@code{screen} displays a notification in the message line. The
+notification message can be redefined by means of the @code{activity}
+command. Each occurrence of @samp{%} in @var{message} is replaced by
+the number of the window in which activity has occurred, and each
+occurrence of @samp{^G} is replaced by the definition for bell in your
+termcap (usually an audible bell). The default message is
+
+@example
+'Activity in window %n'
+@end example
+
+Note that monitoring is off for all windows by default, but can be altered
+by use of the @code{monitor} command (@kbd{C-a M}).
+@end deffn
+
+@deffn Command defmonitor state
+(none)@*
+Same as the @code{monitor} command except that the default setting for
+new windows is changed. Initial setting is `off'.
+@end deffn
+
+@kindex M
+@deffn Command monitor [state]
+(@kbd{C-a M})@*
+Toggles monitoring of the current window. When monitoring is turned on
+and the affected window is switched into the background, the activity
+notification message will be displayed in the status line at the first
+sign of output, and the window will also be marked with an @samp{@@} in
+the window-status display (@pxref{Windows}). Monitoring defaults to
+@samp{off} for all windows.
+@end deffn
+
+@kindex _
+@deffn Command silence [@var{state}|@var{sec}]
+(@kbd{C-a _})@*
+Toggles silence monitoring of windows. When silence is turned on and an
+affected window is switched into the background, you will receive the
+silence notification message in the status line after a specified period
+of inactivity (silence). The default timeout can be changed with the
+@code{silencewait} command or by specifying a number of seconds instead of
+@code{on} or @code{off}. Silence is initially off for all windows.
+@end deffn
+
+@deffn Command defsilence state
+(none)@*
+Same as the @code{silence} command except that the default setting for
+new windows is changed. Initial setting is `off'.
+@end deffn
+
+@deffn Command silencewait @var{seconds}
+(none)@*
+Define the time that all windows monitored for silence should wait
+before displaying a message. Default is 30 seconds.
+@end deffn
+
+@node Windows, Hardstatus, Monitor, Window Settings
+@section Windows
+@kindex w
+@kindex C-w
+@deffn Command windows [ string ]
+(@kbd{C-a w}, @kbd{C-a C-w})@*
+Uses the message line to display a list of all the windows. Each
+window is listed by number with the name of the program running in the
+window (or its title).
+
+The current window is marked with a @samp{*};
+the previous window is marked with a @samp{-};
+all the windows that are logged in are marked with a @samp{$} (@pxref{Login});
+a background window that has received a bell is marked with a @samp{!};
+a background window that is being monitored and has had activity occur is
+marked with an @samp{@@} (@pxref{Monitor});
+a window which has output logging turned on is marked with @samp{(L)};
+windows occupied by other users are marked with @samp{&}
+or @samp{&&} if the window is shared by other users;
+windows in the zombie state are marked with @samp{Z}.
+
+If this list is too long to fit on the terminal's status line only the
+portion around the current window is displayed.
+
+You can customize the output format to any string you like including
+string escapes (@pxref{String Escapes}).
+In this case, if the string parameter is passed, the maximum output
+size is unlimited (instead of 1024 bytes if no parameter is passed).
+@end deffn
+
+@node Hardstatus, Mousetrack, Windows, Window Settings
+@section Hardstatus
+
+@code{Screen} maintains a hardstatus line for every window. If a window
+gets selected, the display's hardstatus will be updated to match
+the window's hardstatus line.
+The hardstatus line can be changed with the ANSI Application
+Program Command (APC): @samp{ESC_<string>ESC\}. As a convenience
+for xterm users the sequence @samp{ESC]0..2;<string>^G} is
+also accepted.
+
+@deffn Command defhstatus [status]
+(none)@*
+The hardstatus line that all new windows will get is set to
+@var{status}.
+This command is useful to make the hardstatus of every window
+display the window number or title or the like. @var{status}
+may contain the same directives as in the window messages, but
+the directive escape character is @samp{^E} (octal 005) instead
+of @samp{%}. This was done to make a misinterpretation of program
+generated hardstatus lines impossible.
+If the parameter @var{status}
+is omitted, the current default string is displayed.
+Per default the hardstatus line of new windows is empty.
+@end deffn
+
+@deffn Command hstatus status
+(none)@*
+Changes the current window's hardstatus line to @var{status}.
+@end deffn
+
+@node Mousetrack, , Hardstatus, Miscellaneous
+@section Mousetrack
+
+@deffn Command mousetrack [ @code{on|off} ]
+(none)@*
+This command determines whether @code{screen} will watch for
+mouse clicks. When this command is enabled, regions that have
+been split in various ways can be selected by pointing to them
+with a mouse and left-clicking them. Without specifying @var{on}
+or @var{off}, the current state is displayed. The default state
+is determined by the @code{defmousetrack} command.
+@end deffn
+
+@deffn Command defmousetrack @code{on|off}
+(none)@*
+This command determines the default state of the @code{mousetrack}
+command, currently defaulting of @var{off}.
+@end deffn
+
+@node Virtual Terminal, Copy and Paste, Window Settings, Top
+@chapter Virtual Terminal
+
+Each window in a @code{screen} session emulates a VT100 terminal, with
+some extra functions added. The VT100 emulator is hard-coded, no other
+terminal types can be emulated.
+The commands described here modify the terminal emulation.
+
+@menu
+* Control Sequences:: Details of the internal VT100 emulation.
+* Input Translation:: How keystrokes are remapped.
+* Digraph:: Entering digraph sequences.
+* Bell:: Getting your attention.
+* Clear:: Clear the window display.
+* Info:: Terminal emulation statistics.
+* Redisplay:: When the display gets confusing.
+* Wrap:: Automatic margins.
+* Reset:: Recovering from ill-behaved applications.
+* Window Size:: Changing the size of your terminal.
+* Character Processing:: Change the effect of special characters.
+@end menu
+
+@node Control Sequences, Input Translation, , Virtual Terminal
+@section Control Sequences
+@cindex control sequences
+The following is a list of control sequences recognized by
+@code{screen}. @samp{(V)} and @samp{(A)} indicate VT100-specific and
+ANSI- or ISO-specific functions, respectively.
+
+@example
+ESC E Next Line
+ESC D Index
+ESC M Reverse Index
+ESC H Horizontal Tab Set
+ESC Z Send VT100 Identification String
+ESC 7 (V) Save Cursor and Attributes
+ESC 8 (V) Restore Cursor and Attributes
+ESC [s (A) Save Cursor and Attributes
+ESC [u (A) Restore Cursor and Attributes
+ESC c Reset to Initial State
+ESC g Visual Bell
+ESC Pn p Cursor Visibility (97801)
+ Pn = 6 Invisible
+ 7 Visible
+ESC = (V) Application Keypad Mode
+ESC > (V) Numeric Keypad Mode
+ESC # 8 (V) Fill Screen with E's
+ESC \ (A) String Terminator
+ESC ^ (A) Privacy Message String (Message Line)
+ESC ! Global Message String (Message Line)
+ESC k Title Definition String
+ESC P (A) Device Control String
+ Outputs a string directly to the host
+ terminal without interpretation.
+ESC _ (A) Application Program Command (Hardstatus)
+ESC ] 0 ; string ^G (A) Operating System Command (Hardstatus, xterm
+ title hack)
+ESC ] 83 ; cmd ^G (A) Execute screen command. This only works if
+ multi-user support is compiled into screen.
+ The pseudo-user ":window:" is used to check
+ the access control list. Use "addacl :window:
+ -rwx #?" to create a user with no rights and
+ allow only the needed commands.
+Control-N (A) Lock Shift G1 (SO)
+Control-O (A) Lock Shift G0 (SI)
+ESC n (A) Lock Shift G2
+ESC o (A) Lock Shift G3
+ESC N (A) Single Shift G2
+ESC O (A) Single Shift G3
+ESC ( Pcs (A) Designate character set as G0
+ESC ) Pcs (A) Designate character set as G1
+ESC * Pcs (A) Designate character set as G2
+ESC + Pcs (A) Designate character set as G3
+ESC [ Pn ; Pn H Direct Cursor Addressing
+ESC [ Pn ; Pn f same as above
+ESC [ Pn J Erase in Display
+ Pn = None or 0 From Cursor to End of Screen
+ 1 From Beginning of Screen to Cursor
+ 2 Entire Screen
+ESC [ Pn K Erase in Line
+ Pn = None or 0 From Cursor to End of Line
+ 1 From Beginning of Line to Cursor
+ 2 Entire Line
+ESC [ Pn X Erase character
+ESC [ Pn A Cursor Up
+ESC [ Pn B Cursor Down
+ESC [ Pn C Cursor Right
+ESC [ Pn D Cursor Left
+ESC [ Pn E Cursor next line
+ESC [ Pn F Cursor previous line
+ESC [ Pn G Cursor horizontal position
+ESC [ Pn ` same as above
+ESC [ Pn d Cursor vertical position
+ESC [ Ps ;...; Ps m Select Graphic Rendition
+ Ps = None or 0 Default Rendition
+ 1 Bold
+ 2 (A) Faint
+ 3 (A) @i{Standout} Mode (ANSI: Italicized)
+ 4 Underlined
+ 5 Blinking
+ 7 Negative Image
+ 22 (A) Normal Intensity
+ 23 (A) @i{Standout} Mode off (ANSI: Italicized off)
+ 24 (A) Not Underlined
+ 25 (A) Not Blinking
+ 27 (A) Positive Image
+ 30 (A) Foreground Black
+ 31 (A) Foreground Red
+ 32 (A) Foreground Green
+ 33 (A) Foreground Yellow
+ 34 (A) Foreground Blue
+ 35 (A) Foreground Magenta
+ 36 (A) Foreground Cyan
+ 37 (A) Foreground White
+ 39 (A) Foreground Default
+ 40 (A) Background Black
+ ... ...
+ 49 (A) Background Default
+ESC [ Pn g Tab Clear
+ Pn = None or 0 Clear Tab at Current Position
+ 3 Clear All Tabs
+ESC [ Pn ; Pn r (V) Set Scrolling Region
+ESC [ Pn I (A) Horizontal Tab
+ESC [ Pn Z (A) Backward Tab
+ESC [ Pn L (A) Insert Line
+ESC [ Pn M (A) Delete Line
+ESC [ Pn @@ (A) Insert Character
+ESC [ Pn P (A) Delete Character
+ESC [ Pn S Scroll Scrolling Region Up
+ESC [ Pn T Scroll Scrolling Region Down
+ESC [ Pn ^ same as above
+ESC [ Ps ;...; Ps h Set Mode
+ESC [ Ps ;...; Ps l Reset Mode
+ Ps = 4 (A) Insert Mode
+ 20 (A) @samp{Automatic Linefeed} Mode.
+ 34 Normal Cursor Visibility
+ ?1 (V) Application Cursor Keys
+ ?3 (V) Change Terminal Width to 132 columns
+ ?5 (V) Reverse Video
+ ?6 (V) @samp{Origin} Mode
+ ?7 (V) @samp{Wrap} Mode
+ ?9 X10 mouse tracking
+ ?25 (V) Visible Cursor
+ ?47 Alternate Screen (old xterm code)
+ ?1000 (V) VT200 mouse tracking
+ ?1047 Alternate Screen (new xterm code)
+ ?1049 Alternate Screen (new xterm code)
+ESC [ 5 i (A) Start relay to printer (ANSI Media Copy)
+ESC [ 4 i (A) Stop relay to printer (ANSI Media Copy)
+ESC [ 8 ; Ph ; Pw t Resize the window to @samp{Ph} lines and
+ @samp{Pw} columns (SunView special)
+ESC [ c Send VT100 Identification String
+ESC [ x (V) Send Terminal Parameter Report
+ESC [ > c Send Secondary Device Attributes String
+ESC [ 6 n Send Cursor Position Report
+
+@end example
+
+
+@node Input Translation, Digraph, Control Sequences, Virtual Terminal
+@section Input Translation
+@cindex input translation
+In order to do a full VT100 emulation @code{screen} has to detect
+that a sequence of characters in the input stream was generated
+by a keypress on the user's keyboard and insert the VT100
+style escape sequence. @code{Screen} has a very flexible way of doing
+this by making it possible to map arbitrary commands on arbitrary
+sequences of characters. For standard VT100 emulation the command
+will always insert a string in the input buffer of the window
+(see also command @code{stuff}, @pxref{Paste}).
+Because the sequences generated by a keypress can
+change after a reattach from a different terminal type, it is
+possible to bind commands to the termcap name of the keys.
+@code{Screen} will insert the correct binding after each
+reattach. See @ref{Bindkey} for further details on the syntax and examples.
+
+Here is the table of the default key bindings. (A) means that the
+command is executed if the keyboard is switched into application
+mode.
+@example
+
+Key name Termcap name Command
+-----------------------------------------------------
+Cursor up ku stuff \033[A
+ stuff \033OA (A)
+Cursor down kd stuff \033[B
+ stuff \033OB (A)
+Cursor right kr stuff \033[C
+ stuff \033OC (A)
+Cursor left kl stuff \033[D
+ stuff \033OD (A)
+Function key 0 k0 stuff \033[10~
+Function key 1 k1 stuff \033OP
+Function key 2 k2 stuff \033OQ
+Function key 3 k3 stuff \033OR
+Function key 4 k4 stuff \033OS
+Function key 5 k5 stuff \033[15~
+Function key 6 k6 stuff \033[17~
+Function key 7 k7 stuff \033[18~
+Function key 8 k8 stuff \033[19~
+Function key 9 k9 stuff \033[20~
+Function key 10 k; stuff \033[21~
+Function key 11 F1 stuff \033[23~
+Function key 12 F2 stuff \033[24~
+Home kh stuff \033[1~
+End kH stuff \033[4~
+Insert kI stuff \033[2~
+Delete kD stuff \033[3~
+Page up kP stuff \033[5~
+Page down kN stuff \033[6~
+Keypad 0 f0 stuff 0
+ stuff \033Op (A)
+Keypad 1 f1 stuff 1
+ stuff \033Oq (A)
+Keypad 2 f2 stuff 2
+ stuff \033Or (A)
+Keypad 3 f3 stuff 3
+ stuff \033Os (A)
+Keypad 4 f4 stuff 4
+ stuff \033Ot (A)
+Keypad 5 f5 stuff 5
+ stuff \033Ou (A)
+Keypad 6 f6 stuff 6
+ stuff \033Ov (A)
+Keypad 7 f7 stuff 7
+ stuff \033Ow (A)
+Keypad 8 f8 stuff 8
+ stuff \033Ox (A)
+Keypad 9 f9 stuff 9
+ stuff \033Oy (A)
+Keypad + f+ stuff +
+ stuff \033Ok (A)
+Keypad - f- stuff -
+ stuff \033Om (A)
+Keypad * f* stuff *
+ stuff \033Oj (A)
+Keypad / f/ stuff /
+ stuff \033Oo (A)
+Keypad = fq stuff =
+ stuff \033OX (A)
+Keypad . f. stuff .
+ stuff \033On (A)
+Keypad , f, stuff ,
+ stuff \033Ol (A)
+Keypad enter fe stuff \015
+ stuff \033OM (A)
+@end example
+
+@node Digraph, Bell, Input Translation, Virtual Terminal
+@section Digraph
+
+@kindex C-v
+@deffn Command digraph [preset [unicode-value]]
+(@kbd{C-a C-v})@*
+This command prompts the user for a digraph sequence. The next
+two characters typed are looked up in a builtin table and the
+resulting character is inserted in the input stream. For example,
+if the user enters @samp{a"}, an a-umlaut will be inserted. If the
+first character entered is a 0 (zero), @code{screen}
+will treat the following characters (up to three) as an octal
+number instead. The optional argument @var{preset}
+is treated as user input, thus one can create an "umlaut" key.
+For example the command @samp{bindkey ^K digraph '"'} enables the user
+to generate an a-umlaut by typing @samp{CTRL-K a}. When a non-zero
+@var{unicode-value} is specified, a new digraph is created with the
+specified preset. The digraph is unset if a zero value is provided
+for the @var{unicode-value}.
+
+The following table is the builtin sequences.
+
+@documentencoding ISO-8859-1
+@example
+ Sequence Octal Digraph Unicode Equivalent
+ -----------------------------------------------
+ ' ', ' ' 160 (space) U+00A0
+ 'N', 'S' 160 (space) U+00A0
+ '~', '!' 161 ¡ U+00A1
+ '!', '!' 161 ¡ U+00A1
+ '!', 'I' 161 ¡ U+00A1
+ 'c', '|' 162 ¢ U+00A2
+ 'c', 't' 162 ¢ U+00A2
+ '$', '$' 163 £ U+00A3
+ 'P', 'd' 163 £ U+00A3
+ 'o', 'x' 164 ¤ U+00A4
+ 'C', 'u' 164 ¤ U+00A4
+ 'C', 'u' 164 ¤ U+00A4
+ 'E', 'u' 164 ¤ U+00A4
+ 'Y', '-' 165 ¥ U+00A5
+ 'Y', 'e' 165 ¥ U+00A5
+ '|', '|' 166 ¦ U+00A6
+ 'B', 'B' 166 ¦ U+00A6
+ 'p', 'a' 167 § U+00A7
+ 'S', 'E' 167 § U+00A7
+ '"', '"' 168 ¨ U+00A8
+ ''', ':' 168 ¨ U+00A8
+ 'c', 'O' 169 © U+00A9
+ 'C', 'o' 169 © U+00A9
+ 'a', '-' 170 ª U+00AA
+ '<', '<' 171 « U+00AB
+ '-', ',' 172 ¬ U+00AC
+ 'N', 'O' 172 ¬ U+00AC
+ '-', '-' 173 ­ U+00AD
+ 'r', 'O' 174 ® U+00AE
+ 'R', 'g' 174 ® U+00AE
+ '-', '=' 175 ¯ U+00AF
+ ''', 'm' 175 ¯ U+00AF
+ '~', 'o' 176 ° U+00B0
+ 'D', 'G' 176 ° U+00B0
+ '+', '-' 177 ± U+00B1
+ '2', '2' 178 ² U+00B2
+ '2', 'S' 178 ² U+00B2
+ '3', '3' 179 ³ U+00B3
+ '3', 'S' 179 ³ U+00B3
+ ''', ''' 180 ´ U+00B4
+ 'j', 'u' 181 µ U+00B5
+ 'M', 'y' 181 µ U+00B5
+ 'p', 'p' 182 ¶ U+00B6
+ 'P', 'I' 182 ¶ U+00B6
+ '~', '.' 183 · U+00B7
+ '.', 'M' 183 · U+00B7
+ ',', ',' 184 ¸ U+00B8
+ ''', ',' 184 ¸ U+00B8
+ '1', '1' 185 ¹ U+00B9
+ '1', 'S' 185 ¹ U+00B9
+ 'o', '-' 186 º U+00BA
+ '>', '>' 187 » U+00BB
+ '1', '4' 188 ¼ U+00BC
+ '1', '2' 189 ½ U+00BD
+ '3', '4' 190 ¾ U+00BE
+ '~', '?' 191 ¿ U+00BF
+ '?', '?' 191 ¿ U+00BF
+ '?', 'I' 191 ¿ U+00BF
+ 'A', '`' 192 À U+00C0
+ 'A', '!' 192 À U+00C0
+ 'A', ''' 193 Á U+00C1
+ 'A', '^' 194 Â U+00C2
+ 'A', '>' 194 Â U+00C2
+ 'A', '~' 195 Ã U+00C3
+ 'A', '?' 195 Ã U+00C3
+ 'A', '"' 196 Ä U+00C4
+ 'A', ':' 196 Ä U+00C4
+ 'A', '@@' 197 Å U+00C5
+ 'A', 'A' 197 Å U+00C5
+ 'A', 'E' 198 Æ U+00C6
+ 'C', ',' 199 Ç U+00C7
+ 'E', '`' 200 È U+00C8
+ 'E', '!' 200 È U+00C8
+ 'E', ''' 201 É U+00C9
+ 'E', '^' 202 Ê U+00CA
+ 'E', '>' 202 Ê U+00CA
+ 'E', '"' 203 Ë U+00CB
+ 'E', ':' 203 Ë U+00CB
+ 'I', '`' 204 Ì U+00CC
+ 'I', '!' 204 Ì U+00CC
+ 'I', ''' 205 Í U+00CD
+ 'I', '^' 206 Î U+00CE
+ 'I', '>' 206 Î U+00CE
+ 'I', '"' 207 Ï U+00CF
+ 'I', ':' 207 Ï U+00CF
+ 'D', '-' 208 Ð U+00D0
+ 'N', '~' 209 Ñ U+00D1
+ 'N', '?' 209 Ñ U+00D1
+ 'O', '`' 210 Ò U+00D2
+ 'O', '!' 210 Ò U+00D2
+ 'O', ''' 211 Ó U+00D3
+ 'O', '^' 212 Ô U+00D4
+ 'O', '>' 212 Ô U+00D4
+ 'O', '~' 213 Õ U+00D5
+ 'O', '?' 213 Õ U+00D5
+ 'O', '"' 214 Ö U+00D6
+ 'O', ':' 214 Ö U+00D6
+ '/', '\' 215 × U+00D7
+ '*', 'x' 215 × U+00D7
+ 'O', '/' 216 Ø U+00D8
+ 'U', '`' 217 Ù U+00D9
+ 'U', '!' 217 Ù U+00D9
+ 'U', ''' 218 Ú U+00DA
+ 'U', '^' 219 Û U+00DB
+ 'U', '>' 219 Û U+00DB
+ 'U', '"' 220 Ü U+00DC
+ 'U', ':' 220 Ü U+00DC
+ 'Y', ''' 221 Ý U+00DD
+ 'I', 'p' 222 Þ U+00DE
+ 'T', 'H' 222 Þ U+00DE
+ 's', 's' 223 ß U+00DF
+ 's', '"' 223 ß U+00DF
+ 'a', '`' 224 à U+00E0
+ 'a', '!' 224 à U+00E0
+ 'a', ''' 225 á U+00E1
+ 'a', '^' 226 â U+00E2
+ 'a', '>' 226 â U+00E2
+ 'a', '~' 227 ã U+00E3
+ 'a', '?' 227 ã U+00E3
+ 'a', '"' 228 ä U+00E4
+ 'a', ':' 228 ä U+00E4
+ 'a', 'a' 229 å U+00E5
+ 'a', 'e' 230 æ U+00E6
+ 'c', ',' 231 ç U+00E7
+ 'e', '`' 232 è U+00E8
+ 'e', '!' 232 è U+00E8
+ 'e', ''' 233 é U+00E9
+ 'e', '^' 234 ê U+00EA
+ 'e', '>' 234 ê U+00EA
+ 'e', '"' 235 ë U+00EB
+ 'e', ':' 235 ë U+00EB
+ 'i', '`' 236 ì U+00EC
+ 'i', '!' 236 ì U+00EC
+ 'i', ''' 237 í U+00ED
+ 'i', '^' 238 î U+00EE
+ 'i', '>' 238 î U+00EE
+ 'i', '"' 239 ï U+00EF
+ 'i', ':' 239 ï U+00EF
+ 'd', '-' 240 ð U+00F0
+ 'n', '~' 241 ñ U+00F1
+ 'n', '?' 241 ñ U+00F1
+ 'o', '`' 242 ò U+00F2
+ 'o', '!' 242 ò U+00F2
+ 'o', ''' 243 ó U+00F3
+ 'o', '^' 244 ô U+00F4
+ 'o', '>' 244 ô U+00F4
+ 'o', '~' 245 õ U+00F5
+ 'o', '?' 245 õ U+00F5
+ 'o', '"' 246 ö U+00F6
+ 'o', ':' 246 ö U+00F6
+ ':', '-' 247 ÷ U+00F7
+ 'o', '/' 248 ø U+00F8
+ 'u', '`' 249 ù U+00F9
+ 'u', '!' 249 ù U+00F9
+ 'u', ''' 250 ú U+00FA
+ 'u', '^' 251 û U+00FB
+ 'u', '>' 251 û U+00FB
+ 'u', '"' 252 ü U+00FC
+ 'u', ':' 252 ü U+00FC
+ 'y', ''' 253 ý U+00FD
+ 'i', 'p' 254 þ U+00FE
+ 't', 'h' 254 þ U+00FE
+ 'y', '"' 255 ÿ U+00FF
+ 'y', ':' 255 ÿ U+00FF
+ '"', '[' 196 Ä U+00C4
+ '"', '\' 214 Ö U+00D6
+ '"', ']' 220 Ü U+00DC
+ '"', '@{' 228 ä U+00E4
+ '"', '|' 246 ö U+00F6
+ '"', '@}' 252 ü U+00FC
+ '"', '~' 223 ß U+00DF
+@end example
+
+@end deffn
+
+@node Bell, Clear, Digraph, Virtual Terminal
+@section Bell
+
+@deffn Command bell_msg [message]
+(none)@*
+When a bell character is sent to a background window, @code{screen}
+displays a notification in the message line. The notification message
+can be re-defined by this command. Each occurrence
+of @samp{%} in @var{message} is replaced by the number of the window to
+which a bell has been sent, and each occurrence of @samp{^G} is replaced
+by the definition for bell in your termcap (usually an audible bell).
+The default message is
+
+@example
+'Bell in window %n'
+@end example
+
+An empty message can be supplied to the @code{bell_msg} command to suppress
+output of a message line (@code{bell_msg ""}).
+Without a parameter, the current message is shown.
+@end deffn
+
+@kindex C-g
+@deffn Command vbell [state]
+(@kbd{C-a C-g})@*
+Sets or toggles the visual bell setting for the current window. If
+@code{vbell} is switched to @samp{on}, but your
+terminal does not support a visual bell, the visual bell message is
+displayed in the status line when the bell character is received.
+Visual bell support of a terminal is
+defined by the termcap variable @code{vb}. @xref{Bell, , Visual Bell,
+termcap, The Termcap Manual}, for more information on visual bells.
+The equivalent terminfo capability is @code{flash}.
+
+Per default, @code{vbell} is @samp{off}, thus the audible bell is used.
+@end deffn
+
+@deffn Command vbell_msg [message]
+(none)@*
+Sets the visual bell message. @var{Message} is printed to the status
+line if the window receives a bell character (^G), @code{vbell} is
+set to @samp{on} and the terminal does not support a visual bell.
+The default message is @samp{Wuff, Wuff!!}.
+Without a parameter, the current message is shown.
+@end deffn
+
+@deffn Command vbellwait sec
+(none)@*
+Define a delay in seconds after each display of @code{screen} 's visual
+bell message. The default is 1 second.
+@end deffn
+
+@node Clear, Info, Bell, Virtual Terminal
+@section Clear
+@kindex C
+@deffn Command clear
+(@kbd{C-a C})@*
+Clears the screen and saves its contents to the scrollback buffer.
+@end deffn
+
+@node Info, Redisplay, Clear, Virtual Terminal
+@section Info
+@kindex i
+@kindex C-i
+@deffn Command info
+(@kbd{C-a i}, @kbd{C-a C-i})@*
+Uses the message line to display some information about the current
+window: the cursor position in the form @samp{(@var{column},@var{row})}
+starting with @samp{(1,1)}, the terminal width and height plus the size
+of the scrollback buffer in lines, like in @samp{(80,24)+50},
+the current state of window XON/XOFF flow control is shown like this
+(@pxref{Flow Control}):
+@example
+ +flow automatic flow control, currently on.
+ -flow automatic flow control, currently off.
+ +(+)flow flow control enabled. Agrees with automatic control.
+ -(+)flow flow control disabled. Disagrees with automatic control.
+ +(-)flow flow control enabled. Disagrees with automatic control.
+ -(-)flow flow control disabled. Agrees with automatic control.
+@end example
+
+The current line wrap setting (@samp{+wrap} indicates enabled, @samp{-wrap}
+not) is also shown. The flags @samp{ins}, @samp{org}, @samp{app}, @samp{log},
+@samp{mon} and @samp{nored} are displayed when the window is in insert mode,
+origin mode, application-keypad mode, has output logging,
+activity monitoring or partial redraw enabled.
+
+The currently active
+character set (@samp{G0}, @samp{G1}, @samp{G2}, or @samp{G3}), and in
+square brackets the terminal character sets that are currently
+designated as @samp{G0} through @samp{G3}.
+If the window is in UTF-8 mode, the string @samp{UTF-8} is shown instead.
+Additional modes depending on the type of the window are displayed at
+the end of the status line (@pxref{Window Types}).
+
+If the state machine of the terminal emulator is in a non-default state,
+the info line is started with a string identifying the current state.
+
+For system information use @code{time}.
+@end deffn
+
+@deffn Command dinfo
+(none)@*
+Show what @code{screen} thinks about your terminal. Useful if you want to know
+why features like color or the alternate charset don't work.
+@end deffn
+
+@node Redisplay, Wrap, Info, Virtual Terminal
+@section Redisplay
+
+@deffn Command allpartial state
+(none)@*
+If set to on, only the current cursor line is refreshed on window change.
+This affects all windows and is useful for slow terminal lines. The
+previous setting of full/partial refresh for each window is restored
+with @code{allpartial off}. This is a global flag that immediately takes effect
+on all windows overriding the @code{partial} settings. It does not change the
+default redraw behavior of newly created windows.
+@end deffn
+
+@deffn Command altscreen state
+(none)@*
+If set to on, "alternate screen" support is enabled in virtual terminals,
+just like in xterm. Initial setting is @samp{off}.
+@end deffn
+
+@deffn Command partial state
+(none)@*
+Defines whether the display should be refreshed (as with
+@code{redisplay}) after switching to the current window. This command
+only affects the current window. To immediately affect all windows use the
+@code{allpartial} command. Default is @samp{off}, of course. This default is
+fixed, as there is currently no @code{defpartial} command.
+@end deffn
+
+@kindex l
+@kindex C-l
+@deffn Command redisplay
+(@kbd{C-a l}, @kbd{C-a C-l})@*
+Redisplay the current window. Needed to get a full redisplay in
+partial redraw mode.
+@end deffn
+
+@node Wrap, Reset, Redisplay, Virtual Terminal
+@section Wrap
+
+@kindex r
+@kindex C-r
+@deffn Command wrap [ on | off ]
+(@kbd{C-a r}, @kbd{C-a C-r}) @*
+Sets the line-wrap setting for the current window. When line-wrap is
+on, the second consecutive printable character output at the last column
+of a line will wrap to the start of the following line. As an added
+feature, backspace (^H) will also wrap through the left margin to the
+previous line. Default is @samp{on}. Without any options, the state of
+@code{wrap} is toggled.
+@end deffn
+
+@deffn Command defwrap state
+(none) @*
+Same as the @code{wrap} command except that the default setting for new
+windows is changed. Initially line-wrap is on and can be toggled with the
+@code{wrap} command (@kbd{C-a r}) or by means of "C-a : wrap on|off".
+@end deffn
+
+@node Reset, Window Size, Wrap, Virtual Terminal
+@section Reset
+@kindex Z
+@deffn Command reset
+(@kbd{C-a Z})@*
+Reset the virtual terminal to its ``power-on'' values. Useful when strange
+settings (like scroll regions or graphics character set) are left over from
+an application.
+@end deffn
+
+@node Window Size, Character Processing, Reset, Virtual Terminal
+@section Window Size
+@kindex W
+@deffn Command width [@code{-w}|@code{-d}] [cols [lines]]
+(@kbd{C-a W})@*
+Toggle the window width between 80 and 132 columns, or set it to
+@var{cols} columns if an argument is specified. This requires a
+capable terminal and the termcap entries @samp{Z0} and @samp{Z1}. See
+the @code{termcap} command (@pxref{Termcap}), for more information.
+You can also specify a height if you want to
+change both values. The @code{-w} option tells screen to leave
+the display size unchanged and just set the window size,
+@code{-d} vice versa.
+@end deffn
+
+@deffn Command height [@code{-w}|@code{-d}] [lines [cols]]
+(none)@*
+Set the display height to a specified number of lines. When no
+argument is given it toggles between 24 and 42 lines display.
+@end deffn
+
+@node Character Processing, ,Window Size, Virtual Terminal
+@section Character Processing
+
+@deffn Command c1 [state]
+(none)@*
+Change c1 code processing. @samp{c1 on} tells screen to treat
+the input characters between 128 and 159 as control functions.
+Such an 8-bit code is normally the same as ESC followed by the
+corresponding 7-bit code. The default setting is to process c1
+codes and can be changed with the @samp{defc1} command.
+Users with fonts that have usable characters in the
+c1 positions may want to turn this off.
+
+@end deffn
+@deffn Command gr [state]
+(none)@*
+Turn GR charset switching on/off. Whenever screen sees an input
+char with an 8th bit set, it will use the charset stored in the
+GR slot and print the character with the 8th bit stripped. The
+default (see also @samp{defgr}) is not to process GR switching because
+otherwise the ISO88591 charset would not work.
+@end deffn
+
+@deffn Command bce [state]
+(none)@*
+Change background-color-erase setting. If @samp{bce} is set to
+on, all characters cleared by an erase/insert/scroll/clear
+operation will be displayed in the current background color.
+Otherwise the default background color is used.
+@end deffn
+
+@deffn Command encoding enc [denc]
+(none)@*
+Tell screen how to interpret the input/output. The first argument
+sets the encoding of the current window.
+Each window can emulate a different encoding. The optional second
+parameter overwrites the encoding of the connected terminal.
+It should never be needed as screen uses the locale setting to detect
+the encoding.
+There is also a way to select a terminal encoding depending on
+the terminal type by using the @samp{KJ} termcap entry. @xref{Special Capabilities}.
+
+Supported encodings are
+@code{eucJP}, @code{SJIS}, @code{eucKR},
+@code{eucCN}, @code{Big5}, @code{GBK}, @code{KOI8-R}, @code{CP1251},
+@code{UTF-8}, @code{ISO8859-2}, @code{ISO8859-3},
+@code{ISO8859-4}, @code{ISO8859-5}, @code{ISO8859-6},
+@code{ISO8859-7}, @code{ISO8859-8}, @code{ISO8859-9},
+@code{ISO8859-10}, @code{ISO8859-15}, @code{jis}.
+
+See also @samp{defencoding}, which changes the default setting of a new
+window.
+@end deffn
+
+@deffn Command charset set
+(none)@*
+Change the current character set slot designation and charset
+mapping. The first four character of @var{set}
+are treated as charset designators while the fifth and sixth
+character must be in range @samp{0} to @samp{3} and set the GL/GR
+charset mapping. On every position a @samp{.} may be used to indicate
+that the corresponding charset/mapping should not be changed
+(@var{set} is padded to six characters internally by appending
+@samp{.} chars). New windows have @samp{BBBB02} as default
+charset, unless a @samp{encoding} command is active.
+
+The current setting can be viewed with the @ref{Info} command.
+@end deffn
+
+@deffn Command utf8 [state [dstate]]
+(none)@*
+Change the encoding used in the current window. If utf8 is enabled, the
+strings sent to the window will be UTF-8 encoded and vice versa.
+Omitting the
+parameter toggles the setting. If a second parameter is given, the
+display's
+encoding is also changed (this should rather be done with screen's
+@samp{-U} option).
+See also @samp{defutf8}, which changes the default setting of a new
+window.
+@end deffn
+
+@deffn Command defc1 state
+(none)@*
+Same as the @samp{c1} command except that the default setting for
+new windows is changed. Initial setting is @samp{on}.
+@end deffn
+
+@deffn Command defgr state
+(none)@*
+Same as the @samp{gr} command except that the default setting for
+new windows is changed. Initial setting is @samp{off}.
+@end deffn
+
+@deffn Command defbce state
+(none)@*
+Same as the @samp{bce} command except that the default setting for
+new windows is changed. Initial setting is @samp{off}.
+@end deffn
+
+@deffn Command defencoding enc
+(none)@*
+Same as the @samp{encoding} command except that the default setting for
+new windows is changed. Initial setting is the encoding taken from the
+terminal.
+@end deffn
+
+@deffn Command defcharset [set]
+(none)@*
+Like the @samp{charset} command except that the default setting for
+new windows is changed. Shows current default if called without
+argument.
+@end deffn
+
+@deffn Command defutf8 state
+(none)@*
+Same as the @samp{utf8} command except that the default setting for new
+windows is changed. Initial setting is @code{on} if screen was started
+with @samp{-U}, otherwise @code{off}.
+@end deffn
+
+@deffn Command cjkwidth [state]
+(none)@*
+Toggle how ambiguoous characters are treated. If cjkwidth is on screen
+interprets them as double (full) width characters. If off then they are seen
+as one cell (half) width characters.
+@end deffn
+
+
+@node Copy and Paste, Subprocess Execution, Virtual Terminal, Top
+@chapter Copy and Paste
+@cindex copy and paste
+
+For those confined to a hardware terminal, these commands provide a cut
+and paste facility more powerful than those provided by most windowing
+systems.
+
+@menu
+* Copy:: Copy from scrollback to buffer
+* Paste:: Paste from buffer into window
+* Registers:: Longer-term storage
+* Screen Exchange:: Sharing data between screen users
+* History:: Recalling previous input
+@end menu
+
+@node Copy, Paste, , Copy and Paste
+@section Copying
+@cindex marking
+@cindex scrollback
+@kindex [
+@kindex C-[
+@kindex ESC
+@deffn Command copy
+(@kbd{C-a [}, @kbd{C-a C-[}, @kbd{C-a @key{ESC}})@*
+Enter copy/scrollback mode. This allows you to copy text from the
+current window and its history into the paste buffer. In this mode a
+@code{vi}-like full screen editor is active, with controls as
+outlined below.
+@end deffn
+
+@menu
+* Line Termination:: End copied lines with CR/LF
+* Scrollback:: Set the size of the scrollback buffer
+* Copy Mode Keys:: Remap keys in copy mode
+* Movement:: Move around in the scrollback buffer
+* Marking:: Select the text you want
+* Repeat count:: Repeat a command
+* Searching:: Find the text you want
+* Specials:: Other random keys
+@end menu
+
+@node Line Termination, Scrollback, , Copy
+@subsection CR/LF
+@deffn Command crlf [state]
+(none)@*
+This affects the copying of text regions with the @code{copy} command.
+If it is set to @samp{on}, lines will be separated by the two character
+sequence @samp{CR}/@samp{LF}. Otherwise only @samp{LF} is used.
+@code{crlf} is off by default.
+When no parameter is given, the state is toggled.
+@end deffn
+
+@node Scrollback, Copy Mode Keys, Line Termination, Copy
+@subsection Scrollback
+To access and use the contents in the scrollback buffer, use the @code{copy} command. @xref{Copy}.
+@deffn Command defscrollback num
+(none)@*
+Same as the @code{scrollback} command except that the default setting
+for new windows is changed. Defaults to 100.
+@end deffn
+
+@deffn Command scrollback num
+(none)@*
+Set the size of the scrollback buffer for the current window to
+@var{num} lines. The default scrollback is 100 lines. Use @code{info}
+to view the current setting.
+@end deffn
+
+@deffn Command compacthist [state]
+(none)@*
+This tells screen whether to suppress trailing blank lines when
+scrolling up text into the history buffer. Turn compacting @samp{on}
+to hold more useful lines in your scrollback buffer.
+@end deffn
+
+@node Copy Mode Keys, Movement, Scrollback, Copy
+@subsection Markkeys
+@deffn Command markkeys string
+(none)@*
+This is a method of changing the keymap used for copy/history mode. The
+string is made up of @var{oldchar}=@var{newchar} pairs which are
+separated by @samp{:}. Example: The command @code{markkeys
+h=^B:l=^F:$=^E} would set some keys to be more familiar to @code{emacs}
+users.
+If your terminal sends characters, that cause you to abort copy mode,
+then this command may help by binding these characters to do nothing.
+The no-op character is `@@' and is used like this: @code{markkeys @@=L=H}
+if you do not want to use the `H' or `L' commands any longer.
+As shown in this example, multiple keys can be assigned to one function
+in a single statement.
+@end deffn
+
+@node Movement, Marking, Copy Mode Keys, Copy
+@subsection Movement Keys
+
+@noindent
+@kbd{h}, @kbd{C-h}, or @kbd{left arrow} move the cursor left.
+
+@noindent
+@kbd{j}, @kbd{C-n}, or @kbd{down arrow} move the cursor down.
+
+@noindent
+@kbd{k}, @kbd{C-p}, or @kbd{up arrow} move the cursor up.
+
+@noindent
+@kbd{l} ('el'), or @kbd{right arrow} move the cursor right.
+
+@noindent
+@kbd{0} (zero) or @kbd{C-a} move to the leftmost column.
+
+@noindent
+@kbd{+} and @kbd{-} move the cursor to the leftmost column of the next
+or previous line.
+
+@noindent
+@kbd{H}, @kbd{M} and @kbd{L} move the cursor to the leftmost column
+of the top, center or bottom line of the window.
+
+@noindent
+@kbd{|} moves to the specified absolute column.
+
+@noindent
+@kbd{g} or @kbd{home} moves to the beginning of the buffer.
+
+@noindent
+@kbd{G} or @kbd{end} moves to the specified absolute line (default: end of buffer).
+
+@noindent
+@kbd{%} jumps to the specified percentage of the buffer.
+
+@noindent
+@kbd{^} or @kbd{$} move to the first
+or last non-whitespace character on the line.
+
+@noindent
+@kbd{w}, @kbd{b}, and @kbd{e} move the cursor word by word.
+
+@noindent
+@kbd{B}, @kbd{E} move the cursor WORD by WORD (as in vi).
+
+@noindent
+@kbd{f}/@kbd{F}, @kbd{t}/@kbd{T} move the cursor forward/backward to the
+next occurence of the target. (eg, '3fy' will move the cursor to the 3rd
+'y' to the right.)
+
+@noindent
+@kbd{;} and @kbd{,} Repeat the last f/F/t/T command in the same/opposite direction.
+
+@noindent
+@kbd{C-e} and @kbd{C-y} scroll the display up/down by one line
+while preserving the cursor position.
+
+@noindent
+@kbd{C-u} and @kbd{C-d} scroll the display up/down by the specified
+amount of lines while preserving the cursor position. (Default: half
+screenful).
+
+@noindent
+@kbd{C-b} and @kbd{C-f} move the cursor up/down a full screen.
+
+Note that Emacs-style movement keys can be specified by a .screenrc
+command. (@code{markkeys "h=^B:l=^F:$=^E"}) There is no simple method for
+a full emacs-style keymap, however, as this involves multi-character codes.
+
+@node Marking, Repeat count, Movement, Copy
+@subsection Marking
+
+The copy range is specified by setting two marks. The text between these
+marks will be highlighted. Press:
+
+@noindent
+@kbd{space} or @kbd{enter} to set the first or second mark respectively.
+If @code{mousetrack} is set to @code{on}, marks can also be set using
+@kbd{left mouse click}.
+
+@noindent
+@kbd{Y} and @kbd{y} can be used to mark one whole line or to mark from
+start of line.
+
+@noindent
+@kbd{W} marks exactly one word.
+
+@node Repeat count, Searching, Marking, Copy
+@subsection Repeat Count
+
+Any command in copy mode can be prefixed with a number (by pressing
+digits @kbd{0@dots{}9}) which is taken as a repeat count. Example:
+@example
+@kbd{C-a C-[ H 10 j 5 Y}
+@end example
+@noindent
+will copy lines 11 to 15 into the paste buffer.
+
+@node Searching, Specials, Repeat count, Copy
+@subsection Searching
+
+@noindent
+@kbd{/} @code{vi}-like search forward.
+
+@noindent
+@kbd{?} @code{vi}-like search backward.
+
+@noindent
+@kbd{C-a s} @code{emacs} style incremental search forward.
+
+@noindent
+@kbd{C-r} @code{emacs} style reverse i-search.
+
+@deffn Command ignorecase [on|off]
+(none)@*
+Tell screen to ignore the case of characters in searches. Default is
+@code{off}. Without any options, the state of @code{ignorecase}
+is toggled.
+@end deffn
+
+@noindent
+@kbd{n} Repeat search in forward direction.
+
+@noindent
+@kbd{N} Repeat search in backward direction.
+
+@node Specials, , Searching, Copy
+@subsection Specials
+
+There are, however, some keys that act differently here from in
+@code{vi}. @code{Vi} does not allow to yank rectangular blocks of text,
+but @code{screen} does. Press:
+
+@noindent
+@kbd{c} or @kbd{C} to set the left or right margin respectively. If no
+repeat count is given, both default to the current cursor position.@*
+Example: Try this on a rather full text screen:
+@example
+@kbd{C-a [ M 20 l SPACE c 10 l 5 j C SPACE}.
+@end example
+
+@noindent
+This moves one to the middle line of the screen, moves in 20 columns left,
+marks the beginning of the paste buffer, sets the left column, moves 5 columns
+down, sets the right column, and then marks the end of
+the paste buffer. Now try:
+@example
+@kbd{C-a [ M 20 l SPACE 10 l 5 j SPACE}
+@end example
+
+@noindent
+and notice the difference in the amount of text copied.
+
+@noindent
+@kbd{J} joins lines. It toggles between 4 modes: lines separated by a
+newline character (012), lines glued seamless, lines separated by a single
+space or comma separated lines. Note that you can prepend the newline
+character with a carriage return character, by issuing a @code{set crlf
+on}.
+
+@noindent
+@kbd{v} or @kbd{V} is for all the @code{vi} users who use @code{:set numbers} - it
+toggles the left margin between column 9 and 1.
+
+@noindent
+@kbd{a} before the final @kbd{space} key turns on append mode. Thus
+the contents of the paste buffer will not be overwritten, but appended to.
+
+@noindent
+@kbd{A} turns on append mode and sets a (second) mark.
+
+@noindent
+@kbd{>} sets the (second) mark and writes the contents of the paste buffer
+to the screen-exchange file (@file{/tmp/screen-exchange} per default)
+once copy-mode is finished. @xref{Screen Exchange}.@*
+This example demonstrates how to dump the
+whole scrollback buffer to that file:
+@example
+@kbd{C-a [ g SPACE G $ >}.
+@end example
+
+@noindent
+@kbd{C-g} gives information about the current line and column.
+
+@noindent
+@kbd{x} or @kbd{o} ('oh') exchanges the first mark and the current cursor position. You
+can use this to adjust an already placed mark.
+
+@noindent
+@kbd{C-l} ('el') will redraw the screen.
+
+@noindent
+@kbd{@@} does nothing. Absolutely nothing. Does not even exit copy
+mode.
+
+@noindent
+All keys not described here exit copy mode.
+
+@node Paste, Registers, Copy, Copy and Paste
+@section Paste
+
+@kindex ]
+@kindex C-]
+@deffn Command paste [registers [destination]]
+(@kbd{C-a ]}, @kbd{C-a C-]})@*
+Write the (concatenated) contents of the specified registers to the stdin
+stream of the current window. The register @samp{.} is treated as the
+paste buffer. If no parameter is specified the user is prompted to enter a
+single register. The paste buffer can be filled with the
+@code{copy}, @code{history} and @code{readbuf} commands.
+Other registers can be filled with the @code{register}, @code{readreg} and
+@code{paste} commands.
+If @code{paste} is called with a second argument, the contents of the specified
+registers is pasted into the named destination register rather than
+the window. If @samp{.} is used as the second argument, the display's paste
+buffer is the destination.
+Note, that @code{paste} uses a wide variety of resources: Usually both, a
+current window and a current display are required. But whenever a second
+argument is specified no current window is needed. When the source specification
+only contains registers (not the paste buffer) then there need not be a current
+display (terminal attached), as the registers are a global resource. The
+paste buffer exists once for every user.
+@end deffn
+
+@deffn Command stuff [string]
+(none)@*
+Stuff the string @var{string} in the input buffer of the current window.
+This is like the @code{paste} command, but with much less overhead.
+Without a paramter, @code{screen} will prompt for a string to stuff.
+You cannot paste large buffers with the @code{stuff} command. It is most
+useful for key bindings. @xref{Bindkey}.
+@end deffn
+
+@deffn Command pastefont [state]
+Tell screen to include font information in the paste buffer. The
+default is not to do so. This command is especially useful for
+multi character fonts like kanji.
+@end deffn
+
+@deffn Command slowpaste msec
+@deffnx Command defslowpaste msec
+(none)@*
+Define the speed text is inserted in the current window by the @code{paste}
+command. If the slowpaste value is nonzero text is written character by
+character.
+@code{screen} will pause for @var{msec} milliseconds after each write
+to allow the application to process the input. only use @code{slowpaste} if
+your underlying system exposes flow control problems while pasting large
+amounts of text.
+@code{defslowpaste} specifies the default for new windows.
+@end deffn
+
+@deffn Command readreg [-e encoding] [register [filename]]
+(none)@*
+Does one of two things, dependent on number of arguments: with zero or one
+arguments it it duplicates the paste buffer contents into the register specified
+or entered at the prompt. With two arguments it reads the contents of the named
+file into the register, just as @code{readbuf} reads the screen-exchange file
+into the paste buffer.
+You can tell screen the encoding of the file via the @code{-e} option.
+The following example will paste the system's password file into
+the screen window (using register p, where a copy remains):
+
+@example
+C-a : readreg p /etc/passwd
+C-a : paste p
+@end example
+@end deffn
+
+@node Registers, Screen Exchange, Paste, Copy and Paste
+@section Registers
+
+@deffn Command copy_reg [key]
+(none)@*
+Removed. Use @code{readreg} instead.
+@end deffn
+
+@deffn Command ins_reg [key]
+(none)@*
+Removed. Use @code{paste} instead.
+@end deffn
+
+@deffn Command process [key]
+(none)@*
+Stuff the contents of the specified register into the @code{screen}
+input queue. If no argument is given you are prompted for a
+register name. The text is parsed as if it had been typed in from the user's
+keyboard. This command can be used to bind multiple actions to a single key.
+@end deffn
+
+@deffn Command register [-e encoding] key string
+(none)@*
+Save the specified @var{string} to the register @var{key}.
+The encoding of the string can be specified via the @code{-e} option.
+@end deffn
+
+@node Screen Exchange, History, Registers, Copy and Paste
+@section Screen Exchange
+
+@deffn Command bufferfile [@var{exchange-file}]
+(none)@*
+Change the filename used for reading and writing with the paste buffer.
+If the @var{exchange-file} parameter is omitted, @code{screen} reverts
+to the default of @file{/tmp/screen-exchange}. The following example
+will paste the system's password file into the screen window (using the
+paste buffer, where a copy remains):
+
+@example
+C-a : bufferfile /etc/passwd
+C-a < C-a ]
+C-a : bufferfile
+@end example
+@end deffn
+
+@kindex <
+@deffn Command readbuf [-e @var{encoding}] [@var{filename}]
+(@kbd{C-a <})@*
+Reads the contents of the specified file into the paste buffer.
+You can tell screen the encoding of the file via the @code{-e} option.
+If no file is specified, the screen-exchange filename is used.
+@end deffn
+
+@kindex =
+@deffn Command removebuf
+(@kbd{C-a =})@*
+Unlinks the screen-exchange file.
+@end deffn
+
+@kindex >
+@deffn Command writebuf [-e @var{encoding}] [@var{filename}]
+(@kbd{C-a >})@*
+Writes the contents of the paste buffer to the specified file, or the
+public accessible screen-exchange file if no filename is given.
+This is thought of as a primitive means of
+communication between @code{screen} users on the same host.
+If an encoding is specified the paste buffer is recoded on the fly to
+match the encoding.
+See also
+@kbd{C-a @key{ESC}} (@pxref{Copy}).
+@end deffn
+
+@node History, , Screen Exchange, Copy and Paste
+@section History
+
+@kindex @{
+@kindex @}
+@deffn Command history
+(@kbd{C-a @{}, @kbd{C-a @}})@*
+Usually users work with a shell that allows easy access to previous
+commands. For example, @code{csh} has the command @code{!!} to repeat
+the last command executed. @code{screen} provides a primitive way of
+recalling ``the command that started @dots{}'': You just type the first
+letter of that command, then hit @kbd{C-a @{} and @code{screen} tries to
+find a previous line that matches with the prompt character to the left
+of the cursor. This line is pasted into this window's input queue. Thus
+you have a crude command history (made up by the visible window and its
+scrollback buffer).
+@end deffn
+
+@node Subprocess Execution, Key Binding, Copy and Paste, Top
+@chapter Subprocess Execution
+Control Input or Output of a window by another filter process.
+Use with care!
+
+@menu
+* Exec:: The @code{exec} command syntax.
+* Using Exec:: Weird things that filters can do.
+@end menu
+
+@node Exec, Using Exec, , Subprocess Execution
+@section Exec
+@deffn Command exec [[@var{fdpat}] @var{newcommand} [@var{args} ... ]]
+(none)@*
+Run a unix subprocess (specified by an executable path @var{newcommand} and
+its optional arguments) in the current window. The flow of data between
+newcommands stdin/stdout/stderr, the process originally started (let us call it
+"application-process") and
+screen itself (window) is controlled by the file descriptor pattern @var{fdpat}.
+This pattern is basically a three character sequence representing stdin, stdout
+and stderr of newcommand. A dot (@code{.}) connects the file descriptor
+to screen. An exclamation mark (@code{!}) causes the file descriptor to be
+connected to the application-process. A colon (@code{:}) combines both.
+@*
+User input will go to newcommand unless newcommand receives the
+application-process'
+output (@var{fdpat}s first character is @samp{!} or @samp{:}) or a pipe symbol
+(@samp{|}) is added to the end of @var{fdpat}.
+@*
+Invoking @code{exec} without arguments shows name and arguments of the currently
+running subprocess in this window. Only one subprocess can be running per
+window.
+@*
+When a subprocess is running the @code{kill} command will affect it instead of
+the windows process. Only one subprocess a time can be running in each window.
+@*
+Refer to the postscript file @file{doc/fdpat.ps} for a confusing
+illustration of all 21 possible combinations. Each drawing shows the digits
+2, 1, 0 representing the three file descriptors of newcommand. The box
+marked `W' is usual pty that has the application-process on its slave side.
+The box marked `P' is the secondary pty that now has screen at its master
+side.
+@end deffn
+
+@node Using Exec, , Exec, Subprocess Execution
+@section Using Exec
+@noindent
+Abbreviations:
+
+@itemize @bullet
+@item
+Whitespace between the word @samp{exec} and @var{fdpat} and the command name
+can be omitted.
+
+@item
+Trailing dots and a @var{fdpat} consisting only of dots can be omitted.
+
+@item
+A simple @samp{|} is synonymous for the @samp{!..|} pattern.
+
+@item
+The word @samp{exec} can be omitted when the @samp{|} abbreviation is used.
+
+@item
+The word @samp{exec} can always be replaced by leading @samp{!}.
+@end itemize
+
+@noindent
+Examples:
+
+@table @code
+@item !/bin/sh
+@itemx exec /bin/sh
+@itemx exec ... /bin/sh
+All of the above are equivalent.
+Creates another shell in the same window, while the original shell is still
+running. Output of both shells is displayed and user input is sent to the new
+@file{/bin/sh}.
+
+@item !!stty 19200
+@itemx exec!stty 19200
+@itemx exec !.. stty 19200
+All of the above are equivalent.
+Set the speed of the window's tty. If your stty command operates on stdout,
+then add another @samp{!}. This is a useful command, when a screen window
+is directly connected to a serial line that needs to be configured.
+
+@item |less
+@itemx exec !..| less
+Both are equivalent.
+This adds a pager to the window output. The special character @samp{|} is
+needed to give the user control over the pager although it gets its input from
+the window's process. This works, because @samp{less} listens on stderr
+(a behavior that @code{screen} would not expect without the @samp{|})
+when its stdin is not a tty. @code{Less} versions newer than 177 fail miserably
+here; good old @code{pg} still works.
+
+@item !:sed -n s/.*Error.*/\007/p
+Sends window output to both, the user and the sed command. The sed inserts an
+additional bell character (oct. 007) to the window output seen by screen.
+This will cause 'Bell in window x' messages, whenever the string @samp{Error}
+appears in the window.
+@end table
+
+@node Key Binding, Flow Control, Subprocess Execution, Top
+@chapter Key Binding
+@cindex key binding
+@cindex binding
+
+You may disagree with some of the default bindings (I know I do). The
+@code{bind} command allows you to redefine them to suit your
+preferences.
+
+@menu
+* Bind:: @code{bind} syntax.
+* Bind Examples:: Using @code{bind}.
+* Command Character:: The character used to start keyboard commands.
+* Help:: Show current key bindings.
+* Bindkey:: @code{bindkey} syntax.
+* Bindkey Examples:: Some easy examples.
+* Bindkey Control:: How to control the bindkey mechanism.
+@end menu
+
+@node Bind, Bind Examples, , Key Binding
+@section The @code{bind} command
+@deffn Command bind [-c class] key [command [args]]
+(none)@*
+Bind a command to a key. The @var{key} argument is either a single
+character, a two-character sequence of the form @samp{^x} (meaning
+@kbd{C-x}), a backslash followed by an octal number (specifying the
+ASCII code of the character), or a backslash followed by a second
+character, such as @samp{\^} or @samp{\\}. The argument can also be
+quoted, if you like. If no further argument is given, any previously
+established binding for this key is removed. The @var{command}
+argument can be any command (@pxref{Command Index}).
+
+If a command class is specified via the @code{-c} option, the
+key is bound for the specified class. Use the @code{command}
+command to activate a class. Command classes can be used
+to create multiple command keys or multi-character bindings.
+
+By default, most suitable commands are bound to one or more keys
+(@pxref{Default Key Bindings}); for instance, the command to create a
+new window is bound to @kbd{C-c} and @kbd{c}. The @code{bind} command
+can be used to redefine the key bindings and to define new bindings.
+@end deffn
+
+@deffn Command unbindall
+(none)@*
+Unbind all the bindings. This can be useful when
+screen is used solely for its detaching abilities, such as when
+letting a console application run as a daemon. If, for some reason,
+it is necessary to bind commands after this, use 'screen -X'.
+@end deffn
+
+@node Bind Examples, Command Character, Bind, Key Binding
+@section Examples of the @code{bind} command
+@noindent
+Some examples:
+
+@example
+bind ' ' windows
+bind ^f screen telnet foobar
+bind \033 screen -ln -t root -h 1000 9 su
+@end example
+
+@noindent
+would bind the space key to the command that displays a list of windows
+(so that the command usually invoked by @kbd{C-a C-w} would also be
+available as @kbd{C-a space}), bind @kbd{C-f} to the command
+``create a window with a TELNET connection to foobar'', and bind
+@key{ESC} to the command that creates an non-login window with title
+@samp{root} in slot #9, with a superuser shell and a scrollback buffer
+of 1000 lines.
+
+@example
+bind -c demo1 0 select 10
+bind -c demo1 1 select 11
+bind -c demo1 2 select 12
+bindkey "^B" command -c demo1
+@end example
+makes @kbd{C-b 0} select window 10, @kbd{C-b 1} window 11, etc.
+
+@example
+bind -c demo2 0 select 10
+bind -c demo2 1 select 11
+bind -c demo2 2 select 12
+bind - command -c demo2
+@end example
+makes @kbd{C-a - 0} select window 10, @kbd{C-a - 1} window 11, etc.
+
+@node Command Character, Help, Bind Examples, Key Binding
+@cindex escape character
+@cindex command character
+@section Command Character
+
+@deffn Command escape xy
+(none)@*
+Set the command character to @var{x} and the character generating a
+literal command character (by triggering the @code{meta} command)
+to @var{y} (similar to the @samp{-e} option).
+Each argument is either a single character, a two-character
+sequence of the form @samp{^x} (meaning @kbd{C-x}), a backslash followed
+by an octal number (specifying the ASCII code of the character), or a
+backslash followed by a second character, such as @samp{\^} or
+@samp{\\}. The default is @samp{^Aa}, but @samp{``} is recommended by
+one of the authors.
+@end deffn
+
+@deffn Command defescape xy
+(none)@*
+Set the default command characters. This is equivalent to the command
+@code{escape} except that it is useful for multiuser sessions only.
+In a multiuser session
+@code{escape} changes the command character of the calling user, where
+@code{defescape} changes the default command characters for users that
+will be added later.
+@end deffn
+
+@kindex a
+@deffn Command meta
+(@kbd{C-a a})@*
+Send the command character (@kbd{C-a}) to the process in the current
+window. The keystroke for this command is the second parameter to the
+@samp{-e} command line switch (@pxref{Invoking Screen}), or the
+@code{escape} .screenrc directive.
+@end deffn
+
+@deffn Command command [-c @var{class}]
+(none)@*
+This command has the same effect as typing the screen escape character
+(@kbd{C-a}). It is probably only useful for key bindings.
+If the @samp{-c} option is given, select the specified command class.
+@xref{Bind}, @xref{Bindkey}.
+@end deffn
+
+@node Help, Bindkey, Command Character, Key Binding
+@section Help
+@kindex ?
+@deffn Command help
+(@kbd{C-a ?})@*
+Displays a help screen showing you all the key bindings. The first
+pages list all the internal commands followed by their bindings.
+Subsequent pages will display the custom commands, one command per key.
+Press space when you're done reading each page, or return to exit early.
+All other characters are ignored.
+If the @samp{-c} option is given, display all bound commands for the
+specified command class.
+@xref{Default Key Bindings}.
+@end deffn
+
+@node Bindkey, Bindkey Examples, Help, Key Binding
+@section Bindkey
+@deffn Command bindkey [@var{opts}] [@var{string} [@var{cmd} @var{args}]]
+(none)@*
+This command manages screen's input translation tables. Every
+entry in one of the tables tells screen how to react if a certain
+sequence of characters is encountered. There are three tables:
+one that should contain actions programmed by the user, one for
+the default actions used for terminal emulation and one for
+screen's copy mode to do cursor movement. See @ref{Input Translation}
+for a list of default key bindings.
+
+If the @samp{-d}
+option is given, bindkey modifies the default table, @samp{-m}
+changes the copy mode table and with neither option the user
+table is selected. The argument @samp{string} is the sequence of
+characters to which an action is bound. This can either be a fixed
+string or a termcap keyboard capability name (selectable with the
+@samp{-k} option).
+
+Some keys on a VT100 terminal can send a different
+string if application mode is turned on (e.g. the cursor keys).
+Such keys have two entries in the translation table. You can
+select the application mode entry by specifying the @samp{-a}
+option.
+
+The @samp{-t} option tells screen not to do inter-character
+timing. One cannot turn off the timing if a termcap capability is
+used.
+
+@samp{cmd} can be any of screen's commands with an arbitrary
+number of @samp{args}. If @samp{cmd} is omitted the key-binding is
+removed from the table.
+@end deffn
+
+@node Bindkey Examples, Bindkey Control,Bindkey, Key Binding
+@section Bindkey Examples
+@noindent
+Here are some examples of keyboard bindings:
+
+@example
+bindkey -d
+@end example
+@noindent
+Show all of the default key bindings. The application mode entries
+are marked with [A].
+
+@example
+bindkey -k k1 select 1
+@end example
+@noindent
+Make the "F1" key switch to window one.
+
+@example
+bindkey -t foo stuff barfoo
+@end example
+@noindent
+Make @samp{foo} an abbreviation of the word @samp{barfoo}. Timeout is
+disabled so that users can type slowly.
+
+@example
+bindkey "\024" mapdefault
+@end example
+@noindent
+This key-binding makes @samp{C-t} an escape character for key-bindings. If
+you did the above @samp{stuff barfoo} binding, you can enter the word
+@samp{foo} by typing @samp{C-t foo}. If you want to insert a
+@samp{C-t} you have to press the key twice (i.e., escape the escape
+binding).
+
+@example
+bindkey -k F1 command
+@end example
+@noindent
+Make the F11 (not F1!) key an alternative screen
+escape (besides @samp{C-a}).
+
+@node Bindkey Control, , Bindkey Examples, Key Binding
+@section Bindkey Control
+@deffn Command mapdefault
+(none)@*
+Tell screen that the next input character should only be looked up
+in the default bindkey table.
+@end deffn
+@deffn Command mapnotnext
+(none)@*
+Like mapdefault, but don't even look in the default bindkey table.
+@end deffn
+@deffn Command maptimeout n
+(none)@*
+Set the inter-character timer for input sequence detection to a timeout
+of @var{n} ms. The default timeout is 300ms. Maptimeout with no
+arguments shows the current setting.
+@end deffn
+
+@node Flow Control, Termcap, Key Binding, Top
+@chapter Flow Control
+@cindex flow control
+
+@code{screen} can trap flow control characters or pass them to the
+program, as you see fit. This is useful when your terminal wants to use
+XON/XOFF flow control and you are running a program which wants to use
+^S/^Q for other purposes (i.e. @code{emacs}).
+
+@menu
+* Flow Control Summary:: The effect of @code{screen} flow control
+* Flow:: Setting the flow control behavior
+* XON/XOFF:: Sending XON or XOFF to the window
+@end menu
+
+@node Flow Control Summary, Flow, , Flow Control
+@section About @code{screen} flow control settings
+Each window has a flow-control setting that determines how screen deals
+with the XON and XOFF characters (and perhaps the interrupt character).
+When flow-control is turned off, screen ignores the XON and XOFF
+characters, which allows the user to send them to the current program by
+simply typing them (useful for the @code{emacs} editor, for instance).
+The trade-off is that it will take longer for output from a
+``normal'' program to pause in response to an XOFF. With
+flow-control turned on, XON and XOFF characters are used to immediately
+pause the output of the current window. You can still send these
+characters to the current program, but you must use the appropriate
+two-character screen commands (typically @kbd{C-a q} (xon) and @kbd{C-a
+s} (xoff)). The xon/xoff commands are also useful for typing C-s and
+C-q past a terminal that intercepts these characters.
+
+Each window has an initial flow-control value set with either the
+@samp{-f} option or the @code{defflow} command. By default the
+windows are set to automatic flow-switching. It can then be toggled
+between the three states 'fixed on', 'fixed off' and 'automatic'
+interactively with the @code{flow} command bound to @kbd{C-a f}.
+
+The automatic flow-switching mode deals with flow control using the
+TIOCPKT mode (like @code{rlogin} does). If the tty driver does not
+support TIOCPKT, screen tries to determine the right mode based on the
+current setting of the application keypad --- when it is enabled,
+flow-control is turned off and visa versa. Of course, you can still
+manipulate flow-control manually when needed.
+
+If you're running with flow-control enabled and find that pressing the
+interrupt key (usually C-c) does not interrupt the display until another
+6-8 lines have scrolled by, try running screen with the @samp{interrupt}
+option (add the @samp{interrupt} flag to the @code{flow} command in your
+.screenrc, or use the @samp{-i} command-line option). This causes the
+output that @code{screen} has accumulated from the interrupted program
+to be flushed. One disadvantage is that the virtual terminal's memory
+contains the non-flushed version of the output, which in rare cases can
+cause minor inaccuracies in the output. For example, if you switch
+screens and return, or update the screen with @kbd{C-a l} you would see
+the version of the output you would have gotten without @samp{interrupt}
+being on. Also, you might need to turn off flow-control (or use
+auto-flow mode to turn it off automatically) when running a program that
+expects you to type the interrupt character as input, as the
+@samp{interrupt} parameter only takes effect when flow-control is
+enabled. If your program's output is interrupted by mistake, a simple
+refresh of the screen with @kbd{C-a l} will restore it. Give each mode
+a try, and use whichever mode you find more comfortable.
+
+@node Flow, XON/XOFF, Flow Control Summary, Flow Control
+@section Flow
+@deffn Command defflow fstate [interrupt]
+(none)@*
+Same as the @code{flow} command except that the default setting for new
+windows is changed. Initial setting is `auto'.
+Specifying @code{flow auto interrupt} has the same effect as the
+command-line options @samp{-fa} and @samp{-i}.
+Note that if @samp{interrupt} is enabled, all existing displays are
+changed immediately to forward interrupt signals.
+@end deffn
+
+@kindex f
+@kindex C-f
+@deffn Command flow [fstate]
+(@kbd{C-a f}, @kbd{C-a C-f})@*
+Sets the flow-control mode for this window to @var{fstate}, which can be
+@samp{on}, @samp{off} or @samp{auto}.
+Without parameters it cycles the current window's
+flow-control setting. Default is set by `defflow'.
+@end deffn
+
+@node XON/XOFF, , Flow, Flow Control
+@section XON and XOFF
+@kindex q
+@kindex C-q
+@deffn Command xon
+(@kbd{C-a q}, @kbd{C-a C-q})@*
+Send a ^Q (ASCII XON) to the program in the current window. Redundant
+if flow control is set to @samp{off} or @samp{auto}.
+@end deffn
+
+@kindex s
+@kindex C-s
+@deffn Command xoff
+(@kbd{C-a s}, @kbd{C-a C-s})@*
+Send a ^S (ASCII XOFF) to the program in the current window.
+@end deffn
+
+@node Termcap, Message Line, Flow Control, Top
+@chapter Termcap
+
+@code{Screen} demands the most out of your terminal so that it can
+perform its VT100 emulation most efficiently. These functions provide
+means for tweaking the termcap entries for both your physical terminal
+and the one simulated by @code{screen}.
+
+@menu
+* Window Termcap:: Choosing a termcap entry for the window.
+* Dump Termcap:: Write out a termcap entry for the window.
+* Termcap Syntax:: The @code{termcap} and @code{terminfo} commands.
+* Termcap Examples:: Uses for @code{termcap}.
+* Special Capabilities:: Non-standard capabilities used by @code{screen}.
+* Autonuke:: Flush unseen output
+* Obuflimit:: Allow pending output when reading more
+* Character Translation:: Emulating fonts and charsets.
+@end menu
+
+@node Window Termcap, Dump Termcap, , Termcap
+@section Choosing the termcap entry for a window
+Usually @code{screen} tries to emulate as much of the VT100/ANSI
+standard as possible. But if your terminal lacks certain capabilities
+the emulation may not be complete. In these cases @code{screen} has to
+tell the applications that some of the features are missing. This is no
+problem on machines using termcap, because @code{screen} can use the
+@code{$TERMCAP} variable to customize the standard screen termcap.
+
+But if you do a rlogin on another machine or your machine supports only
+terminfo this method fails. Because of this @code{screen} offers a way
+to deal with these cases. Here is how it works:
+
+When @code{screen} tries to figure out a terminal name for itself, it
+first looks for an entry named @code{screen.@var{term}}, where
+@var{term} is the contents of your @code{$TERM} variable. If no such entry
+exists, @code{screen} tries @samp{screen} (or @samp{screen-w}, if the
+terminal is wide (132 cols or more)). If even this entry cannot be
+found, @samp{vt100} is used as a substitute.
+
+The idea is that if you have a terminal which doesn't support an
+important feature (e.g. delete char or clear to EOS) you can build a new
+termcap/terminfo entry for @code{screen} (named
+@samp{screen.@var{dumbterm}}) in which this capability has been
+disabled. If this entry is installed on your machines you are able to
+do a rlogin and still keep the correct termcap/terminfo entry. The
+terminal name is put in the @code{$TERM} variable of all new windows.
+@code{screen} also sets the @code{$TERMCAP} variable reflecting the
+capabilities of the virtual terminal emulated.
+Furthermore, the variable @code{$WINDOW} is set to the window number of each
+window.
+
+The actual set of capabilities supported by the virtual terminal depends
+on the capabilities supported by the physical terminal. If, for
+instance, the physical terminal does not support underscore mode,
+@code{screen} does not put the @samp{us} and @samp{ue} capabilities into
+the window's @code{$TERMCAP} variable, accordingly. However, a minimum number
+of capabilities must be supported by a terminal in order to run
+@code{screen}; namely scrolling, clear screen, and direct cursor
+addressing (in addition, @code{screen} does not run on hardcopy
+terminals or on terminals that over-strike).
+
+Also, you can customize the @code{$TERMCAP} value used by @code{screen} by
+using the @code{termcap} command, or by defining the variable
+@code{$SCREENCAP} prior to startup. When the latter defined, its value will be
+copied verbatim into each window's @code{$TERMCAP} variable. This can either
+be the full terminal definition, or a filename where the terminal
+@samp{screen} (and/or @samp{screen-w}) is defined.
+
+Note that @code{screen} honors the @code{terminfo} command if the system
+uses the terminfo database rather than termcap. On such machines the
+@code{$TERMCAP} variable has no effect and you must use the
+@code{dumptermcap} command (@pxref{Dump Termcap}) and the @code{tic}
+program to generate terminfo entries for @code{screen} windows.
+
+When the boolean @samp{G0} capability is present in the termcap entry
+for the terminal on which @code{screen} has been called, the terminal
+emulation of @code{screen} supports multiple character sets. This
+allows an application to make use of, for instance, the VT100 graphics
+character set or national character sets. The following control
+functions from ISO 2022 are supported: @samp{lock shift G0} (@samp{SI}),
+@samp{lock shift G1} (@samp{SO}), @samp{lock shift G2}, @samp{lock shift
+G3}, @samp{single shift G2}, and @samp{single shift G3}. When a virtual
+terminal is created or reset, the ASCII character set is designated as
+@samp{G0} through @samp{G3}. When the @samp{G0} capability is present,
+screen evaluates the capabilities @samp{S0}, @samp{E0}, and @samp{C0} if
+present. @samp{S0} is the sequence the terminal uses to enable and start
+the graphics character set rather than @samp{SI}. @samp{E0} is the
+corresponding replacement for @samp{SO}. @samp{C0} gives a character by
+character translation string that is used during semi-graphics mode.
+This string is built like the @samp{acsc} terminfo capability.
+
+When the @samp{po} and @samp{pf} capabilities are present in the
+terminal's termcap entry, applications running in a @code{screen} window
+can send output to the printer port of the terminal. This allows a user
+to have an application in one window sending output to a printer
+connected to the terminal, while all other windows are still active (the
+printer port is enabled and disabled again for each chunk of output).
+As a side-effect, programs running in different windows can send output
+to the printer simultaneously. Data sent to the printer is not
+displayed in the window. The @code{info} command displays a line starting
+with @samp{PRIN} while the printer is active.
+
+Some capabilities are only put into the @code{$TERMCAP} variable of the virtual
+terminal if they can be efficiently implemented by the physical
+terminal. For instance, @samp{dl} (delete line) is only put into the
+@code{$TERMCAP} variable if the terminal supports either delete line itself or
+scrolling regions. Note that this may provoke confusion, when the
+session is reattached on a different terminal, as the value of @code{$TERMCAP}
+cannot be modified by parent processes. You can force @code{screen} to
+include all capabilities in @code{$TERMCAP} with the @samp{-a}
+command-line option (@pxref{Invoking Screen}).
+
+The "alternate screen" capability is not enabled by default.
+Set the @code{altscreen} @file{.screenrc} command to enable it.
+
+@node Dump Termcap, Termcap Syntax, Window Termcap, Termcap
+@section Write out the window's termcap entry
+@kindex .
+@deffn Command dumptermcap
+(@kbd{C-a .})@*
+Write the termcap entry for the virtual terminal optimized for the
+currently active window to the file @file{.termcap} in the user's
+@file{$HOME/.screen} directory (or wherever @code{screen} stores its
+sockets. @pxref{Files}). This termcap entry is identical to
+the value of the environment variable @code{$TERMCAP} that is set up by
+@code{screen} for each window. For terminfo based systems you will need
+to run a converter like @code{captoinfo} and then compile the entry with
+@code{tic}.
+@end deffn
+
+@node Termcap Syntax, Termcap Examples, Dump Termcap, Termcap
+@section The @code{termcap} command
+@deffn Command termcap term terminal-tweaks [window-tweaks]
+@deffnx Command terminfo term terminal-tweaks [window-tweaks]
+@deffnx Command termcapinfo term terminal-tweaks [window-tweaks]
+(none)@*
+Use this command to modify your terminal's termcap entry without going
+through all the hassles involved in creating a custom termcap entry.
+Plus, you can optionally customize the termcap generated for the
+windows.
+You have to place these commands in one of the screenrc startup files, as they
+are meaningless once the terminal emulator is booted.
+
+If your system uses the terminfo database rather than termcap,
+@code{screen} will understand the @code{terminfo} command, which has the
+same effects as the @code{termcap} command. Two separate commands are
+provided, as there are subtle syntactic differences, e.g. when parameter
+interpolation (using @samp{%}) is required. Note that the termcap names of
+the capabilities should also be used with the @code{terminfo} command.
+
+In many cases, where the arguments are valid in both terminfo and termcap
+syntax, you can use the command @code{termcapinfo}, which is just a
+shorthand for a pair of @code{termcap} and @code{terminfo} commands with
+identical arguments.
+@end deffn
+
+The first argument specifies which terminal(s) should be affected by
+this definition. You can specify multiple terminal names by separating
+them with @samp{|}s. Use @samp{*} to match all terminals and @samp{vt*}
+to match all terminals that begin with @samp{vt}.
+
+Each @var{tweak} argument contains one or more termcap defines
+(separated by @samp{:}s) to be inserted at the start of the appropriate
+termcap entry, enhancing it or overriding existing values. The first
+tweak modifies your terminal's termcap, and contains definitions that
+your terminal uses to perform certain functions. Specify a null string
+to leave this unchanged (e.g. ""). The second (optional) tweak modifies
+all the window termcaps, and should contain definitions that screen
+understands (@pxref{Virtual Terminal}).
+
+@node Termcap Examples, Special Capabilities, Termcap Syntax, Termcap
+@section Termcap Examples
+Some examples:
+
+@example
+termcap xterm* xn:hs@@
+@end example
+
+@noindent
+Informs @code{screen} that all terminals that begin with @samp{xterm}
+have firm auto-margins that allow the last position on the screen to be
+updated (xn), but they don't really have a status line (no 'hs' --
+append @samp{@@} to turn entries off). Note that we assume @samp{xn} for
+all terminal names that start with @samp{vt}, but only if you don't
+specify a termcap command for that terminal.
+
+@example
+termcap vt* xn
+termcap vt102|vt220 Z0=\E[?3h:Z1=\E[?3l
+@end example
+
+@noindent
+Specifies the firm-margined @samp{xn} capability for all terminals that
+begin with @samp{vt}, and the second line will also add the
+escape-sequences to switch into (Z0) and back out of (Z1)
+132-character-per-line mode if this is a VT102 or VT220. (You must
+specify Z0 and Z1 in your termcap to use the width-changing commands.)
+
+@example
+termcap vt100 "" l0=PF1:l1=PF2:l2=PF3:l3=PF4
+@end example
+
+@noindent
+This leaves your vt100 termcap alone and adds the function key labels to
+each window's termcap entry.
+
+@example
+termcap h19|z19 am@@:im=\E@@:ei=\EO dc=\E[P
+@end example
+
+@noindent
+Takes a h19 or z19 termcap and turns off auto-margins (am@@) and enables
+the insert mode (im) and end-insert (ei) capabilities (the @samp{@@} in
+the @samp{im} string is after the @samp{=}, so it is part of the
+string). Having the @samp{im} and @samp{ei} definitions put into your
+terminal's termcap will cause screen to automatically advertise the
+character-insert capability in each window's termcap. Each window will
+also get the delete-character capability (dc) added to its termcap,
+which screen will translate into a line-update for the terminal (we're
+pretending it doesn't support character deletion).
+
+If you would like to fully specify each window's termcap entry, you
+should instead set the @code{$SCREENCAP} variable prior to running
+@code{screen}. @xref{Virtual Terminal}, for the details of the
+@code{screen} terminal emulation. @xref{Top, , Termcap, termcap, The
+Termcap Manual}, for more information on termcap definitions.
+
+@node Special Capabilities, Autonuke, Termcap Examples, Termcap
+@section Special Terminal Capabilities
+@cindex terminal capabilities
+@cindex capabilities
+The following table describes all terminal capabilities that are
+recognized by @code{screen} and are not in the termcap manual
+(@pxref{Top, , Termcap, termcap, The Termcap Manual}).
+You can place these capabilities in your termcap entries (in
+@file{/etc/termcap}) or use them with the commands @code{termcap},
+@code{terminfo} and @code{termcapinfo} in your @code{screenrc} files. It is
+often not possible to place these capabilities in the terminfo database.
+@table @samp
+@item LP
+(bool)@*
+Terminal has VT100 style margins (`magic margins'). Note that
+this capability is obsolete --- @code{screen} now uses the standard
+@samp{xn} instead.
+
+@item Z0
+(str)@*
+Change width to 132 columns.
+
+@item Z1
+(str)@*
+Change width to 80 columns.
+
+@item WS
+(str)@*
+Resize display. This capability has the desired width and height as
+arguments. SunView(tm) example: @samp{\E[8;%d;%dt}.
+
+@item NF
+(bool)@*
+Terminal doesn't need flow control. Send ^S and ^Q direct to
+the application. Same as @code{flow off}. The opposite of this
+capability is @samp{nx}.
+
+@item G0
+(bool)@*
+Terminal can deal with ISO 2022 font selection sequences.
+
+@item S0
+(str)@*
+Switch charset @samp{G0} to the specified charset. Default
+is @samp{\E(%.}.
+
+@item E0
+(str)@*
+Switch charset @samp{G0} back to standard charset. Default
+is @samp{\E(B}.
+
+@item C0
+(str)@*
+Use the string as a conversion table for font 0. See
+the @samp{ac} capability for more details.
+
+@item CS
+(str)@*
+Switch cursor-keys to application mode.
+
+@item CE
+(str)@*
+Switch cursor-keys to cursor mode.
+
+@item AN
+(bool)@*
+Enable autonuke for displays of this terminal type.
+(@pxref{Autonuke}).
+
+@item OL
+(num)@*
+Set the output buffer limit. See the @samp{obuflimit} command
+(@pxref{Obuflimit}) for more details.
+
+@item KJ
+(str)@*
+Set the encoding of the terminal. See the @samp{encoding} command
+(@pxref{Character Processing}) for valid encodings.
+
+@item AF
+(str)@*
+Change character foreground color in an ANSI conform way. This
+capability will almost always be set to @samp{\E[3%dm}
+(@samp{\E[3%p1%dm} on terminfo machines).
+
+@item AB
+(str)@*
+Same as @samp{AF}, but change background color.
+
+@item AX
+(bool)@*
+Does understand ANSI set default fg/bg color (@samp{\E[39m / \E[49m}).
+
+@item XC
+(str)@*
+Describe a translation of characters to strings depending on the
+current font. (@pxref{Character Translation}).
+
+@item XT
+(bool)@*
+Terminal understands special xterm sequences (OSC, mouse tracking).
+
+@item C8
+(bool)@*
+Terminal needs bold to display high-intensity colors (e.g. Eterm).
+
+@item TF
+(bool)@*
+Add missing capabilities to the termcap/info entry. (Set by default).
+@end table
+
+@node Autonuke, Obuflimit, Special Capabilities, Termcap
+@section Autonuke
+@deffn Command autonuke @var{state}
+(none)@*
+Sets whether a clear screen sequence should nuke all the output
+that has not been written to the terminal. @xref{Obuflimit}.
+This property is set per display, not per window.
+@end deffn
+
+@deffn Command defautonuke @var{state}
+(none)@*
+Same as the @code{autonuke} command except that the default setting for
+new displays is also changed. Initial setting is @code{off}.
+Note that you can use the special @code{AN} terminal capability if you
+want to have a terminal type dependent setting.
+@end deffn
+
+@node Obuflimit, Character Translation, Autonuke, Termcap
+@section Obuflimit
+@deffn Command obuflimit [@var{limit}]
+(none)@*
+If the output buffer contains more bytes than the specified limit, no
+more data will be read from the windows. The default value is 256. If
+you have a fast display (like @code{xterm}), you can set it to some
+higher value. If no argument is specified, the current setting is displayed.
+This property is set per display, not per window.
+@end deffn
+
+@deffn Command defobuflimit @var{limit}
+(none)@*
+Same as the @code{obuflimit} command except that the default setting for new
+displays is also changed. Initial setting is 256 bytes. Note that you can use
+the special @code{OL} terminal capability if you want to have a terminal
+type dependent limit.
+@end deffn
+
+@node Character Translation, , Obuflimit, Termcap
+@section Character Translation
+@code{Screen} has a powerful mechanism to translate characters to
+arbitrary strings depending on the current font and terminal type.
+Use this feature if you want to work with a common standard character
+set (say ISO8851-latin1) even on terminals that scatter the more
+unusual characters over several national language font pages.
+
+Syntax:
+
+@example
+ XC=@var{<charset-mapping>}@{,,@var{<charset-mapping>}@}
+ @var{<charset-mapping>} := @var{<designator>}@var{<template>}@{,@var{<mapping>}@}
+ @var{<mapping>} := @var{<char-to-be-mapped>}@var{<template-arg>}
+@end example
+
+The things in braces may be repeated any number of times.
+
+A @var{<charset-mapping>} tells screen how to map characters
+in font @var{<designator>} (@samp{B}: Ascii, @samp{A}: UK,
+@samp{K}: german, etc.)
+to strings. Every @var{<mapping>} describes to what string a single
+character will be translated. A template mechanism is used, as
+most of the time the codes have a lot in common (for example
+strings to switch to and from another charset). Each occurrence
+of @samp{%} in @var{<template>} gets substituted with the
+@var{template-arg}
+specified together with the character. If your strings are not
+similar at all, then use @samp{%} as a template and place the full
+string in @var{<template-arg>}. A quoting mechanism was added to make
+it possible to use a real @samp{%}. The @samp{\} character quotes the
+special characters @samp{\}, @samp{%}, and @samp{,}.
+
+Here is an example:
+
+@example
+ termcap hp700 'XC=B\E(K%\E(B,\304[,\326\\\\,\334]'
+@end example
+
+This tells @code{screen}, how to translate ISOlatin1 (charset @samp{B})
+upper case umlaut characters on a @code{hp700} terminal that has a
+German charset. @samp{\304} gets translated to
+@samp{\E(K[\E(B} and so on.
+Note that this line gets parsed *three* times before the internal
+lookup table is built, therefore a lot of quoting is needed to
+create a single @samp{\}.
+
+Another extension was added to allow more emulation: If a mapping
+translates the unquoted @samp{%} char, it will be sent to the terminal
+whenever screen switches to the corresponding @var{<designator>}.
+In this
+special case the template is assumed to be just @samp{%} because
+the charset switch sequence and the character mappings normally
+haven't much in common.
+
+This example shows one use of the extension:
+@example
+ termcap xterm 'XC=K%,%\E(B,[\304,\\\\\326,]\334'
+@end example
+
+Here, a part of the German (@samp{K}) charset is emulated on an xterm.
+If screen has to change to the @samp{K} charset, @samp{\E(B} will be
+sent
+to the terminal, i.e. the ASCII charset is used instead. The
+template is just @samp{%}, so the mapping is straightforward:
+@samp{[} to @samp{\304}, @samp{\} to @samp{\326}, and @samp{]} to
+@samp{\334}.
+
+@node Message Line, Logging, Termcap, Top
+@chapter The Message Line
+@cindex message line
+
+@code{Screen} displays informational messages and other diagnostics in a
+@dfn{message line} at the bottom of the screen. If your terminal has a
+status line defined in its termcap, screen will use this for displaying
+its messages, otherwise the last line of the screen will be temporarily
+overwritten and output will be momentarily interrupted. The message
+line is automatically removed after a few seconds delay, but it can also
+be removed early (on terminals without a status line) by beginning to
+type.
+
+@menu
+* Privacy Message:: Using the message line from your program.
+* Hardware Status Line:: Use the terminal's hardware status line.
+* Last Message:: Redisplay the last message.
+* Message Wait:: Control how long messages are displayed.
+@end menu
+
+@node Privacy Message, Hardware Status Line, , Message Line
+@section Using the message line from your program
+The message line facility can be used by an application running in the
+current window by means of the ANSI @dfn{Privacy message} control
+sequence. For instance, from within the shell, try something like:
+
+@example
+echo "@value{esc}^Hello world from window $WINDOW@value{esc}\"
+@end example
+
+where @samp{@value{esc}} is ASCII ESC and the @samp{^} that follows it
+is a literal caret or up-arrow.
+
+@node Hardware Status Line, Last Message, Privacy Message, Message Line
+@section Hardware Status Line
+@deffn Command hardstatus [state]
+@deffnx Command hardstatus [@code{always}]@code{firstline}|@code{lastline}|@code{message}|@code{ignore} [string]
+@deffnx Command hardstatus @code{string} [string]
+(none)@*
+This command configures the use and emulation of the terminal's
+hardstatus line. The first form toggles whether @code{screen}
+will use the hardware status line to display messages. If the
+flag is set to @samp{off}, these messages
+are overlaid in reverse video mode at the display line. The default
+setting is @samp{on}.
+
+The second form tells screen what to do if the terminal doesn't
+have a hardstatus line (i.e. the termcap/terminfo capabilities
+"hs", "ts", "fs" and "ds" are not set). If the type
+@code{firstline}/@code{lastline} is used, screen will reserve the first/last
+line of the display for the hardstatus. @code{message} uses
+@code{screen}'s message mechanism and
+@code{ignore} tells @code{screen} never to display the hardstatus.
+If you prepend the word @code{always} to the type (e.g., @code{alwayslastline}), @code{screen} will use
+the type even if the terminal supports a hardstatus line.
+
+The third form specifies the contents of the hardstatus line.
+@code{%h} is used as default string, i.e., the stored hardstatus of the
+current window (settable via @samp{ESC]0;^G} or @samp{ESC_\\}) is
+displayed.
+You can customize this to any string you like including
+string escapes (@pxref{String Escapes}).
+If you leave
+out the argument @var{string}, the current string is displayed.
+
+You can mix the second and third form by providing the string as
+additional argument.
+@end deffn
+
+@node Last Message, Message Wait, Hardware Status Line, Message Line
+@section Display Last Message
+@kindex m
+@kindex C-m
+@deffn Command lastmsg
+(@kbd{C-a m}, @kbd{C-a C-m})@*
+Repeat the last message displayed in the message line. Useful if you're
+typing when a message appears, because (unless your terminal has a
+hardware status line) the message goes away when you press a key.
+@end deffn
+
+@node Message Wait, , Last Message, Message Line
+@section Message Wait
+@deffn Command msgminwait sec
+(none)@*
+Defines the time @code{screen} delays a new message when another is
+currently displayed. Defaults to 1 second.
+@end deffn
+
+@deffn Command msgwait sec
+(none)@*
+Defines the time a message is displayed, if @code{screen} is not
+disturbed by other activity. Defaults to 5 seconds.
+@end deffn
+
+@node Logging, Startup, Message Line, Top
+@chapter Logging
+
+This section describes the commands for keeping a record of your session.
+
+@menu
+* Hardcopy:: Dump the current screen to a file
+* Log:: Log the output of a window to a file
+@end menu
+
+@node Hardcopy, Log, , Logging
+@section hardcopy
+@kindex h
+@deffn Command hardcopy [-h] [@var{file}]
+(@kbd{C-a h})@*
+Writes out the currently displayed image to the file @var{file}, or,
+if no filename is specified, to @file{hardcopy.@var{n}}
+in the default directory, where @var{n} is the number of the
+current window. This either appends or overwrites the file if it
+exists, as determined by the @code{hardcopy_append} command.
+If the option @code{-h} is specified, dump also the
+contents of the scrollback buffer.
+@end deffn
+
+@deffn Command hardcopy_append state
+(none)@*
+If set to @samp{on}, @code{screen} will append to the
+@file{hardcopy.@var{n}} files created by the command @code{hardcopy};
+otherwise, these files are overwritten each time.
+@end deffn
+
+@deffn Command hardcopydir directory
+(none)@*
+Defines a directory where hardcopy files will be placed.
+If unset, hardcopys are dumped in screen's current working
+directory.
+@end deffn
+
+@node Log, , Hardcopy, Logging
+@section log
+
+@deffn Command deflog state
+(none)@*
+Same as the @code{log} command except that the default setting for new
+windows is changed. Initial setting is `off'.
+@end deffn
+
+@kindex H
+@deffn Command log [state]
+(@kbd{C-a H})@*
+Begins/ends logging of the current window to the file
+@file{screenlog.@var{n}} in the window's default directory, where
+@var{n} is the number of the current window.
+This filename can be changed with the @samp{logfile} command.
+If no parameter is given,
+the logging state is toggled. The session log is
+appended to the previous contents of the file if it already exists. The
+current contents and the contents of the scrollback history are not
+included in the session log. Default is @samp{off}.
+@end deffn
+
+@deffn Command logfile filename
+@deffnx Command logfile flush secs
+(none)@*
+Defines the name the log files will get. The default is @samp{screenlog.%n}.
+The second form changes the number of seconds @code{screen}
+will wait before flushing the logfile buffer to the file-system. The
+default value is 10 seconds.
+@end deffn
+
+@deffn Command logtstamp [state]
+@deffnx Command logtstamp @code{after} secs
+@deffnx Command logtstamp @code{string} string
+(none)@*
+This command controls logfile time-stamp mechanism of screen. If
+time-stamps are turned @samp{on}, screen adds a string containing
+the current time to the logfile after two minutes of inactivity.
+When output continues and more than another two minutes have passed,
+a second time-stamp is added to document the restart of the
+output. You can change this timeout with the second form
+of the command. The third form is used for customizing the time-stamp
+string (@samp{-- %n:%t -- time-stamp -- %M/%d/%y %c:%s --\n} by
+default).
+@end deffn
+
+@node Startup, Miscellaneous, Logging, Top
+@chapter Startup
+
+This section describes commands which are only useful in the
+@file{.screenrc} file, for use at startup.
+
+@menu
+* echo:: Display a message.
+* sleep:: Pause execution of the @file{.screenrc}.
+* Startup Message:: Control display of the copyright notice.
+@end menu
+
+@node echo, sleep, , Startup
+@section echo
+@deffn Command echo [@samp{-n}] message
+(none)@*
+The echo command may be used to annoy @code{screen} users with a
+'message of the day'. Typically installed in a global screenrc.
+The option @samp{-n} may be used to suppress the line feed.
+See also @code{sleep}.
+Echo is also useful for online checking of environment variables.
+@end deffn
+
+@node sleep, Startup Message, echo, Startup
+@section sleep
+@deffn Command sleep num
+(none)@*
+This command will pause the execution of a .screenrc file for @var{num}
+seconds. Keyboard activity will end the sleep. It may be used to give
+users a chance to read the messages output by @code{echo}.
+@end deffn
+
+@node Startup Message, , sleep, Startup
+@section Startup Message
+@deffn Command startup_message state
+(none)@*
+Select whether you want to see the copyright notice during startup.
+Default is @samp{on}, as you probably noticed.
+@end deffn
+
+@node Miscellaneous, String Escapes, Startup, Top
+@chapter Miscellaneous commands
+
+The commands described here do not fit well under any of the other
+categories.
+
+@menu
+* At:: Execute a command at other displays or windows.
+* Break:: Send a break signal to the window.
+* Bumpleft:: Swaps window with previous one on window list.
+* Bumpright:: Swaps window with next one on window list.
+* Collapse:: Collapses window list.
+* Debug:: Suppress/allow debugging output.
+* License:: Display the disclaimer page.
+* Nethack:: Use @code{nethack}-like error messages.
+* Nonblock:: Disable flow-control to a display.
+* Number:: Change the current window's number.
+* Time:: Display the time and load average.
+* Verbose:: Display window creation commands.
+* Version:: Display the version of @code{screen}.
+* Zombie:: Keep dead windows.
+* Printcmd:: Set command for VT100 printer port emulation.
+* Rendition:: Change text attributes in caption for flagged windows.
+* Sorendition:: Change the text highlighting method.
+* Attrcolor:: Map attributes to colors.
+* Setsid:: Change process group management.
+* Eval:: Parse and execute arguments.
+* Maxwin:: Set the maximum window number.
+* Backtick:: Program a command for a backtick string escape.
+* Screen Saver:: Define a screen safer.
+* Zmodem:: Define how screen treats zmodem requests.
+* Mousetrack:: Set whether screen should track mouse events.
+@end menu
+
+@node At, Break, , Miscellaneous
+@section At
+@deffn Command at [identifier][#|*|%] command [args]
+(none)@*
+Execute a command at other displays or windows as if it had been entered there.
+@code{At} changes the context (the `current window' or `current display'
+setting) of the command. If the first parameter describes a non-unique context,
+the command will be executed multiple times. If the first parameter is of the
+form @samp{@var{identifier}*} then identifier is matched against user names.
+The command is executed once for each display of the selected user(s).
+If the first parameter is of the form @samp{@var{identifier}%} identifier is
+matched against displays. Displays are named after the ttys they attach. The
+prefix @samp{/dev/} or @samp{/dev/tty} may be omitted from the identifier.
+If @var{identifier} has a @code{#} or nothing appended it is matched against
+window numbers and titles. Omitting an identifier in front of the @code{#},
+@code{*} or @code{%} character selects all users, displays or windows because
+a prefix-match is performed. Note that on the affected display(s) a short
+message will describe what happened.
+Note that the @code{#} character works as a comment introducer when it is
+preceded by whitespace. This can be escaped by prefixing @code{#} with a
+@code{\}.
+Permission is checked for the initiator of the @code{at} command, not for the
+owners of the affected display(s).
+Caveat:
+When matching against windows, the command is executed at least
+once per window. Commands that change the internal arrangement of windows
+(like @code{other}) may be called again. In shared windows the command will
+be repeated for each attached display. Beware, when issuing toggle commands
+like @code{login}!
+Some commands (e.g. @code{\*Qprocess}) require
+that a display is associated with the target windows. These commands may not
+work correctly under @code{at} looping over windows.
+@end deffn
+
+@node Break, Bumpleft, At, Miscellaneous
+@section Break
+@kindex b
+@kindex C-b
+@deffn Command break [duration]
+(@kbd{C-a b}, @kbd{C-a C-b})@*
+Send a break signal for @var{duration}*0.25 seconds to this window.
+For non-Posix systems the time interval is rounded up to full seconds.
+Most useful if a character device is attached to the window rather than
+a shell process (@pxref{Window Types}). The maximum duration of
+a break signal is limited to 15 seconds.
+@end deffn
+
+@kindex B
+@deffn Command pow_break
+(@kbd{C-a B})@*
+Reopen the window's terminal line and send a break condition.
+@end deffn
+
+@deffn Command breaktype [tcsendbreak|TIOCSBRK|TCSBRK]
+(none)@*
+Choose one of the available methods of generating a break signal for
+terminal devices. This command should affect the current window only.
+But it still behaves identical to @code{defbreaktype}. This will be changed in
+the future.
+Calling @code{breaktype} with no parameter displays the break setting for the
+current window.
+@end deffn
+
+@deffn Command defbreaktype [tcsendbreak|TIOCSBRK|TCSBRK]
+(none)@*
+Choose one of the available methods of generating a break signal for
+terminal devices opened afterwards. The preferred methods are
+@code{tcsendbreak} and
+@code{TIOCSBRK}. The third, @code{TCSBRK}, blocks the complete @code{screen}
+session for the duration of the break, but it may be the only way to
+generate long breaks. @code{tcsendbreak} and @code{TIOCSBRK} may or may not
+produce long breaks with spikes (e.g. 4 per second). This is not only system
+dependent, this also differs between serial board drivers.
+Calling @code{defbreaktype} with no parameter displays the current setting.
+@end deffn
+
+@node Bumpleft, Bumpright, Break, Miscellaneous
+@section Bumpleft
+@deffn Command bumpleft
+(none)@*
+Exchanges windows positions on window list, with window having lower number
+(left to current one).
+@end deffn
+
+@node Bumpright, Collapse, Bumpleft, Miscellaneous
+@section Bumpright
+@deffn Command bumpright
+(none)@*
+Exchanges windows positions on window list, with window having bigger number
+(right to current one).
+@end deffn
+
+@node Collapse, Debug, Bumpright, Miscellaneous
+@section Collapse
+@deffn Command collapse
+(none)@*
+Changes windows numbers, so there is no gaps between them.
+@end deffn
+
+@node Debug, License, Collapse, Miscellaneous
+@section Debug
+@deffn Command debug [on|off]
+(none)@*
+Turns runtime debugging on or off. If @code{screen} has been compiled with
+option @code{-DDEBUG} debugging is available and is turned on per default.
+Note that this command only affects debugging output from the main
+@samp{SCREEN} process correctly. Debug output from attacher processes can only
+be turned off once and forever.
+@end deffn
+
+@node License, Nethack, Debug, Miscellaneous
+@section License
+@kindex ,
+@deffn Command license
+(@kbd{C-a ,})@*
+Display the disclaimer page. This is done whenever @code{screen} is
+started without options, which should be often enough.
+@end deffn
+
+@node Nethack, Nonblock, License, Miscellaneous
+@section Nethack
+@deffn Command nethack state
+(none)@*
+Changes the kind of error messages used by @code{screen}. When you are
+familiar with the game @code{nethack}, you may enjoy the nethack-style
+messages which will often blur the facts a little, but are much funnier
+to read. Anyway, standard messages often tend to be unclear as well.
+
+This option is only available if @code{screen} was compiled with the
+NETHACK flag defined (@pxref{Installation}). The default setting is then
+determined by the presence of the environment variable
+@code{$NETHACKOPTIONS} and the file @code{~/.nethackrc} - if either one is
+present, the default is @code{on}.
+@end deffn
+
+@node Nonblock, Number, Nethack, Miscellaneous
+@section Nonblock
+@deffn Command nonblock [@var{state}|@var{numsecs}]
+Tell screen how to deal with user interfaces (displays) that cease to
+accept output. This can happen if a user presses ^S or a TCP/modem
+connection gets cut but no hangup is received. If nonblock is
+@code{off} (this is the default) screen waits until the display
+restarts to accept the output. If nonblock is @code{on}, screen
+waits until the timeout is reached (@code{on} is treated as 1s). If the
+display still doesn't receive characters, screen will consider
+it ``blocked'' and stop sending characters to it. If at
+some time it restarts to accept characters, screen will unblock
+the display and redisplay the updated window contents.
+@end deffn
+
+@deffn Command defnonblock @var{state}|@var{numsecs}
+Same as the @code{nonblock} command except that the default setting for
+displays is changed. Initial setting is @code{off}.
+@end deffn
+
+@node Number, Time, Nonblock, Miscellaneous
+@section Number
+@kindex N
+@deffn Command number [[+|-]@var{n}]
+(@kbd{C-a N})@*
+Change the current window's number. If the given number @var{n} is already
+used by another window, both windows exchange their numbers. If no argument is
+specified, the current window number (and title) is shown. Using either a
+plus (`+') or minus (`-') will change the window's number by the relative
+amount specified.
+@end deffn
+
+@node Time, Verbose, Number, Miscellaneous
+@section Time
+@kindex t
+@kindex C-t
+@deffn Command time [@var{string}]
+(@kbd{C-a t}, @kbd{C-a C-t})@*
+Uses the message line to display the time of day, the host name, and the
+load averages over 1, 5, and 15 minutes (if this is available on your
+system). For window-specific information use @code{info} (@pxref{Info}).
+If a @var{string} is specified, it changes the format of the time report
+like it is described in the string escapes chapter (@pxref{String Escapes}). Screen uses a default of @samp{%c:%s %M %d %H%? %l%?}.
+@end deffn
+
+@node Verbose, Version, Time, Miscellaneous
+@section Verbose
+@deffn Command verbose [on|off]
+If verbose is switched on, the command name is echoed, whenever a window
+is created (or resurrected from zombie state). Default is off.
+Without a parameter, the current setting is shown.
+@end deffn
+
+@node Version, Zombie, Verbose, Miscellaneous
+@section Version
+@kindex v
+@deffn Command version
+(@kbd{C-a v})@*
+Display the version and modification date in the message line.
+@end deffn
+
+@node Zombie, Printcmd, Version, Miscellaneous
+@section Zombie
+@deffn Command zombie [@var{keys} [onerror] ]
+@deffn Command zombie_timeout [@var{seconds}]
+@end deffn
+(none)@*
+Per default windows are removed from the window list as soon as the
+windows process (e.g. shell) exits. When a string of two keys is
+specified to the zombie command, `dead' windows will remain in the list.
+The @code{kill} command may be used to remove the window. Pressing the first key
+in the dead window has the same effect. Pressing the second key, however,
+screen will attempt to resurrect the window. The process that was initially
+running in the window will be launched again. Calling @code{zombie} without
+parameters will clear the zombie setting, thus making windows disappear when
+the process terminates.
+
+As the zombie setting is affected globally for all windows, this command
+should probably be called @code{defzombie}, but it isn't.
+
+Optionally you can put the word @code{onerror} after the keys. This will
+cause screen to monitor exit status of the process running in the window.
+If it exits normally ('0'), the window disappears. Any other exit value
+causes the window to become a zombie.
+
+Additionally the @code{zombie_timeout} command exists.
+If a window is declared ``dead'', screen will automatically try to
+resurrect the window after the timeout.
+It only works if zombie keys are defined via @code{zombie} command.
+@end deffn
+
+@node Printcmd, Rendition, Zombie, Miscellaneous
+@section Printcmd
+@deffn Command printcmd [@var{cmd}]
+(none)@*
+If @var{cmd} is not an empty string, screen will not use the terminal
+capabilities @code{po/pf} for printing if it detects an ansi print
+sequence @code{ESC [ 5 i}, but pipe the output into @var{cmd}.
+This should normally be a command like @samp{lpr} or
+@samp{cat > /tmp/scrprint}.
+@code{Printcmd} without an argument displays the current setting.
+The ansi sequence @code{ESC \} ends printing and closes the pipe.
+
+Warning: Be careful with this command! If other user have write
+access to your terminal, they will be able to fire off print commands.
+@end deffn
+
+@node Rendition, Sorendition, Printcmd, Miscellaneous
+@section Rendition
+@deffn Command rendition bell | monitor | silence | so @var{attr} [@var{color}]
+(none)@*
+Change the way screen renders the titles of windows that have monitor
+or bell flags set in caption or hardstatus or windowlist.
+See the chapter
+about string escapes (@pxref{String Escapes}) for the syntax of
+the modifiers. The default for monitor is currently @samp{=b} (bold,
+active colors), for bell @samp{=ub} (underline, bold and active colors), and
+for silence @samp{=u}.
+@end deffn
+
+@node Sorendition, Attrcolor, Rendition, Miscellaneous
+@section Sorendition
+@deffn Command sorendition [@var{attr} [@var{color}]]
+(none)@*
+This command has been deprecated. Use @code{rendition so} instead.
+@end deffn
+
+@node Attrcolor, Setsid, Sorendition, Miscellaneous
+@section Attrcolor
+@deffn Command attrcolor @var{attrib} [@var{attribute/color-modifier}]
+(none)@*
+This command can be used to highlight attributes by changing the color of
+the text. If the attribute
+@var{attrib}
+is in use, the specified attribute/color modifier is also applied. If no
+modifier is given, the current one is deleted. See the chapter
+about string escapes (@pxref{String Escapes}) for the syntax of
+the modifier. @code{Screen} understands two pseudo-attributes, @code{i}
+stands for high-intensity foreground color and @code{I} for
+high-intensity background color.
+
+@noindent
+Examples:
+@table @code
+@item attrcolor b "R"
+Change the color to bright red if bold text is to be printed.
+@item attrcolor u "-u b"
+Use blue text instead of underline.
+@item attrcolor b ".I"
+Use bright colors for bold text. Most terminal emulators do this
+already.
+@item attrcolor i "+b"
+Make bright colored text also bold.
+@end table
+@end deffn
+
+@node Setsid, Eval, Attrcolor, Miscellaneous
+@section Setsid
+@deffn Command setsid state
+(none)@*
+Normally @code{screen} uses different sessions and process groups for
+the windows. If setsid is turned @code{off}, this is not done
+anymore and all windows will be in the same process group as the
+screen backend process. This also breaks job-control, so be careful.
+The default is @code{on}, of course. This command is probably useful
+only in rare circumstances.
+@end deffn
+
+@node Eval, Maxwin, Setsid, Miscellaneous
+@section Eval
+@deffn Command eval @var{command1} [@var{command2} ...]
+(none)@*
+Parses and executes each argument as separate command.
+@end deffn
+
+@node Maxwin, Backtick, Eval, Miscellaneous
+@section Maxwin
+@deffn Command maxwin @var{n}
+(none)@*
+Set the maximum window number screen will create. Doesn't affect
+already existing windows. The number can be increased only when there are no
+existing windows.
+@end deffn
+
+@node Backtick, Screen Saver, Maxwin, Miscellaneous
+@section Backtick
+@deffn Command backtick @var{id} @var{lifespan} @var{autorefresh} @var{command} [@var{args}]
+@deffnx Command backtick @var{id}
+(none)@*
+Program the backtick command with the numerical id @var{id}.
+The output of such a command is used for substitution of the
+@code{%`} string escape (@pxref{String Escapes}).
+The specified @var{lifespan} is the number
+of seconds the output is considered valid. After this time, the
+command is run again if a corresponding string escape is encountered.
+The @var{autorefresh} parameter triggers an
+automatic refresh for caption and hardstatus strings after the
+specified number of seconds. Only the last line of output is used
+for substitution.
+
+If both the @var{lifespan} and the @var{autorefresh} parameters
+are zero, the backtick program is expected to stay in the
+background and generate output once in a while.
+In this case, the command is executed right away and screen stores
+the last line of output. If a new line gets printed screen will
+automatically refresh the hardstatus or the captions.
+
+The second form of the command deletes the backtick command
+with the numerical id @var{id}.
+@end deffn
+
+@node Screen Saver, Zmodem, Backtick, Miscellaneous
+@section Screen Saver
+@deffn Command idle [@var{timeout} [@var{cmd} @var{args}]]
+(none)@*
+Sets a command that is run after the specified number of
+seconds inactivity is reached. This command will normally
+be the @code{blanker} command to create a screen blanker, but
+it can be any screen command. If no command is specified,
+only the timeout is set. A timeout of zero (ot the special
+timeout @code{off}) disables the timer. If no arguments are
+given, the current settings are displayed.
+@end deffn
+
+@deffn Command blanker
+(none)@*
+Activate the screen blanker. First the screen is cleared.
+If no blanker program is defined, the cursor is turned
+off, otherwise, the program is started and it's output is
+written to the screen. The screen blanker is killed with
+the first keypress, the read key is discarded.
+
+This command is normally used together with the @code{idle}
+command.
+@end deffn
+
+@deffn Command blankerprg [@var{program args}]
+Defines a blanker program. Disables the blanker program if an
+empty argument is given. Shows the currently set blanker program if no
+arguments are given.
+
+@end deffn
+
+@node Zmodem, , Screen Saver, Miscellaneous
+@section Zmodem
+@deffn Command zmodem [off|auto|catch|pass]
+@deffnx Command zmodem sendcmd [string]
+@deffnx Command zmodem recvcmd [string]
+(none)@*
+Define zmodem support for @code{screen}. @code{Screen} understands two
+different modes when it detects a zmodem request: @code{pass}
+and @code{catch}. If the mode is set to @code{pass}, screen will
+relay all data to the attacher until the end of the
+transmission is reached. In @code{catch} mode screen acts as a
+zmodem endpoint and starts the corresponding rz/sz commands.
+If the mode is set to @code{auto}, screen will use @code{catch} if
+the window is a tty (e.g. a serial line), otherwise it
+will use @code{pass}.
+
+You can define the templates screen uses in @code{catch} mode
+via the second and the third form.
+
+Note also that this is an experimental feature.
+@end deffn
+
+@node String Escapes, Environment, Miscellaneous, Top
+@chapter String Escapes
+@cindex string escapes
+Screen provides an escape mechanism to insert information like the
+current time into messages or file names. The escape character
+is @code{%} with one exception: inside of a window's hardstatus
+@code{^%} (@code{^E}) is used instead.
+
+Here is the full list of supported escapes:
+
+@table @code
+@item %
+the escape character itself
+@item a
+either @code{am} or @code{pm}
+@item A
+either @code{AM} or @code{PM}
+@item c
+current time @code{HH:MM} in 24h format
+@item C
+current time @code{HH:MM} in 12h format
+@item d
+day number
+@item D
+weekday name
+@item E
+sets %? to true if the escape character has been pressed.
+@item f
+flags of the window. @xref{Windows}, for meanings of the various flags.
+@item F
+sets %? to true if the window has the focus
+@item h
+hardstatus of the window
+@item H
+hostname of the system
+@item l
+current load of the system
+@item m
+month number
+@item M
+month name
+@item n
+window number
+@item P
+sets %? to true if the current region is in copy/paste mode
+@item s
+seconds
+@item S
+session name
+@item t
+window title
+@item u
+all other users on this window
+@item w
+all window numbers and names. With @code{-} qualifier: up to the current
+window; with @code{+} qualifier: starting with the window after the current
+one.
+@item W
+all window numbers and names except the current one
+@item y
+last two digits of the year number
+@item Y
+full year number
+@item ?
+the part to the next @code{%?} is displayed only if a @code{%} escape
+inside the part expands to a non-empty string
+@item :
+else part of @code{%?}
+@item =
+pad the string to the display's width (like TeX's hfill). If a
+number is specified, pad to the percentage of the window's width.
+A @code{0} qualifier tells screen to treat the number as absolute position.
+You can specify to pad relative to the last absolute pad position
+by adding a @code{+} qualifier or to pad relative to the right margin
+by using @code{-}. The padding truncates the string if the specified
+position lies before the current position. Add the @code{L} qualifier
+to change this.
+@item <
+same as @code{%=} but just do truncation, do not fill with spaces
+@item >
+mark the current text position for the next truncation. When
+screen needs to do truncation, it tries to do it in a way that
+the marked position gets moved to the specified percentage of
+the output area. (The area starts from the last absolute pad
+position and ends with the position specified by the truncation
+operator.) The @code{L} qualifier tells screen to mark the truncated
+parts with @samp{...}.
+@item @{
+attribute/color modifier string terminated by the next @code{@}}
+@item `
+Substitute with the output of a `backtick' command. The length
+qualifier is misused to identify one of the commands. @xref{Backtick}.
+@end table
+The @code{c} and @code{C} escape may be qualified with a @code{0} to
+make screen use
+zero instead of space as fill character.
+The @code{n} and
+@code{=} escapes understand
+a length qualifier (e.g. @code{%3n}), @code{D} and @code{M} can be
+prefixed with @code{L} to generate long names, @code{w} and
+@code{W} also show the window flags if @code{L} is given.
+
+An attribute/color modifier is is used to change the attributes or the
+color settings. Its format
+is @samp{[attribute modifier] [color description]}. The attribute modifier
+must be prefixed by a change type indicator if it can be confused with
+a color description. The following change types are known:
+@table @code
+@item +
+add the specified set to the current attributes
+@item -
+remove the set from the current attributes
+@item !
+invert the set in the current attributes
+@item =
+change the current attributes to the specified set
+@end table
+The attribute set can either be specified as a hexadecimal number or
+a combination of the following letters:
+@table @code
+@item d
+dim
+@item u
+underline
+@item b
+bold
+@item r
+reverse
+@item s
+standout
+@item B
+blinking
+@end table
+Colors are coded either as a hexadecimal number or two letters specifying
+the desired background and foreground color (in that order). The following
+colors are known:
+@table @code
+@item k
+black
+@item r
+red
+@item g
+green
+@item y
+yellow
+@item b
+blue
+@item m
+magenta
+@item c
+cyan
+@item w
+white
+@item d
+default color
+@item .
+leave color unchanged
+@end table
+The capitalized versions of the letter specify bright colors. You can also
+use the pseudo-color @samp{i} to set just the brightness and leave the color
+unchanged.
+
+A one digit/letter color description is treated as foreground or
+background color dependent on the current attributes: if reverse mode is
+set, the background color is changed instead of the foreground color.
+If you don't like this, prefix the color with a @samp{.}. If you want
+the same behavior for two-letter color descriptions, also prefix them
+with a @samp{.}.
+
+As a special case, @samp{%@{-@}} restores the attributes and colors that
+were set before the last change was made (i.e. pops one level of the
+color-change stack).
+
+@noindent
+Examples:
+@table @samp
+@item G
+set color to bright green
+@item +b r
+use bold red
+@item = yd
+clear all attributes, write in default color on yellow background.
+@item %-Lw%@{= BW@}%50>%n%f* %t%@{-@}%+Lw%<
+The available windows centered at the current win dow and truncated to
+the available width. The current window is displayed white on blue.
+This can be used with @samp{hardstatus alwayslastline}.
+@item %?%F%@{.R.@}%?%3n %t%? [%h]%?
+The window number and title and the window's hardstatus, if one is set.
+Also use a red background if this is the active focus.
+Useful for @samp{caption string}.
+@end table
+
+
+@node Environment, Files, String Escapes, Top
+@chapter Environment Variables
+@cindex environment
+
+@table @code
+@item COLUMNS
+Number of columns on the terminal (overrides termcap entry).
+
+@item HOME
+Directory in which to look for .screenrc.
+
+@item LINES
+Number of lines on the terminal (overrides termcap entry).
+
+@item LOCKPRG
+Screen lock program.
+
+@item NETHACKOPTIONS
+Turns on @code{nethack} option.
+
+@item PATH
+Used for locating programs to run.
+
+@item SCREENCAP
+For customizing a terminal's @code{TERMCAP} value.
+
+@item SCREENDIR
+Alternate socket directory.
+
+@item SCREENRC
+Alternate user screenrc file.
+
+@item SHELL
+Default shell program for opening windows (default @file{/bin/sh}).
+See also @code{shell} .screenrc command.
+
+@item STY
+Alternate socket name. If @code{screen} is invoked, and the environment variable
+@code{STY} is set, then it creates only a window in the running @code{screen}
+session rather than starting a new session.
+
+@item SYSSCREENRC
+Alternate system screenrc file.
+
+@item TERM
+Terminal name.
+
+@item TERMCAP
+Terminal description.
+
+@item WINDOW
+Window number of a window (at creation time).
+@end table
+
+@node Files, Credits, Environment, Top
+@chapter Files Referenced
+@cindex files
+
+@table @file
+@item .../screen-4.?.??/etc/screenrc
+@itemx .../screen-4.?.??/etc/etcscreenrc
+Examples in the @code{screen} distribution package for private and
+global initialization files.
+
+@item @code{$SYSSCREENRC}
+@itemx /local/etc/screenrc
+@code{screen} initialization commands
+
+@item @code{$SCREENRC}
+@itemx @code{$HOME}/.iscreenrc
+@itemx @code{$HOME}/.screenrc
+Read in after /local/etc/screenrc
+
+@item @code{$SCREENDIR}/S-@var{login}
+
+@item /local/screens/S-@var{login}
+Socket directories (default)
+
+@item /usr/tmp/screens/S-@var{login}
+Alternate socket directories.
+
+@item @var{socket directory}/.termcap
+Written by the @code{dumptermcap} command
+
+@item /usr/tmp/screens/screen-exchange or
+@itemx /tmp/screen-exchange
+@code{screen} interprocess communication buffer
+
+@item hardcopy.[0-9]
+Screen images created by the hardcopy command
+
+@item screenlog.[0-9]
+Output log files created by the log command
+
+@item /usr/lib/terminfo/?/* or
+@itemx /etc/termcap
+Terminal capability databases
+
+@item /etc/utmp
+Login records
+
+@item @code{$LOCKPRG}
+Program for locking the terminal.
+@end table
+
+@node Credits, Bugs, Files, Top
+@chapter Credits
+
+@noindent
+Authors @*
+=======
+
+Originally created by Oliver Laumann. For a long time maintained
+and developed by Juergen Weigert, Michael Schroeder, Micah Cowan
+and Sadrul Habib Chowdhury. This latest version was produced by
+Amadeusz Slawinski <amade@@asmblr.net>
+and Alexander Naumov <alexander_naumov@@opensuse.org>.
+
+@noindent
+Contributors @*
+============
+
+@verbatim
+ Thomas Renninger <treen@suse.com>,
+ Axel Beckert <abe@deuxchevaux.org>,
+ Ken Beal <kbeal@@amber.ssd.csd.harris.com>,
+ Rudolf Koenig <rfkoenig@@informatik.uni-erlangen.de>,
+ Toerless Eckert <eckert@@informatik.uni-erlangen.de>,
+ Wayne Davison <davison@@borland.com>,
+ Patrick Wolfe <pat@@kai.com, kailand!pat>,
+ Bart Schaefer <schaefer@@cse.ogi.edu>,
+ Nathan Glasser <nathan@@brokaw.lcs.mit.edu>,
+ Larry W. Virden <lvirden@@cas.org>,
+ Howard Chu <hyc@@hanauma.jpl.nasa.gov>,
+ Tim MacKenzie <tym@@dibbler.cs.monash.edu.au>,
+ Markku Jarvinen <mta@@@{cc,cs,ee@}.tut.fi>,
+ Marc Boucher <marc@@CAM.ORG>,
+ Doug Siebert <dsiebert@@isca.uiowa.edu>,
+ Ken Stillson <stillson@@tsfsrv.mitre.org>,
+ Ian Frechett <frechett@@spot.Colorado.EDU>,
+ Brian Koehmstedt <bpk@@gnu.ai.mit.edu>,
+ Don Smith <djs6015@@ultb.isc.rit.edu>,
+ Frank van der Linden <vdlinden@@fwi.uva.nl>,
+ Martin Schweikert <schweik@@cpp.ob.open.de>,
+ David Vrona <dave@@sashimi.lcu.com>,
+ E. Tye McQueen <tye%spillman.UUCP@@uunet.uu.net>,
+ Matthew Green <mrg@@eterna.com.au>,
+ Christopher Williams <cgw@@pobox.com>,
+ Matt Mosley <mattm@@access.digex.net>,
+ Gregory Neil Shapiro <gshapiro@@wpi.WPI.EDU>,
+ Jason Merrill <jason@@jarthur.Claremont.EDU>,
+ Johannes Zellner <johannes@@zellner.org>,
+ Pablo Averbuj <pablo@@averbuj.com>.
+@end verbatim
+
+@noindent
+Version @*
+=======
+
+This manual describes version @value{version} of the @code{screen}
+program. Its roots are a merge of a custom version 2.3PR7 by Wayne
+Davison and several enhancements to Oliver Laumann's version 2.0.
+Note that all versions numbered 2.x are copyright by Oliver Laumann.
+
+See also @xref{Availability}.
+
+@node Bugs, Installation, Credits, Top
+@chapter Bugs
+@cindex bugs
+
+Just like any other significant piece of software, @code{screen} has a
+few bugs and missing features. Please send in a bug report if you have
+found a bug not mentioned here.
+
+@menu
+* Known Bugs:: Problems we know about.
+* Reporting Bugs:: How to contact the maintainers.
+* Availability:: Where to find the latest screen version.
+@end menu
+
+@node Known Bugs, Reporting Bugs, , Bugs
+@section Known Bugs
+
+@itemize @bullet
+@item
+@samp{dm} (delete mode) and @samp{xs} are not handled correctly (they
+are ignored). @samp{xn} is treated as a magic-margin indicator.
+
+@item
+@code{screen} has no clue about double-high or double-wide characters.
+But this is the only area where @code{vttest} is allowed to fail.
+
+@item
+It is not possible to change the environment variable @code{$TERMCAP}
+when reattaching under a different terminal type.
+
+@item
+The support of terminfo based systems is very limited. Adding extra
+capabilities to @code{$TERMCAP} may not have any effects.
+
+@item
+@code{screen} does not make use of hardware tabs.
+
+@item
+@code{screen} must be installed setuid root on most systems
+in order to be able to
+correctly change the owner of the tty device file for each window.
+Special permission may also be required to write the file
+@file{/etc/utmp}.
+
+@item
+Entries in @file{/etc/utmp} are not removed when @code{screen} is killed
+with SIGKILL. This will cause some programs (like "w" or "rwho") to
+advertise that a user is logged on who really isn't.
+
+@item
+@code{screen} may give a strange warning when your tty has no utmp
+entry.
+
+@item
+When the modem line was hung up, @code{screen} may not automatically detach
+(or quit) unless the device driver sends a HANGUP signal. To detach such a
+@code{screen} session use the -D or -d command line option.
+
+@item
+If a password is set, the command line options -d and -D still detach a
+session without asking.
+
+@item
+Both @code{breaktype} and @code{defbreaktype} change the break generating
+method used by all terminal devices. The first should change a window
+specific setting, where the latter should change only the default for new
+windows.
+
+@item
+When attaching to a multiuser session, the user's @file{.screenrc} file is not
+sourced. Each users personal settings have to be included in the
+@file{.screenrc} file from which the session is booted, or have to be
+changed manually.
+
+@item
+A weird imagination is most useful to gain full advantage of all the
+features.
+@end itemize
+
+@node Reporting Bugs, Availability, Known Bugs, Bugs
+@section Reporting Bugs
+@cindex bug report
+
+If you find a bug in @code{Screen}, please send electronic mail to
+@w{@samp{screen-devel@@gnu.org}}. Include the version number
+of @code{Screen} which you are using. Also include in your message the
+hardware and operating system, the compiler used to compile, a
+description of the bug behavior, and the conditions that triggered the
+bug. Please recompile @code{screen} with the @samp{-DDEBUG} options
+enabled, reproduce the bug, and have a look at the debug output written to
+the directory @file{/tmp/debug}. If necessary quote suspect passages from the
+debug output and show the contents of your @file{config.h} if it matters.
+
+@node Availability, , Reporting Bugs, Bugs
+@section Availability
+@cindex availability
+
+@code{Screen} is available under the @code{GNU} copyleft.
+
+The latest official release of @code{screen} available via anonymous
+ftp from @samp{prep.ai.mit.edu}, @samp{nic.funet.fi} or any other
+@code{GNU} distribution site. The home site of
+@code{screen} is @samp{ftp.uni-erlangen.de
+(131.188.3.71)}, in the directory @file{pub/utilities/screen}.
+The subdirectory @samp{private} contains the latest beta testing release.
+If you want to help, send a note to screen-devel@@gnu.org.
+
+@node Installation, Concept Index, Bugs, Top
+@chapter Installation
+@cindex installation
+
+Since @code{screen} uses pseudo-ttys, the select system call, and
+UNIX-domain sockets/named pipes, it will not run under a system that
+does not include these features of 4.2 and 4.3 BSD UNIX.
+
+@menu
+* Socket Directory:: Where screen stores its handle.
+* Compiling Screen::
+@end menu
+
+@node Socket Directory,
+@section Socket Directory
+@cindex socket directory
+
+The socket directory defaults either to @file{$HOME/.screen} or simply to
+@file{/tmp/screens} or preferably to @file{/usr/local/screens} chosen at
+compile-time. If @code{screen} is installed
+setuid root, then the administrator should compile screen with an
+adequate (not NFS mounted) @code{SOCKDIR}. If @code{screen} is not
+running setuid-root, the user can specify any mode 700 directory in the
+environment variable @code{$SCREENDIR}.
+
+@node Compiling Screen, , Socket Directory, Installation
+@section Compiling Screen
+@cindex compiling screen
+
+To compile and install screen:
+
+The @code{screen} package comes with a @code{GNU Autoconf} configuration
+script. Before you compile the package run
+
+@center @code{sh ./configure}
+
+This will create a @file{config.h} and @file{Makefile} for your machine.
+If @code{configure} fails for some reason, then look at the examples and
+comments found in the @file{Makefile.in} and @file{config.h.in} templates.
+Rename @file{config.status} to @file{config.status.@var{machine}} when
+you want to keep configuration data for multiple architectures. Running
+@code{sh ./config.status.@var{machine}} recreates your configuration
+significantly faster than rerunning @code{configure}.
+@*
+Read through the "User Configuration" section of @file{config.h}, and verify
+that it suits your needs.
+A comment near the top of this section explains why it's best to
+install screen setuid to root.
+Check for the place for the global @file{screenrc}-file and for the socket
+directory.
+@*
+Check the compiler used in @file{Makefile}, the prefix path where to install
+@code{screen}. Then run
+
+@center @code{make}
+
+If @code{make} fails to produce one of the files @file{term.h}, @file{comm.h}
+or @file{tty.c}, then use @code{@var{filename.x}.dist} instead.
+For additional information about installation of @code{screen} refer to the
+file @file{INSTALLATION}, coming with this package.
+
+@node Concept Index, Command Index, Installation, Top
+@unnumbered Concept Index
+
+@printindex cp
+
+@node Command Index, Keystroke Index, Concept Index, Top
+@unnumbered Command Index
+
+This is a list of all the commands supported by @code{screen}.
+
+@printindex fn
+
+@node Keystroke Index, , Command Index, Top
+@unnumbered Keystroke Index
+
+This is a list of the default key bindings.
+
+The leading escape character (@pxref{Command Character}) has been omitted
+from the key sequences, since it is the same for all bindings.
+
+@printindex ky
+
+@bye
+
diff --git a/doc/window_to_display.ps b/doc/window_to_display.ps
new file mode 100644
index 0000000..cee66b3
--- /dev/null
+++ b/doc/window_to_display.ps
@@ -0,0 +1,2959 @@
+%!PS-Adobe-2.0 EPSF-1.2
+%%Creator: idraw
+%%DocumentFonts: Courier Times-Bold
+%%Pages: 1
+%%BoundingBox: 20 154 576 782
+%%EndComments
+
+%%BeginIdrawPrologue
+/arrowhead {
+0 begin
+transform originalCTM itransform
+/taily exch def
+/tailx exch def
+transform originalCTM itransform
+/tipy exch def
+/tipx exch def
+/dy tipy taily sub def
+/dx tipx tailx sub def
+/angle dx 0 ne dy 0 ne or { dy dx atan } { 90 } ifelse def
+gsave
+originalCTM setmatrix
+tipx tipy translate
+angle rotate
+newpath
+arrowHeight neg arrowWidth 2 div moveto
+0 0 lineto
+arrowHeight neg arrowWidth 2 div neg lineto
+patternNone not {
+originalCTM setmatrix
+/padtip arrowHeight 2 exp 0.25 arrowWidth 2 exp mul add sqrt brushWidth mul
+arrowWidth div def
+/padtail brushWidth 2 div def
+tipx tipy translate
+angle rotate
+padtip 0 translate
+arrowHeight padtip add padtail add arrowHeight div dup scale
+arrowheadpath
+ifill
+} if
+brushNone not {
+originalCTM setmatrix
+tipx tipy translate
+angle rotate
+arrowheadpath
+istroke
+} if
+grestore
+end
+} dup 0 9 dict put def
+
+/arrowheadpath {
+newpath
+arrowHeight neg arrowWidth 2 div moveto
+0 0 lineto
+arrowHeight neg arrowWidth 2 div neg lineto
+} def
+
+/leftarrow {
+0 begin
+y exch get /taily exch def
+x exch get /tailx exch def
+y exch get /tipy exch def
+x exch get /tipx exch def
+brushLeftArrow { tipx tipy tailx taily arrowhead } if
+end
+} dup 0 4 dict put def
+
+/rightarrow {
+0 begin
+y exch get /tipy exch def
+x exch get /tipx exch def
+y exch get /taily exch def
+x exch get /tailx exch def
+brushRightArrow { tipx tipy tailx taily arrowhead } if
+end
+} dup 0 4 dict put def
+
+%%EndIdrawPrologue
+
+/arrowHeight 8 def
+/arrowWidth 4 def
+
+/IdrawDict 52 dict def
+IdrawDict begin
+
+/reencodeISO {
+dup dup findfont dup length dict begin
+{ 1 index /FID ne { def }{ pop pop } ifelse } forall
+/Encoding ISOLatin1Encoding def
+currentdict end definefont
+} def
+
+/ISOLatin1Encoding [
+/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright
+/parenleft/parenright/asterisk/plus/comma/minus/period/slash
+/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon
+/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N
+/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright
+/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m
+/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde
+/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve
+/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut
+/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar
+/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot
+/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior
+/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine
+/guillemotright/onequarter/onehalf/threequarters/questiondown
+/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla
+/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex
+/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis
+/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute
+/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis
+/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave
+/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex
+/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis
+/yacute/thorn/ydieresis
+] def
+/Courier reencodeISO def
+/Times-Bold reencodeISO def
+
+/none null def
+/numGraphicParameters 17 def
+/stringLimit 65535 def
+
+/Begin {
+save
+numGraphicParameters dict begin
+} def
+
+/End {
+end
+restore
+} def
+
+/SetB {
+dup type /nulltype eq {
+pop
+false /brushRightArrow idef
+false /brushLeftArrow idef
+true /brushNone idef
+} {
+/brushDashOffset idef
+/brushDashArray idef
+0 ne /brushRightArrow idef
+0 ne /brushLeftArrow idef
+/brushWidth idef
+false /brushNone idef
+} ifelse
+} def
+
+/SetCFg {
+/fgblue idef
+/fggreen idef
+/fgred idef
+} def
+
+/SetCBg {
+/bgblue idef
+/bggreen idef
+/bgred idef
+} def
+
+/SetF {
+/printSize idef
+/printFont idef
+} def
+
+/SetP {
+dup type /nulltype eq {
+pop true /patternNone idef
+} {
+dup -1 eq {
+/patternGrayLevel idef
+/patternString idef
+} {
+/patternGrayLevel idef
+} ifelse
+false /patternNone idef
+} ifelse
+} def
+
+/BSpl {
+0 begin
+storexyn
+newpath
+n 1 gt {
+0 0 0 0 0 0 1 1 true subspline
+n 2 gt {
+0 0 0 0 1 1 2 2 false subspline
+1 1 n 3 sub {
+/i exch def
+i 1 sub dup i dup i 1 add dup i 2 add dup false subspline
+} for
+n 3 sub dup n 2 sub dup n 1 sub dup 2 copy false subspline
+} if
+n 2 sub dup n 1 sub dup 2 copy 2 copy false subspline
+patternNone not brushLeftArrow not brushRightArrow not and and { ifill } if
+brushNone not { istroke } if
+0 0 1 1 leftarrow
+n 2 sub dup n 1 sub dup rightarrow
+} if
+end
+} dup 0 4 dict put def
+
+/Circ {
+newpath
+0 360 arc
+patternNone not { ifill } if
+brushNone not { istroke } if
+} def
+
+/CBSpl {
+0 begin
+dup 2 gt {
+storexyn
+newpath
+n 1 sub dup 0 0 1 1 2 2 true subspline
+1 1 n 3 sub {
+/i exch def
+i 1 sub dup i dup i 1 add dup i 2 add dup false subspline
+} for
+n 3 sub dup n 2 sub dup n 1 sub dup 0 0 false subspline
+n 2 sub dup n 1 sub dup 0 0 1 1 false subspline
+patternNone not { ifill } if
+brushNone not { istroke } if
+} {
+Poly
+} ifelse
+end
+} dup 0 4 dict put def
+
+/Elli {
+0 begin
+newpath
+4 2 roll
+translate
+scale
+0 0 1 0 360 arc
+patternNone not { ifill } if
+brushNone not { istroke } if
+end
+} dup 0 1 dict put def
+
+/Line {
+0 begin
+2 storexyn
+newpath
+x 0 get y 0 get moveto
+x 1 get y 1 get lineto
+brushNone not { istroke } if
+0 0 1 1 leftarrow
+0 0 1 1 rightarrow
+end
+} dup 0 4 dict put def
+
+/MLine {
+0 begin
+storexyn
+newpath
+n 1 gt {
+x 0 get y 0 get moveto
+1 1 n 1 sub {
+/i exch def
+x i get y i get lineto
+} for
+patternNone not brushLeftArrow not brushRightArrow not and and { ifill } if
+brushNone not { istroke } if
+0 0 1 1 leftarrow
+n 2 sub dup n 1 sub dup rightarrow
+} if
+end
+} dup 0 4 dict put def
+
+/Poly {
+3 1 roll
+newpath
+moveto
+-1 add
+{ lineto } repeat
+closepath
+patternNone not { ifill } if
+brushNone not { istroke } if
+} def
+
+/Rect {
+0 begin
+/t exch def
+/r exch def
+/b exch def
+/l exch def
+newpath
+l b moveto
+l t lineto
+r t lineto
+r b lineto
+closepath
+patternNone not { ifill } if
+brushNone not { istroke } if
+end
+} dup 0 4 dict put def
+
+/Text {
+ishow
+} def
+
+/idef {
+dup where { pop pop pop } { exch def } ifelse
+} def
+
+/ifill {
+0 begin
+gsave
+patternGrayLevel -1 ne {
+fgred bgred fgred sub patternGrayLevel mul add
+fggreen bggreen fggreen sub patternGrayLevel mul add
+fgblue bgblue fgblue sub patternGrayLevel mul add setrgbcolor
+eofill
+} {
+eoclip
+originalCTM setmatrix
+pathbbox /t exch def /r exch def /b exch def /l exch def
+/w r l sub ceiling cvi def
+/h t b sub ceiling cvi def
+/imageByteWidth w 8 div ceiling cvi def
+/imageHeight h def
+bgred bggreen bgblue setrgbcolor
+eofill
+fgred fggreen fgblue setrgbcolor
+w 0 gt h 0 gt and {
+l w add b translate w neg h scale
+w h true [w 0 0 h neg 0 h] { patternproc } imagemask
+} if
+} ifelse
+grestore
+end
+} dup 0 8 dict put def
+
+/istroke {
+gsave
+brushDashOffset -1 eq {
+[] 0 setdash
+1 setgray
+} {
+brushDashArray brushDashOffset setdash
+fgred fggreen fgblue setrgbcolor
+} ifelse
+brushWidth setlinewidth
+originalCTM setmatrix
+stroke
+grestore
+} def
+
+/ishow {
+0 begin
+gsave
+fgred fggreen fgblue setrgbcolor
+/fontDict printFont printSize scalefont dup setfont def
+/descender fontDict begin 0 [FontBBox] 1 get FontMatrix end
+transform exch pop def
+/vertoffset 1 printSize sub descender sub def {
+0 vertoffset moveto show
+/vertoffset vertoffset printSize sub def
+} forall
+grestore
+end
+} dup 0 3 dict put def
+/patternproc {
+0 begin
+/patternByteLength patternString length def
+/patternHeight patternByteLength 8 mul sqrt cvi def
+/patternWidth patternHeight def
+/patternByteWidth patternWidth 8 idiv def
+/imageByteMaxLength imageByteWidth imageHeight mul
+stringLimit patternByteWidth sub min def
+/imageMaxHeight imageByteMaxLength imageByteWidth idiv patternHeight idiv
+patternHeight mul patternHeight max def
+/imageHeight imageHeight imageMaxHeight sub store
+/imageString imageByteWidth imageMaxHeight mul patternByteWidth add string def
+0 1 imageMaxHeight 1 sub {
+/y exch def
+/patternRow y patternByteWidth mul patternByteLength mod def
+/patternRowString patternString patternRow patternByteWidth getinterval def
+/imageRow y imageByteWidth mul def
+0 patternByteWidth imageByteWidth 1 sub {
+/x exch def
+imageString imageRow x add patternRowString putinterval
+} for
+} for
+imageString
+end
+} dup 0 12 dict put def
+
+/min {
+dup 3 2 roll dup 4 3 roll lt { exch } if pop
+} def
+
+/max {
+dup 3 2 roll dup 4 3 roll gt { exch } if pop
+} def
+
+/midpoint {
+0 begin
+/y1 exch def
+/x1 exch def
+/y0 exch def
+/x0 exch def
+x0 x1 add 2 div
+y0 y1 add 2 div
+end
+} dup 0 4 dict put def
+
+/thirdpoint {
+0 begin
+/y1 exch def
+/x1 exch def
+/y0 exch def
+/x0 exch def
+x0 2 mul x1 add 3 div
+y0 2 mul y1 add 3 div
+end
+} dup 0 4 dict put def
+
+/subspline {
+0 begin
+/movetoNeeded exch def
+y exch get /y3 exch def
+x exch get /x3 exch def
+y exch get /y2 exch def
+x exch get /x2 exch def
+y exch get /y1 exch def
+x exch get /x1 exch def
+y exch get /y0 exch def
+x exch get /x0 exch def
+x1 y1 x2 y2 thirdpoint
+/p1y exch def
+/p1x exch def
+x2 y2 x1 y1 thirdpoint
+/p2y exch def
+/p2x exch def
+x1 y1 x0 y0 thirdpoint
+p1x p1y midpoint
+/p0y exch def
+/p0x exch def
+x2 y2 x3 y3 thirdpoint
+p2x p2y midpoint
+/p3y exch def
+/p3x exch def
+movetoNeeded { p0x p0y moveto } if
+p1x p1y p2x p2y p3x p3y curveto
+end
+} dup 0 17 dict put def
+
+/storexyn {
+/n exch def
+/y n array def
+/x n array def
+n 1 sub -1 0 {
+/i exch def
+y i 3 2 roll put
+x i 3 2 roll put
+} for
+} def
+
+/SSten {
+fgred fggreen fgblue setrgbcolor
+dup true exch 1 0 0 -1 0 6 -1 roll matrix astore
+} def
+
+/FSten {
+dup 3 -1 roll dup 4 1 roll exch
+newpath
+0 0 moveto
+dup 0 exch lineto
+exch dup 3 1 roll exch lineto
+0 lineto
+closepath
+bgred bggreen bgblue setrgbcolor
+eofill
+SSten
+} def
+
+/Rast {
+exch dup 3 1 roll 1 0 0 -1 0 6 -1 roll matrix astore
+} def
+
+%%EndProlog
+
+%I Idraw 10 Grid 8 8
+
+%%Page: 1 1
+
+Begin
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 0.95606 0 0 0.95606 0 0 ] concat
+/originalCTM matrix currentmatrix def
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 6
+276 433
+276 449
+292 449
+364 449
+380 449
+380 433
+6 BSpl
+%I 1
+End
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t u
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 -400 -208 ] concat
+
+Begin %I CBSpl
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg LtGray
+0.762951 0.762951 0.762951 SetCBg
+%I p
+0.5 SetP
+%I t
+[ 0.5 0 0 0.5 350 330.5 ] concat
+%I 12
+340 107
+340 123
+340 187
+340 203
+356 203
+468 203
+484 203
+484 187
+484 123
+484 107
+468 107
+356 107
+12 CBSpl
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 535.5 381 ] concat
+%I
+[
+(w_ptyfd)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 88 -23.9999 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ -4.37114e-08 -1 1 -4.37114e-08 -608 640 ] concat
+
+Begin %I Poly
+none SetB %I b n
+%I cfg Black
+0 0 0 SetCFg
+%I cbg LtGray
+0.762951 0.762951 0.762951 SetCBg
+%I p
+0.5 SetP
+%I t
+[ 0.5 0 0 0.5 238 522.5 ] concat
+%I 4
+164 315
+228 315
+228 363
+164 363
+4 Poly
+End
+
+Begin %I Rect
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+233 363 241 387 Rect
+End
+
+Begin %I Line
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+225 387 225 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+217 387 217 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+233 363 201 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+201 387 233 387 Line
+%I 1
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 66.5 285 ] concat
+%I
+[
+(d_obuf)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 153.5 244 ] concat
+%I
+[
+(write\(\))
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+2 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg Black
+0 0 0 SetCBg
+none SetP %I p n
+%I t
+[ 0.5 0 0 0.5 56 123.5 ] concat
+%I 3
+272 281
+288 249
+272 201
+3 BSpl
+%I 2
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t u
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 -239.5 -207.5 ] concat
+
+Begin %I CBSpl
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg LtGray
+0.762951 0.762951 0.762951 SetCBg
+%I p
+0.5 SetP
+%I t
+[ 0.5 0 0 0.5 350 330.5 ] concat
+%I 12
+340 107
+340 123
+340 187
+340 203
+356 203
+468 203
+484 203
+484 187
+484 123
+484 107
+468 107
+356 107
+12 CBSpl
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 535.5 381 ] concat
+%I
+[
+(w_ptyfd)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 248.5 -23.5 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ -4.37114e-08 -1 1 -4.37114e-08 -608 640 ] concat
+
+Begin %I Poly
+none SetB %I b n
+%I cfg Black
+0 0 0 SetCFg
+%I cbg LtGray
+0.762951 0.762951 0.762951 SetCBg
+%I p
+0.5 SetP
+%I t
+[ 0.5 0 0 0.5 238 522.5 ] concat
+%I 4
+164 315
+228 315
+228 363
+164 363
+4 Poly
+End
+
+Begin %I Rect
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+233 363 241 387 Rect
+End
+
+Begin %I Line
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+225 387 225 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+217 387 217 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+233 363 201 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+201 387 233 387 Line
+%I 1
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 66.5 285 ] concat
+%I
+[
+(d_obuf)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 314 244.5 ] concat
+%I
+[
+(write\(\))
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+2 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg Black
+0 0 0 SetCBg
+none SetP %I p n
+%I t
+[ 0.5 0 0 0.5 216.5 124 ] concat
+%I 3
+272 281
+288 249
+272 201
+3 BSpl
+%I 2
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t u
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 -79.5 -207.5 ] concat
+
+Begin %I CBSpl
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg LtGray
+0.762951 0.762951 0.762951 SetCBg
+%I p
+0.5 SetP
+%I t
+[ 0.5 0 0 0.5 350 330.5 ] concat
+%I 12
+340 107
+340 123
+340 187
+340 203
+356 203
+468 203
+484 203
+484 187
+484 123
+484 107
+468 107
+356 107
+12 CBSpl
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 535.5 381 ] concat
+%I
+[
+(w_ptyfd)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 408.5 -23.5 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ -4.37114e-08 -1 1 -4.37114e-08 -608 640 ] concat
+
+Begin %I Poly
+none SetB %I b n
+%I cfg Black
+0 0 0 SetCFg
+%I cbg LtGray
+0.762951 0.762951 0.762951 SetCBg
+%I p
+0.5 SetP
+%I t
+[ 0.5 0 0 0.5 238 522.5 ] concat
+%I 4
+164 315
+228 315
+228 363
+164 363
+4 Poly
+End
+
+Begin %I Rect
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+233 363 241 387 Rect
+End
+
+Begin %I Line
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+225 387 225 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+217 387 217 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+233 363 201 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+201 387 233 387 Line
+%I 1
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 66.5 285 ] concat
+%I
+[
+(d_obuf)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 474 244.5 ] concat
+%I
+[
+(write\(\))
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+2 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg Black
+0 0 0 SetCBg
+none SetP %I p n
+%I t
+[ 0.5 0 0 0.5 376.5 124 ] concat
+%I 3
+272 281
+288 249
+272 201
+3 BSpl
+%I 2
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 289 540 ] concat
+%I
+[
+(WriteString\(\))
+] Text
+End
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 0 168 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 32 56 ] concat
+
+Begin %I Rect
+%I b 65535
+3 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg LtGray
+0.762951 0.762951 0.762951 SetCBg
+%I p
+0.5 SetP
+%I t
+[ 1 0 0 1 61 197 ] concat
+%I
+195 243 259 291 Rect
+End
+
+Begin %I Line
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 61 197 ] concat
+%I
+203 283 251 283 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 61 197 ] concat
+%I
+203 275 251 275 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 61 197 ] concat
+%I
+203 267 251 267 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 61 197 ] concat
+%I
+203 259 251 259 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+1 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 61 197 ] concat
+%I
+203 251 251 251 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 61 197 ] concat
+%I
+203 299 251 299 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 61 197 ] concat
+%I
+203 307 251 307 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 61 197 ] concat
+%I
+203 315 251 315 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 61 197 ] concat
+%I
+203 323 251 323 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 53 197 ] concat
+%I
+203 331 251 331 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 0.5 0 0 0.5 162 329 ] concat
+%I
+188 318 188 366 Line
+%I 2
+End
+
+Begin %I Line
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 0.5 0 0 0.5 162 329 ] concat
+%I
+316 318 316 366 Line
+%I 2
+End
+
+Begin %I BSpl
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 0.5 0 0 0.5 162 329 ] concat
+%I 3
+316 366
+316 398
+300 398
+3 BSpl
+%I 2
+End
+
+Begin %I BSpl
+%I b 65535
+0 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 0.5 0 0 0.5 162 329 ] concat
+%I 3
+188 366
+188 398
+172 398
+3 BSpl
+%I 2
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 296 492.5 ] concat
+%I
+[
+(w_image[])
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 312 567 ] concat
+%I
+[
+(\(CB8\))
+] Text
+End
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 1.52588e-05 16 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ -4.37114e-08 -1 1 -4.37114e-08 -567.5 808.5 ] concat
+
+Begin %I Poly
+none SetB %I b n
+%I cfg Black
+0 0 0 SetCFg
+%I cbg LtGray
+0.762951 0.762951 0.762951 SetCBg
+%I p
+0.5 SetP
+%I t
+[ 0.5 0 0 0.5 238 522.5 ] concat
+%I 4
+164 315
+228 315
+228 363
+164 363
+4 Poly
+End
+
+Begin %I Rect
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+233 363 241 387 Rect
+End
+
+Begin %I Line
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+225 387 225 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+217 387 217 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+233 363 201 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 111 317 ] concat
+%I
+201 387 233 387 Line
+%I 1
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 101 453.5 ] concat
+%I
+[
+(w_string)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t u
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t u
+
+Begin %I Poly
+none SetB %I b n
+%I cfg Black
+0 0 0 SetCFg
+%I cbg LtGray
+0.762951 0.762951 0.762951 SetCBg
+%I p
+0.5 SetP
+%I t
+[ 0.5 0 0 0.5 230 434.5 ] concat
+%I 4
+164 315
+228 315
+228 363
+164 363
+4 Poly
+End
+
+Begin %I Pict
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 -32 32 ] concat
+
+Begin %I Rect
+%I b 65535
+3 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 135 197.5 ] concat
+%I
+233 363 241 387 Rect
+End
+
+Begin %I Line
+%I b 65535
+3 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 135 197.5 ] concat
+%I
+225 387 225 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+3 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 135 197.5 ] concat
+%I
+217 387 217 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+3 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 135 197.5 ] concat
+%I
+233 363 201 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+3 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 135 197.5 ] concat
+%I
+201 387 233 387 Line
+%I 1
+End
+
+End %I eop
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 300.5 589 ] concat
+%I
+[
+(w_outbuf)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-times-bold-r-normal-*-14-*-*-*-*-*-*-*
+Times-Bold 14 SetF
+%I t
+[ 1 0 0 1 185 814 ] concat
+%I
+[
+(Window to display data flow in Screen)
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 4
+108 361
+60 361
+44 361
+44 345
+4 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 4
+148 361
+156 361
+172 361
+172 345
+4 BSpl
+%I 1
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 34 491 ] concat
+%I
+[
+(PrintFlush\(\))
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 7
+300 409
+276 409
+276 433
+276 457
+276 481
+300 481
+308 481
+7 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 4
+356 481
+380 481
+380 457
+380 449
+4 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 5
+220 505
+220 529
+220 553
+244 553
+252 553
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 6
+276 409
+252 409
+252 433
+252 529
+252 553
+284 553
+6 BSpl
+%I 1
+End
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 0 136 ] concat
+
+Begin %I CBSpl
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg LtGray
+0.762951 0.762951 0.762951 SetCBg
+%I p
+0.5 SetP
+%I t
+[ 0.5 0 0 0.5 350 330.5 ] concat
+%I 12
+340 107
+340 123
+340 187
+340 203
+356 203
+468 203
+484 203
+484 187
+484 123
+484 107
+468 107
+356 107
+12 CBSpl
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 535.5 381 ] concat
+%I
+[
+(w_ptyfd)
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 0 88 ] concat
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t u
+
+Begin %I Rect
+none SetB %I b n
+%I cfg Black
+0 0 0 SetCFg
+%I cbg LtGray
+0.762951 0.762951 0.762951 SetCBg
+%I p
+0.5 SetP
+%I t
+[ 0.5 -0 -0 0.5 380.5 362.5 ] concat
+%I
+71 123 135 171 Rect
+End
+
+Begin %I Pict
+%I b 65535
+2 0 0 [] 0 SetB
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 24 -136 ] concat
+
+Begin %I Rect
+%I b 65535
+3 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 135 197.5 ] concat
+%I
+257 363 265 387 Rect
+End
+
+Begin %I Line
+%I b 65535
+3 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 135 197.5 ] concat
+%I
+273 387 273 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+3 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 135 197.5 ] concat
+%I
+281 387 281 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+3 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 135 197.5 ] concat
+%I
+265 363 297 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65535
+3 0 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 135 197.5 ] concat
+%I
+265 387 297 387 Line
+%I 1
+End
+
+End %I eop
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 416.5 419 ] concat
+%I
+[
+(main:buf)
+] Text
+End
+
+End %I eop
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 464 538 ] concat
+%I
+[
+(read\(\))
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+2 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 -4 111 ] concat
+%I 3
+516 409
+484 417
+460 409
+3 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 7
+412 401
+396 401
+396 385
+396 361
+396 345
+412 345
+420 345
+7 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 3
+36 337
+36 305
+76 257
+3 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 3
+44 337
+52 297
+108 265
+3 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 3
+52 337
+68 297
+132 273
+3 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 3
+164 337
+164 321
+172 273
+3 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 3
+172 337
+172 321
+204 289
+3 BSpl
+%I 1
+End
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 0 104 ] concat
+
+Begin %I Rect
+none SetB %I b n
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I
+28 201 92 217 Rect
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 29.5 332 ] concat
+%I
+[
+(AddStrn\(\))
+] Text
+End
+
+End %I eop
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t u
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 471 481 ] concat
+%I
+[
+(write\(\))
+] Text
+End
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+none SetP %I p n
+%I t
+[ 1 0 0 1 0 -120 ] concat
+
+Begin %I CBSpl
+%I b 65520
+2 0 0 [12 4] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg LtGray
+0.762951 0.762951 0.762951 SetCBg
+%I p
+0.5 SetP
+%I t
+[ 0.5 0 0 0.5 350 482.5 ] concat
+%I 12
+340 107
+340 123
+340 187
+340 203
+356 203
+468 203
+484 203
+484 187
+484 123
+484 107
+468 107
+356 107
+12 CBSpl
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 511.5 533 ] concat
+%I
+[
+(w_pwin->p_ptyfd)
+] Text
+End
+
+End %I eop
+
+Begin %I BSpl
+%I b 65535
+1 1 0 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 3
+516 345
+492 353
+468 345
+3 BSpl
+%I 1
+End
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t u
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 391.5 445.5 ] concat
+%I
+[
+(w_pwin->p_inbuf)
+] Text
+End
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t u
+
+Begin %I Poly
+none SetB %I b n
+%I cfg Black
+0 0 0 SetCFg
+%I cbg LtGray
+0.762951 0.762951 0.762951 SetCBg
+none SetP %I p n
+%I t
+[ 0.5 0 0 0.5 342 290.5 ] concat
+%I 4
+164 315
+228 315
+228 363
+164 363
+4 Poly
+End
+
+Begin %I Rect
+%I b 65520
+2 0 0 [12 4] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 215 85.0002 ] concat
+%I
+233 363 241 387 Rect
+End
+
+Begin %I Line
+%I b 65520
+2 0 0 [12 4] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 215 85.0002 ] concat
+%I
+225 387 225 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65520
+2 0 0 [12 4] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 215 85.0002 ] concat
+%I
+233 363 201 363 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65520
+2 0 0 [12 4] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 0 0 1 215 85.0002 ] concat
+%I
+201 387 233 387 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65520
+2 0 0 [12 4] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 119 140 ] concat
+%I
+313 308 313 332 Line
+%I 1
+End
+
+End %I eop
+
+End %I eop
+
+End %I eop
+
+Begin %I Line
+%I b 65520
+0 0 0 [12 4] 0 SetB
+%I cfg LtGray
+0.762951 0.762951 0.762951 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -22 198.5 ] concat
+%I
+222 210 358 106 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65520
+0 0 0 [12 4] 0 SetB
+%I cfg LtGray
+0.762951 0.762951 0.762951 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -22 198.5 ] concat
+%I
+190 194 198 106 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65520
+0 0 0 [12 4] 0 SetB
+%I cfg LtGray
+0.762951 0.762951 0.762951 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -22 198.5 ] concat
+%I
+150 194 518 106 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65520
+0 0 0 [12 4] 0 SetB
+%I cfg LtGray
+0.762951 0.762951 0.762951 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -22 198.5 ] concat
+%I
+126 186 358 106 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65520
+0 0 0 [12 4] 0 SetB
+%I cfg LtGray
+0.762951 0.762951 0.762951 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -22 198.5 ] concat
+%I
+94 178 198 106 Line
+%I 1
+End
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t u
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 184 615 ] concat
+%I
+[
+(Special\(\))
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 127 ] concat
+%I 6
+220 505
+220 529
+196 529
+164 529
+140 529
+140 505
+6 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -22 198.5 ] concat
+%I 3
+166 425
+166 409
+198 378
+3 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -22 198.5 ] concat
+%I 3
+158 425
+158 410
+182 370
+3 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -22 198.5 ] concat
+%I 3
+150 425
+150 409
+158 362
+3 BSpl
+%I 1
+End
+
+End %I eop
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -22 198.5 ] concat
+%I 3
+198 257
+198 241
+254 210
+3 BSpl
+%I 1
+End
+
+Begin %I Pict
+%I b u
+%I cfg u
+%I cbg u
+%I f u
+%I p u
+%I t
+[ 1 0 0 1 120 48 ] concat
+
+Begin %I Rect
+none SetB %I b n
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+%I p
+1 SetP
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I
+28 257 108 273 Rect
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 28.5 388 ] concat
+%I
+[
+(MakeStatus\(\))
+] Text
+End
+
+End %I eop
+
+Begin %I Line
+%I b 65520
+0 0 0 [12 4] 0 SetB
+%I cfg LtGray
+0.762951 0.762951 0.762951 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -22 198.5 ] concat
+%I
+254 210 518 106 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65520
+0 0 0 [12 4] 0 SetB
+%I cfg LtGray
+0.762951 0.762951 0.762951 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -22 198.5 ] concat
+%I
+198 378 518 106 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65520
+0 0 0 [12 4] 0 SetB
+%I cfg LtGray
+0.762951 0.762951 0.762951 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -22 198.5 ] concat
+%I
+182 370 358 106 Line
+%I 1
+End
+
+Begin %I Line
+%I b 65520
+0 0 0 [12 4] 0 SetB
+%I cfg LtGray
+0.762951 0.762951 0.762951 SetCFg
+%I cbg Black
+0 0 0 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -22 198.5 ] concat
+%I
+158 362 198 106 Line
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+2 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 4
+268 337
+268 281
+180 241
+180 185
+4 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+2 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 0.5 -0 -0 0.5 197.5 193.5 ] concat
+%I 4
+181 525
+181 413
+277 333
+277 221
+4 BSpl
+%I 2
+End
+
+Begin %I BSpl
+%I b 65535
+2 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 4
+316 337
+316 281
+500 241
+500 185
+4 BSpl
+%I 1
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 0.587415 -0.809286 0.809286 0.587415 298.171 395.796 ] concat
+%I
+[
+(AddChar\(\))
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 0.810117 0.586269 -0.586269 0.810117 198.687 362.705 ] concat
+%I
+[
+(AddChar\(\))
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 0.954268 -0.298951 0.298951 0.954268 391.408 381.739 ] concat
+%I
+[
+(AddChar\(\))
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+2 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg Black
+0 0 0 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 5
+412 409
+308 409
+292 409
+292 393
+292 361
+5 BSpl
+%I 1
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 232.5 473.5 ] concat
+%I
+[
+(w_dlist->next->next...)
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 134 540 ] concat
+%I
+[
+(PrintChar\(\))
+] Text
+End
+
+Begin %I Text
+%I cfg Black
+0 0 0 SetCFg
+%I f -*-courier-medium-r-normal-*-10-*-*-*-*-*-*-*
+Courier 10 SetF
+%I t
+[ 1 0 0 1 139 525 ] concat
+%I
+[
+(SaveChar\(\))
+] Text
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg Black
+0 0 0 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 5
+412 409
+292 409
+148 409
+132 409
+132 393
+5 BSpl
+%I 1
+End
+
+Begin %I BSpl
+%I b 65535
+1 0 1 [] 0 SetB
+%I cfg Black
+0 0 0 SetCFg
+%I cbg White
+1 1 1 SetCBg
+none SetP %I p n
+%I t
+[ 1 -0 -0 1 -4 119 ] concat
+%I 4
+244 409
+220 409
+220 433
+220 481
+4 BSpl
+%I 1
+End
+
+End %I eop
+
+showpage
+
+%%Trailer
+
+end
diff --git a/encoding.c b/encoding.c
new file mode 100644
index 0000000..021369d
--- /dev/null
+++ b/encoding.c
@@ -0,0 +1,2134 @@
+/* Copyright (c) 1993-2003
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+
+#include "config.h"
+#include "screen.h"
+#include "extern.h"
+
+#ifdef ENCODINGS
+
+extern unsigned char *null;
+extern struct display *display, *displays;
+extern struct layer *flayer;
+
+extern char *screenencodings;
+
+#ifdef DW_CHARS
+extern int cjkwidth;
+#endif
+
+static int encmatch __P((char *, char *));
+# ifdef UTF8
+static int recode_char __P((int, int, int));
+static int recode_char_to_encoding __P((int, int));
+static void comb_tofront __P((int, int));
+# ifdef DW_CHARS
+static int recode_char_dw __P((int, int *, int, int));
+static int recode_char_dw_to_encoding __P((int, int *, int));
+# endif
+# endif
+
+struct encoding {
+ char *name;
+ char *charsets;
+ int deffont;
+ int usegr;
+ int noc1;
+ char *fontlist;
+};
+
+/* big5 font: ^X */
+/* KOI8-R font: 96 ! */
+/* CP1251 font: 96 ? */
+
+struct encoding encodings[] = {
+ { "C", 0, 0, 0, 0, 0 },
+ { "eucJP", "B\002I\00401", 0, 1, 0, "\002\004I" },
+ { "SJIS", "BIBB01", 0, 1, 1, "\002I" },
+ { "eucKR", "B\003BB01", 0, 1, 0, "\003" },
+ { "eucCN", "B\001BB01", 0, 1, 0, "\001" },
+ { "Big5", "B\030BB01", 0, 1, 0, "\030" },
+ { "KOI8-R", 0, 0x80|'!', 0, 1, 0 },
+ { "CP1251", 0, 0x80|'?', 0, 1, 0 },
+ { "UTF-8", 0, -1, 0, 0, 0 },
+ { "ISO8859-2", 0, 0x80|'B', 0, 0, 0 },
+ { "ISO8859-3", 0, 0x80|'C', 0, 0, 0 },
+ { "ISO8859-4", 0, 0x80|'D', 0, 0, 0 },
+ { "ISO8859-5", 0, 0x80|'L', 0, 0, 0 },
+ { "ISO8859-6", 0, 0x80|'G', 0, 0, 0 },
+ { "ISO8859-7", 0, 0x80|'F', 0, 0, 0 },
+ { "ISO8859-8", 0, 0x80|'H', 0, 0, 0 },
+ { "ISO8859-9", 0, 0x80|'M', 0, 0, 0 },
+ { "ISO8859-10", 0, 0x80|'V', 0, 0, 0 },
+ { "ISO8859-15", 0, 0x80|'b', 0, 0, 0 },
+ { "jis", 0, 0, 0, 0, "\002\004I" },
+ { "GBK", "B\031BB01", 0x80|'b', 1, 1, "\031" }
+};
+
+#ifdef UTF8
+
+static unsigned short builtin_tabs[][2] = {
+ { 0x30, 0 }, /* 0: special graphics (line drawing) */
+ { 0x005f, 0x25AE },
+ { 0x0060, 0x25C6 },
+ { 0x0061, 0x2592 },
+ { 0x0062, 0x2409 },
+ { 0x0063, 0x240C },
+ { 0x0064, 0x240D },
+ { 0x0065, 0x240A },
+ { 0x0066, 0x00B0 },
+ { 0x0067, 0x00B1 },
+ { 0x0068, 0x2424 },
+ { 0x0069, 0x240B },
+ { 0x006a, 0x2518 },
+ { 0x006b, 0x2510 },
+ { 0x006c, 0x250C },
+ { 0x006d, 0x2514 },
+ { 0x006e, 0x253C },
+ { 0x006f, 0x23BA },
+ { 0x0070, 0x23BB },
+ { 0x0071, 0x2500 },
+ { 0x0072, 0x23BC },
+ { 0x0073, 0x23BD },
+ { 0x0074, 0x251C },
+ { 0x0075, 0x2524 },
+ { 0x0076, 0x2534 },
+ { 0x0077, 0x252C },
+ { 0x0078, 0x2502 },
+ { 0x0079, 0x2264 },
+ { 0x007a, 0x2265 },
+ { 0x007b, 0x03C0 },
+ { 0x007c, 0x2260 },
+ { 0x007d, 0x00A3 },
+ { 0x007e, 0x00B7 },
+ { 0, 0},
+
+ { 0x34, 0 }, /* 4: Dutch */
+ { 0x0023, 0x00a3 },
+ { 0x0040, 0x00be },
+ { 0x005b, 0x00ff },
+ { 0x005c, 0x00bd },
+ { 0x005d, 0x007c },
+ { 0x007b, 0x00a8 },
+ { 0x007c, 0x0066 },
+ { 0x007d, 0x00bc },
+ { 0x007e, 0x00b4 },
+ { 0, 0},
+
+ { 0x35, 0 }, /* 5: Finnish */
+ { 0x005b, 0x00c4 },
+ { 0x005c, 0x00d6 },
+ { 0x005d, 0x00c5 },
+ { 0x005e, 0x00dc },
+ { 0x0060, 0x00e9 },
+ { 0x007b, 0x00e4 },
+ { 0x007c, 0x00f6 },
+ { 0x007d, 0x00e5 },
+ { 0x007e, 0x00fc },
+ { 0, 0},
+
+ { 0x36, 0 }, /* 6: Norwegian/Danish */
+ { 0x0040, 0x00c4 },
+ { 0x005b, 0x00c6 },
+ { 0x005c, 0x00d8 },
+ { 0x005d, 0x00c5 },
+ { 0x005e, 0x00dc },
+ { 0x0060, 0x00e4 },
+ { 0x007b, 0x00e6 },
+ { 0x007c, 0x00f8 },
+ { 0x007d, 0x00e5 },
+ { 0x007e, 0x00fc },
+ { 0, 0},
+
+ { 0x37, 0 }, /* 7: Swedish */
+ { 0x0040, 0x00c9 },
+ { 0x005b, 0x00c4 },
+ { 0x005c, 0x00d6 },
+ { 0x005d, 0x00c5 },
+ { 0x005e, 0x00dc },
+ { 0x0060, 0x00e9 },
+ { 0x007b, 0x00e4 },
+ { 0x007c, 0x00f6 },
+ { 0x007d, 0x00e5 },
+ { 0x007e, 0x00fc },
+ { 0, 0},
+
+ { 0x3d, 0}, /* =: Swiss */
+ { 0x0023, 0x00f9 },
+ { 0x0040, 0x00e0 },
+ { 0x005b, 0x00e9 },
+ { 0x005c, 0x00e7 },
+ { 0x005d, 0x00ea },
+ { 0x005e, 0x00ee },
+ { 0x005f, 0x00e8 },
+ { 0x0060, 0x00f4 },
+ { 0x007b, 0x00e4 },
+ { 0x007c, 0x00f6 },
+ { 0x007d, 0x00fc },
+ { 0x007e, 0x00fb },
+ { 0, 0},
+
+ { 0x41, 0}, /* A: UK */
+ { 0x0023, 0x00a3 },
+ { 0, 0},
+
+ { 0x4b, 0}, /* K: German */
+ { 0x0040, 0x00a7 },
+ { 0x005b, 0x00c4 },
+ { 0x005c, 0x00d6 },
+ { 0x005d, 0x00dc },
+ { 0x007b, 0x00e4 },
+ { 0x007c, 0x00f6 },
+ { 0x007d, 0x00fc },
+ { 0x007e, 0x00df },
+ { 0, 0},
+
+ { 0x51, 0}, /* Q: French Canadian */
+ { 0x0040, 0x00e0 },
+ { 0x005b, 0x00e2 },
+ { 0x005c, 0x00e7 },
+ { 0x005d, 0x00ea },
+ { 0x005e, 0x00ee },
+ { 0x0060, 0x00f4 },
+ { 0x007b, 0x00e9 },
+ { 0x007c, 0x00f9 },
+ { 0x007d, 0x00e8 },
+ { 0x007e, 0x00fb },
+ { 0, 0},
+
+ { 0x52, 0}, /* R: French */
+ { 0x0023, 0x00a3 },
+ { 0x0040, 0x00e0 },
+ { 0x005b, 0x00b0 },
+ { 0x005c, 0x00e7 },
+ { 0x005d, 0x00a7 },
+ { 0x007b, 0x00e9 },
+ { 0x007c, 0x00f9 },
+ { 0x007d, 0x00e8 },
+ { 0x007e, 0x00a8 },
+ { 0, 0},
+
+ { 0x59, 0}, /* Y: Italian */
+ { 0x0023, 0x00a3 },
+ { 0x0040, 0x00a7 },
+ { 0x005b, 0x00b0 },
+ { 0x005c, 0x00e7 },
+ { 0x005d, 0x00e9 },
+ { 0x0060, 0x00f9 },
+ { 0x007b, 0x00e0 },
+ { 0x007c, 0x00f2 },
+ { 0x007d, 0x00e8 },
+ { 0x007e, 0x00ec },
+ { 0, 0},
+
+ { 0x5a, 0}, /* Z: Spanish */
+ { 0x0023, 0x00a3 },
+ { 0x0040, 0x00a7 },
+ { 0x005b, 0x00a1 },
+ { 0x005c, 0x00d1 },
+ { 0x005d, 0x00bf },
+ { 0x007b, 0x00b0 },
+ { 0x007c, 0x00f1 },
+ { 0x007d, 0x00e7 },
+ { 0, 0},
+
+ { 0xe2, 0}, /* 96-b: ISO-8859-15 */
+ { 0x00a4, 0x20ac },
+ { 0x00a6, 0x0160 },
+ { 0x00a8, 0x0161 },
+ { 0x00b4, 0x017D },
+ { 0x00b8, 0x017E },
+ { 0x00bc, 0x0152 },
+ { 0x00bd, 0x0153 },
+ { 0x00be, 0x0178 },
+ { 0, 0},
+
+ { 0x4a, 0}, /* J: JIS 0201 Roman */
+ { 0x005c, 0x00a5 },
+ { 0x007e, 0x203e },
+ { 0, 0},
+
+ { 0x49, 0}, /* I: halfwidth katakana */
+ { 0x0021, 0xff61 },
+ { 0x005f|0x8000, 0xff9f },
+ { 0, 0},
+
+ { 0, 0}
+};
+
+struct recodetab
+{
+ unsigned short (*tab)[2];
+ int flags;
+};
+
+#define RECODETAB_ALLOCED 1
+#define RECODETAB_BUILTIN 2
+#define RECODETAB_TRIED 4
+
+static struct recodetab recodetabs[256];
+
+void
+InitBuiltinTabs()
+{
+ unsigned short (*p)[2];
+ for (p = builtin_tabs; (*p)[0]; p++)
+ {
+ recodetabs[(*p)[0]].flags = RECODETAB_BUILTIN;
+ recodetabs[(*p)[0]].tab = p + 1;
+ p++;
+ while((*p)[0])
+ p++;
+ }
+}
+
+static int
+recode_char(c, to_utf, font)
+int c, to_utf, font;
+{
+ int f;
+ unsigned short (*p)[2];
+
+ if (to_utf)
+ {
+ if (c < 256)
+ return c;
+ f = (c >> 8) & 0xff;
+ c &= 0xff;
+ /* map aliases to keep the table small */
+ switch (f)
+ {
+ case 'C':
+ f ^= ('C' ^ '5');
+ break;
+ case 'E':
+ f ^= ('E' ^ '6');
+ break;
+ case 'H':
+ f ^= ('H' ^ '7');
+ break;
+ default:
+ break;
+ }
+ p = recodetabs[f].tab;
+ if (p == 0 && recodetabs[f].flags == 0)
+ {
+ LoadFontTranslation(f, 0);
+ p = recodetabs[f].tab;
+ }
+ if (p)
+ for (; (*p)[0]; p++)
+ {
+ if ((p[0][0] & 0x8000) && (c <= (p[0][0] & 0x7fff)) && c >= p[-1][0])
+ return c - p[-1][0] + p[-1][1];
+ if ((*p)[0] == c)
+ return (*p)[1];
+ }
+ return c & 0xff; /* map to latin1 */
+ }
+ if (font == -1)
+ {
+ if (c < 256)
+ return c; /* latin1 */
+ for (font = 32; font < 128; font++)
+ {
+ p = recodetabs[font].tab;
+ if (p)
+ for (; (*p)[1]; p++)
+ {
+ if ((p[0][0] & 0x8000) && c <= p[0][1] && c >= p[-1][1])
+ return (c - p[-1][1] + p[-1][0]) | (font << 8);
+ if ((*p)[1] == c)
+ return (*p)[0] | (font << 8);
+ }
+ }
+ return '?';
+ }
+ if (c < 128 && (font & 128) != 0)
+ return c;
+ if (font >= 32)
+ {
+ p = recodetabs[font].tab;
+ if (p == 0 && recodetabs[font].flags == 0)
+ {
+ LoadFontTranslation(font, 0);
+ p = recodetabs[font].tab;
+ }
+ if (p)
+ for (; (*p)[1]; p++)
+ {
+ if ((p[0][0] & 0x8000) && c <= p[0][1] && c >= p[-1][1])
+ return (c - p[-1][1] + p[-1][0]) | (font & 128 ? 0 : font << 8);
+ if ((*p)[1] == c)
+ return (*p)[0] | (font & 128 ? 0 : font << 8);
+ }
+ }
+ return -1;
+}
+
+
+#ifdef DW_CHARS
+static int
+recode_char_dw(c, c2p, to_utf, font)
+int c, *c2p, to_utf, font;
+{
+ int f;
+ unsigned short (*p)[2];
+
+ if (to_utf)
+ {
+ f = (c >> 8) & 0xff;
+ c = (c & 255) << 8 | (*c2p & 255);
+ *c2p = 0xffff;
+ p = recodetabs[f].tab;
+ if (p == 0 && recodetabs[f].flags == 0)
+ {
+ LoadFontTranslation(f, 0);
+ p = recodetabs[f].tab;
+ }
+ if (p)
+ for (; (*p)[0]; p++)
+ if ((*p)[0] == c)
+ {
+#ifdef DW_CHARS
+ if (!utf8_isdouble((*p)[1]))
+ *c2p = ' ';
+#endif
+ return (*p)[1];
+ }
+ return UCS_REPL_DW;
+ }
+ if (font == -1)
+ {
+ for (font = 0; font < 030; font++)
+ {
+ p = recodetabs[font].tab;
+ if (p)
+ for (; (*p)[1]; p++)
+ if ((*p)[1] == c)
+ {
+ *c2p = ((*p)[0] & 255) | font << 8 | 0x8000;
+ return ((*p)[0] >> 8) | font << 8;
+ }
+ }
+ *c2p = '?';
+ return '?';
+ }
+ if (font < 32)
+ {
+ p = recodetabs[font].tab;
+ if (p == 0 && recodetabs[font].flags == 0)
+ {
+ LoadFontTranslation(font, 0);
+ p = recodetabs[font].tab;
+ }
+ if (p)
+ for (; (*p)[1]; p++)
+ if ((*p)[1] == c)
+ {
+ *c2p = ((*p)[0] & 255) | font << 8 | 0x8000;
+ return ((*p)[0] >> 8) | font << 8;
+ }
+ }
+ return -1;
+}
+#endif
+
+static int
+recode_char_to_encoding(c, encoding)
+int c, encoding;
+{
+ char *fp;
+ int x;
+
+ if (encoding == UTF8)
+ return recode_char(c, 1, -1);
+ if ((fp = encodings[encoding].fontlist) != 0)
+ while(*fp)
+ if ((x = recode_char(c, 0, (unsigned char)*fp++)) != -1)
+ return x;
+ if (encodings[encoding].deffont)
+ if ((x = recode_char(c, 0, encodings[encoding].deffont)) != -1)
+ return x;
+ return recode_char(c, 0, -1);
+}
+
+#ifdef DW_CHARS
+static int
+recode_char_dw_to_encoding(c, c2p, encoding)
+int c, *c2p, encoding;
+{
+ char *fp;
+ int x;
+
+ if (encoding == UTF8)
+ return recode_char_dw(c, c2p, 1, -1);
+ if ((fp = encodings[encoding].fontlist) != 0)
+ while(*fp)
+ if ((x = recode_char_dw(c, c2p, 0, (unsigned char)*fp++)) != -1)
+ return x;
+ if (encodings[encoding].deffont)
+ if ((x = recode_char_dw(c, c2p, 0, encodings[encoding].deffont)) != -1)
+ return x;
+ return recode_char_dw(c, c2p, 0, -1);
+}
+#endif
+
+
+struct mchar *
+recode_mchar(mc, from, to)
+struct mchar *mc;
+int from, to;
+{
+ static struct mchar rmc;
+ int c;
+
+ debug3("recode_mchar %02x from %d to %d\n", mc->image, from, to);
+ if (from == to || (from != UTF8 && to != UTF8))
+ return mc;
+ rmc = *mc;
+ if (rmc.font == 0 && from != UTF8)
+ rmc.font = encodings[from].deffont;
+ if (rmc.font == 0) /* latin1 is the same in unicode */
+ return mc;
+ c = rmc.image | (rmc.font << 8);
+ if (from == UTF8)
+ c |= rmc.fontx << 16;
+#ifdef DW_CHARS
+ if (rmc.mbcs)
+ {
+ int c2 = rmc.mbcs;
+ c = recode_char_dw_to_encoding(c, &c2, to);
+ rmc.mbcs = c2;
+ }
+ else
+#endif
+ c = recode_char_to_encoding(c, to);
+ rmc.image = c & 255;
+ rmc.font = c >> 8 & 255;
+ if (to == UTF8)
+ rmc.fontx = c >> 16 & 255;
+ return &rmc;
+}
+
+struct mline *
+recode_mline(ml, w, from, to)
+struct mline *ml;
+int w;
+int from, to;
+{
+ static int maxlen;
+ static int last;
+ static struct mline rml[2], *rl;
+ int i, c;
+
+ if (from == to || (from != UTF8 && to != UTF8) || w == 0)
+ return ml;
+ if (ml->font == null && ml->fontx == null && encodings[from].deffont == 0)
+ return ml;
+ if (w > maxlen)
+ {
+ for (i = 0; i < 2; i++)
+ {
+ if (rml[i].image == 0)
+ rml[i].image = malloc(w);
+ else
+ rml[i].image = realloc(rml[i].image, w);
+ if (rml[i].font == 0)
+ rml[i].font = malloc(w);
+ else
+ rml[i].font = realloc(rml[i].font, w);
+ if (rml[i].fontx == 0)
+ rml[i].fontx = malloc(w);
+ else
+ rml[i].fontx = realloc(rml[i].fontx, w);
+ if (rml[i].image == 0 || rml[i].font == 0 || rml[i].fontx == 0)
+ {
+ maxlen = 0;
+ return ml; /* sorry */
+ }
+ }
+ maxlen = w;
+ }
+
+ debug("recode_mline: from\n");
+ for (i = 0; i < w; i++)
+ debug1("%c", "0123456789abcdef"[(ml->image[i] >> 4) & 15]);
+ debug("\n");
+ for (i = 0; i < w; i++)
+ debug1("%c", "0123456789abcdef"[(ml->image[i] ) & 15]);
+ debug("\n");
+ for (i = 0; i < w; i++)
+ debug1("%c", "0123456789abcdef"[(ml->font[i] >> 4) & 15]);
+ debug("\n");
+ for (i = 0; i < w; i++)
+ debug1("%c", "0123456789abcdef"[(ml->font[i] ) & 15]);
+ debug("\n");
+ for (i = 0; i < w; i++)
+ debug1("%c", "0123456789abcdef"[(ml->fontx[i] >> 4) & 15]);
+ debug("\n");
+ for (i = 0; i < w; i++)
+ debug1("%c", "0123456789abcdef"[(ml->fontx[i] ) & 15]);
+ debug("\n");
+
+ rl = rml + last;
+ rl->attr = ml->attr;
+#ifdef COLOR
+ rl->color = ml->color;
+# ifdef COLORS256
+ rl->colorx = ml->colorx;
+# endif
+#endif
+ for (i = 0; i < w; i++)
+ {
+ c = ml->image[i] | (ml->font[i] << 8);
+ if (from == UTF8)
+ c |= ml->fontx[i] << 16;
+ if (from != UTF8 && c < 256)
+ c |= encodings[from].deffont << 8;
+#ifdef DW_CHARS
+ if ((from != UTF8 && (c & 0x1f00) != 0 && (c & 0xe000) == 0) || (from == UTF8 && utf8_isdouble(c)))
+ {
+ if (i + 1 == w)
+ c = '?';
+ else
+ {
+ int c2;
+ i++;
+ c2 = ml->image[i] | (ml->font[i] << 8);
+ c = recode_char_dw_to_encoding(c, &c2, to);
+ if (to == UTF8)
+ rl->fontx[i - 1] = c >> 16 & 255;
+ rl->font[i - 1] = c >> 8 & 255;
+ rl->image[i - 1] = c & 255;
+ c = c2;
+ }
+ }
+ else
+#endif
+ c = recode_char_to_encoding(c, to);
+ rl->image[i] = c & 255;
+ rl->font[i] = c >> 8 & 255;
+ if (to == UTF8)
+ rl->fontx[i] = c >> 16 & 255;
+ }
+ last ^= 1;
+ debug("recode_mline: to\n");
+ for (i = 0; i < w; i++)
+ debug1("%c", "0123456789abcdef"[(rl->image[i] >> 4) & 15]);
+ debug("\n");
+ for (i = 0; i < w; i++)
+ debug1("%c", "0123456789abcdef"[(rl->image[i] ) & 15]);
+ debug("\n");
+ for (i = 0; i < w; i++)
+ debug1("%c", "0123456789abcdef"[(rl->font[i] >> 4) & 15]);
+ debug("\n");
+ for (i = 0; i < w; i++)
+ debug1("%c", "0123456789abcdef"[(rl->font[i] ) & 15]);
+ debug("\n");
+ for (i = 0; i < w; i++)
+ debug1("%c", "0123456789abcdef"[(rl->fontx[i] >> 4) & 15]);
+ debug("\n");
+ for (i = 0; i < w; i++)
+ debug1("%c", "0123456789abcdef"[(rl->fontx[i] ) & 15]);
+ debug("\n");
+ return rl;
+}
+
+struct combchar {
+ unsigned int c1;
+ unsigned int c2;
+ unsigned int next;
+ unsigned int prev;
+};
+struct combchar **combchars;
+
+void
+AddUtf8(c)
+int c;
+{
+ ASSERT(D_encoding == UTF8);
+ if (c >= 0xd800 && c < 0xe000 && combchars && combchars[c - 0xd800])
+ {
+ AddUtf8(combchars[c - 0xd800]->c1);
+ c = combchars[c - 0xd800]->c2;
+ }
+ if (c >= 0x10000)
+ {
+ if (c >= 0x200000)
+ {
+ AddChar((c & 0x3000000) >> 12 ^ 0xf8);
+ c = (c & 0xffffff) ^ ((0xf0 ^ 0x80) << 18);
+ }
+ AddChar((c & 0x1fc0000) >> 18 ^ 0xf0);
+ c = (c & 0x3ffff) ^ ((0xe0 ^ 0x80) << 12);
+ }
+ if (c >= 0x800)
+ {
+ AddChar((c & 0x7f000) >> 12 ^ 0xe0);
+ c = (c & 0x0fff) ^ ((0xc0 ^ 0x80) << 6);
+ }
+ if (c >= 0x80)
+ {
+ AddChar((c & 0x1fc0) >> 6 ^ 0xc0);
+ c = (c & 0x3f) | 0x80;
+ }
+ AddChar(c);
+}
+
+int
+ToUtf8_comb(p, c)
+char *p;
+int c;
+{
+ int l;
+
+ if (c >= 0xd800 && c < 0xe000 && combchars && combchars[c - 0xd800])
+ {
+ l = ToUtf8_comb(p, combchars[c - 0xd800]->c1);
+ return l + ToUtf8(p ? p + l : 0, combchars[c - 0xd800]->c2);
+ }
+ return ToUtf8(p, c);
+}
+
+int
+ToUtf8(p, c)
+char *p;
+int c;
+{
+ int l = 1;
+ if (c >= 0x10000)
+ {
+ if (c >= 0x200000)
+ {
+ if (p)
+ *p++ = (c & 0x3000000) >> 12 ^ 0xf8;
+ l++;
+ c = (c & 0xffffff) ^ ((0xf0 ^ 0x80) << 18);
+ }
+ if (p)
+ *p++ = (c & 0x1fc0000) >> 18 ^ 0xf0;
+ l++;
+ c = (c & 0x3ffff) ^ ((0xe0 ^ 0x80) << 12);
+ }
+ if (c >= 0x800)
+ {
+ if (p)
+ *p++ = (c & 0x7f000) >> 12 ^ 0xe0;
+ l++;
+ c = (c & 0x0fff) | 0x1000;
+ }
+ if (c >= 0x80)
+ {
+ if (p)
+ *p++ = (c & 0x1fc0) >> 6 ^ 0xc0;
+ l++;
+ c = (c & 0x3f) | 0x80;
+ }
+ if (p)
+ *p++ = c;
+ return l;
+}
+
+/*
+ * returns:
+ * -1: need more bytes, sequence not finished
+ * -2: corrupt sequence found, redo last char
+ * >= 0: decoded character
+ */
+int
+FromUtf8(c, utf8charp)
+int c, *utf8charp;
+{
+ int utf8char = *utf8charp;
+ if (utf8char)
+ {
+ if ((c & 0xc0) != 0x80)
+ {
+ *utf8charp = 0;
+ return -2; /* corrupt sequence! */
+ }
+ else
+ c = (c & 0x3f) | (utf8char << 6);
+ if (!(utf8char & 0x40000000))
+ {
+ /* check for overlong sequences */
+ if ((c & 0x820823e0) == 0x80000000)
+ c = 0xfdffffff;
+ else if ((c & 0x020821f0) == 0x02000000)
+ c = 0xfff7ffff;
+ else if ((c & 0x000820f8) == 0x00080000)
+ c = 0xffffd000;
+ else if ((c & 0x0000207c) == 0x00002000)
+ c = 0xffffff70;
+ }
+ }
+ else
+ {
+ /* new sequence */
+ if (c >= 0xfe)
+ c = UCS_REPL;
+ else if (c >= 0xfc)
+ c = (c & 0x01) | 0xbffffffc; /* 5 bytes to follow */
+ else if (c >= 0xf8)
+ c = (c & 0x03) | 0xbfffff00; /* 4 */
+ else if (c >= 0xf0)
+ c = (c & 0x07) | 0xbfffc000; /* 3 */
+ else if (c >= 0xe0)
+ c = (c & 0x0f) | 0xbff00000; /* 2 */
+ else if (c >= 0xc2)
+ c = (c & 0x1f) | 0xfc000000; /* 1 */
+ else if (c >= 0xc0)
+ c = 0xfdffffff; /* overlong */
+ else if (c >= 0x80)
+ c = UCS_REPL;
+ }
+ *utf8charp = utf8char = (c & 0x80000000) ? c : 0;
+ if (utf8char)
+ return -1;
+#if 0
+ if (c & 0xffff0000)
+ c = UCS_REPL; /* sorry, only know 16bit Unicode */
+#else
+ if (c & 0xff800000)
+ c = UCS_REPL; /* sorry, only know 23bit Unicode */
+#endif
+ if (c >= 0xd800 && (c <= 0xdfff || c == 0xfffe || c == 0xffff))
+ c = UCS_REPL; /* illegal code */
+ return c;
+}
+
+
+void
+WinSwitchEncoding(p, encoding)
+struct win *p;
+int encoding;
+{
+ int i, j, c;
+ struct mline *ml;
+ struct display *d;
+ struct canvas *cv;
+ struct layer *oldflayer;
+
+ if ((p->w_encoding == UTF8) == (encoding == UTF8))
+ {
+ p->w_encoding = encoding;
+ return;
+ }
+ oldflayer = flayer;
+ for (d = displays; d; d = d->d_next)
+ for (cv = d->d_cvlist; cv; cv = cv->c_next)
+ if (p == Layer2Window(cv->c_layer))
+ {
+ flayer = cv->c_layer;
+ while(flayer->l_next)
+ {
+ if (oldflayer == flayer)
+ oldflayer = flayer->l_next;
+ ExitOverlayPage();
+ }
+ }
+ flayer = oldflayer;
+ for (j = 0; j < p->w_height + p->w_histheight; j++)
+ {
+#ifdef COPY_PASTE
+ ml = j < p->w_height ? &p->w_mlines[j] : &p->w_hlines[j - p->w_height];
+#else
+ ml = &p->w_mlines[j];
+#endif
+ if (ml->font == null && ml->fontx == 0 && encodings[p->w_encoding].deffont == 0)
+ continue;
+ for (i = 0; i < p->w_width; i++)
+ {
+ c = ml->image[i] | (ml->font[i] << 8);
+ if (p->w_encoding == UTF8)
+ c |= ml->fontx[i] << 16;
+ if (p->w_encoding != UTF8 && c < 256)
+ c |= encodings[p->w_encoding].deffont << 8;
+ if (c < 256)
+ continue;
+ if (ml->font == null)
+ {
+ if ((ml->font = (unsigned char *)calloc(p->w_width + 1, 1)) == 0)
+ {
+ ml->font = null;
+ break;
+ }
+ }
+#ifdef DW_CHARS
+ if ((p->w_encoding != UTF8 && (c & 0x1f00) != 0 && (c & 0xe000) == 0) || (p->w_encoding == UTF8 && utf8_isdouble(c)))
+ {
+ if (i + 1 == p->w_width)
+ c = '?';
+ else
+ {
+ int c2;
+ i++;
+ c2 = ml->image[i] | (ml->font[i] << 8) | (ml->fontx[i] << 16);
+ c = recode_char_dw_to_encoding(c, &c2, encoding);
+ if (encoding == UTF8)
+ {
+ if (c > 0x10000 && ml->fontx == null)
+ {
+ if ((ml->fontx = (unsigned char *)calloc(p->w_width + 1, 1)) == 0)
+ {
+ ml->fontx = null;
+ break;
+ }
+ }
+ ml->fontx[i - 1] = c >> 16 & 255;
+ }
+ else
+ ml->fontx = null;
+ ml->font[i - 1] = c >> 8 & 255;
+ ml->image[i - 1] = c & 255;
+ c = c2;
+ }
+ }
+ else
+#endif
+ c = recode_char_to_encoding(c, encoding);
+ ml->image[i] = c & 255;
+ ml->font[i] = c >> 8 & 255;
+ if (encoding == UTF8)
+ {
+ if (c > 0x10000 && ml->fontx == null)
+ {
+ if ((ml->fontx = (unsigned char *)calloc(p->w_width + 1, 1)) == 0)
+ {
+ ml->fontx = null;
+ break;
+ }
+ }
+ ml->fontx[i] = c >> 16 & 255;
+ }
+ else
+ ml->fontx = null;
+ }
+ }
+ p->w_encoding = encoding;
+ return;
+}
+
+#ifdef DW_CHARS
+struct interval {
+ int first;
+ int last;
+};
+
+/* auxiliary function for binary search in interval table */
+static int bisearch(int ucs, const struct interval *table, int max) {
+ int min = 0;
+ int mid;
+
+ if (ucs < table[0].first || ucs > table[max].last)
+ return 0;
+ while (max >= min) {
+ mid = (min + max) / 2;
+ if (ucs > table[mid].last)
+ min = mid + 1;
+ else if (ucs < table[mid].first)
+ max = mid - 1;
+ else
+ return 1;
+ }
+
+ return 0;
+}
+
+int
+utf8_isdouble(c)
+int c;
+{
+ /* A sorted list of intervals of ambiguous width characters generated by
+ * https://github.com/GNOME/glib/blob/glib-2-50/glib/gen-unicode-tables.pl */
+ static const struct interval ambiguous[] = {
+ {0x00A1, 0x00A1},
+ {0x00A4, 0x00A4},
+ {0x00A7, 0x00A8},
+ {0x00AA, 0x00AA},
+ {0x00AD, 0x00AE},
+ {0x00B0, 0x00B4},
+ {0x00B6, 0x00BA},
+ {0x00BC, 0x00BF},
+ {0x00C6, 0x00C6},
+ {0x00D0, 0x00D0},
+ {0x00D7, 0x00D8},
+ {0x00DE, 0x00E1},
+ {0x00E6, 0x00E6},
+ {0x00E8, 0x00EA},
+ {0x00EC, 0x00ED},
+ {0x00F0, 0x00F0},
+ {0x00F2, 0x00F3},
+ {0x00F7, 0x00FA},
+ {0x00FC, 0x00FC},
+ {0x00FE, 0x00FE},
+ {0x0101, 0x0101},
+ {0x0111, 0x0111},
+ {0x0113, 0x0113},
+ {0x011B, 0x011B},
+ {0x0126, 0x0127},
+ {0x012B, 0x012B},
+ {0x0131, 0x0133},
+ {0x0138, 0x0138},
+ {0x013F, 0x0142},
+ {0x0144, 0x0144},
+ {0x0148, 0x014B},
+ {0x014D, 0x014D},
+ {0x0152, 0x0153},
+ {0x0166, 0x0167},
+ {0x016B, 0x016B},
+ {0x01CE, 0x01CE},
+ {0x01D0, 0x01D0},
+ {0x01D2, 0x01D2},
+ {0x01D4, 0x01D4},
+ {0x01D6, 0x01D6},
+ {0x01D8, 0x01D8},
+ {0x01DA, 0x01DA},
+ {0x01DC, 0x01DC},
+ {0x0251, 0x0251},
+ {0x0261, 0x0261},
+ {0x02C4, 0x02C4},
+ {0x02C7, 0x02C7},
+ {0x02C9, 0x02CB},
+ {0x02CD, 0x02CD},
+ {0x02D0, 0x02D0},
+ {0x02D8, 0x02DB},
+ {0x02DD, 0x02DD},
+ {0x02DF, 0x02DF},
+ {0x0300, 0x036F},
+ {0x0391, 0x03A1},
+ {0x03A3, 0x03A9},
+ {0x03B1, 0x03C1},
+ {0x03C3, 0x03C9},
+ {0x0401, 0x0401},
+ {0x0410, 0x044F},
+ {0x0451, 0x0451},
+ {0x2010, 0x2010},
+ {0x2013, 0x2016},
+ {0x2018, 0x2019},
+ {0x201C, 0x201D},
+ {0x2020, 0x2022},
+ {0x2024, 0x2027},
+ {0x2030, 0x2030},
+ {0x2032, 0x2033},
+ {0x2035, 0x2035},
+ {0x203B, 0x203B},
+ {0x203E, 0x203E},
+ {0x2074, 0x2074},
+ {0x207F, 0x207F},
+ {0x2081, 0x2084},
+ {0x20AC, 0x20AC},
+ {0x2103, 0x2103},
+ {0x2105, 0x2105},
+ {0x2109, 0x2109},
+ {0x2113, 0x2113},
+ {0x2116, 0x2116},
+ {0x2121, 0x2122},
+ {0x2126, 0x2126},
+ {0x212B, 0x212B},
+ {0x2153, 0x2154},
+ {0x215B, 0x215E},
+ {0x2160, 0x216B},
+ {0x2170, 0x2179},
+ {0x2189, 0x2189},
+ {0x2190, 0x2199},
+ {0x21B8, 0x21B9},
+ {0x21D2, 0x21D2},
+ {0x21D4, 0x21D4},
+ {0x21E7, 0x21E7},
+ {0x2200, 0x2200},
+ {0x2202, 0x2203},
+ {0x2207, 0x2208},
+ {0x220B, 0x220B},
+ {0x220F, 0x220F},
+ {0x2211, 0x2211},
+ {0x2215, 0x2215},
+ {0x221A, 0x221A},
+ {0x221D, 0x2220},
+ {0x2223, 0x2223},
+ {0x2225, 0x2225},
+ {0x2227, 0x222C},
+ {0x222E, 0x222E},
+ {0x2234, 0x2237},
+ {0x223C, 0x223D},
+ {0x2248, 0x2248},
+ {0x224C, 0x224C},
+ {0x2252, 0x2252},
+ {0x2260, 0x2261},
+ {0x2264, 0x2267},
+ {0x226A, 0x226B},
+ {0x226E, 0x226F},
+ {0x2282, 0x2283},
+ {0x2286, 0x2287},
+ {0x2295, 0x2295},
+ {0x2299, 0x2299},
+ {0x22A5, 0x22A5},
+ {0x22BF, 0x22BF},
+ {0x2312, 0x2312},
+ {0x2460, 0x24E9},
+ {0x24EB, 0x254B},
+ {0x2550, 0x2573},
+ {0x2580, 0x258F},
+ {0x2592, 0x2595},
+ {0x25A0, 0x25A1},
+ {0x25A3, 0x25A9},
+ {0x25B2, 0x25B3},
+ {0x25B6, 0x25B7},
+ {0x25BC, 0x25BD},
+ {0x25C0, 0x25C1},
+ {0x25C6, 0x25C8},
+ {0x25CB, 0x25CB},
+ {0x25CE, 0x25D1},
+ {0x25E2, 0x25E5},
+ {0x25EF, 0x25EF},
+ {0x2605, 0x2606},
+ {0x2609, 0x2609},
+ {0x260E, 0x260F},
+ {0x261C, 0x261C},
+ {0x261E, 0x261E},
+ {0x2640, 0x2640},
+ {0x2642, 0x2642},
+ {0x2660, 0x2661},
+ {0x2663, 0x2665},
+ {0x2667, 0x266A},
+ {0x266C, 0x266D},
+ {0x266F, 0x266F},
+ {0x269E, 0x269F},
+ {0x26BF, 0x26BF},
+ {0x26C6, 0x26CD},
+ {0x26CF, 0x26D3},
+ {0x26D5, 0x26E1},
+ {0x26E3, 0x26E3},
+ {0x26E8, 0x26E9},
+ {0x26EB, 0x26F1},
+ {0x26F4, 0x26F4},
+ {0x26F6, 0x26F9},
+ {0x26FB, 0x26FC},
+ {0x26FE, 0x26FF},
+ {0x273D, 0x273D},
+ {0x2776, 0x277F},
+ {0x2B56, 0x2B59},
+ {0x3248, 0x324F},
+ {0xE000, 0xF8FF},
+ {0xFE00, 0xFE0F},
+ {0xFFFD, 0xFFFD},
+ {0x1F100, 0x1F10A},
+ {0x1F110, 0x1F12D},
+ {0x1F130, 0x1F169},
+ {0x1F170, 0x1F18D},
+ {0x1F18F, 0x1F190},
+ {0x1F19B, 0x1F1AC},
+ {0xE0100, 0xE01EF},
+ {0xF0000, 0xFFFFD},
+ {0x100000, 0x10FFFD},
+ };
+ /* A sorted list of intervals of double width characters generated by
+ * https://github.com/GNOME/glib/blob/glib-2-50/glib/gen-unicode-tables.pl */
+ static const struct interval wide[] = {
+ {0x1100, 0x115F},
+ {0x231A, 0x231B},
+ {0x2329, 0x232A},
+ {0x23E9, 0x23EC},
+ {0x23F0, 0x23F0},
+ {0x23F3, 0x23F3},
+ {0x25FD, 0x25FE},
+ {0x2614, 0x2615},
+ {0x2648, 0x2653},
+ {0x267F, 0x267F},
+ {0x2693, 0x2693},
+ {0x26A1, 0x26A1},
+ {0x26AA, 0x26AB},
+ {0x26BD, 0x26BE},
+ {0x26C4, 0x26C5},
+ {0x26CE, 0x26CE},
+ {0x26D4, 0x26D4},
+ {0x26EA, 0x26EA},
+ {0x26F2, 0x26F3},
+ {0x26F5, 0x26F5},
+ {0x26FA, 0x26FA},
+ {0x26FD, 0x26FD},
+ {0x2705, 0x2705},
+ {0x270A, 0x270B},
+ {0x2728, 0x2728},
+ {0x274C, 0x274C},
+ {0x274E, 0x274E},
+ {0x2753, 0x2755},
+ {0x2757, 0x2757},
+ {0x2795, 0x2797},
+ {0x27B0, 0x27B0},
+ {0x27BF, 0x27BF},
+ {0x2B1B, 0x2B1C},
+ {0x2B50, 0x2B50},
+ {0x2B55, 0x2B55},
+ {0x2E80, 0x2E99},
+ {0x2E9B, 0x2EF3},
+ {0x2F00, 0x2FD5},
+ {0x2FF0, 0x2FFB},
+ {0x3000, 0x303E},
+ {0x3041, 0x3096},
+ {0x3099, 0x30FF},
+ {0x3105, 0x312D},
+ {0x3131, 0x318E},
+ {0x3190, 0x31BA},
+ {0x31C0, 0x31E3},
+ {0x31F0, 0x321E},
+ {0x3220, 0x3247},
+ {0x3250, 0x32FE},
+ {0x3300, 0x4DBF},
+ {0x4E00, 0xA48C},
+ {0xA490, 0xA4C6},
+ {0xA960, 0xA97C},
+ {0xAC00, 0xD7A3},
+ {0xF900, 0xFAFF},
+ {0xFE10, 0xFE19},
+ {0xFE30, 0xFE52},
+ {0xFE54, 0xFE66},
+ {0xFE68, 0xFE6B},
+ {0xFF01, 0xFF60},
+ {0xFFE0, 0xFFE6},
+ {0x16FE0, 0x16FE0},
+ {0x17000, 0x187EC},
+ {0x18800, 0x18AF2},
+ {0x1B000, 0x1B001},
+ {0x1F004, 0x1F004},
+ {0x1F0CF, 0x1F0CF},
+ {0x1F18E, 0x1F18E},
+ {0x1F191, 0x1F19A},
+ {0x1F200, 0x1F202},
+ {0x1F210, 0x1F23B},
+ {0x1F240, 0x1F248},
+ {0x1F250, 0x1F251},
+ {0x1F300, 0x1F320},
+ {0x1F32D, 0x1F335},
+ {0x1F337, 0x1F37C},
+ {0x1F37E, 0x1F393},
+ {0x1F3A0, 0x1F3CA},
+ {0x1F3CF, 0x1F3D3},
+ {0x1F3E0, 0x1F3F0},
+ {0x1F3F4, 0x1F3F4},
+ {0x1F3F8, 0x1F43E},
+ {0x1F440, 0x1F440},
+ {0x1F442, 0x1F4FC},
+ {0x1F4FF, 0x1F53D},
+ {0x1F54B, 0x1F54E},
+ {0x1F550, 0x1F567},
+ {0x1F57A, 0x1F57A},
+ {0x1F595, 0x1F596},
+ {0x1F5A4, 0x1F5A4},
+ {0x1F5FB, 0x1F64F},
+ {0x1F680, 0x1F6C5},
+ {0x1F6CC, 0x1F6CC},
+ {0x1F6D0, 0x1F6D2},
+ {0x1F6EB, 0x1F6EC},
+ {0x1F6F4, 0x1F6F6},
+ {0x1F910, 0x1F91E},
+ {0x1F920, 0x1F927},
+ {0x1F930, 0x1F930},
+ {0x1F933, 0x1F93E},
+ {0x1F940, 0x1F94B},
+ {0x1F950, 0x1F95E},
+ {0x1F980, 0x1F991},
+ {0x1F9C0, 0x1F9C0},
+ {0x20000, 0x2FFFD},
+ {0x30000, 0x3FFFD},
+ };
+
+ return ((bisearch(c, wide, sizeof(wide) / sizeof(struct interval) - 1)) ||
+ (cjkwidth &&
+ bisearch(c, ambiguous,
+ sizeof(ambiguous) / sizeof(struct interval) - 1)));
+}
+#endif
+
+int
+utf8_iscomb(c)
+int c;
+{
+ /* taken from Markus Kuhn's wcwidth */
+ static const struct interval combining[] = {
+ { 0x0300, 0x036F }, { 0x0483, 0x0486 }, { 0x0488, 0x0489 },
+ { 0x0591, 0x05BD }, { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 },
+ { 0x05C4, 0x05C5 }, { 0x05C7, 0x05C7 }, { 0x0600, 0x0603 },
+ { 0x0610, 0x0615 }, { 0x064B, 0x065E }, { 0x0670, 0x0670 },
+ { 0x06D6, 0x06E4 }, { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED },
+ { 0x070F, 0x070F }, { 0x0711, 0x0711 }, { 0x0730, 0x074A },
+ { 0x07A6, 0x07B0 }, { 0x07EB, 0x07F3 }, { 0x0901, 0x0902 },
+ { 0x093C, 0x093C }, { 0x0941, 0x0948 }, { 0x094D, 0x094D },
+ { 0x0951, 0x0954 }, { 0x0962, 0x0963 }, { 0x0981, 0x0981 },
+ { 0x09BC, 0x09BC }, { 0x09C1, 0x09C4 }, { 0x09CD, 0x09CD },
+ { 0x09E2, 0x09E3 }, { 0x0A01, 0x0A02 }, { 0x0A3C, 0x0A3C },
+ { 0x0A41, 0x0A42 }, { 0x0A47, 0x0A48 }, { 0x0A4B, 0x0A4D },
+ { 0x0A70, 0x0A71 }, { 0x0A81, 0x0A82 }, { 0x0ABC, 0x0ABC },
+ { 0x0AC1, 0x0AC5 }, { 0x0AC7, 0x0AC8 }, { 0x0ACD, 0x0ACD },
+ { 0x0AE2, 0x0AE3 }, { 0x0B01, 0x0B01 }, { 0x0B3C, 0x0B3C },
+ { 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B43 }, { 0x0B4D, 0x0B4D },
+ { 0x0B56, 0x0B56 }, { 0x0B82, 0x0B82 }, { 0x0BC0, 0x0BC0 },
+ { 0x0BCD, 0x0BCD }, { 0x0C3E, 0x0C40 }, { 0x0C46, 0x0C48 },
+ { 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 }, { 0x0CBC, 0x0CBC },
+ { 0x0CBF, 0x0CBF }, { 0x0CC6, 0x0CC6 }, { 0x0CCC, 0x0CCD },
+ { 0x0CE2, 0x0CE3 }, { 0x0D41, 0x0D43 }, { 0x0D4D, 0x0D4D },
+ { 0x0DCA, 0x0DCA }, { 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 },
+ { 0x0E31, 0x0E31 }, { 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E },
+ { 0x0EB1, 0x0EB1 }, { 0x0EB4, 0x0EB9 }, { 0x0EBB, 0x0EBC },
+ { 0x0EC8, 0x0ECD }, { 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 },
+ { 0x0F37, 0x0F37 }, { 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E },
+ { 0x0F80, 0x0F84 }, { 0x0F86, 0x0F87 }, { 0x0F90, 0x0F97 },
+ { 0x0F99, 0x0FBC }, { 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 },
+ { 0x1032, 0x1032 }, { 0x1036, 0x1037 }, { 0x1039, 0x1039 },
+ { 0x1058, 0x1059 }, { 0x1160, 0x11FF }, { 0x135F, 0x135F },
+ { 0x1712, 0x1714 }, { 0x1732, 0x1734 }, { 0x1752, 0x1753 },
+ { 0x1772, 0x1773 }, { 0x17B4, 0x17B5 }, { 0x17B7, 0x17BD },
+ { 0x17C6, 0x17C6 }, { 0x17C9, 0x17D3 }, { 0x17DD, 0x17DD },
+ { 0x180B, 0x180D }, { 0x18A9, 0x18A9 }, { 0x1920, 0x1922 },
+ { 0x1927, 0x1928 }, { 0x1932, 0x1932 }, { 0x1939, 0x193B },
+ { 0x1A17, 0x1A18 }, { 0x1B00, 0x1B03 }, { 0x1B34, 0x1B34 },
+ { 0x1B36, 0x1B3A }, { 0x1B3C, 0x1B3C }, { 0x1B42, 0x1B42 },
+ { 0x1B6B, 0x1B73 }, { 0x1DC0, 0x1DCA }, { 0x1DFE, 0x1DFF },
+ { 0x200B, 0x200F }, { 0x202A, 0x202E }, { 0x2060, 0x2063 },
+ { 0x206A, 0x206F }, { 0x20D0, 0x20EF }, { 0x302A, 0x302F },
+ { 0x3099, 0x309A }, { 0xA806, 0xA806 }, { 0xA80B, 0xA80B },
+ { 0xA825, 0xA826 }, { 0xFB1E, 0xFB1E }, { 0xFE00, 0xFE0F },
+ { 0xFE20, 0xFE23 }, { 0xFEFF, 0xFEFF }, { 0xFFF9, 0xFFFB },
+ { 0x10A01, 0x10A03 }, { 0x10A05, 0x10A06 }, { 0x10A0C, 0x10A0F },
+ { 0x10A38, 0x10A3A }, { 0x10A3F, 0x10A3F }, { 0x1D167, 0x1D169 },
+ { 0x1D173, 0x1D182 }, { 0x1D185, 0x1D18B }, { 0x1D1AA, 0x1D1AD },
+ { 0x1D242, 0x1D244 }, { 0xE0001, 0xE0001 }, { 0xE0020, 0xE007F },
+ { 0xE0100, 0xE01EF }
+ };
+
+ return bisearch(c, combining, sizeof(combining) / sizeof(struct interval) - 1);
+}
+
+static void
+comb_tofront(root, i)
+int root, i;
+{
+ for (;;)
+ {
+ debug1("bring to front: %x\n", i);
+ combchars[combchars[i]->prev]->next = combchars[i]->next;
+ combchars[combchars[i]->next]->prev = combchars[i]->prev;
+ combchars[i]->next = combchars[root]->next;
+ combchars[i]->prev = root;
+ combchars[combchars[root]->next]->prev = i;
+ combchars[root]->next = i;
+ i = combchars[i]->c1;
+ if (i < 0xd800 || i >= 0xe000)
+ return;
+ i -= 0xd800;
+ }
+}
+
+void
+utf8_handle_comb(c, mc)
+int c;
+struct mchar *mc;
+{
+ int root, i, c1;
+ int isdouble;
+
+ c1 = mc->image | (mc->font << 8) | mc->fontx << 16;
+ isdouble = c1 >= 0x1100 && utf8_isdouble(c1);
+ if (!combchars)
+ {
+ combchars = (struct combchar **)calloc(0x802, sizeof(struct combchar *));
+ if (!combchars)
+ return;
+ combchars[0x800] = (struct combchar *)malloc(sizeof(struct combchar));
+ combchars[0x801] = (struct combchar *)malloc(sizeof(struct combchar));
+ if (!combchars[0x800] || !combchars[0x801])
+ {
+ if (combchars[0x800])
+ free(combchars[0x800]);
+ if (combchars[0x801])
+ free(combchars[0x801]);
+ free(combchars);
+ return;
+ }
+ combchars[0x800]->c1 = 0x000;
+ combchars[0x800]->c2 = 0x700;
+ combchars[0x800]->next = 0x800;
+ combchars[0x800]->prev = 0x800;
+ combchars[0x801]->c1 = 0x700;
+ combchars[0x801]->c2 = 0x800;
+ combchars[0x801]->next = 0x801;
+ combchars[0x801]->prev = 0x801;
+ }
+ root = isdouble ? 0x801 : 0x800;
+ for (i = combchars[root]->c1; i < combchars[root]->c2; i++)
+ {
+ if (!combchars[i])
+ break;
+ if (combchars[i]->c1 == c1 && combchars[i]->c2 == c)
+ break;
+ }
+ if (i == combchars[root]->c2)
+ {
+ /* full, recycle old entry */
+ if (c1 >= 0xd800 && c1 < 0xe000)
+ comb_tofront(root, c1 - 0xd800);
+ i = combchars[root]->prev;
+ if (c1 == i + 0xd800)
+ {
+ /* completely full, can't recycle */
+ debug("utf8_handle_comp: completely full!\n");
+ mc->image = '?';
+ mc->font = 0;
+ return;
+ }
+ /* FIXME: delete old char from all buffers */
+ }
+ else if (!combchars[i])
+ {
+ combchars[i] = (struct combchar *)malloc(sizeof(struct combchar));
+ if (!combchars[i])
+ return;
+ combchars[i]->prev = i;
+ combchars[i]->next = i;
+ }
+ combchars[i]->c1 = c1;
+ combchars[i]->c2 = c;
+ mc->image = i & 0xff;
+ mc->font = (i >> 8) + 0xd8;
+ mc->fontx = 0;
+ debug3("combinig char %x %x -> %x\n", c1, c, i + 0xd800);
+ comb_tofront(root, i);
+}
+
+#else /* !UTF8 */
+
+void
+WinSwitchEncoding(p, encoding)
+struct win *p;
+int encoding;
+{
+ p->w_encoding = encoding;
+ return;
+}
+
+#endif /* UTF8 */
+
+static int
+encmatch(s1, s2)
+char *s1;
+char *s2;
+{
+ int c1, c2;
+ do
+ {
+ c1 = (unsigned char)*s1;
+ if (c1 >= 'A' && c1 <= 'Z')
+ c1 += 'a' - 'A';
+ if (!(c1 >= 'a' && c1 <= 'z') && !(c1 >= '0' && c1 <= '9'))
+ {
+ s1++;
+ continue;
+ }
+ c2 = (unsigned char)*s2;
+ if (c2 >= 'A' && c2 <= 'Z')
+ c2 += 'a' - 'A';
+ if (!(c2 >= 'a' && c2 <= 'z') && !(c2 >= '0' && c2 <= '9'))
+ {
+ s2++;
+ continue;
+ }
+ if (c1 != c2)
+ return 0;
+ s1++;
+ s2++;
+ }
+ while(c1);
+ return 1;
+}
+
+int
+FindEncoding(name)
+char *name;
+{
+ int encoding;
+
+ debug1("FindEncoding %s\n", name);
+ if (name == 0 || *name == 0)
+ return 0;
+ if (encmatch(name, "euc"))
+ name = "eucJP";
+ if (encmatch(name, "off") || encmatch(name, "iso8859-1"))
+ return 0;
+#ifndef UTF8
+ if (encmatch(name, "UTF-8"))
+ return -1;
+#endif
+ for (encoding = 0; encoding < (int)(sizeof(encodings)/sizeof(*encodings)); encoding++)
+ if (encmatch(name, encodings[encoding].name))
+ {
+#ifdef UTF8
+ LoadFontTranslationsForEncoding(encoding);
+#endif
+ return encoding;
+ }
+ return -1;
+}
+
+char *
+EncodingName(encoding)
+int encoding;
+{
+ if (encoding >= (int)(sizeof(encodings)/sizeof(*encodings)))
+ return 0;
+ return encodings[encoding].name;
+}
+
+int
+EncodingDefFont(encoding)
+int encoding;
+{
+ return encodings[encoding].deffont;
+}
+
+void
+ResetEncoding(p)
+struct win *p;
+{
+ char *c;
+ int encoding = p->w_encoding;
+
+ c = encodings[encoding].charsets;
+ if (c)
+ SetCharsets(p, c);
+#ifdef UTF8
+ LoadFontTranslationsForEncoding(encoding);
+#endif
+ if (encodings[encoding].usegr)
+ {
+ p->w_gr = 2;
+ p->w_FontE = encodings[encoding].charsets[1];
+ }
+ else
+ p->w_FontE = 0;
+ if (encodings[encoding].noc1)
+ p->w_c1 = 0;
+}
+
+/* decoded char: 32-bit <fontx><font><c2><c>
+ * fontx: non-bmp utf8
+ * c2: multi-byte character
+ * font is always zero for utf8
+ * returns: -1 need more bytes
+ * -2 decode error
+ */
+
+
+int
+DecodeChar(c, encoding, statep)
+int c;
+int encoding;
+int *statep;
+{
+ int t;
+
+ debug2("Decoding char %02x for encoding %d\n", c, encoding);
+#ifdef UTF8
+ if (encoding == UTF8)
+ {
+ c = FromUtf8(c, statep);
+ if (c >= 0x10000)
+ c = (c & 0x7f0000) << 8 | (c & 0xffff);
+ return c;
+ }
+#endif
+ if (encoding == SJIS)
+ {
+ if (!*statep)
+ {
+ if ((0x81 <= c && c <= 0x9f) || (0xe0 <= c && c <= 0xef))
+ {
+ *statep = c;
+ return -1;
+ }
+ if (c < 0x80)
+ return c;
+ return c | (KANA << 16);
+ }
+ t = c;
+ c = *statep;
+ *statep = 0;
+ if (0x40 <= t && t <= 0xfc && t != 0x7f)
+ {
+ if (c <= 0x9f)
+ c = (c - 0x81) * 2 + 0x21;
+ else
+ c = (c - 0xc1) * 2 + 0x21;
+ if (t <= 0x7e)
+ t -= 0x1f;
+ else if (t <= 0x9e)
+ t -= 0x20;
+ else
+ t -= 0x7e, c++;
+ return (c << 8) | t | (KANJI << 16);
+ }
+ return t;
+ }
+ if (encoding == EUC_JP || encoding == EUC_KR || encoding == EUC_CN)
+ {
+ if (!*statep)
+ {
+ if (c & 0x80)
+ {
+ *statep = c;
+ return -1;
+ }
+ return c;
+ }
+ t = c;
+ c = *statep;
+ *statep = 0;
+ if (encoding == EUC_JP)
+ {
+ if (c == 0x8e)
+ return t | (KANA << 16);
+ if (c == 0x8f)
+ {
+ *statep = t | (KANJI0212 << 8);
+ return -1;
+ }
+ }
+ c &= 0xff7f;
+ t &= 0x7f;
+ c = c << 8 | t;
+ if (encoding == EUC_KR)
+ return c | (3 << 16);
+ if (encoding == EUC_CN)
+ return c | (1 << 16);
+ if (c & (KANJI0212 << 16))
+ return c;
+ else
+ return c | (KANJI << 16);
+ }
+ if (encoding == BIG5 || encoding == GBK)
+ {
+ if (!*statep)
+ {
+ if (c & 0x80)
+ {
+ if (encoding == GBK && c == 0x80)
+ return 0xa4 | (('b'|0x80) << 16);
+ *statep = c;
+ return -1;
+ }
+ return c;
+ }
+ t = c;
+ c = *statep;
+ *statep = 0;
+ c &= 0x7f;
+ return c << 8 | t | (encoding == BIG5 ? 030 << 16 : 031 << 16);
+ }
+ return c | (encodings[encoding].deffont << 16);
+}
+
+int
+EncodeChar(bp, c, encoding, fontp)
+char *bp;
+int c;
+int encoding;
+int *fontp;
+{
+ int t, f, l;
+
+ debug2("Encoding char %02x for encoding %d\n", c, encoding);
+ if (c == -1 && fontp)
+ {
+ if (*fontp == 0)
+ return 0;
+ if (bp)
+ {
+ *bp++ = 033;
+ *bp++ = '(';
+ *bp++ = 'B';
+ }
+ return 3;
+ }
+ f = (c >> 16) & 0xff;
+
+#ifdef UTF8
+ if (encoding == UTF8)
+ {
+ if (f)
+ {
+# ifdef DW_CHARS
+ if (is_dw_font(f))
+ {
+ int c2 = c & 0xff;
+ c = (c >> 8 & 0xff) | (f << 8);
+ c = recode_char_dw_to_encoding(c, &c2, encoding);
+ }
+ else
+# endif
+ {
+ c = (c & 0xff) | (f << 8);
+ c = recode_char_to_encoding(c, encoding);
+ }
+ }
+ return ToUtf8(bp, c);
+ }
+ if (f == 0 && (c & 0x7f00ff00) != 0) /* is_utf8? */
+ {
+ if (c >= 0x10000)
+ c = (c & 0x7f0000) >> 8 | (c & 0xffff);
+# ifdef DW_CHARS
+ if (utf8_isdouble(c))
+ {
+ int c2 = 0xffff;
+ c = recode_char_dw_to_encoding(c, &c2, encoding);
+ c = (c << 8) | (c2 & 0xff);
+ }
+ else
+# endif
+ {
+ c = recode_char_to_encoding(c, encoding);
+ c = ((c & 0xff00) << 8) | (c & 0xff);
+ }
+ debug1("Encode: char mapped from utf8 to %x\n", c);
+ f = c >> 16;
+ }
+#endif
+ if (f & 0x80) /* map special 96-fonts to latin1 */
+ f = 0;
+
+ if (encoding == SJIS)
+ {
+ if (f == KANA)
+ c = (c & 0xff) | 0x80;
+ else if (f == KANJI)
+ {
+ if (!bp)
+ return 2;
+ t = c & 0xff;
+ c = (c >> 8) & 0xff;
+ t += (c & 1) ? ((t <= 0x5f) ? 0x1f : 0x20) : 0x7e;
+ c = (c - 0x21) / 2 + ((c < 0x5f) ? 0x81 : 0xc1);
+ *bp++ = c;
+ *bp++ = t;
+ return 2;
+ }
+ }
+ if (encoding == EUC)
+ {
+ if (f == KANA)
+ {
+ if (bp)
+ {
+ *bp++ = 0x8e;
+ *bp++ = c;
+ }
+ return 2;
+ }
+ if (f == KANJI)
+ {
+ if (bp)
+ {
+ *bp++ = (c >> 8) | 0x80;
+ *bp++ = c | 0x80;
+ }
+ return 2;
+ }
+ if (f == KANJI0212)
+ {
+ if (bp)
+ {
+ *bp++ = 0x8f;
+ *bp++ = c >> 8;
+ *bp++ = c;
+ }
+ return 3;
+ }
+ }
+ if ((encoding == EUC_KR && f == 3) || (encoding == EUC_CN && f == 1))
+ {
+ if (bp)
+ {
+ *bp++ = (c >> 8) | 0x80;
+ *bp++ = c | 0x80;
+ }
+ return 2;
+ }
+ if ((encoding == BIG5 && f == 030) || (encoding == GBK && f == 031))
+ {
+ if (bp)
+ {
+ *bp++ = (c >> 8) | 0x80;
+ *bp++ = c;
+ }
+ return 2;
+ }
+ if (encoding == GBK && f == 0 && c == 0xa4)
+ c = 0x80;
+
+ l = 0;
+ if (fontp && f != *fontp)
+ {
+ *fontp = f;
+ if (f && f < ' ')
+ {
+ if (bp)
+ {
+ *bp++ = 033;
+ *bp++ = '$';
+ if (f > 2)
+ *bp++ = '(';
+ *bp++ = '@' + f;
+ }
+ l += f > 2 ? 4 : 3;
+ }
+ else if (f < 128)
+ {
+ if (f == 0)
+ f = 'B';
+ if (bp)
+ {
+ *bp++ = 033;
+ *bp++ = '(';
+ *bp++ = f;
+ }
+ l += 3;
+ }
+ }
+ if (c & 0xff00)
+ {
+ if (bp)
+ *bp++ = c >> 8;
+ l++;
+ }
+ if (bp)
+ *bp++ = c;
+ return l + 1;
+}
+
+int
+CanEncodeFont(encoding, f)
+int encoding, f;
+{
+ switch(encoding)
+ {
+#ifdef UTF8
+ case UTF8:
+ return 1;
+#endif
+ case SJIS:
+ return f == KANJI || f == KANA;
+ case EUC:
+ return f == KANJI || f == KANA || f == KANJI0212;
+ case EUC_KR:
+ return f == 3;
+ case EUC_CN:
+ return f == 1;
+ case BIG5:
+ return f == 030;
+ case GBK:
+ return f == 031;
+ default:
+ break;
+ }
+ return 0;
+}
+
+#ifdef DW_CHARS
+int
+PrepareEncodedChar(c)
+int c;
+{
+ int encoding;
+ int t = 0;
+ int f;
+
+ encoding = D_encoding;
+ f = D_rend.font;
+ t = D_mbcs;
+ if (encoding == SJIS)
+ {
+ if (f == KANA)
+ return c | 0x80;
+ else if (f == KANJI)
+ {
+ t += (c & 1) ? ((t <= 0x5f) ? 0x1f : 0x20) : 0x7e;
+ c = (c - 0x21) / 2 + ((c < 0x5f) ? 0x81 : 0xc1);
+ D_mbcs = t;
+ }
+ return c;
+ }
+ if (encoding == EUC)
+ {
+ if (f == KANA)
+ {
+ AddChar(0x8e);
+ return c | 0x80;
+ }
+ if (f == KANJI)
+ {
+ D_mbcs = t | 0x80;
+ return c | 0x80;
+ }
+ if (f == KANJI0212)
+ {
+ AddChar(0x8f);
+ D_mbcs = t | 0x80;
+ return c | 0x80;
+ }
+ }
+ if ((encoding == EUC_KR && f == 3) || (encoding == EUC_CN && f == 1))
+ {
+ D_mbcs = t | 0x80;
+ return c | 0x80;
+ }
+ if ((encoding == BIG5 && f == 030) || (encoding == GBK && f == 031))
+ return c | 0x80;
+ return c;
+}
+#endif
+
+int
+RecodeBuf(fbuf, flen, fenc, tenc, tbuf)
+unsigned char *fbuf;
+int flen;
+int fenc, tenc;
+unsigned char *tbuf;
+{
+ int c, i, j;
+ int decstate = 0, font = 0;
+
+ for (i = j = 0; i < flen; i++)
+ {
+ c = fbuf[i];
+ c = DecodeChar(c, fenc, &decstate);
+ if (c == -2)
+ i--;
+ if (c < 0)
+ continue;
+ j += EncodeChar(tbuf ? (char *)tbuf + j : 0, c, tenc, &font);
+ }
+ j += EncodeChar(tbuf ? (char *)tbuf + j : 0, -1, tenc, &font);
+ return j;
+}
+
+#ifdef UTF8
+int
+ContainsSpecialDeffont(ml, xs, xe, encoding)
+struct mline *ml;
+int xs, xe;
+int encoding;
+{
+ unsigned char *f, *i;
+ int c, x, dx;
+
+ if (encoding == UTF8 || encodings[encoding].deffont == 0)
+ return 0;
+ i = ml->image + xs;
+ f = ml->font + xs;
+ dx = xe - xs + 1;
+ while (dx-- > 0)
+ {
+ if (*f++)
+ continue;
+ c = *i++;
+ x = recode_char_to_encoding(c | (encodings[encoding].deffont << 8), UTF8);
+ if (c != x)
+ {
+ debug2("ContainsSpecialDeffont: yes %02x != %02x\n", c, x);
+ return 1;
+ }
+ }
+ debug("ContainsSpecialDeffont: no\n");
+ return 0;
+}
+
+
+int
+LoadFontTranslation(font, file)
+int font;
+char *file;
+{
+ char buf[1024], *myfile;
+ FILE *f;
+ int i;
+ int fo;
+ int x, u, c, ok;
+ unsigned short (*p)[2], (*tab)[2];
+
+ myfile = file;
+ if (myfile == 0)
+ {
+ if (font == 0 || screenencodings == 0)
+ return -1;
+ if (strlen(screenencodings) > sizeof(buf) - 10)
+ return -1;
+ sprintf(buf, "%s/%02x", screenencodings, font & 0xff);
+ myfile = buf;
+ }
+ debug1("LoadFontTranslation: trying %s\n", myfile);
+ if ((f = secfopen(myfile, "r")) == 0)
+ return -1;
+ i = ok = 0;
+ for (;;)
+ {
+ for(; i < 12; i++)
+ if (getc(f) != "ScreenI2UTF8"[i])
+ break;
+ if (getc(f) != 0) /* format */
+ break;
+ fo = getc(f); /* id */
+ if (fo == EOF)
+ break;
+ if (font != -1 && font != fo)
+ break;
+ i = getc(f);
+ x = getc(f);
+ if (x == EOF)
+ break;
+ i = i << 8 | x;
+ getc(f);
+ while ((x = getc(f)) && x != EOF)
+ getc(f); /* skip font name (padded to 2 bytes) */
+ if ((p = malloc(sizeof(*p) * (i + 1))) == 0)
+ break;
+ tab = p;
+ while(i > 0)
+ {
+ x = getc(f);
+ x = x << 8 | getc(f);
+ u = getc(f);
+ c = getc(f);
+ u = u << 8 | c;
+ if (c == EOF)
+ break;
+ (*p)[0] = x;
+ (*p)[1] = u;
+ p++;
+ i--;
+ }
+ (*p)[0] = 0;
+ (*p)[1] = 0;
+ if (i || (tab[0][0] & 0x8000))
+ {
+ free(tab);
+ break;
+ }
+ if (recodetabs[fo].tab && (recodetabs[fo].flags & RECODETAB_ALLOCED) != 0)
+ free(recodetabs[fo].tab);
+ recodetabs[fo].tab = tab;
+ recodetabs[fo].flags = RECODETAB_ALLOCED;
+ debug1("Successful load of recodetab %02x\n", fo);
+ c = getc(f);
+ if (c == EOF)
+ {
+ ok = 1;
+ break;
+ }
+ if (c != 'S')
+ break;
+ i = 1;
+ }
+ fclose(f);
+ if (font != -1 && file == 0 && recodetabs[font].flags == 0)
+ recodetabs[font].flags = RECODETAB_TRIED;
+ return ok ? 0 : -1;
+}
+
+void
+LoadFontTranslationsForEncoding(encoding)
+int encoding;
+{
+ char *c;
+ int f;
+
+ debug1("LoadFontTranslationsForEncoding: encoding %d\n", encoding);
+ if ((c = encodings[encoding].fontlist) != 0)
+ while ((f = (unsigned char)*c++) != 0)
+ if (recodetabs[f].flags == 0)
+ LoadFontTranslation(f, 0);
+ f = encodings[encoding].deffont;
+ if (f > 0 && recodetabs[f].flags == 0)
+ LoadFontTranslation(f, 0);
+}
+
+#endif /* UTF8 */
+
+#else /* !ENCODINGS */
+
+/* Simple version of EncodeChar to encode font changes for
+ * copy/paste mode
+ */
+int
+EncodeChar(bp, c, encoding, fontp)
+char *bp;
+int c;
+int encoding;
+int *fontp;
+{
+ int f, l;
+ f = (c == -1) ? 0 : c >> 16;
+ l = 0;
+ if (fontp && f != *fontp)
+ {
+ *fontp = f;
+ if (f && f < ' ')
+ {
+ if (bp)
+ {
+ *bp++ = 033;
+ *bp++ = '$';
+ if (f > 2)
+ *bp++ = '(';
+ *bp++ = '@' + f;
+ }
+ l += f > 2 ? 4 : 3;
+ }
+ else if (f < 128)
+ {
+ if (f == 0)
+ f = 'B';
+ if (bp)
+ {
+ *bp++ = 033;
+ *bp++ = '(';
+ *bp++ = f;
+ }
+ l += 3;
+ }
+ }
+ if (c == -1)
+ return l;
+ if (c & 0xff00)
+ {
+ if (bp)
+ *bp++ = c >> 8;
+ l++;
+ }
+ if (bp)
+ *bp++ = c;
+ return l + 1;
+}
+
+#endif /* ENCODINGS */
diff --git a/etc/ccdefs b/etc/ccdefs
new file mode 100755
index 0000000..2fc98ff
--- /dev/null
+++ b/etc/ccdefs
@@ -0,0 +1,46 @@
+#!/bin/sh
+cd /tmp
+umask 022
+
+CC=cc
+CPP=cpp
+PATH="$PATH:/lib"
+
+TEMP=def$$
+trap 'rm -f ${TEMP}*; trap 0; exit' 0 1 2 3 15
+
+set `type $CC`
+q=$#
+set x `type $CC`
+shift $q
+cc=$1
+
+set `type $CPP`
+q=$#
+set x `type $CPP`
+shift $q
+cpp=$1
+
+strings - "$cc" 2>/dev/null | tr ' ' '\012' > ${TEMP}.x
+
+if test -x "$cpp"; then
+strings - "$cpp" 2>/dev/null | tr ' ' '\012' >> ${TEMP}.x
+else
+echo "Warning: cpp not found."
+fi
+
+sort < ${TEMP}.x | uniq | awk '
+/^-D[A-Za-z_][A-Za-z_0-9]*$/ {
+ printf("#ifdef %s\n", substr($0,3))
+ printf("\"%s\": %s\n", substr($0,3), substr($0,3))
+ print "#endif"
+ }
+/^[A-Za-z_][A-Za-z_0-9]*$/ {
+ printf("#ifdef %s\n", $0)
+ printf("\"%s\": %s\n", $0, $0)
+ print "#endif"
+ }
+' > ${TEMP}.c
+
+echo "Defines in cc are:"
+cc -E ${TEMP}.c | sed -n -e 's/"\([^:]*\)":/\1:/p' | sort | uniq
diff --git a/etc/completer.zsh b/etc/completer.zsh
new file mode 100644
index 0000000..b5acaa3
--- /dev/null
+++ b/etc/completer.zsh
@@ -0,0 +1,53 @@
+#compdef screen
+#Generated by
+# help2simple.pl -c screen -p -f
+# simple2long.xsl
+# args.xsl
+# For details see:
+# http://www.geocities.com/f_rosencrantz/xml_completion.htm
+
+ local context state line
+ typeset -A opt_args
+ _arguments \
+ "-a[Force all capabilities into each window's termcap.]" \
+ '-A:Adapt all windows to the new display width & height.' \
+ "-c:Read configuration file instead of '.screenrc'.:_files -/" \
+ '-d:Detach the elsewhere running screen (with -r: reattach here).:->sessionname' \
+ '-dmS:Start as daemon: Screen session in detached mode.' \
+ '-D:Detach and logout remote (with -r: reattach here).' \
+ '-e:Change command characters.' \
+ '-f-:Flow control on, -fn = off, -fa = auto.:((n\:Flow\ conrol\ off a\:Flow\ conrol\ auto))' \
+ '-h:Set the size of the scrollback history buffer.' \
+ '-i[Interrupt output sooner when flow control is on.]' \
+ '-l[Login mode on (update /var/run/utmp), -ln = off.]' \
+ '-list[Do nothing, just list our SockDir.]' \
+ '-ls[Do nothing, just list our SockDir.]' \
+ "-L[Terminal's last character can be safely updated.]" \
+ '-m[ignore $STY variable, do create a new screen session.]' \
+ '-O[Choose optimal output rather than exact vt100 emulation.]' \
+ '-p:Preselect the named window if it exists.' \
+ '-q[Quiet startup. Exits with non-zero return code if unsuccessful.]' \
+ '-r[Reattach to a detached screen process.]:Handling Tag sessionname:->sessionname' \
+ '-R[Reattach if possible, otherwise start a new session.]' \
+ '-s:Shell to execute rather than $SHELL.' \
+ '-S:Name this session <pid>.sockname instead of <pid>.<tty>.<host>.' \
+ "-t:Set title. (window's name)." \
+ '-T:Use term as $TERM for windows, rather than "screen".' \
+ '-U[Tell screen to use UTF-8 encoding.]' \
+ '-v[Print "Screen version 3.09.11beta (FAU) 11-Oct-01".]' \
+ '-wipe[Do nothing, just clean up SockDir.]' \
+ '-x[Attach to a not detached screen. (Multi display mode).]' \
+ '-X[Execute <cmd> as a screen command in the specified session.]:Handling Tag screencmd:( acladd addacl aclchg acldel aclgrp aclumask activity allpartial at attrcolor autodetach autonuke bce bell_msg bind bindkey break breaktype bufferfile c1 caption charset chdir clear colon command compacthist console copy copy_reg crlf debug defc1 defautonuke defbce defbreaktype defcharset defescape defflow defgr defhstatus defkanji deflogin defmode defmonitor defobuflimit defscrollback defshell defsilence defslowpaste defutf8 defwrap defwritelock detach dinfo displays digraph dumptermcap echo escape exec fit flow focus gr hardcopy hardcopy_append hardcopydir hardstatus height help history hstatus info ins_reg kill lastmsg license lockscreen log logfile login logtstamp mapdefault mapnotnext maptimeout markkeys meta monitor msgminwait msgwait multiuser nethack next nonblock number obu!
+!
+flimit only other partial password paste pastefont pow_break pow_detach pow_detach_msg prev printcmd process quit readbuf readreg redisplay register remove removebuf reset resize screen scrollback select sessionname setenv shell shelltitle silence silencewait sleep slowpaste sorendition split startup_message stuff su term termcap terminfo termcapinfo time title unsetenv utf8 vbell vbell_msg vbellwait verbose version wall width windows wrap writebuf writelock xoff xon zombie)'
+case $state in
+ "sessionname")
+ # Complete folder names.
+ local screendir
+
+ screendir=(`screen -ls | grep Socket | sed -n -e 's/\.$//' -e '$p' | awk '{print $NF;}'`)
+
+ _wanted files expl 'screen process' _path_files -W screendir
+;;
+esac
+
diff --git a/etc/countmail b/etc/countmail
new file mode 100755
index 0000000..974f143
--- /dev/null
+++ b/etc/countmail
@@ -0,0 +1,67 @@
+#!/usr/bin/perl
+
+sub countmsgs {
+ return -1 unless open(M, "<$mbox");
+ my $inhdr = 0;
+ my $cl = undef;
+ my $msgread = 0;
+ my $count = 0;
+ while(<M>) {
+ if (!$inhdr && /^From\s+\S+\s+(?i:sun|mon|tue|wed|thu|fri|sat)\s+(?i:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\s+\d+\s/) {
+ $inhdr = 1;
+ $msgread = 0;
+ undef $cl;
+ next;
+ }
+ if ($inhdr) {
+ if (/^content-length:\s+(\d+)/i) {
+ $cl = 0+$1;
+ next;
+ }
+ if (/^status:\s+(\S)/i) {
+ $msgread = 1 unless $1 eq 'N' || $1 eq 'U';
+ next;
+ }
+ if ($_ eq "\n") {
+ $count++ if !$msgread;
+ seek(M, $cl, 1) if defined $cl;
+ $inhdr = 0;
+ }
+ }
+ }
+ close M;
+ return $count;
+}
+
+$| = 1;
+$mbox = $ARGV[0] || $ENV{'MAIL'};
+$oldfmt = $ARGV[1] || "%4d ";
+$newfmt = $ARGV[2] || "\005{Rk}%4d \005{-}";
+
+@oldstat = stat($mbox);
+if (!@oldstat) {
+ print "\005{Rk} ??? \005{-}\n";
+ exit 1;
+}
+$oldcount = 0;
+while(1) {
+ $count = countmsgs($mbox);
+ if ($count == -1) {
+ print "\005{Rk} ??? \005{-}\n";
+ } elsif ($count < $oldcount || $count == 0) {
+ printf "$oldfmt\n", $count;
+ } else {
+ printf "$newfmt\n", $count;
+ }
+ $oldcount = $count;
+ while (1) {
+ @newstat = stat($mbox);
+ if (!@newstat) {
+ print "\005{Rk} ??? \005{-}\n";
+ exit 1;
+ }
+ last if $newstat[7] != $oldstat[7] || $newstat[9] != $oldstat[9];
+ sleep 1;
+ }
+ @oldstat = @newstat;
+}
diff --git a/etc/etcscreenrc b/etc/etcscreenrc
new file mode 100644
index 0000000..a51d64a
--- /dev/null
+++ b/etc/etcscreenrc
@@ -0,0 +1,94 @@
+#
+# This is an example for the global screenrc file.
+# You may want to install this file as /usr/local/etc/screenrc.
+# Check config.h for the exact location.
+#
+# Flaws of termcap and standard settings are done here.
+#
+
+#startup_message off
+
+#defflow on # will force screen to process ^S/^Q
+
+deflogin on
+#autodetach off
+
+vbell on
+vbell_msg " Wuff ---- Wuff!! "
+
+# all termcap entries are now duplicated as terminfo entries.
+# only difference should be the slightly modified syntax, and check for
+# terminfo entries, that are already corected in the database.
+#
+# G0 we have a SEMI-GRAPHICS-CHARACTER-MODE
+# WS this sequence resizes our window.
+# cs this sequence changes the scrollregion
+# hs@ we have no hardware statusline. screen will only believe that
+# there is a hardware status line if hs,ts,fs,ds are all set.
+# ts to statusline
+# fs from statusline
+# ds delete statusline
+# al add one line
+# AL add multiple lines
+# dl delete one line
+# DL delete multiple lines
+# ic insert one char (space)
+# IC insert multiple chars
+# nx terminal uses xon/xoff
+
+termcap facit|vt100|xterm LP:G0
+terminfo facit|vt100|xterm LP:G0
+
+#the vt100 description does not mention "dl". *sigh*
+termcap vt100 dl=5\E[M
+terminfo vt100 dl=5\E[M
+
+#facit's "al" / "dl" are buggy if the current / last line
+#contain attributes...
+termcap facit al=\E[L\E[K:AL@:dl@:DL@:cs=\E[%i%d;%dr:ic@
+terminfo facit al=\E[L\E[K:AL@:dl@:DL@:cs=\E[%i%p1%d;%p2%dr:ic@
+
+#make sun termcap/info better
+termcap sun 'up=^K:AL=\E[%dL:DL=\E[%dM:UP=\E[%dA:DO=\E[%dB:LE=\E[%dD:RI=\E[%dC:IC=\E[%d@:WS=1000\E[8;%d;%dt'
+terminfo sun 'up=^K:AL=\E[%p1%dL:DL=\E[%p1%dM:UP=\E[%p1%dA:DO=\E[%p1%dB:LE=\E[%p1%dD:RI=\E[%p1%dC:IC=\E[%p1%d@:WS=\E[8;%p1%d;%p2%dt$<1000>'
+
+#xterm understands both im/ic and doesn't have a status line.
+#Note: Do not specify im and ic in the real termcap/info file as
+#some programs (e.g. vi) will (no,no, may (jw)) not work anymore.
+termcap xterm|fptwist hs@:cs=\E[%i%d;%dr:im=\E[4h:ei=\E[4l
+terminfo xterm|fptwist hs@:cs=\E[%i%p1%d;%p2%dr:im=\E[4h:ei=\E[4l
+
+# Long time I had this in my private screenrc file. But many people
+# seem to want it (jw):
+# we do not want the width to change to 80 characters on startup:
+# on suns, /etc/termcap has :is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;3;4;6l:
+termcap xterm 'is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l'
+terminfo xterm 'is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l'
+
+#
+# Do not use xterms alternate window buffer.
+# This one would not add lines to the scrollback buffer.
+termcap xterm|xterms|xs ti=\E7\E[?47l
+terminfo xterm|xterms|xs ti=\E7\E[?47l
+
+#make hp700 termcap/info better
+termcap hp700 'Z0=\E[?3h:Z1=\E[?3l:hs:ts=\E[62"p\E[0$~\E[2$~\E[1$}:fs=\E[0}\E[61"p:ds=\E[62"p\E[1$~\E[61"p:ic@'
+terminfo hp700 'Z0=\E[?3h:Z1=\E[?3l:hs:ts=\E[62"p\E[0$~\E[2$~\E[1$}:fs=\E[0}\E[61"p:ds=\E[62"p\E[1$~\E[61"p:ic@'
+
+#wyse-75-42 must have defflow control (xo = "terminal uses xon/xoff")
+#(nowadays: nx = padding doesn't work, have to use xon/off)
+#essential to have it here, as this is a slow terminal.
+termcap wy75-42 nx:xo:Z0=\E[?3h\E[31h:Z1=\E[?3l\E[31h
+terminfo wy75-42 nx:xo:Z0=\E[?3h\E[31h:Z1=\E[?3l\E[31h
+
+#remove some stupid / dangerous key bindings
+bind ^k
+#bind L
+bind ^\
+#make them better
+bind \\ quit
+bind K kill
+bind I login on
+bind O login off
+bind } history
+
diff --git a/etc/gr-braille.tbl b/etc/gr-braille.tbl
new file mode 100644
index 0000000..34407b7
--- /dev/null
+++ b/etc/gr-braille.tbl
@@ -0,0 +1,260 @@
+# GERMAN BRAILLE TABLE
+#
+# Dec Hex Braille Description
+# ------------------------------------------------------------------------
+ 0 00 (--345--8) NUL
+ 1 01 (1------8) SOH
+ 2 02 (12-----8) STX
+ 3 03 (1--4---8) ETX
+ 4 04 (1--45--8) EOT
+ 5 05 (1---5--8) ENQ
+ 6 06 (12-4---8) ACK
+ 7 07 (12-45--8) BEL
+ 8 08 (12--5--8) BS
+ 9 09 (-2-4---8) HT
+ 10 OA (-2-45--8) LF
+ 11 0B (1-3----8) VT
+ 12 OC (123----8) FF
+ 13 0D (1-34---8) CR
+ 14 0E (1-345--8) SO
+ 15 OF (1-3-5--8) SI
+ 16 10 (1234---8) DLE
+ 17 11 (12345--8) DC1
+ 18 12 (123-5--8) DC2
+ 19 13 (-234---8) DC3
+ 20 14 (-2345--8) DC4
+ 21 15 (1-3--6-8) NAK
+ 22 16 (123--6-8) SYN
+ 23 17 (-2-456-8) ETB
+ 24 18 (1-34-6-8) CAN
+ 25 19 (1-3456-8) EM
+ 26 1A (1-3-56-8) SUB
+ 27 lB (123-56-8) ESC
+ 28 lC (--34---8) FS
+ 29 1D (-23456-8) GS
+ 30 lE (-234-6-8) RS
+ 31 1F (---456-8) US
+ 32 20 (--------) Space
+ 33 21 (----5---) !
+ 34 22 (---4----) "
+ 35 23 (--3456--) #
+ 36 24 (---4-6--) $
+ 37 25 (123456--) %
+ 38 26 (1234-6--) &
+ 39 27 (-----6--) '
+ 40 28 (-23--6--) (
+ 41 29 (--3-56--) )
+ 42 2A (--3-5---) *
+ 43 2B (-23-5---) +
+ 44 2C (-2------) ,
+ 45 2D (--3--6--) -
+ 46 2E (--3-----) .
+ 47 2F (-2--56--) /
+ 48 30 (--34-6--) 0
+ 49 31 (1----6--) 1
+ 50 32 (12---6--) 2
+ 51 33 (1--4-6--) 3
+ 52 34 (1--456--) 4
+ 53 35 (1---56--) 5
+ 54 36 (12-4-6--) 6
+ 55 37 (12-456--) 7
+ 56 38 (12--56--) 8
+ 57 39 (-2-4-6--) 9
+ 58 3A (-2--5---) :
+ 59 3B (-23-----) ;
+ 60 3C (----56--) <
+ 61 3D (-23-56--)
+ 62 3E (---45---) >
+ 63 3F (-2---6--) ?
+ 64 40 (--345---) Special sign
+ 65 41 (1-----7-) A
+ 66 42 (12----7-) B
+ 67 43 (1--4--7-) C
+ 68 44 (1--45-7-) D
+ 69 45 (1---5-7-) E
+ 70 46 (12-4--7-) F
+ 71 47 (12-45-7-) G
+ 72 48 (12--5-7-) H
+ 73 49 (-2-4--7-) I
+ 74 4A (-2-45-7-) j
+ 75 4B (1-3---7-) K
+ 76 4C (123---7-) L
+ 77 4D (1-34--7-) M
+ 78 4E (1-345-7-) N
+ 79 4F (1-3-5-7-) O
+ 80 50 (1234--7-) P
+ 81 51 (12345-7-) Q
+ 82 52 (123-5-7-) R
+ 83 53 (-234--7-) S
+ 84 54 (-2345-7-) T
+ 85 55 (1-3--67-) U
+ 86 56 (123--67-) V
+ 87 57 (-2-4567-) W
+ 88 58 (1-34-67-) X
+ 89 59 (1-34567-) Y
+ 90 5A (1-3-567-) Z
+ 91 5B (123-567-) [ or A umlaut
+ 92 5C (--34--7-) \ or umlaut O
+ 93 5D (-234567-) ] or umlaut U
+ 94 5E (-234-67-) ^ or tilde
+ 95 5F (---456--) _
+ 96 60 (--345--8) '
+ 97 61 (1-------) a
+ 98 62 (12------) b
+ 99 63 (1--4----) c
+ 100 64 (1--45---) d
+ 101 65 (1---5---) e
+ 102 66 (12-4----) f
+ 103 67 (12-45---) g
+ 104 68 (12--5---) h
+ 105 69 (-2-4----) i
+ 106 6A (-2-45---) j
+ 107 6B (1-3-----) k
+ 108 6C (123-----) l
+ 109 6D (1-34----) m
+ 110 6E (1-345---) n
+ 111 6F (1-3-5---) o
+ 112 70 (1234----) p
+ 113 71 (12345---) q
+ 114 72 (123-5---) r
+ 115 73 (-234----) s
+ 116 74 (-2345---) t
+ 117 75 (1-3--6--) u
+ 118 76 (123--6--) v
+ 119 77 (-2-456--) w
+ 120 78 (1-34-6--) x
+ 121 79 (1-3456--) y
+ 122 7A (1-3-56--) z
+ 123 7B (123-56--) { or umlaut a
+ 124 7C (--34----) | or umlaut o
+ 125 7D (-23456--) } or umlaut u
+ 126 7E (-234-6--) '
+ 127 7F (---456-8) DEL
+ 128 80 (1234-67-) C Cedilla (upper case)
+ 129 81 (12-456--) u Umlaut (lower case)
+ 130 82 (123456-8) e Acute (lower case)
+ 131 83 (1----6-8) a Circumflex
+ 132 84 (123-56--) a Umlaut (lower case)
+ 133 85 (123-56-8) a Grave
+ 134 86 (-2-----8) a Ring (lower case)
+ 135 87 (1234-6-8) c Cedilla (lower case)
+ 136 88 (12---6-8) e Circumflex
+ 137 89 (12-4-6-8) e Umlaut (lower case)
+ 138 8A (-234-6-8) e Grave
+ 139 8B (12-456-8) i Umlaut (lower case)
+ 140 8C (1--4-6-8) i Circumflex
+ 141 8D (-2-4---8) I Grave
+ 142 8E (123-567-) A Umlaut (upper case)
+ 143 8F (1----67-) A Ring (upper case)
+ 144 90 (1234567-) E Acute (upper case)
+ 145 91 (123-56--) ae Digraph (lower case)
+ 146 92 (123-567-) AE Digraph (upper case)
+ 147 93 (1--456-8) o Circumflex
+ 148 94 (--34----) o Umlaut (lower case)
+ 149 95 (--34-6-8) o Grave
+ 150 96 (1---56-8) u Circumflex
+ 151 97 (-23456-8) u Grave
+ 152 98 (1-3456-8) y Umlaut
+ 153 99 (--34--7-) O Umlaut (upper case)
+ 154 9A (-234567-) U Umlaut (upper case)
+ 155 9B (-23-5678) Cent
+ 156 9C (----56-8) Pound/Sterling
+ 157 9D (-2--5678) Yen
+ 158 9E (-23-5--8) Peseta
+ 159 9F (12-4---8) Franc
+ 160 A0 (-23--678) a Acute (lower case)
+ 161 Al (----5-7-) i Acute (lower case)
+ 162 A2 (----5-78) o Acute (lower case)
+ 163 A3 (--3-5678) u Acute (lower case)
+ 164 A4 (1-345--8) n Tilde (lower case)
+ 165 A5 (--345-7-) N Tilde (upper case)
+ 166 A6 (1------8) Feminine Spanish Ordinal
+ 167 A7 (1-3-5--8) Masculine Spanish Ordinal
+ 168 A8 (--3----8) Inverted Question Mark
+ 169 A9 (--3--67-) Left square corner
+ 170 AA (--3--6-8) Right square corner
+ 171 AB (-23----8) 1/2
+ 172 AC (-2--56-8) 1/4
+ 173 AD (----5--8) Inverted Exclamation Mark
+ 174 AE (--3----8) Left Double Guillemet
+ 175 AF (--3---7-) Right Double Guillemet
+ 176 B0 (--34-67-) Box [Shade 1]
+ 177 B1 (---4-678) Box [Shade 2]
+ 178 B2 (12---67-) Box [Shade 3]
+ 179 B3 (1--4-67-) Box [top bottom]
+ 180 B4 (1--4567-) Box [left top bottom]
+ 181 B5 (1---567-) Box [LEFT top bottom]
+ 182 B6 (12-4-67-) Box [left TOP BOTTOM]
+ 183 B7 (12-4567-) Box [left BOTTOM]
+ 184 B8 (12--567-) Box [LEFT bottom]
+ 185 B9 (-2-4-67-) Box [LEFT TOP BOTTOM]
+ 186 BA (-2--5-7-) Box [TOP BOTTOM]
+ 187 BB (-23---7-) Box [LEFT BOTTOM]
+ 188 BC (----567-) Box [LEFT TOP]
+ 189 BD (-23-567-) Box [left TOP]
+ 190 BE (---45-7-) Box [LEFT top]
+ 191 BF (-2---67-) Box [left bottom]
+ 192 CO (--345--8) Box [top right]
+ 193 C1 (--3---78) Box [left top right]
+ 194 C2 (1--45678) Box [left right bottom]
+ 195 C3 (-2-4-678) Box [top right bottom]
+ 196 C4 (1--45--8) Box [left right]
+ 197 C5 (1---5--8) Box [left top right bottom]
+ 198 C6 (-2--5-78) Box [top RIGHT bottom]
+ 199 C7 (12-45--8) Box [TOP right BOTTOM]
+ 200 C8 (------78) Box [TOP RIGHT]
+ 201 C9 (-2--5--8) Box [RIGHT BOTTOM]
+ 202 CA (-2-45--8) Box [LEFT TOP RIGHT]
+ 203 CB (1-3----8) Box [LEFT RIGHT BOTTOM]
+ 204 CC (123----8) Box [TOP RIGHT BOTTOM]
+ 205 CD (1-34---8) Box [LEFT RIGHT]
+ 206 CE (---4--78) Box [LEFT TOP RIGHT BOTTOM]
+ 207 CF (--345678) Box [LEFT top RIGHT]
+ 208 DO (123----8) Box [left TOP right]
+ 209 D1 (12345--8) Box [LEFT RIGHT bottom]
+ 210 D2 (123-5--8) Box [left right BOTTOM]
+ 211 D3 (-234---8) Box [TOP right]
+ 212 D4 (-2345--8) Box [top RIGHT]
+ 213 D5 (1-3--6-8) Box [RIGHT bottom]
+ 214 D6 (123--6-8) Box [right BOTTOM]
+ 215 D7 (-2-456-8) Box [left TOP right BOTTOM]
+ 216 D8 (1-34-6-8) Box [LEFT top RIGHT bottom]
+ 217 D9 (12345678) Box [left top]
+ 218 DA (1-3-56-8) Box [right bottom]
+ 219 DB (-----678) Box [Shade 4]
+ 220 DC (--34-678) Box [box bottom]
+ 221 DD (1234-678) Box [box right]
+ 222 DE (--3-5-78) Box [box left]
+ 223 DF (---4567-) Box [box top]
+ 224 E0 (------7-) Alpha (lower case)
+ 225 E1 (-234-6--) Beta (lower case)
+ 226 E2 (-23-5-78) Gamma (upper case)
+ 227 E3 (-23-5-7-) Pi (lower case)
+ 228 E4 (---4-6-8) Sigma (upper case)
+ 229 E5 (-2----78) Sigma (lower case)
+ 230 E6 (--3--678) Mu (lower case)
+ 231 E7 (-----6-8) Tau (lower case)
+ 232 E8 (-23--6-8) Phi (upper case)
+ 233 E9 (--3-56-8) Theta (lower case)
+ 234 EA (--3-5--8) Omega (upper case)
+ 235 EB (1----678) Delta (lower case)
+ 236 EC (12---678) infinity
+ 237 ED (1--4-678) Phi (lower case)
+ 238 EE (1---5678) Epsilon (lower case)
+ 239 EF (12-4-678) Intersection
+ 240 F0 (12-45678) Equivalent (Member)
+ 241 F1 (12--5678) Plus or minus
+ 242 F2 (------7-) Greater than or equal
+ 243 F3 (--34567-) Less than or equal
+ 244 F4 (---4-67-) Integral [top]
+ 245 F5 (-23---78) Integral [bottom]
+ 246 F6 (-----67-) Division
+ 247 F7 (-23--67-) Approximately equal
+ 248 F8 (12--56-8) Small circle
+ 249 F9 (-2-4-6-8) Bullet
+ 250 FA (-2--5--8) Small bullet
+ 251 FB (--3-567-) Bent Radical
+ 252 FC (----56-8) Power of n
+ 253 FD (-23-56-8) Power of 2
+ 254 FE (---45--8) Large square bullet
+ 255 FF (-2---6-8) blank (hard space)
diff --git a/etc/gs-braille.tbl b/etc/gs-braille.tbl
new file mode 100644
index 0000000..0c5ef9b
--- /dev/null
+++ b/etc/gs-braille.tbl
@@ -0,0 +1,261 @@
+# GS BRAILLE TABLE
+#
+# Dec Hex Braille Description
+# ------------------------------------------------------------------------
+ 0 0 (--------) NUL
+ 1 1 (--------) SOH
+ 2 2 (--------) STX
+ 3 3 (--------) ETX
+ 4 4 (--------) EOT
+ 5 5 (--------) ENQ
+ 6 6 (--------) ACK
+ 7 7 (--------) BEL
+ 8 8 (--------) BS
+ 9 9 (--------) HT
+ 10 A (--------) LF
+ 11 B (--------) VT
+ 12 C (--------) FF
+ 13 D (--------) CR
+ 14 E (--------) SO
+ 15 F (--------) SI
+ 16 10 (--------) DLE
+ 17 11 (--------) DC1
+ 18 12 (--------) DC2
+ 19 13 (--------) DC3
+ 20 14 (--------) DC4
+ 21 15 (--------) NAK
+ 22 16 (--------) SYN
+ 23 17 (--------) ETB
+ 24 18 (--------) CAN
+ 25 19 (--------) EM
+ 26 1A (--------) SUB
+ 27 1B (--------) ESC
+ 28 1C (--------) FS
+ 29 1D (--------) GS
+ 30 1E (--------) RS
+ 31 1F (--------) US
+ 32 20 (--------) space
+ 33 21 (-23-5---) bang
+ 34 22 (--3--678) unidirectional double quote
+ 35 23 (----5678) # (number or hash) symbol
+ 36 24 (--34567-) $
+ 37 25 (--34---8) % symbol
+ 38 26 (-23-5-78) & symbol
+ 39 27 (--3-----) apostrophe
+ 40 28 (-23----8) left parenthesis symbol
+ 41 29 (----567-) right parenthesis symbol
+ 42 2A (--34--7-) asterisk
+ 43 2B (-2--5-7-) plus symbol
+ 44 2C (-2------) comma
+ 45 2D (--3--6--) dash, also used as over/under bar.
+ 46 2E (-2--56--) period, decimal point
+ 47 2F (--34--78) / symbol
+ 48 30 (-2-45-78) zero
+ 49 31 (1-----78) one
+ 50 32 (12----78) two
+ 51 33 (1--4--78) three
+ 52 34 (1--45-78) four
+ 53 35 (1---5-78) five
+ 54 36 (12-4--78) six
+ 55 37 (12-45-78) seven
+ 56 38 (12--5-78) eight
+ 57 39 (-2-4--78) nine
+ 58 3A (-2--5---) colon
+ 59 3B (-23-----) semicolon
+ 60 3C (1234567-) open angle bracket
+ 61 3D (-2--5-78) equals symbol
+ 62 3E (123456-8) close angle bracket
+ 63 3F (-23--6--) question mark
+ 64 40 (--345-78) @ sign
+ 65 41 (1-----7-) A
+ 66 42 (12----7-) B
+ 67 43 (1--4--7-) C
+ 68 44 (1--45-7-) D
+ 69 45 (1---5-7-) E
+ 70 46 (12-4--7-) F
+ 71 47 (12-45-7-) G
+ 72 48 (12--5-7-) H
+ 73 49 (-2-4--7-) I
+ 74 4A (-2-45-7-) J
+ 75 4B (1-3---7-) K
+ 76 4C (123---7-) L
+ 77 4D (1-34--7-) M
+ 78 4E (1-345-7-) N
+ 79 4F (1-3-5-7-) O
+ 80 50 (1234--7-) P
+ 81 51 (12345-7-) Q
+ 82 52 (123-5-7-) R
+ 83 53 (-234--7-) S
+ 84 54 (-2345-7-) T
+ 85 55 (1-3--67-) U
+ 86 56 (123--67-) V
+ 87 57 (-2-4567-) W
+ 88 58 (1-34-67-) X
+ 89 59 (1-34567-) Y
+ 90 5A (1-3-567-) Z
+ 91 5B (-23--678) [ symbol
+ 92 5C (1----678) \ symbol
+ 93 5D (--3-5678) ] symbol
+ 94 5E (--345-7-) ^
+ 95 5F (-2---6-8) _
+ 96 60 (--3----8) opening single quote
+ 97 61 (1-------) a
+ 98 62 (12------) b
+ 99 63 (1--4----) c
+ 100 64 (1--45---) d
+ 101 65 (1---5---) e
+ 102 66 (12-4----) f
+ 103 67 (12-45---) g
+ 104 68 (12--5---) h
+ 105 69 (-2-4----) i
+ 106 6A (-2-45---) j
+ 107 6B (1-3-----) k
+ 108 6C (123-----) l
+ 109 6D (1-34----) m
+ 110 6E (1-345---) n
+ 111 6F (1-3-5---) o
+ 112 70 (1234----) p
+ 113 71 (12345---) q
+ 114 72 (123-5---) r
+ 115 73 (-234----) s
+ 116 74 (-2345---) t
+ 117 75 (1-3--6--) u
+ 118 76 (123--6--) v
+ 119 77 (-2-456--) w
+ 120 78 (1-34-6--) x
+ 121 79 (1-3456--) y
+ 122 7A (1-3-56--) z
+ 123 7B (123-5678) { symbol
+ 124 7C (--34-678) |
+ 125 7D (-2345678) } symbol
+ 126 7E (--34-67-) ~
+ 127 7F (1--4-678) del, nabla sign
+ 128 80 (--3-5-7-) negative power indicator
+ 129 81 (--34-67-) ~
+ 130 82 (--3---78) opening double quote
+ 131 83 (--34----) complex fraction line indicator
+ 132 84 (--3-5-78) left superscript
+ 133 85 (--345678) start extended math mode
+ 134 86 (-23---7-) end of line in 2-D array
+ 135 87 (-23--67-) right arrow sign
+ 136 88 (-23-567-) proportional to sign
+ 137 89 (-23---78) ` (grave accent)
+ 138 8A (-234-678) integral sign
+ 139 8B (-23-5678) identically equals sign
+ 140 8C (--3-5--8) < (less) symbol
+ 141 8D (-2---67-) > (greater) symbol
+ 142 8E (123--678) end extended math mode.
+ 143 8F (12345678) infinity sign
+ 144 90 (1--4-6--) overscript indicator
+ 145 91 (1---56--) slashed symbol or NOT indicator
+ 146 92 (1--456--) function indicator
+ 147 93 (---45-7-) bold symbol indicator
+ 148 94 (---4-67-) italic symbol indicator
+ 149 95 (---4567-) special (text default=underlined) symbol indicator
+ 150 96 (------78) minus sign
+ 151 97 (---4--78) gothic font symbol indicator
+ 152 98 (----5-78) divide by sign
+ 153 99 (---45-78) special font 1 symbol indicator
+ 154 9A (-----678) closing double quote
+ 155 9B (---4-678) special font 2 symbol indicator
+ 156 9C (---45678) special font 3 symbol indicator
+ 157 9D (-2----78) times cross sign
+ 158 9E (-2---678) left subscript
+ 159 9F (--3---7-) end of element in 2-D array
+ 160 A0 (-2-4-6--) radical indicator
+ 161 A1 (-----67-) closing single quote
+ 162 A2 (----5---) In 8 dot code in shapes and as a soft hyphen.
+ 163 A3 (---45---) To be used for foreign indicators and/or phonetic indicators.
+ 164 A4 (-----6--) 04 never appears in 8 dot code except shapes.
+ 165 A5 (---4-6--) 05 never appears in 8 dot code except shapes.
+ 166 A6 (----56--) grade 1 indicator in both codes.
+ 167 A7 (---456--) Converts upper cell to cell + dot-67, other root to root + dot-78.
+ 168 A8 (-------8) Under user control can indicate hyperlinks or font enhancements or...
+ 169 A9 (---4---8) start shape beginning with 01 and ending at first root cell
+ 170 AA (----5--8) start shape beginning with 02
+ 171 AB (---45--8) start shape beginning with 03
+ 172 AC (-----6-8) start shape beginning with 04
+ 173 AD (---4-6-8) start shape beginning with 05
+ 174 AE (----56-8) start shape beginning with 06
+ 175 AF (---456-8) start shape beginning with 07
+ 176 B0 (1--4---8) Copyright sign
+ 177 B1 (1--4-6-8) partial differential sign
+ 178 B2 (-2---6--) subscript indicator
+ 179 B3 (1------8) alpha
+ 180 B4 (12-----8) beta
+ 181 B5 (12-45--8) gamma
+ 182 B6 (1--45--8) delta
+ 183 B7 (1---5--8) epsilon
+ 184 B8 (1-3-56-8) zeta
+ 185 B9 (1---56-8) eta
+ 186 BA (1--456-8) theta
+ 187 BB (-2-4---8) iota
+ 188 BC (1-3----8) kappa
+ 189 BD (123----8) lambda
+ 190 BE (1-34---8) mu
+ 191 BF (1-345--8) nu
+ 192 C0 (1-34-6-8) xi
+ 193 C1 (1-3-5--8) omichron
+ 194 C2 (1234---8) pi
+ 195 C3 (123-5--8) rho
+ 196 C4 (-234---8) sigma
+ 197 C5 (-2345--8) tau
+ 198 C6 (1-3--6-8) upsilon
+ 199 C7 (12-4---8) phi
+ 200 C8 (1234-6-8) chi
+ 201 C9 (1-3456-8) psi
+ 202 CA (-2-456-8) omega
+ 203 CB (1----67-) cap Alpha
+ 204 CC (12---67-) cap Beta
+ 205 CD (12-4567-) cap Gamma
+ 206 CE (1--4567-) cap Delta
+ 207 CF (1---567-) cap Epsilon
+ 208 D0 (1-3-5678) cap zeta
+ 209 D1 (1---5678) cap Eta
+ 210 D2 (1--45678) cap Theta
+ 211 D3 (-2-4-67-) cap Iota
+ 212 D4 (1-3---78) cap kappa
+ 213 D5 (123---78) cap lambda
+ 214 D6 (1-34--78) cap mu
+ 215 D7 (1-345-78) cap nu
+ 216 D8 (1-34-678) cap xi
+ 217 D9 (1-3-5-78) cap omichron
+ 218 DA (1234--78) cap pi
+ 219 DB (123-5-78) cap rho
+ 220 DC (-234--78) cap sigma
+ 221 DD (-2345-78) cap tau
+ 222 DE (1-3--678) cap upsilon
+ 223 DF (12-4-67-) cap Phi
+ 224 E0 (1234-678) cap chi
+ 225 E1 (1-345678) cap psi
+ 226 E2 (-2-45678) cap omega
+ 227 E3 (-2--5--8) times dot sign
+ 228 E4 (-2-45--8) small circle sign
+ 229 E5 (-2-4-6-8) radical sign, not operator
+ 230 E6 (12---6--) open braille bracket
+ 231 E7 (12-4-6--) horizontal combination symbol indicator
+ 232 E8 (12--56--) vertical stack symbol indicator
+ 233 E9 (12-456--) superimposed combination symbol indicator
+ 234 EA (12--56-8) absolute value bar sign
+ 235 EB (--3-5---) superscript indicator
+ 236 EC (--345---) close braille bracket
+ 237 ED (--34-6--) underscript indicator
+ 238 EE (--3-56--) start math word indicator
+ 239 EF (--3456--) Number indicator (6 dot code)
+ 240 F0 (---4----) Accent mark
+ 241 F1 (--3--6-8) ellipses sign
+ 242 F2 (--34-6-8) dagger, transpose sign
+ 243 F3 (--3-56-8) left arrow sign
+ 244 F4 (--3456-8) UK pound
+ 245 F5 (-234-6--) two dimensional array indicator
+ 246 F6 (1----6--) simple fraction line indicator
+ 247 F7 (-23-56--) contraction indicator.
+ 248 F8 (-23456--) close fraction indicator
+ 249 F9 (-234-6-8) end of two dimensional array
+ 250 FA (-23-56-8) approximately equals sign, single tilde over single bar.
+ 251 FB (1234-6--) Large symbol indicator.
+ 252 FC (123-56--) open fraction indicator
+ 253 FD (123456--) quantity indicator
+ 254 FE (------7-) prime mark
+ 255 FF (---4--7-) script font symbol indicator
+
diff --git a/etc/mkinstalldirs b/etc/mkinstalldirs
new file mode 100755
index 0000000..0e29377
--- /dev/null
+++ b/etc/mkinstalldirs
@@ -0,0 +1,35 @@
+#!/bin/sh
+# Make directory hierarchy.
+# Written by Noah Friedman <friedman@prep.ai.mit.edu>
+# Public domain.
+
+defaultIFS='
+'
+IFS="${IFS-${defaultIFS}}"
+
+errstatus=0
+
+for file in ${1+"$@"} ; do
+ oIFS="${IFS}"
+ # Some sh's can't handle IFS=/ for some reason.
+ IFS='%'
+ set - `echo ${file} | sed -e 's@/@%@g' -e 's@^%@/@'`
+ IFS="${oIFS}"
+
+ pathcomp=''
+
+ for d in ${1+"$@"} ; do
+ pathcomp="${pathcomp}${d}"
+
+ if test ! -d "${pathcomp}"; then
+ echo "mkdir $pathcomp" 1>&2
+ mkdir "${pathcomp}" || errstatus=$?
+ fi
+
+ pathcomp="${pathcomp}/"
+ done
+done
+
+exit $errstatus
+
+# eof
diff --git a/etc/newsyntax b/etc/newsyntax
new file mode 100755
index 0000000..6b5bb03
--- /dev/null
+++ b/etc/newsyntax
@@ -0,0 +1,64 @@
+#!/bin/sh
+#
+# newsyntax -- update a screenrc file from 3.2 to 3.3 syntax
+#
+# please check all comments after running this script and watch out
+# for funny passages.
+#
+if [ $# != 1 ]; then
+ echo "usage $0 screenrcfile"
+ exit 1;
+fi
+
+#Ultrix 4.2 /bin/sh does not handle "read a < $1"
+#Dean Gaudet <dgaudet@watdragon.uwaterloo.ca>
+exec < $1
+read a
+
+if [ ."$a" = '.#3.3' ]; then
+ echo "$1 already updated"
+ exit 0
+fi
+
+cp $1 $1.old
+echo "#3.3" > $1
+echo "# Do not remove the above line. This screen rc file was updated" >> $1
+echo "# by the newsyntax script." >> $1
+sed < $1.old >> $1 \
+-e 's/\([ #]\)flow/\1defflow/g' \
+-e 's/^flow/defflow/g' \
+-e 's/\([ #]\)set[ ]*defflow/\1flow/g' \
+-e 's/^set[ ]*defflow/flow/g' \
+-e 's/\([ #]\)mode/\1defmode/g' \
+-e 's/^mode/defmode/g' \
+-e 's/\([ #]\)set[ ]*defmode/\1defmode/g' \
+-e 's/^set[ ]*defmode/defmode/g' \
+-e 's/\([ #]\)monitor/\1defmonitor/g' \
+-e 's/^monitor/defmonitor/g' \
+-e 's/\([ #]\)set[ ]*defmonitor/\1monitor/g' \
+-e 's/^set[ ]*defmonitor/monitor/g' \
+-e 's/\([ #]\)login/\1deflogin/g' \
+-e 's/^login/deflogin/g' \
+-e 's/\([ #]\)set[ ]*deflogin/\1login/g' \
+-e 's/^set[ ]*deflogin/login/g' \
+-e 's/\([ #]\)wrap/\1defwrap/g' \
+-e 's/^wrap/defwrap/g' \
+-e 's/\([ #]\)set[ ]*defwrap/\1wrap/g' \
+-e 's/^set[ ]*defwrap/wrap/g' \
+-e 's/\([ #]\)scrollback/\1defscrollback/g' \
+-e 's/^scrollback/defscrollback/g' \
+-e 's/\([ #]\)set[ ]*defscrollback/\1scrollback/g' \
+-e 's/^set[ ]*defscrollback/scrollback/g' \
+-e 's/\([ #]\)refresh/\1allPARtial/g' \
+-e 's/^refresh/allPARtial/g' \
+-e 's/\([ #]\)redraw/\1allPARtial/g' \
+-e 's/^redraw/allPARtial/g' \
+-e 's/\([ #]\)set[ ]*allPARtial/\1PARtial/g' \
+-e 's/^set[ ]*allPARtial/PARtial/g' \
+-e 's/\([ #]\)visualbell/\1vbell/g' \
+-e 's/^visualbell/vbell/g' \
+-e 's/PARtial\([ ]*\)on/partial\1off/g' \
+-e 's/PARtial\([ ]*\)off/partial\1on/g' \
+-e 's/allPARtial/refresh/g' \
+-e 's/^set[ ]//g'
+
diff --git a/etc/newsyntax38 b/etc/newsyntax38
new file mode 100755
index 0000000..b22850d
--- /dev/null
+++ b/etc/newsyntax38
@@ -0,0 +1,71 @@
+#! /bin/sh
+#
+# newsyntax38 -- update a screenrc file from 3.3 to 3.8 syntax
+#
+# Please bring your scripts up to syntax level 3.3 before running this script.
+# Please check all comments after running this script and watch out
+# for funny passages.
+#
+# * aka and shellaka are replaced by title and shelltitle.
+#
+# * Pairs of termcap and terminfo commands are folded into a single
+# termcapinfo command where possible.
+#
+# * trailing blanks are zapped. Unintentionally.
+#
+# 12.10.95, jnweiger, use at your own risk.
+#
+if [ $# != 1 ]; then
+ echo "usage $0 screenrcfile"
+ echo ""
+ echo "The named file will be updated in place to the syntax of screen 3.8"
+ echo "A backup copy will be written to <screenrcfile>.bak"
+ exit 1;
+fi
+
+#Ultrix 4.2 /bin/sh does not handle "read a < $1"
+#Dean Gaudet <dgaudet@watdragon.uwaterloo.ca>
+exec < $1
+read a
+
+if [ "$a" = "#3.8" ]; then
+ echo "$1 already updated"
+ exit 0
+fi
+
+rm -f $1.old $1.dups
+
+cp $1 $1.old
+echo "#3.8" > $1
+echo "# Do not remove the above line. This screen rc file was updated" >> $1
+echo "# by the newsyntax script." >> $1
+
+# termcap and terminfo lines can only be folded when there is no parameter
+# expansion in the codes. Parameters are denoted differently in
+# termcap and termcap syntax. Everything else is identical, I assume.
+# Thus codes not containing '%' can be savely folded.
+
+sed < $1.old > $1.dups \
+-e 's/^\([ #]*\)aka/\1title/' \
+-e 's/^\([ #]*\)shellaka/\1shelltitle/' \
+-e 's/^\([ #]*\)termcap[ ][ ]*\([^%]*$\)/\1termcapinfo \2/' \
+-e 's/^\([ #]*\)terminfo[ ][ ]*\([^%]*$\)/\1termcapinfo \2/' \
+-e 's/\\/\\\\/g'
+
+# Oh, my bourne shell seems to gobble backslashes while reading.
+# Thus the sed above duplicates them in advance.
+# Hope this is not just another silly bash featureism.
+# It still zaps trailing blanks. I do not know why. But that is nice.
+
+exec < $1.dups
+while read a ; do
+ if [ "$a" = "$b" ]; then
+ case "$a" in
+ *termcapinfo*) continue ;;
+ esac
+ fi
+ echo "$a" >> $1
+ b="$a"
+done
+
+rm -f $1.dups
diff --git a/etc/screenrc b/etc/screenrc
new file mode 100644
index 0000000..ca6561d
--- /dev/null
+++ b/etc/screenrc
@@ -0,0 +1,153 @@
+#
+# Example of a user's .screenrc file
+#
+
+# This is how one can set a reattach password:
+# password ODSJQf.4IJN7E # "1234"
+
+# no annoying audible bell, please
+vbell on
+
+# detach on hangup
+autodetach on
+
+# don't display the copyright page
+startup_message off
+
+# emulate .logout message
+pow_detach_msg "Screen session of \$LOGNAME \$:cr:\$:nl:ended."
+
+# advertise hardstatus support to $TERMCAP
+# termcapinfo * '' 'hs:ts=\E_:fs=\E\\:ds=\E_\E\\'
+
+# make the shell in every window a login shell
+#shell -$SHELL
+
+# autoaka testing
+# shellaka '> |tcsh'
+# shellaka '$ |sh'
+
+# set every new windows hardstatus line to somenthing descriptive
+# defhstatus "screen: ^En (^Et)"
+
+defscrollback 1000
+
+# don't kill window after the process died
+# zombie "^["
+
+# enable support for the "alternate screen" capability in all windows
+# altscreen on
+
+################
+#
+# xterm tweaks
+#
+
+#xterm understands both im/ic and doesn't have a status line.
+#Note: Do not specify im and ic in the real termcap/info file as
+#some programs (e.g. vi) will not work anymore.
+termcap xterm hs@:cs=\E[%i%d;%dr:im=\E[4h:ei=\E[4l
+terminfo xterm hs@:cs=\E[%i%p1%d;%p2%dr:im=\E[4h:ei=\E[4l
+
+#80/132 column switching must be enabled for ^AW to work
+#change init sequence to not switch width
+termcapinfo xterm Z0=\E[?3h:Z1=\E[?3l:is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l
+
+# Make the output buffer large for (fast) xterms.
+#termcapinfo xterm* OL=10000
+termcapinfo xterm* OL=100
+
+# tell screen that xterm can switch to dark background and has function
+# keys.
+termcapinfo xterm 'VR=\E[?5h:VN=\E[?5l'
+termcapinfo xterm 'k1=\E[11~:k2=\E[12~:k3=\E[13~:k4=\E[14~'
+termcapinfo xterm 'kh=\EOH:kI=\E[2~:kD=\E[3~:kH=\EOF:kP=\E[5~:kN=\E[6~'
+
+# special xterm hardstatus: use the window title.
+termcapinfo xterm 'hs:ts=\E]2;:fs=\007:ds=\E]2;screen\007'
+
+#terminfo xterm 'vb=\E[?5h$<200/>\E[?5l'
+termcapinfo xterm 'vi=\E[?25l:ve=\E[34h\E[?25h:vs=\E[34l'
+
+# emulate part of the 'K' charset
+termcapinfo xterm 'XC=K%,%\E(B,[\304,\\\\\326,]\334,{\344,|\366,}\374,~\337'
+
+# xterm-52 tweaks:
+# - uses background color for delete operations
+termcapinfo xterm* be
+
+################
+#
+# wyse terminals
+#
+
+#wyse-75-42 must have flow control (xo = "terminal uses xon/xoff")
+#essential to have it here, as this is a slow terminal.
+termcapinfo wy75-42 xo:hs@
+
+# New termcap sequences for cursor application mode.
+termcapinfo wy* CS=\E[?1h:CE=\E[?1l:vi=\E[?25l:ve=\E[?25h:VR=\E[?5h:VN=\E[?5l:cb=\E[1K:CD=\E[1J
+
+################
+#
+# other terminals
+#
+
+# make hp700 termcap/info better
+termcapinfo hp700 'Z0=\E[?3h:Z1=\E[?3l:hs:ts=\E[62"p\E[0$~\E[2$~\E[1$}:fs=\E[0}\E[61"p:ds=\E[62"p\E[1$~\E[61"p:ic@'
+
+# Extend the vt100 desciption by some sequences.
+termcap vt100* ms:AL=\E[%dL:DL=\E[%dM:UP=\E[%dA:DO=\E[%dB:LE=\E[%dD:RI=\E[%dC
+terminfo vt100* ms:AL=\E[%p1%dL:DL=\E[%p1%dM:UP=\E[%p1%dA:DO=\E[%p1%dB:LE=\E[%p1%dD:RI=\E[%p1%dC
+termcapinfo linux C8
+# old rxvt versions also need this
+# termcapinfo rxvt C8
+
+
+################
+#
+# keybindings
+#
+
+#remove some stupid / dangerous key bindings
+bind k
+bind ^k
+bind .
+bind ^\
+bind \\
+bind ^h
+bind h
+#make them better
+bind 'K' kill
+bind 'I' login on
+bind 'O' login off
+bind '}' history
+
+# Yet another hack:
+# Prepend/append register [/] to the paste if ^a^] is pressed.
+# This lets me have autoindent mode in vi.
+register [ "\033:se noai\015a"
+register ] "\033:se ai\015a"
+bind ^] paste [.]
+
+################
+#
+# default windows
+#
+
+# screen -t local 0
+# screen -t mail 1 mutt
+# screen -t 40 2 rlogin server
+
+# caption always "%3n %t%? @%u%?%? [%h]%?%=%c"
+# hardstatus alwaysignore
+# hardstatus alwayslastline "%Lw"
+
+# bind = resize =
+# bind + resize +1
+# bind - resize -1
+# bind _ resize max
+#
+# defnonblock 1
+# blankerprg rain -d 100
+# idle 30 blanker
diff --git a/etc/toolcheck b/etc/toolcheck
new file mode 100755
index 0000000..1b8ee39
--- /dev/null
+++ b/etc/toolcheck
@@ -0,0 +1,44 @@
+#!/bin/sh
+# toolcheck -- check for tools that have severe bugs. Good that all the buggy
+# tools identify by version numbers. This is the spirit of GNU :-)
+#
+# 24.7.95 jw.
+
+retval=0
+reply="`sh -version 2>&1 < /dev/null | sed q`"
+case "$reply" in
+ GNU*1.14.3*)
+ echo "- sh is '$reply'";
+ echo " CAUTION: This shell has a buggy 'trap' command.";
+ echo " The configure script may fail silently.";
+ retval=1;
+ ;;
+ GNU*1.14.2*|GNU*1.14.4*|GNU*1.13.*)
+ echo "- sh is '$reply' - good.";
+ ;;
+ GNU*) echo "- sh is '$reply'.";
+ ;;
+ *) ;;
+esac
+
+reply="`sed --version 2>&1 < /dev/null | sed q`"
+case "$reply" in
+ GNU\ sed\ version\ 2.0[34])
+ echo "- sed is '$reply'";
+ echo " CAUTION: This sed cannot configure screen properly."
+ retval=1;
+ ;;
+ GNU\ sed\ version\ 2.05|GNU\ sed\ version\ 2.03\ kevin)
+ echo "- sed is '$reply' - good.";
+ ;;
+ GNU*) echo "- sed is '$reply'.";
+ ;;
+ *) ;;
+esac
+
+if [ "$retval" != 0 ]; then
+ echo " ***********************************************************"
+ echo " Please fix the above problem before reporting a screen bug!"
+ echo " ***********************************************************"
+fi
+exit $retval
diff --git a/etc/us-braille.tbl b/etc/us-braille.tbl
new file mode 100644
index 0000000..640f62f
--- /dev/null
+++ b/etc/us-braille.tbl
@@ -0,0 +1,260 @@
+# U.S. BRAILLE TABLE
+#
+# Dec Hex Braille Description
+# ------------------------------------------------------------------------
+ 0 00 (---4--78) NUL
+ 1 01 (1-----78) SOH
+ 2 02 (12----78) STX
+ 3 03 (1--4--78) ETX
+ 4 04 (1--45-78) EOT
+ 5 05 (1---5-78) ENQ
+ 6 06 (12-4--78) ACK
+ 7 07 (12-45-78) BEL
+ 8 08 (12--5-78) BS
+ 9 09 (-2-4--78) HT
+ 10 OA (-2-45-78) LF
+ 11 0B (1-3---78) VT
+ 12 OC (123---78) FF
+ 13 0D (1-34--78) CR
+ 14 0E (1-345-78) SO
+ 15 OF (1-3-5-78) SI
+ 16 10 (1234--78) DLE
+ 17 11 (12345-78) DC1
+ 18 12 (123-5-78) DC2
+ 19 13 (-234--78) DC3
+ 20 14 (-2345-78) DC4
+ 21 15 (1-3--678) NAK
+ 22 16 (123--678) SYN
+ 23 17 (-2-45678) ETB
+ 24 18 (1-34-678) CAN
+ 25 19 (1-345678) EM
+ 26 1A (1-3-5678) SUB
+ 27 lB (-2-4-678) ESC
+ 28 lC (12--5678) FS
+ 29 1D (12-45678) GS
+ 30 lE (---45-78) RS
+ 31 1F (---45678) US
+ 32 20 (--------) Space
+ 33 21 (-234-6--) !
+ 34 22 (----5---) "
+ 35 23 (--3456--) #
+ 36 24 (12-4-6--) $
+ 37 25 (1--4-6--) %
+ 38 26 (1234-6--) &
+ 39 27 (--3-----) '
+ 40 28 (123-56--) (
+ 41 29 (-23456--) )
+ 42 2A (1----6--) *
+ 43 2B (--34-6--) +
+ 44 2C (-----6--) ,
+ 45 2D (--3--6--) -
+ 46 2E (---4-6--) .
+ 47 2F (--34----) /
+ 48 30 (--3-56--) 0
+ 49 31 (-2------) 1
+ 50 32 (-23-----) 2
+ 51 33 (-2--5---) 3
+ 52 34 (-2--56--) 4
+ 53 35 (-2---6--) 5
+ 54 36 (-23-5---) 6
+ 55 37 (-23-56--) 7
+ 56 38 (-23--6--) 8
+ 57 39 (--3-5---) 9
+ 58 3A (1---56--) :
+ 59 3B (----56--) ;
+ 60 3C (12---6--) <
+ 61 3D (123456--) -
+ 62 3E (--345---) >
+ 63 3F (1--456--) ?
+ 64 40 (---4--7-) @
+ 65 41 (1-----7-) A
+ 66 42 (12----7-) B
+ 67 43 (1--4--7-) C
+ 68 44 (1--45-7-) D
+ 69 45 (1---5-7-) E
+ 70 46 (12-4--7-) F
+ 71 47 (12-45-7-) G
+ 72 48 (12--5-7-) H
+ 73 49 (-2-4--7-) I
+ 74 4A (-2-45-7-) J
+ 75 4B (1-3---7-) K
+ 76 4C (123---7-) L
+ 77 4D (1-34--7-) M
+ 78 4E (1-345-7-) N
+ 79 4F (1-3-5-7-) O
+ 80 50 (1234--7-) P
+ 81 51 (12345-7-) Q
+ 82 52 (123-5-7-) R
+ 83 53 (-234--7-) S
+ 84 54 (-2345-7-) T
+ 85 55 (1-3--67-) U
+ 86 56 (123--67-) V
+ 87 57 (-2-4567-) W
+ 88 58 (1-34-67-) X
+ 89 59 (1-34567-) Y
+ 90 5A (1-3-567-) Z
+ 91 5B (-2-4-67-) [
+ 92 5C (12--567-) \
+ 93 5D (12-4567-) ]
+ 94 5E (---45-7-) ^
+ 95 5F (---4567-) _
+ 96 60 (---4----) '
+ 97 61 (1-------) a
+ 98 62 (12------) b
+ 99 63 (1--4----) c
+ 100 64 (1--45---) d
+ 101 65 (1---5---) e
+ 102 66 (12-4----) f
+ 103 67 (12-45---) g
+ 104 68 (12--5---) h
+ 105 69 (-2-4----) i
+ 106 6A (-2-45---) j
+ 107 6B (1-3-----) k
+ 108 6C (123-----) l
+ 109 6D (1-34----) m
+ 110 6E (1-345---) n
+ 111 6F (1-3-5---) o
+ 112 70 (1234----) p
+ 113 71 (12345---) q
+ 114 72 (123-5---) r
+ 115 73 (-234----) s
+ 116 74 (-2345---) t
+ 117 75 (1-3--6--) u
+ 118 76 (123--6--) v
+ 119 77 (-2-456--) w
+ 120 78 (1-34-6--) x
+ 121 79 (1-3456--) y
+ 122 7A (1-3-56--) z
+ 123 7B (-2-4-6--) {
+ 124 7C (12--56--) |
+ 125 7D (12-456--) }
+ 126 7E (---45---) ~
+ 127 7F (---456--) DEL
+ 128 80 (---4---8) C Cedilla (upper case)
+ 129 81 (1------8) u Umlaut (lower case)
+ 130 82 (12-----8) e Acute (lower case)
+ 131 83 (1--4---8) a Circumflex
+ 132 84 (1--45--8) a Umlaut (lower case)
+ 133 85 (1---5--8) a Grave
+ 134 86 (12-4---8) a Ring (lower case)
+ 135 87 (12-45--8) c Cedilla (lower case)
+ 136 88 (12--5--8) e Circumflex
+ 137 89 (-2-4---8) e Umlaut (lower case)
+ 138 8A (--2-45-8) e Grave
+ 139 8B (1-3----8) i Umlaut (lower case)
+ 140 8C (123----8) i Circumflex
+ 141 8D (1-34---8) I Grave
+ 142 8E (1-345--8) A Umlaut (upper case)
+ 143 8F (1-3-5--8) A Ring (upper case)
+ 144 90 (1234---8) E Acute (upper case)
+ 145 91 (12345--8) ae Digraph (lower case)
+ 146 92 (123-5--8) AE Digraph (upper case)
+ 147 93 (-234---8) o Circumflex
+ 148 94 (-2345--8) o Umlaut (lower case)
+ 149 95 (1-3--6-8) o Grave
+ 150 96 (123--6-8) u Circumflex
+ 151 97 (-2-456-8) u Grave
+ 152 98 (1-34-6-8) y Umlaut
+ 153 99 (1-3456-8) O Umlaut (upper case)
+ 154 9A (1-3-56-8) U Umlaut (upper case)
+ 155 9B (-2-4-6-8) Cent
+ 156 9C (12--56-8) Pound/Sterling
+ 157 9D (12-456-8) Yen
+ 158 9E (---45--8) Peseta
+ 159 9F (---456-8) Franc
+ 160 A0 (------7-) a Acute (lower case)
+ 161 Al (-234-67-) i Acute (lower case)
+ 162 A2 (----5-7-) o Acute (lower case)
+ 163 A3 (--34567-) u Acute (lower case)
+ 164 A4 (12-4-67-) n Tilde (lower case)
+ 165 A5 (1--4-67-) N Tilde (upper case)
+ 166 A6 (1234-67-) Feminine Spanish Ordinal
+ 167 A7 (--3---7-) Masculine Spanish Ordinal
+ 168 A8 (123-567-) Inverted Question Mark
+ 169 A9 (-234567-) Left square corner
+ 170 AA (1----67-) Right square corner
+ 171 AB (--34-67-) 1/2
+ 172 AC (-----67-) 1/4
+ 173 AD (--3--67-) Inverted Exclamation Mark
+ 174 AE (---4-67-) Left Double Guillemet
+ 175 AF (--34--7-) Right Double Guillemet
+ 176 B0 (--3-567-) Box [Shade 1]
+ 177 B1 (-2----7-) Box [Shade 2]
+ 178 B2 (-23---7-) Box [Shade 3]
+ 179 B3 (-2--5-7-) Box [top bottom]
+ 180 B4 (-2--567-) Box [left top bottom]
+ 181 B5 (-2---67-) Box [LEFT top bottom]
+ 182 B6 (-23-5-7-) Box [left TOP BOTTOM]
+ 183 B7 (-23-567-) Box [left BOTTOM]
+ 184 B8 (-23--67-) Box [LEFT bottom]
+ 185 B9 (--3-5-7-) Box [LEFT TOP BOTTOM]
+ 186 BA (1---567-) Box [TOP BOTTOM]
+ 187 BB (----567-) Box [LEFT BOTTOM]
+ 188 BC (12---67-) Box [LEFT TOP]
+ 189 BD (1234567-) Box [left TOP]
+ 190 BE (--345-7-) Box [LEFT top]
+ 191 BF (1--4567-) Box [left bottom]
+ 192 CO (------78) Box [top right]
+ 193 C1 (-234-678) Box [left top right]
+ 194 C2 (----5-78) Box [left right bottom]
+ 195 C3 (--345678) Box [top right bottom]
+ 196 C4 (12-4-678) Box [left right]
+ 197 C5 (1--4-678) Box [left top right bottom]
+ 198 C6 (1234-678) Box [top RIGHT bottom]
+ 199 C7 (--3---78) Box [TOP right BOTTOM]
+ 200 C8 (123-5678) Box [TOP RIGHT]
+ 201 C9 (-2345678) Box [RIGHT BOTTOM]
+ 202 CA (1----678) Box [LEFT TOP RIGHT]
+ 203 CB (--34-678) Box [LEFT RIGHT BOTTOM]
+ 204 CC (-----678) Box [TOP RIGHT BOTTOM]
+ 205 CD (--3--678) Box [LEFT RIGHT]
+ 206 CE (---4-678) Box [LEFT TOP RIGHT BOTTOM]
+ 207 CF (--34--78) Box [LEFT top RIGHT]
+ 208 DO (--3-5678) Box [left TOP right]
+ 209 D1 (-2----78) Box [LEFT RIGHT bottom]
+ 210 D2 (-23---78) Box [left right BOTTOM]
+ 211 D3 (-2--5-78) Box [TOP right]
+ 212 D4 (-2--5678) Box [top RIGHT]
+ 213 D5 (-2---678) Box [RIGHT bottom]
+ 214 D6 (-23-5-78) Box [right BOTTOM]
+ 215 D7 (-23-5678) Box [left TOP right BOTTOM]
+ 216 D8 (-23--678) Box [LEFT top RIGHT bottom]
+ 217 D9 (--3-5-78) Box [left top]
+ 218 DA (1---5678) Box [right bottom]
+ 219 DB (----5678) Box [Shade 4]
+ 220 DC (12---678) Box [box bottom]
+ 221 DD (12345678) Box [box right]
+ 222 DE (--345-78) Box [box left]
+ 223 DF (1--45678) Box [box top]
+ 224 E0 (-------8) Alpha (lower case)
+ 225 E1 (-234-6-8) Beta (lower case)
+ 226 E2 (----5--8) Gamma (upper case)
+ 227 E3 (--3456-8) Pi (lower case)
+ 228 E4 (12-4-6-8) Sigma (upper case)
+ 229 E5 (1--4-6-8) Sigma (lower case)
+ 230 E6 (1234-6-8) Mu (lower case)
+ 231 E7 (--3----8) Tau (lower case)
+ 232 E8 (123-56-8) Phi (upper case)
+ 233 E9 (-23456-8) Theta (lower case)
+ 234 EA (1----6-8) Omega (upper case)
+ 235 EB (--34-6-8) Delta (lower case)
+ 236 EC (-----6-8) infinity
+ 237 ED (--3--6-8) Phi (lower case)
+ 238 EE (---4-6-8) Epsilon (lower case)
+ 239 EF (--34---8) Intersection
+ 240 F0 (--3-56-8) Equivalent (Member)
+ 241 F1 (-2-----8) Plus or minus
+ 242 F2 (-23----8) Greater than or equal
+ 243 F3 (-2--5--8) Less than or equal
+ 244 F4 (-2--56-8) Integral [top]
+ 245 F5 (-2---6-8) Integral [bottom]
+ 246 F6 (-23-5--8) Division
+ 247 F7 (-23-56-8) Approximately equal
+ 248 F8 (-23--6-8) Small circle
+ 249 F9 (--3-5--8) Bullet
+ 250 FA (1---56-8) Small bullet
+ 251 FB (----56-8) Bent Radical
+ 252 FC (12---6-8) Power of n
+ 253 FD (123456-8) Power of 2
+ 254 FE (--345--8) Large square bullet
+ 255 FF (1--456-8) blank (hard space)
diff --git a/extern.h b/extern.h
new file mode 100644
index 0000000..55e007d
--- /dev/null
+++ b/extern.h
@@ -0,0 +1,511 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+#if !defined(__GNUC__) || __GNUC__ < 2
+#undef __attribute__
+#define __attribute__(x)
+#endif
+
+#include <stdbool.h>
+
+/* screen.c */
+extern int main __P((int, char **));
+extern sigret_t SigHup __P(SIGPROTOARG);
+extern void eexit __P((int)) __attribute__((__noreturn__));
+extern void Detach __P((int));
+extern void Hangup __P((void));
+extern void Kill __P((int, int));
+#ifdef USEVARARGS
+extern void Msg __P((int, const char *, ...)) __attribute__((format(printf, 2, 3)));
+extern void Panic __P((int, const char *, ...)) __attribute__((format(printf, 2, 3))) __attribute__((__noreturn__));
+extern void QueryMsg __P((int, const char *, ...)) __attribute__((format(printf, 2, 3)));
+extern void Dummy __P((int, const char *, ...)) __attribute__((format(printf, 2, 3)));
+#else
+extern void Msg __P(());
+extern void Panic __P(());
+extern void QueryMsg __P(());
+extern void Dummy __P(());
+#endif
+extern void Finit __P((int));
+extern void MakeNewEnv __P((void));
+extern char *MakeWinMsg __P((char *, struct win *, int));
+extern char *MakeWinMsgEv __P((char *, struct win *, int, int, struct event *, int));
+extern int AddWinMsgRend __P((const char *, int));
+extern void PutWinMsg __P((char *, int, int));
+#ifdef BSDWAIT
+extern void WindowDied __P((struct win *, union wait, int));
+#else
+extern void WindowDied __P((struct win *, int, int));
+#endif
+extern void setbacktick __P((int, int, int, char **));
+
+/* ansi.c */
+extern void ResetAnsiState __P((struct win *));
+extern void ResetWindow __P((struct win *));
+extern void ResetCharsets __P((struct win *));
+extern void WriteString __P((struct win *, char *, int));
+extern void ChangeAKA __P((struct win *, char *, int));
+extern void SetCharsets __P((struct win *, char *));
+extern int GetAnsiStatus __P((struct win *, char *));
+extern void WNewAutoFlow __P((struct win *, int));
+extern void WBell __P((struct win *, int));
+extern void WMsg __P((struct win *, int, char *));
+extern void WChangeSize __P((struct win *, int, int));
+extern void WindowChanged __P((struct win *, int));
+extern int MFindUsedLine __P((struct win *, int, int));
+
+/* fileio.c */
+extern int StartRc __P((char *, int));
+extern void FinishRc __P((char *));
+extern void RcLine __P((char *, int));
+extern FILE *secfopen __P((char *, char *));
+extern int secopen __P((char *, int, int));
+extern void WriteFile __P((struct acluser *, char *, int));
+extern char *ReadFile __P((char *, int *));
+extern void KillBuffers __P((void));
+extern int printpipe __P((struct win *, char *));
+extern int readpipe __P((char **));
+extern void RunBlanker __P((char **));
+extern void do_source __P((char *));
+
+/* tty.c */
+extern int OpenTTY __P((char *, char *));
+extern void InitTTY __P((struct mode *, int));
+extern void GetTTY __P((int, struct mode *));
+extern void SetTTY __P((int, struct mode *));
+extern void SetMode __P((struct mode *, struct mode *, int, int));
+extern void SetFlow __P((int));
+extern void SendBreak __P((struct win *, int, int));
+extern int TtyGrabConsole __P((int, int, char *));
+extern char *TtyGetModemStatus __P((int, char *));
+#ifdef DEBUG
+extern void DebugTTY __P((struct mode *));
+#endif /* DEBUG */
+extern int fgtty __P((int));
+extern void brktty __P((int));
+extern struct baud_values *lookup_baud __P((int bps));
+extern int SetBaud __P((struct mode *, int, int));
+extern int SttyMode __P((struct mode *, char *));
+extern int CheckTtyname __P((char *));
+extern char *GetPtsPathOrSymlink __P((int));
+
+/* mark.c */
+extern int GetHistory __P((void));
+extern void MarkRoutine __P((void));
+extern void revto_line __P((int, int, int));
+extern void revto __P((int, int));
+extern int InMark __P((void));
+extern void MakePaster __P((struct paster *, char *, int, int));
+extern void FreePaster __P((struct paster *));
+
+/* search.c */
+extern void Search __P((int));
+extern void ISearch __P((int));
+
+/* input.c */
+extern void inp_setprompt __P((char *, char *));
+extern void Input __P((char *, int, int, void (*)(char *, int, char *), char *, int));
+extern int InInput __P((void));
+
+/* help.c */
+extern void exit_with_usage __P((char *, char *, char *));
+extern void display_help __P((char *, struct action *));
+extern void display_copyright __P((void));
+extern void display_displays __P((void));
+extern void display_bindkey __P((char *, struct action *));
+extern int InWList __P((void));
+extern void WListUpdatecv __P((struct canvas *, struct win *));
+extern void WListLinkChanged __P((void));
+#ifdef ZMODEM
+extern void ZmodemPage __P((void));
+#endif
+
+/* window.c */
+extern int MakeWindow __P((struct NewWindow *));
+extern int RemakeWindow __P((struct win *));
+extern void FreeWindow __P((struct win *));
+#ifdef PSEUDOS
+extern int winexec __P((char **));
+extern void FreePseudowin __P((struct win *));
+#endif
+extern void nwin_compose __P((struct NewWindow *, struct NewWindow *, struct NewWindow *));
+extern int DoStartLog __P((struct win *, char *, int));
+extern int ReleaseAutoWritelock __P((struct display *, struct win *));
+extern int ObtainAutoWritelock __P((struct display *, struct win *));
+extern void CloseDevice __P((struct win *));
+#ifdef ZMODEM
+extern void zmodem_abort __P((struct win *, struct display *));
+#endif
+#ifndef HAVE_EXECVPE
+extern void execvpe __P((char *, char **, char **));
+#endif
+
+/* utmp.c */
+#ifdef UTMPOK
+extern void InitUtmp __P((void));
+extern void RemoveLoginSlot __P((void));
+extern void RestoreLoginSlot __P((void));
+extern int SetUtmp __P((struct win *));
+extern int RemoveUtmp __P((struct win *));
+#endif /* UTMPOK */
+extern void SlotToggle __P((int));
+#ifdef USRLIMIT
+extern int CountUsers __P((void));
+#endif
+#ifdef CAREFULUTMP
+extern void CarefulUtmp __P((void));
+#else
+# define CarefulUtmp() /* nothing */
+#endif /* CAREFULUTMP */
+
+
+/* loadav.c */
+#ifdef LOADAV
+extern void InitLoadav __P((void));
+extern void AddLoadav __P((char *));
+#endif
+
+/* pty.c */
+extern int OpenPTY __P((char **));
+extern void InitPTY __P((int));
+
+/* process.c */
+extern void InitKeytab __P((void));
+extern void ProcessInput __P((char *, int));
+#ifdef MAPKEYS
+extern void ProcessInput2 __P((char *, int));
+#endif
+extern void DoProcess __P((struct win *, char **, int *, struct paster *));
+extern void DoAction __P((struct action *, int));
+extern int FindCommnr __P((const char *));
+extern void DoCommand __P((char **, int *));
+extern void Activate __P((int));
+extern void KillWindow __P((struct win *));
+extern void SetForeWindow __P((struct win *));
+extern int Parse __P((char *, int, char **, int *));
+extern void SetEscape __P((struct acluser *, int, int));
+extern void DoScreen __P((char *, char **));
+extern int IsNumColon __P((char *, int, char *, int));
+extern void ShowWindows __P((int));
+extern char *AddWindows __P((char *, int, int, int));
+extern char *AddWindowFlags __P((char *, int, struct win *));
+extern char *AddOtherUsers __P((char *, int, struct win *));
+extern int WindowByNoN __P((char *));
+extern struct win *FindNiceWindow __P((struct win *, char *));
+#ifdef COPY_PASTE
+extern int CompileKeys __P((char *, int, unsigned char *));
+#endif
+#ifdef RXVT_OSC
+extern void RefreshXtermOSC __P((void));
+#endif
+extern int ParseSaveStr __P((struct action *act, char **));
+extern int ParseNum __P((struct action *act, int *));
+extern int ParseSwitch __P((struct action *, int *));
+extern int ParseAttrColor __P((char *, char *, int));
+extern void ApplyAttrColor __P((int, struct mchar *));
+extern void SwitchWindow __P((int));
+extern int StuffKey __P((int));
+
+/* termcap.c */
+extern int InitTermcap __P((int, int));
+extern char *MakeTermcap __P((int));
+extern char *gettermcapstring __P((char *));
+#ifdef MAPKEYS
+extern int remap __P((int, int));
+extern void CheckEscape __P((void));
+#endif
+extern int CreateTransTable __P((char *));
+extern void FreeTransTable __P((void));
+
+/* attacher.c */
+extern int Attach __P((int));
+extern void Attacher __P((void));
+extern sigret_t AttacherFinit __P(SIGPROTOARG);
+extern void SendCmdMessage __P((char *, char *, char **, int));
+
+/* display.c */
+extern struct display *MakeDisplay __P((char *, char *, char *, int, int, struct mode *));
+extern void FreeDisplay __P((void));
+extern void DefProcess __P((char **, int *));
+extern void DefRedisplayLine __P((int, int, int, int));
+extern void DefClearLine __P((int, int, int, int));
+extern int DefRewrite __P((int, int, int, struct mchar *, int));
+extern int DefResize __P((int, int));
+extern void DefRestore __P((void));
+extern void AddCStr __P((char *));
+extern void AddCStr2 __P((char *, int));
+extern void InitTerm __P((int));
+extern void FinitTerm __P((void));
+extern void PUTCHAR __P((int));
+extern void PUTCHARLP __P((int));
+extern void ClearAll __P((void));
+extern void ClearArea __P((int, int, int, int, int, int, int, int));
+extern void ClearLine __P((struct mline *, int, int, int, int));
+extern void RefreshAll __P((int));
+extern void RefreshArea __P((int, int, int, int, int));
+extern void RefreshLine __P((int, int, int, int));
+extern void Redisplay __P((int));
+extern void RedisplayDisplays __P((int));
+extern void ShowHStatus __P((char *));
+extern void RefreshHStatus __P((void));
+extern void DisplayLine __P((struct mline *, struct mline *, int, int, int));
+extern void GotoPos __P((int, int));
+extern int CalcCost __P((char *));
+extern void ScrollH __P((int, int, int, int, int, struct mline *));
+extern void ScrollV __P((int, int, int, int, int, int));
+extern void PutChar __P((struct mchar *, int, int));
+extern void InsChar __P((struct mchar *, int, int, int, struct mline *));
+extern void WrapChar __P((struct mchar *, int, int, int, int, int, int, int));
+extern void ChangeScrollRegion __P((int, int));
+extern void InsertMode __P((int));
+extern void KeypadMode __P((int));
+extern void CursorkeysMode __P((int));
+extern void ReverseVideo __P((int));
+extern void CursorVisibility __P((int));
+extern void MouseMode __P((int));
+extern void SetFont __P((int));
+extern void SetAttr __P((int));
+extern void SetColor __P((int, int));
+extern void SetRendition __P((struct mchar *));
+extern void SetRenditionMline __P((struct mline *, int));
+extern void MakeStatus __P((char *));
+extern void RemoveStatus __P((void));
+extern int ResizeDisplay __P((int, int));
+extern void AddStr __P((char *));
+extern void AddStrn __P((char *, int));
+extern void Flush __P((int));
+extern void freetty __P((void));
+extern void Resize_obuf __P((void));
+#ifdef AUTO_NUKE
+extern void NukePending __P((void));
+#endif
+#ifdef RXVT_OSC
+extern void ClearAllXtermOSC __P((void));
+extern void SetXtermOSC __P((int, char *));
+#endif
+#ifdef COLOR
+extern int color256to16 __P((int));
+# ifdef COLORS256
+extern int color256to88 __P((int));
+# endif
+#endif
+extern void ResetIdle __P((void));
+extern void KillBlanker __P((void));
+extern void DisplaySleep1000 __P((int, int));
+
+/* resize.c */
+extern int ChangeWindowSize __P((struct win *, int, int, int));
+extern void ChangeScreenSize __P((int, int, int));
+extern void CheckScreenSize __P((int));
+extern char *xrealloc __P((char *, int));
+extern void ResizeLayersToCanvases __P((void));
+extern void ResizeLayer __P((struct layer *, int, int, struct display *));
+extern int MayResizeLayer __P((struct layer *));
+extern void FreeAltScreen __P((struct win *));
+extern void EnterAltScreen __P((struct win *));
+extern void LeaveAltScreen __P((struct win *));
+
+/* sched.c */
+extern void evenq __P((struct event *));
+extern void evdeq __P((struct event *));
+extern void SetTimeout __P((struct event *, int));
+extern void sched __P((void));
+
+/* socket.c */
+extern int FindSocket __P((int *, int *, int *, char *, bool *));
+extern int MakeClientSocket __P((int, bool));
+extern int MakeServerSocket __P((bool));
+extern int RecoverSocket __P((void));
+extern int chsock __P((void));
+extern void ReceiveMsg __P((void));
+extern void SendCreateMsg __P((char *, struct NewWindow *));
+extern int SendErrorMsg __P((char *, char *));
+extern int SendAttachMsg __P((int, struct msg *, int));
+extern void ReceiveRaw __P((int));
+extern bool IsSocket __P((const char *));
+
+/* misc.c */
+extern char *SaveStr __P((const char *));
+extern char *SaveStrn __P((const char *, int));
+extern char *InStr __P((char *, const char *));
+#ifndef HAVE_STRERROR
+extern char *strerror __P((int));
+#endif
+extern void centerline __P((char *, int));
+extern void leftline __P((char *, int, struct mchar *));
+extern char *Filename __P((char *));
+extern char *stripdev __P((char *));
+#ifdef NEED_OWN_BCOPY
+extern void xbcopy __P((char *, char *, int));
+#endif
+extern void bclear __P((char *, int));
+extern void closeallfiles __P((int));
+extern int UserContext __P((void));
+extern void UserReturn __P((int));
+extern int UserStatus __P((void));
+#if defined(POSIX) || defined(hpux)
+extern void (*xsignal __P((int, void (*)SIGPROTOARG))) __P(SIGPROTOARG);
+#endif
+#ifndef HAVE_RENAME
+extern int rename __P((char *, char *));
+#endif
+#if defined(HAVE_SETEUID) || defined(HAVE_SETREUID)
+extern void xseteuid __P((int));
+extern void xsetegid __P((int));
+#endif
+extern int AddXChar __P((char *, int));
+extern int AddXChars __P((char *, int, char *));
+extern void xsetenv __P((char *, char *));
+extern void sleep1000 __P((int));
+#ifdef DEBUG
+extern void opendebug __P((int, int));
+#endif
+#ifdef USEVARARGS
+# ifndef HAVE_VSNPRINTF
+extern int xvsnprintf __P((char *, int, char *, va_list));
+# endif
+#else
+extern int xsnprintf __P(());
+#endif
+
+
+/* acl.c */
+#ifdef MULTIUSER
+extern int AclCheckPermWin __P((struct acluser *, int, struct win *));
+extern int AclCheckPermCmd __P((struct acluser *, int, struct comm *));
+extern int AclSetPerm __P((struct acluser *, struct acluser *, char *, char *));
+extern int AclUmask __P((struct acluser *, char *, char **));
+extern int UsersAcl __P((struct acluser *, int, char **));
+extern void AclWinSwap __P((int, int));
+extern int NewWindowAcl __P((struct win *, struct acluser *));
+extern void FreeWindowAcl __P((struct win *));
+extern char *DoSu __P((struct acluser **, char *, char *, char *));
+extern int AclLinkUser __P((char *, char *));
+#endif /* MULTIUSER */
+extern int UserFreeCopyBuffer __P((struct acluser *));
+extern struct acluser **FindUserPtr __P((char *));
+extern int UserAdd __P((char *, char *, struct acluser **));
+extern int UserDel __P((char *, struct acluser **));
+
+
+/* braile.c */
+#ifdef HAVE_BRAILLE
+extern void InitBraille __P((void));
+extern void RefreshBraille __P((void));
+extern void DoBrailleAction __P((struct action *, int));
+extern void BGotoPos __P((struct layer *, int, int));
+extern void BPutChar __P((struct layer *, struct mchar *, int, int));
+extern void BPutStr __P((struct layer *, char *, int, struct mchar *, int, int));
+extern void BCDisplayLine __P((struct layer *, struct mline *, int, int, int, int));
+#endif
+
+
+
+
+/* layer.c */
+extern void LGotoPos __P((struct layer *, int, int));
+extern void LPutChar __P((struct layer *, struct mchar *, int, int));
+extern void LInsChar __P((struct layer *, struct mchar *, int, int, struct mline *));
+extern void LPutStr __P((struct layer *, char *, int, struct mchar *, int, int));
+extern void LPutWinMsg __P((struct layer *, char *, int, struct mchar *, int, int));
+extern void LScrollH __P((struct layer *, int, int, int, int, int, struct mline *));
+extern void LScrollV __P((struct layer *, int, int, int, int));
+extern void LClearAll __P((struct layer *, int));
+extern void LClearArea __P((struct layer *, int, int, int, int, int, int));
+extern void LClearLine __P((struct layer *, int, int, int, int, struct mline *));
+extern void LRefreshAll __P((struct layer *, int));
+extern void LCDisplayLine __P((struct layer *, struct mline *, int, int, int, int));
+extern void LCDisplayLineWrap __P((struct layer *, struct mline *, int, int, int, int));
+extern void LSetRendition __P((struct layer *, struct mchar *));
+extern void LWrapChar __P((struct layer *, struct mchar *, int, int, int, int));
+extern void LCursorVisibility __P((struct layer *, int));
+extern void LSetFlow __P((struct layer *, int));
+extern void LKeypadMode __P((struct layer *, int));
+extern void LCursorkeysMode __P((struct layer *, int));
+extern void LMouseMode __P((struct layer *, int));
+#if defined(USEVARARGS)
+extern void LMsg __P((int, const char *, ...)) __attribute__((format(printf, 2, 3)));
+#else
+extern void LMsg __P(());
+#endif
+extern void KillLayerChain __P((struct layer *));
+extern int InitOverlayPage __P((int, struct LayFuncs *, int));
+extern void ExitOverlayPage __P((void));
+extern int LayProcessMouse __P((struct layer *, unsigned char));
+extern void LayProcessMouseSwitch __P((struct layer *, int));
+
+/* teln.c */
+#ifdef BUILTIN_TELNET
+extern int TelOpenAndConnect __P((struct win *));
+extern int TelIsline __P((struct win *p));
+extern void TelProcessLine __P((char **, int *));
+extern int DoTelnet __P((char *, int *, int));
+extern int TelIn __P((struct win *, char *, int, int));
+extern void TelBreak __P((struct win *));
+extern void TelWindowSize __P((struct win *));
+extern void TelStatus __P((struct win *, char *, int));
+#endif
+
+/* nethack.c */
+extern const char *DoNLS __P((const char *));
+
+/* encoding.c */
+#ifdef ENCODINGS
+# ifdef UTF8
+extern void InitBuiltinTabs __P((void));
+extern struct mchar *recode_mchar __P((struct mchar *, int, int));
+extern struct mline *recode_mline __P((struct mline *, int, int, int));
+extern int FromUtf8 __P((int, int *));
+extern void AddUtf8 __P((int));
+extern int ToUtf8 __P((char *, int));
+extern int ToUtf8_comb __P((char *, int));
+extern int utf8_isdouble __P((int));
+extern int utf8_iscomb __P((int));
+extern void utf8_handle_comb __P((int, struct mchar *));
+extern int ContainsSpecialDeffont __P((struct mline *, int, int, int));
+extern int LoadFontTranslation __P((int, char *));
+extern void LoadFontTranslationsForEncoding __P((int));
+# endif /* UTF8 */
+extern void WinSwitchEncoding __P((struct win *, int));
+extern int FindEncoding __P((char *));
+extern char *EncodingName __P((int));
+extern int EncodingDefFont __P((int));
+extern void ResetEncoding __P((struct win *));
+extern int CanEncodeFont __P((int, int));
+extern int DecodeChar __P((int, int, int *));
+extern int RecodeBuf __P((unsigned char *, int, int, int, unsigned char *));
+# ifdef DW_CHARS
+extern int PrepareEncodedChar __P((int));
+# endif
+#endif
+extern int EncodeChar __P((char *, int, int, int *));
+
+/* layout.c */
+extern void RemoveLayout __P((struct layout *));
+extern int LayoutDumpCanvas __P((struct canvas *, char *));
diff --git a/fileio.c b/fileio.c
new file mode 100644
index 0000000..14bb9b1
--- /dev/null
+++ b/fileio.c
@@ -0,0 +1,773 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <pwd.h>
+
+#ifndef SIGINT
+# include <signal.h>
+#endif
+
+#include "config.h"
+#include "screen.h"
+#include "extern.h"
+
+extern struct display *display, *displays;
+extern struct win *fore;
+extern struct layer *flayer;
+extern int real_uid, eff_uid;
+extern int real_gid, eff_gid;
+extern char *extra_incap, *extra_outcap;
+extern char *home, *RcFileName;
+extern char SockPath[], *SockName;
+#ifdef COPY_PASTE
+extern char *BufferFile;
+#endif
+extern int hardcopy_append;
+extern char *hardcopydir;
+
+static char *CatExtra __P((char *, char *));
+static char *findrcfile __P((char *));
+
+
+char *rc_name = "";
+int rc_recursion = 0;
+
+static char * CatExtra(register char *str1, register char *str2) {
+ register char *cp;
+ register int len1, len2, add_colon;
+
+ len1 = strlen(str1);
+ if (len1 == 0)
+ return str2;
+ add_colon = (str1[len1 - 1] != ':');
+ if (str2) {
+ len2 = strlen(str2);
+ if ((cp = realloc(str2, (unsigned) len1 + len2 + add_colon + 1)) == NULL)
+ Panic(0, "%s", strnomem);
+ bcopy(cp, cp + len1 + add_colon, len2 + 1);
+ }
+ else {
+ if ((cp = malloc((unsigned) len1 + add_colon + 1)) == NULL)
+ Panic(0, "%s", strnomem);
+ cp[len1 + add_colon] = '\0';
+ }
+ bcopy(str1, cp, len1);
+ if (add_colon)
+ cp[len1] = ':';
+ return cp;
+}
+
+static char *findrcfile(char *rcfile) {
+ char buf[256];
+ char *p;
+
+ /* Tilde prefix support courtesy <hesso@pool.math.tu-berlin.de>,
+ * taken from a Debian patch. */
+ if (rcfile && *rcfile == '~') {
+ static char rcfilename_tilde_exp[MAXPATHLEN+1];
+ char *slash_position = strchr(rcfile, '/');
+
+ if (slash_position == rcfile+1) {
+ char *home = getenv("HOME");
+ if (!home) {
+ Msg(0, "%s: source: tilde expansion failed", rc_name);
+ return NULL;
+ }
+ snprintf(rcfilename_tilde_exp, MAXPATHLEN, "%s/%s", home, rcfile+2);
+ }
+ else if (slash_position) {
+ struct passwd *p;
+ *slash_position = 0;
+ p = getpwnam(rcfile+1);
+ if (!p){
+ Msg(0, "%s: source: tilde expansion failed for user %s", rc_name, rcfile+1);
+ return NULL;
+ }
+ snprintf(rcfilename_tilde_exp, MAXPATHLEN, "%s/%s", p->pw_dir, slash_position+1);
+ }
+ else {
+ Msg(0, "%s: source: illegal tilde expression.", rc_name);
+ return NULL;
+ }
+ rcfile = rcfilename_tilde_exp;
+ }
+
+ if (rcfile) {
+ char *rcend = rindex(rc_name, '/');
+ if (*rcfile != '/' && rcend && (rcend - rc_name) + strlen(rcfile) + 2 < sizeof(buf)) {
+ strncpy(buf, rc_name, rcend - rc_name + 1);
+ strcpy(buf + (rcend - rc_name) + 1, rcfile);
+ if (access(buf, R_OK) == 0)
+ return SaveStr(buf);
+ }
+ debug1("findrcfile: you specified '%s'\n", rcfile);
+ return SaveStr(rcfile);
+ }
+
+ debug("findrcfile: you specified nothing...\n");
+ if ((p = getenv("SCREENRC")) != NULL && *p != '\0') {
+ debug1(" $SCREENRC has: '%s'\n", p);
+ return SaveStr(p);
+ }
+ else {
+ debug(" ...nothing in $SCREENRC, defaulting $HOME/.screenrc\n");
+ if (strlen(home) > sizeof(buf) - 12)
+ Panic(0, "Rc: home too large");
+ sprintf(buf, "%s/.screenrc", home);
+ return SaveStr(buf);
+ }
+}
+
+/*
+ * this will be called twice:
+ * 1) rcfilename = "/etc/screenrc"
+ * 2) rcfilename = RcFileName
+ */
+int StartRc(char *rcfilename, int nopanic) {
+ register int argc, len;
+ register char *p, *cp;
+ char buf[2048];
+ char *args[MAXARGS];
+ int argl[MAXARGS];
+ FILE *fp;
+ char *oldrc_name = rc_name;
+
+ /* always fix termcap/info capabilities */
+ extra_incap = CatExtra("TF", extra_incap);
+
+ /* Special settings for vt100 and others */
+ if (display && (!strncmp(D_termname, "vt", 2) || !strncmp(D_termname, "xterm", 5)))
+ extra_incap = CatExtra("xn:f0=\033Op:f1=\033Oq:f2=\033Or:f3=\033Os:f4=\033Ot:f5=\033Ou:f6=\033Ov:f7=\033Ow:f8=\033Ox:f9=\033Oy:f.=\033On:f,=\033Ol:fe=\033OM:f+=\033Ok:f-=\033Om:f*=\033Oj:f/=\033Oo:fq=\033OX", extra_incap);
+
+ rc_name = findrcfile(rcfilename);
+ if (rc_name == NULL || (fp = secfopen(rc_name, "r")) == NULL) {
+ const char *rc_nonnull = rc_name ? rc_name : rcfilename;
+ if (!rc_recursion && RcFileName && !strcmp(RcFileName, rc_nonnull)) {
+ /*
+ * User explicitly gave us that name,
+ * this is the only case, where we get angry, if we can't read
+ * the file.
+ */
+ debug3("StartRc: '%s','%s', '%s'\n", RcFileName, rc_name ? rc_name : "(null)", rcfilename);
+ if (!nopanic) Panic(0, "Unable to open \"%s\".", rc_nonnull);
+ /* possibly NOTREACHED */
+ }
+
+ debug1("StartRc: '%s' no good. ignored\n", rc_nonnull);
+ if (rc_name)
+ Free(rc_name);
+ rc_name = oldrc_name;
+ return 1;
+ }
+ while (fgets(buf, sizeof buf, fp) != NULL) {
+ if ((p = rindex(buf, '\n')) != NULL)
+ *p = '\0';
+
+ if ((argc = Parse(buf, sizeof buf, args, argl)) == 0)
+ continue;
+
+ if (strcmp(args[0], "echo") == 0) {
+ if (!display)
+ continue;
+ if (argc < 2 || (argc == 3 && strcmp(args[1], "-n")) || argc > 3) {
+ Msg(0, "%s: 'echo [-n] \"string\"' expected.", rc_name);
+ continue;
+ }
+ AddStr(args[argc - 1]);
+ if (argc != 3) {
+ AddStr("\r\n");
+ Flush(0);
+ }
+ }
+
+ else if (strcmp(args[0], "sleep") == 0) {
+ if (!display)
+ continue;
+ debug("sleeeeeeep\n");
+ if (argc != 2) {
+ Msg(0, "%s: sleep: one numeric argument expected.", rc_name);
+ continue;
+ }
+ DisplaySleep1000(1000 * atoi(args[1]), 1);
+ }
+#ifdef TERMINFO
+ else if (!strcmp(args[0], "termcapinfo") || !strcmp(args[0], "terminfo")) {
+#else
+ else if (!strcmp(args[0], "termcapinfo") || !strcmp(args[0], "termcap")) {
+#endif
+ if (!display)
+ continue;
+ if (argc < 3 || argc > 4) {
+ Msg(0, "%s: %s: incorrect number of arguments.", rc_name, args[0]);
+ continue;
+ }
+
+ for (p = args[1]; p && *p; p = cp) {
+ if ((cp = index(p, '|')) != 0)
+ *cp++ = '\0';
+ len = strlen(p);
+ if (p[len - 1] == '*') {
+ if (!(len - 1) || !strncmp(p, D_termname, len - 1))
+ break;
+ }
+ else if (!strcmp(p, D_termname))
+ break;
+ }
+ if (!(p && *p))
+ continue;
+ extra_incap = CatExtra(args[2], extra_incap);
+ if (argc == 4)
+ extra_outcap = CatExtra(args[3], extra_outcap);
+ }
+ else if (!strcmp(args[0], "source")) {
+ if (rc_recursion <= 10) {
+ rc_recursion++;
+ (void)StartRc(args[1], 0);
+ rc_recursion--;
+ }
+ }
+ }
+ fclose(fp);
+ Free(rc_name);
+ rc_name = oldrc_name;
+ return 0;
+}
+
+void FinishRc(char *rcfilename) {
+ char buf[2048];
+ FILE *fp;
+ char *oldrc_name = rc_name;
+
+ rc_name = findrcfile(rcfilename);
+
+ if (rc_name == NULL || (fp = secfopen(rc_name, "r")) == NULL) {
+ const char *rc_nonnull = rc_name ? rc_name : rcfilename;
+ if (rc_recursion)
+ Msg(errno, "%s: source %s", oldrc_name, rc_nonnull);
+ else if (RcFileName && !strcmp(RcFileName, rc_nonnull)) {
+ /*
+ * User explicitly gave us that name,
+ * this is the only case, where we get angry, if we can't read
+ * the file.
+ */
+ debug3("FinishRc:'%s','%s','%s'\n", RcFileName, rc_name ? rc_name : "(null)", rcfilename);
+ Panic(0, "Unable to open \"%s\".", rc_nonnull);
+ /* NOTREACHED */
+ }
+ debug1("FinishRc: '%s' no good. ignored\n", rc_nonnull);
+ if (rc_name)
+ Free(rc_name);
+ rc_name = oldrc_name;
+ return;
+ }
+
+ debug("finishrc is going...\n");
+ while (fgets(buf, sizeof buf, fp) != NULL)
+ RcLine(buf, sizeof buf);
+ (void) fclose(fp);
+ Free(rc_name);
+ rc_name = oldrc_name;
+}
+
+void do_source(char *rcfilename) {
+ if (rc_recursion > 10) {
+ Msg(0, "%s: source: recursion limit reached", rc_name);
+ return;
+ }
+ rc_recursion++;
+ FinishRc(rcfilename);
+ rc_recursion--;
+}
+
+
+/*
+ * Running a Command Line in the environment determined by the display.
+ * The fore window is taken from the display as well as the user.
+ * This is bad when we run detached.
+ */
+void RcLine(char *ubuf, int ubufl) {
+ char *args[MAXARGS];
+ int argl[MAXARGS];
+#ifdef MULTIUSER
+ extern struct acluser *EffectiveAclUser; /* acl.c */
+ extern struct acluser *users; /* acl.c */
+#endif
+
+ if (display) {
+ fore = D_fore;
+ flayer = D_forecv->c_layer;
+ }
+ else
+ flayer = fore ? fore->w_savelayer : 0;
+ if (Parse(ubuf, ubufl, args, argl) <= 0)
+ return;
+
+#ifdef MULTIUSER
+ if (!display) {
+ /* the session owner does it, when there is no display here */
+ EffectiveAclUser = users;
+ debug("RcLine: WARNING, no display no user! Session owner executes command\n");
+ }
+#endif
+
+ DoCommand(args, argl);
+
+#ifdef MULTIUSER
+ EffectiveAclUser = 0;
+#endif
+}
+
+/* needs display for copybuffer access and termcap dumping */
+void WriteFile(struct acluser *user, char *fn, int dump) {
+ /* dump==0: create .termcap,
+ * dump==1: hardcopy,
+ * #ifdef COPY_PASTE
+ * dump==2: BUFFERFILE
+ * #endif COPY_PASTE
+ * dump==1: scrollback,
+ */
+ register int i, j, k;
+ register char *p;
+ register FILE *f;
+ char fnbuf[1024];
+ char *mode = "w";
+
+#ifdef COPY_PASTE
+ int public = 0;
+# ifdef HAVE_LSTAT
+ struct stat stb, stb2;
+ int fd, exists = 0;
+# endif
+#endif
+
+ switch (dump) {
+ case DUMP_TERMCAP:
+ if (fn == 0) {
+ i = SockName - SockPath;
+ if (i > (int)sizeof(fnbuf) - 9)
+ i = 0;
+ strncpy(fnbuf, SockPath, i);
+ strcpy(fnbuf + i, ".termcap");
+ fn = fnbuf;
+ }
+ break;
+
+ case DUMP_HARDCOPY:
+ case DUMP_SCROLLBACK:
+ if (fn == 0) {
+ if (fore == 0)
+ return;
+ if (hardcopydir && *hardcopydir && strlen(hardcopydir) < sizeof(fnbuf) - 21)
+ sprintf(fnbuf, "%s/hardcopy.%d", hardcopydir, fore->w_number);
+ else
+ sprintf(fnbuf, "hardcopy.%d", fore->w_number);
+ fn = fnbuf;
+ }
+ if (hardcopy_append && !access(fn, W_OK))
+ mode = "a";
+ break;
+
+#ifdef COPY_PASTE
+ case DUMP_EXCHANGE:
+ if (fn == 0) {
+ strncpy(fnbuf, BufferFile, sizeof(fnbuf) - 1);
+ fnbuf[sizeof(fnbuf) - 1] = 0;
+ fn = fnbuf;
+ }
+ public = !strcmp(fn, DEFAULT_BUFFERFILE);
+# ifdef HAVE_LSTAT
+ exists = !lstat(fn, &stb);
+ if (public && exists && (S_ISLNK(stb.st_mode) || stb.st_nlink > 1)) {
+ Msg(0, "No write to links, please.");
+ return;
+ }
+# endif
+ break;
+#endif
+ }
+
+ debug2("WriteFile(%d) %s\n", dump, fn);
+ if (UserContext() > 0) {
+ debug("Writefile: usercontext\n");
+#ifdef COPY_PASTE
+ if (dump == DUMP_EXCHANGE && public) {
+# ifdef HAVE_LSTAT
+ if (exists) {
+ if ((fd = open(fn, O_WRONLY, 0666)) >= 0) {
+ if (fstat(fd, &stb2) == 0 && stb.st_dev == stb2.st_dev && stb.st_ino == stb2.st_ino)
+ ftruncate(fd, 0);
+ else {
+ close(fd);
+ fd = -1;
+ }
+ }
+ }
+ else
+ fd = open(fn, O_WRONLY|O_CREAT|O_EXCL, 0666);
+ f = fd >= 0 ? fdopen(fd, mode) : 0;
+# else
+ f = fopen(fn, mode);
+# endif
+ }
+ else
+#endif /* COPY_PASTE */
+ f = fopen(fn, mode);
+ if (f == NULL) {
+ debug2("WriteFile: fopen(%s,\"%s\") failed\n", fn, mode);
+ UserReturn(0);
+ }
+ else {
+ switch (dump) {
+ case DUMP_HARDCOPY:
+ case DUMP_SCROLLBACK:
+ if (!fore)
+ break;
+ if (*mode == 'a') {
+ putc('>', f);
+ for (j = fore->w_width - 2; j > 0; j--)
+ putc('=', f);
+ fputs("<\n", f);
+ }
+ if (dump == DUMP_SCROLLBACK) {
+#ifdef COPY_PASTE
+ for (i = fore->w_histheight - fore->w_scrollback_height; i < fore->w_histheight; i++) {
+ p = (char *)(WIN(i)->image);
+ for (k = fore->w_width - 1; k >= 0 && p[k] == ' '; k--)
+ ;
+ for (j = 0; j <= k; j++)
+ putc(p[j], f);
+ putc('\n', f);
+ }
+#endif
+ }
+ for (i = 0; i < fore->w_height; i++) {
+ p = (char *)fore->w_mlines[i].image;
+ for (k = fore->w_width - 1; k >= 0 && p[k] == ' '; k--)
+ ;
+ for (j = 0; j <= k; j++)
+ putc(p[j], f);
+ putc('\n', f);
+ }
+ break;
+
+ case DUMP_TERMCAP:
+ if ((p = index(MakeTermcap(fore->w_aflag), '=')) != NULL) {
+ fputs(++p, f);
+ putc('\n', f);
+ }
+ break;
+
+#ifdef COPY_PASTE
+ case DUMP_EXCHANGE:
+ p = user->u_plop.buf;
+ for (i = user->u_plop.len; i-- > 0; p++)
+ if (*p == '\r' && (i == 0 || p[1] != '\n'))
+ putc('\n', f);
+ else
+ putc(*p, f);
+ break;
+#endif
+ }
+ (void) fclose(f);
+ UserReturn(1);
+ }
+ }
+ if (UserStatus() <= 0)
+ Msg(0, "Cannot open \"%s\"", fn);
+ else if (display && !*rc_name) {
+ switch (dump) {
+ case DUMP_TERMCAP:
+ Msg(0, "Termcap entry written to \"%s\".", fn);
+ break;
+ case DUMP_HARDCOPY:
+ case DUMP_SCROLLBACK:
+ Msg(0, "Screen image %s to \"%s\".", (*mode == 'a') ? "appended" : "written", fn);
+ break;
+#ifdef COPY_PASTE
+ case DUMP_EXCHANGE:
+ Msg(0, "Copybuffer written to \"%s\".", fn);
+#endif
+ }
+ }
+}
+
+#ifdef COPY_PASTE
+
+/*
+ * returns an allocated buffer which holds a copy of the file named fn.
+ * lenp (if nonzero) points to a location, where the buffer size should be
+ * stored.
+ */
+char *ReadFile(char *fn, int *lenp) {
+ int i, l, size;
+ char c, *bp, *buf;
+ struct stat stb;
+
+ ASSERT(lenp);
+ debug1("ReadFile(%s)\n", fn);
+
+ if ((i = secopen(fn, O_RDONLY, 0)) < 0) {
+ Msg(errno, "no %s -- no slurp", fn);
+ return NULL;
+ }
+
+ if (fstat(i, &stb)) {
+ Msg(errno, "no good %s -- no slurp", fn);
+ close(i);
+ return NULL;
+ }
+ size = stb.st_size;
+
+ if ((buf = malloc(size)) == NULL) {
+ close(i);
+ Msg(0, "%s", strnomem);
+ return NULL;
+ }
+ errno = 0;
+
+ if ((l = read(i, buf, size)) != size) {
+ if (l < 0)
+ l = 0;
+ Msg(errno, "Got only %d bytes from %s", l, fn);
+ }
+ else {
+ if (read(i, &c, 1) > 0)
+ Msg(0, "Slurped only %d characters (of %d) into buffer - try again", l, size);
+ else
+ Msg(0, "Slurped %d characters into buffer", l);
+ }
+ close(i);
+ *lenp = l;
+ for (bp = buf; l-- > 0; bp++)
+ if (*bp == '\n' && (bp == buf || bp[-1] != '\r'))
+ *bp = '\r';
+ return buf;
+}
+
+void KillBuffers() {
+ if (UserContext() > 0)
+ UserReturn(unlink(BufferFile) ? errno : 0);
+ errno = UserStatus();
+ Msg(errno, "%s %sremoved", BufferFile, errno ? "not " : "");
+}
+#endif /* COPY_PASTE */
+
+
+/* (Almost) secure open and fopen... */
+
+FILE *secfopen(char *name, char *mode) {
+ FILE *fi;
+#ifndef USE_SETEUID
+ int flags, fd;
+#endif
+
+ debug2("secfopen(%s, %s)\n", name, mode);
+#ifdef USE_SETEUID
+ xseteuid(real_uid);
+ xsetegid(real_gid);
+ fi = fopen(name, mode);
+ xseteuid(eff_uid);
+ xsetegid(eff_gid);
+ return fi;
+
+#else
+ if (eff_uid == real_uid)
+ return fopen(name, mode);
+ if (mode[0] && mode[1] == '+')
+ flags = O_RDWR;
+ else
+ flags = (mode[0] == 'r') ? O_RDONLY : O_WRONLY;
+ if (mode[0] == 'w')
+ flags |= O_CREAT | O_TRUNC;
+ else if (mode[0] == 'a')
+ flags |= O_CREAT | O_APPEND;
+ else if (mode[0] != 'r') {
+ errno = EINVAL;
+ return 0;
+ }
+ if ((fd = secopen(name, flags, 0666)) < 0)
+ return 0;
+ if ((fi = fdopen(fd, mode)) == 0) {
+ close(fd);
+ return 0;
+ }
+ return fi;
+#endif
+}
+
+
+int secopen(char *name, int flags, int mode) {
+ int fd;
+#ifndef USE_SETEUID
+ int q;
+ struct stat stb;
+#endif
+
+ debug3("secopen(%s, 0x%x, 0%03o)\n", name, flags, mode);
+#ifdef USE_SETEUID
+ xseteuid(real_uid);
+ xsetegid(real_gid);
+ fd = open(name, flags, mode);
+ xseteuid(eff_uid);
+ xsetegid(eff_gid);
+ return fd;
+#else
+ if (eff_uid == real_uid)
+ return open(name, flags, mode);
+ /* Truncation/creation is done in UserContext */
+ if ((flags & O_TRUNC) || ((flags & O_CREAT) && access(name, F_OK))) {
+ if (UserContext() > 0) {
+ if ((fd = open(name, flags, mode)) >= 0) {
+ close(fd);
+ UserReturn(0);
+ }
+ if (errno == 0)
+ errno = EACCES;
+ UserReturn(errno);
+ }
+ if ((q = UserStatus())) {
+ if (q > 0)
+ errno = q;
+ return -1;
+ }
+ }
+ if (access(name, F_OK))
+ return -1;
+ if ((fd = open(name, flags & ~(O_TRUNC | O_CREAT), 0)) < 0)
+ return -1;
+ debug("open successful\n");
+ if (fstat(fd, &stb)) {
+ close(fd);
+ return -1;
+ }
+ debug("fstat successful\n");
+ if (stb.st_uid != real_uid) {
+ switch (flags & (O_RDONLY | O_WRONLY | O_RDWR)) {
+ case O_RDONLY:
+ q = 0004;
+ break;
+ case O_WRONLY:
+ q = 0002;
+ break;
+ default:
+ q = 0006;
+ break;
+ }
+ if ((stb.st_mode & q) != q) {
+ debug1("secopen: permission denied (%03o)\n", stb.st_mode & 07777);
+ close(fd);
+ errno = EACCES;
+ return -1;
+ }
+ }
+ debug1("secopen ok - returning %d\n", fd);
+ return fd;
+#endif
+}
+
+
+int printpipe(struct win *p, char *cmd) {
+ int pi[2];
+ if (pipe(pi)) {
+ WMsg(p, errno, "printing pipe");
+ return -1;
+ }
+ switch (fork()) {
+ case -1:
+ WMsg(p, errno, "printing fork");
+ return -1;
+ case 0:
+ display = p->w_pdisplay;
+ displays = 0;
+
+#ifdef DEBUG
+ if (dfp && dfp != stderr)
+ fclose(dfp);
+#endif
+ close(0);
+ dup(pi[0]);
+ closeallfiles(0);
+ if (setgid(real_gid) || setuid(real_uid))
+ Panic(errno, "printpipe setuid");
+
+#ifdef SIGPIPE
+ signal(SIGPIPE, SIG_DFL);
+#endif
+ execl("/bin/sh", "sh", "-c", cmd, (char *)0);
+ Panic(errno, "/bin/sh");
+ default:
+ break;
+ }
+ close(pi[0]);
+ return pi[1];
+}
+
+int readpipe(char **cmdv) {
+ int pi[2];
+
+ if (pipe(pi)) {
+ Msg(errno, "pipe");
+ return -1;
+ }
+
+ switch (fork()) {
+ case -1:
+ Msg(errno, "fork");
+ return -1;
+ case 0:
+ displays = 0;
+#ifdef DEBUG
+ if (dfp && dfp != stderr)
+ fclose(dfp);
+#endif
+ close(1);
+ if (dup(pi[1]) != 1) {
+ close(pi[1]);
+ Panic(0, "dup");
+ }
+ closeallfiles(1);
+
+ if (setgid(real_gid) || setuid(real_uid)) {
+ close(1);
+ Panic(errno, "setuid/setgid");
+ }
+#ifdef SIGPIPE
+ signal(SIGPIPE, SIG_DFL);
+#endif
+ execvp(*cmdv, cmdv);
+ close(1);
+ Panic(errno, "%s", *cmdv);
+ default:
+ break;
+ }
+ close(pi[1]);
+ return pi[0];
+}
diff --git a/help.c b/help.c
new file mode 100644
index 0000000..ea6c15d
--- /dev/null
+++ b/help.c
@@ -0,0 +1,934 @@
+/* Copyright (c) 2010
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+
+#include "config.h"
+#include "screen.h"
+#include "extern.h"
+#include "list_generic.h"
+
+char version[60]; /* initialised by main() */
+
+extern struct layer *flayer;
+extern struct display *display, *displays;
+extern struct win *windows;
+extern int maxwin;
+extern char *noargs[];
+extern struct mchar mchar_blank, mchar_so;
+extern int renditions[];
+extern unsigned char *blank;
+extern struct win **wtab;
+#ifdef MAPKEYS
+extern struct term term[];
+#endif
+
+extern struct LayFuncs ListLf;
+
+static void PadStr __P((char *, int, int, int));
+
+extern char *wliststr;
+extern char *wlisttit;
+
+void exit_with_usage(char *myname, char *message, char *arg)
+{
+ printf("Use: %s [-opts] [cmd [args]]\n", myname);
+ printf(" or: %s -r [host.tty]\n\nOptions:\n", myname);
+#ifdef BUILTIN_TELNET
+ printf("-4 Resolve hostnames only to IPv4 addresses.\n");
+ printf("-6 Resolve hostnames only to IPv6 addresses.\n");
+#endif
+ printf("-a Force all capabilities into each window's termcap.\n");
+ printf("-A -[r|R] Adapt all windows to the new display width & height.\n");
+ printf("-c file Read configuration file instead of '.screenrc'.\n");
+#ifdef REMOTE_DETACH
+ printf("-d (-r) Detach the elsewhere running screen (and reattach here).\n");
+ printf("-dmS name Start as daemon: Screen session in detached mode.\n");
+ printf("-D (-r) Detach and logout remote (and reattach here).\n");
+ printf("-D -RR Do whatever is needed to get a screen session.\n");
+#endif
+ printf("-e xy Change command characters.\n");
+ printf("-f Flow control on, -fn = off, -fa = auto.\n");
+ printf("-h lines Set the size of the scrollback history buffer.\n");
+ printf("-i Interrupt output sooner when flow control is on.\n");
+#if defined(LOGOUTOK) && defined(UTMPOK)
+ printf("-l Login mode on (update %s), -ln = off.\n", UTMPFILE);
+#endif
+ printf("-ls [match] or\n");
+ printf("-list Do nothing, just list our SockDir [on possible matches].\n");
+ printf("-L Turn on output logging.\n");
+ printf("-Logfile file Set logfile name.\n");
+ printf("-m ignore $STY variable, do create a new screen session.\n");
+ printf("-O Choose optimal output rather than exact vt100 emulation.\n");
+ printf("-p window Preselect the named window if it exists.\n");
+ printf("-q Quiet startup. Exits with non-zero return code if unsuccessful.\n");
+ printf("-Q Commands will send the response to the stdout of the querying process.\n");
+ printf("-r [session] Reattach to a detached screen process.\n");
+ printf("-R Reattach if possible, otherwise start a new session.\n");
+ printf("-s shell Shell to execute rather than $SHELL.\n");
+ printf("-S sockname Name this session <pid>.sockname instead of <pid>.<tty>.<host>.\n");
+ printf("-t title Set title. (window's name).\n");
+ printf("-T term Use term as $TERM for windows, rather than \"screen\".\n");
+#ifdef UTF8
+ printf("-U Tell screen to use UTF-8 encoding.\n");
+#endif
+ printf("-v Print \"Screen version %s\".\n", version);
+ printf("-wipe [match] Do nothing, just clean up SockDir [on possible matches].\n");
+#ifdef MULTI
+ printf("-x Attach to a not detached screen. (Multi display mode).\n");
+#endif /* MULTI */
+ printf("-X Execute <cmd> as a screen command in the specified session.\n");
+
+ if (message && *message) {
+ printf("\nError: ");
+ printf(message, arg);
+ printf("\n");
+ }
+ exit(1);
+}
+
+/* Here come the help page routines */
+
+extern struct comm comms[];
+extern struct action ktab[];
+
+static void HelpProcess __P((char **, int *));
+static void HelpAbort __P((void));
+static void HelpRedisplayLine __P((int, int, int, int));
+static void add_key_to_buf __P((char *, int));
+static void AddAction __P((struct action *, int, int));
+static int helppage __P((void));
+
+struct helpdata {
+ char *class;
+ struct action *ktabp;
+ int maxrow, grow, numcols, numrows, num_names;
+ int numskip, numpages;
+ int command_search, command_bindings;
+ int refgrow, refcommand_search;
+ int inter, mcom, mkey;
+ int nact[RC_LAST + 1];
+};
+
+#define MAXKLEN 256
+
+static struct LayFuncs HelpLf =
+{
+ HelpProcess,
+ HelpAbort,
+ HelpRedisplayLine,
+ DefClearLine,
+ DefRewrite,
+ DefResize,
+ DefRestore,
+ 0
+};
+
+
+void display_help(char *class, struct action *ktabp) {
+ int i, n, key, mcom, mkey, l, used[RC_LAST + 1];
+ struct helpdata *helpdata;
+
+ if (flayer->l_height < 6) {
+ LMsg(0, "Window height too small for help page");
+ return;
+ }
+ if (InitOverlayPage(sizeof(*helpdata), &HelpLf, 0))
+ return;
+
+ helpdata = (struct helpdata *)flayer->l_data;
+ helpdata->class = class;
+ helpdata->ktabp = ktabp;
+ helpdata->num_names = helpdata->command_bindings = 0;
+ helpdata->command_search = 0;
+ for (n = 0; n <= RC_LAST; n++)
+ used[n] = 0;
+ mcom = 0;
+ mkey = 0;
+ for (key = 0; key < 256 + KMAP_KEYS; key++) {
+ n = ktabp[key].nr;
+ if (n == RC_ILLEGAL)
+ continue;
+ if (ktabp[key].args == noargs) {
+ used[n] += (key <= ' ' || key == 0x7f) ? 3 : (key > 0x7f) ? 5 : 2;
+ }
+ else
+ helpdata->command_bindings++;
+ }
+ for (n = i = 0; n <= RC_LAST; n++)
+ if (used[n]) {
+ l = strlen(comms[n].name);
+ if (l > mcom)
+ mcom = l;
+ if (used[n] > mkey)
+ mkey = used[n];
+ helpdata->nact[i++] = n;
+ }
+
+ debug1("help: %d commands bound to keys with no arguments\n", i);
+ debug2("mcom: %d mkey: %d\n", mcom, mkey);
+ helpdata->num_names = i;
+
+ if (mkey > MAXKLEN)
+ mkey = MAXKLEN;
+ helpdata->numcols = flayer->l_width / (mcom + mkey + 1);
+ if (helpdata->numcols == 0) {
+ HelpAbort();
+ LMsg(0, "Width too small");
+ return;
+ }
+
+ helpdata->inter = (flayer->l_width - (mcom + mkey) * helpdata->numcols) / (helpdata->numcols + 1);
+ if (helpdata->inter <= 0)
+ helpdata->inter = 1;
+ debug1("inter: %d\n", helpdata->inter);
+ helpdata->mcom = mcom;
+ helpdata->mkey = mkey;
+ helpdata->numrows = (helpdata->num_names + helpdata->numcols - 1) / helpdata->numcols;
+ debug1("Numrows: %d\n", helpdata->numrows);
+ helpdata->numskip = flayer->l_height-5 - (2 + helpdata->numrows);
+
+ while (helpdata->numskip < 0)
+ helpdata->numskip += flayer->l_height-5;
+ helpdata->numskip %= flayer->l_height-5;
+ debug1("Numskip: %d\n", helpdata->numskip);
+
+ if (helpdata->numskip > flayer->l_height/3 || helpdata->numskip > helpdata->command_bindings)
+ helpdata->numskip = 1;
+ helpdata->maxrow = 2 + helpdata->numrows + helpdata->numskip + helpdata->command_bindings;
+ helpdata->grow = 0;
+
+ helpdata->numpages = (helpdata->maxrow + flayer->l_height-6) / (flayer->l_height-5);
+ flayer->l_x = 0;
+ flayer->l_y = flayer->l_height - 1;
+ helppage();
+}
+
+static void HelpProcess(char **ppbuf, int *plen) {
+ int done = 0;
+
+ while (!done && *plen > 0) {
+ switch (**ppbuf) {
+ case ' ':
+ if (helppage() == 0)
+ break;
+ /* FALLTHROUGH */
+ case '\r':
+ case '\n':
+ done = 1;
+ break;
+ default:
+ break;
+ }
+ ++*ppbuf;
+ --*plen;
+ }
+ if (done)
+ HelpAbort();
+}
+
+static void HelpAbort() {
+ LAY_CALL_UP(LRefreshAll(flayer, 0));
+ ExitOverlayPage();
+}
+
+static int helppage() {
+ struct helpdata *helpdata;
+ int col, crow, n, key, x;
+ char buf[MAXKLEN], Esc_buf[5], cbuf[256];
+ struct action *ktabp;
+
+ helpdata = (struct helpdata *)flayer->l_data;
+
+ ktabp = helpdata->ktabp;
+ if (helpdata->grow >= helpdata->maxrow)
+ return -1;
+ helpdata->refgrow = helpdata->grow;
+ helpdata->refcommand_search = helpdata->command_search;
+
+ /* Clear the help screen */
+ LClearAll(flayer, 0);
+
+ sprintf(cbuf,"Screen key bindings, page %d of %d.", helpdata->grow / (flayer->l_height-5) + 1, helpdata->numpages);
+ centerline(cbuf, 0);
+ crow = 2;
+
+ *Esc_buf = '\0';
+ *buf = '\0';
+ /* XXX fix escape character */
+ if (flayer->l_cvlist && flayer->l_cvlist->c_display) {
+ add_key_to_buf(buf, flayer->l_cvlist->c_display->d_user->u_MetaEsc);
+ add_key_to_buf(Esc_buf, flayer->l_cvlist->c_display->d_user->u_Esc);
+ }
+ else {
+ strcpy(Esc_buf, "??");
+ strcpy(buf, "??");
+ }
+
+ for (; crow < flayer->l_height - 3; crow++) {
+ if (helpdata->grow < 1) {
+ if (ktabp == ktab)
+ sprintf(cbuf,"Command key: %s Literal %s: %s", Esc_buf, Esc_buf, buf);
+ else
+ sprintf(cbuf,"Command class: '%.80s'", helpdata->class);
+
+ centerline(cbuf, crow);
+ helpdata->grow++;
+ }
+
+ else if (helpdata->grow >= 2 && helpdata->grow-2 < helpdata->numrows) {
+ x = 0;
+ for (col = 0; col < helpdata->numcols && (n = helpdata->numrows * col + (helpdata->grow-2)) < helpdata->num_names; col++) {
+ x += helpdata->inter - !col;
+ n = helpdata->nact[n];
+ buf[0] = '\0';
+ for (key = 0; key < 256 + KMAP_KEYS; key++)
+ if (ktabp[key].nr == n && ktabp[key].args == noargs && strlen(buf) < sizeof(buf) - 7) {
+ strcat(buf, " ");
+ add_key_to_buf(buf, key);
+ }
+
+ PadStr(comms[n].name, helpdata->mcom, x, crow);
+ x += helpdata->mcom;
+ PadStr(buf, helpdata->mkey, x, crow);
+ x += helpdata->mkey;
+ }
+ helpdata->grow++;
+ }
+
+ else if (helpdata->grow-2-helpdata->numrows >= helpdata->numskip
+ && helpdata->grow-2-helpdata->numrows-helpdata->numskip < helpdata->command_bindings) {
+ while ((n = ktabp[helpdata->command_search].nr) == RC_ILLEGAL || ktabp[helpdata->command_search].args == noargs) {
+ if (++helpdata->command_search >= 256 + KMAP_KEYS)
+ return -1;
+ }
+
+ buf[0] = '\0';
+ add_key_to_buf(buf, helpdata->command_search);
+ PadStr(buf, 5, 0, crow);
+ AddAction(&ktabp[helpdata->command_search++], 5, crow);
+ helpdata->grow++;
+ }
+
+ else
+ helpdata->grow++;
+ }
+ sprintf(cbuf,"[Press Space %s Return to end.]", helpdata->grow < helpdata->maxrow ? "for next page;" : "or");
+ centerline(cbuf, flayer->l_height - 2);
+ LaySetCursor();
+ return 0;
+}
+
+static void AddAction(struct action *act, int x, int y) {
+ char buf[256];
+ int del, l, fr;
+ char *bp, *cp, **pp;
+ int *lp, ll;
+ struct mchar mchar_dol;
+
+ mchar_dol = mchar_blank;
+ mchar_dol.image = '$';
+
+ fr = flayer->l_width - 1 - x;
+ if (fr <= 0)
+ return;
+ l = strlen(comms[act->nr].name);
+
+ if (l + 1 > fr)
+ l = fr - 1;
+ PadStr(comms[act->nr].name, l, x, y);
+ x += l;
+ fr -= l + 1;
+ LPutChar(flayer, fr ? &mchar_blank : &mchar_dol, x++, y);
+
+ pp = act->args;
+ lp = act->argl;
+ while (pp && (cp = *pp) != NULL) {
+ del = 0;
+ bp = buf;
+ ll = *lp++;
+ if (!ll || (index(cp, ' ') != NULL)) {
+ if (index(cp, '\'') != NULL)
+ *bp++ = del = '"';
+ else
+ *bp++ = del = '\'';
+ }
+
+ while (ll-- && bp < buf + 250)
+ bp += AddXChar(bp, *(unsigned char *)cp++);
+ if (del)
+ *bp++ = del;
+ *bp = 0;
+ if ((fr -= (bp - buf) + 1) < 0) {
+ fr += bp - buf;
+ if (fr > 0)
+ PadStr(buf, fr, x, y);
+ if (fr == 0)
+ LPutChar(flayer, &mchar_dol, x, y);
+ return;
+ }
+
+ PadStr(buf, strlen(buf), x, y);
+ x += strlen(buf);
+ pp++;
+ if (*pp)
+ LPutChar(flayer, fr ? &mchar_blank : &mchar_dol, x++, y);
+ }
+}
+
+static void add_key_to_buf(char *buf, int key) {
+ buf += strlen(buf);
+ if (key < 0)
+ strcpy(buf, "unset");
+ else if (key == ' ')
+ strcpy(buf, "sp");
+#ifdef MAPKEYS
+ else if (key >= 256) {
+ key = key - 256 + T_CAPS;
+ buf[0] = ':';
+ buf[1] = term[key].tcname[0];
+ buf[2] = term[key].tcname[1];
+ buf[3] = ':';
+ buf[4] = 0;
+ }
+#endif
+ else
+ buf[AddXChar(buf, key)] = 0;
+}
+
+static void HelpRedisplayLine(int y, int xs, int xe, int isblank) {
+ if (y < 0) {
+ struct helpdata *helpdata;
+
+ helpdata = (struct helpdata *)flayer->l_data;
+ helpdata->grow = helpdata->refgrow;
+ helpdata->command_search = helpdata->refcommand_search;
+ helppage();
+ return;
+ }
+ if (y != 0 && y != flayer->l_height - 1)
+ return;
+ if (!isblank)
+ LClearArea(flayer, xs, y, xe, y, 0, 0);
+}
+
+
+/* here is all the copyright stuff */
+
+static void CopyrightProcess __P((char **, int *));
+static void CopyrightRedisplayLine __P((int, int, int, int));
+static void CopyrightAbort __P((void));
+static void copypage __P((void));
+
+struct copydata {
+ char *cps, *savedcps; /* position in the message */
+ char *refcps, *refsavedcps; /* backup for redisplaying */
+};
+
+static struct LayFuncs CopyrightLf = {
+ CopyrightProcess,
+ CopyrightAbort,
+ CopyrightRedisplayLine,
+ DefClearLine,
+ DefRewrite,
+ DefResize,
+ DefRestore,
+ 0
+};
+
+static const char cpmsg[] = "\
+\n\
+GNU Screen version %v\n\
+\n\
+Copyright (c) 2015-2017 Juergen Weigert, Alexander Naumov, Amadeusz Slawinski\n\
+Copyright (c) 2010-2014 Juergen Weigert, Sadrul Habib Chowdhury\n\
+Copyright (c) 2008-2009 Juergen Weigert, Michael Schroeder, Micah Cowan, Sadrul Habib Chowdhury\n\
+Copyright (c) 1993-2007 Juergen Weigert, Michael Schroeder\n\
+Copyright (c) 1987 Oliver Laumann\n\
+\n\
+This program is free software; you can redistribute it and/or \
+modify it under the terms of the GNU General Public License as published \
+by the Free Software Foundation; either version 3, or (at your option) \
+any later version.\n\
+\n\
+This program is distributed in the hope that it will be useful, \
+but WITHOUT ANY WARRANTY; without even the implied warranty of \
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \
+GNU General Public License for more details.\n\
+\n\
+You should have received a copy of the GNU General Public License \
+along with this program (see the file COPYING); if not, see \
+http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc., \
+51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA.\n\
+\n\
+Send bugreports, fixes, enhancements, t-shirts, money, beer & pizza to \
+screen-devel@gnu.org\n\n\n"
+
+"Capabilities:\n"
+
+#ifdef COPY_PASTE
+"+copy "
+#else
+"-copy "
+#endif
+
+#ifdef REMOTE_DETACH
+"+remote-detach "
+#else
+"-remote-detach "
+#endif
+
+#ifdef POW_DETACH
+"+power-detach "
+#else
+"-power-detach "
+#endif
+
+#ifdef MULTI
+"+multi-attach "
+#else
+"-multi-attach "
+#endif
+
+#ifdef MULTIUSER
+"+multi-user "
+#else
+"-multi-user "
+#endif
+
+#ifdef FONT
+"+font "
+#else
+"-font "
+#endif
+
+#ifdef COLORS256
+"+color-256 "
+#elif defined(COLORS16)
+"+color-16 "
+#elif defined(COLOR)
+"+color "
+#else
+"-color "
+#endif
+
+#ifdef UTF8
+"+utf8 "
+#else
+"-utf8 "
+#endif
+
+#ifdef RXVT_OSC
+"+rxvt "
+#else
+"-rxvt "
+#endif
+
+#ifdef BUILTIN_TELNET
+"+builtin-telnet "
+#else
+"-builtin-telnet "
+#endif
+;
+
+static void CopyrightProcess(char **ppbuf, int *plen) {
+ int done = 0;
+ struct copydata *copydata;
+
+ copydata = (struct copydata *)flayer->l_data;
+ while (!done && *plen > 0) {
+ switch (**ppbuf) {
+ case ' ':
+ if (*copydata->cps) {
+ copypage();
+ break;
+ }
+ /* FALLTHROUGH */
+ case '\r':
+ case '\n':
+ CopyrightAbort();
+ done = 1;
+ break;
+ default:
+ break;
+ }
+ ++*ppbuf;
+ --*plen;
+ }
+}
+
+static void CopyrightAbort() {
+ LAY_CALL_UP(LRefreshAll(flayer, 0));
+ ExitOverlayPage();
+}
+
+void display_copyright() {
+ struct copydata *copydata;
+
+ if (flayer->l_width < 10 || flayer->l_height < 5) {
+ LMsg(0, "Window size too small for copyright page");
+ return;
+ }
+ if (InitOverlayPage(sizeof(*copydata), &CopyrightLf, 0))
+ return;
+ copydata = (struct copydata *)flayer->l_data;
+ copydata->cps = (char *)cpmsg;
+ copydata->savedcps = 0;
+ flayer->l_x = 0;
+ flayer->l_y = flayer->l_height - 1;
+ copypage();
+}
+
+static void copypage() {
+ register char *cps;
+ char *ws;
+ int x, y, l;
+ char cbuf[80];
+ struct copydata *copydata;
+
+ ASSERT(flayer);
+ copydata = (struct copydata *)flayer->l_data;
+
+ LClearAll(flayer, 0);
+ x = y = 0;
+ cps = copydata->cps;
+ copydata->refcps = cps;
+ copydata->refsavedcps = copydata->savedcps;
+ while (*cps && y < flayer->l_height - 3) {
+ ws = cps;
+ while (*cps == ' ')
+ cps++;
+ if (strncmp(cps, "%v", 2) == 0) {
+ copydata->savedcps = cps + 2;
+ cps = version;
+ continue;
+ }
+ while (*cps && *cps != ' ' && *cps != '\n')
+ cps++;
+
+ l = cps - ws;
+ cps = ws;
+ if (l > flayer->l_width - 1)
+ l = flayer->l_width - 1;
+
+ if (x && x + l >= flayer->l_width - 2) {
+ x = 0;
+ y++;
+ continue;
+ }
+
+ if (x) {
+ LPutChar(flayer, &mchar_blank, x, y);
+ x++;
+ }
+
+ if (l)
+ LPutStr(flayer, ws, l, &mchar_blank, x, y);
+ x += l;
+ cps += l;
+ if (*cps == 0 && copydata->savedcps) {
+ cps = copydata->savedcps;
+ copydata->savedcps = 0;
+ }
+
+ if (*cps == '\n') {
+ x = 0;
+ y++;
+ }
+
+ if (*cps == ' ' || *cps == '\n')
+ cps++;
+ }
+ while (*cps == '\n')
+ cps++;
+ sprintf(cbuf,"[Press Space %s Return to end.]", *cps ? "for next page;" : "or");
+ centerline(cbuf, flayer->l_height - 2);
+ copydata->cps = cps;
+ LaySetCursor();
+}
+
+static void CopyrightRedisplayLine(int y, int xs, int xe, int isblank) {
+ ASSERT(flayer);
+ if (y < 0) {
+ struct copydata *copydata;
+
+ copydata = (struct copydata *)flayer->l_data;
+ copydata->cps = copydata->refcps;
+ copydata->savedcps = copydata->refsavedcps;
+ copypage();
+ return;
+ }
+ if (y != 0 && y != flayer->l_height - 1)
+ return;
+ if (isblank)
+ return;
+ LClearArea(flayer, xs, y, xe, y, 0, 0);
+}
+
+
+/* The bindkey help page */
+
+#ifdef MAPKEYS
+extern struct kmap_ext *kmap_exts;
+extern int kmap_extn;
+extern struct action dmtab[];
+extern struct action mmtab[];
+
+static void BindkeyProcess __P((char **, int *));
+static void BindkeyAbort __P((void));
+static void BindkeyRedisplayLine __P((int, int, int, int));
+static void bindkeypage __P((void));
+
+struct bindkeydata {
+ char *title;
+ struct action *tab;
+ int pos;
+ int last;
+ int page;
+ int pages;
+};
+
+static struct LayFuncs BindkeyLf = {
+ BindkeyProcess,
+ BindkeyAbort,
+ BindkeyRedisplayLine,
+ DefClearLine,
+ DefRewrite,
+ DefResize,
+ DefRestore,
+ 0
+};
+
+
+void display_bindkey(char *title, struct action *tab) {
+ struct bindkeydata *bindkeydata;
+ int i, n;
+
+ if (flayer->l_height < 6) {
+ LMsg(0, "Window height too small for bindkey page");
+ return;
+ }
+ if (InitOverlayPage(sizeof(*bindkeydata), &BindkeyLf, 0))
+ return;
+
+ bindkeydata = (struct bindkeydata *)flayer->l_data;
+ bindkeydata->title = title;
+ bindkeydata->tab = tab;
+
+ n = 0;
+ for (i = 0; i < KMAP_KEYS+KMAP_AKEYS+kmap_extn; i++) {
+ if (tab[i].nr != RC_ILLEGAL)
+ n++;
+ }
+ bindkeydata->pos = 0;
+ bindkeydata->page = 1;
+ bindkeydata->pages = (n + flayer->l_height - 6) / (flayer->l_height - 5);
+ if (bindkeydata->pages == 0)
+ bindkeydata->pages = 1;
+ flayer->l_x = 0;
+ flayer->l_y = flayer->l_height - 1;
+ bindkeypage();
+}
+
+static void BindkeyAbort() {
+ LAY_CALL_UP(LRefreshAll(flayer, 0));
+ ExitOverlayPage();
+}
+
+static void bindkeypage() {
+ struct bindkeydata *bindkeydata;
+ struct kmap_ext *kme;
+ char tbuf[256];
+ int del, i, y, sl;
+ struct action *act;
+ char *xch, *s, *p;
+
+ bindkeydata = (struct bindkeydata *)flayer->l_data;
+ LClearAll(flayer, 0);
+
+ sprintf(tbuf, "%s key bindings, page %d of %d.", bindkeydata->title, bindkeydata->page, bindkeydata->pages);
+ centerline(tbuf, 0);
+ y = 2;
+ for (i = bindkeydata->pos; i < KMAP_KEYS+KMAP_AKEYS+kmap_extn && y < flayer->l_height - 3; i++) {
+ p = tbuf;
+ xch = " ";
+ if (i < KMAP_KEYS) {
+ act = &bindkeydata->tab[i];
+ if (act->nr == RC_ILLEGAL)
+ continue;
+ del = *p++ = ':';
+ s = term[i + T_CAPS].tcname;
+ sl = s ? strlen(s) : 0;
+ }
+
+ else if (i < KMAP_KEYS+KMAP_AKEYS) {
+ act = &bindkeydata->tab[i];
+ if (act->nr == RC_ILLEGAL)
+ continue;
+ del = *p++ = ':';
+ s = term[i + (T_CAPS - T_OCAPS + T_CURSOR)].tcname;
+ sl = s ? strlen(s) : 0;
+ xch = "[A]";
+ }
+
+ else {
+ kme = kmap_exts + (i - (KMAP_KEYS+KMAP_AKEYS));
+ del = 0;
+ s = kme->str;
+ sl = kme->fl & ~KMAP_NOTIMEOUT;
+ if ((kme->fl & KMAP_NOTIMEOUT) != 0)
+ xch = "[T]";
+ act = bindkeydata->tab == dmtab ? &kme->dm : bindkeydata->tab == mmtab ? &kme->mm : &kme->um;
+ if (act->nr == RC_ILLEGAL)
+ continue;
+ }
+
+ while (sl-- > 0)
+ p += AddXChar(p, *(unsigned char *)s++);
+
+ if (del)
+ *p++ = del;
+
+ *p++ = ' ';
+ while (p < tbuf + 15)
+ *p++ = ' ';
+ sprintf(p, "%s -> ", xch);
+ p += 7;
+ if (p - tbuf > flayer->l_width - 1) {
+ tbuf[flayer->l_width - 2] = '$';
+ tbuf[flayer->l_width - 1] = 0;
+ }
+
+ PadStr(tbuf, strlen(tbuf), 0, y);
+ AddAction(act, strlen(tbuf), y);
+ y++;
+ }
+ y++;
+ bindkeydata->last = i;
+ sprintf(tbuf,"[Press Space %s Return to end.]", bindkeydata->page < bindkeydata->pages ? "for next page;" : "or");
+ centerline(tbuf, flayer->l_height - 2);
+ LaySetCursor();
+}
+
+static void BindkeyProcess(char **ppbuf, int *plen) {
+ int done = 0;
+ struct bindkeydata *bindkeydata;
+
+ bindkeydata = (struct bindkeydata *)flayer->l_data;
+ while (!done && *plen > 0) {
+ switch (**ppbuf) {
+ case ' ':
+ if (bindkeydata->page < bindkeydata->pages) {
+ bindkeydata->pos = bindkeydata->last;
+ bindkeydata->page++;
+ bindkeypage();
+ break;
+ }
+ /* FALLTHROUGH */
+ case '\r':
+ case '\n':
+ done = 1;
+ break;
+ default:
+ break;
+ }
+ ++*ppbuf;
+ --*plen;
+ }
+ if (done)
+ BindkeyAbort();
+}
+
+static void BindkeyRedisplayLine(int y, int xs, int xe, int isblank) {
+ if (y < 0) {
+ bindkeypage();
+ return;
+ }
+ if (y != 0 && y != flayer->l_height - 1)
+ return;
+ if (!isblank)
+ LClearArea(flayer, xs, y, xe, y, 0, 0);
+}
+
+#endif /* MAPKEYS */
+
+/* The zmodem active page */
+
+#ifdef ZMODEM
+
+static void ZmodemRedisplayLine __P((int, int, int, int));
+static int ZmodemResize __P((int, int));
+
+static struct LayFuncs ZmodemLf = {
+ DefProcess,
+ 0,
+ ZmodemRedisplayLine,
+ DefClearLine,
+ DefRewrite,
+ ZmodemResize,
+ DefRestore,
+ 0
+};
+
+/*ARGSUSED*/
+static int ZmodemResize(int wi, int he) {
+ flayer->l_width = wi;
+ flayer->l_height = he;
+ flayer->l_x = flayer->l_width > 32 ? 32 : 0;
+ return 0;
+}
+
+static void ZmodemRedisplayLine(int y, int xs, int xe, int isblank) {
+ DefRedisplayLine(y, xs, xe, isblank);
+ if (y == 0 && xs == 0)
+ LPutStr(flayer, "Zmodem active on another display", flayer->l_width > 32 ? 32 : flayer->l_width, &mchar_blank, 0, 0);
+}
+
+void ZmodemPage() {
+ if (InitOverlayPage(1, &ZmodemLf, 1))
+ return;
+ LRefreshAll(flayer, 0);
+ flayer->l_x = flayer->l_width > 32 ? 32 : 0;
+ flayer->l_y = 0;
+}
+
+#endif
+
+static void PadStr(char *str, int n, int x, int y) {
+ int l;
+
+ l = strlen(str);
+ if (l > n)
+ l = n;
+ LPutStr(flayer, str, l, &mchar_blank, x, y);
+ if (l < n)
+ LPutStr(flayer, (char *)blank, n - l, &mchar_blank, x + l, y);
+}
diff --git a/image.h b/image.h
new file mode 100644
index 0000000..2e9b1a6
--- /dev/null
+++ b/image.h
@@ -0,0 +1,189 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+
+#undef IFFONT
+#undef IFCOLOR
+
+#ifdef FONT
+# define IFFONT(x) x
+# define IFFONTX(x) x
+#else
+# define IFFONT(x)
+# define IFFONTX(x)
+#endif
+
+#ifdef COLOR
+# define IFCOLOR(x) x
+#else
+# define IFCOLOR(x)
+#endif
+
+#if defined(COLOR) && defined(COLORS16) && defined(COLORS256)
+# define IFCOLORX(x) x
+#else
+# define IFCOLORX(x)
+#endif
+
+#ifdef DW_CHARS
+# define IFDWCHAR(x) x
+#else
+# define IFDWCHAR(x)
+#endif
+
+struct mchar {
+ unsigned char image;
+ unsigned char attr;
+IFFONT( unsigned char font; )
+IFFONTX( unsigned char fontx; )
+IFCOLOR( unsigned char color; )
+IFCOLORX(unsigned char colorx; )
+IFDWCHAR(unsigned char mbcs; )
+};
+
+struct mline {
+ unsigned char *image;
+ unsigned char *attr;
+IFFONT( unsigned char *font; )
+IFFONTX( unsigned char *fontx; )
+IFCOLOR( unsigned char *color; )
+IFCOLORX(unsigned char *colorx; )
+};
+
+
+
+#define save_mline(ml, n) do { \
+ bcopy((char *)(ml)->image, (char *)mline_old.image, (n)); \
+ bcopy((char *)(ml)->attr, (char *)mline_old.attr, (n)); \
+IFFONT( bcopy((char *)(ml)->font, (char *)mline_old.font, (n)); ) \
+IFFONTX( bcopy((char *)(ml)->fontx, (char *)mline_old.fontx, (n)); ) \
+IFCOLOR( bcopy((char *)(ml)->color, (char *)mline_old.color, (n)); ) \
+IFCOLORX(bcopy((char *)(ml)->colorx, (char *)mline_old.colorx, (n)); ) \
+} while (0)
+
+#define bcopy_mline(ml, xf, xt, n) do { \
+ bcopy((char *)(ml)->image + (xf), (char *)(ml)->image + (xt), (n)); \
+ bcopy((char *)(ml)->attr + (xf), (char *)(ml)->attr + (xt), (n)); \
+IFFONT( bcopy((char *)(ml)->font + (xf), (char *)(ml)->font + (xt), (n)); ) \
+IFFONTX( bcopy((char *)(ml)->fontx + (xf), (char *)(ml)->fontx + (xt), (n)); ) \
+IFCOLOR( bcopy((char *)(ml)->color + (xf), (char *)(ml)->color + (xt), (n)); ) \
+IFCOLORX(bcopy((char *)(ml)->colorx + (xf), (char *)(ml)->colorx + (xt), (n));) \
+} while (0)
+
+#define clear_mline(ml, x, n) do { \
+ bclear((char *)(ml)->image + (x), (n)); \
+ if ((ml)->attr != null) bzero((char *)(ml)->attr + (x), (n)); \
+IFFONT( if ((ml)->font != null) bzero((char *)(ml)->font + (x), (n)); ) \
+IFFONTX( if ((ml)->fontx != null) bzero((char *)(ml)->fontx + (x), (n)); ) \
+IFCOLOR( if ((ml)->color!= null) bzero((char *)(ml)->color + (x), (n)); ) \
+IFCOLORX(if ((ml)->colorx!= null) bzero((char *)(ml)->colorx + (x), (n)); ) \
+} while (0)
+
+#define cmp_mline(ml1, ml2, x) ( \
+ (ml1)->image[x] == (ml2)->image[x] \
+ && (ml1)->attr[x] == (ml2)->attr[x] \
+IFFONT( && (ml1)->font[x] == (ml2)->font[x] ) \
+IFFONTX( && (ml1)->fontx[x] == (ml2)->fontx[x] ) \
+IFCOLOR( && (ml1)->color[x] == (ml2)->color[x] ) \
+IFCOLORX(&& (ml1)->colorx[x] == (ml2)->colorx[x] ) \
+)
+
+#define cmp_mchar(mc1, mc2) ( \
+ (mc1)->image == (mc2)->image \
+ && (mc1)->attr == (mc2)->attr \
+IFFONT( && (mc1)->font == (mc2)->font ) \
+IFFONTX( && (mc1)->fontx == (mc2)->fontx ) \
+IFCOLOR( && (mc1)->color == (mc2)->color ) \
+IFCOLORX(&& (mc1)->colorx == (mc2)->colorx ) \
+)
+
+#define cmp_mchar_mline(mc, ml, x) ( \
+ (mc)->image == (ml)->image[x] \
+ && (mc)->attr == (ml)->attr[x] \
+IFFONT( && (mc)->font == (ml)->font[x] ) \
+IFFONTX( && (mc)->fontx == (ml)->fontx[x] ) \
+IFCOLOR( && (mc)->color == (ml)->color[x] ) \
+IFCOLORX(&& (mc)->colorx == (ml)->colorx[x] ) \
+)
+
+#define copy_mchar2mline(mc, ml, x) do { \
+ (ml)->image[x] = (mc)->image; \
+ (ml)->attr[x] = (mc)->attr; \
+IFFONT( (ml)->font[x] = (mc)->font; ) \
+IFFONTX( (ml)->fontx[x] = (mc)->fontx; ) \
+IFCOLOR( (ml)->color[x] = (mc)->color; ) \
+IFCOLORX((ml)->colorx[x] = (mc)->colorx; ) \
+} while (0)
+
+#define copy_mline2mchar(mc, ml, x) do { \
+ (mc)->image = (ml)->image[x]; \
+ (mc)->attr = (ml)->attr[x]; \
+IFFONT( (mc)->font = (ml)->font[x]; ) \
+IFFONTX( (mc)->fontx = (ml)->fontx[x]; ) \
+IFCOLOR( (mc)->color = (ml)->color[x]; ) \
+IFCOLORX((mc)->colorx = (ml)->colorx[x]; ) \
+IFDWCHAR((mc)->mbcs = 0; ) \
+} while (0)
+
+#ifdef COLOR
+# ifdef COLORS16
+# ifdef COLORS256
+# define rend_getbg(mc) (((mc)->color & 0xf0) >> 4 | ((mc)->attr & A_BBG ? 0x100 : 0) | ((mc)->colorx & 0xf0))
+# define rend_setbg(mc, c) ((mc)->color = ((mc)->color & 0x0f) | (c << 4 & 0xf0), (mc)->colorx = ((mc)->colorx & 0x0f) | (c & 0xf0), (mc)->attr = ((mc)->attr | A_BBG) ^ (c & 0x100 ? 0 : A_BBG))
+# define rend_getfg(mc) (((mc)->color & 0x0f) | ((mc)->attr & A_BFG ? 0x100 : 0) | (((mc)->colorx & 0x0f) << 4))
+# define rend_setfg(mc, c) ((mc)->color = ((mc)->color & 0xf0) | (c & 0x0f), (mc)->colorx = ((mc)->colorx & 0xf0) | ((c & 0xf0) >> 4), (mc)->attr = ((mc)->attr | A_BFG) ^ (c & 0x100 ? 0 : A_BFG))
+# define rend_setdefault(mc) ((mc)->color = (mc)->colorx = 0, (mc)->attr &= ~(A_BBG|A_BFG))
+# else
+# define rend_getbg(mc) (((mc)->color & 0xf0) >> 4 | ((mc)->attr & A_BBG ? 0x100 : 0))
+# define rend_setbg(mc, c) ((mc)->color = ((mc)->color & 0x0f) | (c << 4 & 0xf0), (mc)->attr = ((mc)->attr | A_BBG) ^ (c & 0x100 ? 0 : A_BBG))
+# define rend_getfg(mc) (((mc)->color & 0x0f) | ((mc)->attr & A_BFG ? 0x100 : 0))
+# define rend_setfg(mc, c) ((mc)->color = ((mc)->color & 0xf0) | (c & 0x0f), (mc)->attr = ((mc)->attr | A_BFG) ^ (c & 0x100 ? 0 : A_BFG))
+# define rend_setdefault(mc) ((mc)->color = 0, (mc)->attr &= ~(A_BBG|A_BFG))
+# endif
+# define coli2e(c) ((((c) & 0x1f8) == 0x108 ? (c) ^ 0x108 : (c & 0xff)) ^ 9)
+# define cole2i(c) ((c) >= 8 && (c) < 16 ? (c) ^ 0x109 : (c) ^ 9)
+# else
+# define rend_getbg(mc) (((mc)->color & 0xf0) >> 4)
+# define rend_setbg(mc, c) ((mc)->color = ((mc)->color & 0x0f) | (c << 4 & 0xf0))
+# define rend_getfg(mc) ((mc)->color & 0x0f)
+# define rend_setfg(mc, c) ((mc)->color = ((mc)->color & 0xf0) | (c & 0x0f))
+# define rend_setdefault(mc) ((mc)->color = 0)
+# define coli2e(c) ((c) ^ 9)
+# define cole2i(c) ((c) ^ 9)
+# endif
+#endif
+
+enum
+{
+ REND_BELL = 0,
+ REND_MONITOR,
+ REND_SILENCE,
+ NUM_RENDS
+};
+
diff --git a/input.c b/input.c
new file mode 100644
index 0000000..c17cd15
--- /dev/null
+++ b/input.c
@@ -0,0 +1,528 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+#include "config.h"
+#include "screen.h"
+#include "extern.h"
+
+#define INPUTLINE (flayer->l_height - 1)
+
+static void InpProcess __P((char **, int *));
+static void InpAbort __P((void));
+static void InpRedisplayLine __P((int, int, int, int));
+
+extern struct layer *flayer;
+extern struct display *display;
+extern struct mchar mchar_blank, mchar_so;
+
+struct inpline
+{
+ char buf[MAXSTR+1]; /* text buffer */
+ int len; /* length of the editible string */
+ int pos; /* cursor position in editable string */
+ struct inpline *next, *prev;
+};
+
+/* 'inphist' is used to store the current input when scrolling through history.
+ * inpline->prev == history-prev
+ * inpline->next == history-next
+ */
+static struct inpline inphist;
+
+struct inpdata
+{
+ struct inpline inp;
+ int inpmaxlen; /* MAXSTR, or less, if caller has shorter buffer */
+ char *inpstring; /* the prompt */
+ int inpstringlen; /* length of the prompt */
+ int inpmode; /* INP_NOECHO, INP_RAW, INP_EVERY */
+ void (*inpfinfunc) __P((char *buf, int len, char *priv));
+ char *priv; /* private data for finfunc */
+ int privdata; /* private data space */
+ char *search; /* the search string */
+};
+
+static struct LayFuncs InpLf =
+{
+ InpProcess,
+ InpAbort,
+ InpRedisplayLine,
+ DefClearLine,
+ DefRewrite,
+ DefResize,
+ DefRestore,
+ 0
+};
+
+/*
+** Here is the input routine
+*/
+
+/* called once, after InitOverlayPage in Input() or Isearch() */
+void
+inp_setprompt(p, s)
+char *p, *s;
+{
+ struct inpdata *inpdata;
+
+ inpdata = (struct inpdata *)flayer->l_data;
+ if (p)
+ {
+ inpdata->inpstringlen = strlen(p);
+ inpdata->inpstring = p;
+ }
+ if (s)
+ {
+ if (s != inpdata->inp.buf)
+ strncpy(inpdata->inp.buf, s, sizeof(inpdata->inp.buf) - 1);
+ inpdata->inp.buf[sizeof(inpdata->inp.buf) - 1] = 0;
+ inpdata->inp.pos = inpdata->inp.len = strlen(inpdata->inp.buf);
+ }
+ InpRedisplayLine(INPUTLINE, 0, flayer->l_width - 1, 0);
+ flayer->l_x = inpdata->inpstringlen + (inpdata->inpmode & INP_NOECHO ? 0 : inpdata->inp.pos);
+ flayer->l_y = INPUTLINE;
+}
+
+/*
+ * We dont use HS status line with Input().
+ * If we would use it, then we should check e_tgetflag("es") if
+ * we are allowed to use esc sequences there.
+ *
+ * mode is an OR of
+ * INP_NOECHO == suppress echoing of characters.
+ * INP_RAW == raw mode. call finfunc after each character typed.
+ * INP_EVERY == digraph mode.
+ */
+void
+Input(istr, len, mode, finfunc, priv, data)
+char *istr;
+int len;
+int mode;
+void (*finfunc) __P((char *buf, int len, char *priv));
+char *priv;
+int data;
+{
+ int maxlen;
+ struct inpdata *inpdata;
+
+ if (!flayer)
+ return;
+
+ if (len > MAXSTR)
+ len = MAXSTR;
+ if (!(mode & INP_NOECHO))
+ {
+ maxlen = flayer->l_width - 1 - strlen(istr);
+ if (len > maxlen)
+ len = maxlen;
+ }
+ if (len < 0)
+ {
+ LMsg(0, "Width %d chars too small", -len);
+ return;
+ }
+ if (InitOverlayPage(sizeof(*inpdata), &InpLf, 1))
+ return;
+ flayer->l_mode = 1;
+ inpdata = (struct inpdata *)flayer->l_data;
+ inpdata->inpmaxlen = len;
+ inpdata->inpfinfunc = finfunc;
+ inpdata->inp.pos = inpdata->inp.len = 0;
+ inpdata->inp.prev = inphist.prev;
+ inpdata->inpmode = mode;
+ inpdata->privdata = data;
+ if (!priv)
+ priv = (char*)&inpdata->privdata;
+ inpdata->priv = priv;
+ inpdata->inpstringlen = 0;
+ inpdata->inpstring = NULL;
+ inpdata->search = NULL;
+ if (istr)
+ inp_setprompt(istr, (char *)NULL);
+}
+
+static void
+erase_chars(inpdata, from, to, x, mv)
+struct inpdata *inpdata;
+char *from;
+char *to;
+int x;
+int mv;
+{
+ int chng;
+ ASSERT(from < to);
+ if (inpdata->inp.len > to - inpdata->inp.buf)
+ bcopy(to, from, inpdata->inp.len - (to - inpdata->inp.buf));
+ chng = to - from;
+ if (mv)
+ {
+ x -= chng;
+ inpdata->inp.pos -= chng;
+ }
+ inpdata->inp.len -= chng;
+ if (!(inpdata->inpmode & INP_NOECHO))
+ {
+ struct mchar mc;
+ char *s = from < to ? from : to;
+ mc = mchar_so;
+ while (s < inpdata->inp.buf+inpdata->inp.len)
+ {
+ mc.image = *s++;
+ LPutChar(flayer, &mc, x++, INPUTLINE);
+ }
+ while (chng--)
+ LPutChar(flayer, &mchar_blank, x++, INPUTLINE);
+ x = inpdata->inpstringlen + inpdata->inp.pos;
+ LGotoPos(flayer, x, INPUTLINE);
+ }
+}
+
+static void
+InpProcess(ppbuf, plen)
+char **ppbuf;
+int *plen;
+{
+ int len, x;
+ char *pbuf;
+ char ch;
+ struct inpdata *inpdata;
+ struct display *inpdisplay;
+ int prev, next, search = 0;
+
+ inpdata = (struct inpdata *)flayer->l_data;
+ inpdisplay = display;
+
+#define RESET_SEARCH do { if (inpdata->search) Free(inpdata->search); } while (0)
+
+ LGotoPos(flayer, inpdata->inpstringlen + (inpdata->inpmode & INP_NOECHO ? 0 : inpdata->inp.pos), INPUTLINE);
+ if (ppbuf == 0)
+ {
+ InpAbort();
+ return;
+ }
+ x = inpdata->inpstringlen + inpdata->inp.pos;
+ len = *plen;
+ pbuf = *ppbuf;
+ while (len)
+ {
+ char *p = inpdata->inp.buf + inpdata->inp.pos;
+
+ ch = *pbuf++;
+ len--;
+ if (inpdata->inpmode & INP_EVERY)
+ {
+ inpdata->inp.buf[inpdata->inp.len] = ch;
+ if (ch)
+ {
+ display = inpdisplay;
+ (*inpdata->inpfinfunc)(inpdata->inp.buf, inpdata->inp.len, inpdata->priv);
+ ch = inpdata->inp.buf[inpdata->inp.len];
+ }
+ }
+ else if (inpdata->inpmode & INP_RAW)
+ {
+ display = inpdisplay;
+ (*inpdata->inpfinfunc)(&ch, 1, inpdata->priv); /* raw */
+ if (ch)
+ continue;
+ }
+ if (((unsigned char)ch & 0177) >= ' ' && ch != 0177 && inpdata->inp.len < inpdata->inpmaxlen)
+ {
+ if (inpdata->inp.len > inpdata->inp.pos)
+ bcopy(p, p+1, inpdata->inp.len - inpdata->inp.pos);
+ inpdata->inp.buf[inpdata->inp.pos++] = ch;
+ inpdata->inp.len++;
+
+ if (!(inpdata->inpmode & INP_NOECHO))
+ {
+ struct mchar mc;
+ mc = mchar_so;
+ mc.image = *p++;
+ LPutChar(flayer, &mc, x, INPUTLINE);
+ x++;
+ if (p < inpdata->inp.buf+inpdata->inp.len)
+ {
+ while (p < inpdata->inp.buf+inpdata->inp.len)
+ {
+ mc.image = *p++;
+ LPutChar(flayer, &mc, x++, INPUTLINE);
+ }
+ x = inpdata->inpstringlen + inpdata->inp.pos;
+ LGotoPos(flayer, x, INPUTLINE);
+ }
+ }
+ RESET_SEARCH;
+ }
+ else if ((ch == '\b' || ch == 0177) && inpdata->inp.pos > 0)
+ {
+ erase_chars(inpdata, p-1, p, x, 1);
+ RESET_SEARCH;
+ }
+ else if (ch == '\025') /* CTRL-U */
+ {
+ x = inpdata->inpstringlen;
+ if (inpdata->inp.len && !(inpdata->inpmode & INP_NOECHO))
+ {
+ LClearArea(flayer, x, INPUTLINE, x + inpdata->inp.len - 1, INPUTLINE, 0, 0);
+ LGotoPos(flayer, x, INPUTLINE);
+ }
+ inpdata->inp.len = inpdata->inp.pos = 0;
+ }
+ else if (ch == '\013') /* CTRL-K */
+ {
+ x = inpdata->inpstringlen + inpdata->inp.pos;
+ if (inpdata->inp.len > inpdata->inp.pos && !(inpdata->inpmode & INP_NOECHO))
+ {
+ LClearArea(flayer, x, INPUTLINE, x + inpdata->inp.len - inpdata->inp.pos - 1, INPUTLINE, 0, 0);
+ LGotoPos(flayer, x, INPUTLINE);
+ }
+ inpdata->inp.len = inpdata->inp.pos;
+ }
+ else if (ch == '\027' && inpdata->inp.pos > 0) /* CTRL-W */
+ {
+ char *oldp = p--;
+ while (p > inpdata->inp.buf && *p == ' ')
+ p--;
+ while (p > inpdata->inp.buf && *(p - 1) != ' ')
+ p--;
+ erase_chars(inpdata, p, oldp, x, 1);
+ RESET_SEARCH;
+ }
+ else if (ch == '\004' && inpdata->inp.pos < inpdata->inp.len) /* CTRL-D */
+ {
+ erase_chars(inpdata, p, p+1, x, 0);
+ RESET_SEARCH;
+ }
+ else if (ch == '\001' || (unsigned char)ch == 0201) /* CTRL-A */
+ {
+ LGotoPos(flayer, x -= inpdata->inp.pos, INPUTLINE);
+ inpdata->inp.pos = 0;
+ }
+ else if ((ch == '\002' || (unsigned char)ch == 0202) && inpdata->inp.pos > 0) /* CTRL-B */
+ {
+ LGotoPos(flayer, --x, INPUTLINE);
+ inpdata->inp.pos--;
+ }
+ else if (ch == '\005' || (unsigned char)ch == 0205) /* CTRL-E */
+ {
+ LGotoPos(flayer, x += inpdata->inp.len - inpdata->inp.pos, INPUTLINE);
+ inpdata->inp.pos = inpdata->inp.len;
+ }
+ else if ((ch == '\006' || (unsigned char)ch == 0206) && inpdata->inp.pos < inpdata->inp.len) /* CTRL-F */
+ {
+ LGotoPos(flayer, ++x, INPUTLINE);
+ inpdata->inp.pos++;
+ }
+ else if ((prev = ((ch == '\020' || (unsigned char)ch == 0220) && /* CTRL-P */
+ inpdata->inp.prev)) ||
+ (next = ((ch == '\016' || (unsigned char)ch == 0216) && /* CTRL-N */
+ inpdata->inp.next)) ||
+ (search = ((ch == '\022' || (unsigned char)ch == 0222) && inpdata->inp.prev)))
+ {
+ struct mchar mc;
+ struct inpline *sel;
+ int pos = -1;
+
+ mc = mchar_so;
+
+ if (prev)
+ sel = inpdata->inp.prev;
+ else if (next)
+ sel = inpdata->inp.next;
+ else
+ {
+ /* search */
+ inpdata->inp.buf[inpdata->inp.len] = 0; /* Remove the ctrl-r from the end */
+ if (!inpdata->search)
+ inpdata->search = SaveStr(inpdata->inp.buf);
+ for (sel = inpdata->inp.prev; sel; sel = sel->prev)
+ {
+ char *f;
+ if ((f = strstr(sel->buf, inpdata->search)))
+ {
+ pos = f - sel->buf;
+ break;
+ }
+ }
+ if (!sel)
+ continue; /* Did not find a match. Process the next input. */
+ }
+
+ if (inpdata->inp.len && !(inpdata->inpmode & INP_NOECHO))
+ LClearArea(flayer, inpdata->inpstringlen, INPUTLINE, inpdata->inpstringlen + inpdata->inp.len - 1, INPUTLINE, 0, 0);
+
+ if ((prev || search) && !inpdata->inp.next)
+ inphist = inpdata->inp;
+ memcpy(&inpdata->inp, sel, sizeof(struct inpline));
+ if (pos != -1)
+ inpdata->inp.pos = pos;
+ if (inpdata->inp.len > inpdata->inpmaxlen)
+ inpdata->inp.len = inpdata->inpmaxlen;
+ if (inpdata->inp.pos > inpdata->inp.len)
+ inpdata->inp.pos = inpdata->inp.len;
+
+ x = inpdata->inpstringlen;
+ p = inpdata->inp.buf;
+
+ if (!(inpdata->inpmode & INP_NOECHO))
+ {
+ while (p < inpdata->inp.buf+inpdata->inp.len)
+ {
+ mc.image = *p++;
+ LPutChar(flayer, &mc, x++, INPUTLINE);
+ }
+ }
+ x = inpdata->inpstringlen + inpdata->inp.pos;
+ LGotoPos(flayer, x, INPUTLINE);
+ }
+
+ else if (ch == '\003' || ch == '\007' || ch == '\033' ||
+ ch == '\000' || ch == '\n' || ch == '\r')
+ {
+ if (ch != '\n' && ch != '\r')
+ inpdata->inp.len = 0;
+ inpdata->inp.buf[inpdata->inp.len] = 0;
+
+ if (inpdata->inp.len && !(inpdata->inpmode & (INP_NOECHO | INP_RAW)))
+ {
+ struct inpline *store;
+
+ /* Look for a duplicate first */
+ for (store = inphist.prev; store; store = store->prev)
+ {
+ if (strcmp(store->buf, inpdata->inp.buf) == 0)
+ {
+ if (store->next)
+ store->next->prev = store->prev;
+ if (store->prev)
+ store->prev->next = store->next;
+ store->pos = inpdata->inp.pos;
+ break;
+ }
+ }
+
+ if (!store)
+ {
+ store = malloc(sizeof(struct inpline));
+ memcpy(store, &inpdata->inp, sizeof(struct inpline));
+ }
+ store->next = &inphist;
+ store->prev = inphist.prev;
+ if (inphist.prev)
+ inphist.prev->next = store;
+ inphist.prev = store;
+ }
+
+ flayer->l_data = 0; /* so inpdata does not get freed */
+ InpAbort(); /* redisplays... */
+ *ppbuf = pbuf;
+ *plen = len;
+ display = inpdisplay;
+ if ((inpdata->inpmode & INP_RAW) == 0)
+ (*inpdata->inpfinfunc)(inpdata->inp.buf, inpdata->inp.len, inpdata->priv);
+ else
+ (*inpdata->inpfinfunc)(pbuf - 1, 0, inpdata->priv);
+ if (inpdata->search)
+ free(inpdata->search);
+ free(inpdata);
+ return;
+ }
+ else
+ {
+ /* The user was searching, and then pressed some non-control input. So reset
+ * the search string. */
+ RESET_SEARCH;
+ }
+ }
+ if (!(inpdata->inpmode & INP_RAW))
+ {
+ flayer->l_x = inpdata->inpstringlen + (inpdata->inpmode & INP_NOECHO ? 0 : inpdata->inp.pos);
+ flayer->l_y = INPUTLINE;
+ }
+ *ppbuf = pbuf;
+ *plen = len;
+}
+
+static void
+InpAbort()
+{
+ LAY_CALL_UP(LayRedisplayLine(INPUTLINE, 0, flayer->l_width - 1, 0));
+ ExitOverlayPage();
+}
+
+static void
+InpRedisplayLine(y, xs, xe, isblank)
+int y, xs, xe, isblank;
+{
+ int q, r, s, l, v;
+ struct inpdata *inpdata;
+
+ inpdata = (struct inpdata *)flayer->l_data;
+ if (y != INPUTLINE)
+ {
+ LAY_CALL_UP(LayRedisplayLine(y, xs, xe, isblank));
+ return;
+ }
+ inpdata->inp.buf[inpdata->inp.len] = 0;
+ q = xs;
+ v = xe - xs + 1;
+ s = 0;
+ r = inpdata->inpstringlen;
+ if (v > 0 && q < r)
+ {
+ l = v;
+ if (l > r - q)
+ l = r - q;
+ LPutStr(flayer, inpdata->inpstring + q - s, l, &mchar_so, q, y);
+ q += l;
+ v -= l;
+ }
+ s = r;
+ r += inpdata->inp.len;
+ if (!(inpdata->inpmode & INP_NOECHO) && v > 0 && q < r)
+ {
+ l = v;
+ if (l > r - q)
+ l = r - q;
+ LPutStr(flayer, inpdata->inp.buf + q - s, l, &mchar_so, q, y);
+ q += l;
+ v -= l;
+ }
+ s = r;
+ r = flayer->l_width;
+ if (!isblank && v > 0 && q < r)
+ {
+ l = v;
+ if (l > r - q)
+ l = r - q;
+ LClearArea(flayer, q, y, q + l - 1, y, 0, 0);
+ q += l;
+ }
+}
+
diff --git a/install.sh b/install.sh
new file mode 100755
index 0000000..8c07c50
--- /dev/null
+++ b/install.sh
@@ -0,0 +1,119 @@
+#! /bin/sh
+
+#
+# install - install a program, script, or datafile
+# This comes from X11R5; it is not part of GNU.
+#
+# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch.
+#
+
+
+# set DOITPROG to echo to test this script
+
+# Don't use :- since 4.3BSD and earlier shells don't like it.
+doit="${DOITPROG-}"
+
+
+# put in absolute paths if you don't have them in your path; or use env. vars.
+
+mvprog="${MVPROG-mv}"
+cpprog="${CPPROG-cp}"
+chmodprog="${CHMODPROG-chmod}"
+chownprog="${CHOWNPROG-chown}"
+chgrpprog="${CHGRPPROG-chgrp}"
+stripprog="${STRIPPROG-strip}"
+rmprog="${RMPROG-rm}"
+
+instcmd="$mvprog"
+chmodcmd=""
+chowncmd=""
+chgrpcmd=""
+stripcmd=""
+rmcmd="$rmprog -f"
+mvcmd="$mvprog"
+src=""
+dst=""
+
+while [ x"$1" != x ]; do
+ case $1 in
+ -c) instcmd="$cpprog"
+ shift
+ continue;;
+
+ -m) chmodcmd="$chmodprog $2"
+ shift
+ shift
+ continue;;
+
+ -o) chowncmd="$chownprog $2"
+ shift
+ shift
+ continue;;
+
+ -g) chgrpcmd="$chgrpprog $2"
+ shift
+ shift
+ continue;;
+
+ -s) stripcmd="$stripprog"
+ shift
+ continue;;
+
+ *) if [ x"$src" = x ]
+ then
+ src=$1
+ else
+ dst=$1
+ fi
+ shift
+ continue;;
+ esac
+done
+
+if [ x"$src" = x ]
+then
+ echo "install: no input file specified"
+ exit 1
+fi
+
+if [ x"$dst" = x ]
+then
+ echo "install: no destination specified"
+ exit 1
+fi
+
+
+# If destination is a directory, append the input filename; if your system
+# does not like double slashes in filenames, you may need to add some logic
+
+if [ -d $dst ]
+then
+ dst="$dst"/`basename $src`
+fi
+
+# Make a temp file name in the proper directory.
+
+dstdir=`dirname $dst`
+dsttmp=$dstdir/#inst.$$#
+
+# Move or copy the file name to the temp name
+
+$doit $instcmd $src $dsttmp
+
+# and set any options; do chmod last to preserve setuid bits
+
+if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; fi
+if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; fi
+if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; fi
+if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; fi
+
+# Now rename the file to the real destination.
+
+$doit $rmcmd $dst
+$doit $mvcmd $dsttmp $dst
+
+
+exit 0
diff --git a/layer.c b/layer.c
new file mode 100644
index 0000000..fc8d03b
--- /dev/null
+++ b/layer.c
@@ -0,0 +1,1230 @@
+/* Copyright (c) 2008-2017
+ * Juergen Weigert <jnweiger@immd4.informatik.uni-erlangen.de>
+ * Michael Schroeder <mlschroe@immd4.informatik.uni-erlangen.de>
+ * Micah Cowan <micah@cowan.name>
+ * Sadrul Habib Chowdhury <sadrul@users.sourceforge.net>
+ *
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert <jnweiger@immd4.informatik.uni-erlangen.de>
+ * Michael Schroeder <mlschroe@immd4.informatik.uni-erlangen.de>
+ *
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+
+#include "config.h"
+#include "screen.h"
+#include "mark.h"
+#include "extern.h"
+#include "braille.h"
+
+extern struct display *display, *displays;
+
+extern struct mline mline_blank, mline_null;
+extern struct mchar mchar_blank, mchar_null;
+
+extern struct layer *flayer; /* sigh */
+extern struct LayFuncs WinLf;
+extern struct LayFuncs BlankLf;
+
+
+static struct mline *mloff __P((struct mline *, int));
+
+/*
+ * Layer subsystem.
+ *
+ * ...here is all the clipping code... beware!
+ *
+ * XXX: add some speedup code!
+ *
+ */
+
+static struct mline *mloff(struct mline *ml, int off)
+{
+ static struct mline mml;
+ if (ml == 0)
+ return 0;
+
+ mml.image = ml->image + off;
+ mml.attr = ml->attr + off;
+#ifdef FONT
+ mml.font = ml->font + off;
+ mml.fontx = ml->fontx + off;
+#endif
+
+#ifdef COLOR
+ mml.color = ml->color + off;
+# ifdef COLORS256
+ mml.colorx = ml->colorx + off;
+# endif
+#endif
+
+ return &mml;
+}
+
+#ifdef UTF8
+# define RECODE_MCHAR(mc) ((l->l_encoding == UTF8) != (D_encoding == UTF8) ? recode_mchar(mc, l->l_encoding, D_encoding) : (mc))
+# define RECODE_MLINE(ml) ((l->l_encoding == UTF8) != (D_encoding == UTF8) ? recode_mline(ml, l->l_width, l->l_encoding, D_encoding) : (ml))
+#else
+# define RECODE_MCHAR(mc) (mc)
+# define RECODE_MLINE(ml) (ml)
+#endif
+
+#define FOR_EACH_UNPAUSED_CANVAS(l, fn) for (cv = (l)->l_cvlist; cv; cv = cv->c_lnext) \
+ { \
+ if ((l)->l_pause.d && cv->c_slorient) \
+ continue; \
+ fn \
+ }
+
+void LGotoPos(struct layer *l, int x, int y)
+{
+ struct canvas *cv;
+ struct viewport *vp;
+ int x2, y2;
+
+ if (l->l_pause.d)
+ LayPauseUpdateRegion(l, x, x, y, y);
+
+#ifdef HAVE_BRAILLE
+ if (bd.bd_refreshing)
+ return;
+#endif
+ FOR_EACH_UNPAUSED_CANVAS(l,
+ {
+ display = cv->c_display;
+ if (D_blocked)
+ continue;
+ if (cv != D_forecv)
+ continue;
+ x2 = x + cv->c_xoff;
+ y2 = y + cv->c_yoff;
+ debug2("---LGotoPos %d %d\n", x2, y2);
+ if (x2 < cv->c_xs)
+ x2 = cv->c_xs;
+ if (y2 < cv->c_ys)
+ y2 = cv->c_ys;
+ if (x2 > cv->c_xe)
+ x2 = cv->c_xe;
+ if (y2 > cv->c_ye)
+ y2 = cv->c_ye;
+ for (vp = cv->c_vplist; vp; vp = vp->v_next) {
+ if (x2 < vp->v_xs || x2 > vp->v_xe)
+ continue;
+ if (y2 < vp->v_ys || y2 > vp->v_ye)
+ continue;
+ GotoPos(x2, y2);
+ break;
+ }
+ }
+ );
+}
+
+void LScrollH(struct layer *l, int n, int y, int xs, int xe, int bce, struct mline *ol)
+{
+ struct canvas *cv;
+ struct viewport *vp;
+ int y2, xs2, xe2;
+
+ if (n == 0)
+ return;
+ if (l->l_pause.d)
+ LayPauseUpdateRegion(l, xs, xe, y, y);
+
+ FOR_EACH_UNPAUSED_CANVAS(l,
+ for (vp = cv->c_vplist; vp; vp = vp->v_next) {
+ y2 = y + vp->v_yoff;
+ if (y2 < vp->v_ys || y2 > vp->v_ye)
+ continue;
+ xs2 = xs + vp->v_xoff;
+ xe2 = xe + vp->v_xoff;
+ if (xs2 < vp->v_xs)
+ xs2 = vp->v_xs;
+ if (xe2 > vp->v_xe)
+ xe2 = vp->v_xe;
+ if (xs2 > xe2)
+ continue;
+ display = cv->c_display;
+ if (D_blocked)
+ continue;
+ ScrollH(y2, xs2, xe2, n, bce, ol ? mloff(ol, -vp->v_xoff) : 0);
+ if (xe2 - xs2 == xe - xs)
+ continue;
+ if (n > 0) {
+ xs2 = xe2 + 1 - n;
+ xe2 = xe + vp->v_xoff - n;
+ }
+ else {
+ xe2 = xs2 - 1 - n;
+ xs2 = xs + vp->v_xoff - n;
+ }
+
+ if (xs2 < vp->v_xs)
+ xs2 = vp->v_xs;
+ if (xe2 > vp->v_xe)
+ xe2 = vp->v_xe;
+ if (xs2 <= xe2)
+ RefreshArea(xs2, y2, xe2, y2, 1);
+ }
+ );
+}
+
+void LScrollV(struct layer *l, int n, int ys, int ye, int bce)
+{
+ struct canvas *cv;
+ struct viewport *vp;
+ int ys2, ye2, xs2, xe2;
+ if (n == 0)
+ return;
+ if (l->l_pause.d)
+ LayPauseUpdateRegion(l, 0, l->l_width - 1, ys, ye);
+ FOR_EACH_UNPAUSED_CANVAS(l,
+ for (vp = cv->c_vplist; vp; vp = vp->v_next) {
+ xs2 = vp->v_xoff;
+ xe2 = l->l_width - 1 + vp->v_xoff;
+ ys2 = ys + vp->v_yoff;
+ ye2 = ye + vp->v_yoff;
+
+ if (xs2 < vp->v_xs)
+ xs2 = vp->v_xs;
+ if (xe2 > vp->v_xe)
+ xe2 = vp->v_xe;
+ if (ys2 < vp->v_ys)
+ ys2 = vp->v_ys;
+ if (ye2 > vp->v_ye)
+ ye2 = vp->v_ye;
+ if (ys2 > ye2 || xs2 > xe2)
+ continue;
+ display = cv->c_display;
+ if (D_blocked)
+ continue;
+#if 0
+ ScrollV(xs2, ys2, xe2, ye2, n, bce);
+#else
+ ScrollV(vp->v_xs, ys2, vp->v_xe, ye2, n, bce);
+#endif
+
+ debug2("LScrollV: %d %d", ys, ye);
+ debug2(" -> %d %d\n", ys2, ye2);
+ if (ye2 - ys2 == ye - ys)
+ continue;
+ if (n > 0) {
+ ys2 = ye2 + 1 - n;
+ ye2 = ye + vp->v_yoff - n;
+ }
+ else {
+ ye2 = ys2 - 1 - n;
+ ys2 = ys + vp->v_yoff - n;
+ }
+
+ debug2("LScrollV: - %d %d\n", ys2, ye2);
+ if (ys2 < vp->v_ys)
+ ys2 = vp->v_ys;
+ if (ye2 > vp->v_ye)
+ ye2 = vp->v_ye;
+ debug2("LScrollV: - %d %d\n", ys2, ye2);
+ if (ys2 <= ye2)
+ RefreshArea(xs2, ys2, xe2, ye2, 1);
+ }
+ );
+}
+
+void LInsChar(struct layer *l, struct mchar *c, int x, int y, struct mline *ol)
+{
+ struct canvas *cv;
+ struct viewport *vp;
+ int xs2, xe2, y2, f;
+ struct mchar *c2, cc;
+ struct mline *rol;
+
+ if (l->l_pause.d)
+ LayPauseUpdateRegion(l, x, l->l_width - 1, y, y);
+ FOR_EACH_UNPAUSED_CANVAS(l,
+ for (vp = cv->c_vplist; vp; vp = vp->v_next) {
+ y2 = y + vp->v_yoff;
+ if (y2 < vp->v_ys || y2 > vp->v_ye)
+ continue;
+ xs2 = x + vp->v_xoff;
+ xe2 = l->l_width - 1 + vp->v_xoff;
+ c2 = c;
+ f = 0;
+ if (xs2 < vp->v_xs) {
+ xs2 = vp->v_xs;
+ c2 = &mchar_blank;
+ if (ol) {
+ int i = xs2 - vp->v_xoff - 1;
+ if (i >= 0 && i < l->l_width) {
+ copy_mline2mchar(&cc, ol, i);
+ c2 = &cc;
+ }
+ }
+ else
+ f = 1;
+ }
+
+ if (xe2 > vp->v_xe)
+ xe2 = vp->v_xe;
+ if (xs2 > xe2)
+ continue;
+ display = cv->c_display;
+ if (D_blocked)
+ continue;
+ rol = RECODE_MLINE(ol);
+ InsChar(RECODE_MCHAR(c2), xs2, xe2, y2, mloff(rol, -vp->v_xoff));
+ if (f)
+ RefreshArea(xs2, y2, xs2, y2, 1);
+ }
+ );
+}
+
+
+void LPutChar(struct layer *l, struct mchar *c, int x, int y)
+{
+ struct canvas *cv;
+ struct viewport *vp;
+ int x2, y2;
+
+#ifdef HAVE_BRAILLE
+ if (bd.bd_refreshing) {
+ BPutChar(l, c, x, y);
+ return;
+ }
+#endif
+
+ if (l->l_pause.d)
+ LayPauseUpdateRegion(l, x,
+
+#ifdef DW_CHARS
+ x + (c->mbcs ? 1 : 0)
+#else
+ x
+#endif
+ , y, y);
+
+
+ FOR_EACH_UNPAUSED_CANVAS(l,
+ {
+ display = cv->c_display;
+ if (D_blocked)
+ continue;
+ for (vp = cv->c_vplist; vp; vp = vp->v_next) {
+ y2 = y + vp->v_yoff;
+ if (y2 < vp->v_ys || y2 > vp->v_ye)
+ continue;
+ x2 = x + vp->v_xoff;
+ if (x2 < vp->v_xs || x2 > vp->v_xe)
+ continue;
+ PutChar(RECODE_MCHAR(c), x2, y2);
+ break;
+ }
+ }
+ );
+}
+
+
+void LPutStr(struct layer *l, char *s, int n, struct mchar *r, int x, int y)
+{
+ struct canvas *cv;
+ struct viewport *vp;
+ char *s2;
+ int xs2, xe2, y2;
+
+ if (x + n > l->l_width)
+ n = l->l_width - x;
+
+#ifdef HAVE_BRAILLE
+ if (bd.bd_refreshing) {
+ BPutStr(l, s, n, r, x, y);
+ return;
+ }
+#endif
+
+ if (l->l_pause.d)
+ LayPauseUpdateRegion(l, x, x + n - 1, y, y);
+
+ FOR_EACH_UNPAUSED_CANVAS(l,
+ for (vp = cv->c_vplist; vp; vp = vp->v_next) {
+ y2 = y + vp->v_yoff;
+ if (y2 < vp->v_ys || y2 > vp->v_ye)
+ continue;
+ xs2 = x + vp->v_xoff;
+ xe2 = xs2 + n - 1;
+ if (xs2 < vp->v_xs)
+ xs2 = vp->v_xs;
+ if (xe2 > vp->v_xe)
+ xe2 = vp->v_xe;
+ if (xs2 > xe2)
+ continue;
+ display = cv->c_display;
+ if (D_blocked)
+ continue;
+ GotoPos(xs2, y2);
+ SetRendition(r);
+ s2 = s + xs2 - x - vp->v_xoff;
+
+#ifdef UTF8
+ if (D_encoding == UTF8 && l->l_encoding != UTF8 && (r->font || r->fontx || l->l_encoding)) {
+ struct mchar mc;
+ mc = *r;
+ while (xs2 <= xe2) {
+ mc.image = *s2++;
+ PutChar(RECODE_MCHAR(&mc), xs2++, y2);
+ }
+ continue;
+ }
+#endif
+
+ while (xs2++ <= xe2)
+ PUTCHARLP(*s2++);
+ }
+ );
+}
+
+
+void LPutWinMsg(struct layer *l, char *s, int n, struct mchar *r, int x, int y)
+{
+ struct canvas *cv;
+ struct viewport *vp;
+ int xs2, xe2, y2, len, len2;
+ struct mchar or;
+
+ if (x + n > l->l_width)
+ n = l->l_width - x;
+
+#ifdef HAVE_BRAILLE
+ if (bd.bd_refreshing) {
+ BPutStr(l, s, n, r, x, y);
+ return;
+ }
+#endif
+
+ if (l->l_pause.d)
+ LayPauseUpdateRegion(l, x, x + n - 1, y, y);
+
+ len = strlen(s);
+ if (len > n)
+ len = n;
+
+ FOR_EACH_UNPAUSED_CANVAS(l,
+ for (vp = cv->c_vplist; vp; vp = vp->v_next) {
+ y2 = y + vp->v_yoff;
+ if (y2 < vp->v_ys || y2 > vp->v_ye)
+ continue;
+ xs2 = x + vp->v_xoff;
+ xe2 = xs2 + n - 1;
+ if (xs2 < vp->v_xs)
+ xs2 = vp->v_xs;
+ if (xe2 > vp->v_xe)
+ xe2 = vp->v_xe;
+ if (xs2 > xe2)
+ continue;
+ display = cv->c_display;
+ if (D_blocked)
+ continue;
+ GotoPos(xs2, y2);
+ SetRendition(r);
+ len2 = xe2 - (x + vp->v_xoff) + 1;
+ if (len2 > len)
+ len2 = len;
+ PutWinMsg(s, xs2 - x - vp->v_xoff, len2);
+ xs2 = x + vp->v_xoff + len2;
+ if (xs2 < vp->v_xs)
+ xs2 = vp->v_xs;
+ or = D_rend;
+ GotoPos(xs2, y2);
+ SetRendition(&or);
+ while (xs2++ <= xe2)
+ PUTCHARLP(' ');
+ }
+ );
+}
+
+
+void LClearLine(struct layer *l, int y, int xs, int xe, int bce, struct mline *ol)
+{
+ struct canvas *cv;
+ struct viewport *vp;
+ int y2, xs2, xe2;
+
+ /* check for magic margin condition */
+ if (xs >= l->l_width)
+ xs = l->l_width - 1;
+ if (xe >= l->l_width)
+ xe = l->l_width - 1;
+ if (l->l_pause.d)
+ LayPauseUpdateRegion(l, xs, xe, y, y);
+
+ FOR_EACH_UNPAUSED_CANVAS(l,
+ for (vp = cv->c_vplist; vp; vp = vp->v_next) {
+ xs2 = xs + vp->v_xoff;
+ xe2 = xe + vp->v_xoff;
+ y2 = y + vp->v_yoff;
+ if (y2 < vp->v_ys || y2 > vp->v_ye)
+ continue;
+ if (xs2 < vp->v_xs)
+ xs2 = vp->v_xs;
+ if (xe2 > vp->v_xe)
+ xe2 = vp->v_xe;
+ if (xs2 > xe2)
+ continue;
+ display = cv->c_display;
+ if (D_blocked)
+ continue;
+ ClearLine(ol ? mloff(RECODE_MLINE(ol), -vp->v_xoff) : (struct mline *)0, y2, xs2, xe2, bce);
+ }
+ );
+}
+
+void LClearArea(struct layer *l, int xs, int ys, int xe, int ye, int bce, int uself)
+{
+ struct canvas *cv;
+ struct viewport *vp;
+ int xs2, ys2, xe2, ye2;
+
+#ifdef HAVE_BRAILLE
+ if (bd.bd_refreshing)
+ return;
+#endif
+
+ /* Check for zero-height window */
+ if (ys < 0 || ye < ys)
+ return;
+
+ /* check for magic margin condition */
+ if (xs >= l->l_width)
+ xs = l->l_width - 1;
+ if (xe >= l->l_width)
+ xe = l->l_width - 1;
+ if (l->l_pause.d)
+ LayPauseUpdateRegion(l, xs, xe, ys, ye);
+
+ FOR_EACH_UNPAUSED_CANVAS(l,
+ {
+ display = cv->c_display;
+ if (D_blocked)
+ continue;
+ for (vp = cv->c_vplist; vp; vp = vp->v_next) {
+ xs2 = xs + vp->v_xoff;
+ xe2 = xe + vp->v_xoff;
+ ys2 = ys + vp->v_yoff;
+ ye2 = ye + vp->v_yoff;
+
+ if (xs2 < vp->v_xs)
+ xs2 = vp->v_xs;
+ if (xe2 > vp->v_xe)
+ xe2 = vp->v_xe;
+ if (xs2 > vp->v_xe)
+ ys2++;
+ if (xe2 < vp->v_xs)
+ ye2--;
+ if (ys2 < vp->v_ys)
+ ys2 = vp->v_ys;
+ if (ye2 > vp->v_ye)
+ ye2 = vp->v_ye;
+ if (ys2 > ye2)
+ continue;
+#if 0
+ xcs = vp->v_xoff;
+ xce = l->l_width - 1 + vp->v_xoff;
+ if (xcs < vp->v_xs)
+ xcs = vp->v_xs;
+ if (xce > vp->v_xe)
+ xce = vp->v_xe;
+ if (xcs > xce)
+ continue;
+ if (ys2 != ys + vp->v_yoff)
+ xs2 = xcs;
+ if (ye2 != ye + vp->v_yoff)
+ xe2 = xce;
+ display = cv->c_display;
+ ClearArea(xs2, ys2, xcs, xce, xe2, ye2, bce, uself);
+#else
+
+ if (xs == 0 || ys2 != ys + vp->v_yoff)
+ xs2 = vp->v_xs;
+ if (xe == l->l_width - 1 || ye2 != ye + vp->v_yoff)
+ xe2 = vp->v_xe;
+ display = cv->c_display;
+ ClearArea(xs2, ys2, vp->v_xs, vp->v_xe, xe2, ye2, bce, uself);
+
+ if (xe == l->l_width - 1 && xe2 > vp->v_xoff + xe) {
+ int y;
+ SetRendition(&mchar_blank);
+ for (y = ys2; y <= ye2; y++) {
+ GotoPos(xe + vp->v_xoff + 1, y);
+ PUTCHARLP('|');
+ }
+ }
+#endif
+ }
+ }
+ );
+}
+
+
+void LCDisplayLine(struct layer *l, struct mline *ml, int y, int xs, int xe, int isblank)
+{
+ struct canvas *cv;
+ struct viewport *vp;
+ int xs2, xe2, y2;
+
+#ifdef HAVE_BRAILLE
+ if (bd.bd_refreshing) {
+ BCDisplayLine(l, ml, y, xs, xe, isblank);
+ return;
+ }
+#endif
+
+ if (l->l_pause.d)
+ LayPauseUpdateRegion(l, xs, xe, y, y);
+
+ FOR_EACH_UNPAUSED_CANVAS(l,
+ {
+ display = cv->c_display;
+ if (D_blocked)
+ continue;
+ for (vp = cv->c_vplist; vp; vp = vp->v_next) {
+ xs2 = xs + vp->v_xoff;
+ xe2 = xe + vp->v_xoff;
+ y2 = y + vp->v_yoff;
+ if (y2 < vp->v_ys || y2 > vp->v_ye)
+ continue;
+ if (xs2 < vp->v_xs)
+ xs2 = vp->v_xs;
+ if (xe2 > vp->v_xe)
+ xe2 = vp->v_xe;
+ if (xs2 > xe2)
+ continue;
+ display = cv->c_display;
+ debug3("LCDisplayLine: DisplayLine %d, %d-%d", y2, xs2, xe2);
+ debug1(" mloff = %d\n", -vp->v_xoff);
+ DisplayLine(isblank ? &mline_blank : &mline_null, mloff(RECODE_MLINE(ml), -vp->v_xoff), y2, xs2, xe2);
+ }
+ }
+ );
+}
+
+
+void LCDisplayLineWrap(struct layer *l, struct mline *ml, int y, int from, int to, int isblank)
+{
+ struct mchar nc;
+ copy_mline2mchar(&nc, ml, 0);
+
+#ifdef DW_CHARS
+ if (dw_left(ml, 0, l->l_encoding)) {
+ nc.mbcs = ml->image[1];
+ from++;
+ }
+#endif
+
+ LWrapChar(l, &nc, y - 1, -1, -1, 0);
+ from++;
+ if (from <= to)
+ LCDisplayLine(l, ml, y, from, to, isblank);
+}
+
+
+void LSetRendition(struct layer *l, struct mchar *r)
+{
+ struct canvas *cv;
+
+ for (cv = l->l_cvlist; cv; cv = cv->c_lnext) {
+ display = cv->c_display;
+ if (D_blocked)
+ continue;
+ SetRendition(r);
+ }
+}
+
+
+void LWrapChar(struct layer *l, struct mchar *c, int y, int top, int bot, int ins)
+{
+ struct canvas *cv, *cvlist, *cvlnext;
+ struct viewport *vp, *evp, **vpp;
+ int yy, y2, yy2, top2, bot2;
+ int bce;
+
+ if (l->l_pause.d)
+ /* XXX: 'y'? */
+ LayPauseUpdateRegion(l, 0, l->l_width - 1, top, bot);
+
+#ifdef COLOR
+ bce = rend_getbg(c);
+#else
+ bce = 0;
+#endif
+
+ if (y != bot) {
+ /* simple case: no scrolling */
+ /* cursor after wrapping */
+ yy = y == l->l_height - 1 ? y : y + 1;
+
+ FOR_EACH_UNPAUSED_CANVAS(l,
+ {
+ y2 = 0; /* gcc -Wall */
+ display = cv->c_display;
+ if (D_blocked)
+ continue;
+
+ /* find the viewport of the wrapped character */
+ for (vp = cv->c_vplist; vp; vp = vp->v_next) {
+ y2 = y + vp->v_yoff;
+ yy2 = yy + vp->v_yoff;
+ if (yy2 >= vp->v_ys && yy2 <= vp->v_ye && vp->v_xoff >= vp->v_xs && vp->v_xoff <= vp->v_xe)
+ break;
+ }
+
+ if (vp == 0)
+ continue; /* nothing to do, character not visible */
+
+ /* find the viewport of the character at the end of the line*/
+ for (evp = cv->c_vplist; evp; evp = evp->v_next)
+ if (y2 >= evp->v_ys && y2 <= evp->v_ye && evp->v_xoff + l->l_width - 1 >= evp->v_xs && evp->v_xoff + l->l_width - 1 <= evp->v_xe)
+ break; /* gotcha! */
+
+ if (evp == 0 || (ins && vp->v_xoff + l->l_width - 1 > vp->v_ye)) {
+ /* no wrapping possible */
+ debug("LWrap: can't wrap!\n");
+ cvlist = l->l_cvlist;
+ cvlnext = cv->c_lnext;
+ l->l_cvlist = cv;
+ cv->c_lnext = 0;
+
+ if (ins)
+ LInsChar(l, c, 0, yy, 0);
+ else
+ LPutChar(l, c, 0, yy);
+
+ l->l_cvlist = cvlist;
+ cv->c_lnext = cvlnext;
+ }
+ else
+ WrapChar(RECODE_MCHAR(c), vp->v_xoff + l->l_width, y2, vp->v_xoff, -1, vp->v_xoff + l->l_width - 1, -1, ins);
+ });
+ }
+ else
+ {
+ /* hard case: scroll up*/
+ FOR_EACH_UNPAUSED_CANVAS(l,
+ {
+ display = cv->c_display;
+ if (D_blocked)
+ continue;
+
+ /* search for wrap viewport */
+ for (vpp = &cv->c_vplist; (vp = *vpp); vpp = &vp->v_next) {
+ yy2 = bot + vp->v_yoff;
+ if (yy2 >= vp->v_ys && yy2 <= vp->v_ye && vp->v_xoff >= vp->v_xs && vp->v_xoff + l->l_width - 1 <= vp->v_xe)
+ break;
+ }
+
+ if (vp) {
+ /* great, can use Wrap on the vp */
+ /* temporarily remove vp from cvlist */
+ *vpp = vp->v_next;
+ }
+
+ if (cv->c_vplist) {
+ /* scroll all viewports != vp */
+ cvlist = l->l_cvlist;
+ cvlnext = cv->c_lnext;
+ l->l_cvlist = cv;
+ cv->c_lnext = 0;
+ LScrollV(l, 1, top, bot, bce);
+ if (!vp) {
+ if (ins)
+ LInsChar(l, c, 0, bot, 0);
+ else
+ LPutChar(l, c, 0, bot);
+ }
+
+ l->l_cvlist = cvlist;
+ cv->c_lnext = cvlnext;
+ }
+ if (vp) {
+ /* add vp back to cvlist */
+ *vpp = vp;
+ top2 = top + vp->v_yoff;
+ bot2 = bot + vp->v_yoff;
+ if (top2 < vp->v_ys)
+ top2 = vp->v_ys;
+ WrapChar(RECODE_MCHAR(c), vp->v_xoff + l->l_width, bot2, vp->v_xoff, top2, vp->v_xoff + l->l_width - 1, bot2, ins);
+ }
+ });
+ }
+}
+
+
+void LCursorVisibility(struct layer *l, int vis)
+{
+ struct canvas *cv;
+ for (cv = l->l_cvlist; cv; cv = cv->c_lnext) {
+ display = cv->c_display;
+ if (D_blocked)
+ continue;
+ if (cv != D_forecv)
+ continue;
+ CursorVisibility(vis);
+ }
+}
+
+
+void LSetFlow(struct layer *l, int flow)
+{
+ struct canvas *cv;
+ for (cv = l->l_cvlist; cv; cv = cv->c_lnext) {
+ display = cv->c_display;
+ if (cv != D_forecv)
+ continue;
+ SetFlow(flow);
+ }
+}
+
+
+void LKeypadMode(struct layer *l, int on)
+{
+ struct canvas *cv;
+ for (cv = l->l_cvlist; cv; cv = cv->c_lnext) {
+ display = cv->c_display;
+ if (D_blocked)
+ continue;
+ if (cv != D_forecv)
+ continue;
+ KeypadMode(on);
+ }
+}
+
+
+void LCursorkeysMode(struct layer *l, int on)
+{
+ struct canvas *cv;
+ for (cv = l->l_cvlist; cv; cv = cv->c_lnext) {
+ display = cv->c_display;
+ if (D_blocked)
+ continue;
+ if (cv != D_forecv)
+ continue;
+ CursorkeysMode(on);
+ }
+}
+
+
+void LMouseMode(struct layer *l, int on)
+{
+ struct canvas *cv;
+ for (cv = l->l_cvlist; cv; cv = cv->c_lnext) {
+ display = cv->c_display;
+ if (D_blocked)
+ continue;
+ if (cv != D_forecv)
+ continue;
+ MouseMode(on);
+ }
+}
+
+void LClearAll(struct layer *l, int uself)
+{
+ LClearArea(l, 0, 0, l->l_width - 1, l->l_height - 1, 0, uself);
+}
+
+
+void LRefreshAll(struct layer *l, int isblank)
+{
+ struct layer *oldflayer;
+ int y;
+
+ debug1("LRefreshAll isblank=%d\n", isblank);
+ oldflayer = flayer;
+ flayer = l;
+ if (!isblank)
+ LClearArea(l, 0, 0, l->l_width - 1, l->l_height - 1, 0, 0);
+ /* signal full refresh */
+ LayRedisplayLine(-1, -1, -1, 1);
+ for (y = 0; y < l->l_height; y++)
+ LayRedisplayLine(y, 0, l->l_width - 1, 1);
+ flayer = oldflayer;
+}
+
+void
+/*VARARGS2*/
+#if defined(USEVARARGS) && defined(__STDC__)
+LMsg(int err, const char *fmt, VA_DOTS)
+#else
+LMsg(err, fmt, VA_DOTS)
+int err;
+const char *fmt;
+VA_DECL
+#endif
+{
+ VA_LIST(ap)
+ char buf[MAXPATHLEN*2];
+ char *p = buf;
+ struct canvas *cv;
+
+ VA_START(ap, fmt);
+ fmt = DoNLS(fmt);
+ (void)vsnprintf(p, sizeof(buf) - 100, fmt, VA_ARGS(ap));
+ VA_END(ap);
+
+ if (err) {
+ p += strlen(p);
+ *p++ = ':';
+ *p++ = ' ';
+ strncpy(p, strerror(err), buf + sizeof(buf) - p - 1);
+ buf[sizeof(buf) - 1] = 0;
+ }
+
+ debug2("LMsg('%s') (%#x);\n", buf, (unsigned int)flayer);
+ for (display = displays; display; display = display->d_next) {
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ if (cv->c_layer == flayer)
+ break;
+
+ if (cv == 0)
+ continue;
+ MakeStatus(buf);
+ }
+}
+
+
+/*******************************************************************/
+/*******************************************************************/
+
+/*
+ * Layer creation / removal
+ */
+
+void KillLayerChain(struct layer *lay)
+{
+ struct canvas *cv, *ncv;
+ struct layer *l, *oldflayer;
+
+ oldflayer = flayer;
+ debug1("KillLayerChain %#x\n", lay);
+ for (l = lay; l; l = l->l_next) {
+ if (l->l_layfn == &WinLf || l->l_layfn == &BlankLf)
+ break;
+ debug1("- killing %#x\n", l);
+ if (oldflayer == l)
+ oldflayer = 0;
+ for (cv = l->l_cvlist; cv; cv = ncv) {
+ ncv = cv->c_lnext;
+ cv->c_layer = 0;
+ cv->c_lnext = 0;
+ }
+ }
+ flayer = lay;
+ while (flayer != l)
+ ExitOverlayPage();
+ flayer = oldflayer;
+}
+
+
+
+int InitOverlayPage(int datasize, struct LayFuncs *lf, int block)
+{
+ char *data;
+ struct layer *newlay;
+ struct canvas *cv, *cvp, **cvpp;
+ struct win *p;
+
+ ASSERT(flayer);
+
+ cv = 0;
+ if (display && D_forecv->c_layer == flayer)
+ cv = D_forecv; /* work only on this cv! */
+
+ if ((newlay = (struct layer *)calloc(1, sizeof(struct layer))) == 0) {
+ Msg(0, "No memory for layer struct");
+ return -1;
+ }
+ debug2("Entering new layer on top of %#x: %#x\n", (unsigned int)flayer, newlay);
+ data = 0;
+ if (datasize) {
+ if ((data = calloc(1, datasize)) == 0) {
+ free((char *)newlay);
+ Msg(0, "No memory for layer data");
+ return -1;
+ }
+ }
+ p = Layer2Window(flayer);
+
+ if (p && (p->w_savelayer == flayer || (block && flayer->l_next == 0))) {
+ if (p->w_savelayer && p->w_savelayer != flayer && p->w_savelayer->l_cvlist == 0)
+ KillLayerChain(p->w_savelayer);
+ p->w_savelayer = newlay;
+ }
+
+ if (cv && flayer->l_next == 0 && !block) {
+ struct display *olddisplay = display;
+ display = cv->c_display;
+ RemoveStatus();
+ display = olddisplay;
+
+ /* new branch -> just get canvas vps */
+ for (cvpp = &flayer->l_cvlist; (cvp = *cvpp); cvpp = &cvp->c_lnext)
+ if (cvp == cv)
+ break;
+
+ ASSERT(cvp);
+ *cvpp = cv->c_lnext;
+ newlay->l_cvlist = cv;
+ cv->c_lnext = 0;
+ cv->c_layer = newlay;
+ }
+ else {
+ LAY_DISPLAYS(flayer, RemoveStatus());
+ if (block)
+ debug("layer is blocking\n");
+ if (block && flayer->l_layfn == &WinLf) {
+ debug("...and is first, so window gets blocked\n");
+ ASSERT(p->w_blocked == 0);
+ p->w_blocked++;
+ newlay->l_blocking = 1;
+ }
+
+ /* change all canvases */
+ newlay->l_cvlist = flayer->l_cvlist;
+
+ for (cvp = newlay->l_cvlist; cvp; cvp = cvp->c_lnext)
+ cvp->c_layer = newlay;
+ flayer->l_cvlist = 0;
+ }
+ newlay->l_width = flayer->l_width;
+ newlay->l_height = flayer->l_height;
+ newlay->l_encoding = 0;
+ newlay->l_layfn = lf;
+ newlay->l_data = data;
+ newlay->l_next = flayer;
+ newlay->l_bottom = flayer->l_bottom;
+ flayer = newlay;
+ LayRestore();
+ return 0;
+}
+
+
+extern struct layout *layouts;
+
+void ExitOverlayPage()
+{
+ struct layer *oldlay;
+ struct win *p;
+ int doredisplay = 0;
+ struct canvas *cv, *ocv;
+ struct layout *lay;
+
+ ASSERT(flayer);
+ debug1("Exiting layer %#x\n", (unsigned int)flayer);
+ oldlay = flayer;
+ if (oldlay->l_data) {
+ if (oldlay->l_layfn->lf_LayFree)
+ LayFree(oldlay->l_data);
+ free(oldlay->l_data);
+ }
+ p = Layer2Window(flayer);
+
+ flayer = oldlay->l_next;
+ if (flayer->l_layfn == &WinLf) {
+ if (oldlay->l_blocking) {
+ ASSERT(p->w_blocked > 0);
+ p->w_blocked--;
+ debug1("layer was blocking, -> w_blocked now %d\n", p->w_blocked);
+ }
+
+ /* don't warp dead layers: check cvlist */
+ if (p->w_blocked && p->w_savelayer && p->w_savelayer != flayer && oldlay->l_cvlist) {
+ debug("warping to top of blocking chain!\n");
+ /* warp ourself into savelayer */
+ flayer = p->w_savelayer;
+ doredisplay = 1;
+ }
+ }
+
+ if (p && p->w_savelayer == oldlay)
+ p->w_savelayer = flayer;
+#ifdef COPY_PASTE
+ if (p && oldlay == p->w_paster.pa_pastelayer)
+ p->w_paster.pa_pastelayer = 0;
+#endif
+
+ for (lay = layouts; lay; lay = lay->lay_next)
+ for (cv = lay->lay_cvlist; cv; cv = cv->c_next)
+ if (cv->c_layer == oldlay)
+ cv->c_layer = flayer;
+
+ /* add all canvases back into next layer's canvas list */
+ for (ocv = 0, cv = oldlay->l_cvlist; cv; cv = cv->c_lnext) {
+ cv->c_layer = flayer;
+ ocv = cv;
+ }
+ if (ocv) {
+ cv = flayer->l_cvlist;
+ ocv->c_lnext = 0;
+ flayer->l_cvlist = oldlay->l_cvlist;
+
+ /* redisplay only the warped cvs */
+ if (doredisplay)
+ LRefreshAll(flayer, 0);
+ ocv->c_lnext = cv;
+ }
+ oldlay->l_cvlist = 0;
+ LayerCleanupMemory(oldlay);
+ free((char *)oldlay);
+ LayRestore();
+ LaySetCursor();
+}
+
+int LayProcessMouse(struct layer *l, unsigned char ch)
+{
+ /* XXX: Make sure the layer accepts mouse events */
+ int len;
+ if (l->l_mouseevent.len >= sizeof(l->l_mouseevent.buffer))
+ return -1;
+
+ len = l->l_mouseevent.len++;
+ l->l_mouseevent.buffer[len] = (len > 0 ? ch - 33 : ch);
+ return (l->l_mouseevent.len == sizeof(l->l_mouseevent.buffer));
+}
+
+void LayProcessMouseSwitch(struct layer *l, int s)
+{
+ if ((l->l_mouseevent.start = s))
+ l->l_mouseevent.len = 0;
+}
+
+
+void LayPause(struct layer *layer, int pause)
+{
+ struct canvas *cv;
+ int line;
+ struct win *win;
+ pause = !!pause;
+
+ if (layer->l_pause.d == pause)
+ return;
+
+ if ((layer->l_pause.d = pause)) {
+ /* Start pausing */
+ layer->l_pause.top = layer->l_pause.bottom = -1;
+ return;
+ }
+
+ /* Unpause. So refresh the regions in the displays! */
+ if (layer->l_pause.top == -1 && layer->l_pause.bottom == -1)
+ return;
+
+ if (layer->l_layfn == &WinLf) /* Currently, this will always be the case! */
+ win = layer->l_data;
+ else
+ win = NULL;
+
+ for (cv = layer->l_cvlist; cv; cv = cv->c_lnext) {
+ struct viewport *vp;
+
+ if (!cv->c_slorient)
+ continue; /* Wasn't split, so already updated. */
+ display = cv->c_display;
+ for (vp = cv->c_vplist; vp; vp = vp->v_next) {
+ for (line = layer->l_pause.top; line <= layer->l_pause.bottom; line++) {
+ int xs, xe;
+ if (line + vp->v_yoff >= vp->v_ys && line + vp->v_yoff <= vp->v_ye &&
+ ((xs = layer->l_pause.left[line]) >= 0) &&
+ ((xe = layer->l_pause.right[line]) >= 0)) {
+ xs += vp->v_xoff;
+ xe += vp->v_xoff;
+
+ if (xs < vp->v_xs) xs = vp->v_xs;
+ if (xe > vp->v_xe) xe = vp->v_xe;
+
+#if defined(DW_CHARS) && defined(UTF8)
+ if (layer->l_encoding == UTF8 && xe < vp->v_xe && win) {
+ struct mline *ml = win->w_mlines + line;
+ if (dw_left(ml, xe, UTF8))
+ xe++;
+ }
+#endif
+
+ if (xs <= xe)
+ RefreshLine(line + vp->v_yoff, xs, xe, 0);
+ }
+ }
+ }
+
+ if (cv == D_forecv) {
+ int cx = layer->l_x + cv->c_xoff;
+ int cy = layer->l_y + cv->c_yoff;
+
+ if (cx < cv->c_xs) cx = cv->c_xs;
+ if (cy < cv->c_ys) cy = cv->c_ys;
+ if (cx > cv->c_xe) cx = cv->c_xe;
+ if (cy > cv->c_ye) cy = cv->c_ye;
+
+ GotoPos(cx, cy);
+ }
+ }
+
+ for (line = layer->l_pause.top; line <= layer->l_pause.bottom; line++)
+ layer->l_pause.left[line] = layer->l_pause.right[line] = -1;
+}
+
+void LayPauseUpdateRegion(struct layer *layer, int xs, int xe, int ys, int ye)
+{
+ if (!layer->l_pause.d)
+ return;
+ if (ys < 0)
+ ys = 0;
+ if (ye >= layer->l_height)
+ ye = layer->l_height - 1;
+ if (xe >= layer->l_width)
+ xe = layer->l_width - 1;
+
+ if (layer->l_pause.top == -1 || layer->l_pause.top > ys)
+ layer->l_pause.top = ys;
+ if (layer->l_pause.bottom < ye) {
+ layer->l_pause.bottom = ye;
+
+ if (layer->l_pause.lines <= ye) {
+ int o = layer->l_pause.lines;
+ layer->l_pause.lines = ye + 32;
+ layer->l_pause.left = realloc(layer->l_pause.left, sizeof(int) * layer->l_pause.lines);
+ layer->l_pause.right = realloc(layer->l_pause.right, sizeof(int) * layer->l_pause.lines);
+ while (o < layer->l_pause.lines) {
+ layer->l_pause.left[o] = layer->l_pause.right[o] = -1;
+ o++;
+ }
+ }
+ }
+ while (ys <= ye) {
+ if (layer->l_pause.left[ys] == -1 || layer->l_pause.left[ys] > xs)
+ layer->l_pause.left[ys] = xs;
+ if (layer->l_pause.right[ys] < xe)
+ layer->l_pause.right[ys] = xe;
+ ys++;
+ }
+}
+
+void LayerCleanupMemory(struct layer *layer)
+{
+ if (layer->l_pause.left)
+ free(layer->l_pause.left);
+ if (layer->l_pause.right)
+ free(layer->l_pause.right);
+}
diff --git a/layer.h b/layer.h
new file mode 100644
index 0000000..8c42d2b
--- /dev/null
+++ b/layer.h
@@ -0,0 +1,163 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+#ifndef SCREEN_LAYER_H
+#define SCREEN_LAYER_H
+
+/*
+ * This is the overlay structure. It is used to create a seperate
+ * layer over the current windows.
+ */
+
+struct mchar; /* forward declaration */
+
+struct LayFuncs
+{
+ void (*lf_LayProcess) __P((char **, int *));
+ void (*lf_LayAbort) __P((void));
+ void (*lf_LayRedisplayLine) __P((int, int, int, int));
+ void (*lf_LayClearLine) __P((int, int, int, int));
+ int (*lf_LayRewrite) __P((int, int, int, struct mchar *, int));
+ int (*lf_LayResize) __P((int, int));
+ void (*lf_LayRestore) __P((void));
+ void (*lf_LayFree) __P((void *)); /* Should only free any data kept in
+ flayer->l_data (but not flayer->l_data itself). */
+};
+
+struct layer
+{
+ struct canvas *l_cvlist; /* list of canvases displaying layer */
+ int l_width;
+ int l_height;
+ int l_x; /* cursor position */
+ int l_y;
+ int l_encoding;
+ struct LayFuncs *l_layfn;
+ void *l_data;
+
+ struct layer *l_next; /* layer stack, should be in data? */
+ struct layer *l_bottom; /* bottom element of layer stack */
+ int l_blocking;
+ int l_mode; /* non-zero == edit mode */
+
+ struct {
+ unsigned char buffer[3]; /* [0]: the button
+ [1]: x
+ [2]: y
+ */
+ int len;
+ int start;
+ } l_mouseevent;
+
+ struct {
+ int d : 1; /* Is the output for the layer blocked? */
+
+ /* After unpausing, what region should we refresh? */
+ int *left, *right;
+ int top, bottom;
+ int lines;
+ } l_pause;
+};
+
+#define LayProcess (*flayer->l_layfn->lf_LayProcess)
+#define LayAbort (*flayer->l_layfn->lf_LayAbort)
+#define LayRedisplayLine (*flayer->l_layfn->lf_LayRedisplayLine)
+#define LayClearLine (*flayer->l_layfn->lf_LayClearLine)
+#define LayRewrite (*flayer->l_layfn->lf_LayRewrite)
+#define LayResize (*flayer->l_layfn->lf_LayResize)
+#define LayRestore (*flayer->l_layfn->lf_LayRestore)
+#define LayFree (*flayer->l_layfn->lf_LayFree)
+
+#define LaySetCursor() LGotoPos(flayer, flayer->l_x, flayer->l_y)
+#define LayCanResize(l) (l->l_layfn->LayResize != DefResize)
+
+/* XXX: AArgh! think again! */
+
+#define LAY_CALL_UP(fn) do \
+ { \
+ struct layer *oldlay = flayer; \
+ struct canvas *oldcvlist, *cv; \
+ debug("LayCallUp\n"); \
+ flayer = flayer->l_next; \
+ oldcvlist = flayer->l_cvlist; \
+ debug1("oldcvlist: %x\n", oldcvlist); \
+ flayer->l_cvlist = oldlay->l_cvlist; \
+ for (cv = flayer->l_cvlist; cv; cv = cv->c_lnext) \
+ cv->c_layer = flayer; \
+ fn; \
+ flayer = oldlay; \
+ for (cv = flayer->l_cvlist; cv; cv = cv->c_lnext) \
+ cv->c_layer = flayer; \
+ flayer->l_next->l_cvlist = oldcvlist; \
+ } while(0)
+
+#define LAY_DISPLAYS(l, fn) do \
+ { \
+ struct display *olddisplay = display; \
+ struct canvas *cv; \
+ for (display = displays; display; display = display->d_next) \
+ { \
+ for (cv = D_cvlist; cv; cv = cv->c_next) \
+ if (cv->c_layer == l) \
+ break; \
+ if (cv == 0) \
+ continue; \
+ fn; \
+ } \
+ display = olddisplay; \
+ } while(0)
+
+#endif /* SCREEN_LAYER_H */
+
+/**
+ * (Un)Pauses a layer.
+ *
+ * @param layer The layer that should be (un)paused.
+ * @param pause Should we pause the layer?
+ */
+void LayPause __P((struct layer *layer, int pause));
+
+/**
+ * Update the region to refresh after a layer is unpaused.
+ *
+ * @param layer The layer.
+ * @param xs The left-end of the region.
+ * @param xe The right-end of the region.
+ * @param ys The top-end of the region.
+ * @param ye The bottom-end of the region.
+ */
+void LayPauseUpdateRegion __P((struct layer *layer, int xs, int xe, int ys, int ye));
+
+/**
+ * Free any internal memory for the layer.
+ *
+ * @param layer The layer.
+ */
+void LayerCleanupMemory __P((struct layer *layer));
+
diff --git a/layout.c b/layout.c
new file mode 100644
index 0000000..02d82a6
--- /dev/null
+++ b/layout.c
@@ -0,0 +1,350 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include "config.h"
+#include "screen.h"
+#include "extern.h"
+#include "layout.h"
+
+extern struct display *display;
+extern int captionalways;
+
+struct layout *layouts;
+struct layout *laytab[MAXLAY];
+struct layout *layout_last, layout_last_marker;
+struct layout *layout_attach = &layout_last_marker;
+
+void FreeLayoutCv(struct canvas *cv)
+{
+ struct canvas *cnext, *c = cv;
+ for (; cv; cv = cnext) {
+ if (cv->c_slperp) {
+ FreeLayoutCv(cv->c_slperp);
+ free(cv->c_slperp);
+ cv->c_slperp = 0;
+ }
+ cnext = cv->c_slnext;
+ cv->c_slnext = 0;
+ if (cv != c)
+ free(cv);
+ }
+}
+
+struct layout *CreateLayout(char *title, int startat)
+{
+ struct layout *lay, **pl;
+ int i;
+
+ if (startat >= MAXLAY || startat < 0)
+ startat = 0;
+ for (i = startat; ;) {
+ if (!laytab[i])
+ break;
+ if (++i == MAXLAY)
+ i = 0;
+ if (i == startat) {
+ Msg(0, "No more layouts\n");
+ return 0;
+ }
+ }
+ lay = (struct layout *)calloc(1, sizeof(*lay));
+ lay->lay_title = SaveStr(title);
+ lay->lay_autosave = 1;
+ lay->lay_number = i;
+ laytab[i] = lay;
+ lay->lay_next = 0;
+
+ pl = &layouts;
+ while (*pl)
+ pl = &(*pl)->lay_next;
+ *pl = lay;
+ return lay;
+}
+
+void SaveLayout(char *name, struct canvas *cv)
+{
+ struct layout *lay;
+ struct canvas *fcv;
+ for (lay = layouts; lay; lay = lay->lay_next)
+ if (!strcmp(lay->lay_title, name))
+ break;
+ if (lay)
+ FreeLayoutCv(&lay->lay_canvas);
+ else
+ lay = CreateLayout(name, 0);
+ if (!lay)
+ return;
+ fcv = D_forecv;
+ DupLayoutCv(cv, &lay->lay_canvas, 1);
+ lay->lay_forecv = D_forecv;
+ D_forecv = fcv;
+ D_layout = lay;
+}
+
+void AutosaveLayout(struct layout *lay)
+{
+ struct canvas *fcv;
+ if (!lay || !lay->lay_autosave)
+ return;
+ FreeLayoutCv(&lay->lay_canvas);
+ fcv = D_forecv;
+ DupLayoutCv(&D_canvas, &lay->lay_canvas, 1);
+ lay->lay_forecv = D_forecv;
+ D_forecv = fcv;
+}
+
+struct layout *FindLayout(char *name)
+{
+ struct layout *lay;
+ char *s;
+ int i;
+ for (i = 0, s = name; *s >= '0' && *s <= '9'; s++)
+ i = i * 10 + (*s - '0');
+ if (!*s && s != name && i >= 0 && i < MAXLAY)
+ return laytab[i];
+ for (lay = layouts; lay; lay = lay->lay_next)
+ if (!strcmp(lay->lay_title, name))
+ break;
+ return lay;
+}
+
+void LoadLayout(struct layout *lay, struct canvas *cv)
+{
+ AutosaveLayout(D_layout);
+ if (!lay) {
+ while (D_canvas.c_slperp)
+ FreeCanvas(D_canvas.c_slperp);
+ MakeDefaultCanvas();
+ SetCanvasWindow(D_forecv, 0);
+ D_layout = 0;
+ return;
+ }
+ while (D_canvas.c_slperp)
+ FreeCanvas(D_canvas.c_slperp);
+ D_cvlist = 0;
+ D_forecv = lay->lay_forecv;
+ if (!D_forecv)
+ MakeDefaultCanvas();
+ DupLayoutCv(&lay->lay_canvas, &D_canvas, 0);
+ D_canvas.c_ys = (D_has_hstatus == HSTATUS_FIRSTLINE);
+ D_canvas.c_ye = D_height - 1 - ((D_canvas.c_slperp && D_canvas.c_slperp->c_slnext) ||
+ captionalways) - (D_has_hstatus == HSTATUS_LASTLINE);
+ ResizeCanvas(&D_canvas);
+ RecreateCanvasChain();
+ RethinkDisplayViewports();
+ PutWindowCv(&D_canvas);
+ ResizeLayersToCanvases();
+ D_layout = lay;
+}
+
+void NewLayout(char *title, int startat)
+{
+ struct layout *lay;
+ struct canvas *fcv;
+
+ lay = CreateLayout(title, startat);
+ if (!lay)
+ return;
+
+ if (display) {
+ LoadLayout(0, &D_canvas);
+ fcv = D_forecv;
+ DupLayoutCv(&D_canvas, &lay->lay_canvas, 1);
+ lay->lay_forecv = D_forecv;
+ D_forecv = fcv;
+ D_layout = lay;
+ }
+ else
+ layout_attach = lay;
+
+ lay->lay_autosave = 1;
+}
+
+
+static char *AddLayoutsInfo(char *buf, int len, int where)
+{
+ char *s, *ss, *t;
+ struct layout *p, **pp;
+ int l;
+
+ s = ss = buf;
+ for (pp = laytab; pp < laytab + MAXLAY; pp++) {
+ if (pp - laytab == where && ss == buf)
+ ss = s;
+ if ((p = *pp) == 0)
+ continue;
+ t = p->lay_title;
+ l = strlen(t);
+ if (l > 20)
+ l = 20;
+ if (s - buf + l > len - 24)
+ break;
+ if (s > buf) {
+ *s++ = ' ';
+ *s++ = ' ';
+ }
+ sprintf(s, "%d", p->lay_number);
+ if (p->lay_number == where)
+ ss = s;
+ s += strlen(s);
+ if (display && p == D_layout)
+ *s++ = '*';
+ *s++ = ' ';
+ strncpy(s, t, l);
+ s += l;
+ }
+ *s = 0;
+ return ss;
+}
+
+void ShowLayouts(int where)
+{
+ char buf[1024];
+ char *s, *ss;
+
+ if (!display)
+ return;
+ if (!layouts) {
+ Msg(0, "No layouts defined\n");
+ return;
+ }
+ if (where == -1 && D_layout)
+ where = D_layout->lay_number;
+ ss = AddLayoutsInfo(buf, sizeof(buf), where);
+ s = buf + strlen(buf);
+ if (ss - buf > D_width / 2) {
+ ss -= D_width / 2;
+ if (s - ss < D_width) {
+ ss = s - D_width;
+ if (ss < buf)
+ ss = buf;
+ }
+ }
+ else
+ ss = buf;
+ Msg(0, "%s", ss);
+}
+
+void RemoveLayout(struct layout *lay)
+{
+ struct layout **layp = &layouts;
+
+ for (; *layp; layp = &(*layp)->lay_next) {
+ if (*layp == lay) {
+ *layp = lay->lay_next;
+ break;
+ }
+ }
+ laytab[lay->lay_number] = (struct layout *)0;
+
+ if (display && D_layout == lay)
+ D_layout = (struct layout *)0;
+
+ FreeLayoutCv(&lay->lay_canvas);
+
+ if (lay->lay_title)
+ free(lay->lay_title);
+ free(lay);
+
+ if (layouts)
+ LoadLayout((display && D_layout) ? D_layout : *layp ? *layp : layouts,
+ display ? &D_canvas : (struct canvas *)0);
+ Activate(0);
+}
+
+void UpdateLayoutCanvas(struct canvas *cv, struct win * wi)
+{
+ for (; cv; cv = cv->c_slnext) {
+ if (cv->c_layer && Layer2Window(cv->c_layer) == wi) {
+ /* A simplistic version of SetCanvasWindow(cv, 0) */
+ struct layer *l = cv->c_layer;
+ cv->c_layer = 0;
+ if (l->l_cvlist == 0 && (wi == 0 || l != wi->w_savelayer))
+ KillLayerChain(l);
+
+ l = &cv->c_blank;
+ l->l_data = 0;
+ if (l->l_cvlist != cv) {
+ cv->c_lnext = l->l_cvlist;
+ l->l_cvlist = cv;
+ }
+ cv->c_layer = l;
+ /* Do not end here. Multiple canvases can have the same window */
+ }
+
+ if (cv->c_slperp)
+ UpdateLayoutCanvas(cv->c_slperp, wi);
+ }
+}
+
+
+static void dump_canvas(struct canvas *cv, FILE *file)
+{
+ struct canvas *c;
+ for (c = cv->c_slperp; c && c->c_slnext; c = c->c_slnext)
+ fprintf(file, "split%s\n", c->c_slorient == SLICE_HORI ? " -v" : "");
+
+ for (c = cv->c_slperp; c; c = c->c_slnext) {
+ if (c->c_slperp)
+ dump_canvas(c, file);
+ else
+ fprintf(file, "focus\n");
+ }
+}
+
+int LayoutDumpCanvas(struct canvas *cv, char *filename)
+{
+ FILE *file = secfopen(filename, "a");
+ if (!file)
+ return 0;
+ dump_canvas(cv, file);
+ fclose(file);
+ return 1;
+}
+
+void RenameLayout(struct layout *layout, const char *name)
+{
+ free(layout->lay_title);
+ layout->lay_title = SaveStr(name);
+}
+
+int RenumberLayout(struct layout *layout, int number)
+{
+ int old;
+ struct layout *lay;
+ old = layout->lay_number;
+ if (number < 0 || number >= MAXLAY)
+ return 0;
+ lay = laytab[number];
+ laytab[number] = layout;
+ layout->lay_number = number;
+ laytab[old] = lay;
+ if (lay)
+ lay->lay_number = old;
+ return 1;
+}
diff --git a/layout.h b/layout.h
new file mode 100644
index 0000000..5f190bd
--- /dev/null
+++ b/layout.h
@@ -0,0 +1,63 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+#ifndef SCREEN_LAYOUT_H
+#define SCREEN_LAYOUT_H
+
+#include "canvas.h"
+
+#define MAXLAY 10
+
+struct layout
+{
+ struct layout *lay_next;
+ char *lay_title;
+ int lay_number;
+ struct canvas lay_canvas;
+ struct canvas *lay_forecv;
+ struct canvas *lay_cvlist;
+ int lay_autosave;
+};
+
+extern void AutosaveLayout __P((struct layout *));
+extern void LoadLayout __P((struct layout *, struct canvas *));
+extern void NewLayout __P((char *, int));
+extern void SaveLayout __P((char *, struct canvas *));
+extern void ShowLayouts __P((int));
+extern struct layout *FindLayout __P((char *));
+extern void UpdateLayoutCanvas __P((struct canvas *, struct win *));
+extern struct layout *CreateLayout __P((char *, int));
+extern void RemoveLayout __P((struct layout *));
+extern int LayoutDumpCanvas __P((struct canvas *, char *));
+
+extern void RenameLayout __P((struct layout *, const char *));
+extern int RenumberLayout __P((struct layout *, int));
+
+#endif /* SCREEN_LAYOUT_H */
+
diff --git a/list_display.c b/list_display.c
new file mode 100644
index 0000000..113bc1c
--- /dev/null
+++ b/list_display.c
@@ -0,0 +1,245 @@
+/* Copyright (c) 2010
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+/* Deals with the list of displays */
+
+#include "config.h"
+
+#include "screen.h"
+#include "extern.h"
+#include "list_generic.h"
+
+#ifdef MULTI
+
+extern struct layer *flayer;
+extern struct display *display, *displays;
+extern struct mchar mchar_blank, mchar_so;
+
+static char ListID[] = "display";
+
+/*
+ * layout of the displays page is as follows:
+
+xterm 80x42 jnweiger@/dev/ttyp4 0(m11) &rWx
+facit 80x24 nb mlschroe@/dev/ttyhf 11(tcsh) rwx
+xterm 80x42 jnhollma@/dev/ttyp5 0(m11) &R.x
+
+ | | | | | | | | ¦___ window permissions
+ | | | | | | | | (R. is locked r-only,
+ | | | | | | | | W has wlock)
+ | | | | | | | |___ Window is shared
+ | | | | | | |___ Name/Title of window
+ | | | | | |___ Number of window
+ | | | | |___ Name of the display (the attached device)
+ | | | |___ Username who is logged in at the display
+ | | |___ Display is in nonblocking mode. Shows 'NB' if obuf is full.
+ | |___ Displays geometry as width x height.
+ |___ the terminal type known by screen for this display.
+
+ */
+
+static int
+gl_Display_header(struct ListData *ldata)
+{
+ leftline("term-type size user interface window Perms", 0, 0);
+ leftline("---------- ------- ---------- ----------------- ---------- -----", 1, 0);
+ return 2;
+}
+
+static int
+gl_Display_footer(struct ListData *ldata)
+{
+ centerline("[Press Space to refresh; Return to end.]", flayer->l_height - 1);
+ return 1;
+}
+
+static int
+gl_Display_row(struct ListData *ldata, struct ListRow *lrow)
+{
+ struct display *d = lrow->data;
+ char tbuf[80];
+ static char *blockstates[5] = {"nb", "NB", "Z<", "Z>", "BL"};
+ struct win *w = d->d_fore;
+ struct mchar m_current = mchar_blank;
+ m_current.attr = A_BD;
+
+ sprintf(tbuf, " %-10.10s%4dx%-4d%10.10s@%-16.16s%s",
+ d->d_termname, d->d_width, d->d_height, d->d_user->u_name,
+ d->d_usertty,
+ (d->d_blocked || d->d_nonblock >= 0) && d->d_blocked <= 4 ? blockstates[d->d_blocked] : " ");
+
+ if (w)
+ {
+ int l = 10 - strlen(w->w_title);
+ if (l < 0)
+ l = 0;
+ sprintf(tbuf + strlen(tbuf), "%3d(%.10s)%*s%c%c%c%c",
+ w->w_number, w->w_title, l, "",
+ /* w->w_dlist->next */ 0 ? '&' : ' ',
+ /*
+ * The rwx triple:
+ * -,r,R no read, read, read only due to foreign wlock
+ * -,.,w,W no write, write suppressed by foreign wlock,
+ * write, own wlock
+ * -,x no execute, execute
+ */
+#ifdef MULTIUSER
+ (AclCheckPermWin(d->d_user, ACL_READ, w) ? '-' :
+ ((w->w_wlock == WLOCK_OFF || d->d_user == w->w_wlockuser) ?
+ 'r' : 'R')),
+ (AclCheckPermWin(d->d_user, ACL_READ, w) ? '-' :
+ ((w->w_wlock == WLOCK_OFF) ? 'w' :
+ ((d->d_user == w->w_wlockuser) ? 'W' : 'v'))),
+ (AclCheckPermWin(d->d_user, ACL_READ, w) ? '-' : 'x')
+#else
+ 'r', 'w', 'x'
+#endif
+ );
+ }
+ leftline(tbuf, lrow->y, lrow == ldata->selected ? &mchar_so : d == display ? &m_current : 0);
+
+ return 1;
+}
+
+static void
+gl_Display_rebuild(struct ListData *ldata)
+{
+ /* recreate the rows */
+ struct display *d;
+ struct ListRow *row = NULL;
+ for (d = displays; d; d = d->d_next)
+ {
+ row = glist_add_row(ldata, d, row);
+ if (d == display)
+ ldata->selected = row;
+ }
+
+ glist_display_all(ldata);
+}
+
+static int
+gl_Display_input(struct ListData *ldata, char **inp, int *len)
+{
+ struct display *cd = display;
+ unsigned char ch;
+
+ if (!ldata->selected)
+ return 0;
+
+ ch = (unsigned char) **inp;
+ ++*inp;
+ --*len;
+
+ switch (ch)
+ {
+ case ' ': /* Space to refresh */
+ glist_remove_rows(ldata);
+ gl_Display_rebuild(ldata);
+ break;
+
+ case '\r':
+ case '\n':
+ glist_abort();
+ *len = 0;
+ break;
+
+#ifdef REMOTE_DETACH
+ case 'd': /* Detach */
+ case 'D': /* Power detach */
+ display = ldata->selected->data;
+ if (display == cd) /* We do not allow detaching the current display */
+ break;
+ Detach(
+#ifdef POW_DETACH
+ ch == 'D' ? D_REMOTE_POWER : D_REMOTE
+#else
+ D_REMOTE
+#endif
+ );
+ display = cd;
+ glist_remove_rows(ldata);
+ gl_Display_rebuild(ldata);
+ break;
+#endif
+
+ default:
+ /* We didn't actually process the input. */
+ --*inp;
+ ++*len;
+ return 0;
+ }
+ return 1;
+}
+
+static int
+gl_Display_freerow(struct ListData *ldata, struct ListRow *row)
+{
+ /* There was no allocation when row->data was set. So nothing to do here. */
+ return 0;
+}
+
+static int
+gl_Display_free(struct ListData *ldata)
+{
+ /* There was no allocation in ldata->data. So nothing to do here. */
+ return 0;
+}
+
+static struct GenericList gl_Display =
+{
+ gl_Display_header,
+ gl_Display_footer,
+ gl_Display_row,
+ gl_Display_input,
+ gl_Display_freerow,
+ gl_Display_free,
+ NULL /* We do not allow searching in the display list, at the moment */
+};
+
+void
+display_displays()
+{
+ struct ListData *ldata;
+ if (flayer->l_width < 10 || flayer->l_height < 5)
+ {
+ LMsg(0, "Window size too small for displays page");
+ return;
+ }
+
+ ldata = glist_display(&gl_Display, ListID);
+ if (!ldata)
+ return;
+
+ gl_Display_rebuild(ldata);
+}
+
+#endif /* MULTI */
+
diff --git a/list_generic.c b/list_generic.c
new file mode 100644
index 0000000..e32acf7
--- /dev/null
+++ b/list_generic.c
@@ -0,0 +1,486 @@
+/* Copyright (c) 2010
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include "config.h"
+#include "screen.h"
+#include "list_generic.h"
+#include "layer.h"
+#include "extern.h"
+
+/* Deals with a generic list display */
+
+extern struct layer *flayer;
+
+static void ListProcess __P((char **, int *));
+static void ListAbort __P((void));
+static void ListRedisplayLine __P((int, int, int, int));
+static void ListClearLine __P((int, int, int, int));
+static int ListRewrite __P((int, int, int, struct mchar *, int));
+static int ListResize __P((int, int));
+static void ListRestore __P((void));
+static void ListFree __P((void *));
+
+struct LayFuncs ListLf =
+{
+ ListProcess,
+ ListAbort,
+ ListRedisplayLine,
+ ListClearLine,
+ ListRewrite,
+ ListResize,
+ ListRestore,
+ ListFree
+};
+
+/** Returns non-zero on success. */
+struct ListData *
+glist_display(struct GenericList *list, const char *name)
+{
+ struct ListData *ldata;
+
+ if (InitOverlayPage(sizeof(struct ListData), &ListLf, 0))
+ return NULL;
+ ldata = flayer->l_data;
+
+ ldata->name = name; /* We do not SaveStr, since the strings should be all static literals */
+ ldata->list_fn = list;
+
+ flayer->l_mode = 1;
+ flayer->l_x = 0;
+ flayer->l_y = flayer->l_height - 1;
+
+ return ldata;
+}
+
+static void
+glist_decide_top(struct ListData *ldata)
+{
+ int count = flayer->l_height - 5; /* 2 for header, 1 for footer */
+ struct ListRow *top = ldata->selected;
+ for (; count && top != ldata->root; top = top->prev, count--)
+ ;
+ ldata->top = top;
+}
+
+static struct ListRow *
+glist_search_dir(struct ListData *ldata, struct ListRow *start, int dir)
+{
+ struct ListRow *row = (dir == 1) ? start->next : start->prev;
+ for (; row; row = (dir == 1) ? row->next : row->prev)
+ if (ldata->list_fn->gl_matchrow(ldata, row, ldata->search))
+ return row;
+
+ if (dir == 1)
+ row = ldata->root;
+ else
+ {
+ /* First, go to the end */
+ if (!start->next)
+ row = start;
+ else
+ for (row = start->next; row->next; row = row->next)
+ ;
+ }
+
+ for (; row != start; row = (dir == 1) ? row->next : row->prev)
+ if (ldata->list_fn->gl_matchrow(ldata, row, ldata->search))
+ break;
+
+ return row;
+}
+
+static void
+glist_search(char *buf, int len, char *data)
+{
+ struct ListData *ldata = (struct ListData *)data;
+ struct ListRow *row;
+
+ if (ldata->search)
+ Free(ldata->search);
+ if (len > 0)
+ ldata->search = SaveStr(buf);
+ else
+ return;
+
+ for (row = ldata->selected; row; row = row->next)
+ if (ldata->list_fn->gl_matchrow(ldata, row, ldata->search))
+ break;
+
+ if (!row)
+ for (row = ldata->root; row != ldata->selected; row = row->next)
+ if (ldata->list_fn->gl_matchrow(ldata, row, ldata->search))
+ break;
+
+ if (row == ldata->selected)
+ return;
+
+ ldata->selected = row;
+ if (ldata->selected->y == -1)
+ glist_decide_top(ldata);
+ glist_display_all(ldata);
+}
+
+static void ListProcess(char **ppbuf, int *plen)
+{
+ struct ListData *ldata = flayer->l_data;
+ int count = 0;
+
+ while (*plen > 0)
+ {
+ struct ListRow *old;
+ unsigned char ch;
+
+ if (!flayer->l_mouseevent.start && ldata->list_fn->gl_pinput &&
+ ldata->list_fn->gl_pinput(ldata, ppbuf, plen))
+ continue;
+
+ ch = **ppbuf;
+ ++*ppbuf;
+ --*plen;
+
+ if (flayer->l_mouseevent.start)
+ {
+ int r = LayProcessMouse(flayer, ch);
+ if (r == -1)
+ {
+ LayProcessMouseSwitch(flayer, 0);
+ continue;
+ }
+ else
+ {
+ if (r)
+ ch = 0222;
+ else
+ continue;
+ }
+ }
+
+ if (!ldata->selected)
+ {
+ *plen = 0;
+ break;
+ }
+
+ old = ldata->selected;
+
+processchar:
+ switch (ch)
+ {
+ case ' ':
+ break;
+
+ case '\r':
+ case '\n':
+ break;
+
+ case 0220: /* up */
+ case 16: /* ^P */
+ case 'k':
+ if (!ldata->selected->prev) /* There's no where to go */
+ break;
+ ldata->selected = old->prev;
+ break;
+
+ case 0216: /* down */
+ case 14: /* ^N like emacs */
+ case 'j':
+ if (!ldata->selected->next) /* Nothing to do */
+ break;
+ ldata->selected = old->next;
+ break;
+
+ case 033: /* escape */
+ case 007: /* ^G */
+ ListAbort();
+ *plen = 0;
+ return;
+
+ case 0201: /* home */
+ case 0001: /* ^A */
+ ldata->selected = ldata->root;
+ break;
+
+ case 0205: /* end */
+ case 0005: /* ^E */
+ while (ldata->selected->next)
+ ldata->selected = ldata->selected->next;
+ if (ldata->selected->y != -1)
+ {
+ /* Both old and current selections are on the screen. So we can just
+ * redraw these two affected rows. */
+ }
+ break;
+
+ case 0004: /* ^D (half-page down) */
+ case 0006: /* page-down, ^F */
+ count = (flayer->l_height - 4) >> (ch == 0004);
+ for (; ldata->selected->next && --count;
+ ldata->selected = ldata->selected->next)
+ ;
+ break;
+
+ case 0025: /* ^U (half-page up) */
+ case 0002: /* page-up, ^B */
+ count = (flayer->l_height - 4) >> (ch == 0025);
+ for (; ldata->selected->prev && --count;
+ ldata->selected = ldata->selected->prev)
+ ;
+ break;
+
+ case '/': /* start searching */
+ if (ldata->list_fn->gl_matchrow)
+ {
+ char *s;
+ Input("Search: ", 80, INP_COOKED, glist_search, (char *)ldata, 0);
+ if ((s = ldata->search))
+ {
+ for (; *s; s++)
+ {
+ char *ss = s;
+ int n = 1;
+ LayProcess(&ss, &n);
+ }
+ }
+ }
+ break;
+
+ /* The following deal with searching. */
+
+ case 'n': /* search next */
+ if (ldata->list_fn->gl_matchrow && ldata->search)
+ ldata->selected = glist_search_dir(ldata, ldata->selected, 1);
+ break;
+
+ case 'N': /* search prev */
+ if (ldata->list_fn->gl_matchrow && ldata->search)
+ ldata->selected = glist_search_dir(ldata, ldata->selected, -1);
+ break;
+
+ /* Now, mouse events. */
+ case 0222:
+ if (flayer->l_mouseevent.start)
+ {
+ int button = flayer->l_mouseevent.buffer[0];
+ if (button == 'a') /* Scroll down */
+ ch = 'j';
+ else if (button == '`') /* Scroll up */
+ ch = 'k';
+ else if (button == ' ') /* Left click */
+ {
+ int y = flayer->l_mouseevent.buffer[2];
+ struct ListRow *r = ldata->top;
+ for (r = ldata->top; r && r->y != -1 && r->y != y; r = r->next)
+ ;
+ if (r && r->y == y)
+ ldata->selected = r;
+ ch = 0;
+ }
+ else
+ ch = 0;
+ LayProcessMouseSwitch(flayer, 0);
+ if (ch)
+ goto processchar;
+ }
+ else
+ LayProcessMouseSwitch(flayer, 1);
+ break;
+ }
+
+ if (old == ldata->selected) /* The selection didn't change */
+ continue;
+
+ if (ldata->selected->y == -1)
+ {
+ /* We need to list all the rows, since we are scrolling down. But first,
+ * find the top of the visible list. */
+ glist_decide_top(ldata);
+ glist_display_all(ldata);
+ }
+ else
+ {
+ /* just redisplay the two lines. */
+ ldata->list_fn->gl_printrow(ldata, old);
+ ldata->list_fn->gl_printrow(ldata, ldata->selected);
+ flayer->l_y = ldata->selected->y;
+ LaySetCursor();
+ }
+ }
+}
+
+static void ListAbort(void)
+{
+ LAY_CALL_UP(LRefreshAll(flayer, 0));
+ ExitOverlayPage();
+}
+
+static void ListFree(void *d)
+{
+ struct ListData *ldata = d;
+ glist_remove_rows(ldata);
+ if (ldata->list_fn->gl_free)
+ ldata->list_fn->gl_free(ldata);
+ if (ldata->search)
+ Free(ldata->search);
+}
+
+static void ListRedisplayLine(int y, int xs, int xe, int isblank)
+{
+ struct ListData *ldata;
+ ASSERT(flayer);
+
+ ldata = flayer->l_data;
+ if (y < 0)
+ {
+ glist_display_all(ldata);
+ return;
+ }
+
+ if (!isblank)
+ LClearArea(flayer, xs, y, xe, y, 0, 0);
+
+ if (ldata->top && y < ldata->top->y)
+ ldata->list_fn->gl_printheader(ldata);
+ else if (y + 1 == flayer->l_height)
+ ldata->list_fn->gl_printfooter(ldata);
+ else
+ {
+ struct ListRow *row;
+ for (row = ldata->top; row && row->y != -1; row = row->next)
+ if (row->y == y)
+ {
+ ldata->list_fn->gl_printrow(ldata, row);
+ break;
+ }
+ }
+}
+
+static void ListClearLine(int y, int xs, int xe, int bce)
+{
+ DefClearLine(y, xs, xe, bce);
+}
+
+static int ListRewrite(int y, int xs, int xe, struct mchar *rend, int doit)
+{
+ return EXPENSIVE;
+}
+
+static int ListResize (int wi, int he)
+{
+ if (wi < 10 || he < 5)
+ return -1;
+
+ flayer->l_width = wi;
+ flayer->l_height = he;
+ flayer->l_y = he - 1;
+
+ return 0;
+}
+
+static void ListRestore (void)
+{
+ DefRestore();
+}
+
+struct ListRow *
+glist_add_row(struct ListData *ldata, void *data, struct ListRow *after)
+{
+ struct ListRow *r = calloc(1, sizeof(struct ListRow));
+ r->data = data;
+
+ if (after)
+ {
+ r->next = after->next;
+ r->prev = after;
+ after->next = r;
+ if (r->next)
+ r->next->prev = r;
+ }
+ else
+ {
+ r->next = ldata->root;
+ if (ldata->root)
+ ldata->root->prev = r;
+ ldata->root = r;
+ }
+
+ return r;
+}
+
+void
+glist_remove_rows(struct ListData *ldata)
+{
+ struct ListRow *row;
+ for (row = ldata->root; row; )
+ {
+ struct ListRow *r = row;
+ row = row->next;
+ ldata->list_fn->gl_freerow(ldata, r);
+ free(r);
+ }
+ ldata->root = ldata->selected = ldata->top = NULL;
+}
+
+void
+glist_display_all(struct ListData *list)
+{
+ int y;
+ struct ListRow *row;
+
+ LClearAll(flayer, 0);
+
+ y = list->list_fn->gl_printheader(list);
+
+ if (!list->top)
+ list->top = list->root;
+ if (!list->selected)
+ list->selected = list->root;
+
+ for (row = list->root; row != list->top; row = row->next)
+ row->y = -1;
+
+ for (row = list->top; row; row = row->next)
+ {
+ row->y = y++;
+ if (!list->list_fn->gl_printrow(list, row))
+ {
+ row->y = -1;
+ y--;
+ }
+ if (y + 1 == flayer->l_height)
+ break;
+ }
+ for (; row; row = row->next)
+ row->y = -1;
+
+ list->list_fn->gl_printfooter(list);
+ if (list->selected && list->selected->y != -1)
+ flayer->l_y = list->selected->y;
+ else
+ flayer->l_y = flayer->l_height - 1;
+ LaySetCursor();
+}
+
+void glist_abort(void)
+{
+ ListAbort();
+}
+
diff --git a/list_generic.h b/list_generic.h
new file mode 100644
index 0000000..234f6de
--- /dev/null
+++ b/list_generic.h
@@ -0,0 +1,73 @@
+/* Copyright (c) 2010
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+struct ListData;
+
+struct ListRow
+{
+ void *data; /* Some data relevant to this row */
+ struct ListRow *next, *prev; /* doubly linked list */
+ int y; /* -1 if not on display */
+};
+
+struct GenericList
+{
+ int (*gl_printheader) __P((struct ListData *)); /* Print the header */
+ int (*gl_printfooter) __P((struct ListData *)); /* Print the footer */
+ int (*gl_printrow) __P((struct ListData *, struct ListRow *)); /* Print one row */
+ int (*gl_pinput) __P((struct ListData *, char **inp, int *len)); /* Process input */
+ int (*gl_freerow) __P((struct ListData *, struct ListRow *)); /* Free data for a row */
+ int (*gl_free) __P((struct ListData *)); /* Free data for the list */
+ int (*gl_matchrow) __P((struct ListData *, struct ListRow *, const char *));
+};
+
+struct ListData
+{
+ const char *name; /* An identifier for the list */
+ struct ListRow *root; /* The first item in the list */
+ struct ListRow *selected; /* The selected row */
+ struct ListRow *top; /* The topmost visible row */
+
+ struct GenericList *list_fn; /* The functions that deal with the list */
+
+ char *search; /* The search term, if any */
+
+ void *data; /* List specific data */
+};
+
+extern struct LayFuncs ListLf;
+
+
+struct ListRow * glist_add_row __P((struct ListData *ldata, void *data, struct ListRow *after));
+
+void glist_remove_rows __P((struct ListData *ldata));
+
+void glist_display_all __P((struct ListData *list));
+
+struct ListData * glist_display __P((struct GenericList *list, const char *name));
+
+void glist_abort __P((void));
+
+void display_displays __P((void));
+
+void display_windows __P((int onblank, int order, struct win *group));
+
diff --git a/list_window.c b/list_window.c
new file mode 100644
index 0000000..4dec643
--- /dev/null
+++ b/list_window.c
@@ -0,0 +1,708 @@
+/* Copyright (c) 2010
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+/* Deals with the list of windows */
+
+/* NOTE: A 'struct win *' is used as the 'data' for each row. It might make more sense
+ * to use 'struct win* ->w_number' as the 'data', instead, because that way, we can
+ * verify that the window does exist (by looking at wtab[]).
+ */
+
+#include "config.h"
+#include "screen.h"
+#include "layer.h"
+#include "extern.h"
+#include "list_generic.h"
+
+extern struct layer *flayer;
+extern struct display *display, *displays;
+
+extern char *wlisttit;
+extern char *wliststr;
+
+extern struct mchar mchar_blank, mchar_so;
+extern int renditions[];
+
+extern struct win **wtab, *windows, *fore;
+extern int maxwin;
+
+extern char *noargs[];
+
+static char ListID[] = "window";
+
+struct gl_Window_Data
+{
+ struct win *group; /* Set only for a W_TYPE_GROUP window */
+ int order; /* MRU? NUM? */
+ int onblank;
+ int nested;
+ struct win *fore; /* The foreground window we had. */
+};
+
+/* Is this wdata for a group window? */
+#define WLIST_FOR_GROUP(wdate) ((wdata)->group && !(wdata)->onblank && Layer2Window(flayer) && Layer2Window(flayer)->w_type == W_TYPE_GROUP)
+
+/* This macro should not be used if 'fn' is expected to update the window list */
+#define FOR_EACH_WINDOW(_wdata, _w, fn) do { \
+ if ((_wdata)->order == WLIST_MRU) \
+ { \
+ struct win *_ww; \
+ for (_ww = windows; _ww; _ww = _ww->w_next) \
+ { \
+ _w = _ww; \
+ fn \
+ } \
+ } \
+ else \
+ { \
+ struct win **_ww, *_witer; \
+ for (_ww = wtab, _witer = windows; _witer && _ww - wtab < maxwin; _ww++) \
+ { \
+ if (!(_w = *_ww)) continue; \
+ fn \
+ _witer = _witer->w_next; \
+ } \
+ } \
+ } while (0)
+
+/* Is 'a' an ancestor of 'd'? */
+static int
+window_ancestor(struct win *a, struct win *d)
+{
+ if (!a)
+ return 1; /* Every window is a descendant of the 'null' group */
+ for (; d; d = d->w_group)
+ if (d->w_group == a)
+ return 1;
+ return 0;
+}
+
+static void
+window_kill_confirm(char *buf, int len, char *data)
+{
+ struct win *w = windows;
+ struct action act;
+
+ if (len || (*buf != 'y' && *buf != 'Y'))
+ {
+ *buf = 0;
+ return;
+ }
+
+ /* Loop over the windows to make sure that the window actually still exists. */
+ for (; w; w = w->w_next)
+ if (w == (struct win *)data)
+ break;
+
+ if (!w)
+ return;
+
+ /* Pretend the selected window is the foreground window. Then trigger a non-interactive 'kill' */
+ fore = w;
+ act.nr = RC_KILL;
+ act.args = noargs;
+ act.argl = 0;
+ act.quiet = 0;
+ DoAction(&act, -1);
+}
+
+static struct ListRow *
+gl_Window_add_group(struct ListData *ldata, struct ListRow *row)
+{
+ /* Right now, 'row' doesn't have any child. */
+ struct gl_Window_Data *wdata = ldata->data;
+ struct win *group = row->data, *w;
+ struct ListRow *cur = row;
+
+ ASSERT(wdata->nested);
+
+ FOR_EACH_WINDOW(wdata, w,
+ if (w->w_group != group)
+ continue;
+
+ cur = glist_add_row(ldata, w, cur);
+ if (w == wdata->fore)
+ ldata->selected = cur;
+
+ if (w->w_type == W_TYPE_GROUP)
+ cur = gl_Window_add_group(ldata, cur);
+ );
+
+ return cur;
+}
+
+static void
+gl_Window_rebuild(struct ListData *ldata)
+{
+ struct ListRow *row = NULL;
+ struct gl_Window_Data *wdata = ldata->data;
+ struct win *w;
+
+ FOR_EACH_WINDOW(wdata, w,
+ if (w->w_group != wdata->group)
+ continue;
+ row = glist_add_row(ldata, w, row);
+ if (w == wdata->fore)
+ ldata->selected = row;
+ if (w->w_type == W_TYPE_GROUP && wdata->nested)
+ row = gl_Window_add_group(ldata, row);
+ );
+ glist_display_all(ldata);
+}
+
+static struct ListRow *
+gl_Window_findrow(struct ListData *ldata, struct win *p)
+{
+ struct ListRow *row = ldata->root;
+ for (; row; row = row->next)
+ {
+ if (row->data == p)
+ break;
+ }
+ return row;
+}
+
+static int
+gl_Window_remove(struct ListData *ldata, struct win *p)
+{
+ struct ListRow *row = gl_Window_findrow(ldata, p);
+ if (!row)
+ return 0;
+
+ /* Remove 'row'. Update 'selected', 'top', 'root' if necessary. */
+ if (row->next)
+ row->next->prev = row->prev;
+ if (row->prev)
+ row->prev->next = row->next;
+
+ if (ldata->selected == row)
+ ldata->selected = row->prev ? row->prev : row->next;
+ if (ldata->top == row)
+ ldata->top = row->prev ? row->prev : row->next;
+ if (ldata->root == row)
+ ldata->root = row->next;
+
+ ldata->list_fn->gl_freerow(ldata, row);
+ free(row);
+
+ return 1;
+}
+
+static int
+gl_Window_header(struct ListData *ldata)
+{
+ char *str;
+ struct gl_Window_Data *wdata = ldata->data;
+ int g;
+
+ if ((g = (wdata->group != NULL)))
+ {
+ LPutWinMsg(flayer, "Group: ", 7, &mchar_blank, 0, 0);
+ LPutWinMsg(flayer, wdata->group->w_title, strlen(wdata->group->w_title), &mchar_blank, 7, 0);
+ }
+
+ str = MakeWinMsgEv(wlisttit, (struct win *)0, '%', flayer->l_width, (struct event *)0, 0);
+
+ LPutWinMsg(flayer, str, strlen(str), &mchar_blank, 0, g);
+ return 2 + g;
+}
+
+static int
+gl_Window_footer(struct ListData *ldata)
+{
+ return 0;
+}
+
+static int
+gl_Window_row(struct ListData *ldata, struct ListRow *lrow)
+{
+ char *str;
+ struct win *w, *g;
+ int xoff;
+ struct mchar *mchar;
+ struct mchar mchar_rend = mchar_blank;
+ struct gl_Window_Data *wdata = ldata->data;
+
+ w = lrow->data;
+
+ /* First, make sure we want to display this window in the list.
+ * If we are showing a list for a group, and not on blank, then we must
+ * only show the windows directly belonging to that group.
+ * Otherwise, do some more checks. */
+
+ for (xoff = 0, g = w->w_group; g != wdata->group; g = g->w_group)
+ xoff += 2;
+ str = MakeWinMsgEv(wliststr, w, '%', flayer->l_width - xoff, NULL, 0);
+ if (ldata->selected == lrow)
+ mchar = &mchar_so;
+ else if (w->w_monitor == MON_DONE && renditions[REND_MONITOR] != -1)
+ {
+ mchar = &mchar_rend;
+ ApplyAttrColor(renditions[REND_MONITOR], mchar);
+ }
+ else if ((w->w_bell == BELL_DONE || w->w_bell == BELL_FOUND) && renditions[REND_BELL] != -1)
+ {
+ mchar = &mchar_rend;
+ ApplyAttrColor(renditions[REND_BELL], mchar);
+ }
+ else if ((w->w_silence == SILENCE_FOUND || w->w_silence == SILENCE_DONE) && renditions[REND_SILENCE] != -1)
+ {
+ mchar = &mchar_rend;
+ ApplyAttrColor(renditions[REND_SILENCE], mchar);
+ }
+ else
+ mchar = &mchar_blank;
+
+ LPutWinMsg(flayer, str, flayer->l_width, mchar, xoff, lrow->y);
+ if (xoff)
+ LPutWinMsg(flayer, "", xoff, mchar, 0, lrow->y);
+
+ return 1;
+}
+
+static int
+gl_Window_input(struct ListData *ldata, char **inp, int *len)
+{
+ struct win *win;
+ unsigned char ch;
+ struct display *cd = display;
+ struct gl_Window_Data *wdata = ldata->data;
+
+ if (!ldata->selected)
+ return 0;
+
+ ch = (unsigned char) **inp;
+ ++*inp;
+ --*len;
+
+ win = ldata->selected->data;
+ switch (ch)
+ {
+ case ' ':
+ case '\n':
+ case '\r':
+ if (!win)
+ break;
+#ifdef MULTIUSER
+ if (display && AclCheckPermWin(D_user, ACL_READ, win))
+ return 0; /* Not allowed to switch to this window. */
+#endif
+ if (WLIST_FOR_GROUP(wdata))
+ SwitchWindow(win->w_number);
+ else
+ {
+ /* Abort list only when not in a group window. */
+ glist_abort();
+ display = cd;
+ if (D_fore != win)
+ SwitchWindow(win->w_number);
+ }
+ *len = 0;
+ break;
+
+ case 'm':
+ /* Toggle MRU-ness */
+ wdata->order = wdata->order == WLIST_MRU ? WLIST_NUM : WLIST_MRU;
+ glist_remove_rows(ldata);
+ gl_Window_rebuild(ldata);
+ break;
+
+ case 'g':
+ /* Toggle nestedness */
+ wdata->nested = !wdata->nested;
+ glist_remove_rows(ldata);
+ gl_Window_rebuild(ldata);
+ break;
+
+ case 'a':
+ /* All-window view */
+ if (wdata->group)
+ {
+ int order = wdata->order | (wdata->nested ? WLIST_NESTED : 0);
+ glist_abort();
+ display = cd;
+ display_windows(1, order, NULL);
+ *len = 0;
+ }
+ else if (!wdata->nested)
+ {
+ wdata->nested = 1;
+ glist_remove_rows(ldata);
+ gl_Window_rebuild(ldata);
+ }
+ break;
+
+ case 010: /* ^H */
+ case 0177: /* Backspace */
+ if (!wdata->group)
+ break;
+ if (wdata->group->w_group)
+ {
+ /* The parent is another group window. So switch to that window. */
+ struct win *g = wdata->group->w_group;
+ glist_abort();
+ display = cd;
+ SetForeWindow(g);
+ *len = 0;
+ }
+ else
+ {
+ /* We were in a group view. Now we are moving to an all-window view.
+ * So treat it as 'windowlist on blank'. */
+ int order = wdata->order | (wdata->nested ? WLIST_NESTED : 0);
+ glist_abort();
+ display = cd;
+ display_windows(1, order, NULL);
+ *len = 0;
+ }
+ break;
+
+ case ',': /* Switch numbers with the previous window. */
+ if (wdata->order == WLIST_NUM && ldata->selected->prev)
+ {
+ struct win *pw = ldata->selected->prev->data;
+ if (win->w_group != pw->w_group)
+ break; /* Do not allow switching with the parent group */
+
+ /* When a windows's number is successfully changed, it triggers a WListUpdatecv
+ * with NULL window. So that causes a redraw of the entire list. So reset the
+ * 'selected' after that. */
+ wdata->fore = win;
+ WindowChangeNumber(win->w_number, pw->w_number);
+ }
+ break;
+
+ case '.': /* Switch numbers with the next window. */
+ if (wdata->order == WLIST_NUM && ldata->selected->next)
+ {
+ struct win *nw = ldata->selected->next->data;
+ if (win->w_group != nw->w_group)
+ break; /* Do not allow switching with the parent group */
+
+ wdata->fore = win;
+ WindowChangeNumber(win->w_number, nw->w_number);
+ }
+ break;
+
+ case 'K': /* Kill a window */
+ {
+ char str[MAXSTR];
+ snprintf(str, sizeof(str) - 1, "Really kill window %d (%s) [y/n]",
+ win->w_number, win->w_title);
+ Input(str, 1, INP_RAW, window_kill_confirm, (char *)win, 0);
+ }
+ break;
+
+ case 033: /* escape */
+ case 007: /* ^G */
+ if (!WLIST_FOR_GROUP(wdata))
+ {
+ int fnumber = wdata->onblank ? wdata->fore->w_number : -1;
+ glist_abort();
+ display = cd;
+ if (fnumber >= 0)
+ SwitchWindow(fnumber);
+ *len = 0;
+ }
+ break;
+ default:
+ if (ch >= '0' && ch <= '9')
+ {
+ struct ListRow *row = ldata->root;
+ for (; row; row = row->next)
+ {
+ struct win *w = row->data;
+ if (w->w_number == ch - '0')
+ {
+ struct ListRow *old = ldata->selected;
+ if (old == row)
+ break;
+ ldata->selected = row;
+ if (ldata->selected->y == -1)
+ {
+ /* We need to list all the rows, since we are scrolling down. But first,
+ * find the top of the visible list. */
+ ldata->top = row;
+ glist_display_all(ldata);
+ }
+ else
+ {
+ /* just redisplay the two lines. */
+ ldata->list_fn->gl_printrow(ldata, old);
+ ldata->list_fn->gl_printrow(ldata, ldata->selected);
+ flayer->l_y = ldata->selected->y;
+ LaySetCursor();
+ }
+ break;
+ }
+ }
+ break;
+ }
+ --*inp;
+ ++*len;
+ return 0;
+ }
+ return 1;
+}
+
+static int
+gl_Window_freerow(struct ListData *ldata, struct ListRow *row)
+{
+ return 0;
+}
+
+static int
+gl_Window_free(struct ListData *ldata)
+{
+ Free(ldata->data);
+ return 0;
+}
+
+static int
+gl_Window_match(struct ListData *ldata, struct ListRow *row, const char *needle)
+{
+ struct win *w = row->data;
+ if (InStr(w->w_title, needle))
+ return 1;
+ return 0;
+}
+
+static struct GenericList gl_Window =
+{
+ gl_Window_header,
+ gl_Window_footer,
+ gl_Window_row,
+ gl_Window_input,
+ gl_Window_freerow,
+ gl_Window_free,
+ gl_Window_match
+};
+
+void
+display_windows(int onblank, int order, struct win *group)
+{
+ struct win *p;
+ struct ListData *ldata;
+ struct gl_Window_Data *wdata;
+
+ if (flayer->l_width < 10 || flayer->l_height < 6)
+ {
+ LMsg(0, "Window size too small for window list page");
+ return;
+ }
+
+ if (group)
+ onblank = 0; /* When drawing a group window, ignore 'onblank' */
+
+ if (onblank)
+ {
+ debug3("flayer %x %d %x\n", flayer, flayer->l_width, flayer->l_height);
+ if (!display)
+ {
+ LMsg(0, "windowlist -b: display required");
+ return;
+ }
+ p = D_fore;
+ if (p)
+ {
+ SetForeWindow((struct win *)0);
+ if (p->w_group)
+ {
+ D_fore = p->w_group;
+ flayer->l_data = (char *)p->w_group;
+ }
+ Activate(0);
+ }
+ if (flayer->l_width < 10 || flayer->l_height < 6)
+ {
+ LMsg(0, "Window size too small for window list page");
+ return;
+ }
+ }
+ else
+ p = Layer2Window(flayer);
+ if (!group && p)
+ group = p->w_group;
+
+ ldata = glist_display(&gl_Window, ListID);
+ if (!ldata)
+ {
+ if (onblank && p)
+ {
+ /* Could not display the list. So restore the window. */
+ SetForeWindow(p);
+ Activate(1);
+ }
+ return;
+ }
+
+ wdata = calloc(1, sizeof(struct gl_Window_Data));
+ wdata->group = group;
+ wdata->order = (order & ~WLIST_NESTED);
+ wdata->nested = !!(order & WLIST_NESTED);
+ wdata->onblank = onblank;
+
+ /* Set the most recent window as selected. */
+ wdata->fore = windows;
+ while (wdata->fore && wdata->fore->w_group != group)
+ wdata->fore = wdata->fore->w_next;
+
+ ldata->data = wdata;
+
+ gl_Window_rebuild(ldata);
+}
+
+static void
+WListUpdate(struct win *p, struct ListData *ldata)
+{
+ struct gl_Window_Data *wdata = ldata->data;
+ struct ListRow *row, *rbefore;
+ struct win *before;
+ int d = 0, sel = 0;
+
+ if (!p)
+ {
+ if (ldata->selected)
+ wdata->fore = ldata->selected->data; /* Try to retain the current selection */
+ glist_remove_rows(ldata);
+ gl_Window_rebuild(ldata);
+ return;
+ }
+
+ /* First decide if this window should be displayed at all. */
+ d = 1;
+ if (wdata->order == WLIST_NUM || wdata->order == WLIST_MRU)
+ {
+ if (p->w_group != wdata->group)
+ {
+ if (!wdata->nested)
+ d = 0;
+ else
+ d = window_ancestor(wdata->group, p);
+ }
+ }
+
+ if (!d)
+ {
+ if (gl_Window_remove(ldata, p))
+ glist_display_all(ldata);
+ return;
+ }
+
+ /* OK, so we keep the window in the list. Update the ordering.
+ * First, find the row where this window should go to. Then, either create
+ * a new row for that window, or move the exising row for the window to the
+ * correct place. */
+ before = NULL;
+ if (wdata->order == WLIST_MRU)
+ {
+ if (windows != p)
+ for (before = windows; before; before = before->w_next)
+ if (before->w_next == p)
+ break;
+ }
+ else if (wdata->order == WLIST_NUM)
+ {
+ if (p->w_number != 0)
+ {
+ struct win **w = wtab + p->w_number - 1;
+ for (; w >= wtab; w--)
+ {
+ if (*w && (*w)->w_group == wdata->group)
+ {
+ before = *w;
+ break;
+ }
+ }
+ }
+ }
+
+ /* Now, find the row belonging to 'before' */
+ if (before)
+ rbefore = gl_Window_findrow(ldata, before);
+ else if (wdata->nested && p->w_group) /* There's no 'before'. So find the group window */
+ rbefore = gl_Window_findrow(ldata, p->w_group);
+ else
+ rbefore = NULL;
+
+ /* For now, just remove the row containing 'p' if it is not already in the right place . */
+ row = gl_Window_findrow(ldata, p);
+ if (row)
+ {
+ if (row->prev != rbefore)
+ {
+ sel = ldata->selected->data == p;
+ gl_Window_remove(ldata, p);
+ }
+ else
+ p = NULL; /* the window is in the correct place */
+ }
+ if (p)
+ {
+ row = glist_add_row(ldata, p, rbefore);
+ if (sel)
+ ldata->selected = row;
+ }
+ glist_display_all(ldata);
+}
+
+void
+WListUpdatecv(cv, p)
+struct canvas *cv;
+struct win *p;
+{
+ struct ListData *ldata;
+ struct gl_Window_Data *wdata;
+
+ if (cv->c_layer->l_layfn != &ListLf)
+ return;
+ ldata = cv->c_layer->l_data;
+ if (ldata->name != ListID)
+ return;
+ wdata = ldata->data;
+ CV_CALL(cv, WListUpdate(p, ldata));
+}
+
+void
+WListLinkChanged()
+{
+ struct display *olddisplay = display;
+ struct canvas *cv;
+ struct ListData *ldata;
+ struct gl_Window_Data *wdata;
+
+ for (display = displays; display; display = display->d_next)
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ {
+ if (!cv->c_layer || cv->c_layer->l_layfn != &ListLf)
+ continue;
+ ldata = cv->c_layer->l_data;
+ if (ldata->name != ListID)
+ continue;
+ wdata = ldata->data;
+ if (!(wdata->order & WLIST_MRU))
+ continue;
+ CV_CALL(cv, WListUpdate(0, ldata));
+ }
+ display = olddisplay;
+}
+
diff --git a/loadav.c b/loadav.c
new file mode 100644
index 0000000..ef05c86
--- /dev/null
+++ b/loadav.c
@@ -0,0 +1,396 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+#include <fcntl.h>
+#ifdef ultrix
+# include <sys/fixpoint.h>
+#endif
+
+/* mach stuff included here to prevent index macro conflict */
+#ifdef NeXT
+# include <sys/version.h>
+# if KERNEL_MAJOR_VERSION > 2
+# include <mach/mach.h>
+# else
+# include <mach.h>
+# endif
+#endif
+
+#ifdef _AIX
+#include <sys/kinfo.h>
+extern int getkerninfo(int op, char *buf, int *buf_size, int32long64_t arg);
+#endif
+
+#include "config.h"
+#include "screen.h"
+
+#include "extern.h"
+
+#ifdef LOADAV
+
+static int GetLoadav __P((void));
+
+static LOADAV_TYPE loadav[LOADAV_NUM];
+static int loadok;
+
+
+
+/***************************************************************/
+
+#if defined(linux) && !defined(LOADAV_DONE)
+#define LOADAV_DONE
+/*
+ * This is the easy way. It relies in /proc being mounted.
+ * For the big and ugly way refer to previous screen version.
+ */
+void
+InitLoadav()
+{
+ loadok = 1;
+}
+
+static int
+GetLoadav()
+{
+ FILE *fp;
+ char buf[128], *s;
+ int i;
+ double d, e;
+
+ if ((fp = secfopen("/proc/loadavg", "r")) == NULL)
+ return 0;
+ *buf = 0;
+ fgets(buf, sizeof(buf), fp);
+ fclose(fp);
+ /* can't use fscanf because the decimal point symbol depends on
+ * the locale but the kernel uses always '.'.
+ */
+ s = buf;
+ for (i = 0; i < (LOADAV_NUM > 3 ? 3 : LOADAV_NUM); i++)
+ {
+ d = e = 0;
+ while(*s == ' ')
+ s++;
+ if (*s == 0)
+ break;
+ for(;;)
+ {
+ if (*s == '.')
+ e = 1;
+ else if (*s >= '0' && *s <= '9')
+ {
+ d = d * 10 + (*s - '0');
+ if (e)
+ e *= 10;
+ }
+ else
+ break;
+ s++;
+ }
+ loadav[i] = e ? d / e : d;
+ }
+ return i;
+}
+#endif /* linux */
+
+/***************************************************************/
+
+#if defined(LOADAV_GETLOADAVG) && !defined(LOADAV_DONE)
+#define LOADAV_DONE
+void
+InitLoadav()
+{
+ loadok = 1;
+}
+
+static int
+GetLoadav()
+{
+ return getloadavg(loadav, LOADAV_NUM);
+}
+#endif
+
+/***************************************************************/
+
+#if defined(apollo) && !defined(LOADAV_DONE)
+#define LOADAV_DONE
+void
+InitLoadav()
+{
+ loadok = 1;
+}
+
+static int
+GetLoadav()
+{
+ proc1_$get_loadav(loadav);
+ return LOADAV_NUM;
+}
+#endif
+
+/***************************************************************/
+
+#if defined(NeXT) && !defined(LOADAV_DONE)
+#define LOADAV_DONE
+
+static processor_set_t default_set;
+
+void
+InitLoadav()
+{
+ kern_return_t error;
+
+ error = processor_set_default(host_self(), &default_set);
+ if (error != KERN_SUCCESS)
+ mach_error("Error calling processor_set_default", error);
+ else
+ loadok = 1;
+}
+
+static int
+GetLoadav()
+{
+ unsigned int info_count;
+ struct processor_set_basic_info info;
+ host_t host;
+
+ info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
+ if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO, &host, (processor_set_info_t)&info, &info_count) != KERN_SUCCESS)
+ return 0;
+ loadav[0] = (float)info.load_average / LOAD_SCALE;
+ return 1;
+}
+#endif
+
+/***************************************************************/
+
+#if defined(sun) && defined(SVR4) && !defined(LOADAV_DONE)
+#define LOADAV_DONE
+
+#include <kstat.h>
+
+static kstat_ctl_t *kc;
+
+void
+InitLoadav()
+{
+ loadok = (kc = kstat_open()) != 0;
+}
+
+static int
+GetLoadav()
+{
+ kstat_t *ks;
+ kstat_named_t *avgs[3];
+ int i;
+
+ kstat_chain_update(kc);
+ if ((ks = kstat_lookup(kc, "unix", -1, "system_misc")) == 0 || kstat_read(kc, ks, (void *)0) == -1)
+ return (loadok = 0);
+ avgs[0] = kstat_data_lookup(ks, "avenrun_1min");
+ avgs[1] = kstat_data_lookup(ks, "avenrun_5min");
+ avgs[2] = kstat_data_lookup(ks, "avenrun_15min");
+ for (i = 0; i < 3; i++)
+ {
+ if (avgs[i] == 0 || avgs[i]->data_type != KSTAT_DATA_ULONG)
+ return (loadok = 0);
+ loadav[i] = avgs[i]->value.ul;
+ }
+ return 3;
+}
+
+#endif
+
+/***************************************************************/
+
+#if defined(__osf__) && defined(__alpha) && !defined(LOADAV_DONE)
+#define LOADAV_DONE
+
+struct rtentry; struct mbuf; /* shut up gcc on OSF/1 4.0 */
+#include <sys/table.h>
+
+void
+InitLoadav()
+{
+ loadok = 1;
+}
+
+static int
+GetLoadav()
+{
+ struct tbl_loadavg tbl;
+ int i;
+
+ if (table(TBL_LOADAVG, 0, &tbl, 1, sizeof(struct tbl_loadavg)) != 1)
+ return 0;
+
+ if (tbl.tl_lscale)
+ {
+ /* in long */
+ for (i = 0; i < LOADAV_NUM; i++)
+ loadav[i] = (double) tbl.tl_avenrun.l[i] / tbl.tl_lscale;
+ }
+ else
+ {
+ /* in double */
+ for (i = 0; i < LOADAV_NUM; i++)
+ loadav[i] = tbl.tl_avenrun.d[i];
+ }
+ return LOADAV_NUM;
+}
+#endif
+
+
+/***************************************************************/
+
+#if defined(_AIX) && !defined(LOADAV_DONE)
+#define LOADAV_DONE
+/*
+ * AIX uses KINFO_GET_AVENRUN syscall
+ */
+void
+InitLoadav()
+{
+ loadok = 1;
+}
+
+static int
+GetLoadav()
+{
+ long long avenrun[3];
+ int avsize = 3 * sizeof(long long);
+ int i;
+
+ if (getkerninfo(KINFO_GET_AVENRUN, (char *)&avenrun, &avsize, 0) < 0)
+ {
+ return 0;
+ }
+
+ for (i = 0; i < (LOADAV_NUM > 3 ? 3 : LOADAV_NUM); i++)
+ {
+ loadav[i] = avenrun[i];
+ }
+
+ return i;
+}
+#endif /* _AIX */
+
+/***************************************************************/
+
+#if !defined(LOADAV_DONE)
+/*
+ * The old fashion way: open kernel and read avenrun
+ *
+ * Header File includes
+ */
+
+# ifdef NLIST_STRUCT
+# include <nlist.h>
+# else
+# include <a.out.h>
+# endif
+# ifndef NLIST_DECLARED
+extern int nlist __P((char *, struct nlist *));
+# endif
+
+#ifdef LOADAV_USE_NLIST64
+# define nlist nlist64
+#endif
+
+static struct nlist nl[2];
+static int kmemf;
+
+#ifdef _IBMR2
+# define nlist(u,l) knlist(l,1,sizeof(*l))
+#endif
+
+void
+InitLoadav()
+{
+ debug("Init Kmem...\n");
+ if ((kmemf = open("/dev/kmem", O_RDONLY)) == -1)
+ return;
+# if !defined(_AUX_SOURCE) && !defined(AUX)
+# ifdef NLIST_NAME_UNION
+ nl[0].n_un.n_name = LOADAV_AVENRUN;
+# else
+ nl[0].n_name = LOADAV_AVENRUN;
+# endif
+# else
+ strncpy(nl[0].n_name, LOADAV_AVENRUN, sizeof(nl[0].n_name));
+# endif
+ debug2("Searching in %s for %s\n", LOADAV_UNIX, nl[0].n_name);
+ nlist(LOADAV_UNIX, nl);
+ if (nl[0].n_value == 0)
+ {
+ close(kmemf);
+ return;
+ }
+# if 0 /* no longer needed (Al.Smith@aeschi.ch.eu.org) */
+# ifdef sgi
+ nl[0].n_value &= (unsigned long)-1 >> 1; /* clear upper bit */
+# endif /* sgi */
+# endif
+ debug1("AvenrunSym found (0x%lx)!!\n", nl[0].n_value);
+ loadok = 1;
+}
+
+static int
+GetLoadav()
+{
+ if (lseek(kmemf, (off_t) nl[0].n_value, 0) == (off_t)-1)
+ return 0;
+ if (read(kmemf, (char *) loadav, sizeof(loadav)) != sizeof(loadav))
+ return 0;
+ return LOADAV_NUM;
+}
+#endif
+
+/***************************************************************/
+
+#ifndef FIX_TO_DBL
+#define FIX_TO_DBL(l) ((double)(l) / LOADAV_SCALE)
+#endif
+
+void
+AddLoadav(p)
+char *p;
+{
+ int i, j;
+ if (loadok == 0)
+ return;
+ j = GetLoadav();
+ for (i = 0; i < j; i++)
+ {
+ sprintf(p, " %2.2f" + !i, FIX_TO_DBL(loadav[i]));
+ p += strlen(p);
+ }
+}
+
+#endif /* LOADAV */
diff --git a/logfile.c b/logfile.c
new file mode 100644
index 0000000..c1ffb15
--- /dev/null
+++ b/logfile.c
@@ -0,0 +1,251 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h> /* dev_t, ino_t, off_t, ... */
+#include <sys/stat.h> /* struct stat */
+#include <fcntl.h> /* O_WRONLY for logfile_reopen */
+
+#include "config.h"
+#include "screen.h"
+#include "extern.h"
+#include "logfile.h"
+
+static void changed_logfile __P((struct logfile *));
+static struct logfile *lookup_logfile __P((char *));
+static int stolen_logfile __P((struct logfile *));
+
+static struct logfile *logroot = NULL;
+
+static void changed_logfile(struct logfile *l) {
+ struct stat o, *s = l->st;
+
+ if (fstat(fileno(l->fp), &o) < 0) /* get trouble later */
+ return;
+ if (o.st_size > s->st_size) { /* aha, appended text */
+ s->st_size = o.st_size; /* this should have changed */
+ s->st_mtime = o.st_mtime; /* only size and mtime */
+ }
+}
+
+/*
+ * Requires fd to be open and need_fd to be closed.
+ * If possible, need_fd will be open afterwards and refer to
+ * the object originally reffered by fd. fd will be closed then.
+ * Works just like ``fcntl(fd, DUPFD, need_fd); close(fd);''
+ *
+ * need_fd is returned on success, else -1 is returned.
+ */
+int lf_move_fd(int fd, int need_fd) {
+ int r = -1;
+
+ if (fd == need_fd)
+ return fd;
+ if (fd >=0 && fd < need_fd)
+ r = lf_move_fd(dup(fd), need_fd);
+ close(fd);
+ return r;
+}
+
+static int logfile_reopen(char *name, int wantfd, struct logfile *l) {
+ int got_fd;
+
+ close(wantfd);
+ if (((got_fd = open(name, O_WRONLY | O_CREAT | O_APPEND, 0666)) < 0) || lf_move_fd(got_fd, wantfd) < 0) {
+ logfclose(l);
+ debug1("logfile_reopen: failed for %s\n", name);
+ return -1;
+ }
+ changed_logfile(l);
+ debug2("logfile_reopen: %d = %s\n", wantfd, name);
+ return 0;
+}
+
+static int (* lf_reopen_fn)() = logfile_reopen;
+
+/*
+ * Whenever logfwrite discoveres that it is required to close and
+ * reopen the logfile, the function registered here is called.
+ * If you do not register anything here, the above logfile_reopen()
+ * will be used instead.
+ * Your function should perform the same steps as logfile_reopen():
+ * a) close the original filedescriptor without flushing any output
+ * b) open a new logfile for future output on the same filedescriptor number.
+ * c) zero out st_dev, st_ino to tell the stolen_logfile() indcator to
+ * reinitialise itself.
+ * d) return 0 on success.
+ */
+void logreopen_register(fn)
+int (*fn) __P((char *, int, struct logfile *));
+{
+ lf_reopen_fn = fn ? fn : logfile_reopen;
+}
+
+/*
+ * If the logfile has been removed, truncated, unlinked or the like,
+ * return nonzero.
+ * The l->st structure initialised by logfopen is updated
+ * on every call.
+ */
+static int stolen_logfile(struct logfile *l) {
+ struct stat o, *s = l->st;
+
+ o = *s;
+ if (fstat(fileno(l->fp), s) < 0) /* remember that stat failed */
+ s->st_ino = s->st_dev = 0;
+
+ ASSERT(s == l->st);
+ if (!o.st_dev && !o.st_ino) /* nothing to compare with */
+ return 0;
+
+ if ((!s->st_dev && !s->st_ino) || /* stat failed, that's new! */
+ !s->st_nlink || /* red alert: file unlinked */
+ (s->st_size < o.st_size) || /* file truncated */
+ (s->st_mtime != o.st_mtime) || /* file modified */
+ ((s->st_ctime != o.st_ctime) && /* file changed (moved) */
+ !(s->st_mtime == s->st_ctime && /* and it was not a change */
+ o.st_ctime < s->st_ctime))) /* due to delayed nfs write */
+ {
+ debug1("stolen_logfile: %s stolen!\n", l->name);
+ debug3("st_dev %d, st_ino %d, st_nlink %d\n", (int)s->st_dev, (int)s->st_ino, (int)s->st_nlink);
+ debug2("s->st_size %d, o.st_size %d\n", (int)s->st_size, (int)o.st_size);
+ debug2("s->st_mtime %d, o.st_mtime %d\n", (int)s->st_mtime, (int)o.st_mtime);
+ debug2("s->st_ctime %d, o.st_ctime %d\n", (int)s->st_ctime, (int)o.st_ctime);
+ return -1;
+ }
+ debug1("stolen_logfile: %s o.k.\n", l->name);
+ return 0;
+}
+
+static struct logfile *lookup_logfile(char *name) {
+ struct logfile *l;
+
+ for (l = logroot; l; l = l->next)
+ if (!strcmp(name, l->name))
+ return l;
+ return NULL;
+}
+
+struct logfile *logfopen(char *name, FILE *fp) {
+ struct logfile *l;
+
+ if (!fp) {
+ if (!(l = lookup_logfile(name)))
+ return NULL;
+ l->opencount++;
+ return l;
+ }
+
+ if (!(l = (struct logfile *)malloc(sizeof(struct logfile))))
+ return NULL;
+ if (!(l->st = (struct stat *)malloc(sizeof(struct stat)))) {
+ free((char *)l);
+ return NULL;
+ }
+
+ if (!(l->name = SaveStr(name))) {
+ free((char *)l->st);
+ free((char *)l);
+ return NULL;
+ }
+ l->fp = fp;
+ l->opencount = 1;
+ l->writecount = 0;
+ l->flushcount = 0;
+ changed_logfile(l);
+
+ l->next = logroot;
+ logroot = l;
+ return l;
+}
+
+int islogfile(char *name) {
+ if (!name)
+ return logroot ? 1 : 0;
+ return lookup_logfile(name) ? 1 : 0;
+}
+
+int logfclose(struct logfile *l) {
+ struct logfile **lp;
+
+ for (lp = &logroot; *lp; lp = &(*lp)->next)
+ if (*lp == l)
+ break;
+
+ if (!*lp)
+ return -1;
+
+ if ((--l->opencount) > 0)
+ return 0;
+ if (l->opencount < 0)
+ abort();
+
+ *lp = l->next;
+ fclose(l->fp);
+ free(l->name);
+ free((char *)l);
+ return 0;
+}
+
+/*
+ * XXX
+ * write and flush both *should* check the file's stat, if it disappeared
+ * or changed, re-open it.
+ */
+int logfwrite(struct logfile *l, char *buf, int n) {
+ int r;
+
+ if (stolen_logfile(l) && lf_reopen_fn(l->name, fileno(l->fp), l))
+ return -1;
+ r = fwrite(buf, n, 1, l->fp);
+ l->writecount += l->flushcount + 1;
+ l->flushcount = 0;
+ changed_logfile(l);
+ return r;
+}
+
+int logfflush(struct logfile *l) {
+ int r = 0;
+
+ if (!l)
+ for (l = logroot; l; l = l->next) {
+ if (stolen_logfile(l) && lf_reopen_fn(l->name, fileno(l->fp), l))
+ return -1;
+ r |= fflush(l->fp);
+ l->flushcount++;
+ changed_logfile(l);
+ }
+ else {
+ if (stolen_logfile(l) && lf_reopen_fn(l->name, fileno(l->fp), l))
+ return -1;
+ r = fflush(l->fp);
+ l->flushcount++;
+ changed_logfile(l);
+ }
+ return r;
+}
+
diff --git a/logfile.h b/logfile.h
new file mode 100644
index 0000000..c588a32
--- /dev/null
+++ b/logfile.h
@@ -0,0 +1,87 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+struct logfile
+{
+ struct logfile *next;
+ FILE *fp; /* a hopefully uniq filepointer to the log file */
+ char *name; /* the name. used to reopen, when stat fails. */
+ int opencount; /* synchronize logfopen() and logfclose() */
+ int writecount; /* increments at logfwrite(), counts write() and fflush() */
+ int flushcount; /* increments at logfflush(), zeroed at logfwrite() */
+ struct stat *st; /* how the file looks like */
+};
+
+/*
+ * open a logfile, The second argument must be NULL, when the named file
+ * is already a logfile or must be a appropriatly opened file pointer
+ * otherwise.
+ * example: l = logfopen(name, islogfile(name) : NULL ? fopen(name, "a"));
+ */
+struct logfile *logfopen __P((char *name, FILE *fp));
+
+/*
+ * lookup a logfile by name. This is useful, so that we can provide
+ * logfopen with a nonzero second argument, exactly when needed.
+ * islogfile(NULL); returns nonzero if there are any open logfiles at all.
+ */
+int islogfile __P((char *name));
+
+/*
+ * logfclose does free()
+ */
+int logfclose __P((struct logfile *));
+int logfwrite __P((struct logfile *, char *, int));
+
+/*
+ * logfflush should be called periodically. If no argument is passed,
+ * all logfiles are flushed, else the specified file
+ * the number of flushed filepointers is returned
+ */
+int logfflush __P((struct logfile *ifany));
+
+/*
+ * a reopen function may be registered here, in case you want to bring your
+ * own (more secure open), it may come along with a private data pointer.
+ * this function is called, whenever logfwrite/logfflush detect that the
+ * file has been (re)moved, truncated or changed by someone else.
+ * if you provide NULL as parameter to logreopen_register, the builtin
+ * reopen function will be reactivated.
+ */
+void logreopen_register __P((int (*fn) __P((char *, int, struct logfile *)) ));
+
+/*
+ * Your custom reopen function is required to reuse the exact
+ * filedescriptor.
+ * See logfile.c for further specs and an example.
+ *
+ * lf_move_fd may help you here, if you do not have dup2(2).
+ * It closes fd and opens wantfd to access whatever fd accessed.
+ */
+int lf_move_fd __P((int fd, int wantfd));
diff --git a/mark.c b/mark.c
new file mode 100644
index 0000000..5b339b4
--- /dev/null
+++ b/mark.c
@@ -0,0 +1,1537 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+#include <ctype.h>
+
+#include "config.h"
+#include "screen.h"
+#include "mark.h"
+#include "extern.h"
+
+#ifdef COPY_PASTE
+
+/*
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ *
+ * WARNING: these routines use the global variables "fore" and
+ * "flayer" to make things easier.
+ *
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ */
+
+static int is_letter __P((int));
+static void nextword __P((int *, int *, int, int));
+static int linestart __P((int));
+static int lineend __P((int));
+static int rem __P((int, int , int , int , int , char *, int));
+static int eq __P((int, int ));
+static int MarkScrollDownDisplay __P((int));
+static int MarkScrollUpDisplay __P((int));
+
+static void MarkProcess __P((char **, int *));
+static void MarkAbort __P((void));
+static void MarkRedisplayLine __P((int, int, int, int));
+static int MarkRewrite __P((int, int, int, struct mchar *, int));
+
+extern struct layer *flayer;
+extern struct display *display, *displays;
+extern struct win *fore;
+extern struct mline mline_blank, mline_null;
+extern struct mchar mchar_so;
+
+#ifdef FONT
+int pastefont = 1;
+#endif
+
+struct LayFuncs MarkLf =
+{
+ MarkProcess,
+ MarkAbort,
+ MarkRedisplayLine,
+ DefClearLine,
+ MarkRewrite,
+ DefResize,
+ DefRestore,
+ 0
+};
+
+int join_with_cr = 0;
+int compacthist = 0;
+
+unsigned char mark_key_tab[256]; /* this array must be initialised first! */
+
+static struct markdata *markdata;
+
+
+/*
+ * VI like is_letter: 0 - whitespace
+ * 1 - letter
+ * 2 - other
+ */
+static int is_letter(c)
+char c;
+{
+ if ((c >= 'a' && c <= 'z') ||
+ (c >= 'A' && c <= 'Z') ||
+ (c >= '0' && c <= '9') ||
+ c == '_' || c == '.' ||
+ c == '@' || c == ':' ||
+ c == '%' || c == '!' ||
+ c == '-' || c == '+')
+ /* thus we can catch email-addresses as a word :-) */
+ return 1;
+ else if (c != ' ')
+ return 2;
+ return 0;
+}
+
+static int
+linestart(y)
+int y;
+{
+ register int x;
+ register unsigned char *i;
+
+ for (x = markdata->left_mar, i = WIN(y)->image + x; x < fore->w_width - 1; x++)
+ if (*i++ != ' ')
+ break;
+ if (x == fore->w_width - 1)
+ x = markdata->left_mar;
+ return x;
+}
+
+static int
+lineend(y)
+int y;
+{
+ register int x;
+ register unsigned char *i;
+
+ for (x = markdata->right_mar, i = WIN(y)->image + x; x >= 0; x--)
+ if (*i-- != ' ')
+ break;
+ if (x < 0)
+ x = markdata->left_mar;
+ return x;
+}
+
+/*
+ * nextchar sets *xp to the num-th occurrence of the target in the line.
+ *
+ * Returns -1 if the target doesn't appear num times, 0 otherwise.
+ */
+static int
+nextchar(int *xp, int *yp, int direction, char target, int num)
+{
+ int width; /* width of the current window. */
+ int x; /* x coordinate of the current cursor position. */
+ int step; /* amount to increment x (+1 or -1) */
+ int adjust; /* Final adjustment of cursor position. */
+ char *displayed_line; /* Line in which search takes place. */
+
+ debug("nextchar\n");
+
+ x = *xp;
+ step = 1;
+ adjust = 0;
+ width = fore->w_width;
+ displayed_line = (char *)WIN(*yp) -> image;
+
+ switch(direction) {
+ case 't':
+ adjust = -1; /* fall through */
+ case 'f':
+ step = 1;
+ break;
+ case 'T':
+ adjust = 1; /* fall through */
+ case 'F':
+ step = -1;
+ break;
+ default:
+ ASSERT(0);
+ }
+
+ x += step;
+
+ debug1("ml->image = %s\n", displayed_line);
+ debug2("num = %d, width = %d\n",num, width);
+ debug2("x = %d target = %c\n", x, target );
+
+ for ( ;x>=0 && x <= width; x += step) {
+ if (displayed_line[x] == target) {
+ if (--num == 0) {
+ *xp = x + adjust;
+ return 0;
+ }
+ }
+ }
+ return -1;
+}
+
+/*
+ * nextword calculates the cursor position of the num'th word.
+ * If the cursor is on a word, it counts as the first.
+ * NW_BACK: search backward
+ * NW_ENDOFWORD: find the end of the word
+ * NW_MUSTMOVE: move at least one char
+ * NW_BIG: match WORDs not words
+ */
+
+#define NW_BACK (1<<0)
+#define NW_ENDOFWORD (1<<1)
+#define NW_MUSTMOVE (1<<2)
+#define NW_BIG (1<<3)
+
+
+
+static void
+nextword(xp, yp, flags, num)
+int *xp, *yp, flags, num;
+{
+ int xx = fore->w_width, yy = fore->w_histheight + fore->w_height;
+ register int sx, oq, q, x, y;
+ struct mline *ml;
+
+ x = *xp;
+ y = *yp;
+ sx = (flags & NW_BACK) ? -1 : 1;
+ if ((flags & NW_ENDOFWORD) && (flags & NW_MUSTMOVE))
+ x += sx;
+ ml = WIN(y);
+ for (oq = -1; ; x += sx, oq = q)
+ {
+ if (x >= xx || x < 0)
+ q = 0;
+ else if (flags & NW_BIG)
+ q = ml->image[x] == ' ';
+ else
+ q = is_letter(ml->image[x]);
+ if (oq >= 0 && oq != q)
+ {
+ if (oq == 0 || !(flags & NW_ENDOFWORD))
+ *xp = x;
+ else
+ *xp = x-sx;
+ *yp = y;
+ if ((!(flags & NW_ENDOFWORD) && q) ||
+ ((flags & NW_ENDOFWORD) && oq))
+ {
+ if (--num <= 0)
+ return;
+ }
+ }
+ if (x == xx)
+ {
+ x = -1;
+ if (++y >= yy)
+ return;
+ ml = WIN(y);
+ }
+ else if (x < 0)
+ {
+ x = xx;
+ if (--y < 0)
+ return;
+ ml = WIN(y);
+ }
+ }
+}
+
+
+/*
+ * y1, y2 are WIN coordinates
+ *
+ * redisplay: 0 - just copy
+ * 1 - redisplay + copy
+ * 2 - count + copy, don't redisplay
+ */
+
+static int
+rem(x1, y1, x2, y2, redisplay, pt, yend)
+int x1, y1, x2, y2, redisplay, yend;
+char *pt;
+{
+ int i, j, from, to, ry, c;
+ int l = 0;
+ unsigned char *im;
+ struct mline *ml;
+#ifdef FONT
+ int cf, cfx, font;
+ unsigned char *fo, *fox;
+#endif
+
+ markdata->second = 0;
+ if (y2 < y1 || ((y2 == y1) && (x2 < x1)))
+ {
+ i = y2;
+ y2 = y1;
+ y1 = i;
+ i = x2;
+ x2 = x1;
+ x1 = i;
+ }
+ ry = y1 - markdata->hist_offset;
+
+ i = y1;
+ if (redisplay != 2 && pt == 0 && ry <0)
+ {
+ i -= ry;
+ ry = 0;
+ }
+ for (; i <= y2; i++, ry++)
+ {
+ if (redisplay != 2 && pt == 0 && ry > yend)
+ break;
+ ml = WIN(i);
+ from = (i == y1) ? x1 : 0;
+ if (from < markdata->left_mar)
+ from = markdata->left_mar;
+ for (to = fore->w_width, im = ml->image + to; to >= 0; to--)
+ if (*im-- != ' ')
+ break;
+ if (i == y2 && x2 < to)
+ to = x2;
+ if (to > markdata->right_mar)
+ to = markdata->right_mar;
+ if (redisplay == 1 && from <= to && ry >=0 && ry <= yend)
+ MarkRedisplayLine(ry, from, to, 0);
+ if (redisplay != 2 && pt == 0) /* don't count/copy */
+ continue;
+ j = from;
+#ifdef DW_CHARS
+ if (dw_right(ml, j, fore->w_encoding))
+ j--;
+#endif
+ im = ml->image + j;
+#ifdef FONT
+ fo = ml->font + j;
+ fox = ml->fontx + j;
+ font = ASCII;
+#endif
+ for (; j <= to; j++)
+ {
+ c = (unsigned char)*im++;
+#ifdef FONT
+ cf = (unsigned char)*fo++;
+ cfx = (unsigned char)*fox++;
+# ifdef UTF8
+ if (fore->w_encoding == UTF8)
+ {
+ c |= cf << 8 | cfx << 16;
+ if (c == UCS_HIDDEN)
+ continue;
+ c = ToUtf8_comb(pt, c);
+ l += c;
+ if (pt)
+ pt += c;
+ continue;
+ }
+# endif
+# ifdef DW_CHARS
+ if (is_dw_font(cf))
+ {
+ c = c << 8 | (unsigned char)*im++;
+ fo++;
+ j++;
+ }
+# endif
+ if (pastefont)
+ {
+ c = EncodeChar(pt, c | cf << 16, fore->w_encoding, &font);
+ l += c;
+ if (pt)
+ pt += c;
+ continue;
+ }
+#endif /* FONT */
+ if (pt)
+ *pt++ = c;
+ l++;
+ }
+#ifdef FONT
+ if (pastefont && font != ASCII)
+ {
+ if (pt)
+ {
+ strcpy(pt, "\033(B");
+ pt += 3;
+ }
+ l += 3;
+ }
+#endif
+ if (i != y2 && (to != fore->w_width - 1 || ml->image[to + 1] == ' '))
+ {
+ /*
+ * this code defines, what glues lines together
+ */
+ switch (markdata->nonl)
+ {
+ case 0: /* lines separated by newlines */
+ if (pt)
+ *pt++ = '\r';
+ l++;
+ if (join_with_cr)
+ {
+ if (pt)
+ *pt++ = '\n';
+ l++;
+ }
+ break;
+ case 1: /* nothing to separate lines */
+ break;
+ case 2: /* lines separated by blanks */
+ if (pt)
+ *pt++ = ' ';
+ l++;
+ break;
+ case 3: /* seperate by comma, for csh junkies */
+ if (pt)
+ *pt++ = ',';
+ l++;
+ break;
+ }
+ }
+ }
+ return l;
+}
+
+/* Check if two chars are identical. All digits are treated
+ * as same. Used for GetHistory()
+ */
+
+static int
+eq(a, b)
+int a, b;
+{
+ if (a == b)
+ return 1;
+ if (a == 0 || b == 0)
+ return 1;
+ if (a <= '9' && a >= '0' && b <= '9' && b >= '0')
+ return 1;
+ return 0;
+}
+
+
+/**********************************************************************/
+
+int
+GetHistory() /* return value 1 if copybuffer changed */
+{
+ int i = 0, q = 0, xx, yy, x, y;
+ unsigned char *linep;
+ struct mline *ml;
+
+ ASSERT(display && fore);
+ x = fore->w_x;
+ if (x >= fore->w_width)
+ x = fore->w_width - 1;
+ y = fore->w_y + fore->w_histheight;
+ debug2("cursor is at x=%d, y=%d\n", x, y);
+ ml = WIN(y);
+ for (xx = x - 1, linep = ml->image + xx; xx >= 0; xx--)
+ if ((q = *linep--) != ' ' )
+ break;
+ debug3("%c at (%d,%d)\n", q, xx, y);
+ for (yy = y - 1; yy >= 0; yy--)
+ {
+ ml = WIN(yy);
+ linep = ml->image;
+ if (xx < 0 || eq(linep[xx], q))
+ { /* line is matching... */
+ for (i = fore->w_width - 1, linep += i; i >= x; i--)
+ if (*linep-- != ' ')
+ break;
+ if (i >= x)
+ break;
+ }
+ }
+ if (yy < 0)
+ return 0;
+ if (D_user->u_plop.buf)
+ UserFreeCopyBuffer(D_user);
+ if ((D_user->u_plop.buf = (char *)malloc((unsigned) (i - x + 2))) == NULL)
+ {
+ LMsg(0, "Not enough memory... Sorry.");
+ return 0;
+ }
+ bcopy((char *)linep - i + x + 1, D_user->u_plop.buf, i - x + 1);
+ D_user->u_plop.len = i - x + 1;
+#ifdef ENCODINGS
+ D_user->u_plop.enc = fore->w_encoding;
+#endif
+ return 1;
+}
+
+/**********************************************************************/
+
+
+void
+MarkRoutine()
+{
+ int x, y;
+
+ ASSERT(fore && display && D_user);
+
+ debug2("MarkRoutine called: fore nr %d, display %s\n",
+ fore->w_number, D_usertty);
+
+ if (InitOverlayPage(sizeof(*markdata), &MarkLf, 1))
+ return;
+ flayer->l_encoding = fore->w_encoding;
+ flayer->l_mode = 1;
+ markdata = (struct markdata *)flayer->l_data;
+ markdata->md_user = D_user; /* XXX: Correct? */
+ markdata->md_window = fore;
+ markdata->second = 0;
+ markdata->rep_cnt = 0;
+ markdata->append_mode = 0;
+ markdata->write_buffer = 0;
+ markdata->nonl = 0;
+ markdata->left_mar = 0;
+ markdata->right_mar = fore->w_width - 1;
+ markdata->hist_offset = fore->w_histheight;
+ x = fore->w_x;
+ y = D2W(fore->w_y);
+ if (x >= fore->w_width)
+ x = fore->w_width - 1;
+
+ LGotoPos(flayer, x, W2D(y));
+ LMsg(0, "Copy mode - Column %d Line %d(+%d) (%d,%d)",
+ x + 1, W2D(y + 1), fore->w_histheight, fore->w_width, fore->w_height);
+ markdata->cx = markdata->x1 = x;
+ markdata->cy = markdata->y1 = y;
+ flayer->l_x = x;
+ flayer->l_y = W2D(y);
+}
+
+static void
+MarkProcess(inbufp,inlenp)
+char **inbufp;
+int *inlenp;
+{
+ char *inbuf, *pt;
+ int inlen;
+ int cx, cy, x2, y2, j, yend;
+ int newcopylen = 0, od;
+ int in_mark;
+ int rep_cnt;
+ struct acluser *md_user;
+
+/*
+ char *extrap = 0, extrabuf[100];
+*/
+
+ markdata = (struct markdata *)flayer->l_data;
+ fore = markdata->md_window;
+ md_user = markdata->md_user;
+ if (inbufp == 0)
+ {
+ MarkAbort();
+ return;
+ }
+
+ LGotoPos(flayer, markdata->cx, W2D(markdata->cy));
+ inbuf= *inbufp;
+ inlen= *inlenp;
+ pt = inbuf;
+ in_mark = 1;
+ while (in_mark && (inlen /* || extrap */))
+ {
+ unsigned char ch = (unsigned char )*pt++;
+ inlen--;
+ if (flayer->l_mouseevent.start)
+ {
+ int r = LayProcessMouse(flayer, ch);
+ if (r == -1)
+ LayProcessMouseSwitch(flayer, 0);
+ else
+ {
+ if (r)
+ ch = 0222;
+ else
+ continue;
+ }
+ }
+ od = mark_key_tab[(int)ch];
+ rep_cnt = markdata->rep_cnt;
+ if (od >= '0' && od <= '9' && !markdata->f_cmd.flag)
+ {
+ if (rep_cnt < 1001 && (od != '0' || rep_cnt != 0))
+ {
+ markdata->rep_cnt = 10 * rep_cnt + od - '0';
+ continue;
+ /*
+ * Now what is that 1001 here? Well, we have a screen with
+ * 25 * 80 = 2000 characters. Movement is at most across the full
+ * screen. This we do with word by word movement, as character by
+ * character movement never steps over line boundaries. The most words
+ * we can place on the screen are 1000 single letter words. Thus 1001
+ * is sufficient. Users with bigger screens never write in single letter
+ * words, as they should be more advanced. jw.
+ * Oh, wrong. We still give even the experienced user a factor of ten.
+ */
+ }
+ }
+ cx = markdata->cx;
+ cy = markdata->cy;
+
+ if (markdata -> f_cmd.flag) {
+ debug2("searching for %c:%d\n",od,rep_cnt);
+ markdata->f_cmd.flag = 0;
+ markdata->rep_cnt = 0;
+
+ if (isgraph (od)) {
+ markdata->f_cmd.target = od;
+ rep_cnt = (rep_cnt) ? rep_cnt : 1;
+ nextchar(&cx, &cy, markdata->f_cmd.direction, od, rep_cnt );
+ revto(cx, cy);
+ continue;
+ }
+ }
+
+processchar:
+ switch (od)
+ {
+ case 'f': /* fall through */
+ case 'F': /* fall through */
+ case 't': /* fall through */
+ case 'T': /* fall through */
+ /*
+ * Set f_cmd to do a search on the next key stroke.
+ * If we break, rep_cnt will be reset, so we
+ * continue instead. It might be cleaner to
+ * store the rep_count in f_cmd and
+ * break here so later followon code will be
+ * hit.
+ */
+ markdata->f_cmd.flag = 1;
+ markdata->f_cmd.direction = od;
+ debug("entering char search\n");
+ continue;
+ case ';':
+ case ',':
+ if (!markdata->f_cmd.target)
+ break;
+ if (!rep_cnt)
+ rep_cnt = 1;
+ nextchar(&cx, &cy,
+ od == ';' ? markdata->f_cmd.direction : (markdata->f_cmd.direction ^ 0x20),
+ markdata->f_cmd.target, rep_cnt );
+ revto(cx, cy);
+ break;
+ case 'o':
+ case 'x':
+ if (!markdata->second)
+ break;
+ markdata->cx = markdata->x1;
+ markdata->cy = markdata->y1;
+ markdata->x1 = cx;
+ markdata->y1 = cy;
+ revto(markdata->cx, markdata->cy);
+ break;
+ case '\014': /* CTRL-L Redisplay */
+ Redisplay(0);
+ LGotoPos(flayer, cx, W2D(cy));
+ break;
+ case 0202: /* M-C-b */
+ case '\010': /* CTRL-H Backspace */
+ case 'h':
+ if (rep_cnt == 0)
+ rep_cnt = 1;
+ revto(cx - rep_cnt, cy);
+ break;
+ case 0216: /* M-C-p */
+ case '\016': /* CTRL-N */
+ case 'j':
+ if (rep_cnt == 0)
+ rep_cnt = 1;
+ revto(cx, cy + rep_cnt);
+ break;
+ case '+':
+ if (rep_cnt == 0)
+ rep_cnt = 1;
+ j = cy + rep_cnt;
+ if (j > fore->w_histheight + fore->w_height - 1)
+ j = fore->w_histheight + fore->w_height - 1;
+ revto(linestart(j), j);
+ break;
+ case '-':
+ if (rep_cnt == 0)
+ rep_cnt = 1;
+ cy -= rep_cnt;
+ if (cy < 0)
+ cy = 0;
+ revto(linestart(cy), cy);
+ break;
+ case '^':
+ revto(linestart(cy), cy);
+ break;
+ case '\n':
+ revto(markdata->left_mar, cy + 1);
+ break;
+ case 0220: /* M-C-p */
+ case '\020': /* CTRL-P */
+ case 'k':
+ if (rep_cnt == 0)
+ rep_cnt = 1;
+ revto(cx, cy - rep_cnt);
+ break;
+ case 0206: /* M-C-f */
+ case 'l':
+ if (rep_cnt == 0)
+ rep_cnt = 1;
+ revto(cx + rep_cnt, cy);
+ break;
+ case '\001': /* CTRL-A from tcsh/emacs */
+ case '0':
+ revto(markdata->left_mar, cy);
+ break;
+ case '\004': /* CTRL-D down half screen */
+ if (rep_cnt == 0)
+ rep_cnt = (fore->w_height + 1) >> 1;
+ revto_line(cx, cy + rep_cnt, W2D(cy));
+ break;
+ case '$':
+ revto(lineend(cy), cy);
+ break;
+ case '\022': /* CTRL-R emacs style backwards search */
+ ISearch(-1);
+ in_mark = 0;
+ break;
+ case '\023': /* CTRL-S emacs style search */
+ ISearch(1);
+ in_mark = 0;
+ break;
+ case '\025': /* CTRL-U up half screen */
+ if (rep_cnt == 0)
+ rep_cnt = (fore->w_height + 1) >> 1;
+ revto_line(cx, cy - rep_cnt, W2D(cy));
+ break;
+ case '\007': /* CTRL-G show cursorpos */
+ if (markdata->left_mar == 0 && markdata->right_mar == fore->w_width - 1)
+ LMsg(0, "Column %d Line %d(+%d)", cx+1, W2D(cy)+1,
+ markdata->hist_offset);
+ else
+ LMsg(0, "Column %d(%d..%d) Line %d(+%d)", cx+1,
+ markdata->left_mar+1, markdata->right_mar+1, W2D(cy)+1, markdata->hist_offset);
+ break;
+ case '\002': /* CTRL-B back one page */
+ if (rep_cnt == 0)
+ rep_cnt = 1;
+ rep_cnt *= fore->w_height;
+ revto(cx, cy - rep_cnt);
+ break;
+ case '\006': /* CTRL-F forward one page */
+ if (rep_cnt == 0)
+ rep_cnt = 1;
+ rep_cnt *= fore->w_height;
+ revto(cx, cy + rep_cnt);
+ break;
+ case '\005': /* CTRL-E scroll up */
+ if (rep_cnt == 0)
+ rep_cnt = 1;
+ rep_cnt = MarkScrollUpDisplay(rep_cnt);
+ if (cy < D2W(0))
+ revto(cx, D2W(0));
+ else
+ LGotoPos(flayer, cx, W2D(cy));
+ break;
+ case '\031': /* CTRL-Y scroll down */
+ if (rep_cnt == 0)
+ rep_cnt = 1;
+ rep_cnt = MarkScrollDownDisplay(rep_cnt);
+ if (cy > D2W(fore->w_height-1))
+ revto(cx, D2W(fore->w_height-1));
+ else
+ LGotoPos(flayer, cx, W2D(cy));
+ break;
+ case '@':
+ /* it may be useful to have a key that does nothing */
+ break;
+ case '%':
+ /* rep_cnt is a percentage for the history buffer */
+ if (rep_cnt < 0)
+ rep_cnt = 0;
+ if (rep_cnt > 100)
+ rep_cnt = 100;
+ revto_line(markdata->left_mar,
+ fore->w_histheight - fore->w_scrollback_height +
+ (int)(rep_cnt * (fore->w_scrollback_height + fore->w_height) / 100.0),
+ (fore->w_height - 1) / 2);
+ break;
+ case 0201:
+ case 'g':
+ rep_cnt = 1;
+ /* FALLTHROUGH */
+ case 0205:
+ case 'G':
+ /* rep_cnt is here the WIN line number */
+ if (rep_cnt == 0)
+ rep_cnt = fore->w_histheight + fore->w_height;
+ revto_line(markdata->left_mar, --rep_cnt, (fore->w_height - 1) / 2);
+ break;
+ case 'H':
+ revto(markdata->left_mar, D2W(0));
+ break;
+ case 'M':
+ revto(markdata->left_mar, D2W((fore->w_height - 1) / 2));
+ break;
+ case 'L':
+ revto(markdata->left_mar, D2W(fore->w_height - 1));
+ break;
+ case '|':
+ revto(--rep_cnt, cy);
+ break;
+ case 'w':
+ if (rep_cnt == 0)
+ rep_cnt = 1;
+ nextword(&cx, &cy, NW_MUSTMOVE, rep_cnt);
+ revto(cx, cy);
+ break;
+ case 'e':
+ case 'E':
+ if (rep_cnt == 0)
+ rep_cnt = 1;
+ nextword(&cx, &cy, NW_ENDOFWORD|NW_MUSTMOVE | (od == 'E' ? NW_BIG : 0), rep_cnt);
+ revto(cx, cy);
+ break;
+ case 'b':
+ case 'B':
+ if (rep_cnt == 0)
+ rep_cnt = 1;
+ nextword(&cx, &cy, NW_BACK|NW_ENDOFWORD|NW_MUSTMOVE | (od == 'B' ? NW_BIG : 0), rep_cnt);
+ revto(cx, cy);
+ break;
+ case 'a':
+ markdata->append_mode = 1 - markdata->append_mode;
+ debug1("append mode %d--\n", markdata->append_mode);
+ LMsg(0, (markdata->append_mode) ? ":set append" : ":set noappend");
+ break;
+ case 'v':
+ case 'V':
+ /* this sets start column to column 9 for VI :set nu users */
+ if (markdata->left_mar == 8)
+ rep_cnt = 1;
+ else
+ rep_cnt = 9;
+ /* FALLTHROUGH */
+ case 'c':
+ case 'C':
+ /* set start column (c) and end column (C) */
+ if (markdata->second)
+ {
+ rem(markdata->x1, markdata->y1, cx, cy, 1, (char *)0, fore->w_height-1); /* Hack */
+ markdata->second = 1; /* rem turns off second */
+ }
+ rep_cnt--;
+ if (rep_cnt < 0)
+ rep_cnt = cx;
+ if (od != 'C')
+ {
+ markdata->left_mar = rep_cnt;
+ if (markdata->left_mar > markdata->right_mar)
+ markdata->left_mar = markdata->right_mar;
+ }
+ else
+ {
+ markdata->right_mar = rep_cnt;
+ if (markdata->left_mar > markdata->right_mar)
+ markdata->right_mar = markdata->left_mar;
+ }
+ if (markdata->second)
+ {
+ markdata->cx = markdata->x1; markdata->cy = markdata->y1;
+ revto(cx, cy);
+ }
+ if (od == 'v' || od == 'V')
+ LMsg(0, (markdata->left_mar != 8) ? ":set nonu" : ":set nu");
+ break;
+ case 'J':
+ /* how do you join lines in VI ? */
+ markdata->nonl = (markdata->nonl + 1) % 4;
+ switch (markdata->nonl)
+ {
+ case 0:
+ if (join_with_cr)
+ LMsg(0, "Multiple lines (CR/LF)");
+ else
+ LMsg(0, "Multiple lines (LF)");
+ break;
+ case 1:
+ LMsg(0, "Lines joined");
+ break;
+ case 2:
+ LMsg(0, "Lines joined with blanks");
+ break;
+ case 3:
+ LMsg(0, "Lines joined with comma");
+ break;
+ }
+ break;
+ case '/':
+ Search(1);
+ in_mark = 0;
+ break;
+ case '?':
+ Search(-1);
+ in_mark = 0;
+ break;
+ case 'n':
+ Search(0);
+ break;
+ case 'N':
+ markdata->isdir = -markdata->isdir;
+ Search(0);
+ markdata->isdir = -markdata->isdir;
+ break;
+ case 'y':
+ case 'Y':
+ if (markdata->second == 0)
+ {
+ revto(linestart(cy), cy);
+ markdata->second++;
+ cx = markdata->x1 = markdata->cx;
+ cy = markdata->y1 = markdata->cy;
+ }
+ if (--rep_cnt > 0)
+ revto(cx, cy + rep_cnt);
+ revto(lineend(markdata->cy), markdata->cy);
+ if (od == 'y')
+ break;
+ /* FALLTHROUGH */
+ case 'W':
+ if (od == 'W')
+ {
+ if (rep_cnt == 0)
+ rep_cnt = 1;
+ if (!markdata->second)
+ {
+ nextword(&cx, &cy, NW_BACK|NW_ENDOFWORD, 1);
+ revto(cx, cy);
+ markdata->second++;
+ cx = markdata->x1 = markdata->cx;
+ cy = markdata->y1 = markdata->cy;
+ }
+ nextword(&cx, &cy, NW_ENDOFWORD, rep_cnt);
+ revto(cx, cy);
+ }
+ cx = markdata->cx;
+ cy = markdata->cy;
+ /* FALLTHROUGH */
+ case 'A':
+ if (od == 'A')
+ markdata->append_mode = 1;
+ /* FALLTHROUGH */
+ case '>':
+ if (od == '>')
+ markdata->write_buffer = 1;
+ /* FALLTHROUGH */
+ case ' ':
+ case '\r':
+ if (!markdata->second)
+ {
+ markdata->second++;
+ markdata->x1 = cx;
+ markdata->y1 = cy;
+ revto(cx, cy);
+ LMsg(0, "First mark set - Column %d Line %d", cx+1, W2D(cy)+1);
+ break;
+ }
+ else
+ {
+ int append_mode = markdata->append_mode;
+ int write_buffer = markdata->write_buffer;
+
+ x2 = cx;
+ y2 = cy;
+ newcopylen = rem(markdata->x1, markdata->y1, x2, y2, 2, (char *)0, 0); /* count */
+ if (md_user->u_plop.buf && !append_mode)
+ UserFreeCopyBuffer(md_user);
+ yend = fore->w_height - 1;
+ if (fore->w_histheight - markdata->hist_offset < fore->w_height)
+ {
+ markdata->second = 0;
+ yend -= MarkScrollUpDisplay(fore->w_histheight - markdata->hist_offset);
+ }
+ if (newcopylen > 0)
+ {
+ /* the +3 below is for : cr + lf + \0 */
+ if (md_user->u_plop.buf)
+ md_user->u_plop.buf = realloc(md_user->u_plop.buf,
+ (unsigned) (md_user->u_plop.len + newcopylen + 3));
+ else
+ {
+ md_user->u_plop.len = 0;
+ md_user->u_plop.buf = malloc((unsigned) (newcopylen + 3));
+ }
+ if (!md_user->u_plop.buf)
+ {
+ MarkAbort();
+ in_mark = 0;
+ LMsg(0, "Not enough memory... Sorry.");
+ md_user->u_plop.len = 0;
+ md_user->u_plop.buf = 0;
+ break;
+ }
+ if (append_mode)
+ {
+ switch (markdata->nonl)
+ {
+ /*
+ * this code defines, what glues lines together
+ */
+ case 0:
+ if (join_with_cr)
+ {
+ md_user->u_plop.buf[md_user->u_plop.len] = '\r';
+ md_user->u_plop.len++;
+ }
+ md_user->u_plop.buf[md_user->u_plop.len] = '\n';
+ md_user->u_plop.len++;
+ break;
+ case 1:
+ break;
+ case 2:
+ md_user->u_plop.buf[md_user->u_plop.len] = ' ';
+ md_user->u_plop.len++;
+ break;
+ case 3:
+ md_user->u_plop.buf[md_user->u_plop.len] = ',';
+ md_user->u_plop.len++;
+ break;
+ }
+ }
+ md_user->u_plop.len += rem(markdata->x1, markdata->y1, x2, y2,
+ markdata->hist_offset == fore->w_histheight,
+ md_user->u_plop.buf + md_user->u_plop.len, yend);
+#ifdef ENCODINGS
+ md_user->u_plop.enc = fore->w_encoding;
+#endif
+ }
+ if (markdata->hist_offset != fore->w_histheight)
+ {
+ LAY_CALL_UP(LRefreshAll(flayer, 0));
+ }
+ ExitOverlayPage();
+ WindowChanged(fore, 'P');
+ if (append_mode)
+ LMsg(0, "Appended %d characters to buffer",
+ newcopylen);
+ else
+ LMsg(0, "Copied %d characters into buffer", md_user->u_plop.len);
+ if (write_buffer)
+ WriteFile(md_user, (char *)0, DUMP_EXCHANGE);
+ in_mark = 0;
+ break;
+ }
+
+ case 0222:
+ if (flayer->l_mouseevent.start)
+ {
+ int button = flayer->l_mouseevent.buffer[0];
+ if (button == 'a')
+ {
+ /* Scroll down */
+ od = 'j';
+ }
+ else if (button == '`')
+ {
+ /* Scroll up */
+ od = 'k';
+ }
+ else if (button == ' ')
+ {
+ /* Left click */
+ cx = flayer->l_mouseevent.buffer[1];
+ cy = D2W(flayer->l_mouseevent.buffer[2]);
+ revto(cx, cy);
+ od = ' ';
+ }
+ else
+ od = 0;
+ LayProcessMouseSwitch(flayer, 0);
+ if (od)
+ goto processchar;
+ }
+ else
+ LayProcessMouseSwitch(flayer, 1);
+ break;
+
+ default:
+ MarkAbort();
+ LMsg(0, "Copy mode aborted");
+ in_mark = 0;
+ break;
+ }
+ if (in_mark) /* markdata may be freed */
+ markdata->rep_cnt = 0;
+ }
+ if (in_mark)
+ {
+ flayer->l_x = markdata->cx;
+ flayer->l_y = W2D(markdata->cy);
+ }
+ *inbufp = pt;
+ *inlenp = inlen;
+}
+
+void revto(tx, ty)
+int tx, ty;
+{
+ revto_line(tx, ty, -1);
+}
+
+/* tx, ty: WINDOW, line: DISPLAY */
+void revto_line(tx, ty, line)
+int tx, ty, line;
+{
+ int fx, fy;
+ int x, y, t, revst, reven, qq, ff, tt, st, en, ce = 0;
+ int ystart = 0, yend = fore->w_height-1;
+ int i, ry;
+ unsigned char *wi;
+ struct mline *ml;
+ struct mchar mc;
+
+ if (tx < 0)
+ tx = 0;
+ else if (tx > fore->w_width - 1)
+ tx = fore->w_width -1;
+ if (ty < fore->w_histheight - fore->w_scrollback_height)
+ ty = fore->w_histheight - fore->w_scrollback_height;
+ else if (ty > fore->w_histheight + fore->w_height - 1)
+ ty = fore->w_histheight + fore->w_height - 1;
+
+ fx = markdata->cx; fy = markdata->cy;
+
+#ifdef DW_CHARS
+ /* don't just move inside of a kanji, the user wants to see something */
+ ml = WIN(ty);
+ if (ty == fy && fx + 1 == tx && dw_right(ml, tx, fore->w_encoding) && tx < D_width - 1)
+ tx++;
+ if (ty == fy && fx - 1 == tx && dw_right(ml, fx, fore->w_encoding) && tx)
+ tx--;
+#endif
+
+ markdata->cx = tx; markdata->cy = ty;
+
+ /*
+ * if we go to a position that is currently offscreen
+ * then scroll the screen
+ */
+ i = 0;
+ if (line >= 0 && line < fore->w_height)
+ i = W2D(ty) - line;
+ else if (ty < markdata->hist_offset)
+ i = ty - markdata->hist_offset;
+ else if (ty > markdata->hist_offset + (fore->w_height - 1))
+ i = ty - markdata->hist_offset - (fore->w_height - 1);
+ if (i > 0)
+ yend -= MarkScrollUpDisplay(i);
+ else if (i < 0)
+ ystart += MarkScrollDownDisplay(-i);
+
+ if (markdata->second == 0)
+ {
+ flayer->l_x = tx;
+ flayer->l_y = W2D(ty);
+ LGotoPos(flayer, tx, W2D(ty));
+ return;
+ }
+
+ qq = markdata->x1 + markdata->y1 * fore->w_width;
+ ff = fx + fy * fore->w_width; /* "from" offset in WIN coords */
+ tt = tx + ty * fore->w_width; /* "to" offset in WIN coords*/
+
+ if (ff > tt)
+ {
+ st = tt; en = ff;
+ x = tx; y = ty;
+ }
+ else
+ {
+ st = ff; en = tt;
+ x = fx; y = fy;
+ }
+ if (st > qq)
+ {
+ st++;
+ x++;
+ }
+ if (en < qq)
+ en--;
+ if (tt > qq)
+ {
+ revst = qq; reven = tt;
+ }
+ else
+ {
+ revst = tt; reven = qq;
+ }
+ ry = y - markdata->hist_offset;
+ if (ry < ystart)
+ {
+ y += (ystart - ry);
+ x = 0;
+ st = y * fore->w_width;
+ ry = ystart;
+ }
+ ml = WIN(y);
+ for (t = st; t <= en; t++, x++)
+ {
+ if (x >= fore->w_width)
+ {
+ x = 0;
+ y++, ry++;
+ ml = WIN(y);
+ }
+ if (ry > yend)
+ break;
+ if (t == st || x == 0)
+ {
+ wi = ml->image + fore->w_width;
+ for (ce = fore->w_width; ce >= 0; ce--, wi--)
+ if (*wi != ' ')
+ break;
+ }
+ if (x <= ce && x >= markdata->left_mar && x <= markdata->right_mar)
+ {
+#ifdef DW_CHARS
+ if (dw_right(ml, x, fore->w_encoding))
+ {
+ if (t == revst)
+ revst--;
+ t--;
+ x--;
+ }
+#endif
+ if (t >= revst && t <= reven)
+ {
+ mc = mchar_so;
+#ifdef FONT
+ if (pastefont)
+ {
+ mc.font = ml->font[x];
+ mc.fontx = ml->fontx[x];
+ }
+#endif
+ mc.image = ml->image[x];
+ }
+ else
+ copy_mline2mchar(&mc, ml, x);
+#ifdef DW_CHARS
+ if (dw_left(ml, x, fore->w_encoding))
+ {
+ mc.mbcs = ml->image[x + 1];
+ LPutChar(flayer, &mc, x, W2D(y));
+ t++;
+ }
+#endif
+ LPutChar(flayer, &mc, x, W2D(y));
+#ifdef DW_CHARS
+ if (dw_left(ml, x, fore->w_encoding))
+ x++;
+#endif
+ }
+ }
+ flayer->l_x = tx;
+ flayer->l_y = W2D(ty);
+ LGotoPos(flayer, tx, W2D(ty));
+}
+
+static void
+MarkAbort()
+{
+ int yend, redisp;
+
+ debug("MarkAbort\n");
+ markdata = (struct markdata *)flayer->l_data;
+ fore = markdata->md_window;
+ yend = fore->w_height - 1;
+ redisp = markdata->second;
+ if (fore->w_histheight - markdata->hist_offset < fore->w_height)
+ {
+ markdata->second = 0;
+ yend -= MarkScrollUpDisplay(fore->w_histheight - markdata->hist_offset);
+ }
+ if (markdata->hist_offset != fore->w_histheight)
+ {
+ LAY_CALL_UP(LRefreshAll(flayer, 0));
+ }
+ else
+ {
+ rem(markdata->x1, markdata->y1, markdata->cx, markdata->cy, redisp, (char *)0, yend);
+ }
+ ExitOverlayPage();
+ WindowChanged(fore, 'P');
+}
+
+
+static void
+MarkRedisplayLine(y, xs, xe, isblank)
+int y; /* NOTE: y is in DISPLAY coords system! */
+int xs, xe;
+int isblank;
+{
+ int wy, x, i, rm;
+ int sta, sto, cp; /* NOTE: these 3 are in WINDOW coords system */
+ unsigned char *wi;
+ struct mline *ml;
+ struct mchar mchar_marked;
+
+ if (y < 0) /* No special full page handling */
+ return;
+
+ markdata = (struct markdata *)flayer->l_data;
+ fore = markdata->md_window;
+
+ mchar_marked = mchar_so;
+
+ wy = D2W(y);
+ ml = WIN(wy);
+
+ if (markdata->second == 0)
+ {
+ if (dw_right(ml, xs, fore->w_encoding) && xs > 0)
+ xs--;
+ if (dw_left(ml, xe, fore->w_encoding) && xe < fore->w_width - 1)
+ xe++;
+ if (xs == 0 && y > 0 && wy > 0 && WIN(wy - 1)->image[flayer->l_width] == 0)
+ LCDisplayLineWrap(flayer, ml, y, xs, xe, isblank);
+ else
+ LCDisplayLine(flayer, ml, y, xs, xe, isblank);
+ return;
+ }
+
+ sta = markdata->y1 * fore->w_width + markdata->x1;
+ sto = markdata->cy * fore->w_width + markdata->cx;
+ if (sta > sto)
+ {
+ i=sta; sta=sto; sto=i;
+ }
+ cp = wy * fore->w_width + xs;
+
+ rm = markdata->right_mar;
+ for (x = fore->w_width, wi = ml->image + fore->w_width; x >= 0; x--, wi--)
+ if (*wi != ' ')
+ break;
+ if (x < rm)
+ rm = x;
+
+ for (x = xs; x <= xe; x++, cp++)
+ if (cp >= sta && x >= markdata->left_mar)
+ break;
+#ifdef DW_CHARS
+ if (dw_right(ml, x, fore->w_encoding))
+ x--;
+#endif
+ if (x > xs)
+ LCDisplayLine(flayer, ml, y, xs, x - 1, isblank);
+ for (; x <= xe; x++, cp++)
+ {
+ if (cp > sto || x > rm)
+ break;
+#ifdef FONT
+ if (pastefont)
+ {
+ mchar_marked.font = ml->font[x];
+ mchar_marked.fontx = ml->fontx[x];
+ }
+#endif
+ mchar_marked.image = ml->image[x];
+#ifdef DW_CHARS
+ mchar_marked.mbcs = 0;
+ if (dw_left(ml, x, fore->w_encoding))
+ {
+ mchar_marked.mbcs = ml->image[x + 1];
+ cp++;
+ }
+#endif
+ LPutChar(flayer, &mchar_marked, x, y);
+#ifdef DW_CHARS
+ if (dw_left(ml, x, fore->w_encoding))
+ x++;
+#endif
+ }
+ if (x <= xe)
+ LCDisplayLine(flayer, ml, y, x, xe, isblank);
+}
+
+
+/*
+ * This ugly routine is to speed up GotoPos()
+ */
+static int
+MarkRewrite(ry, xs, xe, rend, doit)
+int ry, xs, xe, doit;
+struct mchar *rend;
+{
+ int dx, x, y, st, en, t, rm;
+ unsigned char *i;
+ struct mline *ml;
+ struct mchar mchar_marked;
+
+ mchar_marked = mchar_so;
+
+ debug3("MarkRewrite %d, %d-%d\n", ry, xs, xe);
+ markdata = (struct markdata *)flayer->l_data;
+ fore = markdata->md_window;
+ y = D2W(ry);
+ ml = WIN(y);
+#ifdef UTF8
+ if (fore->w_encoding && fore->w_encoding != UTF8 && D_encoding == UTF8 && ContainsSpecialDeffont(ml, xs, xe, fore->w_encoding))
+ return EXPENSIVE;
+#endif
+ dx = xe - xs + 1;
+ if (doit)
+ {
+ i = ml->image + xs;
+ while (dx--)
+ PUTCHAR(*i++);
+ return 0;
+ }
+
+ if (markdata->second == 0)
+ st = en = -1;
+ else
+ {
+ st = markdata->y1 * fore->w_width + markdata->x1;
+ en = markdata->cy * fore->w_width + markdata->cx;
+ if (st > en)
+ {
+ t = st; st = en; en = t;
+ }
+ }
+ t = y * fore->w_width + xs;
+ for (rm = fore->w_width, i = ml->image + fore->w_width; rm >= 0; rm--)
+ if (*i-- != ' ')
+ break;
+ if (rm > markdata->right_mar)
+ rm = markdata->right_mar;
+ x = xs;
+ while (dx--)
+ {
+ if (t >= st && t <= en && x >= markdata->left_mar && x <= rm)
+ {
+#ifdef FONT
+ if (pastefont)
+ {
+ mchar_marked.font = ml->font[x];
+ mchar_marked.fontx = ml->fontx[x];
+ }
+#endif
+ rend->image = mchar_marked.image;
+ if (!cmp_mchar(rend, &mchar_marked))
+ return EXPENSIVE;
+ }
+ else
+ {
+ rend->image = ml->image[x];
+ if (!cmp_mchar_mline(rend, ml, x))
+ return EXPENSIVE;
+ }
+ x++;
+ }
+ return xe - xs + 1;
+}
+
+
+/*
+ * scroll the screen contents up/down.
+ */
+static int MarkScrollUpDisplay(n)
+int n;
+{
+ int i;
+
+ debug1("MarkScrollUpDisplay(%d)\n", n);
+ if (n <= 0)
+ return 0;
+ if (n > fore->w_histheight - markdata->hist_offset)
+ n = fore->w_histheight - markdata->hist_offset;
+ markdata->hist_offset += n;
+ i = (n < flayer->l_height) ? n : (flayer->l_height);
+ LScrollV(flayer, i, 0, flayer->l_height - 1, 0);
+ while (i-- > 0)
+ MarkRedisplayLine(flayer->l_height - i - 1, 0, flayer->l_width - 1, 1);
+ return n;
+}
+
+static int
+MarkScrollDownDisplay(n)
+int n;
+{
+ int i;
+
+ debug1("MarkScrollDownDisplay(%d)\n", n);
+ if (n <= 0)
+ return 0;
+ if (n > markdata->hist_offset)
+ n = markdata->hist_offset;
+ markdata->hist_offset -= n;
+ i = (n < flayer->l_height) ? n : (flayer->l_height);
+ LScrollV(flayer, -i, 0, fore->w_height - 1, 0);
+ while (i-- > 0)
+ MarkRedisplayLine(i, 0, flayer->l_width - 1, 1);
+ return n;
+}
+
+void
+MakePaster(pa, buf, len, bufiscopy)
+struct paster *pa;
+char *buf;
+int len;
+int bufiscopy;
+{
+ FreePaster(pa);
+ pa->pa_pasteptr = buf;
+ pa->pa_pastelen = len;
+ if (bufiscopy)
+ pa->pa_pastebuf = buf;
+ pa->pa_pastelayer = flayer;
+ DoProcess(Layer2Window(flayer), &pa->pa_pasteptr, &pa->pa_pastelen, pa);
+}
+
+void
+FreePaster(pa)
+struct paster *pa;
+{
+ if (pa->pa_pastebuf)
+ free(pa->pa_pastebuf);
+ pa->pa_pastebuf = 0;
+ pa->pa_pasteptr = 0;
+ pa->pa_pastelen = 0;
+ pa->pa_pastelayer = 0;
+ evdeq(&pa->pa_slowev);
+}
+
+#endif /* COPY_PASTE */
+
diff --git a/mark.h b/mark.h
new file mode 100644
index 0000000..a275fe9
--- /dev/null
+++ b/mark.h
@@ -0,0 +1,58 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+struct markdata
+{
+ struct win *md_window;/* pointer to window we are working on */
+ struct acluser *md_user; /* The user who brought us up */
+ int cx, cy; /* cursor Position in WIN coords*/
+ int x1, y1; /* first mark in WIN coords */
+ int second; /* first mark dropped flag */
+ int left_mar, right_mar, nonl;
+ int rep_cnt; /* number of repeats */
+ int append_mode; /* shall we overwrite or append to copybuffer */
+ int write_buffer; /* shall we do a KEY_WRITE_EXCHANGE right away? */
+ int hist_offset; /* how many lines are on top of the screen */
+ char isstr[100]; /* string we are searching for */
+ int isstrl;
+ char isistr[200]; /* string of chars user has typed */
+ int isistrl;
+ int isdir; /* current search direction */
+ int isstartpos; /* position where isearch was started */
+ int isstartdir; /* direction when isearch was started */
+ struct { /* bookkeeping for fFtT;, commands */
+ int flag, target, direction;
+ } f_cmd;
+
+};
+
+
+#define W2D(y) ((y) - markdata->hist_offset)
+#define D2W(y) ((y) + markdata->hist_offset)
+
diff --git a/misc.c b/misc.c
new file mode 100644
index 0000000..43e93a2
--- /dev/null
+++ b/misc.c
@@ -0,0 +1,771 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h> /* mkdir() declaration */
+#include <signal.h>
+
+#include "config.h"
+#include "screen.h"
+#include "extern.h"
+
+#ifdef SVR4
+# include <sys/resource.h>
+#endif
+
+extern struct layer *flayer;
+
+extern int eff_uid, real_uid;
+extern int eff_gid, real_gid;
+extern struct mline mline_old;
+extern struct mchar mchar_blank;
+extern unsigned char *null, *blank;
+
+#ifdef HAVE_FDWALK
+static int close_func __P((void *, int));
+#endif
+
+char *
+SaveStr(str)
+register const char *str;
+{
+ register char *cp;
+
+ if ((cp = malloc(strlen(str) + 1)) == NULL)
+ Panic(0, "%s", strnomem);
+ else
+ strcpy(cp, str);
+ return cp;
+}
+
+char *
+SaveStrn(str, n)
+register const char *str;
+int n;
+{
+ register char *cp;
+
+ if ((cp = malloc(n + 1)) == NULL)
+ Panic(0, "%s", strnomem);
+ else
+ {
+ bcopy((char *)str, cp, n);
+ cp[n] = 0;
+ }
+ return cp;
+}
+
+/* cheap strstr replacement */
+char *
+InStr(str, pat)
+char *str;
+const char *pat;
+{
+ int npat = strlen(pat);
+ for (;*str; str++)
+ if (!strncmp(str, pat, npat))
+ return str;
+ return 0;
+}
+
+#ifndef HAVE_STRERROR
+char *
+strerror(err)
+int err;
+{
+ extern int sys_nerr;
+ extern char *sys_errlist[];
+
+ static char er[20];
+ if (err > 0 && err < sys_nerr)
+ return sys_errlist[err];
+ sprintf(er, "Error %d", err);
+ return er;
+}
+#endif
+
+void
+centerline(str, y)
+char *str;
+int y;
+{
+ int l, n;
+
+ ASSERT(flayer);
+ n = strlen(str);
+ if (n > flayer->l_width - 1)
+ n = flayer->l_width - 1;
+ l = (flayer->l_width - 1 - n) / 2;
+ LPutStr(flayer, str, n, &mchar_blank, l, y);
+}
+
+void
+leftline(str, y, rend)
+char *str;
+int y;
+struct mchar *rend;
+{
+ int l, n;
+ struct mchar mchar_dol;
+
+ mchar_dol = mchar_blank;
+ mchar_dol.image = '$';
+
+ ASSERT(flayer);
+ l = n = strlen(str);
+ if (n > flayer->l_width - 1)
+ n = flayer->l_width - 1;
+ LPutStr(flayer, str, n, rend ? rend : &mchar_blank, 0, y);
+ if (n != l)
+ LPutChar(flayer, &mchar_dol, n, y);
+}
+
+
+char *
+Filename(s)
+char *s;
+{
+ register char *p = s;
+
+ if (p)
+ while (*p)
+ if (*p++ == '/')
+ s = p;
+ return s;
+}
+
+char *
+stripdev(nam)
+char *nam;
+{
+#ifdef apollo
+ char *p;
+
+ if (nam == NULL)
+ return NULL;
+# ifdef SVR4
+ /* unixware has /dev/pts012 as synonym for /dev/pts/12 */
+ if (!strncmp(nam, "/dev/pts", 8) && nam[8] >= '0' && nam[8] <= '9')
+ {
+ static char b[13];
+ sprintf(b, "pts/%d", atoi(nam + 8));
+ return b;
+ }
+# endif /* SVR4 */
+ if (p = strstr(nam,"/dev/"))
+ return p + 5;
+#else /* apollo */
+ if (nam == NULL)
+ return NULL;
+ if (strncmp(nam, "/dev/", 5) == 0)
+ return nam + 5;
+#endif /* apollo */
+ return nam;
+}
+
+
+/*
+ * Signal handling
+ */
+
+#ifdef POSIX
+sigret_t (*xsignal(sig, func))
+# ifndef __APPLE__
+ __P(SIGPROTOARG)
+# else
+()
+# endif
+int sig;
+sigret_t (*func) __P(SIGPROTOARG);
+{
+ struct sigaction osa, sa;
+ sa.sa_handler = func;
+ (void)sigemptyset(&sa.sa_mask);
+#ifdef SA_RESTART
+ sa.sa_flags = (sig == SIGCHLD ? SA_RESTART : 0);
+#else
+ sa.sa_flags = 0;
+#endif
+ if (sigaction(sig, &sa, &osa))
+ return (sigret_t (*)__P(SIGPROTOARG))-1;
+ return osa.sa_handler;
+}
+
+#else
+# ifdef hpux
+/*
+ * hpux has berkeley signal semantics if we use sigvector,
+ * but not, if we use signal, so we define our own signal() routine.
+ */
+void (*xsignal(sig, func)) __P(SIGPROTOARG)
+int sig;
+void (*func) __P(SIGPROTOARG);
+{
+ struct sigvec osv, sv;
+
+ sv.sv_handler = func;
+ sv.sv_mask = sigmask(sig);
+ sv.sv_flags = SV_BSDSIG;
+ if (sigvector(sig, &sv, &osv) < 0)
+ return (void (*)__P(SIGPROTOARG))(BADSIG);
+ return osv.sv_handler;
+}
+# endif /* hpux */
+#endif /* POSIX */
+
+
+/*
+ * uid/gid handling
+ */
+
+#ifdef HAVE_SETEUID
+
+void
+xseteuid(euid)
+int euid;
+{
+ if (seteuid(euid) == 0)
+ return;
+ seteuid(0);
+ if (seteuid(euid))
+ Panic(errno, "seteuid");
+}
+
+void
+xsetegid(egid)
+int egid;
+{
+ if (setegid(egid))
+ Panic(errno, "setegid");
+}
+
+#else /* HAVE_SETEUID */
+# ifdef HAVE_SETREUID
+
+void
+xseteuid(euid)
+int euid;
+{
+ int oeuid;
+
+ oeuid = geteuid();
+ if (oeuid == euid)
+ return;
+ if ((int)getuid() != euid)
+ oeuid = getuid();
+ if (setreuid(oeuid, euid))
+ Panic(errno, "setreuid");
+}
+
+void
+xsetegid(egid)
+int egid;
+{
+ int oegid;
+
+ oegid = getegid();
+ if (oegid == egid)
+ return;
+ if ((int)getgid() != egid)
+ oegid = getgid();
+ if (setregid(oegid, egid))
+ Panic(errno, "setregid");
+}
+
+# endif /* HAVE_SETREUID */
+#endif /* HAVE_SETEUID */
+
+
+
+#ifdef NEED_OWN_BCOPY
+void
+xbcopy(s1, s2, len)
+register char *s1, *s2;
+register int len;
+{
+ if (s1 < s2 && s2 < s1 + len)
+ {
+ s1 += len;
+ s2 += len;
+ while (len-- > 0)
+ *--s2 = *--s1;
+ }
+ else
+ while (len-- > 0)
+ *s2++ = *s1++;
+}
+#endif /* NEED_OWN_BCOPY */
+
+void
+bclear(p, n)
+char *p;
+int n;
+{
+ bcopy((char *)blank, p, n);
+}
+
+
+void
+Kill(pid, sig)
+int pid, sig;
+{
+ if (pid < 2)
+ return;
+ (void) kill(pid, sig);
+}
+
+#ifdef HAVE_FDWALK
+/*
+ * Modern versions of Solaris include fdwalk(3c) which allows efficient
+ * implementation of closing open descriptors; this is helpful because
+ * the default file descriptor limit has risen to 65k.
+ */
+static int
+close_func(cb_data, fd)
+void *cb_data;
+int fd;
+{
+ int except = *(int *)cb_data;
+ if (fd > 2 && fd != except)
+ (void)close(fd);
+ return (0);
+}
+
+void
+closeallfiles(except)
+int except;
+{
+ (void)fdwalk(close_func, &except);
+}
+
+#else /* HAVE_FDWALK */
+
+void
+closeallfiles(except)
+int except;
+{
+ int f;
+#ifdef SVR4
+ struct rlimit rl;
+
+ if ((getrlimit(RLIMIT_NOFILE, &rl) == 0) && rl.rlim_max != RLIM_INFINITY)
+ f = rl.rlim_max;
+ else
+#endif /* SVR4 */
+#if defined(SYSV) && defined(NOFILE) && !defined(ISC)
+ f = NOFILE;
+#else /* SYSV && !ISC */
+ f = getdtablesize();
+#endif /* SYSV && !ISC */
+ while (--f > 2)
+ if (f != except)
+ close(f);
+}
+
+#endif /* HAVE_FDWALK */
+
+
+/*
+ * Security - switch to real uid
+ */
+
+#ifndef USE_SETEUID
+static int UserPID;
+static sigret_t (*Usersigcld)__P(SIGPROTOARG);
+#endif
+static int UserSTAT;
+
+int
+UserContext()
+{
+#ifndef USE_SETEUID
+ if (eff_uid == real_uid && eff_gid == real_gid)
+ return 1;
+ Usersigcld = signal(SIGCHLD, SIG_DFL);
+ debug("UserContext: forking.\n");
+ switch (UserPID = fork())
+ {
+ case -1:
+ Msg(errno, "fork");
+ return -1;
+ case 0:
+ signal(SIGHUP, SIG_DFL);
+ signal(SIGINT, SIG_IGN);
+ signal(SIGQUIT, SIG_DFL);
+ signal(SIGTERM, SIG_DFL);
+# ifdef BSDJOBS
+ signal(SIGTTIN, SIG_DFL);
+ signal(SIGTTOU, SIG_DFL);
+# endif
+ setuid(real_uid);
+ setgid(real_gid);
+ return 1;
+ default:
+ return 0;
+ }
+#else
+ xseteuid(real_uid);
+ xsetegid(real_gid);
+ return 1;
+#endif
+}
+
+void
+UserReturn(val)
+int val;
+{
+#ifndef USE_SETEUID
+ if (eff_uid == real_uid && eff_gid == real_gid)
+ UserSTAT = val;
+ else
+ _exit(val);
+#else
+ xseteuid(eff_uid);
+ xsetegid(eff_gid);
+ UserSTAT = val;
+#endif
+}
+
+int
+UserStatus()
+{
+#ifndef USE_SETEUID
+ int i;
+# ifdef BSDWAIT
+ union wait wstat;
+# else
+ int wstat;
+# endif
+
+ if (eff_uid == real_uid && eff_gid == real_gid)
+ return UserSTAT;
+ if (UserPID < 0)
+ return -1;
+ while ((errno = 0, i = wait(&wstat)) != UserPID)
+ if (i < 0 && errno != EINTR)
+ break;
+ (void) signal(SIGCHLD, Usersigcld);
+ if (i == -1)
+ return -1;
+ return WEXITSTATUS(wstat);
+#else
+ return UserSTAT;
+#endif
+}
+
+#ifndef HAVE_RENAME
+int
+rename (old, new)
+char *old;
+char *new;
+{
+ if (link(old, new) < 0)
+ return -1;
+ return unlink(old);
+}
+#endif
+
+
+int
+AddXChar(buf, ch)
+char *buf;
+int ch;
+{
+ char *p = buf;
+
+ if (ch < ' ' || ch == 0x7f)
+ {
+ *p++ = '^';
+ *p++ = ch ^ 0x40;
+ }
+ else if (ch >= 0x80)
+ {
+ *p++ = '\\';
+ *p++ = (ch >> 6 & 7) + '0';
+ *p++ = (ch >> 3 & 7) + '0';
+ *p++ = (ch >> 0 & 7) + '0';
+ }
+ else
+ *p++ = ch;
+ return p - buf;
+}
+
+int
+AddXChars(buf, len, str)
+char *buf, *str;
+int len;
+{
+ char *p;
+
+ if (str == 0)
+ {
+ *buf = 0;
+ return 0;
+ }
+ len -= 4; /* longest sequence produced by AddXChar() */
+ for (p = buf; p < buf + len && *str; str++)
+ {
+ if (*str == ' ')
+ *p++ = *str;
+ else
+ p += AddXChar(p, *str);
+ }
+ *p = 0;
+ return p - buf;
+}
+
+
+#ifdef DEBUG
+void
+opendebug(new, shout)
+int new, shout;
+{
+ char buf[256];
+
+#ifdef _MODE_T
+ mode_t oumask = umask(0);
+#else
+ int oumask = umask(0);
+#endif
+
+ ASSERT(!dfp);
+
+ (void) mkdir(DEBUGDIR, 0777);
+ sprintf(buf, shout ? "%s/SCREEN.%d" : "%s/screen.%d", DEBUGDIR, getpid());
+ if (!(dfp = fopen(buf, new ? "w" : "a")))
+ dfp = stderr;
+ else
+ (void)chmod(buf, 0666);
+
+ (void)umask(oumask);
+ debug("opendebug: done.\n");
+}
+#endif /* DEBUG */
+
+void
+sleep1000(msec)
+int msec;
+
+{
+ struct timeval t;
+
+ t.tv_sec = (long) (msec / 1000);
+ t.tv_usec = (long) ((msec % 1000) * 1000);
+ select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t);
+}
+
+
+/*
+ * This uses either setenv() or putenv(). If it is putenv() we cannot dare
+ * to free the buffer after putenv(), unless it it the one found in putenv.c
+ */
+void
+xsetenv(var, value)
+char *var;
+char *value;
+{
+#ifndef USESETENV
+ char *buf;
+ int l;
+
+ if ((buf = (char *)malloc((l = strlen(var)) +
+ strlen(value) + 2)) == NULL)
+ {
+ Msg(0, strnomem);
+ return;
+ }
+ strcpy(buf, var);
+ buf[l] = '=';
+ strcpy(buf + l + 1, value);
+ putenv(buf);
+# ifdef NEEDPUTENV
+ /*
+ * we use our own putenv(), knowing that it does a malloc()
+ * the string space, we can free our buf now.
+ */
+ free(buf);
+# else /* NEEDPUTENV */
+ /*
+ * For all sysv-ish systems that link a standard putenv()
+ * the string-space buf is added to the environment and must not
+ * be freed, or modified.
+ * We are sorry to say that memory is lost here, when setting
+ * the same variable again and again.
+ */
+# endif /* NEEDPUTENV */
+#else /* USESETENV */
+# if HAVE_SETENV_3
+ setenv(var, value, 1);
+# else
+ setenv(var, value);
+# endif /* HAVE_SETENV_3 */
+#endif /* USESETENV */
+}
+
+#ifdef TERMINFO
+/*
+ * This is a replacement for the buggy _delay function from the termcap
+ * emulation of libcurses, which ignores ospeed.
+ */
+int
+_delay(delay, outc)
+register int delay;
+int (*outc) __P((int));
+{
+ int pad;
+ extern short ospeed;
+ static short osp2pad[] = {
+ 0,2000,1333,909,743,666,500,333,166,83,55,41,20,10,5,2,1,1
+ };
+
+ if (ospeed <= 0 || ospeed >= (int)(sizeof(osp2pad)/sizeof(*osp2pad)))
+ return 0;
+ pad =osp2pad[ospeed];
+ delay = (delay + pad / 2) / pad;
+ while (delay-- > 0)
+ (*outc)(0);
+ return 0;
+}
+
+#endif /* TERMINFO */
+
+
+
+#ifndef USEVARARGS
+
+# define xva_arg(s, t, tn) (*(t *)(s += xsnoff(tn, 0, 0), s - xsnoff(tn, 0, 0)))
+# define xva_list char *
+
+static int
+xsnoff(a, b, c)
+int a;
+char *b;
+int c;
+{
+ return a ? (char *)&c - (char *)&b : (char *)&b - (char *)&a;
+}
+
+int
+xsnprintf(s, n, fmt, p1, p2, p3, p4, p5, p6)
+char *s;
+int n;
+char *fmt;
+unsigned long p1, p2, p3, p4, p5, p6;
+{
+ int xvsnprintf __P((char *, int, char *, xva_list));
+ return xvsnprintf(s, n, fmt, (char *)&fmt + xsnoff(1, 0, 0));
+}
+
+#else
+
+# define xva_arg(s, t, tn) va_arg(s, t)
+# define xva_list va_list
+
+#endif
+
+
+#if !defined(USEVARARGS) || !defined(HAVE_VSNPRINTF)
+
+int
+xvsnprintf(s, n, fmt, stack)
+char *s;
+int n;
+char *fmt;
+xva_list stack;
+{
+ char *f, *sf = 0;
+ int i, on, argl = 0;
+ char myf[10], buf[20];
+ char *arg, *myfp;
+
+ on = n;
+ f = fmt;
+ arg = 0;
+ while(arg || (sf = index(f, '%')) || (sf = f + strlen(f)))
+ {
+ if (arg == 0)
+ {
+ arg = f;
+ argl = sf - f;
+ }
+ if (argl)
+ {
+ i = argl > n - 1 ? n - 1 : argl;
+ strncpy(s, arg, i);
+ s += i;
+ n -= i;
+ if (i < argl)
+ {
+ *s = 0;
+ return on;
+ }
+ }
+ arg = 0;
+ if (sf == 0)
+ continue;
+ f = sf;
+ sf = 0;
+ if (!*f)
+ break;
+ myfp = myf;
+ *myfp++ = *f++;
+ while (((*f >= '0' && *f <='9') || *f == '#') && myfp - myf < 8)
+ *myfp++ = *f++;
+ *myfp++ = *f;
+ *myfp = 0;
+ if (!*f++)
+ break;
+ switch(f[-1])
+ {
+ case '%':
+ arg = "%";
+ break;
+ case 'c':
+ case 'o':
+ case 'd':
+ case 'x':
+ i = xva_arg(stack, int, 0);
+ sprintf(buf, myf, i);
+ arg = buf;
+ break;
+ case 's':
+ arg = xva_arg(stack, char *, 1);
+ if (arg == 0)
+ arg = "NULL";
+ break;
+ default:
+ arg = "";
+ break;
+ }
+ argl = strlen(arg);
+ }
+ *s = 0;
+ return on - n;
+}
+
+#endif
diff --git a/nethack.c b/nethack.c
new file mode 100644
index 0000000..d8ae456
--- /dev/null
+++ b/nethack.c
@@ -0,0 +1,138 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include "config.h"
+#include "screen.h"
+
+#ifdef NETHACK
+extern int nethackflag;
+#endif
+
+struct nlstrans {
+ char *from;
+ char *to;
+};
+
+#ifdef NETHACK
+static struct nlstrans nethacktrans[] = {
+{"Cannot lock terminal - fork failed",
+ "Cannot fork terminal - lock failed"},
+{"Got only %d bytes from %s",
+ "You choke on your food: %d bytes from %s"},
+{"Copy mode - Column %d Line %d(+%d) (%d,%d)",
+ "Welcome to hacker's treasure zoo - Column %d Line %d(+%d) (%d,%d)"},
+{"First mark set - Column %d Line %d",
+ "You drop a magic marker - Column %d Line %d"},
+{"Copy mode aborted",
+ "You escaped the dungeon."},
+{"Filter removed.",
+ "You have a sad feeling for a moment..."},
+{"Window %d (%s) killed.",
+ "You destroy poor window %d (%s)."},
+{"Window %d (%s) is now being monitored for all activity.",
+ "You feel like someone is watching you..."},
+{"Window %d (%s) is no longer being monitored for activity.",
+ "You no longer sense the watcher's presence."},
+{"empty buffer",
+ "Nothing happens."},
+{"switched to audible bell.",
+ "Suddenly you can't see your bell!"},
+{"switched to visual bell.",
+ "Your bell is no longer invisible."},
+{"The window is now being monitored for %d sec. silence.",
+ "You feel like someone is waiting for %d sec. silence..."},
+{"The window is no longer being monitored for silence.",
+ "You no longer sense the watcher's silence."},
+{"No other window.",
+ "You cannot escape from window %d!"},
+{"Logfile \"%s\" closed.",
+ "You put away your scroll of logging named \"%s\"." },
+{"Error opening logfile \"%s\"",
+ "You don't seem to have a scroll of logging named \"%s\"."},
+{"Creating logfile \"%s\".",
+ "You start writing on your scroll of logging named \"%s\"."},
+{"Appending to logfile \"%s\".",
+ "You add to your scroll of logging named \"%s\"."},
+{"Detach aborted.",
+ "The blast of disintegration whizzes by you!"},
+{"Empty register.",
+ "Nothing happens."},
+{"[ Passwords don't match - checking turned off ]",
+ "[ Passwords don't match - your armor crumbles away ]"},
+{"Aborted because of window size change.",
+ "KAABLAMM!!! You triggered a land mine!"},
+{"Out of memory.",
+ "Who was that Maude person anyway?"},
+{"getpwuid() can't identify your account!",
+ "An alarm sounds through the dungeon...\nThe Keystone Kops are after you!"},
+{"Must be connected to a terminal.",
+ "You must play from a terminal."},
+{"No Sockets found in %s.\n",
+ "This room is empty (%s).\n"},
+{"New screen...",
+ "Be careful! New screen tonight."},
+{"Child has been stopped, restarting.",
+ "You regain consciousness."},
+{"There are screens on:",
+ "Your inventory:"},
+{"There is a screen on:",
+ "Your inventory:"},
+{"There are several screens on:",
+ "Prove thyself worthy or perish:"},
+{"There is a suitable screen on:",
+ "You see here a good looking screen:"},
+{"There are several suitable screens on:",
+ "You may wish for a screen, what do you want?"},
+{"%d socket%s wiped out.",
+ "You hear %d distant explosion%s."},
+{"Remove dead screens with 'screen -wipe'.",
+ "The dead screen%s touch%s you. Try 'screen -wipe'."},
+{"Illegal reattach attempt from terminal %s.",
+ "'%s' tries to touch your session, but fails."},
+{"Could not write %s",
+ "%s is too hard to dig in"},
+{0, 0}
+};
+#endif
+
+const char *
+DoNLS(from)
+const char *from;
+{
+#ifdef NETHACK
+ struct nlstrans *t;
+
+ if (nethackflag)
+ {
+ for (t = nethacktrans; t->from; t++)
+ if (strcmp(from, t->from) == 0)
+ return t->to;
+ }
+#endif
+ return from;
+}
diff --git a/os.h b/os.h
new file mode 100644
index 0000000..55de249
--- /dev/null
+++ b/os.h
@@ -0,0 +1,529 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+#include <stdio.h>
+#include <errno.h>
+
+#include <sys/param.h>
+
+/* In strict ANSI mode, HP-UX machines define __hpux but not hpux */
+#if defined(__hpux) && !defined(hpux)
+# define hpux
+#endif
+
+#if defined(__bsdi__) || defined(__386BSD__) || defined(_CX_UX) || defined(hpux) || defined(_IBMR2) || defined(linux)
+# include <signal.h>
+#endif /* __bsdi__ || __386BSD__ || _CX_UX || hpux || _IBMR2 || linux */
+
+#if !defined(HAVE_LONG_FILE_NAMES) && !defined(NAME_MAX)
+#define NAME_MAX 14
+#endif
+
+#ifdef ISC
+# ifdef ENAMETOOLONG
+# undef ENAMETOOLONG
+# endif
+# ifdef ENOTEMPTY
+# undef ENOTEMPTY
+# endif
+# include <sys/bsdtypes.h>
+# include <net/errno.h>
+#endif
+
+#ifdef sun
+# define getpgrp __getpgrp
+# define exit __exit
+#endif
+#ifdef POSIX
+# include <unistd.h>
+# if defined(__STDC__)
+# include <stdlib.h>
+# endif /* __STDC__ */
+#endif /* POSIX */
+#ifdef sun
+# undef getpgrp
+# undef exit
+#endif /* sun */
+
+#ifndef linux /* all done in <errno.h> */
+extern int errno;
+#endif /* linux */
+#ifndef HAVE_STRERROR
+/* No macros, please */
+#undef strerror
+#endif
+
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+
+#ifdef USEVARARGS
+# if defined(__STDC__)
+# include <stdarg.h>
+# define VA_LIST(var) va_list var;
+# define VA_DOTS ...
+# define VA_DECL
+# define VA_START(ap, fmt) va_start(ap, fmt)
+# define VA_ARGS(ap) ap
+# define VA_END(ap) va_end(ap)
+# else
+# include <varargs.h>
+# define VA_LIST(var) va_list var;
+# define VA_DOTS va_alist
+# define VA_DECL va_dcl
+# define VA_START(ap, fmt) va_start(ap)
+# define VA_ARGS(ap) ap
+# define VA_END(ap) va_end(ap)
+# endif
+#else
+# define VA_LIST(var)
+# define VA_DOTS p1, p2, p3, p4, p5, p6
+# define VA_DECL unsigned long VA_DOTS;
+# define VA_START(ap, fmt)
+# define VA_ARGS(ap) VA_DOTS
+# define VA_END(ap)
+# undef vsnprintf
+# define vsnprintf xsnprintf
+#endif
+
+#if !defined(sun) && !defined(B43) && !defined(ISC) && !defined(pyr) && !defined(_CX_UX)
+# include <time.h>
+#endif
+#include <sys/time.h>
+
+#ifdef M_UNIX /* SCO */
+# include <sys/stream.h>
+# include <sys/ptem.h>
+# define ftruncate(fd, s) chsize(fd, s)
+#endif
+
+#ifdef SYSV
+# define index strchr
+# define rindex strrchr
+# define bzero(poi,len) memset(poi,0,len)
+# define bcmp memcmp
+# define killpg(pgrp,sig) kill( -(pgrp), sig)
+#endif
+
+#ifndef HAVE_GETCWD
+# define getcwd(b,l) getwd(b)
+#endif
+
+#ifndef USEBCOPY
+# ifdef USEMEMMOVE
+# define bcopy(s,d,len) memmove(d,s,len)
+# else
+# ifdef USEMEMCPY
+# define bcopy(s,d,len) memcpy(d,s,len)
+# else
+# define NEED_OWN_BCOPY
+# define bcopy xbcopy
+# endif
+# endif
+#endif
+
+#if defined(HAVE_SETRESUID) && !defined(HAVE_SETREUID)
+# define setreuid(ruid, euid) setresuid(ruid, euid, -1)
+# define setregid(rgid, egid) setresgid(rgid, egid, -1)
+#endif
+
+#if defined(HAVE_SETEUID) || defined(HAVE_SETREUID) || defined(HAVE_SETRESUID)
+# define USE_SETEUID
+#endif
+
+#if !defined(HAVE__EXIT) && !defined(_exit)
+#define _exit(x) exit(x)
+#endif
+
+#ifndef HAVE_UTIMES
+# define utimes utime
+#endif
+#ifndef HAVE_VSNPRINTF
+# define vsnprintf xvsnprintf
+#endif
+
+#ifdef BUILTIN_TELNET
+# include <netinet/in.h>
+# include <arpa/inet.h>
+#endif
+
+#if defined(USE_LOCALE) && (!defined(HAVE_SETLOCALE) || !defined(HAVE_STRFTIME))
+# undef USE_LOCALE
+#endif
+
+/*****************************************************************
+ * terminal handling
+ */
+
+#ifdef POSIX
+# include <termios.h>
+# ifdef hpux
+# include <bsdtty.h>
+# endif /* hpux */
+# ifdef NCCS
+# define MAXCC NCCS
+# else
+# define MAXCC 256
+# endif
+#else /* POSIX */
+# ifdef TERMIO
+# include <termio.h>
+# ifdef NCC
+# define MAXCC NCC
+# else
+# define MAXCC 256
+# endif
+# ifdef CYTERMIO
+# include <cytermio.h>
+# endif
+# else /* TERMIO */
+# include <sgtty.h>
+# endif /* TERMIO */
+#endif /* POSIX */
+
+#ifndef VDISABLE
+# ifdef _POSIX_VDISABLE
+# define VDISABLE _POSIX_VDISABLE
+# else
+# define VDISABLE 0377
+# endif /* _POSIX_VDISABLE */
+#endif /* !VDISABLE */
+
+
+/* on sgi, regardless of the stream head's read mode (RNORM/RMSGN/RMSGD)
+ * TIOCPKT mode causes data loss if our buffer is too small (IOSIZE)
+ * to hold the whole packet at first read().
+ * (Marc Boucher)
+ *
+ * matthew green:
+ * TIOCPKT is broken on dgux 5.4.1 generic AViiON mc88100
+ *
+ * Joe Traister: On AIX4, programs like irc won't work if screen
+ * uses TIOCPKT (select fails to return on pty read).
+ */
+#if defined(sgi) || defined(DGUX) || defined(_IBMR2)
+# undef TIOCPKT
+#endif
+
+/* Alexandre Oliva: SVR4 style ptys don't work with osf */
+#ifdef __osf__
+# undef HAVE_SVR4_PTYS
+#endif
+
+/*****************************************************************
+ * utmp handling
+ */
+
+#ifdef GETUTENT
+ typedef char *slot_t;
+#else
+ typedef int slot_t;
+#endif
+
+#if defined(UTMPOK) || defined(BUGGYGETLOGIN)
+# if defined(SVR4) && !defined(DGUX) && !defined(__hpux) && !defined(linux)
+# include <utmpx.h>
+# define UTMPFILE UTMPX_FILE
+# define utmp utmpx
+# define getutent getutxent
+# define getutid getutxid
+# define getutline getutxline
+# define pututline pututxline
+# define setutent setutxent
+# define endutent endutxent
+# define ut_time ut_xtime
+# else /* SVR4 */
+# include <utmp.h>
+# endif /* SVR4 */
+# ifdef apollo
+ /*
+ * We don't have GETUTENT, so we dig into utmp ourselves.
+ * But we save the permanent filedescriptor and
+ * open utmp just when we need to.
+ * This code supports an unsorted utmp. jw.
+ */
+# define UTNOKEEP
+# endif /* apollo */
+
+# ifndef UTMPFILE
+# ifdef UTMP_FILE
+# define UTMPFILE UTMP_FILE
+# else
+# ifdef _PATH_UTMP
+# define UTMPFILE _PATH_UTMP
+# else
+# define UTMPFILE "/etc/utmp"
+# endif /* _PATH_UTMP */
+# endif
+# endif
+
+#endif /* UTMPOK || BUGGYGETLOGIN */
+
+#if !defined(UTMPOK) && defined(USRLIMIT)
+# undef USRLIMIT
+#endif
+
+#ifdef LOGOUTOK
+# ifndef LOGINDEFAULT
+# define LOGINDEFAULT 0
+# endif
+#else
+# ifdef LOGINDEFAULT
+# undef LOGINDEFAULT
+# endif
+# define LOGINDEFAULT 1
+#endif
+
+
+/*****************************************************************
+ * file stuff
+ */
+
+#ifndef F_OK
+#define F_OK 0
+#endif
+#ifndef X_OK
+#define X_OK 1
+#endif
+#ifndef W_OK
+#define W_OK 2
+#endif
+#ifndef R_OK
+#define R_OK 4
+#endif
+
+#ifndef S_IFIFO
+#define S_IFIFO 0010000
+#endif
+#ifndef S_IREAD
+#define S_IREAD 0000400
+#endif
+#ifndef S_IWRITE
+#define S_IWRITE 0000200
+#endif
+#ifndef S_IEXEC
+#define S_IEXEC 0000100
+#endif
+
+#if defined(S_IFIFO) && defined(S_IFMT) && !defined(S_ISFIFO)
+#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
+#endif
+#if defined(S_IFSOCK) && defined(S_IFMT) && !defined(S_ISSOCK)
+#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
+#endif
+#if defined(S_IFCHR) && defined(S_IFMT) && !defined(S_ISCHR)
+#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
+#endif
+#if defined(S_IFDIR) && defined(S_IFMT) && !defined(S_ISDIR)
+#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+#endif
+#if defined(S_IFLNK) && defined(S_IFMT) && !defined(S_ISLNK)
+#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
+#endif
+
+/*
+ * SunOS 4.1.3: `man 2V open' has only one line that mentions O_NOBLOCK:
+ *
+ * O_NONBLOCK Same as O_NDELAY above.
+ *
+ * on the very same SunOS 4.1.3, I traced the open system call and found
+ * that an open("/dev/ttyy08", O_RDWR|O_NONBLOCK|O_NOCTTY) was blocked,
+ * whereas open("/dev/ttyy08", O_RDWR|O_NDELAY |O_NOCTTY) went through.
+ *
+ * For this simple reason I now favour O_NDELAY. jw. 4.5.95
+ */
+#if defined(sun) && !defined(SVR4)
+# undef O_NONBLOCK
+#endif
+
+#if !defined(O_NONBLOCK) && defined(O_NDELAY)
+# define O_NONBLOCK O_NDELAY
+#endif
+
+#if !defined(FNBLOCK) && defined(FNONBLOCK)
+# define FNBLOCK FNONBLOCK
+#endif
+#if !defined(FNBLOCK) && defined(FNDELAY)
+# define FNBLOCK FNDELAY
+#endif
+#if !defined(FNBLOCK) && defined(O_NONBLOCK)
+# define FNBLOCK O_NONBLOCK
+#endif
+
+#ifndef POSIX
+#undef mkfifo
+#define mkfifo(n,m) mknod(n,S_IFIFO|(m),0)
+#endif
+
+#if !defined(HAVE_LSTAT) && !defined(lstat)
+# define lstat stat
+#endif
+
+/*****************************************************************
+ * signal handling
+ */
+
+#ifdef SIGVOID
+# define SIGRETURN
+# define sigret_t void
+#else
+# define SIGRETURN return 0;
+# define sigret_t int
+#endif
+
+/* Geeeee, reverse it? */
+#if defined(SVR4) || (defined(SYSV) && defined(ISC)) || defined(_AIX) || defined(linux) || defined(ultrix) || defined(__386BSD__) || defined(__bsdi__) || defined(POSIX) || defined(NeXT)
+# define SIGHASARG
+#endif
+
+#ifdef SIGHASARG
+# define SIGPROTOARG (int)
+# define SIGDEFARG (sigsig) int sigsig;
+# define SIGARG 0
+#else
+# define SIGPROTOARG (void)
+# define SIGDEFARG ()
+# define SIGARG
+#endif
+
+#ifndef SIGCHLD
+#define SIGCHLD SIGCLD
+#endif
+
+#if defined(POSIX) || defined(hpux)
+# define signal xsignal
+#else
+# ifdef USESIGSET
+# define signal sigset
+# endif /* USESIGSET */
+#endif
+
+/* used in screen.c and attacher.c */
+#ifndef NSIG /* kbeal needs these w/o SYSV */
+# define NSIG 32
+#endif /* !NSIG */
+
+
+/*****************************************************************
+ * Wait stuff
+ */
+
+#if (!defined(sysV68) && !defined(M_XENIX)) || defined(NeXT) || defined(M_UNIX)
+# include <sys/wait.h>
+#endif
+
+#ifndef WTERMSIG
+# ifndef BSDWAIT /* if wait is NOT a union: */
+# define WTERMSIG(status) (status & 0177)
+# else
+# define WTERMSIG(status) status.w_T.w_Termsig
+# endif
+#endif
+
+#ifndef WSTOPSIG
+# ifndef BSDWAIT /* if wait is NOT a union: */
+# define WSTOPSIG(status) ((status >> 8) & 0377)
+# else
+# define WSTOPSIG(status) status.w_S.w_Stopsig
+# endif
+#endif
+
+/* NET-2 uses WCOREDUMP */
+#if defined(WCOREDUMP) && !defined(WIFCORESIG)
+# define WIFCORESIG(status) WCOREDUMP(status)
+#endif
+
+#ifndef WIFCORESIG
+# ifndef BSDWAIT /* if wait is NOT a union: */
+# define WIFCORESIG(status) (status & 0200)
+# else
+# define WIFCORESIG(status) status.w_T.w_Coredump
+# endif
+#endif
+
+#ifndef WEXITSTATUS
+# ifndef BSDWAIT /* if wait is NOT a union: */
+# define WEXITSTATUS(status) ((status >> 8) & 0377)
+# else
+# define WEXITSTATUS(status) status.w_T.w_Retcode
+# endif
+#endif
+
+
+/*****************************************************************
+ * select stuff
+ */
+
+#if defined(M_XENIX) || defined(M_UNIX) || defined(_SEQUENT_)
+#include <sys/select.h> /* for timeval + FD... */
+#endif
+
+/*
+ * SunOS 3.5 - Tom Schmidt - Micron Semiconductor, Inc - 27-Jul-93
+ * tschmidt@vax.micron.com
+ */
+#ifndef FD_SET
+# ifndef SUNOS3
+typedef struct fd_set { int fds_bits[1]; } fd_set;
+# endif
+# define FD_ZERO(fd) ((fd)->fds_bits[0] = 0)
+# define FD_SET(b, fd) ((fd)->fds_bits[0] |= 1 << (b))
+# define FD_ISSET(b, fd) ((fd)->fds_bits[0] & 1 << (b))
+# define FD_SETSIZE 32
+#endif
+
+
+/*****************************************************************
+ * user defineable stuff
+ */
+
+#ifndef TERMCAP_BUFSIZE
+# define TERMCAP_BUFSIZE 2048
+#endif
+
+#ifndef MAXPATHLEN
+# define MAXPATHLEN 1024
+#endif
+
+/*
+ * you may try to vary this value. Use low values if your (VMS) system
+ * tends to choke when pasting. Use high values if you want to test
+ * how many characters your pty's can buffer.
+ */
+#define IOSIZE 4096
+
+/* Changing those you won't be able to attach to your old sessions
+ * when changing those values in official tree don't forget to bump
+ * MSG_VERSION */
+#define MAXTERMLEN 32
+#define MAXLOGINLEN 256
+
diff --git a/osdef.h.in b/osdef.h.in
new file mode 100644
index 0000000..0dd821e
--- /dev/null
+++ b/osdef.h.in
@@ -0,0 +1,202 @@
+/* Copyright (c) 1993-2000
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+/****************************************************************
+ * Thanks to Christos S. Zoulas (christos@ee.cornell.edu) who
+ * mangled the screen source through 'gcc -Wall'.
+ ****************************************************************
+ */
+
+extern int printf __P((char *, ...));
+extern int fprintf __P((FILE *, char *, ...));
+extern int sprintf __P((char *, char *, ...));
+#ifdef USEVARARGS
+extern int vsprintf __P((char *, char *, char *));
+#endif
+
+#ifdef LOG_NOTICE
+extern int openlog __P((char *, int, int));
+extern int syslog __P((int, char *, ... ));
+extern int closelog __P((void));
+#endif
+
+#if defined(sun) || defined(_SEQUENT_)
+extern int _flsbuf __P((int, FILE *));
+#endif
+
+#ifdef SYSV
+extern char *strchr __P((char *, int));
+extern char *strrchr __P((char *, int));
+extern char *memset __P((char *, int, int));
+extern int memcmp __P((char *, char *, int));
+#else
+extern char *index __P((char *, int));
+extern char *rindex __P((char *, int));
+extern void bzero __P((char *, int));
+extern int bcmp __P((char *, char *, int));
+extern int killpg __P((int, int));
+#endif
+
+#ifndef USEBCOPY
+# ifdef USEMEMCPY
+extern void memcpy __P((char *, char *, int));
+# else
+# ifdef USEMEMMOVE
+extern void memmove __P((char *, char *, int));
+# else
+extern void bcopy __P((char *, char *, int));
+# endif
+# endif
+#else
+extern void bcopy __P((char *, char *, int));
+#endif
+
+#ifdef BSDWAIT
+struct rusage; /* for wait3 __P */
+union wait; /* for wait3 __P */
+extern int wait3 __P((union wait *, int, struct rusage *));
+#else
+extern int waitpid __P((int, int *, int));
+#endif
+
+extern int getdtablesize __P((void));
+
+#ifdef HAVE_SETRESUID
+extern int setresuid __P((int, int, int));
+extern int setresgid __P((int, int, int));
+#endif
+#ifdef HAVE_SETREUID
+extern int setreuid __P((int, int));
+extern int setregid __P((int, int));
+#endif
+#ifdef HAVE_SETEUID
+extern int seteuid __P((int));
+extern int setegid __P((int));
+#endif
+
+extern char *crypt __P((char *, char *));
+extern int putenv __P((char *));
+
+extern int tgetent __P((char *, char *));
+extern char *tgetstr __P((char *, char **));
+extern int tgetnum __P((char *));
+extern int tgetflag __P((char *));
+extern void tputs __P((char *, int, int (*)(int)));
+extern char *tgoto __P((char *, int, int));
+
+#ifdef POSIX
+#include <string.h>
+extern int setsid __P((void));
+extern int setpgid __P((int, int));
+extern int tcsetpgrp __P((int, int));
+#endif
+extern int ioctl __P((int, int, char *));
+
+extern int kill __P((int, int));
+
+extern int getpid __P((void));
+extern int getuid __P((void));
+extern int geteuid __P((void));
+extern int getgid __P((void));
+extern int getegid __P((void));
+struct passwd; /* for getpwuid __P */
+extern struct passwd *getpwuid __P((int));
+extern struct passwd *getpwnam __P((char *));
+extern int isatty __P((int));
+extern int chown __P((char *, int, int));
+extern int rename __P((char *, char *));
+
+extern int gethostname __P((char *, int));
+extern int lseek __P((int, int, int));
+extern void exit __P((int));
+extern char *getwd __P((char *));
+extern char *getenv __P((char *));
+extern time_t time __P((time_t *));
+
+extern char *getpass __P((char *));
+extern char *getlogin __P((void));
+extern char *ttyname __P((int));
+
+extern int fputs __P((char *, FILE *));
+extern int fwrite __P((char *, int, int, FILE *));
+extern int fflush __P((FILE *));
+extern int fclose __P((FILE *));
+
+extern char *malloc __P((int));
+extern char *realloc __P((char *, int));
+extern void free __P((char *));
+
+extern int mknod __P((char *, int, int));
+struct sockaddr; /* for connect __P */
+extern int socket __P((int, int, int));
+extern int connect __P((int, struct sockaddr *, int));
+extern int bind __P((int, struct sockaddr *, int));
+extern int listen __P((int, int));
+#ifdef _AIX
+extern int accept __P((int, struct sockaddr *, socklen_t *));
+#else
+extern int accept __P((int, struct sockaddr *, int *));
+#endif
+
+#if defined(UTMPOK) && defined(GETUTENT)
+extern void setutent __P((void));
+#endif
+
+#if defined(sequent) || defined(_SEQUENT_)
+extern int getpseudotty __P((char **, char **));
+#ifdef _SEQUENT_
+extern int fvhangup __P((char *));
+#endif
+#endif
+
+struct timeval; /* for select __P */
+extern int select __P((int, fd_set *, fd_set *, fd_set *, struct timeval *));
+#ifdef HAVE_UTIMES
+extern int utimes __P((char *, struct timeval *));
+#endif
+
+extern void unsetenv __P((char *));
+
+# if defined(GETTTYENT) && !defined(GETUTENT) && !defined(UTNOKEEP)
+struct ttyent; /* for getttyent __P */
+extern void setttyent __P((void));
+extern struct ttyent *getttyent __P((void));
+# endif
+
+#ifdef SVR4
+struct rlimit; /* for getrlimit __P */
+extern int getrlimit __P((int, struct rlimit *));
+#endif
+
+struct stat;
+extern int stat __P((char *, struct stat *));
+extern int lstat __P((char *, struct stat *));
+extern int fstat __P((int, struct stat *));
+extern int fchmod __P((int, int));
+extern int fchown __P((int, int, int));
+
+#if defined(LOADAV) && defined(LOADAV_GETLOADAVG)
+extern int getloadavg(double *, int);
+#endif
+
diff --git a/osdef.sh b/osdef.sh
new file mode 100644
index 0000000..1922229
--- /dev/null
+++ b/osdef.sh
@@ -0,0 +1,69 @@
+#! /bin/sh
+
+if test -z "$CPP"; then
+ CPP="cc -E"
+fi
+if test -z "$srcdir"; then
+ srcdir=.
+fi
+
+rm -f core*
+
+sed < $srcdir/osdef.h.in -n -e '/^extern/s@.*[)* ][)* ]*\([^ *]*\) __P.*@/[)*, ]\1[ (]/i\\\
+\\/\\[^a-zA-Z_\\]\1 __P\\/d@p' > osdef1.sed
+cat << EOF > osdef0.c
+#include "config.h"
+#include <sys/types.h>
+#include <stdio.h>
+#include <signal.h>
+#include <sys/stat.h>
+#include <pwd.h>
+#ifdef SHADOWPW
+#include <shadow.h>
+#endif
+#ifndef sun
+#include <sys/ioctl.h>
+#endif
+#ifdef linux
+#include <string.h>
+#include <stdlib.h>
+#endif
+#include <sys/socket.h>
+#ifndef NOSYSLOG
+#include <syslog.h>
+#endif
+#include "os.h"
+#if defined(UTMPOK) && defined (GETTTYENT) && !defined(GETUTENT)
+#include <ttyent.h>
+#endif
+#ifdef SVR4
+# include <sys/resource.h>
+#endif
+EOF
+cat << EOF > osdef2.sed
+1i\\
+/*
+1i\\
+ * This file is automagically created from osdef.sh -- DO NOT EDIT
+1i\\
+ */
+EOF
+$CPP -I. -I$srcdir osdef0.c | sed -n -f osdef1.sed >> osdef2.sed
+sed -f osdef2.sed < $srcdir/osdef.h.in > osdef.h
+rm osdef0.c osdef1.sed osdef2.sed
+
+if test -f core*; then
+ file core*
+ echo " Sorry, your sed is broken. Call the system administrator."
+ echo " Meanwhile, you may try to compile screen with an empty osdef.h file."
+ echo " But if your compiler needs to have all functions declared, you should"
+ echo " retry 'make' now and only remove offending lines from osdef.h later."
+ exit 1
+fi
+if eval test "`diff osdef.h $srcdir/osdef.h.in | wc -l`" -eq 4; then
+ echo " Hmm, sed is very pessimistic about your system header files."
+ echo " But it did not dump core -- strange! Let's continue carefully..."
+ echo " If this fails, you may want to remove offending lines from osdef.h"
+ echo " or try with an empty osdef.h file, if your compiler can do without"
+ echo " function declarations."
+fi
diff --git a/patchlevel.h b/patchlevel.h
new file mode 100644
index 0000000..60c8131
--- /dev/null
+++ b/patchlevel.h
@@ -0,0 +1,538 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+/****************************************************************
+ *
+ * patchlevel.h: Our life story.
+ *
+ * 08.07.91 -- 3.00.01 -wipe and a 'setenv TERM dumb' bugfix.
+ * 17.07.91 -- 3.00.02 another patchlevel by Wayne Davison
+ * 31.07.91 -- 3.00.03 E0, S0, C0 for flexible semi-graphics, nonblocking
+ * window title input and 'C-a :' command input.
+ * 10.08.91 -- 3.00.04 scrollback, markkeys and some bugfixes.
+ * 13.08.91 -- 3.00.05 mark routine improved, ansi prototypes added.
+ * 20.08.91 -- 3.00.06 screen -h, faster GotoPos in overlay, termcap %.
+ * instead of %c
+ * 28.08.91 -- 3.00.07 environment variable support. security. terminfo.
+ * pyramid and ultrix support.
+ * 07.09.91 -- 3.00.99 secopen(), MIPS support, SVR4 support.
+ * 09.09.91 -- 3.01.00 backspace bug fixed.
+ * 03.10.91 -- 3.01.01 ansi.c: null-ptr fixed, CLS now saves to scrollback.
+ * Using setresuid on hpux. Memory leak fixed.
+ * Better GotoPos(). Support for IC. Another resize bug.
+ * Detach() w/o fore crashed. -T and -A(dapt) option.
+ * GNU copyleft.
+ * 19.12.91 -- 3.01.02 flow now really automatic (autoflow killed).
+ * 7 bit restriction removed from WriteString().
+ * 09.01.92 -- 3.01.03 flow reattach bug fixed. VDISCARD bug fixed.
+ * 13.01.92 -- 3.01.04 new flow concept: ^Af toggles now three states
+ * 21.01.92 -- 3.01.05 '^A:screen 11' bug fixed. aflag in DoScreen().
+ * Some code cleanup. attach_tty and display_tty[]
+ * added.
+ * 26.01.92 -- 3.01.06 apollo support, "hardcopy_append on", "bufferfile",
+ * SECURITY PROBLEM cleared..
+ * 28.01.92 -- 3.01.07 screen after su allowed. Pid became part of
+ * SockName. sysvish 14 character restriction considered.
+ * 31.01.92 -- 3.02.00 Ultrix port, Irix 3.3 SGI port, shadow pw support,
+ * data loss on stdin overflow fixed. "refresh off".
+ * 12.02.92 -- 3.02.02 stripdev() moved, -S introduced, bufferfile improved,
+ * ShellProg coredump cleared. SVR4 bugfixes.
+ * I/O code speedup added.
+ * 24.04.92 -- 3.02.03 perfectly stackable overlays. One scrollback per window,
+ * not per display.
+ * 05.05.92 -- 3.02.04 very nasty initialisation bug fixed.
+ * 09.05.92 -- 3.02.05 parsing for $:cl: termcap strings and \012 octal notation
+ * in screenrc file. More structuring. Detached startup
+ * with 'screen -d -m -S...' bugfixed.
+ * 11.05.92 -- 3.02.06 setreuid() bugs cleared, C-a : setenv added.
+ * "xn" capability in TERMCAP needed since "am" is there.
+ * 25.06.92 -- 3.02.07 The multi display test version. Have merci.
+ * 15.07.92 -- 3.02.08 :B8: supports automatic charset switching for 8-bit
+ * 26.09.92 -- 3.02.09 Ported to linux. Ignoring bad files in $SCREENDIR
+ * 22.10.92 -- 3.02.10 screen.c/ansi.c splitted in several pieces.
+ * Better ISearch. Cleanup of loadav.c
+ * 29.10.92 -- 3.02.11 Key mechanism rewritten. New command names.
+ * New iscreenrc syntax.
+ * 02.11.92 -- 3.02.12 'bind g copy_reg' and 'bind x ins_reg' as suggested by
+ * stillson@tsfsrv.mitre.org (Ken Stillson).
+ * 03.11.92 -- 3.02.13 Ported to SunOs 4.1.2. Gulp. Some NULL ptrs fixed and
+ * misc. braindamage fixed.
+ * 03.11.92 -- 3.02.14 Argument number checking, AKA fixed.
+ * 05.11.92 -- 3.02.15 Memory leaks in Detach() and KillWindow() fixed.
+ * Lockprg powerdetaches on SIGHUP.
+ * 12.11.92 -- 3.02.16 Introduced two new termcaps: "CS" and "CE".
+ * (Switch cursorkeys in application mode)
+ * Tim's async output patch.
+ * Fixed an ugly bug in WriteString().
+ * New command: 'process'
+ * 16.11.92 -- 3.02.17 Nuking unsent tty output is now optional, (toxic
+ * ESC radiation).
+ * 30.11.92 -- 3.02.18 Lots of multi display bugs fixed. New layer
+ * function 'Restore'. MULTIUSER code cleanup.
+ * Rudimental acls added for multiuser.
+ * No more error output, when output gives write errors.
+ * 02.12.92 -- 3.02.19 BROKEN_PIPE and SOCK_NOT_IN_FS defines added for
+ * braindead systems. Bug in recover socket code fixed.
+ * Can create windows again from shell.
+ * 22.12.92 -- 3.02.20 Made a superb configure script. STY and break fixed.
+ * 01.02.93 -- 3.02.21 Coredump bug fixed: 8-bit output in background windows.
+ * Console grabbing somewhat more useable.
+ * 23.02.93 -- 3.02.22 Added ^:exec command, but not tested at all.
+ * 23.02.93 -- 3.02.23 Added 'hardcopydir' and 'logdir' commands.
+ * 11.03.93 -- 3.02.24 Prefixed display and window structure elements.
+ * Screen now handles autowrapped lines correctly
+ * in the redisplay and mark function.
+ * 19.03.93 -- 3.03.00 Patched for BSD386. pseudos work.
+ * 31.03.93 -- 3.03.01 Don't allocate so much empty attr and font lines.
+ * 04.04.93 -- 3.03.02 fixed :exec !..| less and :|less, patched BELL_DONE &
+ * ^B/^F. Fixed auto_nuke attribute resetting. Better linux
+ * configure. ^AW shows '&' when window has other attacher.
+ * MAXWIN > 10 patch. KEEP_UNDEF in config.h.in, shellaka
+ * bug fixed. dec alpha port. Solaris port.
+ * 02.05.93 -- 3.03.03 Configure tweaked for sgi. Update environment with
+ * setenv command. Silence on|off, silencewait <sec>,
+ * defautonuke commands added. Manual page updated.
+ * 13.05.93 -- 3.03.04 exit in newsyntax script, finished _CX_UX port.
+ * Texinfo page added by Jason Merrill. Much longish debug
+ * output removed. Select window by title (or number).
+ * 16.06.93 -- 3.04.00 Replaced ^A- by ^A^H to be complementary to ^A SPACE.
+ * Moved into CVS. Yacc.
+ * 28.06.93 -- 3.04.01 Fixed selecting windows with numeric title. Silence
+ * now works without nethackoption set.
+ * 01.07.93 -- 3.04.02 Implementing real acls.
+ * 22.07.93 -- 3.05.00 Fixed SVR4, some multiuser bugs, -- DISTRIBUTED
+ * 05.08.93 -- 3.05.01 ${srcdir} feature added. Shellprog bug fixed.
+ * Motorola reattach bug fixed. Writelock bug fixed.
+ * Copybuffer moved into struct acluser. Configure.in
+ * uglified for Autoconf1.5. Paste may now have an
+ * argument. Interactive setenv. Right margin bug
+ * fixed. IRIX 5 patches. -- DISTRIBUTED
+ * 13.08.93 -- 3.05.02 ultrix support added. expand_vars removed from
+ * register function. Paste bug fixed.
+ * sysmacros.h now included in pty.c on sgis
+ * Strange hpux hack added for TTYCMP.
+ * Zombie feature improved.
+ * 08.09.93 -- 3.05.03 Makefile and OSF1 fine tuning. Eased attach to
+ * multi sessions. Writelock now obeys acl write
+ * permissions. UserDel() now preserves defaults.
+ * acladd/aclchg syntax improved. Updated
+ * documentation. Bug in at command fixed.
+ * MakeWindow() now obeys perm defaults.
+ * 03.10.93 -- 3.05.90 Multiple displays can now share the same window.
+ * Layers now belong to Windows. "Select -" yields a blank
+ * page. Debug output can be switched on/off at runtime.
+ * Number command changes window number and utmp-slot.
+ * 14.10.93 -- 3.05.91 Mechanism to find the "best" window added. Much
+ * debugging done and still needed. Slowpaste setting now
+ * per window. Preserving fore AND other window when
+ * detached. Per user settings for `monitor' and `silence'.
+ * New command `su'. BlankWindow performs now ColonInput.
+ * History command fixed, it depended on paste code that
+ * was previously changed to allow concatenation of buffers.
+ * Fixing umask problem with WriteFile() reported by Jamie
+ * Mason.
+ * 30.11.93 -- 3.05.04 Kanji support added. New keymap feature:
+ * bindkey and various map commands. GR and C1
+ * flags now define the character processing.
+ * 30.11.93 -- 3.05.92 Kanji support added. New keymap feature:
+ * bindkey and various map commands. GR and C1
+ * flags now define the character processing.
+ * 17.12.93 -- 3.05.93 Tcon authentification mechanism. AddChar macro broken up
+ * into 2 functions. Acl.c, network.c, misc.c, termcap.c
+ * and tty.c are now display free!
+ * 27.12.93 -- 3.05.94 Telnet login works, can export one window per mux.
+ * Acl-groups added. Export rights is an acl.
+ * connect works, can create shadow window thus import
+ * command channel and switch windows. Can detach sessions
+ * from each other. Can renumber imported and exported
+ * windows. DL_LOOP prevents now SEGV, sessions have names
+ * and can be connected to very flexible.
+ * 03.01.94 -- 3.05.95 Import and export of any number of channels works,
+ * except a small bug with margin handling when exporting.
+ * Window titles are forwarded, break is forwarded and
+ * tcon learned the mux protocoll. A few more bugs in
+ * network.c fixed. Tcon has Mux arrays, Protocoll is '\0'
+ * free.
+ * 08.01.94 -- 3.05.96 More tcon work. Solaris debugging.
+ *
+ * 14.01.94 -- 3.05.05 New FindSocket() code. Nicer socket handling.
+ * 20.01.94 -- 3.05.06 New attribute handling code. NeXT fixes.
+ * 04.02.94 -- 3.05.07 Ugly bug in ScrollH fixed. Keymap defaults.
+ * 10.03.94 -- 3.05.97 'defsilence' by Lloyd Zusman. Zombie resurrekt key.
+ * -b, -p options. Fixed Compilekeys(), gulp. config.h
+ * allows choice of VMIN/VTIME/NDELAY for ttys.
+ * 13.04.94 -- 3.05.08 Kanji bug fixed. POSIX sigaction support.
+ * os.h cleanup. UTNOKEEP splitted into
+ * UT_CLOSE and UT_UNSORTED. linux no longer
+ * implies UT_CLOSE. "struct display" name
+ * convention change: _d_ to d_ and d_ to D_.
+ * 20.04.94 -- 3.05.09 configure.in ptyrange bug fixed. Upgraded
+ * to autoconf-1.8
+ * 27.04.94 -- 3.05.10 97801 obscure code support. Linux long
+ * password workaround.
+ * 09.05.94 -- 3.05.11 seteuid() support added. Security fixes.
+ * _IBMR2 kludge makes call to sleep obsolete.
+ * Small fixes in uname() code. djm suggests replace of
+ * BSDI by __bsdi__.
+ * 27.07.94 -- 3.05.12 seteuid attacher bug fixed. ks/ke changed
+ * in termcap/info and termcap.c
+ * 01.09.94 -- 3.05.58 (There are a few more patches to come, subtracted 40)
+ * breaktype command to select how we cause breaks.
+ * Testing logfile.c. Manual and texinfo documentation
+ * updated to explain all new commands except keymapping.
+ * Added modem lines to info of plain ttys. Using
+ * cfset{i,o}speed() for POSIX is better, much better.
+ * 07.09.94 -- 3.05.59 Flushing logfiles every 5 seconds. Testing new
+ * resize linewrap code. Resize with care.
+ * Resurrect now displays its command string.
+ * 11.09.94 -- 3.05.60 Lines are now correctly wrapped, when window size
+ * changes; this prevents loss of text.
+ * 15.09.94 -- 3.05.61 umask renamed to aclumask, bell renamed to bell_msg.
+ * *_msg commands show message when called w/o parameter.
+ * Many changes in the manual, thanks to Sven Guckes.
+ * -O removed.
+ * 27.09.94 -- 3.05.13 defwlock stupidity fixed. MakeTermcap ks/ke
+ * ':' removed. Termcap entry improved.
+ * copy_reg and ins_reg obsoleted by better paste command:
+ * paste => paste .
+ * copy_reg r => paste . r
+ * ins_reg r => paste r
+ * ins_reg => paste
+ * 18.10.94 -- 3.05.62 breaktype changed. -L option added to enable logging
+ * from both command line and screenrc. SIGXFSZ ignored.
+ * 28.11.94 -- 3.05.63 ACL's sharpened. No user has any rights, unless
+ * explicitly given. Only two exceptions: 1) "acladd user"
+ * without further parameters. 2) Evry user has a default
+ * umask that gives himself all permissions on the windows
+ * he creates. Bug with colon input on shared windows fixed.
+ * The commad is now executed by the user typing the final
+ * Enter-Key rather by a random user.
+ * 30.11.94 -- 3.05.64 On demand grabbing of pending auto writelocks.
+ * Solaris troubles us with kill(pid, 0) ... not fixed...
+ * defbreaktype added. (breaktype is also global, still...)
+ * SIGARGHACK cleared, to pamper poor little Ultrix4.4 cfe.
+ * defescape added.
+ * w_status changed to w_hstatus, it's a #define in
+ * Domain/OS reported by ejackson@iastate.edu.
+ * 05.12.94 -- 3.05.17 SVR4 pty bug fixed, don't update window status
+ * line if not changed, onyx support. Manual
+ * pages updated.
+ * 14.12.94 -- 3.05.18 w_status changed to w_hstatus, it's a #define in
+ * Domain/OS reported by ejackson@iastate.edu.
+ * Screen manpage patches by larry.
+ * Ugly seteuid bug in ForkWindow() fixed.
+ * 20.12.94 -- 3.06.00 Solaris has broken seteuid().
+ * osf loadav patches. -- DISTRIBUTED
+ * 08.01.95 -- 3.05.65 Bug with LOGOUTOK and -ln fixed. redundant secfopen()
+ * avoided, when logfflush() looks at delayed nfs updates.
+ * Option parser now allowes condensed options. -A fixed.
+ * New commands 'preselect' and 'defpreselect'. New option
+ * -WdmS starts a detached screen session with watchdog.
+ * 16.01.95 -- 3.06.01 KANJI patch. doc/Makefile.in fixed.
+ * Install now calls doc/Makefile install.
+ * Don't use 'ds' too often, breaks MSkermit.
+ * undef'd LOGOUTOK logs in now.
+ * Ultrix is broken, too (seteuid).
+ * Use \r (not \n) to join lines in pastebuf.
+ * bindkey can now remove sequences.
+ * InitTTY fixed for PLAIN. -- DISTRIBUTED
+ * 06.02.95 -- 3.05.66 DisplayLine() does now clipping to reduce coredump-
+ * frequency. Window size is adapted to the display that
+ * types input, to reduce multi-user confusion. Scrollback
+ * mode still may get the wrong size.
+ * 07.02.95 -- 3.05.67 WinRewrite() also needs to clip. Users without unix
+ * account, but with screen password allowed. Chacl
+ * allows password change, su prompts for user name too.
+ * 01.03.95 -- 3.05.68 Leaving a window may now cause a resize to match a
+ * remaining display. Simple ESC-CR fix in the vt100
+ * state machine.
+ * 26.03.95 -- 3.05.69 Markroutine() needs to resize the window to avoid
+ * coredumps, just like WinProcess() already does.
+ * More NEED_ flags added in comm.c to avoid coredumps.
+ * 04.04.95 -- 3.06.02 Simple ESC-CR fix in the vt100 state machine.
+ * Now compiles again with all extras disabled.
+ * Zombie resurrect added. defc1, defgr, defkanji
+ * added. Screen now replies to a secondary DA
+ * query. Some missing NEED_XXX added in comm.c.
+ * Better default tty permissions/group test.
+ * More AUX support, now compiles with POSIX.
+ * Function keycodes xtermified (F11, F12).
+ * Paste bug fixed (only worked with KANJI).
+ * Check bcopy before memcpy/memmove.
+ * FindSocket code much fixed & improved.
+ * 10.04.95 -- 3.05.70 Display_displays() now shows the users permissions on
+ * the currently displayed window, this is easier than a
+ * full featured lsacl, but also helps. chacl can now copy
+ * users, but we need to copy windows.
+ * 26.04.95 -- 3.05.71 Multi digit screen numbers in utmp. MakeWindow() now
+ * echoes what it does, just like RemakeWindow() when
+ * 'verbose on' (default off).
+ * `screen -ls myname/' will find own(!) non-multi sessions.
+ * Command line option -q improved and documented.
+ * 'debug off' also shuts attacher debugging off now.
+ * 03.05.95 -- 3.05.72 'connect' command bugfixed. colon prompt improved.
+ * open(O_NONBLOCK) does not work on 4.1.3, using O_NDELAY.
+ * There are writes to exp_wid2chan[-1], XXX I just added
+ * fillers to the mux structure, please debug this ASAP!
+ * WindowByName() prefers exact matches now. Esc forwarding
+ * from Frontend to Backend suppressed unless specified.
+ * 26.06.95 -- 3.05.73 Improving the combination of dflag and rflag: If both
+ * are set, a screen session is reattached, regardless
+ * if it was previously detached or attached elseewhere.
+ * "screen -D -RR" is thus most powerful: Give me my screen
+ * session here and now. No matter, if this means creating
+ * a new session (due to the second R without warning
+ * message), detching the session first (and due to the
+ * capitalised D logging out), or simply attaching to it.
+ * 13.07.95 -- 3.05.74 Markroutine learned new join mode: comma seperated.
+ * Can disable the detach feature from config.h.
+ * Configure.in now calls etc/toolcheck. Password is no
+ * longer a static array.
+ * 30.07.95 -- 3.05.75 Karl Heuer wants to install with a relative symlink.
+ * Command line option -k removed (try -t).
+ * 31.08.95 -- 3.06.03 Color support, digraph command, code
+ * cleanup (struct mchar/mline added).
+ * 03.09.95 -- 3.06.04 SetRendition display check. Solaris unblock
+ * SIGHUP. w_curchar->w_rend, lintified.
+ * Shadow-password code moved and rewritten
+ * (includes sun C2).
+ * 06.09.95 -- 3.05.76 Added support for braille displays (by Hadi Bargi Rangin
+ * and Bill Barry, {bargy,barryb}@dots.physics.orst.edu
+ * Added baud, cs8, istrip, ixon, ixoff options for plain
+ * tty windows. Untested.
+ * 09.09.95 -- 3.07.99 Merged 3.7.76 back into the main distribution but
+ * without network, blankwindow and dlist support.
+ * Global variable Password removed.
+ * Resize code completely rewritten.
+ * New commands: sorendition, (def)charset.
+ * strftime-like message generation.
+ * 26.09.95 -- 3.06.05 resize code completely rewritten.
+ * Very visible cursor added. vbell sequence
+ * \Eb added. _delay for terminfo libs added
+ * to make the padding work for the first time.
+ * New ProcessInput() makes "command command"
+ * work. '[def]escape ""' clears escape chars.
+ * Changed logdir command to logfile. It now uses
+ * MakeWinMsg() to create the filename.
+ * Updated the manuals.
+ * 03.10.95 -- 3.08.00 Merged 3.07.99 back into my 3.06.05.
+ * pause removed. NONROOT now in config.h.
+ * sysV68 configure test. Socket protocol got
+ * revision number. New command termcapinfo.
+ * Screenrcs, docs & configure.in updated
+ * 18.10.95 -- 3.08.01 Info shows parser state.
+ * Very visible cursor added. vbell sequence
+ * \Eb added. _delay for terminfo libs added
+ * to make the padding work for the first time.
+ * Braille code almost completely reworked.
+ * New ProcessInput() makes "command command"
+ * work. '[def]escape ""' clears escape chars.
+ * Command logdir -> logfile and uses MakeWinMsg.
+ * Updated the manuals. New mark command 'x'.
+ * stuff has new "-k" parameter.
+ * 28.10.95 -- 3.06.06 Added new 'XC' capability to provide
+ * a method for character translation.
+ * 17.11.95 -- 3.07.00 Added CheckEscape() function.
+ * acl -> acls because of hpux10 nameclash
+ * /stand/vmunix added to kernel list (hpux10)
+ * stripdev changed to translate
+ * /dev/pts<n> to /dev/pts/<n> (unixware)
+ * -lgen added to GETUTENT configure test.
+ * 20.11.95 -- 3.07.01 corrected vbell null ptr reference.
+ * -- DISTRIBUTED
+ * 27.11.95 -- 3.08.02 Added CheckEscape() function.
+ * acl -> acls because of hpux10 nameclash
+ * /stand/vmunix added to kernel list (hpux10)
+ * stripdev changed to translate
+ * /dev/pts<n> to /dev/pts/<n> (unixware)
+ * -lgen added to GETUTENT configure test.
+ * corrected vbell null ptr reference
+ * -- 3.08.03 etc/toolcheck is now shouting louder.
+ * Solaris 2.5 has /kernel/genunix.
+ * Touching socket when detach/attach.
+ * FindWindow corrected. AIX4 patch
+ * from robert@mayday.cix.co.uk.
+ * 1.09.96 -- 3.07.02 added #ifdef MAPKEYS for CheckEscape.
+ * etc/toolcheck is now shouting louder.
+ * Touching socket when detach/attach.
+ * Linux tcflush hack. Linux md5 password suport.
+ * USE_SGR support for dumb (wyse) terminals.
+ * "at" and "reset" commands improved.
+ * Now sensitive to broken AIX4 TIOCPKT.
+ * tek patch unapplied.
+ * linux utmp patch: set slot to DEAD_PROCESS.
+ * include signal.h for killpg if hpux10.10.
+ * linux: elf, but no SVR4, check for utmpx.
+ * hpux10.10 libcurses breaks select()!
+ * -- DISTRIBUTED
+ * 27.09.96 -- 3.07.03 ncurses tgetflag returns -1 if cap not valid.
+ * autonuke fix: reset application mode. An init
+ * string may have cleared it.
+ * Small UTMPOK patch from Douglas B. Jones.
+ * 23.06.97 -- 3.07.04 Some bugfixes. Kanji fixed.
+ * Code update from 3.8.6: Colon line editing added.
+ * Digraph made line-editing resistant.
+ * DEC ALPHA ut_user[0] = 0;
+ * Added error messages to exit_with_usage.
+ * FindSocket code improved (the MULTIUSER part).
+ * Use utimes() if available. Power-detached start.
+ * vsnprintf() support. exit -> _exit in window.c.
+ * AddXChars now tolerates NULL string.
+ * -- DISTRIBUTED
+ * 10.11.98 -- 3.07.05 Wayne's resize.c patch to keep the cursor
+ * onscreen. FindWindow corrected. AIX4 patch
+ * from robert@mayday.cix.co.uk.
+ * Fixed kanji am & markcursor bugs.
+ * SCO support (Gert Doering).
+ * Wayne's statusline extra space. New flag nospc
+ * for MakeWinMsg. New TF capability: add missing
+ * termcap/info caps. screen-exchange security
+ * fix. Use kstat for Solaris' loadavg.
+ * Check for mode 775 if screen runs setgid.
+ * Fixed typo in silence command.
+ * Allow detach with no tty. HPUX10.20 ltchars
+ * hack. Use @1/@7 as replacement for kh/kH.
+ * Use seteuid before calling tgetent.
+ * Check for displays in Msg().
+ * Linux ncurses hack: redefine _nc_timed_wait.
+ * Configure check for ncurses (sigh).
+ * ITOH Yasufumi: kanji fixes, osf support,
+ * bug fixes. More secure Rewrite().
+ * Increased line buffer size to 2048 bytes.
+ * SCO-5 Fixes (Brian L. Gentry).
+ * 25.11.98 -- 3.07.06 resize code now handles tabs correctly.
+ * -- DISTRIBUTED
+ * -- 3.09.00 loads'o'bugs fixed, 3.8 merged with 3.7.
+ * new region clip code.
+ * Many new features (see NEWS file).
+ * 3.08.99 -- 3.09.02 -- DISTRIBUTED
+ * 11.08.99 -- 3.09.04 small utmp fix, BSD chflags fix, tty mode fix
+ * -- DISTRIBUTED
+ * 1.09.99 -- 3.09.05 linux SVR4_PTYS fixes, better ShowWindos(),
+ * Panic() displays bug fixed, strerror fixed,
+ * missing $srcdir & bad prefix in Makefiles.
+ * console grabbing with SRIOCSREDIR.
+ * linux utmp workaround added. Some KANJI bugs
+ * fixed. Stupid StuffKey() bug fixed.
+ * -- DISTRIBUTED
+ * 24.07.00 -- 3.09.06 kanji fixes. lock escape char fix.
+ * removed delayed message hack.
+ * resize command & focus subcomands by joze.
+ * fix for solaris' utmp_helper bug.
+ * linux tty handling fix.
+ * mousetracking, rxvt osc sequences.
+ * background color erase support.
+ * don't log user in after hangup.
+ * hstatus escape update bug fixed.
+ * 1.09.00 -- 3.09.08 -- DISTRIBUTED
+ * 25.05.01 -- 3.09.09 use $DESTDIR in Makefiles.
+ * renamed struct user to acluser to fix hpux
+ * problem for good. utf8 support. 16 color
+ * support. New -X option and escape sequence
+ * to send screen commands.
+ * New commands: attrcolor, defutf8, dinfo, utf8.
+ * Extended commands: width, height, readbuf,
+ * writebuf. Better nlist64 detection.
+ * New config.h option SOCKDIR_IS_LOCAL_TO_HOST.
+ * Don't call tputs with an empty string.
+ * New string escape %{ for attr/color changes.
+ * LRefreshAll bug fixed (0 instead of -1 as bce).
+ * New quote handling in Parse(). Workaround for
+ * some bad termcap/info entries added. Set BE
+ * for all xtermish emulators. Added '0x' and
+ * 'U+' prefix in digraph command. LOADAV_TYPE
+ * detection fixed.
+ * -- DISTRIBUTED
+ * 4.09.01 -- 3.09.10 '-R' security fix. Fixed array in MScrollV().
+ * -- DISTRIBUTED
+ * Reset charset after 'me'.
+ * 14.02.02 -- 3.09.11 Support for other encodings. Double width
+ * utf-8 chars. 'L' modifier for %D, %M, %w
+ * and %W. New %= (hfill), %H (hostname),
+ * %f (flags), %F (focus) escapes. New commands
+ * source, windowlist, deflog. Command key classes.
+ * New login state: always. Time format
+ * changeable. 256 color support.
+ * Updated digraph table. Ignorecase.
+ * Windowlist resizeable on blank window.
+ * Added encoding to paste buffers.
+ * Hpux loadtype detection fixed.
+ * Disabled im/ic warning. Fixed a bug that
+ * could cause window lockups in rare
+ * circumstances. Made hangup signal to the
+ * backend process detach all displays.
+ * New escapes %< %>, + and - flag for %w.
+ * Added eval command, added -h option to detach.
+ * Also set flayer when processing -X commands.
+ * use getpt() on linux systems. doc patches from
+ * Adam Lazur. tty flow/intr cleanup.
+ * -- DISTRIBUTED
+ * 29.08.2002 3.09.12 Port to POSIX 1003.1-2001 hosts (Paul Eggert).
+ * Fixed encoding for reattach password test.
+ * Fixed NUL characters when encodings are active.
+ * Fixed silly encodings bugs. Fixed bogus
+ * oldflayer when a window gets freed.
+ * Altscreen support by Gurusamy Sarathy.
+ * Reuse old password in builtin_screenlock.
+ * -- DISTRIBUTED
+ * 05.09.2002 3.09.13 added missing break statement that broke
+ * the eval command.
+ * -- DISTRIBUTED
+ * 13.03.2003 3.09.15 Console workaround for linux. Scrolling-region
+ * reset fix. GBK encoding added.
+ * support for unicode combining characters added.
+ * openpty() support added (thomas@xs4all.nl).
+ * preselect of blank window ('-') or window
+ * list ('=') added. Added %` string escape
+ * and backtick command.
+ * -- DISTRIBUTED
+ * 08.09.2003 4.00.00 rewrote nonblock command, added defnonblock.
+ * added zmodem support (catch & passthrough).
+ * added screenblanker.
+ * fixed a couple of GBK bugs.
+ * rewrote command parsing.
+ * added -m option to windowlist (Felix Rosencrantz)
+ * -- DISTRIBUTED
+ * 18.09.2003 4.00.01 fixed two small bugs in the new parser.
+ * -- DISTRIBUTED
+ * 05.12.2003 4.00.02 fixed a bug in the ansi parser. fixed execs
+ * on ttys. fixed hardstatus line on blanked screen.
+ * -- DISTRIBUTED
+ * 11.10.2004, 4.00.03jw handle StartRc errors nonfatal if due to a msg.
+ * 12.10.2004, 4.00.03jw1 let docu of 'split' 'focus' 'remove' and 'only' refer to each other.
+ * 01.11.2004, 4.00.03jw2 zombie command has new option 'onerror'
+ * 2005-12-19, 4.00.03jw3 syntax error.
+*/
+
+#define ORIGIN "GNU"
+#define REV 4
+#define VERS 6
+#define PATCHLEVEL 2
+#define DATE "23-Oct-17"
+#define STATE ""
diff --git a/process.c b/process.c
new file mode 100644
index 0000000..ec5a911
--- /dev/null
+++ b/process.c
@@ -0,0 +1,7414 @@
+/* Copyright (c) 2010
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include "config.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <fcntl.h>
+#if !defined(sun) && !defined(B43) && !defined(ISC) && !defined(pyr) && !defined(_CX_UX)
+# include <time.h>
+#endif
+#include <sys/time.h>
+#ifndef sun
+#include <sys/ioctl.h>
+#endif
+
+
+/* for solaris 2.1, Unixware (SVR4.2) and possibly others: */
+#ifdef HAVE_STROPTS_H
+# include <sys/stropts.h>
+#endif
+
+#include "screen.h"
+#include "extern.h"
+#include "logfile.h"
+#include "layout.h"
+#include "viewport.h"
+#include "list_generic.h"
+
+extern struct comm comms[];
+extern char *rc_name;
+extern char *RcFileName, *home;
+extern char *BellString, *ActivityString, *ShellProg, *ShellArgs[];
+extern char *hstatusstring, *captionstring, *timestring;
+extern char *wliststr, *wlisttit;
+extern int captionalways;
+extern int queryflag;
+extern char *hardcopydir, *screenlogfile, *logtstamp_string;
+extern int log_flush, logtstamp_on, logtstamp_after;
+extern char *VisualBellString;
+extern int VBellWait, MsgWait, MsgMinWait, SilenceWait;
+extern char SockPath[], *SockName;
+extern int TtyMode, auto_detach, use_altscreen;
+extern int iflag, maxwin;
+extern int focusminwidth, focusminheight;
+extern int use_hardstatus, visual_bell;
+#ifdef COLOR
+extern int attr2color[][4];
+extern int nattr2color;
+#endif
+extern int hardstatusemu;
+extern char *printcmd;
+extern int default_startup;
+extern int defobuflimit;
+extern int defnonblock;
+extern int defmousetrack;
+extern int ZombieKey_destroy;
+extern int ZombieKey_resurrect;
+extern int ZombieKey_onerror;
+#ifdef AUTO_NUKE
+extern int defautonuke;
+#endif
+extern int separate_sids;
+extern struct NewWindow nwin_default, nwin_undef;
+#ifdef COPY_PASTE
+extern int join_with_cr;
+extern int compacthist;
+extern int search_ic;
+# ifdef FONT
+extern int pastefont;
+# endif
+extern unsigned char mark_key_tab[];
+extern char *BufferFile;
+#endif
+#ifdef POW_DETACH
+extern char *BufferFile, *PowDetachString;
+#endif
+#ifdef MULTIUSER
+extern struct acluser *EffectiveAclUser; /* acl.c */
+#endif
+extern struct term term[]; /* terminal capabilities */
+#ifdef MAPKEYS
+extern char *kmapdef[];
+extern char *kmapadef[];
+extern char *kmapmdef[];
+#endif
+extern struct mchar mchar_so, mchar_null;
+extern int renditions[];
+extern int VerboseCreate;
+#ifdef UTF8
+extern char *screenencodings;
+#endif
+#ifdef DW_CHARS
+extern int cjkwidth;
+#endif
+
+static int CheckArgNum __P((int, char **));
+static void ClearAction __P((struct action *));
+static void SaveAction __P((struct action *, int, char **, int *));
+static int NextWindow __P((void));
+static int PreviousWindow __P((void));
+static int MoreWindows __P((void));
+static void CollapseWindowlist __P((void));
+static void LogToggle __P((int));
+static void ShowInfo __P((void));
+static void ShowDInfo __P((void));
+static struct win *WindowByName __P((char *));
+static int WindowByNumber __P((char *));
+static int ParseOnOff __P((struct action *, int *));
+static int ParseWinNum __P((struct action *, int *));
+static int ParseBase __P((struct action *, char *, int *, int, char *));
+static int ParseNum1000 __P((struct action *, int *));
+static char **SaveArgs __P((char **));
+static int IsNum __P((char *, int));
+static void Colonfin __P((char *, int, char *));
+static void InputSelect __P((void));
+static void InputSetenv __P((char *));
+static void InputAKA __P((void));
+#ifdef MULTIUSER
+static int InputSu __P((struct win *, struct acluser **, char *));
+static void su_fin __P((char *, int, char *));
+#endif
+static void AKAfin __P((char *, int, char *));
+#ifdef COPY_PASTE
+static void copy_reg_fn __P((char *, int, char *));
+static void ins_reg_fn __P((char *, int, char *));
+#endif
+static void process_fn __P((char *, int, char *));
+#ifdef PASSWORD
+static void pass1 __P((char *, int, char *));
+static void pass2 __P((char *, int, char *));
+#endif
+#ifdef POW_DETACH
+static void pow_detach_fn __P((char *, int, char *));
+#endif
+static void digraph_fn __P((char *, int, char *));
+static int digraph_find __P((const char *buf));
+static void confirm_fn __P((char *, int, char *));
+static int IsOnDisplay __P((struct win *));
+static void ResizeRegions __P((char *, int));
+static void ResizeFin __P((char *, int, char *));
+static struct action *FindKtab __P((char *, int));
+static void SelectFin __P((char *, int, char *));
+static void SelectLayoutFin __P((char *, int, char *));
+static void ShowWindowsX __P((char *));
+
+
+extern struct layer *flayer;
+extern struct display *display, *displays;
+extern struct win *fore, *console_window, *windows;
+extern struct acluser *users;
+extern struct layout *layouts, *layout_attach, layout_last_marker;
+extern struct layout *laytab[];
+
+extern char screenterm[], HostName[], version[];
+extern struct NewWindow nwin_undef, nwin_default;
+extern struct LayFuncs WinLf, MarkLf;
+
+extern const int Z0width, Z1width;
+extern int real_uid, real_gid;
+
+#ifdef NETHACK
+extern int nethackflag;
+#endif
+
+
+extern struct win **wtab;
+
+#ifdef MULTIUSER
+extern char *multi;
+extern int maxusercount;
+#endif
+char NullStr[] = "";
+
+struct plop plop_tab[MAX_PLOP_DEFS];
+
+#ifndef PTYMODE
+# define PTYMODE 0622
+#endif
+
+int TtyMode = PTYMODE;
+int hardcopy_append = 0;
+int all_norefresh = 0;
+#ifdef ZMODEM
+int zmodem_mode = 0;
+char *zmodem_sendcmd;
+char *zmodem_recvcmd;
+static char *zmodes[4] = {"off", "auto", "catch", "pass"};
+#endif
+
+int idletimo;
+struct action idleaction;
+#ifdef BLANKER_PRG
+char **blankerprg;
+#endif
+
+struct action ktab[256 + KMAP_KEYS]; /* command key translation table */
+struct kclass {
+ struct kclass *next;
+ char *name;
+ struct action ktab[256 + KMAP_KEYS];
+};
+struct kclass *kclasses;
+
+#ifdef MAPKEYS
+struct action umtab[KMAP_KEYS+KMAP_AKEYS];
+struct action dmtab[KMAP_KEYS+KMAP_AKEYS];
+struct action mmtab[KMAP_KEYS+KMAP_AKEYS];
+struct kmap_ext *kmap_exts;
+int kmap_extn;
+static int maptimeout = 300;
+#endif
+
+#ifndef MAX_DIGRAPH
+#define MAX_DIGRAPH 512
+#endif
+
+struct digraph
+{
+ unsigned char d[2];
+ int value;
+};
+
+/* digraph table taken from old vim and rfc1345 */
+static struct digraph digraphs[MAX_DIGRAPH + 1] = {
+ {{' ', ' '}, 160}, /*   */
+ {{'N', 'S'}, 160}, /*   */
+ {{'~', '!'}, 161}, /* ¡ */
+ {{'!', '!'}, 161}, /* ¡ */
+ {{'!', 'I'}, 161}, /* ¡ */
+ {{'c', '|'}, 162}, /* ¢ */
+ {{'c', 't'}, 162}, /* ¢ */
+ {{'$', '$'}, 163}, /* £ */
+ {{'P', 'd'}, 163}, /* £ */
+ {{'o', 'x'}, 164}, /* ¤ */
+ {{'C', 'u'}, 164}, /* ¤ */
+ {{'C', 'u'}, 164}, /* ¤ */
+ {{'E', 'u'}, 164}, /* ¤ */
+ {{'Y', '-'}, 165}, /* ¥ */
+ {{'Y', 'e'}, 165}, /* ¥ */
+ {{'|', '|'}, 166}, /* ¦ */
+ {{'B', 'B'}, 166}, /* ¦ */
+ {{'p', 'a'}, 167}, /* § */
+ {{'S', 'E'}, 167}, /* § */
+ {{'"', '"'}, 168}, /* ¨ */
+ {{'\'', ':'}, 168}, /* ¨ */
+ {{'c', 'O'}, 169}, /* © */
+ {{'C', 'o'}, 169}, /* © */
+ {{'a', '-'}, 170}, /* ª */
+ {{'<', '<'}, 171}, /* « */
+ {{'-', ','}, 172}, /* ¬ */
+ {{'N', 'O'}, 172}, /* ¬ */
+ {{'-', '-'}, 173}, /* ­ */
+ {{'r', 'O'}, 174}, /* ® */
+ {{'R', 'g'}, 174}, /* ® */
+ {{'-', '='}, 175}, /* ¯ */
+ {{'\'', 'm'}, 175}, /* ¯ */
+ {{'~', 'o'}, 176}, /* ° */
+ {{'D', 'G'}, 176}, /* ° */
+ {{'+', '-'}, 177}, /* ± */
+ {{'2', '2'}, 178}, /* ² */
+ {{'2', 'S'}, 178}, /* ² */
+ {{'3', '3'}, 179}, /* ³ */
+ {{'3', 'S'}, 179}, /* ³ */
+ {{'\'', '\''}, 180}, /* ´ */
+ {{'j', 'u'}, 181}, /* µ */
+ {{'M', 'y'}, 181}, /* µ */
+ {{'p', 'p'}, 182}, /* ¶ */
+ {{'P', 'I'}, 182}, /* ¶ */
+ {{'~', '.'}, 183}, /* · */
+ {{'.', 'M'}, 183}, /* · */
+ {{',', ','}, 184}, /* ¸ */
+ {{'\'', ','}, 184}, /* ¸ */
+ {{'1', '1'}, 185}, /* ¹ */
+ {{'1', 'S'}, 185}, /* ¹ */
+ {{'o', '-'}, 186}, /* º */
+ {{'>', '>'}, 187}, /* » */
+ {{'1', '4'}, 188}, /* ¼ */
+ {{'1', '2'}, 189}, /* ½ */
+ {{'3', '4'}, 190}, /* ¾ */
+ {{'~', '?'}, 191}, /* ¿ */
+ {{'?', '?'}, 191}, /* ¿ */
+ {{'?', 'I'}, 191}, /* ¿ */
+ {{'A', '`'}, 192}, /* À */
+ {{'A', '!'}, 192}, /* À */
+ {{'A', '\''}, 193}, /* Á */
+ {{'A', '^'}, 194}, /* Â */
+ {{'A', '>'}, 194}, /* Â */
+ {{'A', '~'}, 195}, /* Ã */
+ {{'A', '?'}, 195}, /* Ã */
+ {{'A', '"'}, 196}, /* Ä */
+ {{'A', ':'}, 196}, /* Ä */
+ {{'A', '@'}, 197}, /* Å */
+ {{'A', 'A'}, 197}, /* Å */
+ {{'A', 'E'}, 198}, /* Æ */
+ {{'C', ','}, 199}, /* Ç */
+ {{'E', '`'}, 200}, /* È */
+ {{'E', '!'}, 200}, /* È */
+ {{'E', '\''}, 201}, /* É */
+ {{'E', '^'}, 202}, /* Ê */
+ {{'E', '>'}, 202}, /* Ê */
+ {{'E', '"'}, 203}, /* Ë */
+ {{'E', ':'}, 203}, /* Ë */
+ {{'I', '`'}, 204}, /* Ì */
+ {{'I', '!'}, 204}, /* Ì */
+ {{'I', '\''}, 205}, /* Í */
+ {{'I', '^'}, 206}, /* Î */
+ {{'I', '>'}, 206}, /* Î */
+ {{'I', '"'}, 207}, /* Ï */
+ {{'I', ':'}, 207}, /* Ï */
+ {{'D', '-'}, 208}, /* Ð */
+ {{'N', '~'}, 209}, /* Ñ */
+ {{'N', '?'}, 209}, /* Ñ */
+ {{'O', '`'}, 210}, /* Ò */
+ {{'O', '!'}, 210}, /* Ò */
+ {{'O', '\''}, 211}, /* Ó */
+ {{'O', '^'}, 212}, /* Ô */
+ {{'O', '>'}, 212}, /* Ô */
+ {{'O', '~'}, 213}, /* Õ */
+ {{'O', '?'}, 213}, /* Õ */
+ {{'O', '"'}, 214}, /* Ö */
+ {{'O', ':'}, 214}, /* Ö */
+ {{'/', '\\'}, 215}, /* × */
+ {{'*', 'x'}, 215}, /* × */
+ {{'O', '/'}, 216}, /* Ø */
+ {{'U', '`'}, 217}, /* Ù */
+ {{'U', '!'}, 217}, /* Ù */
+ {{'U', '\''}, 218}, /* Ú */
+ {{'U', '^'}, 219}, /* Û */
+ {{'U', '>'}, 219}, /* Û */
+ {{'U', '"'}, 220}, /* Ü */
+ {{'U', ':'}, 220}, /* Ü */
+ {{'Y', '\''}, 221}, /* Ý */
+ {{'I', 'p'}, 222}, /* Þ */
+ {{'T', 'H'}, 222}, /* Þ */
+ {{'s', 's'}, 223}, /* ß */
+ {{'s', '"'}, 223}, /* ß */
+ {{'a', '`'}, 224}, /* à */
+ {{'a', '!'}, 224}, /* à */
+ {{'a', '\''}, 225}, /* á */
+ {{'a', '^'}, 226}, /* â */
+ {{'a', '>'}, 226}, /* â */
+ {{'a', '~'}, 227}, /* ã */
+ {{'a', '?'}, 227}, /* ã */
+ {{'a', '"'}, 228}, /* ä */
+ {{'a', ':'}, 228}, /* ä */
+ {{'a', 'a'}, 229}, /* å */
+ {{'a', 'e'}, 230}, /* æ */
+ {{'c', ','}, 231}, /* ç */
+ {{'e', '`'}, 232}, /* è */
+ {{'e', '!'}, 232}, /* è */
+ {{'e', '\''}, 233}, /* é */
+ {{'e', '^'}, 234}, /* ê */
+ {{'e', '>'}, 234}, /* ê */
+ {{'e', '"'}, 235}, /* ë */
+ {{'e', ':'}, 235}, /* ë */
+ {{'i', '`'}, 236}, /* ì */
+ {{'i', '!'}, 236}, /* ì */
+ {{'i', '\''}, 237}, /* í */
+ {{'i', '^'}, 238}, /* î */
+ {{'i', '>'}, 238}, /* î */
+ {{'i', '"'}, 239}, /* ï */
+ {{'i', ':'}, 239}, /* ï */
+ {{'d', '-'}, 240}, /* ð */
+ {{'n', '~'}, 241}, /* ñ */
+ {{'n', '?'}, 241}, /* ñ */
+ {{'o', '`'}, 242}, /* ò */
+ {{'o', '!'}, 242}, /* ò */
+ {{'o', '\''}, 243}, /* ó */
+ {{'o', '^'}, 244}, /* ô */
+ {{'o', '>'}, 244}, /* ô */
+ {{'o', '~'}, 245}, /* õ */
+ {{'o', '?'}, 245}, /* õ */
+ {{'o', '"'}, 246}, /* ö */
+ {{'o', ':'}, 246}, /* ö */
+ {{':', '-'}, 247}, /* ÷ */
+ {{'o', '/'}, 248}, /* ø */
+ {{'u', '`'}, 249}, /* ù */
+ {{'u', '!'}, 249}, /* ù */
+ {{'u', '\''}, 250}, /* ú */
+ {{'u', '^'}, 251}, /* û */
+ {{'u', '>'}, 251}, /* û */
+ {{'u', '"'}, 252}, /* ü */
+ {{'u', ':'}, 252}, /* ü */
+ {{'y', '\''}, 253}, /* ý */
+ {{'i', 'p'}, 254}, /* þ */
+ {{'t', 'h'}, 254}, /* þ */
+ {{'y', '"'}, 255}, /* ÿ */
+ {{'y', ':'}, 255}, /* ÿ */
+ {{'"', '['}, 196}, /* Ä */
+ {{'"', '\\'}, 214}, /* Ö */
+ {{'"', ']'}, 220}, /* Ü */
+ {{'"', '{'}, 228}, /* ä */
+ {{'"', '|'}, 246}, /* ö */
+ {{'"', '}'}, 252}, /* ü */
+ {{'"', '~'}, 223} /* ß */
+};
+
+#define RESIZE_FLAG_H 1
+#define RESIZE_FLAG_V 2
+#define RESIZE_FLAG_L 4
+
+static char *resizeprompts[] = {
+ "resize # lines: ",
+ "resize -h # lines: ",
+ "resize -v # lines: ",
+ "resize -b # lines: ",
+ "resize -l # lines: ",
+ "resize -l -h # lines: ",
+ "resize -l -v # lines: ",
+ "resize -l -b # lines: ",
+};
+
+
+static int
+parse_input_int(buf, len, val)
+const char *buf;
+int len;
+int *val;
+{
+ int x = 0, i;
+ if (len >= 1 && ((*buf == 'U' && buf[1] == '+') || (*buf == '0' && (buf[1] == 'x' || buf[1] == 'X'))))
+ {
+ x = 0;
+ for (i = 2; i < len; i++)
+ {
+ if (buf[i] >= '0' && buf[i] <= '9')
+ x = x * 16 | (buf[i] - '0');
+ else if (buf[i] >= 'a' && buf[i] <= 'f')
+ x = x * 16 | (buf[i] - ('a' - 10));
+ else if (buf[i] >= 'A' && buf[i] <= 'F')
+ x = x * 16 | (buf[i] - ('A' - 10));
+ else
+ return 0;
+ }
+ }
+ else if (buf[0] == '0')
+ {
+ x = 0;
+ for (i = 1; i < len; i++)
+ {
+ if (buf[i] < '0' || buf[i] > '7')
+ return 0;
+ x = x * 8 | (buf[i] - '0');
+ }
+ }
+ else
+ return 0;
+ *val = x;
+ return 1;
+}
+
+char *noargs[1];
+
+int enter_window_name_mode = 0;
+
+void
+InitKeytab()
+{
+ register unsigned int i;
+#ifdef MAPKEYS
+ char *argarr[2];
+#endif
+
+ for (i = 0; i < sizeof(ktab)/sizeof(*ktab); i++)
+ {
+ ktab[i].nr = RC_ILLEGAL;
+ ktab[i].args = noargs;
+ ktab[i].argl = 0;
+ }
+#ifdef MAPKEYS
+ for (i = 0; i < KMAP_KEYS+KMAP_AKEYS; i++)
+ {
+ umtab[i].nr = RC_ILLEGAL;
+ umtab[i].args = noargs;
+ umtab[i].argl = 0;
+ dmtab[i].nr = RC_ILLEGAL;
+ dmtab[i].args = noargs;
+ dmtab[i].argl = 0;
+ mmtab[i].nr = RC_ILLEGAL;
+ mmtab[i].args = noargs;
+ mmtab[i].argl = 0;
+ }
+ argarr[1] = 0;
+ for (i = 0; i < NKMAPDEF; i++)
+ {
+ if (i + KMAPDEFSTART < T_CAPS)
+ continue;
+ if (i + KMAPDEFSTART >= T_CAPS + KMAP_KEYS)
+ continue;
+ if (kmapdef[i] == 0)
+ continue;
+ argarr[0] = kmapdef[i];
+ SaveAction(dmtab + i + (KMAPDEFSTART - T_CAPS), RC_STUFF, argarr, 0);
+ }
+ for (i = 0; i < NKMAPADEF; i++)
+ {
+ if (i + KMAPADEFSTART < T_CURSOR)
+ continue;
+ if (i + KMAPADEFSTART >= T_CURSOR + KMAP_AKEYS)
+ continue;
+ if (kmapadef[i] == 0)
+ continue;
+ argarr[0] = kmapadef[i];
+ SaveAction(dmtab + i + (KMAPADEFSTART - T_CURSOR + KMAP_KEYS), RC_STUFF, argarr, 0);
+ }
+ for (i = 0; i < NKMAPMDEF; i++)
+ {
+ if (i + KMAPMDEFSTART < T_CAPS)
+ continue;
+ if (i + KMAPMDEFSTART >= T_CAPS + KMAP_KEYS)
+ continue;
+ if (kmapmdef[i] == 0)
+ continue;
+ argarr[0] = kmapmdef[i];
+ argarr[1] = 0;
+ SaveAction(mmtab + i + (KMAPMDEFSTART - T_CAPS), RC_STUFF, argarr, 0);
+ }
+#endif
+
+ ktab['h'].nr = RC_HARDCOPY;
+#ifdef BSDJOBS
+ ktab['z'].nr = ktab[Ctrl('z')].nr = RC_SUSPEND;
+#endif
+ ktab['c'].nr = ktab[Ctrl('c')].nr = RC_SCREEN;
+ ktab[' '].nr = ktab[Ctrl(' ')].nr =
+ ktab['n'].nr = ktab[Ctrl('n')].nr = RC_NEXT;
+ ktab['N'].nr = RC_NUMBER;
+ ktab[Ctrl('h')].nr = ktab[0177].nr = ktab['p'].nr = ktab[Ctrl('p')].nr = RC_PREV;
+ ktab['k'].nr = ktab[Ctrl('k')].nr = RC_KILL;
+ ktab['l'].nr = ktab[Ctrl('l')].nr = RC_REDISPLAY;
+ ktab['w'].nr = ktab[Ctrl('w')].nr = RC_WINDOWS;
+ ktab['v'].nr = RC_VERSION;
+ ktab[Ctrl('v')].nr = RC_DIGRAPH;
+ ktab['q'].nr = ktab[Ctrl('q')].nr = RC_XON;
+ ktab['s'].nr = ktab[Ctrl('s')].nr = RC_XOFF;
+ ktab['t'].nr = ktab[Ctrl('t')].nr = RC_TIME;
+ ktab['i'].nr = ktab[Ctrl('i')].nr = RC_INFO;
+ ktab['m'].nr = ktab[Ctrl('m')].nr = RC_LASTMSG;
+ ktab['A'].nr = RC_TITLE;
+#if defined(UTMPOK) && defined(LOGOUTOK)
+ ktab['L'].nr = RC_LOGIN;
+#endif
+ ktab[','].nr = RC_LICENSE;
+ ktab['W'].nr = RC_WIDTH;
+ ktab['.'].nr = RC_DUMPTERMCAP;
+ ktab[Ctrl('\\')].nr = RC_QUIT;
+#ifdef DETACH
+ ktab['d'].nr = ktab[Ctrl('d')].nr = RC_DETACH;
+# ifdef POW_DETACH
+ ktab['D'].nr = RC_POW_DETACH;
+# endif
+#endif
+ ktab['r'].nr = ktab[Ctrl('r')].nr = RC_WRAP;
+ ktab['f'].nr = ktab[Ctrl('f')].nr = RC_FLOW;
+ ktab['C'].nr = RC_CLEAR;
+ ktab['Z'].nr = RC_RESET;
+ ktab['H'].nr = RC_LOG;
+ ktab['M'].nr = RC_MONITOR;
+ ktab['?'].nr = RC_HELP;
+#ifdef MULTI
+ ktab['*'].nr = RC_DISPLAYS;
+#endif
+ {
+ char *args[2];
+ args[0] = "-";
+ args[1] = NULL;
+ SaveAction(ktab + '-', RC_SELECT, args, 0);
+ }
+ for (i = 0; i < ((maxwin && maxwin < 10) ? maxwin : 10); i++)
+ {
+ char *args[2], arg1[10];
+ args[0] = arg1;
+ args[1] = 0;
+ sprintf(arg1, "%d", i);
+ SaveAction(ktab + '0' + i, RC_SELECT, args, 0);
+ }
+ ktab['\''].nr = RC_SELECT; /* calling a window by name */
+ {
+ char *args[2];
+ args[0] = "-b";
+ args[1] = 0;
+ SaveAction(ktab + '"', RC_WINDOWLIST, args, 0);
+ }
+ ktab[Ctrl('G')].nr = RC_VBELL;
+ ktab[':'].nr = RC_COLON;
+#ifdef COPY_PASTE
+ ktab['['].nr = ktab[Ctrl('[')].nr = RC_COPY;
+ {
+ char *args[2];
+ args[0] = ".";
+ args[1] = 0;
+ SaveAction(ktab + ']', RC_PASTE, args, 0);
+ SaveAction(ktab + Ctrl(']'), RC_PASTE, args, 0);
+ }
+ ktab['{'].nr = RC_HISTORY;
+ ktab['}'].nr = RC_HISTORY;
+ ktab['>'].nr = RC_WRITEBUF;
+ ktab['<'].nr = RC_READBUF;
+ ktab['='].nr = RC_REMOVEBUF;
+#endif
+#ifdef POW_DETACH
+ ktab['D'].nr = RC_POW_DETACH;
+#endif
+#ifdef LOCK
+ ktab['x'].nr = ktab[Ctrl('x')].nr = RC_LOCKSCREEN;
+#endif
+ ktab['b'].nr = ktab[Ctrl('b')].nr = RC_BREAK;
+ ktab['B'].nr = RC_POW_BREAK;
+ ktab['_'].nr = RC_SILENCE;
+ ktab['S'].nr = RC_SPLIT;
+ ktab['Q'].nr = RC_ONLY;
+ ktab['X'].nr = RC_REMOVE;
+ ktab['F'].nr = RC_FIT;
+ ktab['\t'].nr = RC_FOCUS;
+ {
+ char *args[2];
+ args[0] = "prev";
+ args[1] = 0;
+ SaveAction(ktab + T_BACKTAB - T_CAPS + 256, RC_FOCUS, args, 0);
+ }
+ {
+ char *args[2];
+ args[0] = "-v";
+ args[1] = 0;
+ SaveAction(ktab + '|', RC_SPLIT, args, 0);
+ }
+ /* These come last; they may want overwrite others: */
+ if (DefaultEsc >= 0)
+ {
+ ClearAction(&ktab[DefaultEsc]);
+ ktab[DefaultEsc].nr = RC_OTHER;
+ }
+ if (DefaultMetaEsc >= 0)
+ {
+ ClearAction(&ktab[DefaultMetaEsc]);
+ ktab[DefaultMetaEsc].nr = RC_META;
+ }
+
+ idleaction.nr = RC_BLANKER;
+ idleaction.args = noargs;
+ idleaction.argl = 0;
+}
+
+static struct action *
+FindKtab(class, create)
+char *class;
+int create;
+{
+ struct kclass *kp, **kpp;
+ int i;
+
+ if (class == 0)
+ return ktab;
+ for (kpp = &kclasses; (kp = *kpp) != 0; kpp = &kp->next)
+ if (!strcmp(kp->name, class))
+ break;
+ if (kp == 0)
+ {
+ if (!create)
+ return 0;
+ if (strlen(class) > 80)
+ {
+ Msg(0, "Command class name too long.");
+ return 0;
+ }
+ kp = malloc(sizeof(*kp));
+ if (kp == 0)
+ {
+ Msg(0, "%s", strnomem);
+ return 0;
+ }
+ kp->name = SaveStr(class);
+ for (i = 0; i < (int)(sizeof(kp->ktab)/sizeof(*kp->ktab)); i++)
+ {
+ kp->ktab[i].nr = RC_ILLEGAL;
+ kp->ktab[i].args = noargs;
+ kp->ktab[i].argl = 0;
+ kp->ktab[i].quiet = 0;
+ }
+ kp->next = 0;
+ *kpp = kp;
+ }
+ return kp->ktab;
+}
+
+static void
+ClearAction(act)
+struct action *act;
+{
+ char **p;
+
+ if (act->nr == RC_ILLEGAL)
+ return;
+ act->nr = RC_ILLEGAL;
+ if (act->args == noargs)
+ return;
+ for (p = act->args; *p; p++)
+ free(*p);
+ free((char *)act->args);
+ act->args = noargs;
+ act->argl = 0;
+}
+
+/*
+ * ProcessInput: process input from display and feed it into
+ * the layer on canvas D_forecv.
+ */
+
+#ifdef MAPKEYS
+
+/*
+ * This ProcessInput just does the keybindings and passes
+ * everything else on to ProcessInput2.
+ */
+
+void
+ProcessInput(ibuf, ilen)
+char *ibuf;
+int ilen;
+{
+ int ch, slen;
+ unsigned char *s, *q;
+ int i, l;
+ char *p;
+
+ debug1("ProcessInput: %d bytes\n", ilen);
+ if (display == 0 || ilen == 0)
+ return;
+ if (D_seql)
+ evdeq(&D_mapev);
+ slen = ilen;
+ s = (unsigned char *)ibuf;
+ while (ilen-- > 0)
+ {
+ ch = *s++;
+ if (D_dontmap || !D_nseqs)
+ {
+ D_dontmap = 0;
+ continue;
+ }
+ for (;;)
+ {
+ debug3("cmp %c %c[%d]\n", ch, *D_seqp, D_seqp - D_kmaps);
+ if (*D_seqp != ch)
+ {
+ l = D_seqp[D_seqp[-D_seql-1] + 1];
+ if (l)
+ {
+ D_seqp += l * 2 + 4;
+ debug1("miss %d\n", D_seqp - D_kmaps);
+ continue;
+ }
+ debug("complete miss\n");
+ D_mapdefault = 0;
+ l = D_seql;
+ p = (char *)D_seqp - l;
+ D_seql = 0;
+ D_seqp = D_kmaps + 3;
+ if (l == 0)
+ break;
+ if ((q = D_seqh) != 0)
+ {
+ D_seqh = 0;
+ i = q[0] << 8 | q[1];
+ i &= ~KMAP_NOTIMEOUT;
+ debug1("Mapping former hit #%d - ", i);
+ debug2("%d(%s) - ", q[2], q + 3);
+ if (StuffKey(i))
+ ProcessInput2((char *)q + 3, q[2]);
+ if (display == 0)
+ return;
+ l -= q[2];
+ p += q[2];
+ }
+ else
+ D_dontmap = 1;
+ debug1("flush old %d\n", l);
+ ProcessInput(p, l);
+ if (display == 0)
+ return;
+ evdeq(&D_mapev);
+ continue;
+ }
+ if (D_seql++ == 0)
+ {
+ /* Finish old stuff */
+ slen -= ilen + 1;
+ debug1("finish old %d\n", slen);
+ if (slen)
+ ProcessInput2(ibuf, slen);
+ if (display == 0)
+ return;
+ D_seqh = 0;
+ }
+ ibuf = (char *)s;
+ slen = ilen;
+ D_seqp++;
+ l = D_seql;
+ debug2("length am %d, want %d\n", l, D_seqp[-l - 1]);
+ if (l == D_seqp[-l - 1])
+ {
+ if (D_seqp[l] != l)
+ {
+ q = D_seqp + 1 + l;
+ if (D_kmaps + D_nseqs > q && q[2] > l && !bcmp(D_seqp - l, q + 3, l))
+ {
+ debug1("have another mapping (%s), delay execution\n", q + 3);
+ D_seqh = D_seqp - 3 - l;
+ D_seqp = q + 3 + l;
+ break;
+ }
+ }
+ i = D_seqp[-l - 3] << 8 | D_seqp[-l - 2];
+ i &= ~KMAP_NOTIMEOUT;
+ debug1("Mapping #%d - ", i);
+ p = (char *)D_seqp - l;
+ debug2("%d(%s) - ", l, p);
+ D_seql = 0;
+ D_seqp = D_kmaps + 3;
+ D_seqh = 0;
+ if (StuffKey(i))
+ ProcessInput2(p, l);
+ if (display == 0)
+ return;
+ }
+ break;
+ }
+ }
+ if (D_seql)
+ {
+ debug("am in sequence -> check for timeout\n");
+ l = D_seql;
+ for (s = D_seqp; ; s += i * 2 + 4)
+ {
+ if (s[-l-3] & KMAP_NOTIMEOUT >> 8)
+ break;
+ if ((i = s[s[-l-1] + 1]) == 0)
+ {
+ SetTimeout(&D_mapev, maptimeout);
+ evenq(&D_mapev);
+ break;
+ }
+ }
+ }
+ ProcessInput2(ibuf, slen);
+}
+
+#else
+# define ProcessInput2 ProcessInput
+#endif
+
+
+/*
+ * Here only the screen escape commands are handled.
+ */
+
+void
+ProcessInput2(ibuf, ilen)
+char *ibuf;
+int ilen;
+{
+ char *s;
+ int ch, slen;
+ struct action *ktabp;
+
+ debug1("ProcessInput2: %d bytes\n", ilen);
+ while (ilen && display)
+ {
+ debug1(" - ilen now %d bytes\n", ilen);
+ flayer = D_forecv->c_layer;
+ fore = D_fore;
+ slen = ilen;
+ s = ibuf;
+ if (!D_ESCseen)
+ {
+ while (ilen > 0)
+ {
+ if ((unsigned char)*s++ == D_user->u_Esc)
+ break;
+ ilen--;
+ }
+ slen -= ilen;
+ if (slen)
+ DoProcess(fore, &ibuf, &slen, 0);
+ if (--ilen == 0)
+ {
+ D_ESCseen = ktab;
+ WindowChanged(fore, 'E');
+ }
+ }
+ if (ilen <= 0)
+ return;
+ ktabp = D_ESCseen ? D_ESCseen : ktab;
+ if (D_ESCseen)
+ {
+ D_ESCseen = 0;
+ WindowChanged(fore, 'E');
+ }
+ ch = (unsigned char)*s;
+
+ /*
+ * As users have different esc characters, but a common ktab[],
+ * we fold back the users esc and meta-esc key to the Default keys
+ * that can be looked up in the ktab[]. grmbl. jw.
+ * XXX: make ktab[] a per user thing.
+ */
+ if (ch == D_user->u_Esc)
+ ch = DefaultEsc;
+ else if (ch == D_user->u_MetaEsc)
+ ch = DefaultMetaEsc;
+
+ if (ch >= 0)
+ DoAction(&ktabp[ch], ch);
+ ibuf = (char *)(s + 1);
+ ilen--;
+ }
+}
+
+void
+DoProcess(p, bufp, lenp, pa)
+struct win *p;
+char **bufp;
+int *lenp;
+struct paster *pa;
+{
+ int oldlen;
+ struct display *d = display;
+
+#ifdef COPY_PASTE
+ /* XXX -> PasteStart */
+ if (pa && *lenp > 1 && p && p->w_slowpaste)
+ {
+ /* schedule slowpaste event */
+ SetTimeout(&p->w_paster.pa_slowev, p->w_slowpaste);
+ evenq(&p->w_paster.pa_slowev);
+ return;
+ }
+#endif
+ while (flayer && *lenp)
+ {
+#ifdef COPY_PASTE
+ if (!pa && p && p->w_paster.pa_pastelen && flayer == p->w_paster.pa_pastelayer)
+ {
+ debug("layer is busy - beep!\n");
+ WBell(p, visual_bell);
+ *bufp += *lenp;
+ *lenp = 0;
+ display = d;
+ return;
+ }
+#endif
+ oldlen = *lenp;
+ LayProcess(bufp, lenp);
+#ifdef COPY_PASTE
+ if (pa && !pa->pa_pastelayer)
+ break; /* flush rest of paste */
+#endif
+ if (*lenp == oldlen)
+ {
+ if (pa)
+ {
+ display = d;
+ return;
+ }
+ /* We're full, let's beep */
+ debug("layer is full - beep!\n");
+ WBell(p, visual_bell);
+ break;
+ }
+ }
+ *bufp += *lenp;
+ *lenp = 0;
+ display = d;
+#ifdef COPY_PASTE
+ if (pa && pa->pa_pastelen == 0)
+ FreePaster(pa);
+#endif
+}
+
+int
+FindCommnr(str)
+const char *str;
+{
+ int x, m, l = 0, r = RC_LAST;
+ while (l <= r)
+ {
+ m = (l + r) / 2;
+ x = strcmp(str, comms[m].name);
+ if (x > 0)
+ l = m + 1;
+ else if (x < 0)
+ r = m - 1;
+ else
+ return m;
+ }
+ return RC_ILLEGAL;
+}
+
+static int
+CheckArgNum(nr, args)
+int nr;
+char **args;
+{
+ int i, n;
+ static char *argss[] = {"no", "one", "two", "three", "four", "OOPS"};
+ static char *orformat[] =
+ {
+ "%s: %s: %s argument%s required",
+ "%s: %s: %s or %s argument%s required",
+ "%s: %s: %s, %s or %s argument%s required",
+ "%s: %s: %s, %s, %s or %s argument%s required"
+ };
+
+ n = comms[nr].flags & ARGS_MASK;
+ for (i = 0; args[i]; i++)
+ ;
+ if (comms[nr].flags & ARGS_ORMORE)
+ {
+ if (i < n)
+ {
+ Msg(0, "%s: %s: at least %s argument%s required",
+ rc_name, comms[nr].name, argss[n], n != 1 ? "s" : "");
+ return -1;
+ }
+ }
+ else if ((comms[nr].flags & ARGS_PLUS1) &&
+ (comms[nr].flags & ARGS_PLUS2) &&
+ (comms[nr].flags & ARGS_PLUS3))
+ {
+ if (i != n && i != n + 1 && i != n + 2 && i != n + 3)
+ {
+ Msg(0, orformat[3], rc_name, comms[nr].name, argss[n],
+ argss[n + 1], argss[n + 2], argss[n + 3], "");
+ return -1;
+ }
+ }
+ else if ((comms[nr].flags & ARGS_PLUS1) &&
+ (comms[nr].flags & ARGS_PLUS2))
+ {
+ if (i != n && i != n + 1 && i != n + 2)
+ {
+ Msg(0, orformat[2], rc_name, comms[nr].name, argss[n],
+ argss[n + 1], argss[n + 2], "");
+ return -1;
+ }
+ }
+ else if ((comms[nr].flags & ARGS_PLUS1) &&
+ (comms[nr].flags & ARGS_PLUS3))
+ {
+ if (i != n && i != n + 1 && i != n + 3)
+ {
+ Msg(0, orformat[2], rc_name, comms[nr].name, argss[n],
+ argss[n + 1], argss[n + 3], "");
+ return -1;
+ }
+ }
+ else if ((comms[nr].flags & ARGS_PLUS2) &&
+ (comms[nr].flags & ARGS_PLUS3))
+ {
+ if (i != n && i != n + 2 && i != n + 3)
+ {
+ Msg(0, orformat[2], rc_name, comms[nr].name, argss[n],
+ argss[n + 2], argss[n + 3], "");
+ return -1;
+ }
+ }
+ else if (comms[nr].flags & ARGS_PLUS1)
+ {
+ if (i != n && i != n + 1)
+ {
+ Msg(0, orformat[1], rc_name, comms[nr].name, argss[n],
+ argss[n + 1], n != 0 ? "s" : "");
+ return -1;
+ }
+ }
+ else if (comms[nr].flags & ARGS_PLUS2)
+ {
+ if (i != n && i != n + 2)
+ {
+ Msg(0, orformat[1], rc_name, comms[nr].name, argss[n],
+ argss[n + 2], "s");
+ return -1;
+ }
+ }
+ else if (comms[nr].flags & ARGS_PLUS3)
+ {
+ if (i != n && i != n + 3)
+ {
+ Msg(0, orformat[1], rc_name, comms[nr].name, argss[n],
+ argss[n + 3], "");
+ return -1;
+ }
+ }
+ else if (i != n)
+ {
+ Msg(0, orformat[0], rc_name, comms[nr].name, argss[n], n != 1 ? "s" : "");
+ return -1;
+ }
+ return i;
+}
+
+static void
+StuffFin(buf, len, data)
+char *buf;
+int len;
+char *data;
+{
+ if (!flayer)
+ return;
+ while(len)
+ LayProcess(&buf, &len);
+}
+
+/* If the command is not 'quieted', then use Msg to output the message. If it's a remote
+ * query, then Msg takes care of also outputting the message to the querying client.
+ *
+ * If we want the command to be quiet, and it's a remote query, then use QueryMsg so that
+ * the response does go back to the querying client.
+ *
+ * If the command is quieted, and it's not a remote query, then just don't print the message.
+ */
+#define OutputMsg (!act->quiet ? Msg : queryflag >= 0 ? QueryMsg : Dummy)
+
+/*ARGSUSED*/
+void
+DoAction(act, key)
+struct action *act;
+int key;
+{
+ int nr = act->nr;
+ char **args = act->args;
+ int *argl = act->argl;
+ struct win *p;
+ int argc, i, n, msgok;
+ char *s;
+ char ch;
+ struct display *odisplay = display;
+ struct acluser *user;
+
+ user = display ? D_user : users;
+ if (nr == RC_ILLEGAL)
+ {
+ debug1("key '%c': No action\n", key);
+ return;
+ }
+ n = comms[nr].flags;
+ /* Commands will have a CAN_QUERY flag, depending on whether they have
+ * something to return on a query. For example, 'windows' can return a result,
+ * but 'other' cannot.
+ * If some command causes an error, then it should reset queryflag to -1, so that
+ * the process requesting the query can be notified that an error happened.
+ */
+ if (!(n & CAN_QUERY) && queryflag >= 0)
+ {
+ /* Query flag is set, but this command cannot be queried. */
+ OutputMsg(0, "%s command cannot be queried.", comms[nr].name);
+ queryflag = -1;
+ return;
+ }
+ if ((n & NEED_DISPLAY) && display == 0)
+ {
+ OutputMsg(0, "%s: %s: display required", rc_name, comms[nr].name);
+ queryflag = -1;
+ return;
+ }
+ if ((n & NEED_FORE) && fore == 0)
+ {
+ OutputMsg(0, "%s: %s: window required", rc_name, comms[nr].name);
+ queryflag = -1;
+ return;
+ }
+ if ((n & NEED_LAYER) && flayer == 0)
+ {
+ OutputMsg(0, "%s: %s: display or window required", rc_name, comms[nr].name);
+ queryflag = -1;
+ return;
+ }
+ if ((argc = CheckArgNum(nr, args)) < 0)
+ return;
+#ifdef MULTIUSER
+ if (display)
+ {
+ if (AclCheckPermCmd(D_user, ACL_EXEC, &comms[nr]))
+ {
+ OutputMsg(0, "%s: %s: permission denied (user %s)",
+ rc_name, comms[nr].name, (EffectiveAclUser ? EffectiveAclUser : D_user)->u_name);
+ queryflag = -1;
+ return;
+ }
+ }
+#endif /* MULTIUSER */
+
+ msgok = display && !*rc_name;
+ switch(nr)
+ {
+ case RC_SELECT:
+ if (!*args)
+ InputSelect();
+ else if (args[0][0] == '-' && !args[0][1])
+ {
+ SetForeWindow((struct win *)0);
+ Activate(0);
+ }
+ else if (args[0][0] == '.' && !args[0][1])
+ {
+ if (!fore)
+ {
+ OutputMsg(0, "select . needs a window");
+ queryflag = -1;
+ }
+ else
+ {
+ SetForeWindow(fore);
+ Activate(0);
+ }
+ }
+ else if (ParseWinNum(act, &n) == 0)
+ SwitchWindow(n);
+ else if (queryflag >= 0)
+ queryflag = -1; /* ParseWinNum already prints out an appropriate error message. */
+ break;
+#ifdef AUTO_NUKE
+ case RC_DEFAUTONUKE:
+ if (ParseOnOff(act, &defautonuke) == 0 && msgok)
+ OutputMsg(0, "Default autonuke turned %s", defautonuke ? "on" : "off");
+ if (display && *rc_name)
+ D_auto_nuke = defautonuke;
+ break;
+ case RC_AUTONUKE:
+ if (ParseOnOff(act, &D_auto_nuke) == 0 && msgok)
+ OutputMsg(0, "Autonuke turned %s", D_auto_nuke ? "on" : "off");
+ break;
+#endif
+ case RC_DEFOBUFLIMIT:
+ if (ParseNum(act, &defobuflimit) == 0 && msgok)
+ OutputMsg(0, "Default limit set to %d", defobuflimit);
+ if (display && *rc_name)
+ {
+ D_obufmax = defobuflimit;
+ D_obuflenmax = D_obuflen - D_obufmax;
+ }
+ break;
+ case RC_OBUFLIMIT:
+ if (*args == 0)
+ OutputMsg(0, "Limit is %d, current buffer size is %d", D_obufmax, D_obuflen);
+ else if (ParseNum(act, &D_obufmax) == 0 && msgok)
+ OutputMsg(0, "Limit set to %d", D_obufmax);
+ D_obuflenmax = D_obuflen - D_obufmax;
+ break;
+ case RC_DUMPTERMCAP:
+ WriteFile(user, (char *)0, DUMP_TERMCAP);
+ break;
+ case RC_HARDCOPY:
+ {
+ int mode = DUMP_HARDCOPY;
+ char *file = NULL;
+
+ if (args[0])
+ {
+ if (!strcmp(*args, "-h"))
+ {
+ mode = DUMP_SCROLLBACK;
+ file = args[1];
+ }
+ else if (!strcmp(*args, "--") && args[1])
+ file = args[1];
+ else
+ file = args[0];
+ }
+
+ if (args[0] && file == args[0] && args[1])
+ {
+ OutputMsg(0, "%s: hardcopy: too many arguments", rc_name);
+ break;
+ }
+ WriteFile(user, file, mode);
+ }
+ break;
+ case RC_DEFLOG:
+ (void)ParseOnOff(act, &nwin_default.Lflag);
+ break;
+ case RC_LOG:
+ n = fore->w_log ? 1 : 0;
+ ParseSwitch(act, &n);
+ LogToggle(n);
+ break;
+#ifdef BSDJOBS
+ case RC_SUSPEND:
+ Detach(D_STOP);
+ break;
+#endif
+ case RC_NEXT:
+ if (MoreWindows())
+ SwitchWindow(NextWindow());
+ break;
+ case RC_PREV:
+ if (MoreWindows())
+ SwitchWindow(PreviousWindow());
+ break;
+ case RC_KILL:
+ {
+ char *name;
+
+ if (key >= 0)
+ {
+#ifdef PSEUDOS
+ Input(fore->w_pwin ? "Really kill this filter [y/n]" : "Really kill this window [y/n]", 1, INP_RAW, confirm_fn, NULL, RC_KILL);
+#else
+ Input("Really kill this window [y/n]", 1, INP_RAW, confirm_fn, NULL, RC_KILL);
+#endif
+ break;
+ }
+ n = fore->w_number;
+#ifdef PSEUDOS
+ if (fore->w_pwin)
+ {
+ FreePseudowin(fore);
+ OutputMsg(0, "Filter removed.");
+ break;
+ }
+#endif
+ name = SaveStr(fore->w_title);
+ KillWindow(fore);
+ OutputMsg(0, "Window %d (%s) killed.", n, name);
+ if (name)
+ free(name);
+ break;
+ }
+ case RC_QUIT:
+ if (key >= 0)
+ {
+ Input("Really quit and kill all your windows [y/n]", 1, INP_RAW, confirm_fn, NULL, RC_QUIT);
+ break;
+ }
+ Finit(0);
+ /* NOTREACHED */
+#ifdef DETACH
+ case RC_DETACH:
+ if (*args && !strcmp(*args, "-h"))
+ Hangup();
+ else
+ Detach(D_DETACH);
+ break;
+# ifdef POW_DETACH
+ case RC_POW_DETACH:
+ if (key >= 0)
+ {
+ static char buf[2];
+
+ buf[0] = key;
+ Input(buf, 1, INP_RAW, pow_detach_fn, NULL, 0);
+ }
+ else
+ Detach(D_POWER); /* detach and kill Attacher's parent */
+ break;
+# endif
+#endif
+ case RC_DEBUG:
+#ifdef DEBUG
+ if (!*args)
+ {
+ if (dfp)
+ OutputMsg(0, "debugging info is written to %s/", DEBUGDIR);
+ else
+ OutputMsg(0, "debugging is currently off. Use 'debug on' to enable.");
+ break;
+ }
+ if (dfp)
+ {
+ debug("debug: closing debug file.\n");
+ fflush(dfp);
+ fclose(dfp);
+ dfp = NULL;
+ }
+ if (strcmp("off", *args))
+ opendebug(0, 1);
+# ifdef SIG_NODEBUG
+ else if (display)
+ kill(D_userpid, SIG_NODEBUG); /* a one shot item, but hey... */
+# endif /* SIG_NODEBUG */
+#else
+ if (*args == 0 || strcmp("off", *args))
+ OutputMsg(0, "Sorry, screen was compiled without -DDEBUG option.");
+#endif
+ break;
+#ifdef ZMODEM
+ case RC_ZMODEM:
+ if (*args && !strcmp(*args, "sendcmd"))
+ {
+ if (args[1])
+ {
+ free(zmodem_sendcmd);
+ zmodem_sendcmd = SaveStr(args[1]);
+ }
+ if (msgok)
+ OutputMsg(0, "zmodem sendcmd: %s", zmodem_sendcmd);
+ break;
+ }
+ if (*args && !strcmp(*args, "recvcmd"))
+ {
+ if (args[1])
+ {
+ free(zmodem_recvcmd);
+ zmodem_recvcmd = SaveStr(args[1]);
+ }
+ if (msgok)
+ OutputMsg(0, "zmodem recvcmd: %s", zmodem_recvcmd);
+ break;
+ }
+ if (*args)
+ {
+ for (i = 0; i < 4; i++)
+ if (!strcmp(zmodes[i], *args))
+ break;
+ if (i == 4 && !strcmp(*args, "on"))
+ i = 1;
+ if (i == 4)
+ {
+ OutputMsg(0, "usage: zmodem off|auto|catch|pass");
+ break;
+ }
+ zmodem_mode = i;
+ }
+ if (msgok)
+ OutputMsg(0, "zmodem mode is %s", zmodes[zmodem_mode]);
+ break;
+#endif
+ case RC_UNBINDALL:
+ {
+ register unsigned int i;
+
+ for (i = 0; i < sizeof(ktab)/sizeof(*ktab); i++)
+ ClearAction(&ktab[i]);
+ OutputMsg(0, "Unbound all keys." );
+ break;
+ }
+ case RC_ZOMBIE:
+ {
+ if (!(s = *args))
+ {
+ ZombieKey_destroy = 0;
+ break;
+ }
+ if (*argl == 0 || *argl > 2)
+ {
+ OutputMsg(0, "%s:zombie: one or two characters expected.", rc_name);
+ break;
+ }
+ if (args[1])
+ {
+ if (!strcmp(args[1], "onerror"))
+ {
+ ZombieKey_onerror = 1;
+ } else {
+ OutputMsg(0, "usage: zombie [keys [onerror]]");
+ break;
+ }
+ } else
+ ZombieKey_onerror = 0;
+ ZombieKey_destroy = args[0][0];
+ ZombieKey_resurrect = *argl == 2 ? args[0][1] : 0;
+ }
+ break;
+ case RC_WALL:
+#ifdef MULTIUSER
+ s = D_user->u_name;
+#else
+ s = D_usertty;
+#endif
+ {
+ struct display *olddisplay = display;
+ display = 0; /* no display will cause a broadcast */
+ OutputMsg(0, "%s: %s", s, *args);
+ display = olddisplay;
+ }
+ break;
+ case RC_AT:
+ /* where this AT command comes from: */
+ if (!user)
+ break;
+#ifdef MULTIUSER
+ s = SaveStr(user->u_name);
+ /* DO NOT RETURN FROM HERE WITHOUT RESETTING THIS: */
+ EffectiveAclUser = user;
+#else
+ s = SaveStr(display ? D_usertty : user->u_name);
+#endif
+ n = strlen(args[0]);
+ if (n) n--;
+ /*
+ * the windows/displays loops are quite dangerous here, take extra
+ * care not to trigger landmines. Things may appear/disappear while
+ * we are walking along.
+ */
+ switch (args[0][n])
+ {
+ case '*': /* user */
+ {
+ struct display *nd;
+ struct acluser *u;
+
+ if (!n)
+ u = user;
+ else
+ {
+ for (u = users; u; u = u->u_next)
+ {
+ debug3("strncmp('%s', '%s', %d)\n", *args, u->u_name, n);
+ if (!strncmp(*args, u->u_name, n))
+ break;
+ }
+ if (!u)
+ {
+ args[0][n] = '\0';
+ OutputMsg(0, "Did not find any user matching '%s'", args[0]);
+ break;
+ }
+ }
+ debug1("at all displays of user %s\n", u->u_name);
+ for (display = displays; display; display = nd)
+ {
+ nd = display->d_next;
+ if (D_forecv == 0)
+ continue;
+ flayer = D_forecv->c_layer;
+ fore = D_fore;
+ if (D_user != u)
+ continue;
+ debug1("AT display %s\n", D_usertty);
+ DoCommand(args + 1, argl + 1);
+ if (display)
+ OutputMsg(0, "command from %s: %s %s",
+ s, args[1], args[2] ? args[2] : "");
+ display = NULL;
+ flayer = 0;
+ fore = NULL;
+ }
+ break;
+ }
+ case '%': /* display */
+ {
+ struct display *nd;
+
+ debug1("at display matching '%s'\n", args[0]);
+ for (display = displays; display; display = nd)
+ {
+ nd = display->d_next;
+ if (D_forecv == 0)
+ continue;
+ fore = D_fore;
+ flayer = D_forecv->c_layer;
+ if (strncmp(args[0], D_usertty, n) &&
+ (strncmp("/dev/", D_usertty, 5) ||
+ strncmp(args[0], D_usertty + 5, n)) &&
+ (strncmp("/dev/tty", D_usertty, 8) ||
+ strncmp(args[0], D_usertty + 8, n)))
+ continue;
+ debug1("AT display %s\n", D_usertty);
+ DoCommand(args + 1, argl + 1);
+ if (display)
+ OutputMsg(0, "command from %s: %s %s",
+ s, args[1], args[2] ? args[2] : "");
+ display = NULL;
+ fore = NULL;
+ flayer = 0;
+ }
+ break;
+ }
+ case '#': /* window */
+ n--;
+ /* FALLTHROUGH */
+ default:
+ {
+ struct win *nw;
+ int ch;
+
+ n++;
+ ch = args[0][n];
+ args[0][n] = '\0';
+ if (!*args[0] || (i = WindowByNumber(args[0])) < 0)
+ {
+ args[0][n] = ch; /* must restore string in case of bind */
+ /* try looping over titles */
+ for (fore = windows; fore; fore = nw)
+ {
+ nw = fore->w_next;
+ if (strncmp(args[0], fore->w_title, n))
+ continue;
+ debug2("AT window %d(%s)\n", fore->w_number, fore->w_title);
+ /*
+ * consider this a bug or a feature:
+ * while looping through windows, we have fore AND
+ * display context. This will confuse users who try to
+ * set up loops inside of loops, but often allows to do
+ * what you mean, even when you adress your context wrong.
+ */
+ i = 0;
+ /* XXX: other displays? */
+ if (fore->w_layer.l_cvlist)
+ display = fore->w_layer.l_cvlist->c_display;
+ flayer = fore->w_savelayer ? fore->w_savelayer : &fore->w_layer;
+ DoCommand(args + 1, argl + 1); /* may destroy our display */
+ if (fore && fore->w_layer.l_cvlist)
+ {
+ display = fore->w_layer.l_cvlist->c_display;
+ OutputMsg(0, "command from %s: %s %s",
+ s, args[1], args[2] ? args[2] : "");
+ }
+ }
+ display = NULL;
+ fore = NULL;
+ if (i < 0)
+ OutputMsg(0, "%s: at '%s': no such window.\n", rc_name, args[0]);
+ break;
+ }
+ else if (i < maxwin && (fore = wtab[i]))
+ {
+ args[0][n] = ch; /* must restore string in case of bind */
+ debug2("AT window %d (%s)\n", fore->w_number, fore->w_title);
+ if (fore->w_layer.l_cvlist)
+ display = fore->w_layer.l_cvlist->c_display;
+ flayer = fore->w_savelayer ? fore->w_savelayer : &fore->w_layer;
+ DoCommand(args + 1, argl + 1);
+ if (fore && fore->w_layer.l_cvlist)
+ {
+ display = fore->w_layer.l_cvlist->c_display;
+ OutputMsg(0, "command from %s: %s %s",
+ s, args[1], args[2] ? args[2] : "");
+ }
+ display = NULL;
+ fore = NULL;
+ }
+ else
+ OutputMsg(0, "%s: at [identifier][%%|*|#] command [args]", rc_name);
+ break;
+ }
+ }
+ free(s);
+#ifdef MULTIUSER
+ EffectiveAclUser = NULL;
+#endif
+ break;
+
+#ifdef COPY_PASTE
+ case RC_READREG:
+#ifdef ENCODINGS
+ i = fore ? fore->w_encoding : display ? display->d_encoding : 0;
+ if (args[0] && args[1] && !strcmp(args[0], "-e"))
+ {
+ i = FindEncoding(args[1]);
+ if (i == -1)
+ {
+ OutputMsg(0, "%s: readreg: unknown encoding", rc_name);
+ break;
+ }
+ args += 2;
+ }
+#endif
+ /*
+ * Without arguments we prompt for a destination register.
+ * It will receive the copybuffer contents.
+ * This is not done by RC_PASTE, as we prompt for source
+ * (not dest) there.
+ */
+ if ((s = *args) == NULL)
+ {
+ Input("Copy to register:", 1, INP_RAW, copy_reg_fn, NULL, 0);
+ break;
+ }
+ if (*argl != 1)
+ {
+ OutputMsg(0, "%s: copyreg: character, ^x, or (octal) \\032 expected.", rc_name);
+ break;
+ }
+ ch = args[0][0];
+ /*
+ * With two arguments we *really* read register contents from file
+ */
+ if (args[1])
+ {
+ if (args[2])
+ {
+ OutputMsg(0, "%s: readreg: too many arguments", rc_name);
+ break;
+ }
+ if ((s = ReadFile(args[1], &n)))
+ {
+ struct plop *pp = plop_tab + (int)(unsigned char)ch;
+
+ if (pp->buf)
+ free(pp->buf);
+ pp->buf = s;
+ pp->len = n;
+#ifdef ENCODINGS
+ pp->enc = i;
+#endif
+ }
+ }
+ else
+ /*
+ * with one argument we copy the copybuffer into a specified register
+ * This could be done with RC_PASTE too, but is here to be consistent
+ * with the zero argument call.
+ */
+ copy_reg_fn(&ch, 0, NULL);
+ break;
+#endif
+ case RC_REGISTER:
+#ifdef ENCODINGS
+ i = fore ? fore->w_encoding : display ? display->d_encoding : 0;
+ if (args[0] && args[1] && !strcmp(args[0], "-e"))
+ {
+ i = FindEncoding(args[1]);
+ if (i == -1)
+ {
+ OutputMsg(0, "%s: register: unknown encoding", rc_name);
+ break;
+ }
+ args += 2;
+ argc -= 2;
+ }
+#endif
+ if (argc != 2)
+ {
+ OutputMsg(0, "%s: register: illegal number of arguments.", rc_name);
+ break;
+ }
+ if (*argl != 1)
+ {
+ OutputMsg(0, "%s: register: character, ^x, or (octal) \\032 expected.", rc_name);
+ break;
+ }
+ ch = args[0][0];
+#ifdef COPY_PASTE
+ if (ch == '.')
+ {
+ if (user->u_plop.buf != NULL)
+ UserFreeCopyBuffer(user);
+ if (args[1] && args[1][0])
+ {
+ user->u_plop.buf = SaveStrn(args[1], argl[1]);
+ user->u_plop.len = argl[1];
+#ifdef ENCODINGS
+ user->u_plop.enc = i;
+#endif
+ }
+ }
+ else
+#endif
+ {
+ struct plop *plp = plop_tab + (int)(unsigned char)ch;
+
+ if (plp->buf)
+ free(plp->buf);
+ plp->buf = SaveStrn(args[1], argl[1]);
+ plp->len = argl[1];
+#ifdef ENCODINGS
+ plp->enc = i;
+#endif
+ }
+ break;
+ case RC_PROCESS:
+ if ((s = *args) == NULL)
+ {
+ Input("Process register:", 1, INP_RAW, process_fn, NULL, 0);
+ break;
+ }
+ if (*argl != 1)
+ {
+ OutputMsg(0, "%s: process: character, ^x, or (octal) \\032 expected.", rc_name);
+ break;
+ }
+ ch = args[0][0];
+ process_fn(&ch, 0, NULL);
+ break;
+ case RC_STUFF:
+ s = *args;
+ if (!args[0])
+ {
+ Input("Stuff:", 100, INP_COOKED, StuffFin, NULL, 0);
+ break;
+ }
+ n = *argl;
+ if (args[1])
+ {
+ if (strcmp(s, "-k"))
+ {
+ OutputMsg(0, "%s: stuff: invalid option %s", rc_name, s);
+ break;
+ }
+ s = args[1];
+ for (i = T_CAPS; i < T_OCAPS; i++)
+ if (strcmp(term[i].tcname, s) == 0)
+ break;
+ if (i == T_OCAPS)
+ {
+ OutputMsg(0, "%s: stuff: unknown key '%s'", rc_name, s);
+ break;
+ }
+#ifdef MAPKEYS
+ if (StuffKey(i - T_CAPS) == 0)
+ break;
+#endif
+ s = display ? D_tcs[i].str : 0;
+ if (s == 0)
+ break;
+ n = strlen(s);
+ }
+ while(n)
+ LayProcess(&s, &n);
+ break;
+ case RC_REDISPLAY:
+ Activate(-1);
+ break;
+ case RC_WINDOWS:
+ if (args[0]) {
+ ShowWindowsX(args[0]);
+ break;
+ }
+ ShowWindows(-1);
+ break;
+ case RC_VERSION:
+ OutputMsg(0, "screen %s", version);
+ break;
+ case RC_TIME:
+ if (*args)
+ {
+ timestring = SaveStr(*args);
+ break;
+ }
+ OutputMsg(0, "%s", MakeWinMsg(timestring, fore, '%'));
+ break;
+ case RC_INFO:
+ ShowInfo();
+ break;
+ case RC_DINFO:
+ ShowDInfo();
+ break;
+ case RC_COMMAND:
+ {
+ struct action *ktabp = ktab;
+ if (argc == 2 && !strcmp(*args, "-c"))
+ {
+ if ((ktabp = FindKtab(args[1], 0)) == 0)
+ {
+ OutputMsg(0, "Unknown command class '%s'", args[1]);
+ break;
+ }
+ }
+ if (D_ESCseen != ktab || ktabp != ktab)
+ {
+ if (D_ESCseen != ktabp)
+ {
+ D_ESCseen = ktabp;
+ WindowChanged(fore, 'E');
+ }
+ break;
+ }
+ if (D_ESCseen)
+ {
+ D_ESCseen = 0;
+ WindowChanged(fore, 'E');
+ }
+ }
+ /* FALLTHROUGH */
+ case RC_OTHER:
+ if (MoreWindows())
+ SwitchWindow(display && D_other ? D_other->w_number : NextWindow());
+ break;
+ case RC_META:
+ if (user->u_Esc == -1)
+ break;
+ ch = user->u_Esc;
+ s = &ch;
+ n = 1;
+ LayProcess(&s, &n);
+ break;
+ case RC_XON:
+ ch = Ctrl('q');
+ s = &ch;
+ n = 1;
+ LayProcess(&s, &n);
+ break;
+ case RC_XOFF:
+ ch = Ctrl('s');
+ s = &ch;
+ n = 1;
+ LayProcess(&s, &n);
+ break;
+ case RC_DEFBREAKTYPE:
+ case RC_BREAKTYPE:
+ {
+ static char *types[] = { "TIOCSBRK", "TCSBRK", "tcsendbreak", NULL };
+ extern int breaktype;
+
+ if (*args)
+ {
+ if (ParseNum(act, &n))
+ for (n = 0; n < (int)(sizeof(types)/sizeof(*types)); n++)
+ {
+ for (i = 0; i < 4; i++)
+ {
+ ch = args[0][i];
+ if (ch >= 'a' && ch <= 'z')
+ ch -= 'a' - 'A';
+ if (ch != types[n][i] && (ch + ('a' - 'A')) != types[n][i])
+ break;
+ }
+ if (i == 4)
+ break;
+ }
+ if (n < 0 || n >= (int)(sizeof(types)/sizeof(*types)))
+ OutputMsg(0, "%s invalid, chose one of %s, %s or %s", *args, types[0], types[1], types[2]);
+ else
+ {
+ breaktype = n;
+ OutputMsg(0, "breaktype set to (%d) %s", n, types[n]);
+ }
+ }
+ else
+ OutputMsg(0, "breaktype is (%d) %s", breaktype, types[breaktype]);
+ }
+ break;
+ case RC_POW_BREAK:
+ case RC_BREAK:
+ n = 0;
+ if (*args && ParseNum(act, &n))
+ break;
+ SendBreak(fore, n, nr == RC_POW_BREAK);
+ break;
+#ifdef LOCK
+ case RC_LOCKSCREEN:
+ Detach(D_LOCK);
+ break;
+#endif
+ case RC_WIDTH:
+ case RC_HEIGHT:
+ {
+ int w, h;
+ int what = 0;
+
+ i = 1;
+ if (*args && !strcmp(*args, "-w"))
+ what = 1;
+ else if (*args && !strcmp(*args, "-d"))
+ what = 2;
+ if (what)
+ args++;
+ if (what == 0 && flayer && !display)
+ what = 1;
+ if (what == 1)
+ {
+ if (!flayer)
+ {
+ OutputMsg(0, "%s: %s: window required", rc_name, comms[nr].name);
+ break;
+ }
+ w = flayer->l_width;
+ h = flayer->l_height;
+ }
+ else
+ {
+ if (!display)
+ {
+ OutputMsg(0, "%s: %s: display required", rc_name, comms[nr].name);
+ break;
+ }
+ w = D_width;
+ h = D_height;
+ }
+ if (*args && args[0][0] == '-')
+ {
+ OutputMsg(0, "%s: %s: unknown option %s", rc_name, comms[nr].name, *args);
+ break;
+ }
+ if (nr == RC_HEIGHT)
+ {
+ if (!*args)
+ {
+#define H0height 42
+#define H1height 24
+ if (h == H0height)
+ h = H1height;
+ else if (h == H1height)
+ h = H0height;
+ else if (h > (H0height + H1height) / 2)
+ h = H0height;
+ else
+ h = H1height;
+ }
+ else
+ {
+ h = atoi(*args);
+ if (args[1])
+ w = atoi(args[1]);
+ }
+ }
+ else
+ {
+ if (!*args)
+ {
+ if (w == Z0width)
+ w = Z1width;
+ else if (w == Z1width)
+ w = Z0width;
+ else if (w > (Z0width + Z1width) / 2)
+ w = Z0width;
+ else
+ w = Z1width;
+ }
+ else
+ {
+ w = atoi(*args);
+ if (args[1])
+ h = atoi(args[1]);
+ }
+ }
+ if (*args && args[1] && args[2])
+ {
+ OutputMsg(0, "%s: %s: too many arguments", rc_name, comms[nr].name);
+ break;
+ }
+ if (w <= 0)
+ {
+ OutputMsg(0, "Illegal width");
+ break;
+ }
+ if (h <= 0)
+ {
+ OutputMsg(0, "Illegal height");
+ break;
+ }
+ if (what == 1)
+ {
+ if (flayer->l_width == w && flayer->l_height == h)
+ break;
+ ResizeLayer(flayer, w, h, (struct display *)0);
+ break;
+ }
+ if (D_width == w && D_height == h)
+ break;
+ if (what == 2)
+ {
+ ChangeScreenSize(w, h, 1);
+ }
+ else
+ {
+ if (ResizeDisplay(w, h) == 0)
+ {
+ Activate(D_fore ? D_fore->w_norefresh : 0);
+ /* autofit */
+ ResizeLayer(D_forecv->c_layer, D_forecv->c_xe - D_forecv->c_xs + 1, D_forecv->c_ye - D_forecv->c_ys + 1, 0);
+ break;
+ }
+ if (h == D_height)
+ OutputMsg(0, "Your termcap does not specify how to change the terminal's width to %d.", w);
+ else if (w == D_width)
+ OutputMsg(0, "Your termcap does not specify how to change the terminal's height to %d.", h);
+ else
+ OutputMsg(0, "Your termcap does not specify how to change the terminal's resolution to %dx%d.", w, h);
+ }
+ }
+ break;
+ case RC_DEFDYNAMICTITLE:
+ (void)ParseOnOff(act, &nwin_default.dynamicaka);
+ break;
+ case RC_DYNAMICTITLE:
+ (void)ParseOnOff(act, &fore->w_dynamicaka);
+ break;
+ case RC_TITLE:
+ if (queryflag >= 0)
+ {
+ if (fore)
+ OutputMsg(0, "%s", fore->w_title);
+ else
+ queryflag = -1;
+ break;
+ }
+ if (*args == 0)
+ InputAKA();
+ else
+ ChangeAKA(fore, *args, strlen(*args));
+ break;
+ case RC_COLON:
+ Input(":", MAXSTR, INP_EVERY, Colonfin, NULL, 0);
+ if (*args && **args)
+ {
+ s = *args;
+ n = strlen(s);
+ LayProcess(&s, &n);
+ }
+ break;
+ case RC_LASTMSG:
+ if (D_status_lastmsg)
+ OutputMsg(0, "%s", D_status_lastmsg);
+ break;
+ case RC_SCREEN:
+ DoScreen("key", args);
+ break;
+ case RC_WRAP:
+ if (ParseSwitch(act, &fore->w_wrap) == 0 && msgok)
+ OutputMsg(0, "%cwrap", fore->w_wrap ? '+' : '-');
+ break;
+ case RC_FLOW:
+ if (*args)
+ {
+ if (args[0][0] == 'a')
+ {
+ fore->w_flow = (fore->w_flow & FLOW_AUTO) ? FLOW_AUTOFLAG |FLOW_AUTO|FLOW_NOW : FLOW_AUTOFLAG;
+ }
+ else
+ {
+ if (ParseOnOff(act, &n))
+ break;
+ fore->w_flow = (fore->w_flow & FLOW_AUTO) | n;
+ }
+ }
+ else
+ {
+ if (fore->w_flow & FLOW_AUTOFLAG)
+ fore->w_flow = (fore->w_flow & FLOW_AUTO) | FLOW_NOW;
+ else if (fore->w_flow & FLOW_NOW)
+ fore->w_flow &= ~FLOW_NOW;
+ else
+ fore->w_flow = fore->w_flow ? FLOW_AUTOFLAG|FLOW_AUTO|FLOW_NOW : FLOW_AUTOFLAG;
+ }
+ SetFlow(fore->w_flow & FLOW_NOW);
+ if (msgok)
+ OutputMsg(0, "%cflow%s", (fore->w_flow & FLOW_NOW) ? '+' : '-',
+ (fore->w_flow & FLOW_AUTOFLAG) ? "(auto)" : "");
+ break;
+#ifdef MULTIUSER
+ case RC_DEFWRITELOCK:
+ if (args[0][0] == 'a')
+ nwin_default.wlock = WLOCK_AUTO;
+ else
+ {
+ if (ParseOnOff(act, &n))
+ break;
+ nwin_default.wlock = n ? WLOCK_ON : WLOCK_OFF;
+ }
+ break;
+ case RC_WRITELOCK:
+ if (*args)
+ {
+ if (args[0][0] == 'a')
+ {
+ fore->w_wlock = WLOCK_AUTO;
+ }
+ else
+ {
+ if (ParseOnOff(act, &n))
+ break;
+ fore->w_wlock = n ? WLOCK_ON : WLOCK_OFF;
+ }
+ /*
+ * user may have permission to change the writelock setting,
+ * but he may never aquire the lock himself without write permission
+ */
+ if (!AclCheckPermWin(D_user, ACL_WRITE, fore))
+ fore->w_wlockuser = D_user;
+ }
+ OutputMsg(0, "writelock %s", (fore->w_wlock == WLOCK_AUTO) ? "auto" :
+ ((fore->w_wlock == WLOCK_OFF) ? "off" : "on"));
+ break;
+#endif
+ case RC_CLEAR:
+ ResetAnsiState(fore);
+ WriteString(fore, "\033[H\033[J", 6);
+ break;
+ case RC_RESET:
+ ResetAnsiState(fore);
+#ifdef ZMODEM
+ if (fore->w_zdisplay)
+ zmodem_abort(fore, fore->w_zdisplay);
+#endif
+ WriteString(fore, "\033c", 2);
+ break;
+ case RC_MONITOR:
+ n = fore->w_monitor != MON_OFF;
+#ifdef MULTIUSER
+ if (display)
+ n = n && (ACLBYTE(fore->w_mon_notify, D_user->u_id) & ACLBIT(D_user->u_id));
+#endif
+ if (ParseSwitch(act, &n))
+ break;
+ if (n)
+ {
+#ifdef MULTIUSER
+ if (display) /* we tell only this user */
+ ACLBYTE(fore->w_mon_notify, D_user->u_id) |= ACLBIT(D_user->u_id);
+ else
+ for (i = 0; i < maxusercount; i++)
+ ACLBYTE(fore->w_mon_notify, i) |= ACLBIT(i);
+#endif
+ if (fore->w_monitor == MON_OFF)
+ fore->w_monitor = MON_ON;
+ OutputMsg(0, "Window %d (%s) is now being monitored for all activity.", fore->w_number, fore->w_title);
+ }
+ else
+ {
+#ifdef MULTIUSER
+ if (display) /* we remove only this user */
+ ACLBYTE(fore->w_mon_notify, D_user->u_id)
+ &= ~ACLBIT(D_user->u_id);
+ else
+ for (i = 0; i < maxusercount; i++)
+ ACLBYTE(fore->w_mon_notify, i) &= ~ACLBIT(i);
+ for (i = maxusercount - 1; i >= 0; i--)
+ if (ACLBYTE(fore->w_mon_notify, i))
+ break;
+ if (i < 0)
+#endif
+ fore->w_monitor = MON_OFF;
+ OutputMsg(0, "Window %d (%s) is no longer being monitored for activity.", fore->w_number, fore->w_title);
+ }
+ break;
+#ifdef MULTI
+ case RC_DISPLAYS:
+ display_displays();
+ break;
+#endif
+ case RC_WINDOWLIST:
+ if (!*args)
+ display_windows(0, WLIST_NUM, (struct win *)0);
+ else if (!strcmp(*args, "string"))
+ {
+ if (args[1])
+ {
+ if (wliststr)
+ free(wliststr);
+ wliststr = SaveStr(args[1]);
+ }
+ if (msgok)
+ OutputMsg(0, "windowlist string is '%s'", wliststr);
+ }
+ else if (!strcmp(*args, "title"))
+ {
+ if (args[1])
+ {
+ if (wlisttit)
+ free(wlisttit);
+ wlisttit = SaveStr(args[1]);
+ }
+ if (msgok)
+ OutputMsg(0, "windowlist title is '%s'", wlisttit);
+ }
+ else
+ {
+ int flag = 0;
+ int blank = 0;
+ for (i = 0; i < argc; i++)
+ if (!args[i])
+ continue;
+ else if (!strcmp(args[i], "-m"))
+ flag |= WLIST_MRU;
+ else if (!strcmp(args[i], "-b"))
+ blank = 1;
+ else if (!strcmp(args[i], "-g"))
+ flag |= WLIST_NESTED;
+ else
+ {
+ OutputMsg(0, "usage: windowlist [-b] [-g] [-m] [string [string] | title [title]]");
+ break;
+ }
+ if (i == argc)
+ display_windows(blank, flag, (struct win *)0);
+ }
+ break;
+ case RC_HELP:
+ if (argc == 2 && !strcmp(*args, "-c"))
+ {
+ struct action *ktabp;
+ if ((ktabp = FindKtab(args[1], 0)) == 0)
+ {
+ OutputMsg(0, "Unknown command class '%s'", args[1]);
+ break;
+ }
+ display_help(args[1], ktabp);
+ }
+ else
+ display_help((char *)0, ktab);
+ break;
+ case RC_LICENSE:
+ display_copyright();
+ break;
+#ifdef COPY_PASTE
+ case RC_COPY:
+ if (flayer->l_layfn != &WinLf)
+ {
+ OutputMsg(0, "Must be on a window layer");
+ break;
+ }
+ MarkRoutine();
+ WindowChanged(fore, 'P');
+ break;
+ case RC_HISTORY:
+ {
+ static char *pasteargs[] = {".", 0};
+ static int pasteargl[] = {1};
+
+ if (flayer->l_layfn != &WinLf)
+ {
+ OutputMsg(0, "Must be on a window layer");
+ break;
+ }
+ if (GetHistory() == 0)
+ break;
+ if (user->u_plop.buf == NULL)
+ break;
+ args = pasteargs;
+ argl = pasteargl;
+ }
+ /*FALLTHROUGH*/
+ case RC_PASTE:
+ {
+ char *ss, *dbuf, dch;
+ int l = 0;
+# ifdef ENCODINGS
+ int enc = -1;
+# endif
+
+ /*
+ * without args we prompt for one(!) register to be pasted in the window
+ */
+ if ((s = *args) == NULL)
+ {
+ Input("Paste from register:", 1, INP_RAW, ins_reg_fn, NULL, 0);
+ break;
+ }
+ if (args[1] == 0 && !fore) /* no window? */
+ break;
+ /*
+ * with two arguments we paste into a destination register
+ * (no window needed here).
+ */
+ if (args[1] && argl[1] != 1)
+ {
+ OutputMsg(0, "%s: paste destination: character, ^x, or (octal) \\032 expected.",
+ rc_name);
+ break;
+ }
+# ifdef ENCODINGS
+ else if (fore)
+ enc = fore->w_encoding;
+# endif
+
+ /*
+ * measure length of needed buffer
+ */
+ for (ss = s = *args; (ch = *ss); ss++)
+ {
+ if (ch == '.')
+ {
+# ifdef ENCODINGS
+ if (enc == -1)
+ enc = user->u_plop.enc;
+ if (enc != user->u_plop.enc)
+ l += RecodeBuf((unsigned char *)user->u_plop.buf, user->u_plop.len, user->u_plop.enc, enc, (unsigned char *)0);
+ else
+# endif
+ l += user->u_plop.len;
+ }
+ else
+ {
+# ifdef ENCODINGS
+ if (enc == -1)
+ enc = plop_tab[(int)(unsigned char)ch].enc;
+ if (enc != plop_tab[(int)(unsigned char)ch].enc)
+ l += RecodeBuf((unsigned char *)plop_tab[(int)(unsigned char)ch].buf, plop_tab[(int)(unsigned char)ch].len, plop_tab[(int)(unsigned char)ch].enc, enc, (unsigned char *)0);
+ else
+# endif
+ l += plop_tab[(int)(unsigned char)ch].len;
+ }
+ }
+ if (l == 0)
+ {
+ OutputMsg(0, "empty buffer");
+ break;
+ }
+ /*
+ * shortcut:
+ * if there is only one source and the destination is a window, then
+ * pass a pointer rather than duplicating the buffer.
+ */
+ if (s[1] == 0 && args[1] == 0)
+# ifdef ENCODINGS
+ if (enc == (*s == '.' ? user->u_plop.enc : plop_tab[(int)(unsigned char)*s].enc))
+# endif
+ {
+ MakePaster(&fore->w_paster, *s == '.' ? user->u_plop.buf : plop_tab[(int)(unsigned char)*s].buf, l, 0);
+ break;
+ }
+ /*
+ * if no shortcut, we construct a buffer
+ */
+ if ((dbuf = (char *)malloc(l)) == 0)
+ {
+ OutputMsg(0, "%s", strnomem);
+ break;
+ }
+ l = 0;
+ /*
+ * concatenate all sources into our own buffer, copy buffer is
+ * special and is skipped if no display exists.
+ */
+ for (ss = s; (ch = *ss); ss++)
+ {
+ struct plop *pp = (ch == '.' ? &user->u_plop : &plop_tab[(int)(unsigned char)ch]);
+#ifdef ENCODINGS
+ if (pp->enc != enc)
+ {
+ l += RecodeBuf((unsigned char *)pp->buf, pp->len, pp->enc, enc, (unsigned char *)dbuf + l);
+ continue;
+ }
+#endif
+ bcopy(pp->buf, dbuf + l, pp->len);
+ l += pp->len;
+ }
+ /*
+ * when called with one argument we paste our buffer into the window
+ */
+ if (args[1] == 0)
+ {
+ MakePaster(&fore->w_paster, dbuf, l, 1);
+ }
+ else
+ {
+ /*
+ * we have two arguments, the second is already in dch.
+ * use this as destination rather than the window.
+ */
+ dch = args[1][0];
+ if (dch == '.')
+ {
+ if (user->u_plop.buf != NULL)
+ UserFreeCopyBuffer(user);
+ user->u_plop.buf = dbuf;
+ user->u_plop.len = l;
+#ifdef ENCODINGS
+ user->u_plop.enc = enc;
+#endif
+ }
+ else
+ {
+ struct plop *pp = plop_tab + (int)(unsigned char)dch;
+ if (pp->buf)
+ free(pp->buf);
+ pp->buf = dbuf;
+ pp->len = l;
+#ifdef ENCODINGS
+ pp->enc = enc;
+#endif
+ }
+ }
+ break;
+ }
+ case RC_WRITEBUF:
+ if (!user->u_plop.buf)
+ {
+ OutputMsg(0, "empty buffer");
+ break;
+ }
+#ifdef ENCODINGS
+ {
+ struct plop oldplop;
+
+ oldplop = user->u_plop;
+ if (args[0] && args[1] && !strcmp(args[0], "-e"))
+ {
+ int enc, l;
+ char *newbuf;
+
+ enc = FindEncoding(args[1]);
+ if (enc == -1)
+ {
+ OutputMsg(0, "%s: writebuf: unknown encoding", rc_name);
+ break;
+ }
+ if (enc != oldplop.enc)
+ {
+ l = RecodeBuf((unsigned char *)oldplop.buf, oldplop.len, oldplop.enc, enc, (unsigned char *)0);
+ newbuf = malloc(l + 1);
+ if (!newbuf)
+ {
+ OutputMsg(0, "%s", strnomem);
+ break;
+ }
+ user->u_plop.len = RecodeBuf((unsigned char *)oldplop.buf, oldplop.len, oldplop.enc, enc, (unsigned char *)newbuf);
+ user->u_plop.buf = newbuf;
+ user->u_plop.enc = enc;
+ }
+ args += 2;
+ }
+#endif
+ if (args[0] && args[1])
+ OutputMsg(0, "%s: writebuf: too many arguments", rc_name);
+ else
+ WriteFile(user, args[0], DUMP_EXCHANGE);
+#ifdef ENCODINGS
+ if (user->u_plop.buf != oldplop.buf)
+ free(user->u_plop.buf);
+ user->u_plop = oldplop;
+ }
+#endif
+ break;
+ case RC_READBUF:
+#ifdef ENCODINGS
+ i = fore ? fore->w_encoding : display ? display->d_encoding : 0;
+ if (args[0] && args[1] && !strcmp(args[0], "-e"))
+ {
+ i = FindEncoding(args[1]);
+ if (i == -1)
+ {
+ OutputMsg(0, "%s: readbuf: unknown encoding", rc_name);
+ break;
+ }
+ args += 2;
+ }
+#endif
+ if (args[0] && args[1])
+ {
+ OutputMsg(0, "%s: readbuf: too many arguments", rc_name);
+ break;
+ }
+ if ((s = ReadFile(args[0] ? args[0] : BufferFile, &n)))
+ {
+ if (user->u_plop.buf)
+ UserFreeCopyBuffer(user);
+ user->u_plop.len = n;
+ user->u_plop.buf = s;
+#ifdef ENCODINGS
+ user->u_plop.enc = i;
+#endif
+ }
+ break;
+ case RC_REMOVEBUF:
+ KillBuffers();
+ break;
+ case RC_IGNORECASE:
+ (void)ParseSwitch(act, &search_ic);
+ if (msgok)
+ OutputMsg(0, "Will %signore case in searches", search_ic ? "" : "not ");
+ break;
+#endif /* COPY_PASTE */
+ case RC_ESCAPE:
+ if (*argl == 0)
+ SetEscape(user, -1, -1);
+ else if (*argl == 2)
+ SetEscape(user, (int)(unsigned char)args[0][0], (int)(unsigned char)args[0][1]);
+ else
+ {
+ OutputMsg(0, "%s: two characters required after escape.", rc_name);
+ break;
+ }
+ /* Change defescape if master user. This is because we only
+ * have one ktab.
+ */
+ if (display && user != users)
+ break;
+ /* FALLTHROUGH */
+ case RC_DEFESCAPE:
+ if (*argl == 0)
+ SetEscape(NULL, -1, -1);
+ else if (*argl == 2)
+ SetEscape(NULL, (int)(unsigned char)args[0][0], (int)(unsigned char)args[0][1]);
+ else
+ {
+ OutputMsg(0, "%s: two characters required after defescape.", rc_name);
+ break;
+ }
+#ifdef MAPKEYS
+ CheckEscape();
+#endif
+ break;
+ case RC_CHDIR:
+ s = *args ? *args : home;
+ if (chdir(s) == -1)
+ OutputMsg(errno, "%s", s);
+ break;
+ case RC_SHELL:
+ case RC_DEFSHELL:
+ if (ParseSaveStr(act, &ShellProg) == 0)
+ ShellArgs[0] = ShellProg;
+ break;
+ case RC_HARDCOPYDIR:
+ if (*args)
+ (void)ParseSaveStr(act, &hardcopydir);
+ if (msgok)
+ OutputMsg(0, "hardcopydir is %s\n", hardcopydir && *hardcopydir ? hardcopydir : "<cwd>");
+ break;
+ case RC_LOGFILE:
+ if (*args)
+ {
+ char buf[1024];
+ if (args[1] && !(strcmp(*args, "flush")))
+ {
+ log_flush = atoi(args[1]);
+ if (msgok)
+ OutputMsg(0, "log flush timeout set to %ds\n", log_flush);
+ break;
+ }
+ if (ParseSaveStr(act, &screenlogfile))
+ break;
+ if (fore && fore->w_log)
+ if (DoStartLog(fore, buf, sizeof(buf)))
+ OutputMsg(0, "Error opening logfile \"%s\"", buf);
+ if (!msgok)
+ break;
+ }
+ OutputMsg(0, "logfile is '%s'", screenlogfile);
+ break;
+ case RC_LOGTSTAMP:
+ if (!*args || !strcmp(*args, "on") || !strcmp(*args, "off"))
+ {
+ if (ParseSwitch(act, &logtstamp_on) == 0 && msgok)
+ OutputMsg(0, "timestamps turned %s", logtstamp_on ? "on" : "off");
+ }
+ else if (!strcmp(*args, "string"))
+ {
+ if (args[1])
+ {
+ if (logtstamp_string)
+ free(logtstamp_string);
+ logtstamp_string = SaveStr(args[1]);
+ }
+ if (msgok)
+ OutputMsg(0, "logfile timestamp is '%s'", logtstamp_string);
+ }
+ else if (!strcmp(*args, "after"))
+ {
+ if (args[1])
+ {
+ logtstamp_after = atoi(args[1]);
+ if (!msgok)
+ break;
+ }
+ OutputMsg(0, "timestamp printed after %ds\n", logtstamp_after);
+ }
+ else
+ OutputMsg(0, "usage: logtstamp [after [n]|string [str]|on|off]");
+ break;
+ case RC_SHELLTITLE:
+ (void)ParseSaveStr(act, &nwin_default.aka);
+ break;
+ case RC_TERMCAP:
+ case RC_TERMCAPINFO:
+ case RC_TERMINFO:
+ if (!rc_name || !*rc_name)
+ OutputMsg(0, "Sorry, too late now. Place that in your .screenrc file.");
+ break;
+ case RC_SLEEP:
+ break; /* Already handled */
+ case RC_TERM:
+ s = NULL;
+ if (ParseSaveStr(act, &s))
+ break;
+ if (strlen(s) > MAXTERMLEN)
+ {
+ OutputMsg(0, "%s: term: argument too long ( < %d)", rc_name, MAXTERMLEN);
+ free(s);
+ break;
+ }
+ strncpy(screenterm, s, MAXTERMLEN);
+ screenterm[MAXTERMLEN] = '\0';
+ free(s);
+ debug1("screenterm set to %s\n", screenterm);
+ MakeTermcap((display == 0));
+ debug("new termcap made\n");
+ break;
+ case RC_ECHO:
+ if (!msgok && (!rc_name || strcmp(rc_name, "-X")))
+ break;
+ /*
+ * user typed ^A:echo... well, echo isn't FinishRc's job,
+ * but as he wanted to test us, we show good will
+ */
+ if (argc > 1 && !strcmp(*args, "-n"))
+ {
+ args++;
+ argc--;
+ }
+ s = *args;
+ if (argc > 1 && !strcmp(*args, "-p"))
+ {
+ args++;
+ argc--;
+ s = *args;
+ if (s)
+ s = MakeWinMsg(s, fore, '%');
+ }
+ if (s)
+ OutputMsg(0, "%s", s);
+ else
+ {
+ OutputMsg(0, "%s: 'echo [-n] [-p] \"string\"' expected.", rc_name);
+ queryflag = -1;
+ }
+ break;
+ case RC_BELL:
+ case RC_BELL_MSG:
+ if (*args == 0)
+ {
+ char buf[256];
+ AddXChars(buf, sizeof(buf), BellString);
+ OutputMsg(0, "bell_msg is '%s'", buf);
+ break;
+ }
+ (void)ParseSaveStr(act, &BellString);
+ break;
+#ifdef COPY_PASTE
+ case RC_BUFFERFILE:
+ if (*args == 0)
+ BufferFile = SaveStr(DEFAULT_BUFFERFILE);
+ else if (ParseSaveStr(act, &BufferFile))
+ break;
+ if (msgok)
+ OutputMsg(0, "Bufferfile is now '%s'", BufferFile);
+ break;
+#endif
+ case RC_ACTIVITY:
+ (void)ParseSaveStr(act, &ActivityString);
+ break;
+#if defined(DETACH) && defined(POW_DETACH)
+ case RC_POW_DETACH_MSG:
+ if (*args == 0)
+ {
+ char buf[256];
+ AddXChars(buf, sizeof(buf), PowDetachString);
+ OutputMsg(0, "pow_detach_msg is '%s'", buf);
+ break;
+ }
+ (void)ParseSaveStr(act, &PowDetachString);
+ break;
+#endif
+#if defined(UTMPOK) && defined(LOGOUTOK)
+ case RC_LOGIN:
+ n = fore->w_slot != (slot_t)-1;
+ if (*args && !strcmp(*args, "always"))
+ {
+ fore->w_lflag = 3;
+ if (!displays && n)
+ SlotToggle(n);
+ break;
+ }
+ if (*args && !strcmp(*args, "attached"))
+ {
+ fore->w_lflag = 1;
+ if (!displays && n)
+ SlotToggle(0);
+ break;
+ }
+ if (ParseSwitch(act, &n) == 0)
+ SlotToggle(n);
+ break;
+ case RC_DEFLOGIN:
+ if (!strcmp(*args, "always"))
+ nwin_default.lflag |= 2;
+ else if (!strcmp(*args, "attached"))
+ nwin_default.lflag &= ~2;
+ else
+ (void)ParseOnOff(act, &nwin_default.lflag);
+ break;
+#endif
+ case RC_DEFFLOW:
+ if (args[0] && args[1] && args[1][0] == 'i')
+ {
+ iflag = 1;
+ for (display = displays; display; display = display->d_next)
+ {
+ if (!D_flow)
+ continue;
+#if defined(TERMIO) || defined(POSIX)
+ D_NewMode.tio.c_cc[VINTR] = D_OldMode.tio.c_cc[VINTR];
+ D_NewMode.tio.c_lflag |= ISIG;
+#else /* TERMIO || POSIX */
+ D_NewMode.m_tchars.t_intrc = D_OldMode.m_tchars.t_intrc;
+#endif /* TERMIO || POSIX */
+ SetTTY(D_userfd, &D_NewMode);
+ }
+ }
+ if (args[0] && args[0][0] == 'a')
+ nwin_default.flowflag = FLOW_AUTOFLAG;
+ else
+ (void)ParseOnOff(act, &nwin_default.flowflag);
+ break;
+ case RC_DEFWRAP:
+ (void)ParseOnOff(act, &nwin_default.wrap);
+ break;
+ case RC_DEFC1:
+ (void)ParseOnOff(act, &nwin_default.c1);
+ break;
+#ifdef COLOR
+ case RC_DEFBCE:
+ (void)ParseOnOff(act, &nwin_default.bce);
+ break;
+#endif
+ case RC_DEFGR:
+ (void)ParseOnOff(act, &nwin_default.gr);
+ break;
+ case RC_DEFMONITOR:
+ if (ParseOnOff(act, &n) == 0)
+ nwin_default.monitor = (n == 0) ? MON_OFF : MON_ON;
+ break;
+ case RC_DEFMOUSETRACK:
+ if (ParseOnOff(act, &n) == 0)
+ defmousetrack = (n == 0) ? 0 : 1000;
+ break;
+ case RC_MOUSETRACK:
+ if (!args[0])
+ {
+ OutputMsg(0, "Mouse tracking for this display is turned %s", D_mousetrack ? "on" : "off");
+ }
+ else if (ParseOnOff(act, &n) == 0)
+ {
+ D_mousetrack = n == 0 ? 0 : 1000;
+ if (D_fore)
+ MouseMode(D_fore->w_mouse);
+ }
+ break;
+ case RC_DEFSILENCE:
+ if (ParseOnOff(act, &n) == 0)
+ nwin_default.silence = (n == 0) ? SILENCE_OFF : SILENCE_ON;
+ break;
+ case RC_VERBOSE:
+ if (!*args)
+ OutputMsg(0, "W%s echo command when creating windows.",
+ VerboseCreate ? "ill" : "on't");
+ else if (ParseOnOff(act, &n) == 0)
+ VerboseCreate = n;
+ break;
+ case RC_HARDSTATUS:
+ if (display)
+ {
+ OutputMsg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
+ RemoveStatus();
+ }
+ if (args[0] && strcmp(args[0], "on") && strcmp(args[0], "off"))
+ {
+ struct display *olddisplay = display;
+ int old_use, new_use = -1;
+
+ s = args[0];
+ if (!strncmp(s, "always", 6))
+ s += 6;
+ if (!strcmp(s, "firstline"))
+ new_use = HSTATUS_FIRSTLINE;
+ else if (!strcmp(s, "lastline"))
+ new_use = HSTATUS_LASTLINE;
+ else if (!strcmp(s, "ignore"))
+ new_use = HSTATUS_IGNORE;
+ else if (!strcmp(s, "message"))
+ new_use = HSTATUS_MESSAGE;
+ else if (!strcmp(args[0], "string"))
+ {
+ if (!args[1])
+ {
+ char buf[256];
+ AddXChars(buf, sizeof(buf), hstatusstring);
+ OutputMsg(0, "hardstatus string is '%s'", buf);
+ break;
+ }
+ }
+ else
+ {
+ OutputMsg(0, "%s: usage: hardstatus [always]lastline|ignore|message|string [string]", rc_name);
+ break;
+ }
+ if (new_use != -1)
+ {
+ hardstatusemu = new_use | (s == args[0] ? 0 : HSTATUS_ALWAYS);
+ for (display = displays; display; display = display->d_next)
+ {
+ RemoveStatus();
+ new_use = hardstatusemu & ~HSTATUS_ALWAYS;
+ if (D_HS && s == args[0])
+ new_use = HSTATUS_HS;
+ ShowHStatus((char *)0);
+ old_use = D_has_hstatus;
+ D_has_hstatus = new_use;
+ if ((new_use == HSTATUS_LASTLINE && old_use != HSTATUS_LASTLINE) || (new_use != HSTATUS_LASTLINE && old_use == HSTATUS_LASTLINE))
+ ChangeScreenSize(D_width, D_height, 1);
+ if ((new_use == HSTATUS_FIRSTLINE && old_use != HSTATUS_FIRSTLINE) || (new_use != HSTATUS_FIRSTLINE && old_use == HSTATUS_FIRSTLINE))
+ ChangeScreenSize(D_width, D_height, 1);
+ RefreshHStatus();
+ }
+ }
+ if (args[1])
+ {
+ if (hstatusstring)
+ free(hstatusstring);
+ hstatusstring = SaveStr(args[1]);
+ for (display = displays; display; display = display->d_next)
+ RefreshHStatus();
+ }
+ display = olddisplay;
+ break;
+ }
+ (void)ParseSwitch(act, &use_hardstatus);
+ if (msgok)
+ OutputMsg(0, "messages displayed on %s", use_hardstatus ? "hardstatus line" : "window");
+ break;
+ case RC_CAPTION:
+ if (strcmp(args[0], "always") == 0 || strcmp(args[0], "splitonly") == 0)
+ {
+ struct display *olddisplay = display;
+
+ captionalways = args[0][0] == 'a';
+ for (display = displays; display; display = display->d_next)
+ ChangeScreenSize(D_width, D_height, 1);
+ display = olddisplay;
+ }
+ else if (strcmp(args[0], "string") == 0)
+ {
+ if (!args[1])
+ {
+ char buf[256];
+ AddXChars(buf, sizeof(buf), captionstring);
+ OutputMsg(0, "caption string is '%s'", buf);
+ break;
+ }
+ }
+ else
+ {
+ OutputMsg(0, "%s: usage: caption always|splitonly|string <string>", rc_name);
+ break;
+ }
+ if (!args[1])
+ break;
+ if (captionstring)
+ free(captionstring);
+ captionstring = SaveStr(args[1]);
+ RedisplayDisplays(0);
+ break;
+ case RC_CONSOLE:
+ n = (console_window != 0);
+ if (ParseSwitch(act, &n))
+ break;
+ if (TtyGrabConsole(fore->w_ptyfd, n, rc_name))
+ break;
+ if (n == 0)
+ OutputMsg(0, "%s: releasing console %s", rc_name, HostName);
+ else if (console_window)
+ OutputMsg(0, "%s: stealing console %s from window %d (%s)", rc_name,
+ HostName, console_window->w_number, console_window->w_title);
+ else
+ OutputMsg(0, "%s: grabbing console %s", rc_name, HostName);
+ console_window = n ? fore : 0;
+ break;
+ case RC_ALLPARTIAL:
+ if (ParseOnOff(act, &all_norefresh))
+ break;
+ if (!all_norefresh && fore)
+ Activate(-1);
+ if (msgok)
+ OutputMsg(0, all_norefresh ? "No refresh on window change!\n" :
+ "Window specific refresh\n");
+ break;
+ case RC_PARTIAL:
+ (void)ParseSwitch(act, &n);
+ fore->w_norefresh = n;
+ break;
+ case RC_VBELL:
+ if (ParseSwitch(act, &visual_bell) || !msgok)
+ break;
+ if (visual_bell == 0)
+ OutputMsg(0, "switched to audible bell.");
+ else
+ OutputMsg(0, "switched to visual bell.");
+ break;
+ case RC_VBELLWAIT:
+ if (ParseNum1000(act, &VBellWait) == 0 && msgok)
+ OutputMsg(0, "vbellwait set to %.10g seconds", VBellWait/1000.);
+ break;
+ case RC_MSGWAIT:
+ if (ParseNum1000(act, &MsgWait) == 0 && msgok)
+ OutputMsg(0, "msgwait set to %.10g seconds", MsgWait/1000.);
+ break;
+ case RC_MSGMINWAIT:
+ if (ParseNum1000(act, &MsgMinWait) == 0 && msgok)
+ OutputMsg(0, "msgminwait set to %.10g seconds", MsgMinWait/1000.);
+ break;
+ case RC_SILENCEWAIT:
+ if (ParseNum(act, &SilenceWait))
+ break;
+ if (SilenceWait < 1)
+ SilenceWait = 1;
+ for (p = windows; p; p = p->w_next)
+ p->w_silencewait = SilenceWait;
+ if (msgok)
+ OutputMsg(0, "silencewait set to %d seconds", SilenceWait);
+ break;
+ case RC_BUMPRIGHT:
+ if (fore->w_number < NextWindow())
+ WindowChangeNumber(fore->w_number, NextWindow());
+ break;
+ case RC_BUMPLEFT:
+ if (fore->w_number > PreviousWindow())
+ WindowChangeNumber(fore->w_number, PreviousWindow());
+ break;
+ case RC_COLLAPSE:
+ CollapseWindowlist();
+ break;
+ case RC_NUMBER:
+ if (*args == 0)
+ OutputMsg(0, queryflag >= 0 ? "%d (%s)" : "This is window %d (%s).", fore->w_number, fore->w_title);
+ else
+ {
+ int old = fore->w_number;
+ int rel = 0, parse;
+ if (args[0][0] == '+')
+ rel = 1;
+ else if (args[0][0] == '-')
+ rel = -1;
+ if (rel)
+ ++act->args[0];
+ parse = ParseNum(act, &n);
+ if (rel)
+ --act->args[0];
+ if (parse)
+ break;
+ if (rel > 0)
+ n += old;
+ else if (rel < 0)
+ n = old - n;
+ if (!WindowChangeNumber(old, n))
+ {
+ /* Window number could not be changed. */
+ queryflag = -1;
+ return;
+ }
+ }
+ break;
+
+ case RC_ZOMBIE_TIMEOUT:
+ if (argc != 1) {
+ Msg(0, "Setting zombie polling needs a timeout arg\n");
+ break;
+ }
+
+ nwin_default.poll_zombie_timeout = atoi(args[0]);
+ if (fore)
+ fore->w_poll_zombie_timeout = nwin_default.poll_zombie_timeout;
+ debug1("Setting zombie polling to %d\n", nwin_default.poll_zombie_timeout);
+ break;
+
+ case RC_SORT:
+ if (fore) {
+ /* Better do not allow this. Not sure what the utmp stuff in number
+ * command above is for (you get four entries in e.g. /var/log/wtmp
+ * per number switch). But I don't know enough about this.
+ */
+ Msg(0, "Sorting inside a window is not allowed. Push CTRL-a \" "
+ "and try again\n");
+ break;
+ }
+ /*
+ * Simple sort algorithm: Look out for the smallest, put it
+ * to the first place, look out for the 2nd smallest, ...
+ */
+ for (i = 0; i < maxwin ; i++) {
+ if (wtab[i] == NULL)
+ continue;
+ n = i;
+
+ for (nr = i + 1; nr < maxwin; nr++) {
+ if (wtab[nr] == NULL)
+ continue;
+ debug2("Testing window %d and %d.\n", nr, n);
+ if (strcmp(wtab[nr]->w_title,wtab[n]->w_title) < 0)
+ n = nr;
+ }
+
+ if (n != i) {
+ debug2("Exchange window %d and %d.\n", i, n);
+ p = wtab[n];
+ wtab[n] = wtab[i];
+ wtab[i] = p;
+ wtab[n]->w_number = n;
+ wtab[i]->w_number = i;
+#ifdef MULTIUSER
+ /* exchange the acls for these windows. */
+ AclWinSwap(i, n);
+#endif
+ }
+ }
+ WindowChanged((struct win *)0, 0);
+ break;
+
+ case RC_SILENCE:
+ n = fore->w_silence != 0;
+ i = fore->w_silencewait;
+ if (args[0] && (args[0][0] == '-' || (args[0][0] >= '0' && args[0][0] <= '9')))
+ {
+ if (ParseNum(act, &i))
+ break;
+ n = i > 0;
+ }
+ else if (ParseSwitch(act, &n))
+ break;
+ if (n)
+ {
+#ifdef MULTIUSER
+ if (display) /* we tell only this user */
+ ACLBYTE(fore->w_lio_notify, D_user->u_id) |= ACLBIT(D_user->u_id);
+ else
+ for (n = 0; n < maxusercount; n++)
+ ACLBYTE(fore->w_lio_notify, n) |= ACLBIT(n);
+#endif
+ fore->w_silencewait = i;
+ fore->w_silence = SILENCE_ON;
+ SetTimeout(&fore->w_silenceev, fore->w_silencewait * 1000);
+ evenq(&fore->w_silenceev);
+
+ if (!msgok)
+ break;
+ OutputMsg(0, "The window is now being monitored for %d sec. silence.", fore->w_silencewait);
+ }
+ else
+ {
+#ifdef MULTIUSER
+ if (display) /* we remove only this user */
+ ACLBYTE(fore->w_lio_notify, D_user->u_id)
+ &= ~ACLBIT(D_user->u_id);
+ else
+ for (n = 0; n < maxusercount; n++)
+ ACLBYTE(fore->w_lio_notify, n) &= ~ACLBIT(n);
+ for (i = maxusercount - 1; i >= 0; i--)
+ if (ACLBYTE(fore->w_lio_notify, i))
+ break;
+ if (i < 0)
+#endif
+ {
+ fore->w_silence = SILENCE_OFF;
+ evdeq(&fore->w_silenceev);
+ }
+ if (!msgok)
+ break;
+ OutputMsg(0, "The window is no longer being monitored for silence.");
+ }
+ break;
+#ifdef COPY_PASTE
+ case RC_DEFSCROLLBACK:
+ (void)ParseNum(act, &nwin_default.histheight);
+ break;
+ case RC_SCROLLBACK:
+ if (flayer->l_layfn == &MarkLf)
+ {
+ OutputMsg(0, "Cannot resize scrollback buffer in copy/scrollback mode.");
+ break;
+ }
+ (void)ParseNum(act, &n);
+ ChangeWindowSize(fore, fore->w_width, fore->w_height, n);
+ if (msgok)
+ OutputMsg(0, "scrollback set to %d", fore->w_histheight);
+ break;
+#endif
+ case RC_SESSIONNAME:
+ if (*args == 0)
+ OutputMsg(0, "This session is named '%s'\n", SockName);
+ else
+ {
+ char buf[MAXPATHLEN];
+
+ s = 0;
+ if (ParseSaveStr(act, &s))
+ break;
+ if (!*s || strlen(s) + (SockName - SockPath) > MAXPATHLEN - 13 || index(s, '/'))
+ {
+ OutputMsg(0, "%s: bad session name '%s'\n", rc_name, s);
+ free(s);
+ break;
+ }
+ strncpy(buf, SockPath, SockName - SockPath);
+ sprintf(buf + (SockName - SockPath), "%d.%s", (int)getpid(), s);
+ free(s);
+ if ((access(buf, F_OK) == 0) || (errno != ENOENT))
+ {
+ OutputMsg(0, "%s: inappropriate path: '%s'.", rc_name, buf);
+ break;
+ }
+ if (rename(SockPath, buf))
+ {
+ OutputMsg(errno, "%s: failed to rename(%s, %s)", rc_name, SockPath, buf);
+ break;
+ }
+ debug2("rename(%s, %s) done\n", SockPath, buf);
+ strcpy(SockPath, buf);
+ MakeNewEnv();
+ WindowChanged((struct win *)0, 'S');
+ }
+ break;
+ case RC_SETENV:
+ if (!args[0] || !args[1])
+ {
+ debug1("RC_SETENV arguments missing: %s\n", args[0] ? args[0] : "");
+ InputSetenv(args[0]);
+ }
+ else
+ {
+ xsetenv(args[0], args[1]);
+ MakeNewEnv();
+ }
+ break;
+ case RC_UNSETENV:
+ unsetenv(*args);
+ MakeNewEnv();
+ break;
+#ifdef COPY_PASTE
+ case RC_DEFSLOWPASTE:
+ (void)ParseNum(act, &nwin_default.slow);
+ break;
+ case RC_SLOWPASTE:
+ if (*args == 0)
+ OutputMsg(0, fore->w_slowpaste ?
+ "Slowpaste in window %d is %d milliseconds." :
+ "Slowpaste in window %d is unset.",
+ fore->w_number, fore->w_slowpaste);
+ else if (ParseNum(act, &fore->w_slowpaste) == 0 && msgok)
+ OutputMsg(0, fore->w_slowpaste ?
+ "Slowpaste in window %d set to %d milliseconds." :
+ "Slowpaste in window %d now unset.",
+ fore->w_number, fore->w_slowpaste);
+ break;
+ case RC_MARKKEYS:
+ if (CompileKeys(*args, *argl, mark_key_tab))
+ {
+ OutputMsg(0, "%s: markkeys: syntax error.", rc_name);
+ break;
+ }
+ debug1("markkeys %s\n", *args);
+ break;
+# ifdef FONT
+ case RC_PASTEFONT:
+ if (ParseSwitch(act, &pastefont) == 0 && msgok)
+ OutputMsg(0, "Will %spaste font settings", pastefont ? "" : "not ");
+ break;
+# endif
+ case RC_CRLF:
+ (void)ParseSwitch(act, &join_with_cr);
+ break;
+ case RC_COMPACTHIST:
+ if (ParseSwitch(act, &compacthist) == 0 && msgok)
+ OutputMsg(0, "%scompacting history lines", compacthist ? "" : "not ");
+ break;
+#endif
+#ifdef NETHACK
+ case RC_NETHACK:
+ (void)ParseOnOff(act, &nethackflag);
+ break;
+#else
+ case RC_NETHACK:
+ Msg(0, "nethack disabled at build time");
+ break;
+#endif
+ case RC_HARDCOPY_APPEND:
+ (void)ParseOnOff(act, &hardcopy_append);
+ break;
+ case RC_VBELL_MSG:
+ if (*args == 0)
+ {
+ char buf[256];
+ AddXChars(buf, sizeof(buf), VisualBellString);
+ OutputMsg(0, "vbell_msg is '%s'", buf);
+ break;
+ }
+ (void)ParseSaveStr(act, &VisualBellString);
+ debug1(" new vbellstr '%s'\n", VisualBellString);
+ break;
+ case RC_DEFMODE:
+ if (ParseBase(act, *args, &n, 8, "octal"))
+ break;
+ if (n < 0 || n > 0777)
+ {
+ OutputMsg(0, "%s: mode: Invalid tty mode %o", rc_name, n);
+ break;
+ }
+ TtyMode = n;
+ if (msgok)
+ OutputMsg(0, "Ttymode set to %03o", TtyMode);
+ break;
+ case RC_AUTODETACH:
+ (void)ParseOnOff(act, &auto_detach);
+ break;
+ case RC_STARTUP_MESSAGE:
+ (void)ParseOnOff(act, &default_startup);
+ break;
+#ifdef PASSWORD
+ case RC_PASSWORD:
+ if (*args)
+ {
+ n = (*user->u_password) ? 1 : 0;
+ if (user->u_password != NullStr) free((char *)user->u_password);
+ user->u_password = SaveStr(*args);
+ if (!strcmp(user->u_password, "none"))
+ {
+ if (n)
+ OutputMsg(0, "Password checking disabled");
+ free(user->u_password);
+ user->u_password = NullStr;
+ }
+ }
+ else
+ {
+ if (!fore)
+ {
+ OutputMsg(0, "%s: password: window required", rc_name);
+ break;
+ }
+ Input("New screen password:", 100, INP_NOECHO, pass1, display ? (char *)D_user : (char *)users, 0);
+ }
+ break;
+#endif /* PASSWORD */
+ case RC_BIND:
+ {
+ struct action *ktabp = ktab;
+ int kflag = 0;
+
+ for (;;)
+ {
+ if (argc > 2 && !strcmp(*args, "-c"))
+ {
+ ktabp = FindKtab(args[1], 1);
+ if (ktabp == 0)
+ break;
+ args += 2;
+ argl += 2;
+ argc -= 2;
+ }
+ else if (argc > 1 && !strcmp(*args, "-k"))
+ {
+ kflag = 1;
+ args++;
+ argl++;
+ argc--;
+ }
+ else
+ break;
+ }
+#ifdef MAPKEYS
+ if (kflag)
+ {
+ for (n = 0; n < KMAP_KEYS; n++)
+ if (strcmp(term[n + T_CAPS].tcname, *args) == 0)
+ break;
+ if (n == KMAP_KEYS)
+ {
+ OutputMsg(0, "%s: bind: unknown key '%s'", rc_name, *args);
+ break;
+ }
+ n += 256;
+ }
+ else
+#endif
+ if (*argl != 1)
+ {
+ OutputMsg(0, "%s: bind: character, ^x, or (octal) \\032 expected.", rc_name);
+ break;
+ }
+ else
+ n = (unsigned char)args[0][0];
+
+ if (args[1])
+ {
+ if ((i = FindCommnr(args[1])) == RC_ILLEGAL)
+ {
+ OutputMsg(0, "%s: bind: unknown command '%s'", rc_name, args[1]);
+ break;
+ }
+ if (CheckArgNum(i, args + 2) < 0)
+ break;
+ ClearAction(&ktabp[n]);
+ SaveAction(ktabp + n, i, args + 2, argl + 2);
+ }
+ else
+ ClearAction(&ktabp[n]);
+ }
+ break;
+#ifdef MAPKEYS
+ case RC_BINDKEY:
+ {
+ struct action *newact;
+ int newnr, fl = 0, kf = 0, af = 0, df = 0, mf = 0;
+ struct display *odisp = display;
+ int used = 0;
+ struct kmap_ext *kme = NULL;
+
+ for (; *args && **args == '-'; args++, argl++)
+ {
+ if (strcmp(*args, "-t") == 0)
+ fl = KMAP_NOTIMEOUT;
+ else if (strcmp(*args, "-k") == 0)
+ kf = 1;
+ else if (strcmp(*args, "-a") == 0)
+ af = 1;
+ else if (strcmp(*args, "-d") == 0)
+ df = 1;
+ else if (strcmp(*args, "-m") == 0)
+ mf = 1;
+ else if (strcmp(*args, "--") == 0)
+ {
+ args++;
+ argl++;
+ break;
+ }
+ else
+ {
+ OutputMsg(0, "%s: bindkey: invalid option %s", rc_name, *args);
+ return;
+ }
+ }
+ if (df && mf)
+ {
+ OutputMsg(0, "%s: bindkey: -d does not work with -m", rc_name);
+ break;
+ }
+ if (*args == 0)
+ {
+ if (mf)
+ display_bindkey("Edit mode", mmtab);
+ else if (df)
+ display_bindkey("Default", dmtab);
+ else
+ display_bindkey("User", umtab);
+ break;
+ }
+ if (kf == 0)
+ {
+ if (af)
+ {
+ OutputMsg(0, "%s: bindkey: -a only works with -k", rc_name);
+ break;
+ }
+ if (*argl == 0)
+ {
+ OutputMsg(0, "%s: bindkey: empty string makes no sense", rc_name);
+ break;
+ }
+ for (i = 0, kme = kmap_exts; i < kmap_extn; i++, kme++)
+ if (kme->str == 0)
+ {
+ if (args[1])
+ break;
+ }
+ else
+ if (*argl == (kme->fl & ~KMAP_NOTIMEOUT) && bcmp(kme->str, *args, *argl) == 0)
+ break;
+ if (i == kmap_extn)
+ {
+ if (!args[1])
+ {
+ OutputMsg(0, "%s: bindkey: keybinding not found", rc_name);
+ break;
+ }
+ kmap_extn += 8;
+ kmap_exts = (struct kmap_ext *)xrealloc((char *)kmap_exts, kmap_extn * sizeof(*kmap_exts));
+ kme = kmap_exts + i;
+ bzero((char *)kme, 8 * sizeof(*kmap_exts));
+ for (; i < kmap_extn; i++, kme++)
+ {
+ kme->str = 0;
+ kme->dm.nr = kme->mm.nr = kme->um.nr = RC_ILLEGAL;
+ kme->dm.args = kme->mm.args = kme->um.args = noargs;
+ kme->dm.argl = kme->mm.argl = kme->um.argl = 0;
+ }
+ i -= 8;
+ kme -= 8;
+ }
+ if (df == 0 && kme->dm.nr != RC_ILLEGAL)
+ used = 1;
+ if (mf == 0 && kme->mm.nr != RC_ILLEGAL)
+ used = 1;
+ if ((df || mf) && kme->um.nr != RC_ILLEGAL)
+ used = 1;
+ i += KMAP_KEYS + KMAP_AKEYS;
+ newact = df ? &kme->dm : mf ? &kme->mm : &kme->um;
+ }
+ else
+ {
+ for (i = T_CAPS; i < T_OCAPS; i++)
+ if (strcmp(term[i].tcname, *args) == 0)
+ break;
+ if (i == T_OCAPS)
+ {
+ OutputMsg(0, "%s: bindkey: unknown key '%s'", rc_name, *args);
+ break;
+ }
+ if (af && i >= T_CURSOR && i < T_OCAPS)
+ i -= T_CURSOR - KMAP_KEYS;
+ else
+ i -= T_CAPS;
+ newact = df ? &dmtab[i] : mf ? &mmtab[i] : &umtab[i];
+ }
+ if (args[1])
+ {
+ if ((newnr = FindCommnr(args[1])) == RC_ILLEGAL)
+ {
+ OutputMsg(0, "%s: bindkey: unknown command '%s'", rc_name, args[1]);
+ break;
+ }
+ if (CheckArgNum(newnr, args + 2) < 0)
+ break;
+ ClearAction(newact);
+ SaveAction(newact, newnr, args + 2, argl + 2);
+ if (kf == 0 && args[1])
+ {
+ if (kme->str)
+ free(kme->str);
+ kme->str = SaveStrn(*args, *argl);
+ kme->fl = fl | *argl;
+ }
+ }
+ else
+ ClearAction(newact);
+ for (display = displays; display; display = display->d_next)
+ remap(i, args[1] ? 1 : 0);
+ if (kf == 0 && !args[1])
+ {
+ if (!used && kme->str)
+ {
+ free(kme->str);
+ kme->str = 0;
+ kme->fl = 0;
+ }
+ }
+ display = odisp;
+ }
+ break;
+ case RC_MAPTIMEOUT:
+ if (*args)
+ {
+ if (ParseNum(act, &n))
+ break;
+ if (n < 0)
+ {
+ OutputMsg(0, "%s: maptimeout: illegal time %d", rc_name, n);
+ break;
+ }
+ maptimeout = n;
+ }
+ if (*args == 0 || msgok)
+ OutputMsg(0, "maptimeout is %dms", maptimeout);
+ break;
+ case RC_MAPNOTNEXT:
+ D_dontmap = 1;
+ break;
+ case RC_MAPDEFAULT:
+ D_mapdefault = 1;
+ break;
+#endif
+#ifdef MULTIUSER
+ case RC_ACLCHG:
+ case RC_ACLADD:
+ case RC_ADDACL:
+ case RC_CHACL:
+ UsersAcl(NULL, argc, args);
+ break;
+ case RC_ACLDEL:
+ if (UserDel(args[0], NULL))
+ break;
+ if (msgok)
+ OutputMsg(0, "%s removed from acl database", args[0]);
+ break;
+ case RC_ACLGRP:
+ /*
+ * modify a user to gain or lose rights granted to a group.
+ * This group is actually a normal user whose rights were defined
+ * with chacl in the usual way.
+ */
+ if (args[1])
+ {
+ if (strcmp(args[1], "none")) /* link a user to another user */
+ {
+ if (AclLinkUser(args[0], args[1]))
+ break;
+ if (msgok)
+ OutputMsg(0, "User %s joined acl-group %s", args[0], args[1]);
+ }
+ else /* remove all groups from user */
+ {
+ struct acluser *u;
+ struct aclusergroup *g;
+
+ if (!(u = *FindUserPtr(args[0])))
+ break;
+ while ((g = u->u_group))
+ {
+ u->u_group = g->next;
+ free((char *)g);
+ }
+ }
+ }
+ else /* show all groups of user */
+ {
+ char buf[256], *p = buf;
+ int ngroups = 0;
+ struct acluser *u;
+ struct aclusergroup *g;
+
+ if (!(u = *FindUserPtr(args[0])))
+ {
+ if (msgok)
+ OutputMsg(0, "User %s does not exist.", args[0]);
+ break;
+ }
+ g = u->u_group;
+ while (g)
+ {
+ ngroups++;
+ sprintf(p, "%s ", g->u->u_name);
+ p += strlen(p);
+ if (p > buf+200)
+ break;
+ g = g->next;
+ }
+ if (ngroups)
+ *(--p) = '\0';
+ OutputMsg(0, "%s's group%s: %s.", args[0], (ngroups == 1) ? "" : "s",
+ (ngroups == 0) ? "none" : buf);
+ }
+ break;
+ case RC_ACLUMASK:
+ case RC_UMASK:
+ while ((s = *args++))
+ {
+ char *err = 0;
+
+ if (AclUmask(display ? D_user : users, s, &err))
+ OutputMsg(0, "umask: %s\n", err);
+ }
+ break;
+ case RC_MULTIUSER:
+ if (ParseOnOff(act, &n))
+ break;
+ multi = n ? "" : 0;
+ chsock();
+ if (msgok)
+ OutputMsg(0, "Multiuser mode %s", multi ? "enabled" : "disabled");
+ break;
+#endif /* MULTIUSER */
+#ifdef PSEUDOS
+ case RC_EXEC:
+ winexec(args);
+ break;
+#endif
+#ifdef MULTI
+ case RC_NONBLOCK:
+ i = D_nonblock >= 0;
+ if (*args && ((args[0][0] >= '0' && args[0][0] <= '9') || args[0][0] == '.'))
+ {
+ if (ParseNum1000(act, &i))
+ break;
+ }
+ else if (!ParseSwitch(act, &i))
+ i = i == 0 ? -1 : 1000;
+ else
+ break;
+ if (msgok && i == -1)
+ OutputMsg(0, "display set to blocking mode");
+ else if (msgok && i == 0)
+ OutputMsg(0, "display set to nonblocking mode, no timeout");
+ else if (msgok)
+ OutputMsg(0, "display set to nonblocking mode, %.10gs timeout", i/1000.);
+ D_nonblock = i;
+ if (D_nonblock <= 0)
+ evdeq(&D_blockedev);
+ break;
+ case RC_DEFNONBLOCK:
+ if (*args && ((args[0][0] >= '0' && args[0][0] <= '9') || args[0][0] == '.'))
+ {
+ if (ParseNum1000(act, &defnonblock))
+ break;
+ }
+ else if (!ParseOnOff(act, &defnonblock))
+ defnonblock = defnonblock == 0 ? -1 : 1000;
+ else
+ break;
+ if (display && *rc_name)
+ {
+ D_nonblock = defnonblock;
+ if (D_nonblock <= 0)
+ evdeq(&D_blockedev);
+ }
+ break;
+#endif
+ case RC_GR:
+#ifdef ENCODINGS
+ if (fore->w_gr == 2)
+ fore->w_gr = 0;
+#endif
+ if (ParseSwitch(act, &fore->w_gr) == 0 && msgok)
+ OutputMsg(0, "Will %suse GR", fore->w_gr ? "" : "not ");
+#ifdef ENCODINGS
+ if (fore->w_gr == 0 && fore->w_FontE)
+ fore->w_gr = 2;
+#endif
+ break;
+ case RC_C1:
+ if (ParseSwitch(act, &fore->w_c1) == 0 && msgok)
+ OutputMsg(0, "Will %suse C1", fore->w_c1 ? "" : "not ");
+ break;
+#ifdef COLOR
+ case RC_BCE:
+ if (ParseSwitch(act, &fore->w_bce) == 0 && msgok)
+ OutputMsg(0, "Will %serase with background color", fore->w_bce ? "" : "not ");
+ break;
+#endif
+#ifdef ENCODINGS
+ case RC_KANJI:
+ case RC_ENCODING:
+#ifdef UTF8
+ if (*args && !strcmp(args[0], "-d"))
+ {
+ if (!args[1])
+ OutputMsg(0, "encodings directory is %s", screenencodings ? screenencodings : "<unset>");
+ else
+ {
+ free(screenencodings);
+ screenencodings = SaveStr(args[1]);
+ }
+ break;
+ }
+ if (*args && !strcmp(args[0], "-l"))
+ {
+ if (!args[1])
+ OutputMsg(0, "encoding: -l: argument required");
+ else if (LoadFontTranslation(-1, args[1]))
+ OutputMsg(0, "encoding: could not load utf8 encoding file");
+ else if (msgok)
+ OutputMsg(0, "encoding: utf8 encoding file loaded");
+ break;
+ }
+#else
+ if (*args && (!strcmp(args[0], "-l") || !strcmp(args[0], "-d")))
+ {
+ if (msgok)
+ OutputMsg(0, "encoding: screen is not compiled for UTF-8.");
+ break;
+ }
+#endif
+ for (i = 0; i < 2; i++)
+ {
+ if (args[i] == 0)
+ break;
+ if (!strcmp(args[i], "."))
+ continue;
+ n = FindEncoding(args[i]);
+ if (n == -1)
+ {
+ OutputMsg(0, "encoding: unknown encoding '%s'", args[i]);
+ break;
+ }
+ if (i == 0 && fore)
+ {
+ WinSwitchEncoding(fore, n);
+ ResetCharsets(fore);
+ }
+ else if (i && display)
+ D_encoding = n;
+ }
+ break;
+ case RC_DEFKANJI:
+ case RC_DEFENCODING:
+ n = FindEncoding(*args);
+ if (n == -1)
+ {
+ OutputMsg(0, "defencoding: unknown encoding '%s'", *args);
+ break;
+ }
+ nwin_default.encoding = n;
+ break;
+#endif
+
+#ifdef UTF8
+ case RC_DEFUTF8:
+ n = nwin_default.encoding == UTF8;
+ if (ParseSwitch(act, &n) == 0)
+ {
+ nwin_default.encoding = n ? UTF8 : 0;
+ if (msgok)
+ OutputMsg(0, "Will %suse UTF-8 encoding for new windows", n ? "" : "not ");
+ }
+ break;
+ case RC_UTF8:
+ for (i = 0; i < 2; i++)
+ {
+ if (i && args[i] == 0)
+ break;
+ if (args[i] == 0)
+ n = fore->w_encoding != UTF8;
+ else if (strcmp(args[i], "off") == 0)
+ n = 0;
+ else if (strcmp(args[i], "on") == 0)
+ n = 1;
+ else
+ {
+ OutputMsg(0, "utf8: illegal argument (%s)", args[i]);
+ break;
+ }
+ if (i == 0)
+ {
+ WinSwitchEncoding(fore, n ? UTF8 : 0);
+ if (msgok)
+ OutputMsg(0, "Will %suse UTF-8 encoding", n ? "" : "not ");
+ }
+ else if (display)
+ D_encoding = n ? UTF8 : 0;
+ if (args[i] == 0)
+ break;
+ }
+ break;
+#endif
+
+ case RC_PRINTCMD:
+ if (*args)
+ {
+ if (printcmd)
+ free(printcmd);
+ printcmd = 0;
+ if (**args)
+ printcmd = SaveStr(*args);
+ }
+ if (*args == 0 || msgok)
+ {
+ if (printcmd)
+ OutputMsg(0, "using '%s' as print command", printcmd);
+ else
+ OutputMsg(0, "using termcap entries for printing");
+ break;
+ }
+ break;
+
+ case RC_DIGRAPH:
+ if (argl && argl[0] > 0 && args[1] && argl[1] > 0)
+ {
+ if (argl[0] != 2)
+ {
+ OutputMsg(0, "Two characters expected to define a digraph");
+ break;
+ }
+ i = digraph_find(args[0]);
+ digraphs[i].d[0] = args[0][0];
+ digraphs[i].d[1] = args[0][1];
+ if (!parse_input_int(args[1], argl[1], &digraphs[i].value))
+ {
+ if (!(digraphs[i].value = atoi(args[1])))
+ {
+ if (!args[1][1])
+ digraphs[i].value = (int)args[1][0];
+#ifdef UTF8
+ else
+ {
+ int t;
+ unsigned char *s = (unsigned char *)args[1];
+ digraphs[i].value = 0;
+ while (*s)
+ {
+ t = FromUtf8(*s++, &digraphs[i].value);
+ if (t == -1)
+ continue;
+ if (t == -2)
+ digraphs[i].value = 0;
+ else
+ digraphs[i].value = t;
+ break;
+ }
+ }
+#endif
+ }
+ }
+ break;
+ }
+ Input("Enter digraph: ", 10, INP_EVERY, digraph_fn, NULL, 0);
+ if (*args && **args)
+ {
+ s = *args;
+ n = strlen(s);
+ LayProcess(&s, &n);
+ }
+ break;
+
+ case RC_DEFHSTATUS:
+ if (*args == 0)
+ {
+ char buf[256];
+ *buf = 0;
+ if (nwin_default.hstatus)
+ AddXChars(buf, sizeof(buf), nwin_default.hstatus);
+ OutputMsg(0, "default hstatus is '%s'", buf);
+ break;
+ }
+ (void)ParseSaveStr(act, &nwin_default.hstatus);
+ if (*nwin_default.hstatus == 0)
+ {
+ free(nwin_default.hstatus);
+ nwin_default.hstatus = 0;
+ }
+ break;
+ case RC_HSTATUS:
+ (void)ParseSaveStr(act, &fore->w_hstatus);
+ if (*fore->w_hstatus == 0)
+ {
+ free(fore->w_hstatus);
+ fore->w_hstatus = 0;
+ }
+ WindowChanged(fore, 'h');
+ break;
+
+#ifdef FONT
+ case RC_DEFCHARSET:
+ case RC_CHARSET:
+ if (*args == 0)
+ {
+ char buf[256];
+ *buf = 0;
+ if (nwin_default.charset)
+ AddXChars(buf, sizeof(buf), nwin_default.charset);
+ OutputMsg(0, "default charset is '%s'", buf);
+ break;
+ }
+ n = strlen(*args);
+ if (n == 0 || n > 6)
+ {
+ OutputMsg(0, "%s: %s: string has illegal size.", rc_name, comms[nr].name);
+ break;
+ }
+ if (n > 4 && (
+ ((args[0][4] < '0' || args[0][4] > '3') && args[0][4] != '.') ||
+ ((args[0][5] < '0' || args[0][5] > '3') && args[0][5] && args[0][5] != '.')))
+ {
+ OutputMsg(0, "%s: %s: illegal mapping number.", rc_name, comms[nr].name);
+ break;
+ }
+ if (nr == RC_CHARSET)
+ {
+ SetCharsets(fore, *args);
+ break;
+ }
+ if (nwin_default.charset)
+ free(nwin_default.charset);
+ nwin_default.charset = SaveStr(*args);
+ break;
+#endif
+#ifdef COLOR
+ case RC_ATTRCOLOR:
+ s = args[0];
+ if (*s >= '0' && *s <= '9')
+ i = *s - '0';
+ else
+ for (i = 0; i < 8; i++)
+ if (*s == "dubrsBiI"[i])
+ break;
+ s++;
+ nr = 0;
+ if (*s && s[1] && !s[2])
+ {
+ if (*s == 'd' && s[1] == 'd')
+ nr = 3;
+ else if (*s == '.' && s[1] == 'd')
+ nr = 2;
+ else if (*s == 'd' && s[1] == '.')
+ nr = 1;
+ else if (*s != '.' || s[1] != '.')
+ s--;
+ s += 2;
+ }
+ if (*s || i < 0 || i >= 8)
+ {
+ OutputMsg(0, "%s: attrcolor: unknown attribute '%s'.", rc_name, args[0]);
+ break;
+ }
+ n = 0;
+ if (args[1])
+ n = ParseAttrColor(args[1], args[2], 1);
+ if (n == -1)
+ break;
+ attr2color[i][nr] = n;
+ n = 0;
+ for (i = 0; i < 8; i++)
+ if (attr2color[i][0] || attr2color[i][1] || attr2color[i][2] || attr2color[i][3])
+ n |= 1 << i;
+ nattr2color = n;
+ break;
+#endif
+ case RC_RENDITION:
+ i = -1;
+ if (strcmp(args[0], "bell") == 0)
+ {
+ i = REND_BELL;
+ }
+ else if (strcmp(args[0], "monitor") == 0)
+ {
+ i = REND_MONITOR;
+ }
+ else if (strcmp(args[0], "silence") == 0)
+ {
+ i = REND_SILENCE;
+ }
+ else if (strcmp(args[0], "so") != 0)
+ {
+ OutputMsg(0, "Invalid option '%s' for rendition", args[0]);
+ break;
+ }
+
+ ++args;
+ ++argl;
+
+ if (i != -1)
+ {
+ renditions[i] = ParseAttrColor(args[0], args[1], 1);
+ WindowChanged((struct win *)0, 'w');
+ WindowChanged((struct win *)0, 'W');
+ WindowChanged((struct win *)0, 0);
+ break;
+ }
+
+ /* We are here, means we want to set the sorendition. */
+ /* FALLTHROUGH*/
+ case RC_SORENDITION:
+ i = 0;
+ if (*args)
+ {
+ i = ParseAttrColor(*args, args[1], 1);
+ if (i == -1)
+ break;
+ ApplyAttrColor(i, &mchar_so);
+ WindowChanged((struct win *)0, 0);
+ debug2("--> %x %x\n", mchar_so.attr, mchar_so.color);
+ }
+ if (msgok)
+#ifdef COLOR
+ OutputMsg(0, "Standout attributes 0x%02x color 0x%02x", (unsigned char)mchar_so.attr, 0x99 ^ (unsigned char)mchar_so.color);
+#else
+ OutputMsg(0, "Standout attributes 0x%02x ", (unsigned char)mchar_so.attr);
+#endif
+ break;
+
+ case RC_SOURCE:
+ do_source(*args);
+ break;
+
+#ifdef MULTIUSER
+ case RC_SU:
+ s = NULL;
+ if (!*args)
+ {
+ OutputMsg(0, "%s:%s screen login", HostName, SockPath);
+ InputSu(D_fore, &D_user, NULL);
+ }
+ else if (!args[1])
+ InputSu(D_fore, &D_user, args[0]);
+ else if (!args[2])
+ s = DoSu(&D_user, args[0], args[1], "\377");
+ else
+ s = DoSu(&D_user, args[0], args[1], args[2]);
+ if (s)
+ OutputMsg(0, "%s", s);
+ break;
+#endif /* MULTIUSER */
+ case RC_SPLIT:
+ s = args[0];
+ if (s && !strcmp(s, "-v"))
+ AddCanvas(SLICE_HORI);
+ else
+ AddCanvas(SLICE_VERT);
+ Activate(-1);
+ break;
+ case RC_REMOVE:
+ RemCanvas();
+ Activate(-1);
+ break;
+ case RC_ONLY:
+ OneCanvas();
+ Activate(-1);
+ break;
+ case RC_FIT:
+ D_forecv->c_xoff = D_forecv->c_xs;
+ D_forecv->c_yoff = D_forecv->c_ys;
+ RethinkViewportOffsets(D_forecv);
+ ResizeLayer(D_forecv->c_layer, D_forecv->c_xe - D_forecv->c_xs + 1, D_forecv->c_ye - D_forecv->c_ys + 1, 0);
+ flayer = D_forecv->c_layer;
+ LaySetCursor();
+ break;
+ case RC_FOCUS:
+ {
+ struct canvas *cv = 0;
+ if (!*args || !strcmp(*args, "next"))
+ cv = D_forecv->c_next ? D_forecv->c_next : D_cvlist;
+ else if (!strcmp(*args, "prev"))
+ {
+ for (cv = D_cvlist; cv->c_next && cv->c_next != D_forecv; cv = cv->c_next)
+ ;
+ }
+ else if (!strcmp(*args, "top"))
+ cv = D_cvlist;
+ else if (!strcmp(*args, "bottom"))
+ {
+ for (cv = D_cvlist; cv->c_next; cv = cv->c_next)
+ ;
+ }
+ else if (!strcmp(*args, "up"))
+ cv = FindCanvas(D_forecv->c_xs, D_forecv->c_ys - 1);
+ else if (!strcmp(*args, "down"))
+ cv = FindCanvas(D_forecv->c_xs, D_forecv->c_ye + 2);
+ else if (!strcmp(*args, "left"))
+ cv = FindCanvas(D_forecv->c_xs - 1, D_forecv->c_ys);
+ else if (!strcmp(*args, "right"))
+ cv = FindCanvas(D_forecv->c_xe + 1, D_forecv->c_ys);
+ else
+ {
+ OutputMsg(0, "%s: usage: focus [next|prev|up|down|left|right|top|bottom]", rc_name);
+ break;
+ }
+ SetForeCanvas(display, cv);
+ }
+ break;
+ case RC_RESIZE:
+ i = 0;
+ if (D_forecv->c_slorient == SLICE_UNKN)
+ {
+ OutputMsg(0, "resize: need more than one region");
+ break;
+ }
+ for (; *args; args++)
+ {
+ if (!strcmp(*args, "-h"))
+ i |= RESIZE_FLAG_H;
+ else if (!strcmp(*args, "-v"))
+ i |= RESIZE_FLAG_V;
+ else if (!strcmp(*args, "-b"))
+ i |= RESIZE_FLAG_H | RESIZE_FLAG_V;
+ else if (!strcmp(*args, "-p"))
+ i |= D_forecv->c_slorient == SLICE_VERT ? RESIZE_FLAG_H : RESIZE_FLAG_V;
+ else if (!strcmp(*args, "-l"))
+ i |= RESIZE_FLAG_L;
+ else
+ break;
+ }
+ if (*args && args[1])
+ {
+ OutputMsg(0, "%s: usage: resize [-h] [-v] [-l] [num]\n", rc_name);
+ break;
+ }
+ if (*args)
+ ResizeRegions(*args, i);
+ else
+ Input(resizeprompts[i], 20, INP_EVERY, ResizeFin, (char*)0, i);
+ break;
+ case RC_SETSID:
+ (void)ParseSwitch(act, &separate_sids);
+ break;
+ case RC_EVAL:
+ args = SaveArgs(args);
+ for (i = 0; args[i]; i++)
+ {
+ if (args[i][0])
+ Colonfin(args[i], strlen(args[i]), (char *)0);
+ free(args[i]);
+ }
+ free(args);
+ break;
+ case RC_ALTSCREEN:
+ (void)ParseSwitch(act, &use_altscreen);
+ if (msgok)
+ OutputMsg(0, "Will %sdo alternate screen switching", use_altscreen ? "" : "not ");
+ break;
+ case RC_MAXWIN:
+ if (!args[0])
+ {
+ OutputMsg(0, "maximum windows allowed: %d", maxwin);
+ break;
+ }
+ if (ParseNum(act, &n))
+ break;
+ if (n < 1)
+ OutputMsg(0, "illegal maxwin number specified");
+ else if (n > 2048)
+ OutputMsg(0, "maximum 2048 windows allowed");
+ else if (n > maxwin && windows)
+ OutputMsg(0, "may increase maxwin only when there's no window");
+ else
+ {
+ if (!windows)
+ {
+ wtab = realloc(wtab, n * sizeof(struct win *));
+ bzero(wtab, n * sizeof(struct win *));
+ }
+ maxwin = n;
+ }
+ break;
+ case RC_BACKTICK:
+ if (ParseBase(act, *args, &n, 10, "decimal"))
+ break;
+ if (!args[1])
+ setbacktick(n, 0, 0, (char **)0);
+ else
+ {
+ int lifespan, tick;
+ if (argc < 4)
+ {
+ OutputMsg(0, "%s: usage: backtick num [lifespan tick cmd args...]", rc_name);
+ break;
+ }
+ if (ParseBase(act, args[1], &lifespan, 10, "decimal"))
+ break;
+ if (ParseBase(act, args[2], &tick, 10, "decimal"))
+ break;
+ setbacktick(n, lifespan, tick, SaveArgs(args + 3));
+ }
+ WindowChanged(0, '`');
+ break;
+ case RC_BLANKER:
+#ifdef BLANKER_PRG
+ if (blankerprg)
+ {
+ RunBlanker(blankerprg);
+ break;
+ }
+#endif
+ ClearAll();
+ CursorVisibility(-1);
+ D_blocked = 4;
+ break;
+#ifdef BLANKER_PRG
+ case RC_BLANKERPRG:
+ if (!args[0])
+ {
+ if (blankerprg)
+ {
+ char path[MAXPATHLEN];
+ char *p = path, **pp;
+ for (pp = blankerprg; *pp; pp++)
+ p += snprintf(p, sizeof(path) - (p - path) - 1, "%s ", *pp);
+ *(p - 1) = '\0';
+ OutputMsg(0, "blankerprg: %s", path);
+ }
+ else
+ OutputMsg(0, "No blankerprg set.");
+ break;
+ }
+ if (blankerprg)
+ {
+ char **pp;
+ for (pp = blankerprg; *pp; pp++)
+ free(*pp);
+ free(blankerprg);
+ blankerprg = 0;
+ }
+ if (args[0][0])
+ blankerprg = SaveArgs(args);
+ break;
+#endif
+ case RC_IDLE:
+ if (*args)
+ {
+ struct display *olddisplay = display;
+ if (!strcmp(*args, "off"))
+ idletimo = 0;
+ else if (args[0][0])
+ idletimo = atoi(*args) * 1000;
+ if (argc > 1)
+ {
+ if ((i = FindCommnr(args[1])) == RC_ILLEGAL)
+ {
+ OutputMsg(0, "%s: idle: unknown command '%s'", rc_name, args[1]);
+ break;
+ }
+ if (CheckArgNum(i, args + 2) < 0)
+ break;
+ ClearAction(&idleaction);
+ SaveAction(&idleaction, i, args + 2, argl + 2);
+ }
+ for (display = displays; display; display = display->d_next)
+ ResetIdle();
+ display = olddisplay;
+ }
+ if (msgok)
+ {
+ if (idletimo)
+ OutputMsg(0, "idle timeout %ds, %s", idletimo / 1000, comms[idleaction.nr].name);
+ else
+ OutputMsg(0, "idle off");
+ }
+ break;
+ case RC_FOCUSMINSIZE:
+ for (i = 0; i < 2 && args[i]; i++)
+ {
+ if (!strcmp(args[i], "max") || !strcmp(args[i], "_"))
+ n = -1;
+ else
+ n = atoi(args[i]);
+ if (i == 0)
+ focusminwidth = n;
+ else
+ focusminheight = n;
+ }
+ if (msgok)
+ {
+ char b[2][20];
+ for (i = 0; i < 2; i++)
+ {
+ n = i == 0 ? focusminwidth : focusminheight;
+ if (n == -1)
+ strcpy(b[i], "max");
+ else
+ sprintf(b[i], "%d", n);
+ }
+ OutputMsg(0, "focus min size is %s %s\n", b[0], b[1]);
+ }
+ break;
+ case RC_GROUP:
+ if (*args)
+ {
+ fore->w_group = 0;
+ if (args[0][0])
+ {
+ fore->w_group = WindowByName(*args);
+ if (fore->w_group == fore || (fore->w_group && fore->w_group->w_type != W_TYPE_GROUP))
+ fore->w_group = 0;
+ }
+ WindowChanged((struct win *)0, 'w');
+ WindowChanged((struct win *)0, 'W');
+ WindowChanged((struct win *)0, 0);
+ }
+ if (msgok)
+ {
+ if (fore->w_group)
+ OutputMsg(0, "window group is %d (%s)\n", fore->w_group->w_number, fore->w_group->w_title);
+ else
+ OutputMsg(0, "window belongs to no group");
+ }
+ break;
+ case RC_LAYOUT:
+ // A number of the subcommands for "layout" are ignored, or not processed correctly when there
+ // is no attached display.
+
+ if (!strcmp(args[0], "title"))
+ {
+ if (!display)
+ {
+ if (!args[1]) // There is no display, and there is no new title. Ignore.
+ break;
+ if (!layout_attach || layout_attach == &layout_last_marker)
+ layout_attach = CreateLayout(args[1], 0);
+ else
+ RenameLayout(layout_attach, args[1]);
+ break;
+ }
+
+ if (!D_layout)
+ {
+ OutputMsg(0, "not on a layout");
+ break;
+ }
+ if (!args[1])
+ {
+ OutputMsg(0, "current layout is %d (%s)", D_layout->lay_number, D_layout->lay_title);
+ break;
+ }
+ RenameLayout(D_layout, args[1]);
+ }
+ else if (!strcmp(args[0], "number"))
+ {
+ if (!display)
+ {
+ if (args[1] && layout_attach && layout_attach != &layout_last_marker)
+ RenumberLayout(layout_attach, atoi(args[1]));
+ break;
+ }
+
+ if (!D_layout)
+ {
+ OutputMsg(0, "not on a layout");
+ break;
+ }
+ if (!args[1])
+ {
+ OutputMsg(0, "This is layout %d (%s).\n", D_layout->lay_number, D_layout->lay_title);
+ break;
+ }
+ RenumberLayout(D_layout, atoi(args[1]));
+ break;
+ }
+ else if (!strcmp(args[0], "autosave"))
+ {
+ if (!display)
+ {
+ if (args[1] && layout_attach && layout_attach != &layout_last_marker)
+ {
+ if (!strcmp(args[1], "on"))
+ layout_attach->lay_autosave = 1;
+ else if (!strcmp(args[1], "off"))
+ layout_attach->lay_autosave = 0;
+ }
+ break;
+ }
+
+ if (!D_layout)
+ {
+ OutputMsg(0, "not on a layout");
+ break;
+ }
+ if (args[1])
+ {
+ if (!strcmp(args[1], "on"))
+ D_layout->lay_autosave = 1;
+ else if (!strcmp(args[1], "off"))
+ D_layout->lay_autosave = 0;
+ else
+ {
+ OutputMsg(0, "invalid argument. Give 'on' or 'off");
+ break;
+ }
+ }
+ if (msgok)
+ OutputMsg(0, "autosave is %s", D_layout->lay_autosave ? "on" : "off");
+ }
+ else if (!strcmp(args[0], "new"))
+ {
+ char *t = args[1];
+ n = 0;
+ if (t)
+ {
+ while (*t >= '0' && *t <= '9')
+ t++;
+ if (t != args[1] && (!*t || *t == ':'))
+ {
+ n = atoi(args[1]);
+ if (*t)
+ t++;
+ }
+ else
+ t = args[1];
+ }
+ if (!t || !*t)
+ t = "layout";
+ NewLayout(t, n);
+ Activate(-1);
+ }
+ else if (!strcmp(args[0], "save"))
+ {
+ if (!args[1])
+ {
+ OutputMsg(0, "usage: layout save <name>");
+ break;
+ }
+ if (display)
+ SaveLayout(args[1], &D_canvas);
+ }
+ else if (!strcmp(args[0], "select"))
+ {
+ if (!display)
+ {
+ if (args[1])
+ layout_attach = FindLayout(args[1]);
+ break;
+ }
+ if (!args[1])
+ {
+ Input("Switch to layout: ", 20, INP_COOKED, SelectLayoutFin, NULL, 0);
+ break;
+ }
+ SelectLayoutFin(args[1], strlen(args[1]), (char *)0);
+ }
+ else if (!strcmp(args[0], "next"))
+ {
+ if (!display)
+ {
+ if (layout_attach && layout_attach != &layout_last_marker)
+ layout_attach = layout_attach->lay_next ? layout_attach->lay_next : layouts;;
+ break;
+ }
+ struct layout *lay = D_layout;
+ if (lay)
+ lay = lay->lay_next ? lay->lay_next : layouts;
+ else
+ lay = layouts;
+ if (!lay)
+ {
+ OutputMsg(0, "no layout defined");
+ break;
+ }
+ if (lay == D_layout)
+ break;
+ LoadLayout(lay, &D_canvas);
+ Activate(-1);
+ }
+ else if (!strcmp(args[0], "prev"))
+ {
+ struct layout *lay = display ? D_layout : layout_attach;
+ struct layout *target = lay;
+ if (lay)
+ {
+ for (lay = layouts; lay->lay_next && lay->lay_next != target; lay = lay->lay_next)
+ ;
+ }
+ else
+ lay = layouts;
+
+ if (!display)
+ {
+ layout_attach = lay;
+ break;
+ }
+
+ if (!lay)
+ {
+ OutputMsg(0, "no layout defined");
+ break;
+ }
+ if (lay == D_layout)
+ break;
+ LoadLayout(lay, &D_canvas);
+ Activate(-1);
+ }
+ else if (!strcmp(args[0], "attach"))
+ {
+ if (!args[1])
+ {
+ if (!layout_attach)
+ OutputMsg(0, "no attach layout set");
+ else if (layout_attach == &layout_last_marker)
+ OutputMsg(0, "will attach to last layout");
+ else
+ OutputMsg(0, "will attach to layout %d (%s)", layout_attach->lay_number, layout_attach->lay_title);
+ break;
+ }
+ if (!strcmp(args[1], ":last"))
+ layout_attach = &layout_last_marker;
+ else if (!args[1][0])
+ layout_attach = 0;
+ else
+ {
+ struct layout *lay;
+ lay = FindLayout(args[1]);
+ if (!lay)
+ {
+ OutputMsg(0, "unknown layout '%s'", args[1]);
+ break;
+ }
+ layout_attach = lay;
+ }
+ }
+ else if (!strcmp(args[0], "show"))
+ {
+ ShowLayouts(-1);
+ }
+ else if (!strcmp(args[0], "remove"))
+ {
+ struct layout *lay = display ? D_layout : layouts;
+ if (args[1])
+ {
+ lay = layouts ? FindLayout(args[1]) : (struct layout *)0;
+ if (!lay)
+ {
+ OutputMsg(0, "unknown layout '%s'", args[1]);
+ break;
+ }
+ }
+ if (lay)
+ RemoveLayout(lay);
+ }
+ else if (!strcmp(args[0], "dump"))
+ {
+ if (!display)
+ OutputMsg(0, "Must have a display for 'layout dump'.");
+ else if (!LayoutDumpCanvas(&D_canvas, args[1] ? args[1] : "layout-dump"))
+ OutputMsg(errno, "Error dumping layout.");
+ else
+ OutputMsg(0, "Layout dumped to \"%s\"", args[1] ? args[1] : "layout-dump");
+ }
+ else
+ OutputMsg(0, "unknown layout subcommand");
+ break;
+#ifdef DW_CHARS
+ case RC_CJKWIDTH:
+ if(ParseSwitch(act, &cjkwidth) == 0)
+ {
+ if(msgok)
+ OutputMsg(0, "Treat ambiguous width characters as %s width", cjkwidth ? "full" : "half");
+ }
+ break;
+#endif
+ default:
+#ifdef HAVE_BRAILLE
+ /* key == -2: input from braille keybord, msgok always 0 */
+ DoBrailleAction(act, key == -2 ? 0 : msgok);
+#endif
+ break;
+ }
+ if (display != odisplay)
+ {
+ for (display = displays; display; display = display->d_next)
+ if (display == odisplay)
+ break;
+ }
+}
+#undef OutputMsg
+
+void
+CollapseWindowlist()
+/* renumber windows from 0, leaving no gaps */
+{
+ int pos, moveto=0;
+
+ for (pos = 1; pos < MAXWIN; pos++)
+ if (wtab[pos])
+ for (; moveto < pos; moveto++)
+ if (!wtab[moveto])
+ {
+ WindowChangeNumber(pos, moveto);
+ break;
+ }
+}
+
+void
+DoCommand(argv, argl)
+char **argv;
+int *argl;
+{
+ struct action act;
+ const char *cmd = *argv;
+
+ act.quiet = 0;
+ /* For now, we actually treat both 'supress error' and 'suppress normal message' as the
+ * same, and ignore all messages on either flag. If we wanted to do otherwise, we would
+ * need to change the definition of 'OutputMsg' slightly. */
+ if (*cmd == '@') /* Suppress error */
+ {
+ act.quiet |= 0x01;
+ cmd++;
+ }
+ if (*cmd == '-') /* Suppress normal message */
+ {
+ act.quiet |= 0x02;
+ cmd++;
+ }
+
+ if ((act.nr = FindCommnr(cmd)) == RC_ILLEGAL)
+ {
+ Msg(0, "%s: unknown command '%s'", rc_name, cmd);
+ return;
+ }
+ act.args = argv + 1;
+ act.argl = argl + 1;
+ DoAction(&act, -1);
+}
+
+static void
+SaveAction(act, nr, args, argl)
+struct action *act;
+int nr;
+char **args;
+int *argl;
+{
+ register int argc = 0;
+ char **pp;
+ int *lp;
+
+ if (args)
+ while (args[argc])
+ argc++;
+ if (argc == 0)
+ {
+ act->nr = nr;
+ act->args = noargs;
+ act->argl = 0;
+ return;
+ }
+ if ((pp = (char **)malloc((unsigned)(argc + 1) * sizeof(char *))) == 0)
+ Panic(0, "%s", strnomem);
+ if ((lp = (int *)malloc((unsigned)(argc) * sizeof(int))) == 0)
+ Panic(0, "%s", strnomem);
+ act->nr = nr;
+ act->args = pp;
+ act->argl = lp;
+ while (argc--)
+ {
+ *lp = argl ? *argl++ : (int)strlen(*args);
+ *pp++ = SaveStrn(*args++, *lp++);
+ }
+ *pp = 0;
+}
+
+static char **
+SaveArgs(args)
+char **args;
+{
+ register char **ap, **pp;
+ register int argc = 0;
+
+ while (args[argc])
+ argc++;
+ if ((pp = ap = (char **)malloc((unsigned)(argc + 1) * sizeof(char **))) == 0)
+ Panic(0, "%s", strnomem);
+ while (argc--)
+ *pp++ = SaveStr(*args++);
+ *pp = 0;
+ return ap;
+}
+
+
+/*
+ * buf is split into argument vector args.
+ * leading whitespace is removed.
+ * @!| abbreviations are expanded.
+ * the end of buffer is recognized by '\0' or an un-escaped '#'.
+ * " and ' are interpreted.
+ *
+ * argc is returned.
+ */
+int
+Parse(buf, bufl, args, argl)
+char *buf, **args;
+int bufl, *argl;
+{
+ register char *p = buf, **ap = args, *pp;
+ register int delim, argc;
+ int *lp = argl;
+
+ debug2("Parse %d %s\n", bufl, buf);
+ argc = 0;
+ pp = buf;
+ delim = 0;
+ for (;;)
+ {
+ *lp = 0;
+ while (*p && (*p == ' ' || *p == '\t'))
+ ++p;
+#ifdef PSEUDOS
+ if (argc == 0 && *p == '!')
+ {
+ *ap++ = "exec";
+ *lp++ = 4;
+ p++;
+ argc++;
+ continue;
+ }
+#endif
+ if (*p == '\0' || *p == '#' || *p == '\n')
+ {
+ *p = '\0';
+ for (delim = 0; delim < argc; delim++)
+ debug1("-- %s\n", args[delim]);
+ args[argc] = 0;
+ return argc;
+ }
+ if (++argc >= MAXARGS)
+ {
+ Msg(0, "%s: too many tokens.", rc_name);
+ return 0;
+ }
+ *ap++ = pp;
+
+ debug1("- new arg %s\n", p);
+ while (*p)
+ {
+ if (*p == delim)
+ delim = 0;
+ else if (delim != '\'' && *p == '\\' && (p[1] == 'n' || p[1] == 'r' || p[1] == 't' || p[1] == '\'' || p[1] == '"' || p[1] == '\\' || p[1] == '$' || p[1] == '#' || p[1] == '^' || (p[1] >= '0' && p[1] <= '7')))
+ {
+ p++;
+ if (*p >= '0' && *p <= '7')
+ {
+ *pp = *p - '0';
+ if (p[1] >= '0' && p[1] <= '7')
+ {
+ p++;
+ *pp = (*pp << 3) | (*p - '0');
+ if (p[1] >= '0' && p[1] <= '7')
+ {
+ p++;
+ *pp = (*pp << 3) | (*p - '0');
+ }
+ }
+ pp++;
+ }
+ else
+ {
+ switch (*p)
+ {
+ case 'n': *pp = '\n'; break;
+ case 'r': *pp = '\r'; break;
+ case 't': *pp = '\t'; break;
+ default: *pp = *p; break;
+ }
+ pp++;
+ }
+ }
+ else if (delim != '\'' && *p == '$' && (p[1] == '{' || p[1] == ':' || (p[1] >= 'a' && p[1] <= 'z') || (p[1] >= 'A' && p[1] <= 'Z') || (p[1] >= '0' && p[1] <= '9') || p[1] == '_'))
+
+ {
+ char *ps, *pe, op, *v, xbuf[11], path[MAXPATHLEN];
+ int vl;
+
+ ps = ++p;
+ debug1("- var %s\n", ps);
+ p++;
+ while (*p)
+ {
+ if (*ps == '{' && *p == '}')
+ break;
+ if (*ps == ':' && *p == ':')
+ break;
+ if (*ps != '{' && *ps != ':' && (*p < 'a' || *p > 'z') && (*p < 'A' || *p > 'Z') && (*p < '0' || *p > '9') && *p != '_')
+ break;
+ p++;
+ }
+ pe = p;
+ if (*ps == '{' || *ps == ':')
+ {
+ if (!*p)
+ {
+ Msg(0, "%s: bad variable name.", rc_name);
+ return 0;
+ }
+ p++;
+ }
+ op = *pe;
+ *pe = 0;
+ debug1("- var is '%s'\n", ps);
+ if (*ps == ':')
+ v = gettermcapstring(ps + 1);
+ else
+ {
+ if (*ps == '{')
+ ps++;
+ v = xbuf;
+ if (!strcmp(ps, "TERM"))
+ v = display ? D_termname : "unknown";
+ else if (!strcmp(ps, "COLUMNS"))
+ sprintf(xbuf, "%d", display ? D_width : -1);
+ else if (!strcmp(ps, "LINES"))
+ sprintf(xbuf, "%d", display ? D_height : -1);
+ else if (!strcmp(ps, "PID"))
+ sprintf(xbuf, "%d", getpid());
+ else if (!strcmp(ps, "PWD"))
+ {
+ if (getcwd(path, sizeof(path) - 1) == 0)
+ v = "?";
+ else
+ v = path;
+ }
+ else if (!strcmp(ps, "STY"))
+ {
+ if ((v = strchr(SockName, '.'))) /* Skip the PID */
+ v++;
+ else
+ v = SockName;
+ }
+ else
+ v = getenv(ps);
+ }
+ *pe = op;
+ vl = v ? strlen(v) : 0;
+ if (vl)
+ {
+ debug1("- sub is '%s'\n", v);
+ if (p - pp < vl)
+ {
+ int right = buf + bufl - (p + strlen(p) + 1);
+ if (right > 0)
+ {
+ bcopy(p, p + right, strlen(p) + 1);
+ p += right;
+ }
+ }
+ if (p - pp < vl)
+ {
+ Msg(0, "%s: no space left for variable expansion.", rc_name);
+ return 0;
+ }
+ bcopy(v, pp, vl);
+ pp += vl;
+ }
+ continue;
+ }
+ else if (delim != '\'' && *p == '^' && p[1])
+ {
+ p++;
+ *pp++ = *p == '?' ? '\177' : *p & 0x1f;
+ }
+ else if (delim == 0 && (*p == '\'' || *p == '"'))
+ delim = *p;
+ else if (delim == 0 && (*p == ' ' || *p == '\t' || *p == '\n'))
+ break;
+ else
+ *pp++ = *p;
+ p++;
+ }
+ if (delim)
+ {
+ Msg(0, "%s: Missing %c quote.", rc_name, delim);
+ return 0;
+ }
+ if (*p)
+ p++;
+ *pp = 0;
+ debug2("- arg done, '%s' rest %s\n", ap[-1], p);
+ *lp++ = pp - ap[-1];
+ pp++;
+ }
+}
+
+void
+SetEscape(u, e, me)
+struct acluser *u;
+int e, me;
+{
+ if (u)
+ {
+ u->u_Esc = e;
+ u->u_MetaEsc = me;
+ }
+ else
+ {
+ if (users)
+ {
+ if (DefaultEsc >= 0)
+ ClearAction(&ktab[DefaultEsc]);
+ if (DefaultMetaEsc >= 0)
+ ClearAction(&ktab[DefaultMetaEsc]);
+ }
+ DefaultEsc = e;
+ DefaultMetaEsc = me;
+ if (users)
+ {
+ if (DefaultEsc >= 0)
+ {
+ ClearAction(&ktab[DefaultEsc]);
+ ktab[DefaultEsc].nr = RC_OTHER;
+ }
+ if (DefaultMetaEsc >= 0)
+ {
+ ClearAction(&ktab[DefaultMetaEsc]);
+ ktab[DefaultMetaEsc].nr = RC_META;
+ }
+ }
+ }
+}
+
+int
+ParseSwitch(act, var)
+struct action *act;
+int *var;
+{
+ if (*act->args == 0)
+ {
+ *var ^= 1;
+ return 0;
+ }
+ return ParseOnOff(act, var);
+}
+
+static int
+ParseOnOff(act, var)
+struct action *act;
+int *var;
+{
+ register int num = -1;
+ char **args = act->args;
+
+ if (args[1] == 0)
+ {
+ if (strcmp(args[0], "on") == 0)
+ num = 1;
+ else if (strcmp(args[0], "off") == 0)
+ num = 0;
+ }
+ if (num < 0)
+ {
+ Msg(0, "%s: %s: invalid argument. Give 'on' or 'off'", rc_name, comms[act->nr].name);
+ return -1;
+ }
+ *var = num;
+ return 0;
+}
+
+int
+ParseSaveStr(act, var)
+struct action *act;
+char **var;
+{
+ char **args = act->args;
+ if (*args == 0 || args[1])
+ {
+ Msg(0, "%s: %s: one argument required.", rc_name, comms[act->nr].name);
+ return -1;
+ }
+ if (*var)
+ free(*var);
+ *var = SaveStr(*args);
+ return 0;
+}
+
+int
+ParseNum(act, var)
+struct action *act;
+int *var;
+{
+ int i;
+ char *p, **args = act->args;
+
+ p = *args;
+ if (p == 0 || *p == 0 || args[1])
+ {
+ Msg(0, "%s: %s: invalid argument. Give one argument.",
+ rc_name, comms[act->nr].name);
+ return -1;
+ }
+ i = 0;
+ while (*p)
+ {
+ if (*p >= '0' && *p <= '9')
+ i = 10 * i + (*p - '0');
+ else
+ {
+ Msg(0, "%s: %s: invalid argument. Give numeric argument.",
+ rc_name, comms[act->nr].name);
+ return -1;
+ }
+ p++;
+ }
+ debug1("ParseNum got %d\n", i);
+ *var = i;
+ return 0;
+}
+
+static int
+ParseNum1000(act, var)
+struct action *act;
+int *var;
+{
+ int i;
+ char *p, **args = act->args;
+ int dig = 0;
+
+ p = *args;
+ if (p == 0 || *p == 0 || args[1])
+ {
+ Msg(0, "%s: %s: invalid argument. Give one argument.",
+ rc_name, comms[act->nr].name);
+ return -1;
+ }
+ i = 0;
+ while (*p)
+ {
+ if (*p >= '0' && *p <= '9')
+ {
+ if (dig < 4)
+ i = 10 * i + (*p - '0');
+ else if (dig == 4 && *p >= '5')
+ i++;
+ if (dig)
+ dig++;
+ }
+ else if (*p == '.' && !dig)
+ dig++;
+ else
+ {
+ Msg(0, "%s: %s: invalid argument. Give floating point argument.",
+ rc_name, comms[act->nr].name);
+ return -1;
+ }
+ p++;
+ }
+ if (dig == 0)
+ i *= 1000;
+ else
+ while (dig++ < 4)
+ i *= 10;
+ if (i < 0)
+ i = (int)((unsigned int)~0 >> 1);
+ debug1("ParseNum1000 got %d\n", i);
+ *var = i;
+ return 0;
+}
+
+static struct win *
+WindowByName(s)
+char *s;
+{
+ struct win *p;
+
+ for (p = windows; p; p = p->w_next)
+ if (!strcmp(p->w_title, s))
+ return p;
+ for (p = windows; p; p = p->w_next)
+ if (!strncmp(p->w_title, s, strlen(s)))
+ return p;
+ return 0;
+}
+
+static int
+WindowByNumber(str)
+char *str;
+{
+ int i;
+ char *s;
+
+ for (i = 0, s = str; *s; s++)
+ {
+ if (*s < '0' || *s > '9')
+ break;
+ i = i * 10 + (*s - '0');
+ }
+ return *s ? -1 : i;
+}
+
+/*
+ * Get window number from Name or Number string.
+ * Numbers are tried first, then names, a prefix match suffices.
+ * Be careful when assigning numeric strings as WindowTitles.
+ */
+int
+WindowByNoN(str)
+char *str;
+{
+ int i;
+ struct win *p;
+
+ if ((i = WindowByNumber(str)) < 0 || i >= maxwin)
+ {
+ if ((p = WindowByName(str)))
+ return p->w_number;
+ return -1;
+ }
+ return i;
+}
+
+static int
+ParseWinNum(act, var)
+struct action *act;
+int *var;
+{
+ char **args = act->args;
+ int i = 0;
+
+ if (*args == 0 || args[1])
+ {
+ Msg(0, "%s: %s: one argument required.", rc_name, comms[act->nr].name);
+ return -1;
+ }
+
+ i = WindowByNoN(*args);
+ if (i < 0)
+ {
+ Msg(0, "%s: %s: invalid argument. Give window number or name.",
+ rc_name, comms[act->nr].name);
+ return -1;
+ }
+ debug1("ParseWinNum got %d\n", i);
+ *var = i;
+ return 0;
+}
+
+static int
+ParseBase(act, p, var, base, bname)
+struct action *act;
+char *p;
+int *var;
+int base;
+char *bname;
+{
+ int i = 0;
+ int c;
+
+ if (*p == 0)
+ {
+ Msg(0, "%s: %s: empty argument.", rc_name, comms[act->nr].name);
+ return -1;
+ }
+ while ((c = *p++))
+ {
+ if (c >= 'a' && c <= 'z')
+ c -= 'a' - 'A';
+ if (c >= 'A' && c <= 'Z')
+ c -= 'A' - ('0' + 10);
+ c -= '0';
+ if (c < 0 || c >= base)
+ {
+ Msg(0, "%s: %s: argument is not %s.", rc_name, comms[act->nr].name, bname);
+ return -1;
+ }
+ i = base * i + c;
+ }
+ debug1("ParseBase got %d\n", i);
+ *var = i;
+ return 0;
+}
+
+static int
+IsNum(s, base)
+register char *s;
+register int base;
+{
+ for (base += '0'; *s; ++s)
+ if (*s < '0' || *s > base)
+ return 0;
+ return 1;
+}
+
+int
+IsNumColon(s, base, p, psize)
+int base, psize;
+char *s, *p;
+{
+ char *q;
+ if ((q = rindex(s, ':')) != 0)
+ {
+ strncpy(p, q + 1, psize - 1);
+ p[psize - 1] = '\0';
+ *q = '\0';
+ }
+ else
+ *p = '\0';
+ return IsNum(s, base);
+}
+
+void
+SwitchWindow(n)
+int n;
+{
+ struct win *p;
+
+ debug1("SwitchWindow %d\n", n);
+ if (n < 0 || n >= maxwin)
+ {
+ ShowWindows(-1);
+ return;
+ }
+ if ((p = wtab[n]) == 0)
+ {
+ ShowWindows(n);
+ return;
+ }
+ if (display == 0)
+ {
+ fore = p;
+ return;
+ }
+ if (p == D_fore)
+ {
+ Msg(0, "This IS window %d (%s).", n, p->w_title);
+ return;
+ }
+#ifdef MULTIUSER
+ if (AclCheckPermWin(D_user, ACL_READ, p))
+ {
+ Msg(0, "Access to window %d denied.", p->w_number);
+ return;
+ }
+#endif
+ SetForeWindow(p);
+ Activate(fore->w_norefresh);
+}
+
+/*
+ * SetForeWindow changes the window in the input focus of the display.
+ * Puts window wi in canvas display->d_forecv.
+ */
+void
+SetForeWindow(wi)
+struct win *wi;
+{
+ struct win *p;
+ if (display == 0)
+ {
+ fore = wi;
+ return;
+ }
+ p = Layer2Window(D_forecv->c_layer);
+ SetCanvasWindow(D_forecv, wi);
+ if (p)
+ WindowChanged(p, 'u');
+ if (wi)
+ WindowChanged(wi, 'u');
+ flayer = D_forecv->c_layer;
+ /* Activate called afterwards, so no RefreshHStatus needed */
+}
+
+
+/*****************************************************************/
+
+/*
+ * Activate - make fore window active
+ * norefresh = -1 forces a refresh, disregard all_norefresh then.
+ */
+void
+Activate(norefresh)
+int norefresh;
+{
+ debug1("Activate(%d)\n", norefresh);
+ if (display == 0)
+ return;
+ if (D_status)
+ {
+ Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
+ RemoveStatus();
+ }
+
+ if (MayResizeLayer(D_forecv->c_layer))
+ ResizeLayer(D_forecv->c_layer, D_forecv->c_xe - D_forecv->c_xs + 1, D_forecv->c_ye - D_forecv->c_ys + 1, display);
+
+ fore = D_fore;
+ if (fore)
+ {
+ /* XXX ? */
+ if (fore->w_monitor != MON_OFF)
+ fore->w_monitor = MON_ON;
+ fore->w_bell = BELL_ON;
+ WindowChanged(fore, 'f');
+
+#if 0
+ if (ResizeDisplay(fore->w_width, fore->w_height))
+ {
+ debug2("Cannot resize from (%d,%d)", D_width, D_height);
+ debug2(" to (%d,%d) -> resize window\n", fore->w_width, fore->w_height);
+ DoResize(D_width, D_height);
+ }
+#endif
+ }
+ Redisplay(norefresh + all_norefresh);
+}
+
+
+static int
+NextWindow()
+{
+ register struct win **pp;
+ int n = fore ? fore->w_number : maxwin;
+ struct win *group = fore ? fore->w_group : 0;
+
+ for (pp = fore ? wtab + n + 1 : wtab; pp != wtab + n; pp++)
+ {
+ if (pp == wtab + maxwin)
+ pp = wtab;
+ if (*pp)
+ {
+ if (!fore || group == (*pp)->w_group)
+ break;
+ }
+ }
+ if (pp == wtab + n)
+ return -1;
+ return pp - wtab;
+}
+
+static int
+PreviousWindow()
+{
+ register struct win **pp;
+ int n = fore ? fore->w_number : -1;
+ struct win *group = fore ? fore->w_group : 0;
+
+ for (pp = wtab + n - 1; pp != wtab + n; pp--)
+ {
+ if (pp == wtab - 1)
+ pp = wtab + maxwin - 1;
+ if (*pp)
+ {
+ if (!fore || group == (*pp)->w_group)
+ break;
+ }
+ }
+ if (pp == wtab + n)
+ return -1;
+ return pp - wtab;
+}
+
+static int
+MoreWindows()
+{
+ char *m = "No other window.";
+ if (windows && (fore == 0 || windows->w_next))
+ return 1;
+ if (fore == 0)
+ {
+ Msg(0, "No window available");
+ return 0;
+ }
+ Msg(0, m, fore->w_number); /* other arg for nethack */
+ return 0;
+}
+
+void
+KillWindow(wi)
+struct win *wi;
+{
+ struct win **pp, *p;
+ struct canvas *cv;
+ int gotone;
+ struct layout *lay;
+
+ /*
+ * Remove window from linked list.
+ */
+ for (pp = &windows; (p = *pp); pp = &p->w_next)
+ if (p == wi)
+ break;
+ ASSERT(p);
+ *pp = p->w_next;
+ wi->w_inlen = 0;
+ wtab[wi->w_number] = 0;
+
+ if (windows == 0)
+ {
+ FreeWindow(wi);
+ Finit(0);
+ }
+
+ /*
+ * switch to different window on all canvases
+ */
+ for (display = displays; display; display = display->d_next)
+ {
+ gotone = 0;
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ {
+ if (Layer2Window(cv->c_layer) != wi)
+ continue;
+ /* switch to other window */
+ SetCanvasWindow(cv, FindNiceWindow(D_other, 0));
+ gotone = 1;
+ }
+ if (gotone)
+ {
+#ifdef ZMODEM
+ if (wi->w_zdisplay == display)
+ {
+ D_blocked = 0;
+ D_readev.condpos = D_readev.condneg = 0;
+ }
+#endif
+ Activate(-1);
+ }
+ }
+
+ /* do the same for the layouts */
+ for (lay = layouts; lay; lay = lay->lay_next)
+ UpdateLayoutCanvas(&lay->lay_canvas, wi);
+
+ FreeWindow(wi);
+ WindowChanged((struct win *)0, 'w');
+ WindowChanged((struct win *)0, 'W');
+ WindowChanged((struct win *)0, 0);
+}
+
+static void
+LogToggle(on)
+int on;
+{
+ char buf[1024];
+
+ if ((fore->w_log != 0) == on)
+ {
+ if (display && !*rc_name)
+ Msg(0, "You are %s logging.", on ? "already" : "not");
+ return;
+ }
+ if (fore->w_log != 0)
+ {
+ Msg(0, "Logfile \"%s\" closed.", fore->w_log->name);
+ logfclose(fore->w_log);
+ fore->w_log = 0;
+ WindowChanged(fore, 'f');
+ return;
+ }
+ if (DoStartLog(fore, buf, sizeof(buf)))
+ {
+ Msg(errno, "Error opening logfile \"%s\"", buf);
+ return;
+ }
+ if (ftell(fore->w_log->fp) == 0)
+ Msg(0, "Creating logfile \"%s\".", fore->w_log->name);
+ else
+ Msg(0, "Appending to logfile \"%s\".", fore->w_log->name);
+ WindowChanged(fore, 'f');
+}
+
+char *
+AddWindows(buf, len, flags, where)
+char *buf;
+int len;
+int flags;
+int where;
+{
+ register char *s, *ss;
+ register struct win **pp, *p;
+ register char *cmd;
+ int l;
+
+ s = ss = buf;
+ if ((flags & 8) && where < 0)
+ {
+ *s = 0;
+ return ss;
+ }
+ for (pp = ((flags & 4) && where >= 0) ? wtab + where + 1: wtab; pp < wtab + maxwin; pp++)
+ {
+ int rend = -1;
+ if (pp - wtab == where && ss == buf)
+ ss = s;
+ if ((p = *pp) == 0)
+ continue;
+ if ((flags & 1) && display && p == D_fore)
+ continue;
+ if (display && D_fore && D_fore->w_group != p->w_group)
+ continue;
+
+ cmd = p->w_title;
+ l = strlen(cmd);
+ if (l > 20)
+ l = 20;
+ if (s - buf + l > len - 24)
+ break;
+ if (s > buf || (flags & 4))
+ {
+ *s++ = ' ';
+ *s++ = ' ';
+ }
+ if (p->w_number == where)
+ {
+ ss = s;
+ if (flags & 8)
+ break;
+ }
+ if (!(flags & 4) || where < 0 || ((flags & 4) && where < p->w_number))
+ {
+ if (p->w_monitor == MON_DONE && renditions[REND_MONITOR] != -1)
+ rend = renditions[REND_MONITOR];
+ else if ((p->w_bell == BELL_DONE || p->w_bell == BELL_FOUND) && renditions[REND_BELL] != -1)
+ rend = renditions[REND_BELL];
+ else if ((p->w_silence == SILENCE_FOUND || p->w_silence == SILENCE_DONE) && renditions[REND_SILENCE] != -1)
+ rend = renditions[REND_SILENCE];
+ }
+ if (rend != -1)
+ AddWinMsgRend(s, rend);
+ sprintf(s, "%d", p->w_number);
+ s += strlen(s);
+ if (display && p == D_fore)
+ *s++ = '*';
+ if (!(flags & 2))
+ {
+ if (display && p == D_other)
+ *s++ = '-';
+ s = AddWindowFlags(s, len, p);
+ }
+ *s++ = ' ';
+ strncpy(s, cmd, l);
+ s += l;
+ if (rend != -1)
+ AddWinMsgRend(s, -1);
+ }
+ *s = 0;
+ return ss;
+}
+
+char *
+AddWindowFlags(buf, len, p)
+char *buf;
+int len;
+struct win *p;
+{
+ char *s = buf;
+ if (p == 0 || len < 12)
+ {
+ *s = 0;
+ return s;
+ }
+#if 0
+ if (display && p == D_fore)
+ *s++ = '*';
+ if (display && p == D_other)
+ *s++ = '-';
+#endif
+ if (p->w_layer.l_cvlist && p->w_layer.l_cvlist->c_lnext)
+ *s++ = '&';
+ if (p->w_monitor == MON_DONE
+#ifdef MULTIUSER
+ && display && (ACLBYTE(p->w_mon_notify, D_user->u_id) & ACLBIT(D_user->u_id))
+#endif
+ )
+ *s++ = '@';
+ if (p->w_bell == BELL_DONE)
+ *s++ = '!';
+#ifdef UTMPOK
+ if (p->w_slot != (slot_t) 0 && p->w_slot != (slot_t) -1)
+ *s++ = '$';
+#endif
+ if (p->w_log != 0)
+ {
+ strcpy(s, "(L)");
+ s += 3;
+ }
+ if (p->w_ptyfd < 0 && p->w_type != W_TYPE_GROUP)
+ *s++ = 'Z';
+ *s = 0;
+ return s;
+}
+
+char *
+AddOtherUsers(buf, len, p)
+char *buf;
+int len;
+struct win *p;
+{
+ struct display *d, *olddisplay = display;
+ struct canvas *cv;
+ char *s;
+ int l;
+
+ s = buf;
+ for (display = displays; display; display = display->d_next)
+ {
+ if (olddisplay && D_user == olddisplay->d_user)
+ continue;
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ if (Layer2Window(cv->c_layer) == p)
+ break;
+ if (!cv)
+ continue;
+ for (d = displays; d && d != display; d = d->d_next)
+ if (D_user == d->d_user)
+ break;
+ if (d && d != display)
+ continue;
+ if (len > 1 && s != buf)
+ {
+ *s++ = ',';
+ len--;
+ }
+ l = strlen(D_user->u_name);
+ if (l + 1 > len)
+ break;
+ strcpy(s, D_user->u_name);
+ s += l;
+ len -= l;
+ }
+ *s = 0;
+ display = olddisplay;
+ return s;
+}
+
+void
+ShowWindows(where)
+int where;
+{
+ char buf[1024];
+ char *s, *ss;
+
+ if (display && where == -1 && D_fore)
+ where = D_fore->w_number;
+ ss = AddWindows(buf, sizeof(buf), 0, where);
+ s = buf + strlen(buf);
+ if (display && ss - buf > D_width / 2)
+ {
+ ss -= D_width / 2;
+ if (s - ss < D_width)
+ {
+ ss = s - D_width;
+ if (ss < buf)
+ ss = buf;
+ }
+ }
+ else
+ ss = buf;
+ Msg(0, "%s", ss);
+}
+
+/*
+* String Escape based windows listing
+* mls: currently does a Msg() call for each(!) window, dunno why
+*/
+static void
+ShowWindowsX(str)
+char *str;
+{
+ int i;
+ debug1("ShowWindowsX: string [%s]", str);
+ for (i = 0; i < maxwin ; i++) {
+ if (!wtab[i])
+ continue;
+ Msg(0, "%s", MakeWinMsg(str, wtab[i], '%'));
+ }
+}
+
+
+static void
+ShowInfo()
+{
+ char buf[512], *p;
+ register struct win *wp = fore;
+ register int i;
+
+ if (wp == 0)
+ {
+ Msg(0, "(%d,%d)/(%d,%d) no window", D_x + 1, D_y + 1, D_width, D_height);
+ return;
+ }
+ p = buf;
+ if (buf < (p += GetAnsiStatus(wp, p)))
+ *p++ = ' ';
+ sprintf(p, "(%d,%d)/(%d,%d)",
+ wp->w_x + 1, wp->w_y + 1, wp->w_width, wp->w_height);
+#ifdef COPY_PASTE
+ sprintf(p += strlen(p), "+%d", wp->w_histheight);
+#endif
+ sprintf(p += strlen(p), " %c%sflow",
+ (wp->w_flow & FLOW_NOW) ? '+' : '-',
+ (wp->w_flow & FLOW_AUTOFLAG) ? "" :
+ ((wp->w_flow & FLOW_AUTO) ? "(+)" : "(-)"));
+ if (!wp->w_wrap) sprintf(p += strlen(p), " -wrap");
+ if (wp->w_insert) sprintf(p += strlen(p), " ins");
+ if (wp->w_origin) sprintf(p += strlen(p), " org");
+ if (wp->w_keypad) sprintf(p += strlen(p), " app");
+ if (wp->w_log) sprintf(p += strlen(p), " log");
+ if (wp->w_monitor != MON_OFF
+#ifdef MULTIUSER
+ && (ACLBYTE(wp->w_mon_notify, D_user->u_id) & ACLBIT(D_user->u_id))
+#endif
+ )
+ sprintf(p += strlen(p), " mon");
+ if (wp->w_mouse) sprintf(p += strlen(p), " mouse");
+#ifdef COLOR
+ if (wp->w_bce) sprintf(p += strlen(p), " bce");
+#endif
+ if (!wp->w_c1) sprintf(p += strlen(p), " -c1");
+ if (wp->w_norefresh) sprintf(p += strlen(p), " nored");
+
+ p += strlen(p);
+#ifdef FONT
+# ifdef ENCODINGS
+ if (wp->w_encoding && (display == 0 || D_encoding != wp->w_encoding || EncodingDefFont(wp->w_encoding) <= 0))
+ {
+ *p++ = ' ';
+ strcpy(p, EncodingName(wp->w_encoding));
+ p += strlen(p);
+ }
+# ifdef UTF8
+ if (wp->w_encoding != UTF8)
+# endif
+# endif
+ if (display && (D_CC0 || (D_CS0 && *D_CS0)))
+ {
+ if (wp->w_gr == 2)
+ {
+ sprintf(p, " G%c", wp->w_Charset + '0');
+ if (wp->w_FontE >= ' ')
+ p[3] = wp->w_FontE;
+ else
+ {
+ p[3] = '^';
+ p[4] = wp->w_FontE ^ 0x40;
+ p++;
+ }
+ p[4] = '[';
+ p++;
+ }
+ else if (wp->w_gr)
+ sprintf(p++, " G%c%c[", wp->w_Charset + '0', wp->w_CharsetR + '0');
+ else
+ sprintf(p, " G%c[", wp->w_Charset + '0');
+ p += 4;
+ for (i = 0; i < 4; i++)
+ {
+ if (wp->w_charsets[i] == ASCII)
+ *p++ = 'B';
+ else if (wp->w_charsets[i] >= ' ')
+ *p++ = wp->w_charsets[i];
+ else
+ {
+ *p++ = '^';
+ *p++ = wp->w_charsets[i] ^ 0x40;
+ }
+ }
+ *p++ = ']';
+ *p = 0;
+ }
+#endif
+
+ if (wp->w_type == W_TYPE_PLAIN)
+ {
+ /* add info about modem control lines */
+ *p++ = ' ';
+ TtyGetModemStatus(wp->w_ptyfd, p);
+ }
+#ifdef BUILTIN_TELNET
+ else if (wp->w_type == W_TYPE_TELNET)
+ {
+ *p++ = ' ';
+ TelStatus(wp, p, sizeof(buf) - 1 - (p - buf));
+ }
+#endif
+ Msg(0, "%s %d(%s)", buf, wp->w_number, wp->w_title);
+}
+
+static void
+ShowDInfo()
+{
+ char buf[512], *p;
+ if (display == 0)
+ return;
+ p = buf;
+ sprintf(p, "(%d,%d)", D_width, D_height),
+ p += strlen(p);
+#ifdef ENCODINGS
+ if (D_encoding)
+ {
+ *p++ = ' ';
+ strcpy(p, EncodingName(D_encoding));
+ p += strlen(p);
+ }
+#endif
+ if (D_CXT)
+ {
+ strcpy(p, " xterm");
+ p += strlen(p);
+ }
+#ifdef COLOR
+ if (D_hascolor)
+ {
+ strcpy(p, " color");
+ p += strlen(p);
+ }
+#endif
+#ifdef FONT
+ if (D_CG0)
+ {
+ strcpy(p, " iso2022");
+ p += strlen(p);
+ }
+ else if (D_CS0 && *D_CS0)
+ {
+ strcpy(p, " altchar");
+ p += strlen(p);
+ }
+#endif
+ Msg(0, "%s", buf);
+}
+
+static void
+AKAfin(buf, len, data)
+char *buf;
+int len;
+char *data; /* dummy */
+{
+ ASSERT(display);
+ if (len && fore)
+ ChangeAKA(fore, buf, strlen(buf));
+
+ enter_window_name_mode = 0;
+}
+
+static void
+InputAKA()
+{
+ char *s, *ss;
+ int n;
+
+ if (enter_window_name_mode == 1) return;
+
+ enter_window_name_mode = 1;
+
+ Input("Set window's title to: ", sizeof(fore->w_akabuf) - 1, INP_COOKED, AKAfin, NULL, 0);
+ s = fore->w_title;
+ if (!s)
+ return;
+ for (; *s; s++)
+ {
+ if ((*(unsigned char *)s & 0x7f) < 0x20 || *s == 0x7f)
+ continue;
+ ss = s;
+ n = 1;
+ LayProcess(&ss, &n);
+ }
+}
+
+static void
+Colonfin(buf, len, data)
+char *buf;
+int len;
+char *data; /* dummy */
+{
+ char mbuf[256];
+
+ RemoveStatus();
+ if (buf[len] == '\t')
+ {
+ int m, x;
+ int l = 0, r = RC_LAST;
+ int showmessage = 0;
+ char *s = buf;
+
+ while (*s && s - buf < len)
+ if (*s++ == ' ')
+ return;
+
+ /* Showing a message when there's no hardstatus or caption cancels the input */
+ if (display &&
+ (captionalways || D_has_hstatus == HSTATUS_LASTLINE || (D_canvas.c_slperp && D_canvas.c_slperp->c_slnext)))
+ showmessage = 1;
+
+ while (l <= r)
+ {
+ m = (l + r) / 2;
+ x = strncmp(buf, comms[m].name, len);
+ if (x > 0)
+ l = m + 1;
+ else if (x < 0)
+ r = m - 1;
+ else
+ {
+ s = mbuf;
+ for (l = m - 1; l >= 0 && strncmp(buf, comms[l].name, len) == 0; l--)
+ ;
+ for (m = ++l; m <= r && strncmp(buf, comms[m].name, len) == 0 && s - mbuf < sizeof(mbuf); m++)
+ s += snprintf(s, sizeof(mbuf) - (s - mbuf), " %s", comms[m].name);
+ if (l < m - 1)
+ {
+ if (showmessage)
+ Msg(0, "Possible commands:%s", mbuf);
+ }
+ else
+ {
+ s = mbuf;
+ len = snprintf(mbuf, sizeof(mbuf), "%s \t", comms[l].name + len);
+ if (len > 0 && len < sizeof(mbuf))
+ LayProcess(&s, &len);
+ }
+ break;
+ }
+ }
+ if (l > r && showmessage)
+ Msg(0, "No commands matching '%*s'", len, buf);
+ return;
+ }
+
+ if (!len || buf[len])
+ return;
+
+ len = strlen(buf) + 1;
+ if (len > (int)sizeof(mbuf))
+ RcLine(buf, len);
+ else
+ {
+ bcopy(buf, mbuf, len);
+ RcLine(mbuf, sizeof mbuf);
+ }
+}
+
+static void
+SelectFin(buf, len, data)
+char *buf;
+int len;
+char *data; /* dummy */
+{
+ int n;
+
+ if (!len || !display)
+ return;
+ if (len == 1 && *buf == '-')
+ {
+ SetForeWindow((struct win *)0);
+ Activate(0);
+ return;
+ }
+ if ((n = WindowByNoN(buf)) < 0)
+ return;
+ SwitchWindow(n);
+}
+
+static void
+SelectLayoutFin(buf, len, data)
+char *buf;
+int len;
+char *data; /* dummy */
+{
+ struct layout *lay;
+
+ if (!len || !display)
+ return;
+ if (len == 1 && *buf == '-')
+ {
+ LoadLayout((struct layout *)0, (struct canvas *)0);
+ Activate(0);
+ return;
+ }
+ lay = FindLayout(buf);
+ if (!lay)
+ Msg(0, "No such layout\n");
+ else if (lay == D_layout)
+ Msg(0, "This IS layout %d (%s).\n", lay->lay_number, lay->lay_title);
+ else
+ {
+ LoadLayout(lay, &D_canvas);
+ Activate(0);
+ }
+}
+
+
+static void
+InputSelect()
+{
+ Input("Switch to window: ", 20, INP_COOKED, SelectFin, NULL, 0);
+}
+
+static char setenv_var[31];
+
+
+static void
+SetenvFin1(buf, len, data)
+char *buf;
+int len;
+char *data; /* dummy */
+{
+ if (!len || !display)
+ return;
+ InputSetenv(buf);
+}
+
+static void
+SetenvFin2(buf, len, data)
+char *buf;
+int len;
+char *data; /* dummy */
+{
+ if (!len || !display)
+ return;
+ debug2("SetenvFin2: setenv '%s' '%s'\n", setenv_var, buf);
+ xsetenv(setenv_var, buf);
+ MakeNewEnv();
+}
+
+static void
+InputSetenv(arg)
+char *arg;
+{
+ static char setenv_buf[50 + sizeof(setenv_var)]; /* need to be static here, cannot be freed */
+
+ if (arg)
+ {
+ strncpy(setenv_var, arg, sizeof(setenv_var) - 1);
+ sprintf(setenv_buf, "Enter value for %s: ", setenv_var);
+ Input(setenv_buf, 30, INP_COOKED, SetenvFin2, NULL, 0);
+ }
+ else
+ Input("Setenv: Enter variable name: ", 30, INP_COOKED, SetenvFin1, NULL, 0);
+}
+
+/*
+ * the following options are understood by this parser:
+ * -f, -f0, -f1, -fy, -fa
+ * -t title, -T terminal-type, -h height-of-scrollback,
+ * -ln, -l0, -ly, -l1, -l
+ * -a, -M, -L
+ */
+void
+DoScreen(fn, av)
+char *fn, **av;
+{
+ struct NewWindow nwin;
+ register int num;
+ char buf[20];
+
+ nwin = nwin_undef;
+ while (av && *av && av[0][0] == '-')
+ {
+ if (av[0][1] == '-')
+ {
+ av++;
+ break;
+ }
+ switch (av[0][1])
+ {
+ case 'f':
+ switch (av[0][2])
+ {
+ case 'n':
+ case '0':
+ nwin.flowflag = FLOW_NOW * 0;
+ break;
+ case 'y':
+ case '1':
+ case '\0':
+ nwin.flowflag = FLOW_NOW * 1;
+ break;
+ case 'a':
+ nwin.flowflag = FLOW_AUTOFLAG;
+ break;
+ default:
+ break;
+ }
+ break;
+ case 't': /* no more -k */
+ if (av[0][2])
+ nwin.aka = &av[0][2];
+ else if (*++av)
+ nwin.aka = *av;
+ else
+ --av;
+ break;
+ case 'T':
+ if (av[0][2])
+ nwin.term = &av[0][2];
+ else if (*++av)
+ nwin.term = *av;
+ else
+ --av;
+ break;
+ case 'h':
+ if (av[0][2])
+ nwin.histheight = atoi(av[0] + 2);
+ else if (*++av)
+ nwin.histheight = atoi(*av);
+ else
+ --av;
+ break;
+#ifdef LOGOUTOK
+ case 'l':
+ switch (av[0][2])
+ {
+ case 'n':
+ case '0':
+ nwin.lflag = 0;
+ break;
+ case 'y':
+ case '1':
+ case '\0':
+ nwin.lflag = 1;
+ break;
+ case 'a':
+ nwin.lflag = 3;
+ break;
+ default:
+ break;
+ }
+ break;
+#endif
+ case 'a':
+ nwin.aflag = 1;
+ break;
+ case 'M':
+ nwin.monitor = MON_ON;
+ break;
+ case 'L':
+ nwin.Lflag = 1;
+ break;
+ default:
+ Msg(0, "%s: screen: invalid option -%c.", fn, av[0][1]);
+ break;
+ }
+ ++av;
+ }
+ if (av && *av && IsNumColon(*av, 10, buf, sizeof(buf)))
+ {
+ if (*buf != '\0')
+ nwin.aka = buf;
+ num = atoi(*av);
+ if (num < 0 || (maxwin && num > maxwin - 1) || (!maxwin && num > MAXWIN - 1))
+ {
+ Msg(0, "%s: illegal screen number %d.", fn, num);
+ num = 0;
+ }
+ nwin.StartAt = num;
+ ++av;
+ }
+ if (av && *av)
+ {
+ nwin.args = av;
+ if (!nwin.aka)
+ nwin.aka = Filename(*av);
+ }
+ MakeWindow(&nwin);
+}
+
+#ifdef COPY_PASTE
+/*
+ * CompileKeys must be called before Markroutine is first used.
+ * to initialise the keys with defaults, call CompileKeys(NULL, mark_key_tab);
+ *
+ * s is an ascii string in a termcap-like syntax. It looks like
+ * "j=u:k=d:l=r:h=l: =.:" and so on...
+ * this example rebinds the cursormovement to the keys u (up), d (down),
+ * l (left), r (right). placing a mark will now be done with ".".
+ */
+int
+CompileKeys(s, sl, array)
+char *s;
+int sl;
+unsigned char *array;
+{
+ int i;
+ unsigned char key, value;
+
+ if (sl == 0)
+ {
+ for (i = 0; i < 256; i++)
+ array[i] = i;
+ return 0;
+ }
+ debug1("CompileKeys: '%s'\n", s);
+ while (sl)
+ {
+ key = *(unsigned char *)s++;
+ if (*s != '=' || sl < 3)
+ return -1;
+ sl--;
+ do
+ {
+ s++;
+ sl -= 2;
+ value = *(unsigned char *)s++;
+ array[value] = key;
+ }
+ while (*s == '=' && sl >= 2);
+ if (sl == 0)
+ break;
+ if (*s++ != ':')
+ return -1;
+ sl--;
+ }
+ return 0;
+}
+#endif /* COPY_PASTE */
+
+/*
+ * Asynchronous input functions
+ */
+
+#if defined(DETACH) && defined(POW_DETACH)
+static void
+pow_detach_fn(buf, len, data)
+char *buf;
+int len;
+char *data; /* dummy */
+{
+ debug("pow_detach_fn called\n");
+ if (len)
+ {
+ *buf = 0;
+ return;
+ }
+ if (ktab[(int)(unsigned char)*buf].nr != RC_POW_DETACH)
+ {
+ if (display)
+ write(D_userfd, "\007", 1);
+ Msg(0, "Detach aborted.");
+ }
+ else
+ Detach(D_POWER);
+}
+#endif /* POW_DETACH */
+
+#ifdef COPY_PASTE
+static void
+copy_reg_fn(buf, len, data)
+char *buf;
+int len;
+char *data; /* dummy */
+{
+ struct plop *pp = plop_tab + (int)(unsigned char)*buf;
+
+ if (len)
+ {
+ *buf = 0;
+ return;
+ }
+ if (pp->buf)
+ free(pp->buf);
+ pp->buf = 0;
+ pp->len = 0;
+ if (D_user->u_plop.len)
+ {
+ if ((pp->buf = (char *)malloc(D_user->u_plop.len)) == NULL)
+ {
+ Msg(0, "%s", strnomem);
+ return;
+ }
+ bcopy(D_user->u_plop.buf, pp->buf, D_user->u_plop.len);
+ }
+ pp->len = D_user->u_plop.len;
+#ifdef ENCODINGS
+ pp->enc = D_user->u_plop.enc;
+#endif
+ Msg(0, "Copied %d characters into register %c", D_user->u_plop.len, *buf);
+}
+
+static void
+ins_reg_fn(buf, len, data)
+char *buf;
+int len;
+char *data; /* dummy */
+{
+ struct plop *pp = plop_tab + (int)(unsigned char)*buf;
+
+ if (len)
+ {
+ *buf = 0;
+ return;
+ }
+ if (!fore)
+ return; /* Input() should not call us w/o fore, but you never know... */
+ if (*buf == '.')
+ Msg(0, "ins_reg_fn: Warning: pasting real register '.'!");
+ if (pp->buf)
+ {
+ MakePaster(&fore->w_paster, pp->buf, pp->len, 0);
+ return;
+ }
+ Msg(0, "Empty register.");
+}
+#endif /* COPY_PASTE */
+
+static void
+process_fn(buf, len, data)
+char *buf;
+int len;
+char *data; /* dummy */
+{
+ struct plop *pp = plop_tab + (int)(unsigned char)*buf;
+
+ if (len)
+ {
+ *buf = 0;
+ return;
+ }
+ if (pp->buf)
+ {
+ ProcessInput(pp->buf, pp->len);
+ return;
+ }
+ Msg(0, "Empty register.");
+}
+
+static void
+confirm_fn(buf, len, data)
+char *buf;
+int len;
+char *data;
+{
+ struct action act;
+
+ if (len || (*buf != 'y' && *buf != 'Y'))
+ {
+ *buf = 0;
+ return;
+ }
+ act.nr = *(int *)data;
+ act.args = noargs;
+ act.argl = 0;
+ act.quiet = 0;
+ DoAction(&act, -1);
+}
+
+#ifdef MULTIUSER
+struct inputsu
+{
+ struct acluser **up;
+ char name[24];
+ char pw1[130]; /* FreeBSD crypts to 128 bytes */
+ char pw2[130];
+};
+
+static void
+su_fin(buf, len, data)
+char *buf;
+int len;
+char *data;
+{
+ struct inputsu *i = (struct inputsu *)data;
+ char *p;
+ int l;
+
+ if (!*i->name)
+ { p = i->name; l = sizeof(i->name) - 1; }
+ else if (!*i->pw1)
+ { strcpy(p = i->pw1, "\377"); l = sizeof(i->pw1) - 1; }
+ else
+ { strcpy(p = i->pw2, "\377"); l = sizeof(i->pw2) - 1; }
+ if (buf && len)
+ strncpy(p, buf, 1 + ((l < len) ? l : len));
+ if (!*i->name)
+ Input("Screen User: ", sizeof(i->name) - 1, INP_COOKED, su_fin, (char *)i, 0);
+ else if (!*i->pw1)
+ Input("User's UNIX Password: ", sizeof(i->pw1)-1, INP_COOKED|INP_NOECHO, su_fin, (char *)i, 0);
+ else if (!*i->pw2)
+ Input("User's Screen Password: ", sizeof(i->pw2)-1, INP_COOKED|INP_NOECHO, su_fin, (char *)i, 0);
+ else
+ {
+ if ((p = DoSu(i->up, i->name, i->pw2, i->pw1)))
+ Msg(0, "%s", p);
+ free((char *)i);
+ }
+}
+
+static int
+InputSu(w, up, name)
+struct win *w;
+struct acluser **up;
+char *name;
+{
+ struct inputsu *i;
+
+ if (!(i = (struct inputsu *)calloc(1, sizeof(struct inputsu))))
+ return -1;
+
+ i->up = up;
+ if (name && *name)
+ su_fin(name, (int)strlen(name), (char *)i); /* can also initialise stuff */
+ else
+ su_fin((char *)0, 0, (char *)i);
+ return 0;
+}
+#endif /* MULTIUSER */
+
+#ifdef PASSWORD
+
+static void
+pass1(buf, len, data)
+char *buf;
+int len;
+char *data;
+{
+ struct acluser *u = (struct acluser *)data;
+
+ if (!*buf)
+ return;
+ ASSERT(u);
+ if (u->u_password != NullStr)
+ free((char *)u->u_password);
+ u->u_password = SaveStr(buf);
+ bzero(buf, strlen(buf));
+ Input("Retype new password:", 100, INP_NOECHO, pass2, data, 0);
+}
+
+static void
+pass2(buf, len, data)
+char *buf;
+int len;
+char *data;
+{
+ int st;
+ char salt[3];
+ struct acluser *u = (struct acluser *)data;
+
+ ASSERT(u);
+ if (!buf || strcmp(u->u_password, buf))
+ {
+ Msg(0, "[ Passwords don't match - checking turned off ]");
+ if (u->u_password != NullStr)
+ {
+ bzero(u->u_password, strlen(u->u_password));
+ free((char *)u->u_password);
+ }
+ u->u_password = NullStr;
+ }
+ else if (u->u_password[0] == '\0')
+ {
+ Msg(0, "[ No password - no secure ]");
+ if (buf)
+ bzero(buf, strlen(buf));
+ }
+
+ if (u->u_password != NullStr)
+ {
+ for (st = 0; st < 2; st++)
+ salt[st] = 'A' + (int)((time(0) >> 6 * st) % 26);
+ salt[2] = 0;
+ buf = crypt(u->u_password, salt);
+ bzero(u->u_password, strlen(u->u_password));
+ free((char *)u->u_password);
+ if (!buf)
+ {
+ Msg(0, "[ crypt() error - no secure ]");
+ u->u_password = NullStr;
+ return;
+ }
+ u->u_password = SaveStr(buf);
+ bzero(buf, strlen(buf));
+#ifdef COPY_PASTE
+ if (u->u_plop.buf)
+ UserFreeCopyBuffer(u);
+ u->u_plop.len = strlen(u->u_password);
+# ifdef ENCODINGS
+ u->u_plop.enc = 0;
+#endif
+ if (!(u->u_plop.buf = SaveStr(u->u_password)))
+ {
+ Msg(0, "%s", strnomem);
+ D_user->u_plop.len = 0;
+ }
+ else
+ Msg(0, "[ Password moved into copybuffer ]");
+#else /* COPY_PASTE */
+ Msg(0, "[ Crypted password is \"%s\" ]", u->u_password);
+#endif /* COPY_PASTE */
+ }
+}
+#endif /* PASSWORD */
+
+static int
+digraph_find(buf)
+const char *buf;
+{
+ int i;
+ for (i = 0; i < MAX_DIGRAPH && digraphs[i].d[0]; i++)
+ if ((digraphs[i].d[0] == (unsigned char)buf[0] && digraphs[i].d[1] == (unsigned char)buf[1]) ||
+ (digraphs[i].d[0] == (unsigned char)buf[1] && digraphs[i].d[1] == (unsigned char)buf[0]))
+ break;
+ return i;
+}
+
+static void
+digraph_fn(buf, len, data)
+char *buf;
+int len;
+char *data; /* dummy */
+{
+ int ch, i, x;
+
+ ch = buf[len];
+ if (ch)
+ {
+ buf[len + 1] = ch; /* so we can restore it later */
+ if (ch < ' ' || ch == '\177')
+ return;
+ if (len >= 1 && ((*buf == 'U' && buf[1] == '+') || (*buf == '0' && (buf[1] == 'x' || buf[1] == 'X'))))
+ {
+ if (len == 1)
+ return;
+ if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f') && (ch < 'A' || ch > 'F'))
+ {
+ buf[len] = '\034'; /* ^] is ignored by Input() */
+ return;
+ }
+ if (len == (*buf == 'U' ? 5 : 3))
+ buf[len] = '\n';
+ return;
+ }
+ if (len && *buf == '0')
+ {
+ if (ch < '0' || ch > '7')
+ {
+ buf[len] = '\034'; /* ^] is ignored by Input() */
+ return;
+ }
+ if (len == 3)
+ buf[len] = '\n';
+ return;
+ }
+ if (len == 1)
+ buf[len] = '\n';
+ return;
+ }
+ if (len < 1)
+ return;
+ if (buf[len + 1])
+ {
+ buf[len] = buf[len + 1]; /* stored above */
+ len++;
+ }
+ if (len < 2)
+ return;
+ if (!parse_input_int(buf, len, &x))
+ {
+ i = digraph_find(buf);
+ if ((x = digraphs[i].value) <= 0)
+ {
+ Msg(0, "Unknown digraph");
+ return;
+ }
+ }
+ i = 1;
+ *buf = x;
+#ifdef UTF8
+ if (flayer->l_encoding == UTF8)
+ i = ToUtf8(buf, x); /* buf is big enough for all UTF-8 codes */
+#endif
+ while(i)
+ LayProcess(&buf, &i);
+}
+
+#ifdef MAPKEYS
+int
+StuffKey(i)
+int i;
+{
+ struct action *act;
+ int discard = 0;
+ int keyno = i;
+
+ debug1("StuffKey #%d", i);
+#ifdef DEBUG
+ if (i < KMAP_KEYS)
+ debug1(" - %s", term[i + T_CAPS].tcname);
+#endif
+
+ if (i < KMAP_KEYS && D_ESCseen)
+ {
+ struct action *act = &D_ESCseen[i + 256];
+ if (act->nr != RC_ILLEGAL)
+ {
+ D_ESCseen = 0;
+ WindowChanged(fore, 'E');
+ DoAction(act, i + 256);
+ return 0;
+ }
+ discard = 1;
+ }
+
+ if (i >= T_CURSOR - T_CAPS && i < T_KEYPAD - T_CAPS && D_cursorkeys)
+ i += T_OCAPS - T_CURSOR;
+ else if (i >= T_KEYPAD - T_CAPS && i < T_OCAPS - T_CAPS && D_keypad)
+ i += T_OCAPS - T_CURSOR;
+ debug1(" - action %d\n", i);
+ flayer = D_forecv->c_layer;
+ fore = D_fore;
+ act = 0;
+#ifdef COPY_PASTE
+ if (flayer && flayer->l_mode == 1)
+ act = i < KMAP_KEYS+KMAP_AKEYS ? &mmtab[i] : &kmap_exts[i - (KMAP_KEYS+KMAP_AKEYS)].mm;
+#endif
+ if ((!act || act->nr == RC_ILLEGAL) && !D_mapdefault)
+ act = i < KMAP_KEYS+KMAP_AKEYS ? &umtab[i] : &kmap_exts[i - (KMAP_KEYS+KMAP_AKEYS)].um;
+ if (!act || act->nr == RC_ILLEGAL)
+ act = i < KMAP_KEYS+KMAP_AKEYS ? &dmtab[i] : &kmap_exts[i - (KMAP_KEYS+KMAP_AKEYS)].dm;
+
+ if (discard && (!act || act->nr != RC_COMMAND))
+ {
+ /* if the input was just a single byte we let it through */
+ if (D_tcs[keyno + T_CAPS].str && strlen(D_tcs[keyno + T_CAPS].str) == 1)
+ return -1;
+ if (D_ESCseen)
+ {
+ D_ESCseen = 0;
+ WindowChanged(fore, 'E');
+ }
+ return 0;
+ }
+ D_mapdefault = 0;
+
+ if (act == 0 || act->nr == RC_ILLEGAL)
+ return -1;
+ DoAction(act, 0);
+ return 0;
+}
+#endif
+
+
+static int
+IsOnDisplay(wi)
+struct win *wi;
+{
+ struct canvas *cv;
+ ASSERT(display);
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ if (Layer2Window(cv->c_layer) == wi)
+ return 1;
+ return 0;
+}
+
+struct win *
+FindNiceWindow(wi, presel)
+struct win *wi;
+char *presel;
+{
+ int i;
+
+ debug2("FindNiceWindow %d %s\n", wi ? wi->w_number : -1 , presel ? presel : "NULL");
+ if (presel)
+ {
+ i = WindowByNoN(presel);
+ if (i >= 0)
+ wi = wtab[i];
+ }
+ if (!display)
+ return wi;
+#ifdef MULTIUSER
+ if (wi && AclCheckPermWin(D_user, ACL_READ, wi))
+ wi = 0;
+#endif
+ if (!wi || (IsOnDisplay(wi) && !presel))
+ {
+ /* try to get another window */
+ wi = 0;
+#ifdef MULTIUSER
+ for (wi = windows; wi; wi = wi->w_next)
+ if (!wi->w_layer.l_cvlist && !AclCheckPermWin(D_user, ACL_WRITE, wi))
+ break;
+ if (!wi)
+ for (wi = windows; wi; wi = wi->w_next)
+ if (wi->w_layer.l_cvlist && !IsOnDisplay(wi) && !AclCheckPermWin(D_user, ACL_WRITE, wi))
+ break;
+ if (!wi)
+ for (wi = windows; wi; wi = wi->w_next)
+ if (!wi->w_layer.l_cvlist && !AclCheckPermWin(D_user, ACL_READ, wi))
+ break;
+ if (!wi)
+ for (wi = windows; wi; wi = wi->w_next)
+ if (wi->w_layer.l_cvlist && !IsOnDisplay(wi) && !AclCheckPermWin(D_user, ACL_READ, wi))
+ break;
+#endif
+ if (!wi)
+ for (wi = windows; wi; wi = wi->w_next)
+ if (!wi->w_layer.l_cvlist)
+ break;
+ if (!wi)
+ for (wi = windows; wi; wi = wi->w_next)
+ if (wi->w_layer.l_cvlist && !IsOnDisplay(wi))
+ break;
+ }
+#ifdef MULTIUSER
+ if (wi && AclCheckPermWin(D_user, ACL_READ, wi))
+ wi = 0;
+#endif
+ return wi;
+}
+
+#if 0
+
+/* sorted list of all commands */
+static struct comm **commtab;
+static int ncommtab;
+
+void
+AddComms(cos, hand)
+struct comm *cos;
+void (*hand) __P((struct comm *, char **, int));
+{
+ int n, i, j, r;
+ for (n = 0; cos[n].name; n++)
+ ;
+ if (n == 0)
+ return;
+ if (commtab)
+ commtab = (struct commt *)realloc(commtab, sizeof(*commtab) * (ncommtab + n));
+ else
+ commtab = (struct commt *)malloc(sizeof(*commtab) * (ncommtab + n));
+ if (!commtab)
+ Panic(0, strnomem);
+ for (i = 0; i < n; i++)
+ {
+ for (j = 0; j < ncommtab; j++)
+ {
+ r = strcmp(cos[i].name, commtab[j]->name);
+ if (r == 0)
+ Panic(0, "Duplicate command: %s\n", cos[i].name);
+ if (r < 0)
+ break;
+ }
+ for (r = ncommtab; r > j; r--)
+ commtab[r] = commtab[r - 1];
+ commtab[j] = cos + i;
+ cos[i].handler = hand;
+ bzero(cos[i].userbits, sizeof(cos[i].userbits));
+ ncommtab++;
+ }
+}
+
+struct comm *
+FindComm(str)
+char *str;
+{
+ int x, m, l = 0, r = ncommtab - 1;
+ while (l <= r)
+ {
+ m = (l + r) / 2;
+ x = strcmp(str, commtab[m]->name);
+ if (x > 0)
+ l = m + 1;
+ else if (x < 0)
+ r = m - 1;
+ else
+ return commtab[m];
+ }
+ return 0;
+}
+
+#endif
+
+static int
+CalcSlicePercent(cv, percent)
+struct canvas *cv;
+int percent;
+{
+ int w, wsum, up;
+ if (!cv || !cv->c_slback)
+ return percent;
+ up = CalcSlicePercent(cv->c_slback->c_slback, percent);
+ w = cv->c_slweight;
+ for (cv = cv->c_slback->c_slperp, wsum = 0; cv; cv = cv->c_slnext)
+ wsum += cv->c_slweight;
+ if (wsum == 0)
+ return 0;
+ return (up * w) / wsum;
+}
+
+static int
+ChangeCanvasSize(fcv, abs, diff, gflag, percent)
+struct canvas *fcv; /* make this canvas bigger */
+int abs; /* mode: 0:rel 1:abs 2:max */
+int diff; /* change this much */
+int gflag; /* go up if neccessary */
+int percent;
+{
+ struct canvas *cv;
+ int done, have, m, dir;
+
+ debug3("ChangeCanvasSize abs %d diff %d percent=%d\n", abs, diff, percent);
+ if (abs == 0 && diff == 0)
+ return 0;
+ if (abs == 2)
+ {
+ if (diff == 0)
+ fcv->c_slweight = 0;
+ else
+ {
+ for (cv = fcv->c_slback->c_slperp; cv; cv = cv->c_slnext)
+ cv->c_slweight = 0;
+ fcv->c_slweight = 1;
+ cv = fcv->c_slback->c_slback;
+ if (gflag && cv && cv->c_slback)
+ ChangeCanvasSize(cv, abs, diff, gflag, percent);
+ }
+ return diff;
+ }
+ if (abs)
+ {
+ if (diff < 0)
+ diff = 0;
+ if (percent && diff > percent)
+ diff = percent;
+ }
+ if (percent)
+ {
+ int wsum, up;
+ for (cv = fcv->c_slback->c_slperp, wsum = 0; cv; cv = cv->c_slnext)
+ wsum += cv->c_slweight;
+ if (wsum)
+ {
+ up = gflag ? CalcSlicePercent(fcv->c_slback->c_slback, percent) : percent;
+ debug3("up=%d, wsum=%d percent=%d\n", up, wsum, percent);
+ if (wsum < 1000)
+ {
+ int scale = wsum < 10 ? 1000 : 100;
+ for (cv = fcv->c_slback->c_slperp; cv; cv = cv->c_slnext)
+ cv->c_slweight *= scale;
+ wsum *= scale;
+ debug1("scaled wsum to %d\n", wsum);
+ }
+ for (cv = fcv->c_slback->c_slperp; cv; cv = cv->c_slnext)
+ {
+ if (cv->c_slweight)
+ {
+ cv->c_slweight = (cv->c_slweight * up) / percent;
+ if (cv->c_slweight == 0)
+ cv->c_slweight = 1;
+ }
+ debug1(" - weight %d\n", cv->c_slweight);
+ }
+ diff = (diff * wsum) / percent;
+ percent = wsum;
+ }
+ }
+ else
+ {
+ if (abs && diff == (fcv->c_slorient == SLICE_VERT ? fcv->c_ye - fcv->c_ys + 2 : fcv->c_xe - fcv->c_xs + 2))
+ return 0;
+ /* fix weights to real size (can't be helped, sorry) */
+ for (cv = fcv->c_slback->c_slperp; cv; cv = cv->c_slnext)
+ {
+ cv->c_slweight = cv->c_slorient == SLICE_VERT ? cv->c_ye - cv->c_ys + 2 : cv->c_xe - cv->c_xs + 2;
+ debug1(" - weight %d\n", cv->c_slweight);
+ }
+ }
+ if (abs)
+ diff = diff - fcv->c_slweight;
+ debug1("diff = %d\n", diff);
+ if (diff == 0)
+ return 0;
+ if (diff < 0)
+ {
+ cv = fcv->c_slnext ? fcv->c_slnext : fcv->c_slprev;
+ fcv->c_slweight += diff;
+ cv->c_slweight -= diff;
+ return diff;
+ }
+ done = 0;
+ dir = 1;
+ for (cv = fcv->c_slnext; diff > 0; cv = dir > 0 ? cv->c_slnext : cv->c_slprev)
+ {
+ if (!cv)
+ {
+ debug1("reached end, dir is %d\n", dir);
+ if (dir == -1)
+ break;
+ dir = -1;
+ cv = fcv;
+ continue;
+ }
+ if (percent)
+ m = 1;
+ else
+ m = cv->c_slperp ? CountCanvasPerp(cv) * 2 : 2;
+ debug2("min is %d, have %d\n", m, cv->c_slweight);
+ if (cv->c_slweight > m)
+ {
+ have = cv->c_slweight - m;
+ if (have > diff)
+ have = diff;
+ debug1("subtract %d\n", have);
+ cv->c_slweight -= have;
+ done += have;
+ diff -= have;
+ }
+ }
+ if (diff && gflag)
+ {
+ /* need more room! */
+ cv = fcv->c_slback->c_slback;
+ if (cv && cv->c_slback)
+ done += ChangeCanvasSize(fcv->c_slback->c_slback, 0, diff, gflag, percent);
+ }
+ fcv->c_slweight += done;
+ debug1("ChangeCanvasSize returns %d\n", done);
+ return done;
+}
+
+static void
+ResizeRegions(arg, flags)
+char *arg;
+int flags;
+{
+ struct canvas *cv;
+ int diff, l;
+ int gflag = 0, abs = 0, percent = 0;
+ int orient = 0;
+
+ ASSERT(display);
+ if (!*arg)
+ return;
+ if (D_forecv->c_slorient == SLICE_UNKN)
+ {
+ Msg(0, "resize: need more than one region");
+ return;
+ }
+ gflag = flags & RESIZE_FLAG_L ? 0 : 1;
+ orient |= flags & RESIZE_FLAG_H ? SLICE_HORI : 0;
+ orient |= flags & RESIZE_FLAG_V ? SLICE_VERT : 0;
+ if (orient == 0)
+ orient = D_forecv->c_slorient;
+ l = strlen(arg);
+ if (*arg == '=')
+ {
+ /* make all regions the same height */
+ struct canvas *cv = gflag ? &D_canvas : D_forecv->c_slback;
+ if (cv->c_slperp->c_slorient & orient)
+ EqualizeCanvas(cv->c_slperp, gflag);
+ /* can't use cv->c_slorient directly as it can be D_canvas */
+ if ((cv->c_slperp->c_slorient ^ (SLICE_HORI ^ SLICE_VERT)) & orient)
+ {
+ if (cv->c_slback)
+ {
+ cv = cv->c_slback;
+ EqualizeCanvas(cv->c_slperp, gflag);
+ }
+ else
+ EqualizeCanvas(cv, gflag);
+ }
+ ResizeCanvas(cv);
+ RecreateCanvasChain();
+ RethinkDisplayViewports();
+ ResizeLayersToCanvases();
+ return;
+ }
+ if (!strcmp(arg, "min") || !strcmp(arg, "0"))
+ {
+ abs = 2;
+ diff = 0;
+ }
+ else if (!strcmp(arg, "max") || !strcmp(arg, "_"))
+ {
+ abs = 2;
+ diff = 1;
+ }
+ else
+ {
+ if (l > 0 && arg[l - 1] == '%')
+ percent = 1000;
+ if (*arg == '+')
+ diff = atoi(arg + 1);
+ else if (*arg == '-')
+ diff = -atoi(arg + 1);
+ else
+ {
+ diff = atoi(arg); /* +1 because of caption line */
+ if (diff < 0)
+ diff = 0;
+ abs = diff == 0 ? 2 : 1;
+ }
+ }
+ if (!abs && !diff)
+ return;
+ if (percent)
+ diff = diff * percent / 100;
+ cv = D_forecv;
+ if (cv->c_slorient & orient)
+ ChangeCanvasSize(cv, abs, diff, gflag, percent);
+ if (cv->c_slback->c_slorient & orient)
+ ChangeCanvasSize(cv->c_slback, abs, diff, gflag, percent);
+
+ ResizeCanvas(&D_canvas);
+ RecreateCanvasChain();
+ RethinkDisplayViewports();
+ ResizeLayersToCanvases();
+ return;
+
+#if 0
+
+ if (siz + diff < 1)
+ diff = 1 - siz;
+ if (siz + diff > dsize - (nreg - 1) * 2 - 1)
+ diff = dsize - (nreg - 1) * 2 - 1 - siz;
+ if (diff == 0 || siz + diff < 1)
+ return;
+
+ if (diff < 0)
+ {
+ if (D_forecv->c_next)
+ {
+ D_forecv->c_ye += diff;
+ D_forecv->c_next->c_ys += diff;
+ D_forecv->c_next->c_yoff += diff;
+ }
+ else
+ {
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ if (cv->c_next == D_forecv)
+ break;
+ ASSERT(cv);
+ cv->c_ye -= diff;
+ D_forecv->c_ys -= diff;
+ D_forecv->c_yoff -= diff;
+ }
+ }
+ else
+ {
+ int s, i = 0, found = 0, di = diff, d2;
+ s = dsize - (nreg - 1) * 2 - 1 - siz;
+ for (cv = D_cvlist; cv; i = cv->c_ye + 2, cv = cv->c_next)
+ {
+ if (cv == D_forecv)
+ {
+ cv->c_ye = i + (cv->c_ye - cv->c_ys) + diff;
+ cv->c_yoff -= cv->c_ys - i;
+ cv->c_ys = i;
+ found = 1;
+ continue;
+ }
+ s -= cv->c_ye - cv->c_ys;
+ if (!found)
+ {
+ if (s >= di)
+ continue;
+ d2 = di - s;
+ }
+ else
+ d2 = di > cv->c_ye - cv->c_ys ? cv->c_ye - cv->c_ys : di;
+ di -= d2;
+ cv->c_ye = i + (cv->c_ye - cv->c_ys) - d2;
+ cv->c_yoff -= cv->c_ys - i;
+ cv->c_ys = i;
+ }
+ }
+ RethinkDisplayViewports();
+ ResizeLayersToCanvases();
+#endif
+}
+
+static void
+ResizeFin(buf, len, data)
+char *buf;
+int len;
+char *data;
+{
+ int ch;
+ int flags = *(int *)data;
+ ch = ((unsigned char *)buf)[len];
+ if (ch == 0)
+ {
+ ResizeRegions(buf, flags);
+ return;
+ }
+ if (ch == 'h')
+ flags ^= RESIZE_FLAG_H;
+ else if (ch == 'v')
+ flags ^= RESIZE_FLAG_V;
+ else if (ch == 'b')
+ flags |= RESIZE_FLAG_H|RESIZE_FLAG_V;
+ else if (ch == 'p')
+ flags ^= D_forecv->c_slorient == SLICE_VERT ? RESIZE_FLAG_H : RESIZE_FLAG_V;
+ else if (ch == 'l')
+ flags ^= RESIZE_FLAG_L;
+ else
+ return;
+ inp_setprompt(resizeprompts[flags], NULL);
+ *(int *)data = flags;
+ buf[len] = '\034';
+}
+
+void
+SetForeCanvas(d, cv)
+struct display *d;
+struct canvas *cv;
+{
+ struct display *odisplay = display;
+ if (d->d_forecv == cv)
+ return;
+
+ display = d;
+ D_forecv = cv;
+ if ((focusminwidth && (focusminwidth < 0 || D_forecv->c_xe - D_forecv->c_xs + 1 < focusminwidth)) ||
+ (focusminheight && (focusminheight < 0 || D_forecv->c_ye - D_forecv->c_ys + 1 < focusminheight)))
+ {
+ ResizeCanvas(&D_canvas);
+ RecreateCanvasChain();
+ RethinkDisplayViewports();
+ ResizeLayersToCanvases(); /* redisplays */
+ }
+ fore = D_fore = Layer2Window(D_forecv->c_layer);
+ if (D_other == fore)
+ D_other = 0;
+ flayer = D_forecv->c_layer;
+#ifdef RXVT_OSC
+ if (D_xtermosc[2] || D_xtermosc[3])
+ {
+ Activate(-1);
+ }
+ else
+#endif
+ {
+ RefreshHStatus();
+#ifdef RXVT_OSC
+ RefreshXtermOSC();
+#endif
+ flayer = D_forecv->c_layer;
+ CV_CALL(D_forecv, LayRestore();LaySetCursor());
+ WindowChanged(0, 'F');
+ }
+
+ display = odisplay;
+}
+
+#ifdef RXVT_OSC
+void
+RefreshXtermOSC()
+{
+ int i;
+ struct win *p;
+
+ p = Layer2Window(D_forecv->c_layer);
+ for (i = 3; i >=0; i--)
+ SetXtermOSC(i, p ? p->w_xtermosc[i] : 0);
+}
+#endif
+
+int
+ParseAttrColor(s1, s2, msgok)
+char *s1, *s2;
+int msgok;
+{
+ int i, n;
+ char *s, *ss;
+ int r = 0;
+
+ s = s1;
+ while (*s == ' ')
+ s++;
+ ss = s;
+ while (*ss && *ss != ' ')
+ ss++;
+ while (*ss == ' ')
+ ss++;
+ if (*s && (s2 || *ss || !((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') || *s == '.')))
+ {
+ int mode = 0, n = 0;
+ if (*s == '+')
+ {
+ mode = 1;
+ s++;
+ }
+ else if (*s == '-')
+ {
+ mode = -1;
+ s++;
+ }
+ else if (*s == '!')
+ {
+ mode = 2;
+ s++;
+ }
+ else if (*s == '=')
+ s++;
+ if (*s >= '0' && *s <= '9')
+ {
+ n = *s++ - '0';
+ if (*s >= '0' && *s <= '9')
+ n = n * 16 + (*s++ - '0');
+ else if (*s >= 'a' && *s <= 'f')
+ n = n * 16 + (*s++ - ('a' - 10));
+ else if (*s >= 'A' && *s <= 'F')
+ n = n * 16 + (*s++ - ('A' - 10));
+ else if (*s && *s != ' ')
+ {
+ if (msgok)
+ Msg(0, "Illegal attribute hexchar '%c'", *s);
+ return -1;
+ }
+ }
+ else
+ {
+ while (*s && *s != ' ')
+ {
+ if (*s == 'd')
+ n |= A_DI;
+ else if (*s == 'u')
+ n |= A_US;
+ else if (*s == 'b')
+ n |= A_BD;
+ else if (*s == 'r')
+ n |= A_RV;
+ else if (*s == 's')
+ n |= A_SO;
+ else if (*s == 'B')
+ n |= A_BL;
+ else
+ {
+ if (msgok)
+ Msg(0, "Illegal attribute specifier '%c'", *s);
+ return -1;
+ }
+ s++;
+ }
+ }
+ if (*s && *s != ' ')
+ {
+ if (msgok)
+ Msg(0, "junk after attribute description: '%c'", *s);
+ return -1;
+ }
+ if (mode == -1)
+ r = n << 8 | n;
+ else if (mode == 1)
+ r = n << 8;
+ else if (mode == 2)
+ r = n;
+ else if (mode == 0)
+ r = 0xffff ^ n;
+ }
+ while (*s && *s == ' ')
+ s++;
+
+ if (s2)
+ {
+ if (*s)
+ {
+ if (msgok)
+ Msg(0, "junk after description: '%c'", *s);
+ return -1;
+ }
+ s = s2;
+ while (*s && *s == ' ')
+ s++;
+ }
+
+#ifdef COLOR
+ if (*s)
+ {
+ static char costr[] = "krgybmcw d i.01234567 9 f FKRGYBMCW I ";
+ int numco = 0, j;
+
+ n = 0;
+ if (*s == '.')
+ {
+ numco++;
+ n = 0x0f;
+ s++;
+ }
+ for (j = 0; j < 2 && *s && *s != ' '; j++)
+ {
+ for (i = 0; costr[i]; i++)
+ if (*s == costr[i])
+ break;
+ if (!costr[i])
+ {
+ if (msgok)
+ Msg(0, "illegal color descriptor: '%c'", *s);
+ return -1;
+ }
+ numco++;
+ n = n << 4 | (i & 15);
+#ifdef COLORS16
+ if (i >= 48)
+ n = (n & 0x20ff) | 0x200;
+#endif
+ s++;
+ }
+ if ((n & 0xf00) == 0xf00)
+ n ^= 0xf00; /* clear superflous bits */
+#ifdef COLORS16
+ if (n & 0x2000)
+ n ^= 0x2400; /* shift bit into right position */
+#endif
+ if (numco == 1)
+ n |= 0xf0; /* don't change bg color */
+ if (numco != 2 && n != 0xff)
+ n |= 0x100; /* special invert mode */
+ if (*s && *s != ' ')
+ {
+ if (msgok)
+ Msg(0, "junk after color description: '%c'", *s);
+ return -1;
+ }
+ n ^= 0xff;
+ r |= n << 16;
+ }
+#endif
+
+ while (*s && *s == ' ')
+ s++;
+ if (*s)
+ {
+ if (msgok)
+ Msg(0, "junk after description: '%c'", *s);
+ return -1;
+ }
+ debug1("ParseAttrColor %06x\n", r);
+ return r;
+}
+
+/*
+ * Color coding:
+ * 0-7 normal colors
+ * 9 default color
+ * e just set intensity
+ * f don't change anything
+ * Intensity is encoded into bits 17(fg) and 18(bg).
+ */
+void
+ApplyAttrColor(i, mc)
+int i;
+struct mchar *mc;
+{
+ debug1("ApplyAttrColor %06x\n", i);
+ mc->attr |= i >> 8 & 255;
+ mc->attr ^= i & 255;
+#ifdef COLOR
+ i = (i >> 16) ^ 0xff;
+ if ((i & 0x100) != 0)
+ {
+ i &= 0xeff;
+ if (mc->attr & (A_SO|A_RV))
+# ifdef COLORS16
+ i = ((i & 0x0f) << 4) | ((i & 0xf0) >> 4) | ((i & 0x200) << 1) | ((i & 0x400) >> 1);
+# else
+ i = ((i & 0x0f) << 4) | ((i & 0xf0) >> 4);
+# endif
+ }
+# ifdef COLORS16
+ if ((i & 0x0f) != 0x0f)
+ mc->attr = (mc->attr & 0xbf) | ((i >> 3) & 0x40);
+ if ((i & 0xf0) != 0xf0)
+ mc->attr = (mc->attr & 0x7f) | ((i >> 3) & 0x80);
+# endif
+ mc->color = 0x99 ^ mc->color;
+ if ((i & 0x0e) == 0x0e)
+ i = (i & 0xf0) | (mc->color & 0x0f);
+ if ((i & 0xe0) == 0xe0)
+ i = (i & 0x0f) | (mc->color & 0xf0);
+ mc->color = 0x99 ^ i;
+ debug2("ApplyAttrColor - %02x %02x\n", mc->attr, i);
+#endif
+}
diff --git a/pty.c b/pty.c
new file mode 100644
index 0000000..1c0660e
--- /dev/null
+++ b/pty.c
@@ -0,0 +1,415 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <signal.h>
+
+#include "config.h"
+#include "screen.h"
+
+#ifndef sun
+# include <sys/ioctl.h>
+#endif
+
+/* for solaris 2.1, Unixware (SVR4.2) and possibly others */
+#ifdef HAVE_STROPTS_H
+# include <sys/stropts.h>
+#endif
+
+#if defined(sun) && defined(LOCKPTY) && !defined(TIOCEXCL)
+# include <sys/ttold.h>
+#endif
+
+#ifdef ISC
+# include <sys/tty.h>
+# include <sys/sioctl.h>
+# include <sys/pty.h>
+#endif
+
+#ifdef sgi
+# include <sys/sysmacros.h>
+#endif /* sgi */
+
+#include "extern.h"
+
+/*
+ * if no PTYRANGE[01] is in the config file, we pick a default
+ */
+#ifndef PTYRANGE0
+# define PTYRANGE0 "qpr"
+#endif
+#ifndef PTYRANGE1
+# define PTYRANGE1 "0123456789abcdef"
+#endif
+
+/* SVR4 pseudo ttys don't seem to work with SCO-5 */
+#ifdef M_UNIX
+# undef HAVE_SVR4_PTYS
+#endif
+
+extern int eff_uid;
+
+/* used for opening a new pty-pair: */
+static char PtyName[32], TtyName[32];
+
+#if !(defined(sequent) || defined(_SEQUENT_) || defined(HAVE_SVR4_PTYS))
+# ifdef hpux
+static char PtyProto[] = "/dev/ptym/ptyXY";
+static char TtyProto[] = "/dev/pty/ttyXY";
+# else
+# ifdef M_UNIX
+static char PtyProto[] = "/dev/ptypXY";
+static char TtyProto[] = "/dev/ttypXY";
+# else
+static char PtyProto[] = "/dev/ptyXY";
+static char TtyProto[] = "/dev/ttyXY";
+# endif
+# endif /* hpux */
+#endif
+
+static void initmaster __P((int));
+
+#if defined(sun)
+/* sun's utmp_update program opens the salve side, thus corrupting
+ */
+int pty_preopen = 1;
+#else
+int pty_preopen = 0;
+#endif
+
+/*
+ * Open all ptys with O_NOCTTY, just to be on the safe side
+ * (RISCos mips breaks otherwise)
+ */
+#ifndef O_NOCTTY
+# define O_NOCTTY 0
+#endif
+
+/***************************************************************/
+
+static void
+initmaster(f)
+int f;
+{
+#ifdef POSIX
+ tcflush(f, TCIOFLUSH);
+#else
+# ifdef TIOCFLUSH
+ (void) ioctl(f, TIOCFLUSH, (char *) 0);
+# endif
+#endif
+#ifdef LOCKPTY
+ (void) ioctl(f, TIOCEXCL, (char *) 0);
+#endif
+}
+
+void
+InitPTY(f)
+int f;
+{
+ if (f < 0)
+ return;
+#if defined(I_PUSH) && defined(HAVE_SVR4_PTYS) && !defined(sgi) && !defined(linux) && !defined(__GLIBC__) && !defined(__osf__) && !defined(M_UNIX)
+ if (ioctl(f, I_PUSH, "ptem"))
+ Panic(errno, "InitPTY: cannot I_PUSH ptem");
+ if (ioctl(f, I_PUSH, "ldterm"))
+ Panic(errno, "InitPTY: cannot I_PUSH ldterm");
+# ifdef sun
+ if (ioctl(f, I_PUSH, "ttcompat"))
+ Panic(errno, "InitPTY: cannot I_PUSH ttcompat");
+# endif
+#endif
+}
+
+/***************************************************************/
+
+#if defined(OSX) && !defined(PTY_DONE)
+#define PTY_DONE
+int
+OpenPTY(ttyn)
+char **ttyn;
+{
+ register int f;
+ if ((f = open_controlling_pty(TtyName)) < 0)
+ return -1;
+ initmaster(f);
+ *ttyn = TtyName;
+ return f;
+}
+#endif
+
+/***************************************************************/
+
+#if (defined(sequent) || defined(_SEQUENT_)) && !defined(PTY_DONE)
+#define PTY_DONE
+int
+OpenPTY(ttyn)
+char **ttyn;
+{
+ char *m, *s;
+ register int f;
+
+ if ((f = getpseudotty(&s, &m)) < 0)
+ return -1;
+#ifdef _SEQUENT_
+ fvhangup(s);
+#endif
+ strncpy(PtyName, m, sizeof(PtyName));
+ strncpy(TtyName, s, sizeof(TtyName));
+ initmaster(f);
+ *ttyn = TtyName;
+ return f;
+}
+#endif
+
+/***************************************************************/
+
+#if defined(__sgi) && !defined(PTY_DONE)
+#define PTY_DONE
+int
+OpenPTY(ttyn)
+char **ttyn;
+{
+ int f;
+ char *name, *_getpty();
+ sigret_t (*sigcld)__P(SIGPROTOARG);
+
+ /*
+ * SIGCHLD set to SIG_DFL for _getpty() because it may fork() and
+ * exec() /usr/adm/mkpts
+ */
+ sigcld = signal(SIGCHLD, SIG_DFL);
+ name = _getpty(&f, O_RDWR | O_NONBLOCK, 0600, 0);
+ signal(SIGCHLD, sigcld);
+
+ if (name == 0)
+ return -1;
+ initmaster(f);
+ *ttyn = name;
+ return f;
+}
+#endif
+
+/***************************************************************/
+
+#if defined(MIPS) && defined(HAVE_DEV_PTC) && !defined(PTY_DONE)
+#define PTY_DONE
+int
+OpenPTY(ttyn)
+char **ttyn;
+{
+ register int f;
+ struct stat buf;
+
+ strcpy(PtyName, "/dev/ptc");
+ if ((f = open(PtyName, O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0)
+ return -1;
+ if (fstat(f, &buf) < 0)
+ {
+ close(f);
+ return -1;
+ }
+ sprintf(TtyName, "/dev/ttyq%d", minor(buf.st_rdev));
+ initmaster(f);
+ *ttyn = TtyName;
+ return f;
+}
+#endif
+
+/***************************************************************/
+
+#if defined(HAVE_SVR4_PTYS) && !defined(PTY_DONE)
+#define PTY_DONE
+int
+OpenPTY(ttyn)
+char **ttyn;
+{
+ register int f;
+ char *m, *ptsname();
+ int unlockpt __P((int)), grantpt __P((int));
+#if defined(HAVE_GETPT) && defined(linux)
+ int getpt __P((void));
+#endif
+ sigret_t (*sigcld)__P(SIGPROTOARG);
+
+ strcpy(PtyName, "/dev/ptmx");
+#if defined(HAVE_GETPT) && (defined(linux) || defined(__GLIBC__))
+ if ((f = getpt()) == -1)
+#else
+ if ((f = open(PtyName, O_RDWR | O_NOCTTY)) == -1)
+#endif
+ return -1;
+
+ /*
+ * SIGCHLD set to SIG_DFL for grantpt() because it fork()s and
+ * exec()s pt_chmod
+ */
+ sigcld = signal(SIGCHLD, SIG_DFL);
+ if ((m = ptsname(f)) == NULL || grantpt(f) || unlockpt(f))
+ {
+ signal(SIGCHLD, sigcld);
+ close(f);
+ return -1;
+ }
+ signal(SIGCHLD, sigcld);
+ strncpy(TtyName, m, sizeof(TtyName));
+ initmaster(f);
+ *ttyn = TtyName;
+ return f;
+}
+#endif
+
+/***************************************************************/
+
+#if defined(_AIX) && defined(HAVE_DEV_PTC) && !defined(PTY_DONE)
+#define PTY_DONE
+
+int
+OpenPTY(ttyn)
+char **ttyn;
+{
+ register int f;
+
+ /* a dumb looking loop replaced by mycrofts code: */
+ strcpy (PtyName, "/dev/ptc");
+ if ((f = open (PtyName, O_RDWR | O_NOCTTY)) < 0)
+ return -1;
+ strncpy(TtyName, GetPtsPathOrSymlink(f), sizeof(TtyName));
+ if (eff_uid && access(TtyName, R_OK | W_OK))
+ {
+ close(f);
+ return -1;
+ }
+ initmaster(f);
+# ifdef _IBMR2
+ pty_preopen = 1;
+# endif
+ *ttyn = TtyName;
+ return f;
+}
+#endif
+
+/***************************************************************/
+
+#if defined(HAVE_OPENPTY) && !defined(PTY_DONE)
+#define PTY_DONE
+int
+OpenPTY(ttyn)
+char **ttyn;
+{
+ int f, s;
+ if (openpty(&f, &s, TtyName, NULL, NULL) != 0)
+ return -1;
+ close(s);
+ initmaster(f);
+ pty_preopen = 1;
+ *ttyn = TtyName;
+ return f;
+}
+#endif
+
+/***************************************************************/
+
+#ifndef PTY_DONE
+int
+OpenPTY(ttyn)
+char **ttyn;
+{
+ register char *p, *q, *l, *d;
+ register int f;
+
+ debug("OpenPTY: Using BSD style ptys.\n");
+ strcpy(PtyName, PtyProto);
+ strcpy(TtyName, TtyProto);
+ for (p = PtyName; *p != 'X'; p++)
+ ;
+ for (q = TtyName; *q != 'X'; q++)
+ ;
+ for (l = PTYRANGE0; (*p = *l) != '\0'; l++)
+ {
+ for (d = PTYRANGE1; (p[1] = *d) != '\0'; d++)
+ {
+ debug1("OpenPTY tries '%s'\n", PtyName);
+ if ((f = open(PtyName, O_RDWR | O_NOCTTY)) == -1)
+ continue;
+ q[0] = *l;
+ q[1] = *d;
+ if (eff_uid && access(TtyName, R_OK | W_OK))
+ {
+ close(f);
+ continue;
+ }
+#if defined(sun) && defined(TIOCGPGRP) && !defined(SUNOS3)
+ /* Hack to ensure that the slave side of the pty is
+ * unused. May not work in anything other than SunOS4.1
+ */
+ {
+ int pgrp;
+
+ /* tcgetpgrp does not work (uses TIOCGETPGRP)! */
+ if (ioctl(f, TIOCGPGRP, (char *)&pgrp) != -1 || errno != EIO)
+ {
+ close(f);
+ continue;
+ }
+ }
+#endif
+ initmaster(f);
+ *ttyn = TtyName;
+ return f;
+ }
+ }
+ return -1;
+}
+#endif
+
+/* len(/proc/self/fd/) + len(max 64 bit int) */
+#define MAX_PTS_SYMLINK (14 + 21)
+char *GetPtsPathOrSymlink(int fd)
+{
+ int ret;
+ char *tty_name;
+ static char tty_symlink[MAX_PTS_SYMLINK];
+
+ errno = 0;
+ tty_name = ttyname(fd);
+ if (!tty_name && errno == ENODEV) {
+ ret = snprintf(tty_symlink, MAX_PTS_SYMLINK, "/proc/self/fd/%d", fd);
+ if (ret < 0 || ret >= MAX_PTS_SYMLINK)
+ return NULL;
+ /* We are setting errno to ENODEV to allow callers to check
+ * whether the pts device exists in another namespace.
+ */
+ errno = ENODEV;
+ return tty_symlink;
+ }
+
+ return tty_name;
+}
diff --git a/putenv.c b/putenv.c
new file mode 100644
index 0000000..2a907f9
--- /dev/null
+++ b/putenv.c
@@ -0,0 +1,216 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+/*
+ * putenv -- put value into environment
+ *
+ * Usage: i = putenv (string)
+ * int i;
+ * char *string;
+ *
+ * where string is of the form <name>=<value>.
+ * If "value" is 0, then "name" will be deleted from the environment.
+ * Putenv returns 0 normally, -1 on error (not enough core for malloc).
+ *
+ * Putenv may need to add a new name into the environment, or to
+ * associate a value longer than the current value with a particular
+ * name. So, to make life simpler, putenv() copies your entire
+ * environment into the heap (i.e. malloc()) from the stack
+ * (i.e. where it resides when your process is initiated) the first
+ * time you call it.
+ *
+ * HISTORY
+ * 3-Sep-91 Michael Schroeder (mlschroe). Modified to behave as
+ * as putenv.
+ * 16-Aug-91 Tim MacKenzie (tym) at Monash University. Modified for
+ * use in screen (iScreen) (ignores final int parameter)
+ * 14-Oct-85 Michael Mauldin (mlm) at Carnegie-Mellon University
+ * Ripped out of CMU lib for Rob-O-Matic portability
+ * 20-Nov-79 Steven Shafer (sas) at Carnegie-Mellon University
+ * Created for VAX. Too bad Bell Labs didn't provide this. It's
+ * unfortunate that you have to copy the whole environment onto the
+ * heap, but the bookkeeping-and-not-so-much-copying approach turns
+ * out to be much hairier. So, I decided to do the simple thing,
+ * copying the entire environment onto the heap the first time you
+ * call putenv(), then doing realloc() uniformly later on.
+ */
+
+#include "config.h"
+
+#ifdef NEEDPUTENV
+
+#if defined(__STDC__)
+# define __P(a) a
+#else
+# define __P(a) ()
+#endif
+
+char *malloc __P((int));
+char *realloc __P((char *, int));
+void free __P((char *));
+int sprintf __P((char *, char *, ...));
+
+#define EXTRASIZE 5 /* increment to add to env. size */
+
+static int envsize = -1; /* current size of environment */
+extern char **environ; /* the global which is your env. */
+
+static int findenv __P((char *)); /* look for a name in the env. */
+static int newenv __P((void)); /* copy env. from stack to heap */
+static int moreenv __P((void)); /* incr. size of env. */
+
+int
+unsetenv(name)
+char *name;
+{
+ register int i;
+
+ if (envsize < 0)
+ { /* first time putenv called */
+ if (newenv() < 0) /* copy env. to heap */
+ return -1;
+ }
+ i = findenv(name);
+ if (i < 0)
+ return 0; /* Already here */
+
+ free(environ[i]);
+ if (envsize > 0)
+ envsize--;
+ for (; environ[i]; i++)
+ environ[i] = environ[i+1];
+ return 0; /* Already here */
+}
+
+int
+putenv(string)
+char *string;
+{
+ register int i;
+ register char *p;
+
+ if (envsize < 0)
+ { /* first time putenv called */
+ if (newenv() < 0) /* copy env. to heap */
+ return -1;
+ }
+
+ i = findenv(string); /* look for name in environment */
+
+ if (i < 0)
+ { /* name must be added */
+ for (i = 0; environ[i]; i++);
+ if (i >= (envsize - 1))
+ { /* need new slot */
+ if (moreenv() < 0)
+ return -1;
+ }
+ p = malloc(strlen(string) + 1);
+ if (p == 0) /* not enough core */
+ return -1;
+ environ[i + 1] = 0; /* new end of env. */
+ }
+ else
+ { /* name already in env. */
+ p = realloc(environ[i], strlen(string) + 1);
+ if (p == 0)
+ return -1;
+ }
+ sprintf(p, "%s", string); /* copy into env. */
+ environ[i] = p;
+
+ return 0;
+}
+
+static int
+findenv(name)
+char *name;
+{
+ register char *namechar, *envchar;
+ register int i, found;
+
+ found = 0;
+ for (i = 0; environ[i] && !found; i++)
+ {
+ envchar = environ[i];
+ namechar = name;
+ while (*namechar && *namechar != '=' && (*namechar == *envchar))
+ {
+ namechar++;
+ envchar++;
+ }
+ found = ((*namechar == '\0' || *namechar == '=') && *envchar == '=');
+ }
+ return found ? i - 1 : -1;
+}
+
+static int
+newenv()
+{
+ register char **env, *elem;
+ register int i, esize;
+
+ for (i = 0; environ[i]; i++)
+ ;
+ esize = i + EXTRASIZE + 1;
+ env = (char **)malloc(esize * sizeof (elem));
+ if (env == 0)
+ return -1;
+
+ for (i = 0; environ[i]; i++)
+ {
+ elem = malloc(strlen(environ[i]) + 1);
+ if (elem == 0)
+ return -1;
+ env[i] = elem;
+ strcpy(elem, environ[i]);
+ }
+
+ env[i] = 0;
+ environ = env;
+ envsize = esize;
+ return 0;
+}
+
+static int
+moreenv()
+{
+ register int esize;
+ register char **env;
+
+ esize = envsize + EXTRASIZE;
+ env = (char **)realloc((char *)environ, esize * sizeof (*env));
+ if (env == 0)
+ return -1;
+ environ = env;
+ envsize = esize;
+ return 0;
+}
+
+#endif /* NEEDPUTENV */
+
diff --git a/resize.c b/resize.c
new file mode 100644
index 0000000..fc4ddb9
--- /dev/null
+++ b/resize.c
@@ -0,0 +1,1136 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+#include <signal.h>
+#ifndef sun
+#include <sys/ioctl.h>
+#endif
+
+#ifdef ISC
+# include <sys/tty.h>
+# include <sys/sioctl.h>
+# include <sys/pty.h>
+#endif
+
+#include "config.h"
+#include "screen.h"
+#include "extern.h"
+
+/* maximum window width */
+#define MAXWIDTH 1000
+
+static void CheckMaxSize __P((int));
+static void FreeMline __P((struct mline *));
+static int AllocMline __P((struct mline *ml, int));
+static void MakeBlankLine __P((unsigned char *, int));
+static void kaablamm __P((void));
+static int BcopyMline __P((struct mline *, int, struct mline *, int, int, int));
+static void SwapAltScreen __P((struct win *));
+
+extern struct layer *flayer;
+extern struct display *display, *displays;
+extern unsigned char *blank, *null;
+extern struct mline mline_blank, mline_null, mline_old;
+extern struct win *windows;
+extern const int Z0width, Z1width;
+extern int captionalways;
+
+#if defined(TIOCGWINSZ) || defined(TIOCSWINSZ)
+struct winsize glwz;
+#endif
+
+static struct mline mline_zero = {
+ (unsigned char *)0,
+ (unsigned char *)0
+#ifdef FONT
+ ,(unsigned char *)0
+#endif
+#ifdef COLOR
+ ,(unsigned char *)0
+# ifdef COLORS256
+ ,(unsigned char *)0
+# endif
+#endif
+};
+
+/*
+ * ChangeFlag: 0: try to modify no window
+ * 1: modify fore (and try to modify no other) + redisplay
+ * 2: modify all windows
+ *
+ * Note: Activate() is only called if change_flag == 1
+ * i.e. on a WINCH event
+ */
+
+void
+CheckScreenSize(change_flag)
+int change_flag;
+{
+ int wi, he;
+
+ if (display == 0)
+ {
+ debug("CheckScreenSize: No display -> no check.\n");
+ return;
+ }
+#ifdef TIOCGWINSZ
+ if (ioctl(D_userfd, TIOCGWINSZ, (char *)&glwz) != 0)
+ {
+ debug2("CheckScreenSize: ioctl(%d, TIOCGWINSZ) errno %d\n", D_userfd, errno);
+ wi = D_CO;
+ he = D_LI;
+ }
+ else
+ {
+ wi = glwz.ws_col;
+ he = glwz.ws_row;
+ if (wi == 0)
+ wi = D_CO;
+ if (he == 0)
+ he = D_LI;
+ }
+#else
+ wi = D_CO;
+ he = D_LI;
+#endif
+
+ debug2("CheckScreenSize: screen is (%d,%d)\n", wi, he);
+
+#if 0 /* XXX: Fixme */
+ if (change_flag == 2)
+ {
+ debug("Trying to adapt all windows (-A)\n");
+ for (p = windows; p; p = p->w_next)
+ if (p->w_display == 0 || p->w_display == display)
+ ChangeWindowSize(p, wi, he, p->w_histheight);
+ }
+#endif
+ if (D_width == wi && D_height == he)
+ {
+ debug("CheckScreenSize: No change -> return.\n");
+ return;
+ }
+#ifdef BLANKER_PRG
+ KillBlanker();
+#endif
+ ResetIdle();
+ ChangeScreenSize(wi, he, change_flag);
+/* XXX Redisplay logic */
+#if 0
+ if (change_flag == 1)
+ Redisplay(D_fore ? D_fore->w_norefresh : 0);
+#endif
+}
+
+void
+ChangeScreenSize(wi, he, change_fore)
+int wi, he;
+int change_fore;
+{
+ struct win *p;
+ struct canvas *cv;
+ int wwi;
+
+ debug2("ChangeScreenSize from (%d,%d) ", D_width, D_height);
+ debug3("to (%d,%d) (change_fore: %d)\n",wi, he, change_fore);
+
+ cv = &D_canvas;
+ cv->c_xe = wi - 1;
+ cv->c_ys = (D_has_hstatus == HSTATUS_FIRSTLINE);
+ cv->c_ye = he - 1 - ((cv->c_slperp && cv->c_slperp->c_slnext) || captionalways) - (D_has_hstatus == HSTATUS_LASTLINE);
+ cv->c_blank.l_height = cv->c_ye - cv->c_ys + 1;
+ if (cv->c_slperp)
+ {
+ ResizeCanvas(cv);
+ RecreateCanvasChain();
+ RethinkDisplayViewports();
+ }
+ if (D_forecv == 0)
+ D_forecv = D_cvlist;
+ if (D_forecv)
+ D_fore = Layer2Window(D_forecv->c_layer);
+
+ D_width = wi;
+ D_height = he;
+
+ CheckMaxSize(wi);
+ if (D_CWS)
+ {
+ D_defwidth = D_CO;
+ D_defheight = D_LI;
+ }
+ else
+ {
+ if (D_CZ0 && (wi == Z0width || wi == Z1width) &&
+ (D_CO == Z0width || D_CO == Z1width))
+ D_defwidth = D_CO;
+ else
+ D_defwidth = wi;
+ D_defheight = he;
+ }
+ debug2("Default size: (%d,%d)\n", D_defwidth, D_defheight);
+ if (change_fore)
+ ResizeLayersToCanvases();
+ if (change_fore == 2 && D_CWS == NULL && displays->d_next == 0)
+ {
+ /* adapt all windows - to be removed ? */
+ for (p = windows; p; p = p->w_next)
+ {
+ debug1("Trying to change window %d.\n", p->w_number);
+ wwi = wi;
+#if 0
+ if (D_CZ0 && p->w_width != wi && (wi == Z0width || wi == Z1width))
+ {
+ if (p->w_width > (Z0width + Z1width) / 2)
+ wwi = Z0width;
+ else
+ wwi = Z1width;
+ }
+#endif
+ if (p->w_savelayer && p->w_savelayer->l_cvlist == 0)
+ ResizeLayer(p->w_savelayer, wwi, he, 0);
+#if 0
+ ChangeWindowSize(p, wwi, he, p->w_histheight);
+#endif
+ }
+ }
+}
+
+void
+ResizeLayersToCanvases()
+{
+ struct canvas *cv;
+ struct layer *l;
+ int lx, ly;
+
+ debug("ResizeLayersToCanvases\n");
+ D_kaablamm = 0;
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ {
+ l = cv->c_layer;
+ if (l == 0)
+ continue;
+ debug("Doing canvas: ");
+ if (l->l_width == cv->c_xe - cv->c_xs + 1 &&
+ l->l_height == cv->c_ye - cv->c_ys + 1)
+ {
+ debug("already fitting.\n");
+ continue;
+ }
+ if (!MayResizeLayer(l))
+ {
+ debug("may not resize.\n");
+ }
+ else
+ {
+ debug("doing resize.\n");
+ ResizeLayer(l, cv->c_xe - cv->c_xs + 1, cv->c_ye - cv->c_ys + 1, display);
+ }
+
+ /* normalize window, see screen.c */
+ lx = cv->c_layer->l_x;
+ ly = cv->c_layer->l_y;
+ if (ly + cv->c_yoff < cv->c_ys)
+ {
+ cv->c_yoff = cv->c_ys - ly;
+ RethinkViewportOffsets(cv);
+ }
+ else if (ly + cv->c_yoff > cv->c_ye)
+ {
+ cv->c_yoff = cv->c_ye - ly;
+ RethinkViewportOffsets(cv);
+ }
+ if (lx + cv->c_xoff < cv->c_xs)
+ {
+ int n = cv->c_xs - (lx + cv->c_xoff);
+ if (n < (cv->c_xe - cv->c_xs + 1) / 2)
+ n = (cv->c_xe - cv->c_xs + 1) / 2;
+ if (cv->c_xoff + n > cv->c_xs)
+ n = cv->c_xs - cv->c_xoff;
+ cv->c_xoff += n;
+ RethinkViewportOffsets(cv);
+ }
+ else if (lx + cv->c_xoff > cv->c_xe)
+ {
+ int n = lx + cv->c_xoff - cv->c_xe;
+ if (n < (cv->c_xe - cv->c_xs + 1) / 2)
+ n = (cv->c_xe - cv->c_xs + 1) / 2;
+ if (cv->c_xoff - n + cv->c_layer->l_width - 1 < cv->c_xe)
+ n = cv->c_xoff + cv->c_layer->l_width - 1 - cv->c_xe;
+ cv->c_xoff -= n;
+ RethinkViewportOffsets(cv);
+ }
+ }
+ Redisplay(0);
+ if (D_kaablamm)
+ {
+ kaablamm();
+ D_kaablamm = 0;
+ }
+}
+
+int
+MayResizeLayer(l)
+struct layer *l;
+{
+ int cvs = 0;
+ debug("MayResizeLayer:\n");
+ for (; l; l = l->l_next)
+ {
+ if (l->l_cvlist)
+ if (++cvs > 1 || l->l_cvlist->c_lnext)
+ {
+ debug1("may not - cvs %d\n", cvs);
+ return 0;
+ }
+ }
+ debug("may resize\n");
+ return 1;
+}
+
+/*
+ * Easy implementation: rely on the fact that the only layers
+ * supporting resize are Win and Blank. So just kill all overlays.
+ *
+ * This is a lot harder if done the right way...
+ */
+
+static void
+kaablamm()
+{
+ Msg(0, "Aborted because of window size change.");
+}
+
+/* Kills non-resizable layers. */
+#define RESIZE_OR_KILL_LAYERS(l, wi, he) do \
+ { \
+ struct layer *_last = NULL; \
+ flayer = (l); \
+ while (flayer->l_next) \
+ { \
+ if (LayResize(wi, he) == 0) \
+ { \
+ _last = flayer; \
+ flayer = flayer->l_next; \
+ } \
+ else \
+ { \
+ struct canvas *_cv; \
+ for (_cv = flayer->l_cvlist; _cv; _cv = _cv->c_lnext) \
+ _cv->c_display->d_kaablamm = 1; \
+ ExitOverlayPage(); \
+ if (_last) \
+ _last->l_next = flayer; \
+ } \
+ } \
+ /* We assume that the bottom-most layer, i.e. when flayer->l_next == 0, \
+ * is always resizable. Currently, WinLf and BlankLf can be the bottom-most layers. \
+ */ \
+ LayResize(wi, he); \
+ } while (0)
+
+void
+ResizeLayer(l, wi, he, norefdisp)
+struct layer *l;
+int wi, he;
+struct display *norefdisp;
+{
+ struct win *p;
+ struct canvas *cv;
+ struct layer *oldflayer = flayer;
+ struct display *d, *olddisplay = display;
+
+ if (l->l_width == wi && l->l_height == he)
+ return;
+ p = Layer2Window(l);
+
+ /* If 'flayer' and 'l' are for the same window, then we will not
+ * restore 'flayer'. */
+ if (oldflayer && (l == oldflayer || Layer2Window(oldflayer) == p))
+ oldflayer = NULL;
+
+ flayer = l;
+
+ if (p)
+ {
+ /* It's a window layer. Kill the overlays on it in all displays. */
+ for (d = displays; d; d = d->d_next)
+ for (cv = d->d_cvlist; cv; cv = cv->c_next)
+ {
+ if (p == Layer2Window(cv->c_layer))
+ {
+ /* Canvas 'cv' on display 'd' shows this window. Remove any non-resizable
+ * layers over it. */
+ RESIZE_OR_KILL_LAYERS(cv->c_layer, wi, he);
+ }
+ }
+ }
+ else
+ {
+ /* It's a Blank layer. Just kill the non-resizable overlays over it. */
+ RESIZE_OR_KILL_LAYERS(flayer, wi, he);
+ }
+
+ for (display = displays; display; display = display->d_next)
+ {
+ if (display == norefdisp)
+ continue;
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ if (Layer2Window(cv->c_layer) == p)
+ {
+ CV_CALL(cv, LayRedisplayLine(-1, -1, -1, 0));
+ RefreshArea(cv->c_xs, cv->c_ys, cv->c_xe, cv->c_ye, 0);
+ }
+ if (D_kaablamm)
+ {
+ kaablamm();
+ D_kaablamm = 0;
+ }
+ }
+
+ /* If we started resizing a non-flayer layer, then restore the flayer.
+ * Otherwise, flayer should already be updated to the topmost foreground layer. */
+ if (oldflayer)
+ flayer = oldflayer;
+ display = olddisplay;
+}
+
+static void
+FreeMline(ml)
+struct mline *ml;
+{
+ if (ml->image)
+ free(ml->image);
+ if (ml->attr && ml->attr != null)
+ free(ml->attr);
+#ifdef FONT
+ if (ml->font && ml->font != null)
+ free(ml->font);
+ if (ml->fontx && ml->fontx != null)
+ free(ml->fontx);
+#endif
+#ifdef COLOR
+ if (ml->color && ml->color != null)
+ free(ml->color);
+# ifdef COLORS256
+ if (ml->colorx && ml->colorx != null)
+ free(ml->colorx);
+# endif
+#endif
+ *ml = mline_zero;
+}
+
+static int
+AllocMline(ml, w)
+struct mline *ml;
+int w;
+{
+ ml->image = malloc(w);
+ ml->attr = null;
+#ifdef FONT
+ ml->font = null;
+ ml->fontx = null;
+#endif
+#ifdef COLOR
+ ml->color = null;
+# ifdef COLORS256
+ ml->colorx = null;
+# endif
+#endif
+ if (ml->image == 0)
+ return -1;
+ return 0;
+}
+
+
+static int
+BcopyMline(mlf, xf, mlt, xt, l, w)
+struct mline *mlf, *mlt;
+int xf, xt, l, w;
+{
+ int r = 0;
+
+ bcopy((char *)mlf->image + xf, (char *)mlt->image + xt, l);
+ if (mlf->attr != null && mlt->attr == null)
+ {
+ if ((mlt->attr = (unsigned char *)calloc(w, 1)) == 0)
+ mlt->attr = null, r = -1;
+ }
+ if (mlt->attr != null)
+ bcopy((char *)mlf->attr + xf, (char *)mlt->attr + xt, l);
+#ifdef FONT
+ if (mlf->font != null && mlt->font == null)
+ {
+ if ((mlt->font = (unsigned char *)calloc(w, 1)) == 0)
+ mlt->font = null, r = -1;
+ }
+ if (mlt->font != null)
+ bcopy((char *)mlf->font + xf, (char *)mlt->font + xt, l);
+ if (mlf->fontx != null && mlt->fontx == null)
+ {
+ if ((mlt->fontx = (unsigned char *)calloc(w, 1)) == 0)
+ mlt->fontx = null, r = -1;
+ }
+ if (mlt->fontx != null)
+ bcopy((char *)mlf->fontx + xf, (char *)mlt->fontx + xt, l);
+#endif
+#ifdef COLOR
+ if (mlf->color != null && mlt->color == null)
+ {
+ if ((mlt->color = (unsigned char *)calloc(w, 1)) == 0)
+ mlt->color = null, r = -1;
+ }
+ if (mlt->color != null)
+ bcopy((char *)mlf->color + xf, (char *)mlt->color + xt, l);
+# ifdef COLORS256
+ if (mlf->colorx != null && mlt->colorx == null)
+ {
+ if ((mlt->colorx = (unsigned char *)calloc(w, 1)) == 0)
+ mlt->colorx = null, r = -1;
+ }
+ if (mlt->colorx != null)
+ bcopy((char *)mlf->colorx + xf, (char *)mlt->colorx + xt, l);
+# endif
+#endif
+ return r;
+}
+
+
+static int maxwidth;
+
+static void
+CheckMaxSize(wi)
+int wi;
+{
+ unsigned char *oldnull = null;
+ unsigned char *oldblank = blank;
+ struct win *p;
+ int i;
+ struct mline *ml;
+
+ if (wi > MAXWIDTH)
+ wi = MAXWIDTH;
+ if (wi <= maxwidth)
+ return;
+ maxwidth = wi + 1;
+ debug1("New maxwidth: %d\n", maxwidth);
+ blank = (unsigned char *)xrealloc((char *)blank, maxwidth);
+ null = (unsigned char *)xrealloc((char *)null, maxwidth);
+ mline_old.image = (unsigned char *)xrealloc((char *)mline_old.image, maxwidth);
+ mline_old.attr = (unsigned char *)xrealloc((char *)mline_old.attr, maxwidth);
+#ifdef FONT
+ mline_old.font = (unsigned char *)xrealloc((char *)mline_old.font, maxwidth);
+ mline_old.fontx = (unsigned char *)xrealloc((char *)mline_old.fontx, maxwidth);
+#endif
+#ifdef COLOR
+ mline_old.color = (unsigned char *)xrealloc((char *)mline_old.color, maxwidth);
+# ifdef COLORS256
+ mline_old.colorx = (unsigned char *)xrealloc((char *)mline_old.colorx, maxwidth);
+# endif
+#endif
+ if (!(blank && null && mline_old.image && mline_old.attr IFFONT(&& mline_old.font) IFFONTX(&& mline_old.fontx) IFCOLOR(&& mline_old.color) IFCOLORX(&& mline_old.colorx)))
+ Panic(0, "%s", strnomem);
+
+ MakeBlankLine(blank, maxwidth);
+ bzero((char *)null, maxwidth);
+
+ mline_blank.image = blank;
+ mline_blank.attr = null;
+ mline_null.image = null;
+ mline_null.attr = null;
+#ifdef FONT
+ mline_blank.font = null;
+ mline_null.font = null;
+ mline_blank.fontx = null;
+ mline_null.fontx = null;
+#endif
+#ifdef COLOR
+ mline_blank.color = null;
+ mline_null.color = null;
+# ifdef COLORS256
+ mline_blank.colorx = null;
+ mline_null.colorx = null;
+# endif
+#endif
+
+#define RESET_AFC(x, bl) do { if (x == old##bl) x = bl; } while (0)
+
+#define RESET_LINES(lines, count) \
+ do { \
+ ml = lines; \
+ for (i = 0; i < count; i++, ml++) \
+ { \
+ RESET_AFC(ml->image, blank); \
+ RESET_AFC(ml->attr, null); \
+ IFFONT(RESET_AFC(ml->font, null)); \
+ IFFONT(RESET_AFC(ml->fontx, null)); \
+ IFCOLOR(RESET_AFC(ml->color, null)); \
+ IFCOLORX(RESET_AFC(ml->colorx, null)); \
+ } \
+ } while (0)
+
+ /* We have to run through all windows to substitute
+ * the null and blank references.
+ */
+ for (p = windows; p; p = p->w_next)
+ {
+ RESET_LINES(p->w_mlines, p->w_height);
+
+#ifdef COPY_PASTE
+ RESET_LINES(p->w_hlines, p->w_histheight);
+ RESET_LINES(p->w_alt.hlines, p->w_alt.histheight);
+#endif
+
+ RESET_LINES(p->w_alt.mlines, p->w_alt.height);
+ }
+}
+
+
+char *
+xrealloc(mem, len)
+char *mem;
+int len;
+{
+ register char *nmem;
+
+ if (mem == 0)
+ return malloc(len);
+ if ((nmem = realloc(mem, len)))
+ return nmem;
+ free(mem);
+ return (char *)0;
+}
+
+static void
+MakeBlankLine(p, n)
+register unsigned char *p;
+register int n;
+{
+ while (n--)
+ *p++ = ' ';
+}
+
+
+
+
+#ifdef COPY_PASTE
+
+#define OLDWIN(y) ((y < p->w_histheight) \
+ ? &p->w_hlines[(p->w_histidx + y) % p->w_histheight] \
+ : &p->w_mlines[y - p->w_histheight])
+
+#define NEWWIN(y) ((y < hi) ? &nhlines[y] : &nmlines[y - hi])
+
+#else
+
+#define OLDWIN(y) (&p->w_mlines[y])
+#define NEWWIN(y) (&nmlines[y])
+
+#endif
+
+
+int
+ChangeWindowSize(p, wi, he, hi)
+struct win *p;
+int wi, he, hi;
+{
+ struct mline *mlf = 0, *mlt = 0, *ml, *nmlines, *nhlines;
+ int fy, ty, l, lx, lf, lt, yy, oty, addone;
+ int ncx, ncy, naka, t;
+ int y, shift;
+
+ if (wi <= 0 || he <= 0)
+ wi = he = hi = 0;
+
+ if (p->w_type == W_TYPE_GROUP)
+ return 0;
+
+ if (wi > MAXWIDTH)
+ {
+ Msg(0, "Window width too large. Truncated to %d.", MAXWIDTH);
+ wi = MAXWIDTH;
+ }
+
+ if (he > MAXWIDTH)
+ {
+ Msg(0, "Window height too large. Truncated to %d.", MAXWIDTH);
+ he = MAXWIDTH;
+ }
+
+ if (p->w_width == wi && p->w_height == he && p->w_histheight == hi)
+ {
+ debug("ChangeWindowSize: No change.\n");
+ return 0;
+ }
+
+ CheckMaxSize(wi);
+
+ /* XXX */
+#if 0
+ /* just in case ... */
+ if (wi && (p->w_width != wi || p->w_height != he) && p->w_lay != &p->w_winlay)
+ {
+ debug("ChangeWindowSize: No resize because of overlay?\n");
+ return -1;
+ }
+#endif
+
+ debug("ChangeWindowSize");
+ debug3(" from (%d,%d)+%d", p->w_width, p->w_height, p->w_histheight);
+ debug3(" to(%d,%d)+%d\n", wi, he, hi);
+
+ fy = p->w_histheight + p->w_height - 1;
+ ty = hi + he - 1;
+
+ nmlines = nhlines = 0;
+ ncx = 0;
+ ncy = 0;
+ naka = 0;
+
+ if (wi)
+ {
+ if (wi != p->w_width || he != p->w_height)
+ {
+ if ((nmlines = (struct mline *)calloc(he, sizeof(struct mline))) == 0)
+ {
+ KillWindow(p);
+ Msg(0, "%s", strnomem);
+ return -1;
+ }
+ }
+ else
+ {
+ debug1("image stays the same: %d lines\n", he);
+ nmlines = p->w_mlines;
+ fy -= he;
+ ty -= he;
+ ncx = p->w_x;
+ ncy = p->w_y;
+ naka = p->w_autoaka;
+ }
+ }
+#ifdef COPY_PASTE
+ if (hi)
+ {
+ if ((nhlines = (struct mline *)calloc(hi, sizeof(struct mline))) == 0)
+ {
+ Msg(0, "No memory for history buffer - turned off");
+ hi = 0;
+ ty = he - 1;
+ }
+ }
+#endif
+
+ /* special case: cursor is at magic margin position */
+ addone = 0;
+ if (p->w_width && p->w_x == p->w_width)
+ {
+ debug2("Special addone case: %d %d\n", p->w_x, p->w_y);
+ addone = 1;
+ p->w_x--;
+ }
+
+ /* handle the cursor and autoaka lines now if the widths are equal */
+ if (p->w_width == wi)
+ {
+ ncx = p->w_x + addone;
+ ncy = p->w_y + he - p->w_height;
+ /* never lose sight of the line with the cursor on it */
+ shift = -ncy;
+ for (yy = p->w_y + p->w_histheight - 1; yy >= 0 && ncy + shift < he; yy--)
+ {
+ ml = OLDWIN(yy);
+ if (!ml->image)
+ break;
+ if (ml->image[p->w_width] == ' ')
+ break;
+ shift++;
+ }
+ if (shift < 0)
+ shift = 0;
+ else
+ debug1("resize: cursor out of bounds, shifting %d\n", shift);
+ ncy += shift;
+ if (p->w_autoaka > 0)
+ {
+ naka = p->w_autoaka + he - p->w_height + shift;
+ if (naka < 1 || naka > he)
+ naka = 0;
+ }
+ while (shift-- > 0)
+ {
+ ml = OLDWIN(fy);
+ FreeMline(ml);
+ fy--;
+ }
+ }
+ debug2("fy %d ty %d\n", fy, ty);
+ if (fy >= 0)
+ mlf = OLDWIN(fy);
+ if (ty >= 0)
+ mlt = NEWWIN(ty);
+
+ while (fy >= 0 && ty >= 0)
+ {
+ if (p->w_width == wi)
+ {
+ /* here is a simple shortcut: just copy over */
+ *mlt = *mlf;
+ *mlf = mline_zero;
+ if (--fy >= 0)
+ mlf = OLDWIN(fy);
+ if (--ty >= 0)
+ mlt = NEWWIN(ty);
+ continue;
+ }
+
+ /* calculate lenght */
+ for (l = p->w_width - 1; l > 0; l--)
+ if (mlf->image[l] != ' ' || mlf->attr[l])
+ break;
+ if (fy == p->w_y + p->w_histheight && l < p->w_x)
+ l = p->w_x; /* cursor is non blank */
+ l++;
+ lf = l;
+
+ /* add wrapped lines to length */
+ for (yy = fy - 1; yy >= 0; yy--)
+ {
+ ml = OLDWIN(yy);
+ if (ml->image[p->w_width] == ' ')
+ break;
+ l += p->w_width;
+ }
+
+ /* rewrap lines */
+ lt = (l - 1) % wi + 1; /* lf is set above */
+ oty = ty;
+ while (l > 0 && fy >= 0 && ty >= 0)
+ {
+ lx = lt > lf ? lf : lt;
+ if (mlt->image == 0)
+ {
+ if (AllocMline(mlt, wi + 1))
+ goto nomem;
+ MakeBlankLine(mlt->image + lt, wi - lt);
+ mlt->image[wi] = ((oty == ty) ? ' ' : 0);
+ }
+ if (BcopyMline(mlf, lf - lx, mlt, lt - lx, lx, wi + 1))
+ goto nomem;
+
+ /* did we copy the cursor ? */
+ if (fy == p->w_y + p->w_histheight && lf - lx <= p->w_x && lf > p->w_x)
+ {
+ ncx = p->w_x + lt - lf + addone;
+ ncy = ty - hi;
+ shift = wi ? -ncy + (l - lx) / wi : 0;
+ if (ty + shift > hi + he - 1)
+ shift = hi + he - 1 - ty;
+ if (shift > 0)
+ {
+ debug3("resize: cursor out of bounds, shifting %d [%d/%d]\n", shift, lt - lx, wi);
+ for (y = hi + he - 1; y >= ty; y--)
+ {
+ mlt = NEWWIN(y);
+ FreeMline(mlt);
+ if (y - shift < ty)
+ continue;
+ ml = NEWWIN(y - shift);
+ *mlt = *ml;
+ *ml = mline_zero;
+ }
+ ncy += shift;
+ ty += shift;
+ mlt = NEWWIN(ty);
+ if (naka > 0)
+ naka = naka + shift > he ? 0 : naka + shift;
+ }
+ ASSERT(ncy >= 0);
+ }
+ /* did we copy autoaka line ? */
+ if (p->w_autoaka > 0 && fy == p->w_autoaka - 1 + p->w_histheight && lf - lx <= 0)
+ naka = ty - hi >= 0 ? 1 + ty - hi : 0;
+
+ lf -= lx;
+ lt -= lx;
+ l -= lx;
+ if (lf == 0)
+ {
+ FreeMline(mlf);
+ lf = p->w_width;
+ if (--fy >= 0)
+ mlf = OLDWIN(fy);
+ }
+ if (lt == 0)
+ {
+ lt = wi;
+ if (--ty >= 0)
+ mlt = NEWWIN(ty);
+ }
+ }
+ ASSERT(l != 0 || fy == yy);
+ }
+ while (fy >= 0)
+ {
+ FreeMline(mlf);
+ if (--fy >= 0)
+ mlf = OLDWIN(fy);
+ }
+ while (ty >= 0)
+ {
+ if (AllocMline(mlt, wi + 1))
+ goto nomem;
+ MakeBlankLine(mlt->image, wi + 1);
+ if (--ty >= 0)
+ mlt = NEWWIN(ty);
+ }
+
+#ifdef DEBUG
+ if (nmlines != p->w_mlines)
+ for (fy = 0; fy < p->w_height + p->w_histheight; fy++)
+ {
+ ml = OLDWIN(fy);
+ ASSERT(ml->image == 0);
+ }
+#endif
+
+ if (p->w_mlines && p->w_mlines != nmlines)
+ free((char *)p->w_mlines);
+ p->w_mlines = nmlines;
+#ifdef COPY_PASTE
+ if (p->w_hlines && p->w_hlines != nhlines)
+ free((char *)p->w_hlines);
+ p->w_hlines = nhlines;
+#endif
+
+ /* change tabs */
+ if (p->w_width != wi)
+ {
+ if (wi)
+ {
+ t = p->w_tabs ? p->w_width : 0;
+ p->w_tabs = xrealloc(p->w_tabs, wi + 1);
+ if (p->w_tabs == 0)
+ {
+ nomem:
+ if (nmlines)
+ {
+ for (ty = he + hi - 1; ty >= 0; ty--)
+ {
+ mlt = NEWWIN(ty);
+ FreeMline(mlt);
+ }
+ if (nmlines && p->w_mlines != nmlines)
+ free((char *)nmlines);
+#ifdef COPY_PASTE
+ if (nhlines && p->w_hlines != nhlines)
+ free((char *)nhlines);
+#endif
+ }
+ KillWindow(p);
+ Msg(0, "%s", strnomem);
+ if (nmlines)
+ free(nmlines);
+ if (nhlines)
+ free(nhlines);
+ return -1;
+ }
+ for (; t < wi; t++)
+ p->w_tabs[t] = t && !(t & 7) ? 1 : 0;
+ p->w_tabs[wi] = 0;
+ }
+ else
+ {
+ if (p->w_tabs)
+ free(p->w_tabs);
+ p->w_tabs = 0;
+ }
+ }
+
+ /* Change w_saved.y - this is only an estimate... */
+ p->w_saved.y += ncy - p->w_y;
+
+ p->w_x = ncx;
+ p->w_y = ncy;
+ if (p->w_autoaka > 0)
+ p->w_autoaka = naka;
+
+ /* do sanity checks */
+ if (p->w_x > wi)
+ p->w_x = wi;
+ if (p->w_y >= he)
+ p->w_y = he - 1;
+ if (p->w_saved.x > wi)
+ p->w_saved.x = wi;
+ if (p->w_saved.y >= he)
+ p->w_saved.y = he - 1;
+ if (p->w_saved.y < 0)
+ p->w_saved.y = 0;
+ if (p->w_alt.cursor.x > wi)
+ p->w_alt.cursor.x = wi;
+ if (p->w_alt.cursor.y >= he)
+ p->w_alt.cursor.y = he - 1;
+ if (p->w_alt.cursor.y < 0)
+ p->w_alt.cursor.y = 0;
+
+ /* reset scrolling region */
+ p->w_top = 0;
+ p->w_bot = he - 1;
+
+ /* signal new size to window */
+#ifdef TIOCSWINSZ
+ if (wi && (p->w_width != wi || p->w_height != he)
+ && p->w_width != 0 && p->w_height != 0 && p->w_ptyfd >= 0 && p->w_pid)
+ {
+ glwz.ws_col = wi;
+ glwz.ws_row = he;
+ debug("Setting pty winsize.\n");
+ if (ioctl(p->w_ptyfd, TIOCSWINSZ, (char *)&glwz))
+ debug2("SetPtySize: errno %d (fd:%d)\n", errno, p->w_ptyfd);
+ }
+#endif /* TIOCSWINSZ */
+
+ /* store new size */
+ p->w_width = wi;
+ p->w_height = he;
+ if(p->w_scrollback_height > hi)
+ p->w_scrollback_height = hi;
+#ifdef COPY_PASTE
+ p->w_histidx = 0;
+ p->w_histheight = hi;
+#endif
+
+#ifdef BUILTIN_TELNET
+ if (p->w_type == W_TYPE_TELNET)
+ TelWindowSize(p);
+#endif
+
+#ifdef DEBUG
+ /* Test if everything was ok */
+ for (fy = 0; fy < p->w_height + p->w_histheight; fy++)
+ {
+ ml = OLDWIN(fy);
+ ASSERT(ml->image);
+# ifdef UTF8
+ if (p->w_encoding == UTF8)
+ {
+ for (l = 0; l < p->w_width; l++)
+ ASSERT(ml->image[l] >= ' ' || ml->font[l] || ml->fontx);
+ }
+ else
+#endif
+ for (l = 0; l < p->w_width; l++)
+ ASSERT(ml->image[l] >= ' ');
+ }
+#endif
+ return 0;
+}
+
+void
+FreeAltScreen(p)
+struct win *p;
+{
+ int i;
+
+ if (p->w_alt.mlines)
+ {
+ for (i = 0; i < p->w_alt.height; i++)
+ FreeMline(p->w_alt.mlines + i);
+ free(p->w_alt.mlines);
+ }
+ p->w_alt.mlines = 0;
+ p->w_alt.width = 0;
+ p->w_alt.height = 0;
+#ifdef COPY_PASTE
+ if (p->w_alt.hlines)
+ {
+ for (i = 0; i < p->w_alt.histheight; i++)
+ FreeMline(p->w_alt.hlines + i);
+ free(p->w_alt.hlines);
+ }
+ p->w_alt.hlines = 0;
+ p->w_alt.histidx = 0;
+ p->w_alt.histheight = 0;
+#endif
+}
+
+static void
+SwapAltScreen(p)
+struct win *p;
+{
+ struct mline *ml;
+ int t;
+
+#define SWAP(item, t) do { (t) = p->w_alt. item; p->w_alt. item = p->w_##item; p->w_##item = (t); } while (0)
+
+ SWAP(mlines, ml);
+ SWAP(width, t);
+ SWAP(height, t);
+
+#ifdef COPY_PASTE
+ SWAP(histheight, t);
+ SWAP(hlines, ml);
+ SWAP(histidx, t);
+#endif
+#undef SWAP
+}
+
+void
+EnterAltScreen(p)
+struct win *p;
+{
+ if (!p->w_alt.on)
+ {
+ /* If not already using the alternate screen buffer, then create
+ a new one and swap it with the 'real' screen buffer. */
+ FreeAltScreen(p);
+ SwapAltScreen(p);
+ }
+ else
+ {
+ /* Already using the alternate buffer. Just clear the screen. To do so, it
+ is only necessary to reset the height(s) without resetting the width. */
+ p->w_height = 0;
+ p->w_histheight = 0;
+ }
+ ChangeWindowSize(p, p->w_alt.width, p->w_alt.height, p->w_alt.histheight);
+ p->w_alt.on = 1;
+}
+
+void
+LeaveAltScreen(p)
+struct win *p;
+{
+ if (!p->w_alt.on)
+ return;
+ SwapAltScreen(p);
+ ChangeWindowSize(p, p->w_alt.width, p->w_alt.height, p->w_alt.histheight);
+ FreeAltScreen(p);
+ p->w_alt.on = 0;
+}
diff --git a/sched.c b/sched.c
new file mode 100644
index 0000000..c2e00df
--- /dev/null
+++ b/sched.c
@@ -0,0 +1,290 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+#if !defined(sun) && !defined(B43) && !defined(ISC) && !defined(pyr) && !defined(_CX_UX)
+# include <time.h>
+#endif
+#include <sys/time.h>
+
+#include "config.h"
+#include "screen.h"
+#include "extern.h"
+
+static struct event *evs;
+static struct event *tevs;
+static struct event *nextev;
+static int calctimeout;
+
+static struct event *calctimo __P((void));
+#if (defined(sgi) && defined(SVR4)) || defined(__osf__) || defined(M_UNIX)
+static int sgihack __P((void));
+#endif
+
+void
+evenq(ev)
+struct event *ev;
+{
+ struct event *evp, **evpp;
+ debug3("New event fd %d type %d queued %d\n", ev->fd, ev->type, ev->queued);
+ if (ev->queued)
+ return;
+ evpp = &evs;
+ if (ev->type == EV_TIMEOUT)
+ {
+ calctimeout = 1;
+ evpp = &tevs;
+ }
+ for (; (evp = *evpp); evpp = &evp->next)
+ if (ev->pri > evp->pri)
+ break;
+ ev->next = evp;
+ *evpp = ev;
+ ev->queued = 1;
+}
+
+void
+evdeq(ev)
+struct event *ev;
+{
+ struct event *evp, **evpp;
+ debug3("Deq event fd %d type %d queued %d\n", ev->fd, ev->type, ev->queued);
+ if (!ev->queued)
+ return;
+ evpp = &evs;
+ if (ev->type == EV_TIMEOUT)
+ {
+ calctimeout = 1;
+ evpp = &tevs;
+ }
+ for (; (evp = *evpp); evpp = &evp->next)
+ if (evp == ev)
+ break;
+ ASSERT(evp);
+ *evpp = ev->next;
+ ev->queued = 0;
+ if (ev == nextev)
+ nextev = nextev->next;
+}
+
+static struct event *
+calctimo()
+{
+ struct event *ev, *min;
+ long mins;
+
+ if ((min = tevs) == 0)
+ return 0;
+ mins = min->timeout.tv_sec;
+ for (ev = tevs->next; ev; ev = ev->next)
+ {
+ ASSERT(ev->type == EV_TIMEOUT);
+ if (mins < ev->timeout.tv_sec)
+ continue;
+ if (mins > ev->timeout.tv_sec || min->timeout.tv_usec > ev->timeout.tv_usec)
+ {
+ min = ev;
+ mins = ev->timeout.tv_sec;
+ }
+ }
+ return min;
+}
+
+void
+sched()
+{
+ struct event *ev;
+ fd_set r, w, *set;
+ struct event *timeoutev = 0;
+ struct timeval timeout;
+ int nsel;
+
+ for (;;)
+ {
+ if (calctimeout)
+ timeoutev = calctimo();
+ if (timeoutev)
+ {
+ gettimeofday(&timeout, NULL);
+ /* tp - timeout */
+ timeout.tv_sec = timeoutev->timeout.tv_sec - timeout.tv_sec;
+ timeout.tv_usec = timeoutev->timeout.tv_usec - timeout.tv_usec;
+ if (timeout.tv_usec < 0)
+ {
+ timeout.tv_usec += 1000000;
+ timeout.tv_sec--;
+ }
+ if (timeout.tv_sec < 0)
+ {
+ timeout.tv_usec = 0;
+ timeout.tv_sec = 0;
+ }
+ }
+#ifdef DEBUG
+ debug("waiting for events");
+ if (timeoutev)
+ debug2(" timeout %d secs %d usecs", timeout.tv_sec, timeout.tv_usec);
+ debug(":\n");
+ for (ev = evs; ev; ev = ev->next)
+ debug3(" - fd %d type %d pri %d\n", ev->fd, ev->type, ev->pri);
+ if (tevs)
+ debug("timed events:\n");
+ for (ev = tevs; ev; ev = ev->next)
+ debug3(" - pri %d sec %d usec %d\n", ev->pri, ev->timeout.tv_sec, ev->timeout.tv_usec);
+#endif
+
+ FD_ZERO(&r);
+ FD_ZERO(&w);
+ for (ev = evs; ev; ev = ev->next)
+ {
+ if (ev->condpos && *ev->condpos <= (ev->condneg ? *ev->condneg : 0))
+ {
+ debug2(" - cond ev fd %d type %d failed\n", ev->fd, ev->type);
+ continue;
+ }
+ if (ev->type == EV_READ)
+ FD_SET(ev->fd, &r);
+ else if (ev->type == EV_WRITE)
+ FD_SET(ev->fd, &w);
+ }
+
+#ifdef DEBUG
+ debug("readfds:");
+ for (nsel = 0; nsel < FD_SETSIZE; nsel++)
+ if (FD_ISSET(nsel, &r))
+ debug1(" %d", nsel);
+ debug("\n");
+ debug("writefds:");
+ for (nsel = 0; nsel < FD_SETSIZE; nsel++)
+ if (FD_ISSET(nsel, &w))
+ debug1(" %d", nsel);
+ debug("\n");
+#endif
+
+ nsel = select(FD_SETSIZE, &r, &w, (fd_set *)0, timeoutev ? &timeout : (struct timeval *) 0);
+ if (nsel < 0)
+ {
+ if (errno != EINTR)
+ {
+#if defined(sgi) && defined(SVR4)
+ if (errno == EIO && sgihack())
+ continue;
+#endif
+#if defined(__osf__) || defined(M_UNIX)
+ /* OSF/1 3.x, SCO bug: EBADF */
+ /* OSF/1 4.x bug: EIO */
+ if ((errno == EIO || errno == EBADF) && sgihack())
+ continue;
+#endif
+ Panic(errno, "select");
+ }
+ nsel = 0;
+ }
+ else if (nsel == 0) /* timeout */
+ {
+ debug("TIMEOUT!\n");
+ ASSERT(timeoutev);
+ evdeq(timeoutev);
+ timeoutev->handler(timeoutev, timeoutev->data);
+ }
+#ifdef SELECT_BROKEN
+ /*
+ * Sequents select emulation counts a descriptor which is
+ * readable and writeable only as one hit. Waaaaa.
+ */
+ if (nsel)
+ nsel = 2 * FD_SETSIZE;
+#endif
+
+ for (ev = evs; ev; ev = nextev)
+ {
+ nextev = ev->next;
+ if (ev->type != EV_ALWAYS)
+ {
+ set = ev->type == EV_READ ? &r : &w;
+ if (nsel == 0 || !FD_ISSET(ev->fd, set))
+ continue;
+ nsel--;
+ }
+ if (ev->condpos && *ev->condpos <= (ev->condneg ? *ev->condneg : 0))
+ continue;
+ debug2(" + hit ev fd %d type %d!\n", ev->fd, ev->type);
+ ev->handler(ev, ev->data);
+ }
+ }
+}
+
+void
+SetTimeout(ev, timo)
+struct event *ev;
+int timo;
+{
+ ASSERT(ev->type == EV_TIMEOUT);
+ debug2("event %x new timeout %d ms\n", ev, timo);
+ gettimeofday(&ev->timeout, NULL);
+ ev->timeout.tv_sec += timo / 1000;
+ ev->timeout.tv_usec += (timo % 1000) * 1000;
+ if (ev->timeout.tv_usec > 1000000)
+ {
+ ev->timeout.tv_usec -= 1000000;
+ ev->timeout.tv_sec++;
+ }
+ if (ev->queued)
+ calctimeout = 1;
+}
+
+
+#if (defined(sgi) && defined(SVR4)) || defined(__osf__) || defined(M_UNIX)
+
+extern struct display *display, *displays;
+static int sgihack()
+{
+ fd_set r, w;
+ struct timeval tv;
+
+ debug("IRIX5.2 workaround: searching for bad display\n");
+ for (display = displays; display; )
+ {
+ FD_ZERO(&r);
+ FD_ZERO(&w);
+ FD_SET(D_userfd, &r);
+ FD_SET(D_userfd, &w);
+ tv.tv_sec = tv.tv_usec = 0;
+ if (select(FD_SETSIZE, &r, &w, (fd_set *)0, &tv) == -1)
+ {
+ if (errno == EINTR)
+ continue;
+ Hangup(); /* goodbye display */
+ return 1;
+ }
+ display = display->d_next;
+ }
+ return 0;
+}
+
+#endif
diff --git a/sched.h b/sched.h
new file mode 100644
index 0000000..fdc3fc4
--- /dev/null
+++ b/sched.h
@@ -0,0 +1,48 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+struct event
+{
+ struct event *next;
+ void (*handler) __P((struct event *, char *));
+ char *data;
+ int fd;
+ int type;
+ int pri;
+ struct timeval timeout;
+ int queued; /* in evs queue */
+ int active; /* in fdset */
+ int *condpos; /* only active if condpos - condneg > 0 */
+ int *condneg;
+};
+
+#define EV_TIMEOUT 0
+#define EV_READ 1
+#define EV_WRITE 2
+#define EV_ALWAYS 3
diff --git a/screen.c b/screen.c
new file mode 100644
index 0000000..c3417e3
--- /dev/null
+++ b/screen.c
@@ -0,0 +1,3416 @@
+/* Copyright (c) 2010
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+#ifdef HAVE_BRAILLE
+ * Modified by:
+ * Authors: Hadi Bargi Rangin bargi@dots.physics.orst.edu
+ * Bill Barry barryb@dots.physics.orst.edu
+ * Randy Lundquist randyl@dots.physics.orst.edu
+ *
+ * Modifications Copyright (c) 1995 by
+ * Science Access Project, Oregon State University.
+#endif
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+#ifdef _AIX
+#include <sys/socket.h>
+#endif
+#include <ctype.h>
+#include <stdbool.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#if defined(__sun)
+# include <limits.h>
+#endif
+
+#ifdef sgi
+# include <sys/sysmacros.h>
+#endif
+
+#include <sys/stat.h>
+#ifndef sun
+# include <sys/ioctl.h>
+#endif
+
+#ifndef SIGINT
+# include <signal.h>
+#endif
+
+#include "config.h"
+
+#ifdef HAVE_STROPTS_H
+# include <sys/stropts.h>
+#endif
+
+#if defined(SYSV) && !defined(ISC)
+# include <sys/utsname.h>
+#endif
+
+#if defined(sequent) || defined(SVR4)
+# include <sys/resource.h>
+#endif /* sequent || SVR4 */
+
+#ifdef ISC
+# include <sys/tty.h>
+# include <sys/sioctl.h>
+# include <sys/pty.h>
+#endif /* ISC */
+
+#if (defined(AUX) || defined(_AUX_SOURCE)) && defined(POSIX)
+# include <compat.h>
+#endif
+#if defined(USE_LOCALE) || defined(ENCODINGS)
+# include <locale.h>
+#endif
+#if defined(HAVE_NL_LANGINFO) && defined(ENCODINGS)
+# include <langinfo.h>
+#endif
+
+#include "screen.h"
+#ifdef HAVE_BRAILLE
+# include "braille.h"
+#endif
+
+#include "patchlevel.h"
+
+/*
+ * At the moment we only need the real password if the
+ * builtin lock is used. Therefore disable SHADOWPW if
+ * we do not really need it (kind of security thing).
+ */
+#ifndef LOCK
+# undef SHADOWPW
+#endif
+
+#include <pwd.h>
+#ifdef SHADOWPW
+# include <shadow.h>
+#endif /* SHADOWPW */
+
+#include "logfile.h" /* islogfile, logfflush, logfopen/logfclose */
+
+#ifdef DEBUG
+FILE *dfp;
+#endif
+
+
+extern char Term[], screenterm[], **environ, Termcap[];
+int force_vt = 1;
+int VBellWait, MsgWait, MsgMinWait, SilenceWait;
+
+extern struct acluser *users;
+extern struct display *displays, *display;
+extern struct LayFuncs MarkLf;
+
+extern int visual_bell;
+#ifdef COPY_PASTE
+extern unsigned char mark_key_tab[];
+#endif
+extern char version[];
+extern char DefaultShell[];
+#ifdef ZMODEM
+extern char *zmodem_sendcmd;
+extern char *zmodem_recvcmd;
+#endif
+extern struct layout *layout_last;
+
+char *ShellProg;
+char *ShellArgs[2];
+
+extern struct NewWindow nwin_undef, nwin_default, nwin_options;
+struct backtick;
+
+static struct passwd *getpwbyname __P((char *, struct passwd *));
+static void SigChldHandler __P((void));
+static sigret_t SigChld __P(SIGPROTOARG);
+static sigret_t SigInt __P(SIGPROTOARG);
+static sigret_t CoreDump __P(SIGPROTOARG);
+static sigret_t FinitHandler __P(SIGPROTOARG);
+static void DoWait __P((void));
+static void serv_read_fn __P((struct event *, char *));
+static void serv_select_fn __P((struct event *, char *));
+static void logflush_fn __P((struct event *, char *));
+static void backtick_filter __P((struct backtick *));
+static void backtick_fn __P((struct event *, char *));
+static char *runbacktick __P((struct backtick *, int *, time_t));
+static int IsSymbol __P((char *, char *));
+static char *ParseChar __P((char *, char *));
+static int ParseEscape __P((char *));
+static char *pad_expand __P((char *, char *, int, int));
+static void SetTtyname __P((bool, struct stat *));
+#ifdef DEBUG
+static void fds __P((void));
+#endif
+
+int nversion; /* numerical version, used for secondary DA */
+
+/* the attacher */
+struct passwd *ppp;
+char *attach_tty;
+/* Indicator whether the current tty exists in another namespace. */
+bool attach_tty_is_in_new_ns = false;
+/* Content of the tty symlink when attach_tty_is_in_new_ns == true. */
+char attach_tty_name_in_ns[MAXPATHLEN];
+int attach_fd = -1;
+char *attach_term;
+char *LoginName;
+struct mode attach_Mode;
+
+char SockPath[MAXPATHLEN + 2 * MAXSTR];
+char *SockName; /* SockName is pointer in SockPath */
+char *SockMatch = NULL; /* session id command line argument */
+int ServerSocket = -1;
+struct event serv_read;
+struct event serv_select;
+struct event logflushev;
+
+char **NewEnv = NULL;
+
+char *RcFileName = NULL;
+char *home;
+
+char *screenlogfile; /* filename layout */
+int log_flush = 10; /* flush interval in seconds */
+int logtstamp_on = 0; /* tstamp disabled */
+char *logtstamp_string; /* stamp layout */
+int logtstamp_after = 120; /* first tstamp after 120s */
+char *hardcopydir = NULL;
+char *BellString;
+char *VisualBellString;
+char *ActivityString;
+#ifdef COPY_PASTE
+char *BufferFile;
+#endif
+#ifdef POW_DETACH
+char *PowDetachString;
+#endif
+char *hstatusstring;
+char *captionstring;
+char *timestring;
+char *wliststr;
+char *wlisttit;
+int auto_detach = 1;
+int iflag, rflag, dflag, lsflag, quietflag, wipeflag, xflag;
+int cmdflag;
+int queryflag = -1;
+int adaptflag;
+
+#ifdef MULTIUSER
+char *multi;
+char *multi_home;
+int multi_uid;
+int own_uid;
+int multiattach;
+int tty_mode;
+int tty_oldmode = -1;
+#endif
+
+char HostName[MAXSTR];
+int MasterPid, PanicPid;
+int real_uid, real_gid, eff_uid, eff_gid;
+int default_startup;
+int ZombieKey_destroy, ZombieKey_resurrect, ZombieKey_onerror;
+char *preselect = NULL; /* only used in Attach() */
+
+#ifdef UTF8
+char *screenencodings;
+#endif
+
+#ifdef DW_CHARS
+int cjkwidth;
+#endif
+
+#ifdef NETHACK
+int nethackflag = 0;
+#endif
+int maxwin;
+
+struct layer *flayer;
+struct win *fore;
+struct win *windows;
+struct win *console_window;
+
+#ifdef BUILTIN_TELNET
+int af;
+#endif
+
+/*
+ * Do this last
+ */
+#include "extern.h"
+
+char strnomem[] = "Out of memory.";
+
+static int InterruptPlease;
+static int GotSigChld;
+
+static int lf_secreopen(name, wantfd, l)
+char *name;
+int wantfd;
+
+struct logfile *l;
+{
+ int got_fd;
+ close(wantfd);
+ if (((got_fd = secopen(name, O_WRONLY | O_CREAT | O_APPEND, 0666)) < 0) || lf_move_fd(got_fd, wantfd) < 0) {
+ logfclose(l);
+ debug1("lf_secreopen: failed for %s\n", name);
+ return -1;
+ }
+ l->st->st_ino = l->st->st_dev = 0;
+ debug2("lf_secreopen: %d = %s\n", wantfd, name);
+ return 0;
+}
+
+/********************************************************************/
+/********************************************************************/
+/********************************************************************/
+
+static struct passwd * getpwbyname(name, ppp)
+char *name;
+
+struct passwd *ppp;
+{
+ int n;
+#ifdef SHADOWPW
+ struct spwd *sss = NULL;
+ static char *spw = NULL;
+#endif
+
+ if (!ppp && !(ppp = getpwnam(name)))
+ return NULL;
+
+ /* Do password sanity check..., allow ##user for SUN_C2 security */
+#ifdef SHADOWPW
+pw_try_again:
+#endif
+ n = 0;
+ if (ppp->pw_passwd[0] == '#' && ppp->pw_passwd[1] == '#' && strcmp(ppp->pw_passwd + 2, ppp->pw_name) == 0)
+ n = 13;
+ for (; n < 13; n++) {
+ char c = ppp->pw_passwd[n];
+ if (!(c == '.' || c == '/' || c == '$' ||
+ (c >= '0' && c <= '9') ||
+ (c >= 'a' && c <= 'z') ||
+ (c >= 'A' && c <= 'Z')))
+ break;
+ }
+
+#ifdef SHADOWPW
+ /* try to determine real password */
+ if (n < 13 && sss == 0) {
+ sss = getspnam(ppp->pw_name);
+ if (sss) {
+ if (spw)
+ free(spw);
+ ppp->pw_passwd = spw = SaveStr(sss->sp_pwdp);
+ endspent(); /* this should delete all buffers ... */
+ goto pw_try_again;
+ }
+ endspent(); /* this should delete all buffers ... */
+ }
+#endif
+ if (n < 13)
+ ppp->pw_passwd = 0;
+#ifdef linux
+ if (ppp->pw_passwd && strlen(ppp->pw_passwd) == 13 + 11)
+ ppp->pw_passwd[13] = 0; /* beware of linux's long passwords */
+#endif
+
+ return ppp;
+}
+
+static char *locale_name(void)
+{
+ static char *s;
+ if (!s) {
+ s = getenv("LC_ALL");
+ if (s == NULL)
+ s = getenv("LC_CTYPE");
+ if (s == NULL)
+ s = getenv("LANG");
+ }
+ return s;
+}
+
+int main(int ac, char** av)
+{
+ register int n;
+ char *ap;
+ char *av0;
+ char socknamebuf[2 * MAXSTR];
+ int mflag = 0;
+ char *myname = (ac == 0) ? "screen" : av[0];
+ char *SockDir;
+ struct stat st;
+#ifdef _MODE_T /* (jw) */
+ mode_t oumask;
+#else
+ int oumask;
+#endif
+#if defined(SYSV) && !defined(ISC)
+ struct utsname utsnam;
+#endif
+ struct NewWindow nwin;
+ int detached = 0; /* start up detached */
+#ifdef MULTIUSER
+ char *sockp;
+#endif
+ char *sty = 0;
+
+#if (defined(AUX) || defined(_AUX_SOURCE)) && defined(POSIX)
+ setcompat(COMPAT_POSIX|COMPAT_BSDPROT); /* turn on seteuid support */
+#endif
+#if defined(sun) && defined(SVR4)
+ {
+ /* Solaris' login blocks SIGHUP! This is _very bad_ */
+ sigset_t sset;
+ sigemptyset(&sset);
+ sigprocmask(SIG_SETMASK, &sset, 0);
+ }
+#endif
+
+ /*
+ * First, close all unused descriptors
+ * (otherwise, we might have problems with the select() call)
+ */
+ closeallfiles(0);
+#ifdef DEBUG
+ opendebug(1, 0);
+#endif
+ snprintf(version, 59, "%d.%.2d.%.2d%s (%s%s) %s", REV, VERS,
+ PATCHLEVEL, STATE, ORIGIN, GIT_REV, DATE);
+ nversion = REV * 10000 + VERS * 100 + PATCHLEVEL;
+ debug2("-- screen debug started %s (%s)\n", *av, version);
+#ifdef POSIX
+ debug("POSIX\n");
+#endif
+#ifdef TERMIO
+ debug("TERMIO\n");
+#endif
+#ifdef SYSV
+ debug("SYSV\n");
+#endif
+#ifdef SYSVSIGS
+ debug("SYSVSIGS\n");
+#endif
+#if defined(SIGWINCH) && defined(TIOCGWINSZ)
+ debug("Window size changing enabled\n");
+#endif
+#ifdef HAVE_SETREUID
+ debug("SETREUID\n");
+#endif
+#ifdef HAVE_SETEUID
+ debug("SETEUID\n");
+#endif
+#ifdef hpux
+ debug("hpux\n");
+#endif
+#ifdef USEBCOPY
+ debug("USEBCOPY\n");
+#endif
+#ifdef UTMPOK
+ debug("UTMPOK\n");
+#endif
+#ifdef LOADAV
+ debug("LOADAV\n");
+#endif
+#ifdef NETHACK
+ debug("NETHACK\n");
+#endif
+#ifdef TERMINFO
+ debug("TERMINFO\n");
+#endif
+#ifdef SHADOWPW
+ debug("SHADOWPW\n");
+#endif
+#ifdef NAME_MAX
+ debug1("NAME_MAX = %d\n", NAME_MAX);
+#endif
+
+ BellString = SaveStr("Bell in window %n");
+ VisualBellString = SaveStr(" Wuff, Wuff!! ");
+ ActivityString = SaveStr("Activity in window %n");
+ screenlogfile = SaveStr("screenlog.%n");
+ logtstamp_string = SaveStr("-- %n:%t -- time-stamp -- %M/%d/%y %c:%s --\n");
+ hstatusstring = SaveStr("%h");
+ captionstring = SaveStr("%4n %t");
+ timestring = SaveStr("%c:%s %M %d %H%? %l%?");
+ wlisttit = SaveStr(" Num Name%=Flags");
+ wliststr = SaveStr("%4n %t%=%f");
+#ifdef COPY_PASTE
+ BufferFile = SaveStr(DEFAULT_BUFFERFILE);
+#endif
+ ShellProg = NULL;
+#ifdef POW_DETACH
+ PowDetachString = 0;
+#endif
+ default_startup = (ac > 1) ? 0 : 1;
+ adaptflag = 0;
+ VBellWait = VBELLWAIT * 1000;
+ MsgWait = MSGWAIT * 1000;
+ MsgMinWait = MSGMINWAIT * 1000;
+ SilenceWait = SILENCEWAIT;
+#ifdef HAVE_BRAILLE
+ InitBraille();
+#endif
+#ifdef ZMODEM
+ zmodem_sendcmd = SaveStr("!!! sz -vv -b ");
+ zmodem_recvcmd = SaveStr("!!! rz -vv -b -E");
+#endif
+
+#ifdef COPY_PASTE
+ CompileKeys((char *)0, 0, mark_key_tab);
+#endif
+#ifdef UTF8
+ InitBuiltinTabs();
+ screenencodings = SaveStr(SCREENENCODINGS);
+#endif
+#ifdef DW_CHARS
+ cjkwidth = 0;
+#endif
+ nwin = nwin_undef;
+ nwin_options = nwin_undef;
+ strncpy(screenterm, "screen", MAXTERMLEN);
+ screenterm[MAXTERMLEN] = '\0';
+#ifdef BUILTIN_TELNET
+ af = AF_UNSPEC;
+#endif
+
+ real_uid = getuid();
+ real_gid = getgid();
+ eff_uid = geteuid();
+ eff_gid = getegid();
+
+ logreopen_register(lf_secreopen);
+
+ av0 = *av; /* if this is a login screen, assume -RR */
+ if (*av0 == '-') {
+ rflag = 4;
+#ifdef MULTI
+ xflag = 1;
+#else
+ dflag = 1;
+#endif
+ ShellProg = SaveStr(DefaultShell); /* to prevent nasty circles */
+ }
+
+ while (ac > 0){
+ ap = *++av;
+ if (--ac > 0 && *ap == '-') {
+ if (ap[1] == '-' && ap[2] == 0) {
+ av++;
+ ac--;
+ break;
+ }
+
+ if (ap[1] == '-' && !strcmp(ap, "--version"))
+ Panic(0, "Screen version %s", version);
+ if (ap[1] == '-' && !strcmp(ap, "--help"))
+ exit_with_usage(myname, NULL, NULL);
+
+ while (ap && *ap && *++ap) {
+ switch (*ap) {
+
+#ifdef BUILTIN_TELNET
+ case '4':
+ af = AF_INET;
+ break;
+
+ case '6':
+ af = AF_INET6;
+ break;
+#endif
+
+ case 'a':
+ nwin_options.aflag = 1;
+ break;
+
+ case 'A':
+ adaptflag = 1;
+ break;
+
+ case 'p': /* preselect */
+ if (*++ap)
+ preselect = ap;
+ else {
+ if (!--ac)
+ exit_with_usage(myname, "Specify a window to preselect with -p", NULL);
+ preselect = *++av;
+ }
+ ap = NULL;
+ break;
+
+#ifdef HAVE_BRAILLE
+ case 'B':
+ bd.bd_start_braille = 1;
+ break;
+#endif
+
+ case 'c':
+ if (*++ap)
+ RcFileName = ap;
+ else {
+ if (--ac == 0)
+ exit_with_usage(myname, "Specify an alternate rc-filename with -c", NULL);
+ RcFileName = *++av;
+ }
+ ap = NULL;
+ break;
+
+ case 'e':
+ if (!*++ap) {
+ if (--ac == 0)
+ exit_with_usage(myname, "Specify command characters with -e", NULL);
+ ap = *++av;
+ }
+ if (ParseEscape(ap))
+ Panic(0, "Two characters are required with -e option, not '%s'.", ap);
+ ap = NULL;
+ break;
+
+ case 'f':
+ ap++;
+ switch (*ap++) {
+ case 'n':
+ case '0':
+ nwin_options.flowflag = FLOW_NOW * 0;
+ break;
+ case '\0':
+ ap--;
+ /* FALLTHROUGH */
+ case 'y':
+ case '1':
+ nwin_options.flowflag = FLOW_NOW * 1;
+ break;
+ case 'a':
+ nwin_options.flowflag = FLOW_AUTOFLAG;
+ break;
+ default:
+ exit_with_usage(myname, "Unknown flow option -%s", --ap);
+ }
+ break;
+
+ case 'h':
+ if (--ac == 0)
+ exit_with_usage(myname, NULL, NULL);
+ nwin_options.histheight = atoi(*++av);
+ if (nwin_options.histheight < 0)
+ exit_with_usage(myname, "-h: %s: negative scrollback size?", *av);
+ break;
+
+ case 'i':
+ iflag = 1;
+ break;
+
+ case 't': /* title, the former AkA == -k */
+ if (--ac == 0)
+ exit_with_usage(myname, "Specify a new window-name with -t", NULL);
+ nwin_options.aka = *++av;
+ break;
+
+ case 'l':
+ ap++;
+ switch (*ap++) {
+ case 'n':
+ case '0':
+ nwin_options.lflag = 0;
+ break;
+ case '\0':
+ ap--;
+ /* FALLTHROUGH */
+ case 'y':
+ case '1':
+ nwin_options.lflag = 1;
+ break;
+ case 'a':
+ nwin_options.lflag = 3;
+ break;
+ case 's': /* -ls */
+ case 'i': /* -list */
+ lsflag = 1;
+ if (ac > 1 && !SockMatch) {
+ SockMatch = *++av;
+ ac--;
+ }
+ ap = NULL;
+ break;
+ default:
+ exit_with_usage(myname, "%s: Unknown suboption to -l", --ap);
+ }
+ break;
+
+ case 'w':
+ if (strcmp(ap+1, "ipe"))
+ exit_with_usage(myname, "Unknown option %s", --ap);
+ lsflag = 1;
+ wipeflag = 1;
+ if (ac > 1 && !SockMatch) {
+ SockMatch = *++av;
+ ac--;
+ }
+ break;
+
+ case 'L':
+ if (!strcmp(ap + 1, "ogfile")) {
+ if (--ac == 0)
+ exit_with_usage(myname, "Specify logfile path with -Logfile", NULL);
+
+ if (strlen(*++av) > PATH_MAX)
+ Panic(1, "-Logfile name too long. (max. %d char)", PATH_MAX);
+
+ free(screenlogfile); /* we already set it up while starting */
+ screenlogfile = SaveStr(*av);
+
+ ap = NULL;
+ } else if (!strcmp(ap, "L"))
+ nwin_options.Lflag = 1;
+
+ break;
+
+ case 'm':
+ mflag = 1;
+ break;
+
+ case 'O': /* to be (or not to be?) deleted. jw. */
+ force_vt = 0;
+ break;
+
+ case 'T':
+ if (--ac == 0)
+ exit_with_usage(myname, "Specify terminal-type with -T", NULL);
+ if (strlen(*++av) < MAXTERMLEN) {
+ strncpy(screenterm, *av, MAXTERMLEN);
+ screenterm[MAXTERMLEN] = '\0';
+ } else
+ Panic(0, "-T: terminal name too long. (max. %d char)", MAXTERMLEN);
+ nwin_options.term = screenterm;
+ break;
+
+ case 'q':
+ quietflag = 1;
+ break;
+
+ case 'Q':
+ queryflag = 1;
+ cmdflag = 1;
+ break;
+
+ case 'r':
+ case 'R':
+#ifdef MULTI
+ case 'x':
+#endif
+ if (ac > 1 && *av[1] != '-' && !SockMatch) {
+ SockMatch = *++av;
+ ac--;
+ debug2("rflag=%d, SockMatch=%s\n", dflag, SockMatch);
+ }
+#ifdef MULTI
+ if (*ap == 'x')
+ xflag = 1;
+#endif
+ if (rflag)
+ rflag = 2;
+ rflag += (*ap == 'R') ? 2 : 1;
+ break;
+
+#ifdef REMOTE_DETACH
+ case 'd':
+ dflag = 1;
+ /* FALLTHROUGH */
+
+ case 'D':
+ if (!dflag)
+ dflag = 2;
+ if (ac == 2) {
+ if (*av[1] != '-' && !SockMatch) {
+ SockMatch = *++av;
+ ac--;
+ debug2("dflag=%d, SockMatch=%s\n", dflag, SockMatch);
+ }
+ }
+ break;
+#endif
+
+ case 's':
+ if (--ac == 0)
+ exit_with_usage(myname, "Specify shell with -s", NULL);
+ if (ShellProg)
+ free(ShellProg);
+ ShellProg = SaveStr(*++av);
+ debug1("ShellProg: '%s'\n", ShellProg);
+ break;
+
+ case 'S':
+ if (!SockMatch) {
+ if (--ac == 0)
+ exit_with_usage(myname, "Specify session-name with -S", NULL);
+ SockMatch = *++av;
+ }
+ if (!*SockMatch)
+ exit_with_usage(myname, "Empty session-name?", NULL);
+ break;
+
+ case 'X':
+ cmdflag = 1;
+ break;
+
+ case 'v':
+ Panic(0, "Screen version %s", version);
+ /* NOTREACHED */
+
+#ifdef UTF8
+ case 'U':
+ nwin_options.encoding = nwin_options.encoding == -1 ? UTF8 : 0;
+ break;
+#endif
+
+ default:
+ exit_with_usage(myname, "Unknown option %s", --ap);
+ }
+ }
+ }
+ else
+ break;
+ }
+
+#ifdef SIGBUS /* OOPS, linux has no bus errors! */
+ signal(SIGBUS, CoreDump);
+#endif /* SIGBUS */
+ signal(SIGSEGV, CoreDump);
+
+
+#ifdef USE_LOCALE
+ setlocale(LC_ALL, "");
+#endif
+#ifdef ENCODINGS
+ if (nwin_options.encoding == -1) {
+ /* ask locale if we should start in UTF-8 mode */
+# ifdef HAVE_NL_LANGINFO
+# ifndef USE_LOCALE
+ setlocale(LC_CTYPE, "");
+# endif
+ nwin_options.encoding = FindEncoding(nl_langinfo(CODESET));
+ debug1("locale says encoding = %d\n", nwin_options.encoding);
+# else
+# ifdef UTF8
+ char *s;
+ if ((s = locale_name()) && InStr(s, "UTF-8"))
+ nwin_options.encoding = UTF8;
+# endif
+ debug1("environment says encoding=%d\n", nwin_options.encoding);
+#endif
+ }
+
+# ifdef DW_CHARS
+ {
+ char *s;
+ if ((s = locale_name())) {
+ if(!strncmp(s, "zh_", 3) || !strncmp(s, "ja_", 3) || !strncmp(s, "ko_", 3)) {
+ cjkwidth = 1;
+ }
+ }
+ }
+#endif
+#endif
+
+ if (nwin_options.aka) {
+#ifdef ENCODINGS
+ if (nwin_options.encoding > 0) {
+ size_t len = strlen(nwin_options.aka);
+ size_t newsz;
+ char *newbuf = malloc(3 * len);
+ if (!newbuf)
+ Panic(0, "%s", strnomem);
+ newsz = RecodeBuf((unsigned char *)nwin_options.aka, len,
+ nwin_options.encoding, 0, (unsigned char *)newbuf);
+ newbuf[newsz] = '\0';
+ nwin_options.aka = newbuf;
+ } else
+#endif
+ {
+ /* If we just use the original value from av,
+ subsequent shelltitle invocations will attempt to free
+ space we don't own... */
+ nwin_options.aka = SaveStr(nwin_options.aka);
+ }
+ }
+
+ if (SockMatch && strlen(SockMatch) >= MAXSTR)
+ Panic(0, "Ridiculously long socketname - try again.");
+ if (cmdflag && !rflag && !dflag && !xflag)
+ xflag = 1;
+ if (!cmdflag && dflag && mflag && !(rflag || xflag))
+ detached = 1;
+ nwin = nwin_options;
+
+#ifdef ENCODINGS
+ nwin.encoding = nwin_undef.encoding; /* let screenrc overwrite it */
+#endif
+ if (ac)
+ nwin.args = av;
+
+ /* make the write() calls return -1 on all errors */
+
+#ifdef SIGXFSZ
+ /*
+ * Ronald F. Guilmette, Oct 29 '94, bug-gnu-utils@prep.ai.mit.edu:
+ * It appears that in System V Release 4, UNIX, if you are writing
+ * an output file and you exceed the currently set file size limit,
+ * you _don't_ just get the call to `write' returning with a
+ * failure code. Rather, you get a signal called `SIGXFSZ' which,
+ * if neither handled nor ignored, will cause your program to crash
+ * with a core dump.
+ */
+ signal(SIGXFSZ, SIG_IGN);
+#endif /* SIGXFSZ */
+
+#ifdef SIGPIPE
+ signal(SIGPIPE, SIG_IGN);
+#endif
+
+ if (!ShellProg) {
+ register char *sh;
+ sh = getenv("SHELL");
+ ShellProg = SaveStr(sh ? sh : DefaultShell);
+ }
+ ShellArgs[0] = ShellProg;
+ home = getenv("HOME");
+ if (!mflag && !SockMatch) {
+ sty = getenv("STY");
+ if (sty && *sty == 0)
+ sty = 0;
+ }
+
+#ifdef NETHACK
+ if (!(nethackflag = (getenv("NETHACKOPTIONS") != NULL))) {
+ char nethackrc[MAXPATHLEN];
+
+ if (home && (strlen(home) < (MAXPATHLEN - 20))) {
+ sprintf(nethackrc,"%s/.nethackrc", home);
+ nethackflag = !access(nethackrc, F_OK);
+ }
+ }
+#endif
+
+#ifdef MULTIUSER
+ own_uid = multi_uid = real_uid;
+ if (SockMatch && (sockp = index(SockMatch, '/'))) {
+ *sockp = 0;
+ multi = SockMatch;
+ SockMatch = sockp + 1;
+ if (*multi) {
+ struct passwd *mppp;
+ if ((mppp = getpwnam(multi)) == (struct passwd *)0)
+ Panic(0, "Cannot identify account '%s'.", multi);
+ multi_uid = mppp->pw_uid;
+ multi_home = SaveStr(mppp->pw_dir);
+ if (strlen(multi_home) > MAXPATHLEN - 10)
+ Panic(0, "home directory path too long");
+
+# ifdef MULTI
+ /* always fake multi attach mode */
+ if (rflag || lsflag)
+ xflag = 1;
+# endif /* MULTI */
+ detached = 0;
+ multiattach = 1;
+ }
+ /* Special case: effective user is multiuser. */
+ if (eff_uid && (multi_uid != eff_uid))
+ Panic(0, "Must run suid root for multiuser support.");
+ }
+ if (SockMatch && *SockMatch == 0)
+ SockMatch = 0;
+#endif /* MULTIUSER */
+
+ if ((LoginName = getlogin()) && LoginName[0] != '\0') {
+ if ((ppp = getpwnam(LoginName)) != (struct passwd *) 0)
+ if ((int)ppp->pw_uid != real_uid)
+ ppp = (struct passwd *) 0;
+ }
+ if (ppp == 0) {
+ if ((ppp = getpwuid(real_uid)) == 0) {
+ Panic(0, "getpwuid() can't identify your account!");
+ exit(1);
+ }
+ LoginName = ppp->pw_name;
+ }
+ LoginName = SaveStr(LoginName);
+ ppp = getpwbyname(LoginName, ppp);
+
+#if !defined(SOCKDIR) && defined(MULTIUSER)
+ if (multi && !multiattach) {
+ if (home && strcmp(home, ppp->pw_dir))
+ Panic(0, "$HOME must match passwd entry for multiuser screens.");
+ }
+#endif
+
+#define SET_GUID() do \
+ { \
+ setgid(real_gid); \
+ setuid(real_uid); \
+ eff_uid = real_uid; \
+ eff_gid = real_gid; \
+ } while (0)
+
+ if (home == 0 || *home == '\0')
+ home = ppp->pw_dir;
+ if (strlen(LoginName) > MAXLOGINLEN)
+ Panic(0, "LoginName too long - sorry.");
+
+#ifdef MULTIUSER
+ if (multi && strlen(multi) > MAXLOGINLEN)
+ Panic(0, "Screen owner name too long - sorry.");
+#endif
+ if (strlen(home) > MAXPATHLEN - 25)
+ Panic(0, "$HOME too long - sorry.");
+
+ attach_tty = "";
+ if (!detached && !lsflag && !cmdflag && !(dflag && !mflag && !rflag && !xflag) &&
+ !(sty && !SockMatch && !mflag && !rflag && !xflag)) {
+ int fl;
+
+ /* ttyname implies isatty */
+ SetTtyname(true, &st);
+#ifdef MULTIUSER
+ tty_mode = (int)st.st_mode & 0777;
+#endif
+
+ fl = fcntl(0, F_GETFL, 0);
+ if (fl != -1 && (fl & (O_RDWR|O_RDONLY|O_WRONLY)) == O_RDWR)
+ attach_fd = 0;
+
+
+ if (attach_fd == -1) {
+ if ((n = secopen(attach_tty, O_RDWR | O_NONBLOCK, 0)) < 0)
+ Panic(0, "Cannot open your terminal '%s' - please check.", attach_tty);
+ /* If the server uses a socket we need an open fd. */
+ attach_fd = n;
+ }
+
+ debug2("attach_tty is %s, attach_fd is %d\n", attach_tty, attach_fd);
+
+ if ((attach_term = getenv("TERM")) == 0 || *attach_term == 0)
+ Panic(0, "Please set a terminal type.");
+ if (strlen(attach_term) > MAXTERMLEN)
+ Panic(0, "$TERM too long - sorry.");
+
+ GetTTY(0, &attach_Mode);
+#ifdef DEBUGGGGGGGGGGGGGGG
+ DebugTTY(&attach_Mode);
+#endif /* DEBUG */
+ }
+
+#ifdef _MODE_T
+ oumask = umask(0); /* well, unsigned never fails? jw. */
+#else
+ if ((oumask = (int)umask(0)) == -1)
+ Panic(errno, "Cannot change umask to zero");
+#endif
+
+ SockDir = getenv("SCREENDIR");
+ if (SockDir) {
+ if (strlen(SockDir) >= MAXPATHLEN - 1)
+ Panic(0, "Ridiculously long $SCREENDIR - try again.");
+
+#ifdef MULTIUSER
+ if (multi)
+ Panic(0, "No $SCREENDIR with multi screens, please.");
+#endif
+ }
+
+#ifdef MULTIUSER
+ if (multiattach) {
+# ifndef SOCKDIR
+ sprintf(SockPath, "%s/.screen", multi_home);
+ SockDir = SockPath;
+# else
+ SockDir = SOCKDIR;
+ sprintf(SockPath, "%s/S-%s", SockDir, multi);
+# endif
+ } else
+#endif
+
+ {
+#ifndef SOCKDIR
+ if (SockDir == 0) {
+ sprintf(SockPath, "%s/.screen", home);
+ SockDir = SockPath;
+ }
+#endif
+
+ if (SockDir) {
+ if (access(SockDir, F_OK)) {
+ debug1("SockDir '%s' missing ...\n", SockDir);
+ if (UserContext() > 0) {
+ if (mkdir(SockDir, 0700))
+ UserReturn(0);
+ UserReturn(1);
+ }
+
+ if (UserStatus() <= 0)
+ Panic(0, "Cannot make directory '%s'.", SockDir);
+ }
+ if (SockDir != SockPath)
+ strcpy(SockPath, SockDir);
+ }
+
+#ifdef SOCKDIR
+ else {
+ SockDir = SOCKDIR;
+ if (stat(SockDir, &st)) {
+ n = (eff_uid == 0 && (real_uid || eff_gid == real_gid)) ? 0755 :
+ (eff_gid != real_gid) ? 0775 :
+#ifdef S_ISVTX
+ 0777|S_ISVTX;
+#else
+ 0777;
+#endif
+
+ if (mkdir(SockDir, n) == -1)
+ Panic(errno, "Cannot make directory '%s'", SockDir);
+ }
+ else {
+ if (!S_ISDIR(st.st_mode))
+ Panic(0, "'%s' must be a directory.", SockDir);
+ if (eff_uid == 0 && real_uid && (int)st.st_uid != eff_uid)
+ Panic(0, "Directory '%s' must be owned by root.", SockDir);
+ n = (eff_uid == 0 && (real_uid || (st.st_mode & 0775) != 0775)) ? 0755 :
+ (eff_gid == (int)st.st_gid && eff_gid != real_gid) ? 0775 : 0777;
+ if (((int)st.st_mode & 0777) != n)
+ Panic(0, "Directory '%s' must have mode %03o.", SockDir, n);
+ }
+ sprintf(SockPath, "%s/S-%s", SockDir, LoginName);
+ if (access(SockPath, F_OK)) {
+ if (mkdir(SockPath, 0700) == -1 && errno != EEXIST)
+ Panic(errno, "Cannot make directory '%s'", SockPath);
+ (void) chown(SockPath, real_uid, real_gid);
+ }
+ }
+#endif
+ }
+
+ if (stat(SockPath, &st) == -1)
+ Panic(errno, "Cannot access %s", SockPath);
+ else
+ if (!S_ISDIR(st.st_mode))
+ Panic(0, "%s is not a directory.", SockPath);
+#ifdef MULTIUSER
+ if (multi) {
+ if ((int)st.st_uid != multi_uid)
+ Panic(0, "%s is not the owner of %s.", multi, SockPath);
+ }
+ else
+#endif
+
+ {
+#ifdef SOCKDIR
+/* if SOCKDIR is not defined, the socket is in $HOME.
+ in that case it does not make sense to compare uids. */
+
+ if ((int)st.st_uid != real_uid)
+ Panic(0, "You are not the owner of %s.", SockPath);
+#endif
+ }
+
+ if ((st.st_mode & 0777) != 0700)
+ Panic(0, "Directory %s must have mode 700.", SockPath);
+ if (SockMatch && index(SockMatch, '/'))
+ Panic(0, "Bad session name '%s'", SockMatch);
+ SockName = SockPath + strlen(SockPath) + 1;
+ *SockName = 0;
+ (void) umask(oumask);
+ debug2("SockPath: %s SockMatch: %s\n", SockPath, SockMatch ? SockMatch : "NULL");
+
+#if defined(SYSV) && !defined(ISC)
+ if (uname(&utsnam) == -1)
+ Panic(errno, "uname");
+ strncpy(HostName, utsnam.nodename, sizeof(utsnam.nodename) < MAXSTR ? sizeof(utsnam.nodename) : MAXSTR - 1);
+ HostName[sizeof(utsnam.nodename) < MAXSTR ? sizeof(utsnam.nodename) : MAXSTR - 1] = '\0';
+#else
+
+ (void) gethostname(HostName, MAXSTR);
+ HostName[MAXSTR - 1] = '\0';
+#endif
+ if ((ap = index(HostName, '.')) != NULL)
+ *ap = '\0';
+
+ if (lsflag) {
+ int i, fo, oth;
+ bool sock;
+
+#ifdef MULTIUSER
+ if (multi)
+ real_uid = multi_uid;
+#endif
+
+ SET_GUID();
+ i = FindSocket((int *)NULL, &fo, &oth, SockMatch, &sock);
+ if (quietflag) {
+ if (rflag)
+ exit(10 + i);
+ else
+ exit(9 + (fo || oth ? 1 : 0) + fo);
+ }
+ if (fo == 0)
+ Panic(0, "No Sockets found in %s.\n", SockPath);
+ Msg(0, "%d Socket%s in %s.", fo, fo > 1 ? "s" : "", SockPath);
+ eexit(0);
+ }
+ signal(SIG_BYE, AttacherFinit); /* prevent races */
+ if (cmdflag) {
+ /* attach_tty is not mandatory */
+ SetTtyname(false, &st);
+ if (!*av)
+ Panic(0, "Please specify a command.");
+ SET_GUID();
+ SendCmdMessage(sty, SockMatch, av, queryflag >= 0);
+ exit(0);
+ }
+ else if (rflag || xflag) {
+ debug("screen -r: - is there anybody out there?\n");
+ if (Attach(MSG_ATTACH)) {
+ Attacher();
+ /* NOTREACHED */
+ }
+#ifdef MULTIUSER
+ if (multiattach)
+ Panic(0, "Can't create sessions of other users.");
+#endif
+
+ debug("screen -r: backend not responding -- still crying\n");
+ }
+ else if (dflag && !mflag) {
+ SetTtyname(false, &st);
+ Attach(MSG_DETACH);
+ Msg(0, "[%s %sdetached.]\n", SockName, (dflag > 1 ? "power " : ""));
+ eexit(0);
+ /* NOTREACHED */
+ }
+ if (!SockMatch && !mflag && sty) {
+ /* attach_tty is not mandatory */
+ SetTtyname(false, &st);
+ SET_GUID();
+ nwin_options.args = av;
+ SendCreateMsg(sty, &nwin);
+ exit(0);
+ /* NOTREACHED */
+ }
+ nwin_compose(&nwin_default, &nwin_options, &nwin_default);
+
+ if (!detached || dflag != 2)
+ MasterPid = fork();
+ else
+ MasterPid = 0;
+
+ switch (MasterPid) {
+ case -1:
+ Panic(errno, "fork");
+ /* NOTREACHED */
+ case 0:
+ break;
+ default:
+ if (detached)
+ exit(0);
+ if (SockMatch)
+ sprintf(socknamebuf, "%d.%s", MasterPid, SockMatch);
+ else
+ sprintf(socknamebuf, "%d.%s.%s", MasterPid, stripdev(attach_tty), HostName);
+ for (ap = socknamebuf; *ap; ap++)
+ if (*ap == '/')
+ *ap = '-';
+#ifdef NAME_MAX
+ if (strlen(socknamebuf) > NAME_MAX)
+ socknamebuf[NAME_MAX] = 0;
+#endif
+ sprintf(SockPath + strlen(SockPath), "/%s", socknamebuf);
+ SET_GUID();
+ Attacher();
+ /* NOTREACHED */
+ }
+
+ if (!detached)
+ PanicPid = getppid();
+
+ if (DefaultEsc == -1)
+ DefaultEsc = Ctrl('a');
+ if (DefaultMetaEsc == -1)
+ DefaultMetaEsc = 'a';
+
+ ap = av0 + strlen(av0) - 1;
+ while (ap >= av0) {
+ if (!strncmp("screen", ap, 6)) {
+ strncpy(ap, "SCREEN", 6); /* name this process "SCREEN-BACKEND" */
+ break;
+ }
+ ap--;
+ }
+ if (ap < av0)
+ *av0 = 'S';
+
+#ifdef DEBUG
+ {
+ char buf[256];
+
+ if (dfp && dfp != stderr)
+ fclose(dfp);
+ sprintf(buf, "%s/SCREEN.%d", DEBUGDIR, (int)getpid());
+ if ((dfp = fopen(buf, "w")) == NULL)
+ dfp = stderr;
+ else
+ (void) chmod(buf, 0666);
+ }
+#endif
+
+ if (!detached) {
+ if (attach_fd == -1) {
+ if ((n = secopen(attach_tty, O_RDWR | O_NONBLOCK, 0)) < 0)
+ Panic(0, "Cannot reopen '%s' - please check.", attach_tty);
+ }
+ else
+ n = dup(attach_fd);
+ }
+ else
+ n = -1;
+ freopen("/dev/null", "r", stdin);
+ freopen("/dev/null", "w", stdout);
+
+#ifdef DEBUG
+ if (dfp != stderr)
+#endif
+ freopen("/dev/null", "w", stderr);
+ debug("-- screen.back debug started\n");
+
+ /* This guarantees that the session owner is listed, even when we
+ * start detached. From now on we should not refer to 'LoginName'
+ * any more, use users->u_name instead.
+ */
+ if (UserAdd(LoginName, (char *)0, (struct acluser **)0) < 0)
+ Panic(0, "Could not create user info");
+ if (!detached) {
+ if (MakeDisplay(LoginName, attach_tty, attach_term, n, getppid(), &attach_Mode) == 0)
+ Panic(0, "Could not alloc display");
+ PanicPid = 0;
+#ifdef ENCODINGS
+ D_encoding = nwin_options.encoding > 0 ? nwin_options.encoding : 0;
+ debug1("D_encoding = %d\n", D_encoding);
+#endif
+ }
+
+ if (SockMatch) {
+ /* user started us with -S option */
+ sprintf(socknamebuf, "%d.%s", (int)getpid(), SockMatch);
+ }
+ else {
+ sprintf(socknamebuf, "%d.%s.%s", (int)getpid(), stripdev(attach_tty), HostName);
+ }
+ for (ap = socknamebuf; *ap; ap++)
+ if (*ap == '/')
+ *ap = '-';
+
+#ifdef NAME_MAX
+ if (strlen(socknamebuf) > NAME_MAX) {
+ debug2("Socketname %s truncated to %d chars\n", socknamebuf, NAME_MAX);
+ socknamebuf[NAME_MAX] = 0;
+ }
+#endif
+
+ sprintf(SockPath + strlen(SockPath), "/%s", socknamebuf);
+ /* Always create sockets. We only allow attaching to fifos not creating
+ * new ones.
+ */
+ ServerSocket = MakeServerSocket(true);
+ InitKeytab();
+
+#ifdef ETCSCREENRC
+# ifdef ALLOW_SYSSCREENRC
+ if ((ap = getenv("SYSSCREENRC")))
+ (void)StartRc(ap, 0);
+ else
+# endif
+ (void)StartRc(ETCSCREENRC, 0);
+#endif
+ (void)StartRc(RcFileName, 0);
+# ifdef UTMPOK
+# ifndef UTNOKEEP
+ InitUtmp();
+# endif /* UTNOKEEP */
+# endif /* UTMPOK */
+ if (display) {
+ if (InitTermcap(0, 0)) {
+ debug("Could not init termcap - exiting\n");
+ fcntl(D_userfd, F_SETFL, 0); /* Flush sets FNBLOCK */
+ freetty();
+ if (D_userpid)
+ Kill(D_userpid, SIG_BYE);
+ eexit(1);
+ }
+ MakeDefaultCanvas();
+ InitTerm(0);
+#ifdef UTMPOK
+ RemoveLoginSlot();
+#endif
+ }
+ else
+ MakeTermcap(1);
+
+#ifdef LOADAV
+ InitLoadav();
+#endif /* LOADAV */
+
+ MakeNewEnv();
+ signal(SIGHUP, SigHup);
+ signal(SIGINT, FinitHandler);
+ signal(SIGQUIT, FinitHandler);
+ signal(SIGTERM, FinitHandler);
+#ifdef BSDJOBS
+ signal(SIGTTIN, SIG_IGN);
+ signal(SIGTTOU, SIG_IGN);
+#endif
+
+ if (display) {
+ brktty(D_userfd);
+ SetMode(&D_OldMode, &D_NewMode, D_flow, iflag);
+ /* Note: SetMode must be called _before_ FinishRc. */
+ SetTTY(D_userfd, &D_NewMode);
+ if (fcntl(D_userfd, F_SETFL, FNBLOCK))
+ Msg(errno, "Warning: NBLOCK fcntl failed");
+ }
+ else
+ brktty(-1); /* just try */
+ signal(SIGCHLD, SigChld);
+#ifdef ETCSCREENRC
+# ifdef ALLOW_SYSSCREENRC
+ if ((ap = getenv("SYSSCREENRC")))
+ FinishRc(ap);
+ else
+# endif
+ FinishRc(ETCSCREENRC);
+#endif
+ FinishRc(RcFileName);
+
+ debug2("UID %d EUID %d\n", (int)getuid(), (int)geteuid());
+ if (windows == NULL) {
+ debug("We open one default window, as screenrc did not specify one.\n");
+ if (MakeWindow(&nwin) == -1) {
+ fd_set rfd;
+ struct timeval tv = { MsgWait/1000, 1000*(MsgWait%1000) };
+ FD_SET(0, &rfd);
+
+ Msg(0, "Sorry, could not find a PTY or TTY.");
+ // allow user to exit early by pressing any key.
+ select(1, &rfd, NULL, NULL, &tv);
+ Finit(0);
+ /* NOTREACHED */
+ }
+ }
+ else if (ac) /* Screen was invoked with a command */
+ MakeWindow(&nwin);
+
+#ifdef HAVE_BRAILLE
+ StartBraille();
+#endif
+
+ if (display && default_startup)
+ display_copyright();
+ signal(SIGINT, SigInt);
+ if (rflag && (rflag & 1) == 0 && !quietflag) {
+ Msg(0, "New screen...");
+ rflag = 0;
+ }
+
+ serv_read.type = EV_READ;
+ serv_read.fd = ServerSocket;
+ serv_read.handler = serv_read_fn;
+ evenq(&serv_read);
+
+ serv_select.pri = -10;
+ serv_select.type = EV_ALWAYS;
+ serv_select.handler = serv_select_fn;
+ evenq(&serv_select);
+
+ logflushev.type = EV_TIMEOUT;
+ logflushev.handler = logflush_fn;
+
+ sched();
+ /* NOTREACHED */
+ return 0;
+}
+
+void
+WindowDied(p, wstat, wstat_valid)
+struct win *p;
+#ifdef BSDWAIT
+ union wait wstat;
+#else
+ int wstat;
+#endif
+
+
+int wstat_valid;
+{
+ int killit = 0;
+ if (p->w_destroyev.data == (char *)p) {
+ wstat = p->w_exitstatus;
+ wstat_valid = 1;
+ evdeq(&p->w_destroyev);
+ p->w_destroyev.data = 0;
+ }
+
+#if defined(BSDJOBS) && !defined(BSDWAIT)
+ if (!wstat_valid && p->w_pid > 0) {
+ /* EOF on file descriptor. The process is probably also dead.
+ * try a waitpid */
+ if (waitpid(p->w_pid, &wstat, WNOHANG | WUNTRACED) == p->w_pid) {
+ p->w_pid = 0;
+ wstat_valid = 1;
+ }
+ }
+#endif
+
+ if (ZombieKey_destroy && ZombieKey_onerror && wstat_valid &&
+ WIFEXITED(wstat) && WEXITSTATUS(wstat) == 0)
+ killit = 1;
+
+ if (ZombieKey_destroy && !killit) {
+ char buf[100], *s, reason[100];
+ time_t now;
+
+ if (wstat_valid) {
+ if (WIFEXITED(wstat))
+ if (WEXITSTATUS(wstat))
+ sprintf(reason, "terminated with exit status %d", WEXITSTATUS(wstat));
+ else
+ sprintf(reason, "terminated normally");
+ else if (WIFSIGNALED(wstat))
+ sprintf(reason, "terminated with signal %d%s", WTERMSIG(wstat),
+
+#ifdef WCOREDUMP
+ WCOREDUMP(wstat) ? " (core file generated)" : "");
+#else
+ "");
+#endif
+ } else
+ sprintf(reason, "detached from window");
+
+ (void) time(&now);
+ s = ctime(&now);
+ if (s && *s)
+ s[strlen(s) - 1] = '\0';
+ debug3("window %d (%s) going into zombie state fd %d", p->w_number, p->w_title, p->w_ptyfd);
+
+#ifdef UTMPOK
+ if (p->w_slot != (slot_t)0 && p->w_slot != (slot_t)-1) {
+ RemoveUtmp(p);
+ p->w_slot = 0; /* "detached" */
+ }
+#endif
+
+ CloseDevice(p);
+ p->w_deadpid = p->w_pid;
+ p->w_pid = 0;
+ ResetWindow(p);
+ /* p->w_y = p->w_bot; */
+ p->w_y = MFindUsedLine(p, p->w_bot, 1);
+ sprintf(buf, "\n\r=== Command %s (%s) ===", reason, s ? s : "?");
+ WriteString(p, buf, strlen(buf));
+ if (p->w_poll_zombie_timeout) {
+ debug2("Set zombie poll timeout for window %s to %d\n", p->w_title,
+ p->w_poll_zombie_timeout);
+ SetTimeout(&p->w_zombieev, p->w_poll_zombie_timeout * 1000);
+ evenq(&p->w_zombieev);
+ }
+ WindowChanged(p, 'f');
+ }
+ else
+ KillWindow(p);
+
+#ifdef UTMPOK
+ CarefulUtmp();
+#endif
+}
+
+static void SigChldHandler()
+{
+ struct stat st;
+#ifdef DEBUG
+ fds();
+#endif
+ while (GotSigChld) {
+ GotSigChld = 0;
+ DoWait();
+#ifdef SYSVSIGS
+ signal(SIGCHLD, SigChld);
+#endif
+ }
+ if (stat(SockPath, &st) == -1) {
+ debug1("SigChldHandler: Yuck! cannot stat '%s'\n", SockPath);
+ if (!RecoverSocket()) {
+ debug("SCREEN cannot recover from corrupt Socket, bye\n");
+ Finit(1);
+ }
+ else
+ debug1("'%s' reconstructed\n", SockPath);
+ }
+ else
+ debug2("SigChldHandler: stat '%s' o.k. (%03o)\n", SockPath, (int)st.st_mode);
+}
+
+static sigret_t SigChld SIGDEFARG
+{
+ debug("SigChld()\n");
+ GotSigChld = 1;
+ SIGRETURN;
+}
+
+sigret_t SigHup SIGDEFARG
+{
+ /* Hangup all displays */
+ while ((display = displays) != 0)
+ Hangup();
+ SIGRETURN;
+}
+
+/*
+ * the backend's Interrupt handler
+ * we cannot insert the intrc directly, as we never know
+ * if fore is valid.
+ */
+static sigret_t SigInt SIGDEFARG
+{
+#if HAZARDOUS
+ char ibuf;
+ debug("SigInt()\n");
+ if (fore && displays) {
+# if defined(TERMIO) || defined(POSIX)
+ ibuf = displays->d_OldMode.tio.c_cc[VINTR];
+# else
+ ibuf = displays->d_OldMode.m_tchars.t_intrc;
+# endif
+ fore->w_inlen = 0;
+ write(fore->w_ptyfd, &ibuf, 1);
+ }
+#else
+ signal(SIGINT, SigInt);
+ debug("SigInt() careful\n");
+ InterruptPlease = 1;
+#endif
+ SIGRETURN;
+}
+
+static sigret_t CoreDump SIGDEFARG
+{
+ /* if running with s-bit, we must reset the s-bit, so that we get a
+ * core file anyway.
+ */
+ struct display *disp;
+ char buf[80];
+ char *dump_msg = " (core dumped)";
+ int running_w_s_bit = getuid() != geteuid();
+
+#if defined(SHADOWPW) && !defined(DEBUG) && !defined(DUMPSHADOW)
+ if (running_w_s_bit)
+ dump_msg = "";
+#endif
+
+#if defined(SYSVSIGS) && defined(SIGHASARG)
+ signal(sigsig, SIG_IGN);
+#endif
+ setgid(getgid());
+ setuid(getuid());
+ unlink("core");
+
+#ifdef SIGHASARG
+ sprintf(buf, "\r\n[screen caught signal %d.%s]\r\n", sigsig, dump_msg);
+#else
+ sprintf(buf, "\r\n[screen caught a fatal signal.%s]\r\n", dump_msg);
+#endif
+
+ for (disp = displays; disp; disp = disp->d_next) {
+ if (disp->d_nonblock < -1 || disp->d_nonblock > 1000000)
+ continue;
+ fcntl(disp->d_userfd, F_SETFL, 0);
+ SetTTY(disp->d_userfd, &D_OldMode);
+ write(disp->d_userfd, buf, strlen(buf));
+ Kill(disp->d_userpid, SIG_BYE);
+ }
+
+ if (running_w_s_bit) {
+#if defined(SHADOWPW) && !defined(DEBUG) && !defined(DUMPSHADOW)
+ Kill(getpid(), SIGKILL);
+ eexit(11);
+#else /* SHADOWPW && !DEBUG */
+ abort();
+#endif /* SHADOWPW && !DEBUG */
+ }
+ else
+ abort();
+
+ SIGRETURN;
+}
+
+static void DoWait()
+{
+ register int pid;
+ struct win *p, *next;
+#ifdef BSDWAIT
+ union wait wstat;
+#else
+ int wstat;
+#endif
+
+#ifdef BSDJOBS
+
+# ifndef BSDWAIT
+ while ((pid = waitpid(-1, &wstat, WNOHANG | WUNTRACED)) > 0)
+# else
+
+# ifdef USE_WAIT2
+ /*
+ * From: rouilj@sni-usa.com (John Rouillard)
+ * note that WUNTRACED is not documented to work, but it is defined in
+ * /usr/include/sys/wait.h, so it may work
+ */
+ while ((pid = wait2(&wstat, WNOHANG | WUNTRACED )) > 0)
+# else /* USE_WAIT2 */
+ while ((pid = wait3(&wstat, WNOHANG | WUNTRACED, (struct rusage *) 0)) > 0)
+# endif /* USE_WAIT2 */
+# endif
+
+#else /* BSDJOBS */
+ while ((pid = wait(&wstat)) < 0)
+ if (errno != EINTR)
+ break;
+ if (pid > 0)
+
+#endif /* BSDJOBS */
+ {
+ for (p = windows; p; p = next) {
+ next = p->w_next;
+ if ((p->w_pid && pid == p->w_pid) || (p->w_deadpid && pid == p->w_deadpid)) {
+ /* child has ceased to exist */
+ p->w_pid = 0;
+
+#ifdef BSDJOBS
+ if (WIFSTOPPED(wstat)) {
+ debug3("Window %d pid %d: WIFSTOPPED (sig %d)\n", p->w_number, pid, WSTOPSIG(wstat));
+
+#ifdef SIGTTIN
+ if (WSTOPSIG(wstat) == SIGTTIN) {
+ Msg(0, "Suspended (tty input)");
+ continue;
+ }
+#endif
+
+
+#ifdef SIGTTOU
+ if (WSTOPSIG(wstat) == SIGTTOU) {
+ Msg(0, "Suspended (tty output)");
+ continue;
+ }
+#endif
+
+ /* Try to restart process */
+ Msg(0, "Child has been stopped, restarting.");
+ if (killpg(pid, SIGCONT))
+ kill(pid, SIGCONT);
+ }
+ else
+#endif
+ {
+ /* Screen will detect the window has died when the window's
+ * file descriptor signals EOF (which it will do when the process in
+ * the window terminates). So do this in a timeout of 10 seconds.
+ * (not doing this at all might also work)
+ * See #27061 for more details.
+ */
+ p->w_destroyev.data = (char *)p;
+ p->w_exitstatus = wstat;
+ SetTimeout(&p->w_destroyev, 10 * 1000);
+ evenq(&p->w_destroyev);
+ }
+ break;
+ }
+
+#ifdef PSEUDOS
+ if (p->w_pwin && pid == p->w_pwin->p_pid) {
+ debug2("pseudo of win Nr %d died. pid == %d\n", p->w_number, p->w_pwin->p_pid);
+ FreePseudowin(p);
+ break;
+ }
+
+#endif
+ }
+
+ if (p == 0) {
+ debug1("pid %d not found - hope that's ok\n", pid);
+ }
+ }
+}
+
+static sigret_t FinitHandler SIGDEFARG
+{
+#ifdef SIGHASARG
+ debug1("FinitHandler called, sig %d.\n", sigsig);
+#else
+ debug("FinitHandler called.\n");
+#endif
+ Finit(1);
+ SIGRETURN;
+}
+
+void Finit(int i)
+{
+ signal(SIGCHLD, SIG_DFL);
+ signal(SIGHUP, SIG_IGN);
+ debug1("Finit(%d);\n", i);
+ while (windows) {
+ struct win *p = windows;
+ windows = windows->w_next;
+ FreeWindow(p);
+ }
+
+ if (ServerSocket != -1) {
+ debug1("we unlink(%s)\n", SockPath);
+#ifdef USE_SETEUID
+ xseteuid(real_uid);
+ xsetegid(real_gid);
+#endif
+ (void) unlink(SockPath);
+#ifdef USE_SETEUID
+ xseteuid(eff_uid);
+ xsetegid(eff_gid);
+#endif
+ }
+
+ for (display = displays; display; display = display->d_next) {
+ if (D_status)
+ RemoveStatus();
+ FinitTerm();
+#ifdef UTMPOK
+ RestoreLoginSlot();
+#endif
+ AddStr("[screen is terminating]\r\n");
+ Flush(3);
+ SetTTY(D_userfd, &D_OldMode);
+ fcntl(D_userfd, F_SETFL, 0);
+ freetty();
+ Kill(D_userpid, SIG_BYE);
+ }
+ /*
+ * we _cannot_ call eexit(i) here,
+ * instead of playing with the Socket above. Sigh.
+ */
+ exit(i);
+}
+
+void eexit(int e)
+{
+ debug("eexit\n");
+ if (ServerSocket != -1) {
+ debug1("we unlink(%s)\n", SockPath);
+ setgid(real_gid);
+ setuid(real_uid);
+ (void) unlink(SockPath);
+ }
+ exit(e);
+}
+
+void Hangup()
+{
+ if (display == 0)
+ return;
+ debug1("Hangup %x\n", display);
+ if (D_userfd >= 0) {
+ close(D_userfd);
+ D_userfd = -1;
+ }
+ if (auto_detach || displays->d_next)
+ Detach(D_HANGUP);
+ else
+ Finit(0);
+}
+
+/*
+ * Detach now has the following modes:
+ *D_DETACH SIG_BYE detach backend and exit attacher
+ *D_HANGUP SIG_BYE detach backend and exit attacher
+ *D_STOP SIG_STOP stop attacher (and detach backend)
+ *D_REMOTE SIG_BYE remote detach -- reattach to new attacher
+ *D_POWER SIG_POWER_BYE power detach -- attacher kills his parent
+ *D_REMOTE_POWER SIG_POWER_BYE remote power detach -- both
+ *D_LOCK SIG_LOCK lock the attacher
+ * (jw)
+ * we always remove our utmp slots. (even when "lock" or "stop")
+ * Note: Take extra care here, we may be called by interrupt!
+ */
+void Detach(int mode)
+{
+ int sign = 0, pid;
+ struct canvas *cv;
+ struct win *p;
+
+ if (display == 0)
+ return;
+
+#define AddStrSock(msg) do { \
+ if (SockName) \
+ { \
+ AddStr("[" msg " from "); \
+ AddStr(SockName); \
+ AddStr("]\r\n"); \
+ } \
+ else \
+ AddStr("[" msg "]\r\n"); \
+ } while (0)
+
+ signal(SIGHUP, SIG_IGN);
+ debug1("Detach(%d)\n", mode);
+ if (D_status)
+ RemoveStatus();
+ FinitTerm();
+ if (!display)
+ return;
+ switch (mode) {
+
+ case D_HANGUP:
+ sign = SIG_BYE;
+ break;
+
+ case D_DETACH:
+ AddStrSock("detached");
+ sign = SIG_BYE;
+ break;
+
+#ifdef BSDJOBS
+ case D_STOP:
+ sign = SIG_STOP;
+ break;
+#endif
+
+#ifdef REMOTE_DETACH
+ case D_REMOTE:
+ AddStrSock("remote detached");
+ sign = SIG_BYE;
+ break;
+#endif
+
+#ifdef POW_DETACH
+ case D_POWER:
+ AddStrSock("power detached");
+ if (PowDetachString) {
+ AddStr(PowDetachString);
+ AddStr("\r\n");
+ }
+ sign = SIG_POWER_BYE;
+ break;
+
+#ifdef REMOTE_DETACH
+ case D_REMOTE_POWER:
+ AddStrSock("remote power detached");
+ if (PowDetachString) {
+ AddStr(PowDetachString);
+ AddStr("\r\n");
+ }
+ sign = SIG_POWER_BYE;
+ break;
+#endif
+#endif
+
+ case D_LOCK:
+ ClearAll();
+ sign = SIG_LOCK;
+ /* tell attacher to lock terminal with a lockprg. */
+ break;
+ }
+
+#ifdef UTMPOK
+ if (displays->d_next == 0) {
+ for (p = windows; p; p = p->w_next) {
+ if (p->w_slot != (slot_t) -1 && !(p->w_lflag & 2)) {
+ RemoveUtmp(p);
+
+ /* Set the slot to 0 to get the window logged in again. */
+ p->w_slot = (slot_t) 0;
+ }
+ }
+ }
+ if (mode != D_HANGUP)
+ RestoreLoginSlot();
+#endif
+
+ if (displays->d_next == 0 && console_window) {
+ if (TtyGrabConsole(console_window->w_ptyfd, 0, "detach")) {
+ debug("could not release console - killing window\n");
+ KillWindow(console_window);
+ display = displays; /* restore display */
+ }
+ }
+ if (D_fore) {
+#ifdef MULTIUSER
+ ReleaseAutoWritelock(display, D_fore);
+#endif
+ D_user->u_detachwin = D_fore->w_number;
+ D_user->u_detachotherwin = D_other ? D_other->w_number : -1;
+ }
+
+ AutosaveLayout(D_layout);
+ layout_last = D_layout;
+ for (cv = D_cvlist; cv; cv = cv->c_next) {
+ p = Layer2Window(cv->c_layer);
+ SetCanvasWindow(cv, 0);
+ if (p)
+ WindowChanged(p, 'u');
+ }
+
+ pid = D_userpid;
+ debug2("display: %#x displays: %#x\n", (unsigned int)display, (unsigned int)displays);
+ FreeDisplay();
+
+ if (displays == 0) /* Flag detached-ness */
+ (void) chsock();
+
+ /*
+ * tell father what to do. We do that after we
+ * freed the tty, thus getty feels more comfortable on hpux
+ * if it was a power detach.
+ */
+ Kill(pid, sign);
+ debug2("Detach: Signal %d to Attacher(%d)!\n", sign, pid);
+ debug("Detach returns, we are successfully detached.\n");
+ signal(SIGHUP, SigHup);
+#undef AddStrSock
+}
+
+static int IsSymbol(char *e, char *s)
+{
+ register int l;
+
+ l = strlen(s);
+ return strncmp(e, s, l) == 0 && e[l] == '=';
+}
+
+void MakeNewEnv()
+{
+ register char **op, **np;
+ static char stybuf[MAXSTR];
+
+ for (op = environ; *op; ++op)
+ ;
+ if (NewEnv)
+ free((char *)NewEnv);
+ NewEnv = np = (char **) malloc((unsigned) (op - environ + 7 + 1) * sizeof(char **));
+ if (!NewEnv)
+ Panic(0, "%s", strnomem);
+ sprintf(stybuf, "STY=%s", strlen(SockName) <= MAXSTR - 5 ? SockName : "?");
+ *np++ = stybuf; /* NewEnv[0] */
+ *np++ = Term; /* NewEnv[1] */
+ np++; /* room for SHELL */
+#ifdef TIOCSWINSZ
+ np += 2; /* room for TERMCAP and WINDOW */
+#else
+ np += 4; /* room for TERMCAP WINDOW LINES COLUMNS */
+#endif
+
+ for (op = environ; *op; ++op) {
+ if (!IsSymbol(*op, "TERM") && !IsSymbol(*op, "TERMCAP")
+ && !IsSymbol(*op, "STY") && !IsSymbol(*op, "WINDOW")
+ && !IsSymbol(*op, "SCREENCAP") && !IsSymbol(*op, "SHELL")
+ && !IsSymbol(*op, "LINES") && !IsSymbol(*op, "COLUMNS"))
+ *np++ = *op;
+ }
+ *np = 0;
+}
+
+#if defined(USEVARARGS) && defined(__STDC__)
+ #define DEFINE_VARARGS_FN(fnname) void fnname (int err, const char *fmt, VA_DOTS)
+#else
+ #define DEFINE_VARARGS_FN(fnname) void fnname(err, fmt, VA_DOTS) \
+ int err; \
+ const char *fmt; \
+ VA_DECL
+#endif
+
+#define PROCESS_MESSAGE(B) do { \
+ char *p = B; \
+ VA_LIST(ap) \
+ VA_START(ap, fmt); \
+ fmt = DoNLS(fmt); \
+ (void)vsnprintf(p, sizeof(B) - 100, fmt, VA_ARGS(ap)); \
+ VA_END(ap); \
+ if (err) \
+ { \
+ p += strlen(p); \
+ *p++ = ':'; \
+ *p++ = ' '; \
+ strncpy(p, strerror(err), B + sizeof(B) - p - 1); \
+ B[sizeof(B) - 1] = 0; \
+ } \
+ } while (0)
+
+DEFINE_VARARGS_FN(Msg)
+{
+ char buf[MAXPATHLEN*2];
+ PROCESS_MESSAGE(buf);
+
+ debug2("Msg('%s') (%#x);\n", buf, (unsigned int)display);
+
+ if (display && displays)
+ MakeStatus(buf);
+ else if (displays) {
+ for (display = displays; display; display = display->d_next)
+ MakeStatus(buf);
+ }
+ else if (display) {
+ /* no displays but a display - must have forked.
+ * send message to backend!
+ */
+ char *tty = D_usertty;
+ struct display *olddisplay = display;
+ display = 0; /* only send once */
+ SendErrorMsg(tty, buf);
+ display = olddisplay;
+ }
+ else
+ printf("%s\r\n", buf);
+
+ if (queryflag >= 0)
+ write(queryflag, buf, strlen(buf));
+}
+
+/*
+ * Call FinitTerm for all displays, write a message to each and call eexit();
+ */
+DEFINE_VARARGS_FN(Panic)
+{
+ char buf[MAXPATHLEN*2];
+ PROCESS_MESSAGE(buf);
+
+ debug3("Panic('%s'); display=%x displays=%x\n", buf, display, displays);
+ if (displays == 0 && display == 0) {
+ printf("%s\r\n", buf);
+ if (PanicPid)
+ Kill(PanicPid, SIG_BYE);
+ }
+ else if (displays == 0) {
+ /* no displays but a display - must have forked.
+ * send message to backend!
+ */
+ char *tty = D_usertty;
+ display = 0;
+ SendErrorMsg(tty, buf);
+ sleep(2);
+ _exit(1);
+ }
+ else
+ for (display = displays; display; display = display->d_next) {
+ if (D_status)
+ RemoveStatus();
+ FinitTerm();
+ Flush(3);
+#ifdef UTMPOK
+ RestoreLoginSlot();
+#endif
+ SetTTY(D_userfd, &D_OldMode);
+ fcntl(D_userfd, F_SETFL, 0);
+ write(D_userfd, buf, strlen(buf));
+ write(D_userfd, "\n", 1);
+ freetty();
+ if (D_userpid)
+ Kill(D_userpid, SIG_BYE);
+ }
+#ifdef MULTIUSER
+ if (tty_oldmode >= 0) {
+
+# ifdef USE_SETEUID
+ if (setuid(own_uid))
+ xseteuid(own_uid); /* may be a loop. sigh. */
+# else
+ setuid(own_uid);
+# endif
+
+ debug1("Panic: changing back modes from %s\n", attach_tty);
+ chmod(attach_tty, tty_oldmode);
+ }
+#endif
+ eexit(1);
+}
+
+DEFINE_VARARGS_FN(QueryMsg)
+{
+ char buf[MAXPATHLEN*2];
+
+ if (queryflag < 0)
+ return;
+
+ PROCESS_MESSAGE(buf);
+ write(queryflag, buf, strlen(buf));
+}
+
+DEFINE_VARARGS_FN(Dummy)
+{}
+
+#undef PROCESS_MESSAGE
+#undef DEFINE_VARARGS_FN
+
+/*
+ * '^' is allowed as an escape mechanism for control characters. jw.
+ *
+ * Added time insertion using ideas/code from /\ndy Jones
+ * (andy@lingua.cltr.uq.OZ.AU) - thanks a lot!
+ *
+ */
+
+#ifndef USE_LOCALE
+static const char days[] = "SunMonTueWedThuFriSat";
+static const char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
+#endif
+
+static char winmsg_buf[MAXSTR];
+#define MAX_WINMSG_REND 256 /* rendition changes */
+static int winmsg_rend[MAX_WINMSG_REND];
+static int winmsg_rendpos[MAX_WINMSG_REND];
+static int winmsg_numrend;
+
+static char *pad_expand(char *buf, char *p, int numpad, int padlen)
+{
+ char *pn, *pn2;
+ int i, r;
+
+ padlen = padlen - (p - buf); /* space for rent */
+ if (padlen < 0)
+ padlen = 0;
+ pn2 = pn = p + padlen;
+ r = winmsg_numrend;
+ while (p >= buf) {
+ if (r && *p != 127 && p - buf == winmsg_rendpos[r - 1]) {
+ winmsg_rendpos[--r] = pn - buf;
+ continue;
+ }
+ *pn-- = *p;
+ if (*p-- == 127) {
+ pn[1] = ' ';
+ i = numpad > 0 ? (padlen + numpad - 1) / numpad : 0;
+ padlen -= i;
+
+ while (i-- > 0)
+ *pn-- = ' ';
+
+ numpad--;
+ if (r && p - buf + 1== winmsg_rendpos[r - 1])
+ winmsg_rendpos[--r] = pn - buf + 1;
+ }
+ }
+ return pn2;
+}
+
+struct backtick {
+ struct backtick *next;
+ int num;
+ int tick;
+ int lifespan;
+ time_t bestbefore;
+ char result[MAXSTR];
+ char **cmdv;
+ struct event ev;
+ char *buf;
+ int bufi;
+};
+
+struct backtick *backticks;
+
+static void backtick_filter(struct backtick *bt)
+{
+ char *p, *q;
+ int c;
+
+ for (p = q = bt->result; (c = (unsigned char)*p++) != 0;) {
+ if (c == '\t')
+ c = ' ';
+ if (c >= ' ' || c == '\005')
+ *q++ = c;
+ }
+ *q = 0;
+}
+
+static void backtick_fn(struct event *ev, char *data)
+{
+ struct backtick *bt;
+ int i, j, k, l;
+
+ bt = (struct backtick *)data;
+ debug1("backtick_fn for #%d\n", bt->num);
+ i = bt->bufi;
+ l = read(ev->fd, bt->buf + i, MAXSTR - i);
+
+ if (l <= 0) {
+ debug1("EOF on backtick #%d\n", bt->num);
+ evdeq(ev);
+ close(ev->fd);
+ ev->fd = -1;
+ return;
+ }
+
+ debug1("read %d bytes\n", l);
+ i += l;
+ for (j = 0; j < l; j++)
+ if (bt->buf[i - j - 1] == '\n')
+ break;
+
+ if (j < l) {
+ for (k = i - j - 2; k >= 0; k--)
+ if (bt->buf[k] == '\n')
+ break;
+ k++;
+ bcopy(bt->buf + k, bt->result, i - j - k);
+ bt->result[i - j - k - 1] = 0;
+ backtick_filter(bt);
+ WindowChanged(0, '`');
+ }
+
+ if (j == l && i == MAXSTR) {
+ j = MAXSTR/2;
+ l = j + 1;
+ }
+
+ if (j < l){
+ if (j)
+ bcopy(bt->buf + i - j, bt->buf, j);
+ i = j;
+ }
+ bt->bufi = i;
+}
+
+void setbacktick(int num, int lifespan, int tick, char **cmdv)
+{
+ struct backtick **btp, *bt;
+ char **v;
+
+ debug1("setbacktick called for backtick #%d\n", num);
+ for (btp = &backticks; (bt = *btp) != 0; btp = &bt->next)
+ if (bt->num == num)
+ break;
+
+ if (!bt && !cmdv)
+ return;
+
+ if (bt) {
+ for (v = bt->cmdv; *v; v++)
+ free(*v);
+ free(bt->cmdv);
+ if (bt->buf)
+ free(bt->buf);
+ if (bt->ev.fd >= 0)
+ close(bt->ev.fd);
+ evdeq(&bt->ev);
+ }
+
+ if (bt && !cmdv) {
+ *btp = bt->next;
+ free(bt);
+ return;
+ }
+
+ if (!bt){
+ bt = (struct backtick *)malloc(sizeof *bt);
+ if (!bt){
+ Msg(0, "%s", strnomem);
+ return;
+ }
+ bzero(bt, sizeof(*bt));
+ bt->next = 0;
+ *btp = bt;
+ }
+
+ bt->num = num;
+ bt->tick = tick;
+ bt->lifespan = lifespan;
+ bt->bestbefore = 0;
+ bt->result[0] = 0;
+ bt->buf = 0;
+ bt->bufi = 0;
+ bt->cmdv = cmdv;
+ bt->ev.fd = -1;
+
+ if (bt->tick == 0 && bt->lifespan == 0) {
+ debug("setbacktick: continuous mode\n");
+ bt->buf = (char *)malloc(MAXSTR);
+ if (bt->buf == 0) {
+ Msg(0, "%s", strnomem);
+ setbacktick(num, 0, 0, (char **)0);
+ return;
+ }
+
+ bt->ev.type = EV_READ;
+ bt->ev.fd = readpipe(bt->cmdv);
+ bt->ev.handler = backtick_fn;
+ bt->ev.data = (char *)bt;
+ if (bt->ev.fd >= 0)
+ evenq(&bt->ev);
+ }
+}
+
+static char * runbacktick(struct backtick *bt, int *tickp, time_t now)
+{
+ int f, i, l, j;
+ time_t now2;
+
+ debug1("runbacktick called for backtick #%d\n", bt->num);
+ if (bt->tick && (!*tickp || bt->tick < *tickp))
+ *tickp = bt->tick;
+ if ((bt->lifespan == 0 && bt->tick == 0) || now < bt->bestbefore) {
+ debug1("returning old result (%d)\n", bt->lifespan);
+ return bt->result;
+ }
+
+ f = readpipe(bt->cmdv);
+ if (f == -1)
+ return bt->result;
+ i = 0;
+ while ((l = read(f, bt->result + i, sizeof(bt->result) - i)) > 0) {
+ debug1("runbacktick: read %d bytes\n", l);
+ i += l;
+ for (j = 1; j < l; j++)
+ if (bt->result[i - j - 1] == '\n')
+ break;
+
+ if (j == l && i == sizeof(bt->result)) {
+ j = sizeof(bt->result) / 2;
+ l = j + 1;
+ }
+
+ if (j < l) {
+ bcopy(bt->result + i - j, bt->result, j);
+ i = j;
+ }
+ }
+
+ close(f);
+ bt->result[sizeof(bt->result) - 1] = '\n';
+ if (i && bt->result[i - 1] == '\n')
+ i--;
+ debug1("runbacktick: finished, %d bytes\n", i);
+ bt->result[i] = 0;
+ backtick_filter(bt);
+ (void)time(&now2);
+ bt->bestbefore = now2 + bt->lifespan;
+ return bt->result;
+}
+
+int AddWinMsgRend(const char *str, int r)
+{
+ if (winmsg_numrend >= MAX_WINMSG_REND || str < winmsg_buf || str >= winmsg_buf + MAXSTR)
+ return -1;
+
+ winmsg_rend[winmsg_numrend] = r;
+ winmsg_rendpos[winmsg_numrend] = str - winmsg_buf;
+ winmsg_numrend++;
+ return 0;
+}
+
+char *MakeWinMsgEv(char *str, struct win *win, int esc, int padlen, struct event *ev, int rec)
+{
+ static int tick;
+ char *s = str;
+ register char *p = winmsg_buf;
+ register int ctrl;
+ struct timeval now;
+ struct tm *tm;
+ int l, i, r;
+ int num;
+ int zeroflg;
+ int longflg;
+ int minusflg;
+ int plusflg;
+ int qmflag = 0, omflag = 0, qmnumrend = 0;
+ char *qmpos = 0;
+ int numpad = 0;
+ int lastpad = 0;
+ int truncpos = -1;
+ int truncper = 0;
+ int trunclong = 0;
+ struct backtick *bt = NULL;
+
+ if (winmsg_numrend >= 0)
+ winmsg_numrend = 0;
+ else
+ winmsg_numrend = -winmsg_numrend;
+
+ tick = 0;
+ tm = 0;
+ ctrl = 0;
+ gettimeofday(&now, NULL);
+ for (; *s && (l = winmsg_buf + MAXSTR - 1 - p) > 0; s++, p++) {
+ *p = *s;
+ if (ctrl) {
+ ctrl = 0;
+ if (*s != '^' && *s >= 64)
+ *p &= 0x1f;
+ continue;
+ }
+
+ if (*s != esc) {
+ if (esc == '%') {
+ switch (*s) {
+#if 0
+ case '~':
+ *p = BELL;
+ break;
+#endif
+ case '^':
+ ctrl = 1;
+ *p-- = '^';
+ break;
+
+ default:
+ break;
+ }
+ }
+ continue;
+ }
+
+ if (*++s == esc) /* double escape ? */
+ continue;
+
+ if ((plusflg = *s == '+') != 0)
+ s++;
+
+ if ((minusflg = *s == '-') != 0)
+ s++;
+
+ if ((zeroflg = *s == '0') != 0)
+ s++;
+
+ num = 0;
+ while(*s >= '0' && *s <= '9')
+ num = num * 10 + (*s++ - '0');
+
+ if ((longflg = *s == 'L') != 0)
+ s++;
+
+ switch (*s) {
+ case '?':
+ p--;
+ if (qmpos) {
+ if ((!qmflag && !omflag) || omflag == 1){
+ p = qmpos;
+ if (qmnumrend < winmsg_numrend)
+ winmsg_numrend = qmnumrend;
+ }
+ qmpos = 0;
+ break;
+ }
+ qmpos = p;
+ qmnumrend = winmsg_numrend;
+ qmflag = omflag = 0;
+ break;
+
+ case ':':
+ p--;
+ if (!qmpos)
+ break;
+ if (qmflag && omflag != 1) {
+ omflag = 1;
+ qmpos = p;
+ qmnumrend = winmsg_numrend;
+ }
+ else {
+ p = qmpos;
+ if (qmnumrend < winmsg_numrend)
+ winmsg_numrend = qmnumrend;
+ omflag = -1;
+ }
+ break;
+
+ case 'd': case 'D': case 'm': case 'M': case 'y': case 'Y':
+ case 'a': case 'A': case 's': case 'c': case 'C':
+
+ if (l < 4)
+ break;
+ if (tm == 0) {
+ time_t nowsec = now.tv_sec;
+ tm = localtime(&nowsec);
+ }
+
+ qmflag = 1;
+ if (!tick || tick > 3600)
+ tick = 3600;
+
+ switch (*s) {
+ case 'd':
+ sprintf(p, "%02d", tm->tm_mday % 100);
+ break;
+
+ case 'D':
+#ifdef USE_LOCALE
+ strftime(p, l, (longflg ? "%A" : "%a"), tm);
+#else
+ sprintf(p, "%3.3s", days + 3 * tm->tm_wday);
+#endif
+ break;
+
+ case 'm':
+ sprintf(p, "%02d", tm->tm_mon + 1);
+ break;
+
+ case 'M':
+#ifdef USE_LOCALE
+ strftime(p, l, (longflg ? "%B" : "%b"), tm);
+#else
+ sprintf(p, "%3.3s", months + 3 * tm->tm_mon);
+#endif
+ break;
+
+ case 'y':
+ sprintf(p, "%02d", tm->tm_year % 100);
+ break;
+
+ case 'Y':
+ sprintf(p, "%04d", tm->tm_year + 1900);
+ break;
+
+ case 'a':
+ sprintf(p, tm->tm_hour >= 12 ? "pm" : "am");
+ break;
+
+ case 'A':
+ sprintf(p, tm->tm_hour >= 12 ? "PM" : "AM");
+ break;
+
+ case 's':
+ sprintf(p, "%02d", tm->tm_sec);
+ tick = 1;
+ break;
+
+ case 'c':
+ sprintf(p, zeroflg ? "%02d:%02d" : "%2d:%02d", tm->tm_hour, tm->tm_min);
+ if (!tick || tick > 60)
+ tick = 60;
+ break;
+
+ case 'C':
+ sprintf(p, zeroflg ? "%02d:%02d" : "%2d:%02d", (tm->tm_hour + 11) % 12 + 1, tm->tm_min);
+ if (!tick || tick > 60)
+ tick = 60;
+ break;
+
+ default:
+ break;
+ }
+
+ p += strlen(p) - 1;
+ break;
+
+ case 'X': case 'x':
+ *p = 0;
+ for (i = 0; win && win->w_cmdargs[i]; i++) {
+ if (l < strlen(win->w_cmdargs[i]) + 1)
+ break;
+ sprintf(p, i ? " %s" : "%s", win->w_cmdargs[i]);
+ l -= strlen(p);
+ p += strlen(p);
+ if (i == 0 && *s == 'X')
+ break;
+ }
+ p--;
+ break;
+
+ case 'l':
+#ifdef LOADAV
+ *p = 0;
+ if (l > 20)
+ AddLoadav(p);
+ if (*p) {
+ qmflag = 1;
+ p += strlen(p) - 1;
+ }
+ else
+ *p = '?';
+
+ if (!tick || tick > 60)
+ tick = 60;
+#else
+ *p = '?';
+#endif
+ p += strlen(p) - 1;
+ break;
+
+ case '`':
+ case 'h':
+ if (rec >= 10 || (*s == 'h' && (win == 0 || win->w_hstatus == 0 || *win->w_hstatus == 0))) {
+ p--;
+ break;
+ }
+ if (*s == '`') {
+ for (bt = backticks; bt; bt = bt->next)
+ if (bt->num == num)
+ break;
+ if (bt == 0) {
+ p--;
+ break;
+ }
+ }
+ {
+ char savebuf[sizeof(winmsg_buf)];
+ int oldtick = tick;
+ int oldnumrend = winmsg_numrend;
+
+ *p = 0;
+ strcpy(savebuf, winmsg_buf);
+ winmsg_numrend = -winmsg_numrend;
+ MakeWinMsgEv(*s == 'h' ?
+ win->w_hstatus : runbacktick(bt, &oldtick, now.tv_sec), win, '\005', 0, (struct event *)0, rec + 1);
+ debug2("oldtick=%d tick=%d\n", oldtick, tick);
+ if (!tick || oldtick < tick)
+ tick = oldtick;
+ if ((int)strlen(winmsg_buf) < l)
+ strcat(savebuf, winmsg_buf);
+ strcpy(winmsg_buf, savebuf);
+ while (oldnumrend < winmsg_numrend)
+ winmsg_rendpos[oldnumrend++] += p - winmsg_buf;
+ if (*p)
+ qmflag = 1;
+ p += strlen(p) - 1;
+ }
+ break;
+
+ case 'w':
+ case 'W':
+ {
+ struct win *oldfore = 0;
+ char *ss;
+ if (display) {
+ oldfore = D_fore;
+ D_fore = win;
+ }
+ ss = AddWindows(p, l - 1, (*s == 'w' ? 0 : 1) |
+ (longflg ? 0 : 2) | (plusflg ? 4 : 0) |
+ (minusflg ? 8 : 0), win ? win->w_number : -1);
+ if (display)
+ D_fore = oldfore;
+ }
+ if (*p)
+ qmflag = 1;
+ p += strlen(p) - 1;
+ break;
+
+ case 'u':
+ *p = 0;
+ if (win)
+ AddOtherUsers(p, l - 1, win);
+ if (*p)
+ qmflag = 1;
+ p += strlen(p) - 1;
+ break;
+
+ case 'f':
+ *p = 0;
+ if (win)
+ AddWindowFlags(p, l - 1, win);
+ if (*p)
+ qmflag = 1;
+ p += strlen(p) - 1;
+ break;
+
+ case 't':
+ *p = 0;
+ if (win && (int)strlen(win->w_title) < l) {
+ strcpy(p, win->w_title);
+ if (*p)
+ qmflag = 1;
+ }
+ p += strlen(p) - 1;
+ break;
+
+ case '{':
+ {
+ char rbuf[128];
+ s++;
+
+ for (i = 0; i < 127; i++)
+ if (s[i] && s[i] != '}')
+ rbuf[i] = s[i];
+ else
+ break;
+
+ if (s[i] == '}' && winmsg_numrend < MAX_WINMSG_REND) {
+ r = -1;
+ rbuf[i] = 0;
+ debug1("MakeWinMsg attrcolor %s\n", rbuf);
+
+ if (i != 1 || rbuf[0] != '-')
+ r = ParseAttrColor(rbuf, (char *)0, 0);
+ if (r != -1 || (i == 1 && rbuf[0] == '-')) {
+ winmsg_rend[winmsg_numrend] = r;
+ winmsg_rendpos[winmsg_numrend] = p - winmsg_buf;
+ winmsg_numrend++;
+ }
+ }
+ s += i;
+ p--;
+ }
+ break;
+
+ case 'H':
+ *p = 0;
+ if ((int)strlen(HostName) < l) {
+ strcpy(p, HostName);
+ if (*p)
+ qmflag = 1;
+ }
+ p += strlen(p) - 1;
+ break;
+
+ case 'S':
+ {
+ char *session_name;
+ *p = 0;
+ session_name = strchr(SockName, '.') + 1;
+ if ((int)strlen(session_name) < l) {
+ strcpy(p, session_name);
+ if (*p)
+ qmflag = 1;
+ }
+ p += strlen(p) - 1;
+ }
+ break;
+
+ case 'p':
+ {
+ sprintf(p, "%d", (plusflg && display) ? D_userpid : getpid());
+ p += strlen(p) - 1;
+ }
+ break;
+
+ case 'F':
+ p--;
+ /* small hack */
+ if (display && ((ev && ev == &D_forecv->c_captev) || (!ev && win && win == D_fore)))
+ minusflg = !minusflg;
+ if (minusflg)
+ qmflag = 1;
+ break;
+
+ case 'P':
+ p--;
+#ifdef COPY_PASTE
+ if (display && ev && ev != &D_hstatusev) { /* Hack */
+ /* Is the layer in the current canvas in copy mode? */
+ struct canvas *cv = (struct canvas *)ev->data;
+ if (ev == &cv->c_captev && cv->c_layer->l_layfn == &MarkLf)
+ qmflag = 1;
+ }
+#endif
+ break;
+
+
+ case 'E':
+ p--;
+ if (display && D_ESCseen)
+ qmflag = 1;
+ break;
+
+ case '>':
+ truncpos = p - winmsg_buf;
+ truncper = num > 100 ? 100 : num;
+ trunclong = longflg;
+ p--;
+ break;
+
+ case '=':
+ case '<':
+ *p = ' ';
+ if (num || zeroflg || plusflg || longflg || (*s != '=')) {
+ /* expand all pads */
+ if (minusflg) {
+ num = (plusflg ? lastpad : padlen) - num;
+ if (!plusflg && padlen == 0)
+ num = p - winmsg_buf;
+ plusflg = 0;
+ }
+ else if (!zeroflg) {
+ if (*s != '=' && num == 0 && !plusflg)
+ num = 100;
+ if (num > 100)
+ num = 100;
+ if (padlen == 0)
+ num = p - winmsg_buf;
+ else
+ num = (padlen - (plusflg ? lastpad : 0)) * num / 100;
+ }
+
+ if (num < 0)
+ num = 0;
+
+ if (plusflg)
+ num += lastpad;
+
+ if (num > MAXSTR - 1)
+ num = MAXSTR - 1;
+
+ if (numpad)
+ p = pad_expand(winmsg_buf, p, numpad, num);
+
+ numpad = 0;
+ if (p - winmsg_buf > num && !longflg) {
+ int left, trunc;
+ if (truncpos == -1) {
+ truncpos = lastpad;
+ truncper = 0;
+ }
+
+ trunc = lastpad + truncper * (num - lastpad) / 100;
+ if (trunc > num)
+ trunc = num;
+ if (trunc < lastpad)
+ trunc = lastpad;
+ left = truncpos - trunc;
+ if (left > p - winmsg_buf - num)
+ left = p - winmsg_buf - num;
+ debug1("lastpad = %d, ", lastpad);
+ debug3("truncpos = %d, trunc = %d, left = %d\n", truncpos, trunc, left);
+
+ if (left > 0) {
+ if (left + lastpad > p - winmsg_buf)
+ left = p - winmsg_buf - lastpad;
+ if (p - winmsg_buf - lastpad - left > 0)
+ bcopy(winmsg_buf + lastpad + left, winmsg_buf + lastpad, p - winmsg_buf - lastpad - left);
+ p -= left;
+ r = winmsg_numrend;
+ while (r && winmsg_rendpos[r - 1] > lastpad) {
+ r--;
+ winmsg_rendpos[r] -= left;
+ if (winmsg_rendpos[r] < lastpad)
+ winmsg_rendpos[r] = lastpad;
+ }
+
+ if (trunclong) {
+ if (p - winmsg_buf > lastpad)
+ winmsg_buf[lastpad] = '.';
+ if (p - winmsg_buf > lastpad + 1)
+ winmsg_buf[lastpad + 1] = '.';
+ if (p - winmsg_buf > lastpad + 2)
+ winmsg_buf[lastpad + 2] = '.';
+ }
+ }
+
+ if (p - winmsg_buf > num) {
+ p = winmsg_buf + num;
+ if (trunclong) {
+ if (num - 1 >= lastpad)
+ p[-1] = '.';
+ if (num - 2 >= lastpad)
+ p[-2] = '.';
+ if (num - 3 >= lastpad)
+ p[-3] = '.';
+ }
+ r = winmsg_numrend;
+ while (r && winmsg_rendpos[r - 1] > num)
+ winmsg_rendpos[--r] = num;
+ }
+ truncpos = -1;
+ trunclong = 0;
+ if (lastpad > p - winmsg_buf)
+ lastpad = p - winmsg_buf;
+ debug1("lastpad now %d\n", lastpad);
+ }
+
+ if (*s == '=') {
+ while (p - winmsg_buf < num)
+ *p++ = ' ';
+ lastpad = p - winmsg_buf;
+ truncpos = -1;
+ trunclong = 0;
+ debug1("lastpad2 now %d\n", lastpad);
+ }
+ p--;
+ }
+ else if (padlen) {
+ *p = 127; /* internal pad representation */
+ numpad++;
+ }
+ break;
+
+ case 'n':
+ s++;
+ /* FALLTHROUGH */
+
+ default:
+ s--;
+ if (l > 10 + num) {
+ if (num == 0)
+ num = 1;
+ if (!win)
+ sprintf(p, "%*s", num, num > 1 ? "--" : "-");
+ else
+ sprintf(p, "%*d", num, win->w_number);
+ qmflag = 1;
+ p += strlen(p) - 1;
+ }
+ break;
+ }
+ }
+
+ if (qmpos && !qmflag)
+ p = qmpos + 1;
+ *p = '\0';
+ if (numpad) {
+ if (padlen > MAXSTR - 1)
+ padlen = MAXSTR - 1;
+ p = pad_expand(winmsg_buf, p, numpad, padlen);
+ }
+ if (ev) {
+ evdeq(ev); /* just in case */
+ ev->timeout.tv_sec = 0;
+ ev->timeout.tv_usec = 0;
+ }
+ if (ev && tick) {
+ now.tv_usec = 100000;
+ if (tick == 1)
+ now.tv_sec++;
+ else
+ now.tv_sec += tick - (now.tv_sec % tick);
+ ev->timeout = now;
+ debug2("NEW timeout %d %d\n", ev->timeout.tv_sec, tick);
+ }
+ return winmsg_buf;
+}
+
+
+char *MakeWinMsg(char *s, struct win *win, int esc)
+{
+ return MakeWinMsgEv(s, win, esc, 0, (struct event *)0, 0);
+}
+
+void PutWinMsg(char *s, int start, int max)
+{
+ int i, p, l, r, n;
+ struct mchar rend;
+ struct mchar rendstack[MAX_WINMSG_REND];
+ int rendstackn = 0;
+
+ if (s != winmsg_buf) {
+ /* sorry, no fancy coloring available */
+ debug1("PutWinMsg %s plain\n", s);
+ l = strlen(s);
+ if (l > max)
+ l = max;
+ l -= start;
+ s += start;
+ while (l-- > 0)
+ PUTCHARLP(*s++);
+ return;
+ }
+ rend = D_rend;
+ p = 0;
+ l = strlen(s);
+ debug2("PutWinMsg %s start attr %x\n", s, rend.attr);
+ for (i = 0; i < winmsg_numrend && max > 0; i++) {
+ if (p > winmsg_rendpos[i] || winmsg_rendpos[i] > l)
+ break;
+ if (p < winmsg_rendpos[i]) {
+ n = winmsg_rendpos[i] - p;
+ if (n > max)
+ n = max;
+ max -= n;
+ p += n;
+ while(n-- > 0) {
+ if (start-- > 0)
+ s++;
+ else
+ PUTCHARLP(*s++);
+ }
+ }
+
+ r = winmsg_rend[i];
+ if (r == -1) {
+ if (rendstackn > 0)
+ rend = rendstack[--rendstackn];
+ }
+ else {
+ rendstack[rendstackn++] = rend;
+ ApplyAttrColor(r, &rend);
+ }
+
+ SetRendition(&rend);
+ }
+ if (p < l){
+ n = l - p;
+ if (n > max)
+ n = max;
+ while(n-- > 0) {
+ if (start-- > 0)
+ s++;
+ else
+ PUTCHARLP(*s++);
+ }
+ }
+}
+
+#ifdef DEBUG
+static void fds1(int i, int j)
+{
+ while (i < j) {
+ debug1("%d ", i);
+ i++;
+ }
+ if ((j = open("/dev/null", 0)) >= 0) {
+ fds1(i + 1, j);
+ close(j);
+ }
+ else {
+ while (dup(++i) < 0 && errno != EBADF)
+ debug1("%d ", i);
+ debug1(" [%d]\n", i);
+ }
+}
+
+static void fds()
+{
+ debug("fds: ");
+ fds1(-1, -1);
+}
+#endif
+
+static void serv_read_fn(struct event *ev, char *data)
+{
+ debug("Knock - knock!\n");
+ ReceiveMsg();
+}
+
+static void serv_select_fn(struct event *ev, char *data)
+{
+ struct win *p;
+ debug("serv_select_fn called\n");
+ /* XXX: messages?? */
+ if (GotSigChld)
+ SigChldHandler();
+
+ if (InterruptPlease) {
+ debug("Backend received interrupt\n");
+ /* This approach is rather questionable in a multi-display
+ * environment */
+ if (fore && displays) {
+#if defined(TERMIO) || defined(POSIX)
+ char ibuf = displays->d_OldMode.tio.c_cc[VINTR];
+#else
+ char ibuf = displays->d_OldMode.m_tchars.t_intrc;
+#endif
+
+
+#ifdef PSEUDOS
+ write(W_UWP(fore) ? fore->w_pwin->p_ptyfd : fore->w_ptyfd, &ibuf, 1);
+ debug1("Backend wrote interrupt to %d", fore->w_number);
+ debug1("%s\n", W_UWP(fore) ? " (pseudowin)" : "");
+#else
+ write(fore->w_ptyfd, &ibuf, 1);
+ debug1("Backend wrote interrupt to %d\n", fore->w_number);
+#endif
+ }
+ InterruptPlease = 0;
+ }
+
+ for (p = windows; p; p = p->w_next){
+ if (p->w_bell == BELL_FOUND || p->w_bell == BELL_VISUAL) {
+ struct canvas *cv;
+ int visual = p->w_bell == BELL_VISUAL || visual_bell;
+ p->w_bell = BELL_ON;
+ for (display = displays; display; display = display->d_next) {
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ if (cv->c_layer->l_bottom == &p->w_layer)
+ break;
+
+ if (cv == 0) {
+ p->w_bell = BELL_DONE;
+ Msg(0, "%s", MakeWinMsg(BellString, p, '%'));
+ }
+ else if (visual && !D_VB && (!D_status || !D_status_bell)) {
+ Msg(0, "%s", VisualBellString);
+
+ if (D_status) {
+ D_status_bell = 1;
+ debug1("using vbell timeout %d\n", VBellWait);
+ SetTimeout(&D_statusev, VBellWait );
+ }
+ }
+ }
+
+ /* don't annoy the user with two messages */
+ if (p->w_monitor == MON_FOUND)
+ p->w_monitor = MON_DONE;
+ WindowChanged(p, 'f');
+ }
+
+ if (p->w_monitor == MON_FOUND) {
+ struct canvas *cv;
+ p->w_monitor = MON_ON;
+ for (display = displays; display; display = display->d_next) {
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ if (cv->c_layer->l_bottom == &p->w_layer)
+ break;
+ if (cv)
+ continue; /* user already sees window */
+
+#ifdef MULTIUSER
+ if (!(ACLBYTE(p->w_mon_notify, D_user->u_id) & ACLBIT(D_user->u_id)))
+ continue; /* user doesn't care */
+#endif
+
+ Msg(0, "%s", MakeWinMsg(ActivityString, p, '%'));
+ p->w_monitor = MON_DONE;
+ }
+ WindowChanged(p, 'f');
+ }
+
+ if (p->w_silence == SILENCE_FOUND) {
+ /* Unset the flag if the user switched to this window. */
+ if (p->w_layer.l_cvlist) {
+ p->w_silence = SILENCE_ON;
+ WindowChanged(p, 'f');
+ }
+ }
+ }
+
+ for (display = displays; display; display = display->d_next) {
+ struct canvas *cv;
+ if (D_status == STATUS_ON_WIN)
+ continue;
+ /* XXX: should use display functions! */
+ for (cv = D_cvlist; cv; cv = cv->c_next) {
+ int lx, ly;
+
+ /* normalize window, see resize.c */
+ lx = cv->c_layer->l_x;
+ ly = cv->c_layer->l_y;
+ if (lx == cv->c_layer->l_width)
+ lx--;
+ if (ly + cv->c_yoff < cv->c_ys) {
+ int i, n = cv->c_ys - (ly + cv->c_yoff);
+ cv->c_yoff = cv->c_ys - ly;
+ RethinkViewportOffsets(cv);
+ if (n > cv->c_layer->l_height)
+ n = cv->c_layer->l_height;
+ CV_CALL(cv,
+ LScrollV(flayer, -n, 0, flayer->l_height - 1, 0);
+ LayRedisplayLine(-1, -1, -1, 1);
+ for (i = 0; i < n; i++)
+ LayRedisplayLine(i, 0, flayer->l_width - 1, 1);
+ if (cv == cv->c_display->d_forecv)
+ LaySetCursor();
+ );
+ }
+ else if (ly + cv->c_yoff > cv->c_ye) {
+ int i, n = ly + cv->c_yoff - cv->c_ye;
+ cv->c_yoff = cv->c_ye - ly;
+ RethinkViewportOffsets(cv);
+ if (n > cv->c_layer->l_height)
+ n = cv->c_layer->l_height;
+ CV_CALL(cv,
+ LScrollV(flayer, n, 0, cv->c_layer->l_height - 1, 0);
+ LayRedisplayLine(-1, -1, -1, 1);
+ for (i = 0; i < n; i++)
+ LayRedisplayLine(i + flayer->l_height - n, 0, flayer->l_width - 1, 1);
+ if (cv == cv->c_display->d_forecv)
+ LaySetCursor();
+ );
+ }
+ if (lx + cv->c_xoff < cv->c_xs) {
+ int i, n = cv->c_xs - (lx + cv->c_xoff);
+ if (n < (cv->c_xe - cv->c_xs + 1) / 2)
+ n = (cv->c_xe - cv->c_xs + 1) / 2;
+ if (cv->c_xoff + n > cv->c_xs)
+ n = cv->c_xs - cv->c_xoff;
+ cv->c_xoff += n;
+ RethinkViewportOffsets(cv);
+ if (n > cv->c_layer->l_width)
+ n = cv->c_layer->l_width;
+ CV_CALL(cv,
+ LayRedisplayLine(-1, -1, -1, 1);
+ for (i = 0; i < flayer->l_height; i++) {
+ LScrollH(flayer, -n, i, 0, flayer->l_width - 1, 0, 0);
+ LayRedisplayLine(i, 0, n - 1, 1);
+ }
+ if (cv == cv->c_display->d_forecv)
+ LaySetCursor();
+ );
+ }
+ else if (lx + cv->c_xoff > cv->c_xe) {
+ int i, n = lx + cv->c_xoff - cv->c_xe;
+ if (n < (cv->c_xe - cv->c_xs + 1) / 2)
+ n = (cv->c_xe - cv->c_xs + 1) / 2;
+ if (cv->c_xoff - n + cv->c_layer->l_width - 1 < cv->c_xe)
+ n = cv->c_xoff + cv->c_layer->l_width - 1 - cv->c_xe;
+ cv->c_xoff -= n;
+ RethinkViewportOffsets(cv);
+ if (n > cv->c_layer->l_width)
+ n = cv->c_layer->l_width;
+ CV_CALL(cv,
+ LayRedisplayLine(-1, -1, -1, 1);
+ for (i = 0; i < flayer->l_height; i++) {
+ LScrollH(flayer, n, i, 0, flayer->l_width - 1, 0, 0);
+ LayRedisplayLine(i, flayer->l_width - n, flayer->l_width - 1, 1);
+ }
+ if (cv == cv->c_display->d_forecv)
+ LaySetCursor();
+ );
+ }
+ }
+ }
+ for (display = displays; display; display = display->d_next) {
+ if (D_status == STATUS_ON_WIN || D_cvlist == 0 || D_cvlist->c_next == 0)
+ continue;
+ debug1("serv_select_fn: Restore on cv %#x\n", (int)D_forecv);
+ CV_CALL(D_forecv, LayRestore();LaySetCursor());
+ }
+}
+
+static void logflush_fn(struct event *ev, char *data)
+{
+ struct win *p;
+ char *buf;
+ int n;
+
+ if (!islogfile(NULL))
+ return; /* no more logfiles */
+ logfflush(NULL);
+ n = log_flush ? log_flush : (logtstamp_after + 4) / 5;
+
+ if (n) {
+ SetTimeout(ev, n * 1000);
+ evenq(ev); /* re-enqueue ourself */
+ }
+
+ if (!logtstamp_on)
+ return;
+
+ /* write fancy time-stamp */
+ for (p = windows; p; p = p->w_next) {
+ if (!p->w_log)
+ continue;
+ p->w_logsilence += n;
+ if (p->w_logsilence < logtstamp_after)
+ continue;
+ if (p->w_logsilence - n >= logtstamp_after)
+ continue;
+ buf = MakeWinMsg(logtstamp_string, p, '%');
+ logfwrite(p->w_log, buf, strlen(buf));
+ }
+}
+
+/*
+ * Interprets ^?, ^@ and other ^-control-char notation.
+ * Interprets \ddd octal notation
+ *
+ * The result is placed in *cp, p is advanced behind the parsed expression and
+ * returned.
+ */
+static char *ParseChar(char *p, char *cp)
+{
+ if (*p == 0)
+ return 0;
+
+ if (*p == '^' && p[1]) {
+ if (*++p == '?')
+ *cp = '\177';
+ else if (*p >= '@')
+ *cp = Ctrl(*p);
+ else
+ return 0;
+ ++p;
+ }
+ else if (*p == '\\' && *++p <= '7' && *p >= '0') {
+ *cp = 0;
+ do
+ *cp = *cp * 8 + *p - '0';
+ while (*++p <= '7' && *p >= '0');
+ }
+ else
+ *cp = *p++;
+ return p;
+}
+
+static int ParseEscape(char *p)
+{
+ unsigned char buf[2];
+
+ if (*p == 0)
+ SetEscape((struct acluser *)0, -1, -1);
+ else {
+ if ((p = ParseChar(p, (char *)buf)) == NULL ||
+ (p = ParseChar(p, (char *)buf+1)) == NULL || *p)
+ return -1;
+ SetEscape((struct acluser *)0, buf[0], buf[1]);
+ }
+ return 0;
+}
+
+void SetTtyname(bool fatal, struct stat *st)
+{
+ int ret;
+ int saved_errno = 0;
+
+ attach_tty_is_in_new_ns = false;
+ memset(&attach_tty_name_in_ns, 0, sizeof(attach_tty_name_in_ns));
+
+ errno = 0;
+ attach_tty = ttyname(0);
+ if (!attach_tty) {
+ if (errno == ENODEV) {
+ saved_errno = errno;
+ attach_tty = "/proc/self/fd/0";
+ attach_tty_is_in_new_ns = true;
+ ret = readlink(attach_tty, attach_tty_name_in_ns, sizeof(attach_tty_name_in_ns));
+ if (ret < 0 || (size_t)ret >= sizeof(attach_tty_name_in_ns))
+ Panic(0, "Bad tty '%s'", attach_tty);
+ } else if (fatal) {
+ Panic(0, "Must be connected to a terminal.");
+ } else {
+ attach_tty = "";
+ }
+ }
+
+ if (attach_tty && strcmp(attach_tty, "")) {
+ if (stat(attach_tty, st))
+ Panic(errno, "Cannot access '%s'", attach_tty);
+
+ if (strlen(attach_tty) >= MAXPATHLEN)
+ Panic(0, "TtyName too long - sorry.");
+
+ /* Only call CheckTtyname() if the device does not exist in
+ * another namespace.
+ */
+ if (saved_errno != ENODEV && CheckTtyname(attach_tty))
+ Panic(0, "Bad tty '%s'", attach_tty);
+ }
+}
diff --git a/screen.h b/screen.h
new file mode 100644
index 0000000..d39b7ea
--- /dev/null
+++ b/screen.h
@@ -0,0 +1,316 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+#include "os.h"
+
+#if defined(__STDC__)
+# ifndef __P
+# define __P(a) a
+# endif
+#else
+# ifndef __P
+# define __P(a) ()
+# endif
+# define const
+#endif
+
+#include "osdef.h"
+
+#include "ansi.h"
+#include "sched.h"
+#include "acls.h"
+#include "comm.h"
+#include "layer.h"
+#include "term.h"
+
+
+#ifdef DEBUG
+# define STATIC /* a function that the debugger should see */
+#else
+# define STATIC static
+#endif
+
+#ifdef DEBUG
+# define DEBUGDIR "/tmp/debug"
+# define debugf(a) do {if(dfp){fprintf a;fflush(dfp);}} while (0)
+# define debug(x) debugf((dfp,x))
+# define debug1(x,a) debugf((dfp,x,a))
+# define debug2(x,a,b) debugf((dfp,x,a,b))
+# define debug3(x,a,b,c) debugf((dfp,x,a,b,c))
+ extern FILE *dfp;
+#else
+# define debugf(a) do {} while (0)
+# define debug(x) debugf(x)
+# define debug1(x,a) debugf(x)
+# define debug2(x,a,b) debugf(x)
+# define debug3(x,a,b,c) debugf(x)
+#endif
+
+#ifndef DEBUG
+# define NOASSERT
+#endif
+
+#ifndef NOASSERT
+# if defined(__STDC__)
+# define ASSERT(lousy_cpp) do {if (!(lousy_cpp)) {if (!dfp) opendebug(0, 1);debug2("ASSERT("#lousy_cpp") failed file %s line %d\n", __FILE__, __LINE__);abort();}} while (0)
+# else
+# define ASSERT(lousy_cpp) do {if (!(lousy_cpp)) {if (!dfp) opendebug(0, 1);debug2("ASSERT(lousy_cpp) failed file %s line %d\n", __FILE__, __LINE__);abort();}} while (0)
+# endif
+#else
+# define ASSERT(lousy_cpp) do {} while (0)
+#endif
+
+/* here comes my own Free: jw. */
+#define Free(a) {if ((a) == 0) abort(); else free((void *)(a)); (a)=0;}
+
+#define Ctrl(c) ((c)&037)
+
+#define MAXSTR 768
+#define MAXARGS 64
+#define MSGWAIT 5
+#define MSGMINWAIT 1
+#define SILENCEWAIT 30
+
+/*
+ * if a nasty user really wants to try a history of 3000 lines on all 10
+ * windows, he will allocate 8 MegaBytes of memory, which is quite enough.
+ */
+#define MAXHISTHEIGHT 3000
+#define DEFAULTHISTHEIGHT 100
+#if defined(NAME_MAX) && NAME_MAX < 16
+# define DEFAULT_BUFFERFILE "/tmp/screen-xchg"
+#else
+# define DEFAULT_BUFFERFILE "/tmp/screen-exchange"
+#endif
+
+
+#if defined(hpux) && !(defined(VSUSP) && defined(VDSUSP) && defined(VWERASE) && defined(VLNEXT))
+# define HPUX_LTCHARS_HACK
+#endif
+
+struct mode
+{
+#ifdef POSIX
+ struct termios tio;
+# ifdef HPUX_LTCHARS_HACK
+ struct ltchars m_ltchars;
+# endif /* HPUX_LTCHARS_HACK */
+#else /* POSIX */
+# ifdef TERMIO
+ struct termio tio;
+# ifdef CYTERMIO
+ int m_mapkey;
+ int m_mapscreen;
+ int m_backspace;
+# endif
+# else /* TERMIO */
+ struct sgttyb m_ttyb;
+ struct tchars m_tchars;
+ struct ltchars m_ltchars;
+ int m_ldisc;
+ int m_lmode;
+# endif /* TERMIO */
+#endif /* POSIX */
+#if defined(KANJI) && defined(TIOCKSET)
+ struct jtchars m_jtchars;
+ int m_knjmode;
+#endif
+};
+
+
+/* #include "logfile.h" */ /* (requires stat.h) struct logfile */
+#include "image.h"
+#include "canvas.h"
+#include "display.h"
+#include "window.h"
+
+/*
+ * Parameters for the Detach() routine
+ */
+#define D_DETACH 0
+#define D_STOP 1
+#define D_REMOTE 2
+#define D_POWER 3
+#define D_REMOTE_POWER 4
+#define D_LOCK 5
+#define D_HANGUP 6
+
+/*
+ * Here are the messages the attacher sends to the backend
+ */
+#define MSG_CREATE 0
+#define MSG_ERROR 1
+#define MSG_ATTACH 2
+#define MSG_CONT 3
+#define MSG_DETACH 4
+#define MSG_POW_DETACH 5
+#define MSG_WINCH 6
+#define MSG_HANGUP 7
+#define MSG_COMMAND 8
+#define MSG_QUERY 9
+
+/*
+ * versions of struct msg:
+ * 0: screen version 3.6.6 (version count introduced)
+ * 1: screen version 4.1.0devel (revisions e3fc19a upto 8147d08)
+ * A few revisions after 8147d08 incorrectly
+ * carried version 1, but should have carried 2.
+ * 2: screen version 4.1.0devel (revisions 8b46d8a upto YYYYYYY)
+ * 3: screen version 4.2.0 (was incorrectly originally. Patched here)
+ * 4: screen version 4.2.1 (bumped once again due to changed terminal and login length)
+ * 5: screen version 4.4.0 (fix screenterm size)
+ */
+#define MSG_VERSION 5
+
+#define MSG_REVISION (('m'<<24) | ('s'<<16) | ('g'<<8) | MSG_VERSION)
+struct msg
+{
+ int protocol_revision; /* reduce harm done by incompatible messages */
+ int type;
+ char m_tty[MAXPATHLEN]; /* ttyname */
+ union
+ {
+ struct
+ {
+ int lflag;
+ int aflag;
+ int flowflag;
+ int hheight; /* size of scrollback buffer */
+ int nargs;
+ char line[MAXPATHLEN];
+ char dir[MAXPATHLEN];
+ char screenterm[MAXTERMLEN + 1]; /* is screen really "screen" ? */
+ }
+ create;
+ struct
+ {
+ char auser[MAXLOGINLEN + 1]; /* username */
+ int apid; /* pid of frontend */
+ int adaptflag; /* adapt window size? */
+ int lines, columns; /* display size */
+ char preselect[20];
+ int esc; /* his new escape character unless -1 */
+ int meta_esc; /* his new meta esc character unless -1 */
+ char envterm[MAXTERMLEN + 1]; /* terminal type */
+ int encoding; /* encoding of display */
+ int detachfirst; /* whether to detach remote sessions first */
+ }
+ attach;
+ struct
+ {
+ char duser[MAXLOGINLEN + 1]; /* username */
+ int dpid; /* pid of frontend */
+ }
+ detach;
+ struct
+ {
+ char auser[MAXLOGINLEN + 1]; /* username */
+ int nargs;
+ char cmd[MAXPATHLEN]; /* command */
+ int apid; /* pid of frontend */
+ char preselect[20];
+ char writeback[MAXPATHLEN]; /* The socket to write the result.
+ Only used for MSG_QUERY */
+ }
+ command;
+ char message[MAXPATHLEN * 2];
+ } m;
+};
+
+/*
+ * And the signals the attacher receives from the backend
+ */
+#define SIG_BYE SIGHUP
+#define SIG_POWER_BYE SIGUSR1
+#define SIG_LOCK SIGUSR2
+#define SIG_STOP SIGTSTP
+#ifdef SIGIO
+#define SIG_NODEBUG SIGIO /* triggerd by command 'debug off' */
+#endif
+
+
+#define BELL (Ctrl('g'))
+#define VBELLWAIT 1 /* No. of seconds a vbell will be displayed */
+
+#define BELL_ON 0 /* No bell has occurred in the window */
+#define BELL_FOUND 1 /* A bell has occurred, but user not yet notified */
+#define BELL_DONE 2 /* A bell has occured, user has been notified */
+
+#define BELL_VISUAL 3 /* A bell has occured in fore win, notify him visually */
+
+#define MON_OFF 0 /* Monitoring is off in the window */
+#define MON_ON 1 /* No activity has occurred in the window */
+#define MON_FOUND 2 /* Activity has occured, but user not yet notified */
+#define MON_DONE 3 /* Activity has occured, user has been notified */
+
+#define DUMP_TERMCAP 0 /* WriteFile() options */
+#define DUMP_HARDCOPY 1
+#define DUMP_EXCHANGE 2
+#define DUMP_SCROLLBACK 3
+
+#define SILENCE_OFF 0 /* Not checking for silence */
+#define SILENCE_ON 1 /* Window being monitored for silence */
+#define SILENCE_FOUND 2 /* Window is silent */
+#define SILENCE_DONE 3 /* Window is silent and user is notified */
+
+extern char strnomem[];
+
+/*
+ * line modes used by Input()
+ */
+#define INP_COOKED 0
+#define INP_NOECHO 1
+#define INP_RAW 2
+#define INP_EVERY 4
+
+
+#ifdef MULTIUSER
+struct acl
+{
+ struct acl *next;
+ char *name;
+};
+#endif
+
+/* register list */
+#define MAX_PLOP_DEFS 256
+
+struct baud_values
+{
+ int idx; /* the index in the bsd-is padding lookup table */
+ int bps; /* bits per seconds */
+ int sym; /* symbol defined in ttydev.h */
+};
+
+/*
+ * windowlist orders
+ */
+#define WLIST_NUM 0
+#define WLIST_MRU 1
+#define WLIST_NESTED 2
diff --git a/search.c b/search.c
new file mode 100644
index 0000000..ac8e64e
--- /dev/null
+++ b/search.c
@@ -0,0 +1,399 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+
+#include "config.h"
+#include "screen.h"
+#include "mark.h"
+#include "extern.h"
+
+#define INPUTLINE (flayer->l_height - 1)
+
+extern struct layer *flayer;
+extern struct win *fore;
+
+#ifdef COPY_PASTE
+
+int search_ic;
+
+/********************************************************************
+ * VI style Search
+ */
+
+static int matchword __P((char *, int, int, int));
+static void searchend __P((char *, int, char *));
+static void backsearchend __P((char *, int, char *));
+
+void
+Search(dir)
+int dir;
+{
+ struct markdata *markdata;
+ if (dir == 0)
+ {
+ markdata = (struct markdata *)flayer->l_data;
+ if (markdata->isdir > 0)
+ searchend(0, 0, NULL);
+ else if (markdata->isdir < 0)
+ backsearchend(0, 0, NULL);
+ else
+ LMsg(0, "No previous pattern");
+ }
+ else
+ Input((dir > 0 ? "/" : "?"), sizeof(markdata->isstr)-1, INP_COOKED,
+ (dir > 0 ? searchend : backsearchend), NULL, 0);
+}
+
+static void
+searchend(buf, len, data)
+char *buf;
+int len;
+char *data; /* dummy */
+{
+ int x = 0, sx, ex, y;
+ struct markdata *markdata;
+ struct win *p;
+
+ markdata = (struct markdata *)flayer->l_data;
+ p = markdata->md_window;
+ markdata->isdir = 1;
+ if (len)
+ strcpy(markdata->isstr, buf);
+ sx = markdata->cx + 1;
+ ex = flayer->l_width - 1;
+ for (y = markdata->cy; y < p->w_histheight + flayer->l_height; y++, sx = 0)
+ {
+ if ((x = matchword(markdata->isstr, y, sx, ex)) >= 0)
+ break;
+ }
+ if (y >= p->w_histheight + flayer->l_height)
+ {
+ LGotoPos(flayer, markdata->cx, W2D(markdata->cy));
+ LMsg(0, "Pattern not found");
+ }
+ else
+ revto(x, y);
+}
+
+static void
+backsearchend(buf, len, data)
+char *buf;
+int len;
+char *data; /* dummy */
+{
+ int sx, ex, x = -1, y;
+ struct markdata *markdata;
+
+ markdata = (struct markdata *)flayer->l_data;
+ markdata->isdir = -1;
+ if (len)
+ strcpy(markdata->isstr, buf);
+ ex = markdata->cx - 1;
+ for (y = markdata->cy; y >= 0; y--, ex = flayer->l_width - 1)
+ {
+ sx = 0;
+ while ((sx = matchword(markdata->isstr, y, sx, ex)) >= 0)
+ x = sx++;
+ if (x >= 0)
+ break;
+ }
+ if (y < 0)
+ {
+ LGotoPos(flayer, markdata->cx, W2D(markdata->cy));
+ LMsg(0, "Pattern not found");
+ }
+ else
+ revto(x, y);
+}
+
+
+/*
+ * Search for a string that matches pattern. The first character of the
+ * match must be on line y, between columns sx and ex (inclusive), but
+ * the rest of the match can extend beyond column ex and even onto the
+ * following line. Returns the starting column of the first match found,
+ * or -1 if there's no match.
+ */
+static int
+matchword(pattern, y, sx, ex)
+char *pattern;
+int y, sx, ex;
+{
+ unsigned char *ip, *cp, *pp, *cpe;
+ int cy;
+
+ fore = ((struct markdata *)flayer->l_data)->md_window;
+
+ for (;sx <= ex; sx++)
+ {
+ cy = y;
+ cp = WIN(cy)->image + sx;
+ cpe = WIN(cy)->image + flayer->l_width;
+ pp = (unsigned char *)pattern;
+ for (;;)
+ {
+ if (*cp != *pp)
+ if (!search_ic || ((*cp ^ *pp) & 0xdf) || (*cp | 0x20) < 'a' || (*cp | 0x20) > 'z')
+ break;
+ cp++;
+ pp++;
+ if (*pp == 0)
+ return sx;
+ if (cp == cpe) {
+ /*
+ * We have a partial match, but we've hit
+ * the end of this line. Does it wrap onto
+ * the following line? If not, we're done.
+ */
+ if (*cp == ' ' || cy >= fore->w_histheight + flayer->l_height - 1)
+ break;
+
+ /*
+ * This line does wrap, so look on the next
+ * line for the rest of our match.
+ */
+ cy++;
+ cp = WIN(cy)->image;
+ cpe = WIN(cy)->image + flayer->l_width;
+ }
+ }
+ }
+ return -1;
+}
+
+
+/********************************************************************
+ * Emacs style ISearch
+ */
+
+static char *isprompts[] = {
+ "I-search backward: ", "failing I-search backward: ",
+ "I-search: ", "failing I-search: "
+};
+
+
+static int is_redo __P((struct markdata *));
+static void is_process __P((char *, int, char *));
+static int is_bm __P((char *, int, int, int, int));
+
+
+static int
+is_bm(str, l, p, end, dir)
+char *str;
+int l, p, end, dir;
+{
+ int tab[256];
+ int i, q;
+ unsigned char *s, c;
+ int w = flayer->l_width;
+
+ /* *sigh* to make WIN work */
+ fore = ((struct markdata *)flayer->l_next->l_data)->md_window;
+ debug2("is_bm: searching for %s len %d\n", str, l);
+ debug3("start at %d end %d dir %d\n", p, end, dir);
+ if (p < 0 || p + l > end)
+ return -1;
+ if (l == 0)
+ return p;
+ if (dir < 0)
+ str += l - 1;
+ for (i = 0; i < 256; i++)
+ tab[i] = l * dir;
+ for (i = 0; i < l - 1; i++, str += dir)
+ {
+ q = *(unsigned char *)str;
+ tab[q] = (l - 1 - i) * dir;
+ if (search_ic && (q | 0x20) >= 'a' && ((q | 0x20) <= 'z'))
+ tab[q ^ 0x20] = (l - 1 - i) * dir;
+ }
+ if (dir > 0)
+ p += l - 1;
+ debug1("first char to match: %c\n", *str);
+ while (p >= 0 && p < end)
+ {
+ q = p;
+ s = (unsigned char *)str;
+ for (i = 0;;)
+ {
+ c = (WIN(q / w))->image[q % w];
+ if (i == 0)
+ p += tab[(int)(unsigned char) c];
+ if (c != *s)
+ if (!search_ic || ((c ^ *s) & 0xdf) || (c | 0x20) < 'a' || (c | 0x20) > 'z')
+ break;
+ q -= dir;
+ s -= dir;
+ if (++i == l)
+ return q + (dir > 0 ? 1 : -l);
+ }
+ }
+ return -1;
+}
+
+
+/*ARGSUSED*/
+static void
+is_process(p, n, data) /* i-search */
+char *p;
+int n;
+char *data; /* dummy */
+{
+ int pos, x, y, dir;
+ struct markdata *markdata;
+
+ if (n == 0)
+ return;
+ ASSERT(p);
+ markdata = (struct markdata *)flayer->l_next->l_data;
+
+ pos = markdata->cx + markdata->cy * flayer->l_width;
+ LGotoPos(flayer, markdata->cx, W2D(markdata->cy));
+
+ switch (*p)
+ {
+ case '\007': /* CTRL-G */
+ pos = markdata->isstartpos;
+ /*FALLTHROUGH*/
+ case '\033': /* ESC */
+ *p = 0;
+ break;
+ case '\013': /* CTRL-K */
+ case '\027': /* CTRL-W */
+ markdata->isistrl = 1;
+ /*FALLTHROUGH*/
+ case '\b':
+ case '\177':
+ if (markdata->isistrl == 0)
+ return;
+ markdata->isistrl--;
+ pos = is_redo(markdata);
+ *p = '\b';
+ break;
+ case '\023': /* CTRL-S */
+ case '\022': /* CTRL-R */
+ if (markdata->isistrl >= (int)sizeof(markdata->isistr))
+ return;
+ dir = (*p == '\023') ? 1 : -1;
+ pos += dir;
+ if (markdata->isdir == dir && markdata->isistrl == 0)
+ {
+ strcpy(markdata->isistr, markdata->isstr);
+ markdata->isistrl = markdata->isstrl = strlen(markdata->isstr);
+ break;
+ }
+ markdata->isdir = dir;
+ markdata->isistr[markdata->isistrl++] = *p;
+ break;
+ default:
+ if (*p < ' ' || markdata->isistrl >= (int)sizeof(markdata->isistr)
+ || markdata->isstrl >= (int)sizeof(markdata->isstr) - 1)
+ return;
+ markdata->isstr[markdata->isstrl++] = *p;
+ markdata->isistr[markdata->isistrl++] = *p;
+ markdata->isstr[markdata->isstrl] = 0;
+ debug2("New char: %c - left %d\n", *p, (int)sizeof(markdata->isistr) - markdata->isistrl);
+ }
+ if (*p && *p != '\b')
+ pos = is_bm(markdata->isstr, markdata->isstrl, pos, flayer->l_width * (markdata->md_window->w_histheight + flayer->l_height), markdata->isdir);
+ if (pos >= 0)
+ {
+ x = pos % flayer->l_width;
+ y = pos / flayer->l_width;
+ LAY_CALL_UP
+ (
+ LayRedisplayLine(INPUTLINE, 0, flayer->l_width - 1, 0);
+ revto(x, y);
+ if (W2D(markdata->cy) == INPUTLINE)
+ revto_line(markdata->cx, markdata->cy, INPUTLINE > 0 ? INPUTLINE - 1 : 1);
+ );
+ }
+ if (*p)
+ inp_setprompt(isprompts[markdata->isdir + (pos < 0) + 1], markdata->isstrl ? markdata->isstr : "");
+ flayer->l_x = markdata->cx;
+ flayer->l_y = W2D(markdata->cy);
+ LGotoPos(flayer, flayer->l_x, flayer->l_y);
+ if (!*p)
+ {
+ /* we are about to finish, keep cursor position */
+ flayer->l_next->l_x = markdata->cx;
+ flayer->l_next->l_y = W2D(markdata->cy);
+ }
+}
+
+static int
+is_redo(markdata)
+struct markdata *markdata;
+{
+ int i, pos, npos, dir;
+ char c;
+
+ npos = pos = markdata->isstartpos;
+ dir = markdata->isstartdir;
+ markdata->isstrl = 0;
+ for (i = 0; i < markdata->isistrl; i++)
+ {
+ c = markdata->isistr[i];
+ if (c == '\022') /* ^R */
+ pos += (dir = -1);
+ else if (c == '\023') /* ^S */
+ pos += (dir = 1);
+ else
+ markdata->isstr[markdata->isstrl++] = c;
+ if (pos >= 0)
+ {
+ npos = is_bm(markdata->isstr, markdata->isstrl, pos, flayer->l_width * (markdata->md_window->w_histheight + flayer->l_height), dir);
+ if (npos >= 0)
+ pos = npos;
+ }
+ }
+ markdata->isstr[markdata->isstrl] = 0;
+ markdata->isdir = dir;
+ return npos;
+}
+
+void
+ISearch(dir)
+int dir;
+{
+ struct markdata *markdata;
+
+ markdata = (struct markdata *)flayer->l_data;
+ markdata->isdir = markdata->isstartdir = dir;
+ markdata->isstartpos = markdata->cx + markdata->cy * flayer->l_width;
+ markdata->isistrl = markdata->isstrl = 0;
+ if (W2D(markdata->cy) == INPUTLINE)
+ revto_line(markdata->cx, markdata->cy, INPUTLINE > 0 ? INPUTLINE - 1 : 1);
+ Input(isprompts[dir + 1], sizeof(markdata->isstr) - 1, INP_RAW,
+ is_process, NULL, 0);
+ LGotoPos(flayer, markdata->cx, W2D(markdata->cy));
+ flayer->l_x = markdata->cx;
+ flayer->l_y = W2D(markdata->cy);
+}
+
+#endif /* COPY_PASTE */
diff --git a/socket.c b/socket.c
new file mode 100644
index 0000000..88c3dd8
--- /dev/null
+++ b/socket.c
@@ -0,0 +1,1930 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include "config.h"
+#include <stdbool.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+# include <sys/socket.h>
+# ifdef _OpenBSD_
+# include <sys/uio.h>
+# endif
+# include <sys/un.h>
+
+#ifndef SIGINT
+# include <signal.h>
+#endif
+
+#include "screen.h"
+
+#ifdef HAVE_DIRENT_H
+# include <dirent.h>
+#else
+# include <sys/dir.h>
+# define dirent direct
+#endif
+
+#ifndef CMSG_LEN
+#define CMSG_LEN(length) ((_CMSG_DATA_ALIGN(sizeof(struct cmsghdr))) + (length))
+#endif
+#ifndef CMSG_SPACE
+#define CMSG_SPACE(length) ((_CMSG_DATA_ALIGN(sizeof(struct cmsghdr))) + (_CMSG_DATA_ALIGN(length)))
+#endif
+
+#include "extern.h"
+#include "list_generic.h"
+
+static int CheckPid __P((int));
+static void ExecCreate __P((struct msg *));
+static void DoCommandMsg __P((struct msg *));
+#if defined(_SEQUENT_)
+# define connect sconnect /* _SEQUENT_ has braindamaged connect */
+static int sconnect __P((int, struct sockaddr *, int));
+#endif
+static void FinishAttach __P((struct msg *));
+static void FinishDetach __P((struct msg *));
+static void AskPassword __P((struct msg *));
+
+
+extern char *RcFileName, *extra_incap, *extra_outcap;
+extern int ServerSocket, real_uid, real_gid, eff_uid, eff_gid;
+extern int dflag, iflag, rflag, lsflag, quietflag, wipeflag, xflag;
+extern int queryflag;
+extern char *attach_tty, *LoginName, HostName[];
+extern struct display *display, *displays;
+extern struct win *fore, **wtab, *console_window, *windows;
+extern struct layer *flayer;
+extern struct layout *layout_attach, *layout_last, layout_last_marker;
+extern struct NewWindow nwin_undef;
+#ifdef MULTIUSER
+extern char *multi;
+#endif
+extern int maxwin;
+
+extern char *getenv();
+
+extern char SockPath[];
+extern struct event serv_read;
+extern char *rc_name;
+extern struct comm comms[];
+
+#ifdef MULTIUSER
+# define SOCKMODE (S_IWRITE | S_IREAD | (displays ? S_IEXEC : 0) | (multi ? 1 : 0))
+#else
+# define SOCKMODE (S_IWRITE | S_IREAD | (displays ? S_IEXEC : 0))
+#endif
+
+
+/*
+ * Socket directory manager
+ *
+ * fdp: pointer to store the first good socket.
+ * nfoundp: pointer to store the number of sockets found matching.
+ * notherp: pointer to store the number of sockets not matching.
+ * match: string to match socket name.
+ *
+ * The socket directory must be in SockPath!
+ * The global variables LoginName, multi, rflag, xflag, dflag,
+ * quietflag, SockPath are used.
+ *
+ * The first good socket is stored in fdp and its name is
+ * appended to SockPath.
+ * If none exists or fdp is NULL SockPath is not changed.
+ *
+ * Returns: number of good sockets.
+ *
+ */
+
+int
+FindSocket(fdp, nfoundp, notherp, match, is_sock)
+int *fdp;
+int *nfoundp, *notherp;
+char *match;
+bool *is_sock;
+{
+ DIR *dirp;
+ struct dirent *dp;
+ struct stat st;
+ int mode;
+ int sdirlen;
+ int matchlen = 0;
+ char *name, *n;
+ int firsts = -1, sockfd;
+ char *firstn = NULL;
+ int nfound = 0, ngood = 0, ndead = 0, nwipe = 0, npriv = 0;
+ int nperfect = 0;
+ struct sent
+ {
+ struct sent *next;
+ int mode;
+ char *name;
+ } *slist, **slisttail, *sent, *nsent;
+
+ if (match)
+ {
+ matchlen = strlen(match);
+#ifdef NAME_MAX
+ if (matchlen > NAME_MAX)
+ matchlen = NAME_MAX;
+#endif
+ }
+
+ /*
+ * SockPath contains the socket directory.
+ * At the end of FindSocket the socket name will be appended to it.
+ * Thus FindSocket() can only be called once!
+ */
+ sdirlen = strlen(SockPath);
+
+#ifdef USE_SETEUID
+ xseteuid(real_uid);
+ xsetegid(real_gid);
+#endif
+
+ if ((dirp = opendir(SockPath)) == 0)
+ Panic(errno, "Cannot opendir %s", SockPath);
+
+ slist = 0;
+ slisttail = &slist;
+ while ((dp = readdir(dirp)))
+ {
+ int cmatch = 0;
+ name = dp->d_name;
+ debug1("- %s\n", name);
+ if (*name == 0 || *name == '.' || strlen(name) > 2*MAXSTR)
+ continue;
+ if (matchlen)
+ {
+ n = name;
+ /* if we don't want to match digits. Skip them */
+ if ((*match <= '0' || *match > '9') && (*n > '0' && *n <= '9'))
+ {
+ while (*n >= '0' && *n <= '9')
+ n++;
+ if (*n == '.')
+ n++;
+ }
+ /* the tty prefix is optional */
+ if (strncmp(match, "tty", 3) && strncmp(n, "tty", 3) == 0)
+ n += 3;
+ if (strncmp(match, n, matchlen))
+ {
+ if (n == name && *match > '0' && *match <= '9')
+ {
+ while (*n >= '0' && *n <= '9')
+ n++;
+ if (*n == '.')
+ n++;
+ if (strncmp(match, n, matchlen))
+ continue;
+ }
+ else
+ continue;
+ }
+ else
+ cmatch = (*(n + matchlen) == 0);
+ debug1(" -> matched %s\n", match);
+ }
+ sprintf(SockPath + sdirlen, "/%s", name);
+
+ debug1("stat %s\n", SockPath);
+ errno = 0;
+ debug2("uid = %d, gid = %d\n", getuid(), getgid());
+ debug2("euid = %d, egid = %d\n", geteuid(), getegid());
+ if (stat(SockPath, &st))
+ {
+ debug1("errno = %d\n", errno);
+ continue;
+ }
+
+ *is_sock = S_ISSOCK(st.st_mode);
+ if (!(*is_sock) && !S_ISFIFO(st.st_mode))
+ continue;
+
+ debug2("st.st_uid = %d, real_uid = %d\n", st.st_uid, real_uid);
+#ifdef SOCKDIR /* if SOCKDIR is not defined, the socket is in $HOME.
+ in that case it does not make sense to compare uids. */
+ if ((int)st.st_uid != real_uid)
+ continue;
+#endif
+ mode = (int)st.st_mode & 0777;
+ debug1(" has mode 0%03o\n", mode);
+#ifdef MULTIUSER
+ if (multi && ((mode & 0677) != 0601))
+ {
+ debug(" is not a MULTI-USER session");
+ if (strcmp(multi, LoginName))
+ {
+ debug(" and we are in a foreign directory.\n");
+ mode = -4;
+ }
+ else
+ {
+ debug(", but it is our own session.\n");
+ }
+ }
+#endif
+ debug(" store it.\n");
+ if ((sent = (struct sent *)malloc(sizeof(struct sent))) == 0)
+ continue;
+ sent->next = 0;
+ sent->name = SaveStr(name);
+ sent->mode = mode;
+ *slisttail = sent;
+ slisttail = &sent->next;
+ nfound++;
+ sockfd = MakeClientSocket(0, *is_sock);
+#ifdef USE_SETEUID
+ /* MakeClientSocket sets ids back to eff */
+ xseteuid(real_uid);
+ xsetegid(real_gid);
+#endif
+ if (sockfd == -1)
+ {
+ debug2(" MakeClientSocket failed, unreachable? %d %d\n",
+ matchlen, wipeflag);
+ sent->mode = -3;
+#ifndef SOCKDIR_IS_LOCAL_TO_HOST
+ /* Unreachable - it is dead if we detect that it's local
+ * or we specified a match
+ */
+ n = name + strlen(name) - 1;
+ while (n != name && *n != '.')
+ n--;
+ if (matchlen == 0 && !(*n == '.' && n[1] && strncmp(HostName, n + 1, strlen(n + 1)) == 0))
+ {
+ npriv++; /* a good socket that was not for us */
+ continue;
+ }
+#endif
+ ndead++;
+ sent->mode = -1;
+ if (wipeflag)
+ {
+ if (unlink(SockPath) == 0)
+ {
+ sent->mode = -2;
+ nwipe++;
+ }
+ }
+ continue;
+ }
+
+ mode &= 0776;
+ /* Shall we connect ? */
+ debug2(" connecting: mode=%03o, rflag=%d, ", mode, rflag);
+ debug2("xflag=%d, dflag=%d ?\n", xflag, dflag);
+
+ /*
+ * mode 600: socket is detached.
+ * mode 700: socket is attached.
+ * xflag implies rflag here.
+ *
+ * fail, when socket mode mode is not 600 or 700
+ * fail, when we want to detach w/o reattach, but it already is detached.
+ * fail, when we only want to attach, but mode 700 and not xflag.
+ * fail, if none of dflag, rflag, xflag is set.
+ */
+ if ((mode != 0700 && mode != 0600) ||
+ (dflag && !rflag && !xflag && mode == 0600) ||
+ (!dflag && rflag && mode == 0700 && !xflag) ||
+ (!dflag && !rflag && !xflag))
+ {
+ close(sockfd);
+ debug(" no!\n");
+ npriv++; /* a good socket that was not for us */
+ continue;
+ }
+ ngood++;
+ if (cmatch)
+ nperfect++;
+ if (fdp && (firsts == -1 || (cmatch && nperfect == 1)))
+ {
+ if (firsts != -1)
+ close(firsts);
+ firsts = sockfd;
+ firstn = sent->name;
+ debug(" taken.\n");
+ }
+ else
+ {
+ debug(" discarded.\n");
+ close(sockfd);
+ }
+ }
+ (void)closedir(dirp);
+ if (!lsflag && nperfect == 1)
+ ngood = nperfect;
+ if (nfound && (lsflag || ngood != 1) && !quietflag)
+ {
+ switch(ngood)
+ {
+ case 0:
+ Msg(0, nfound > 1 ? "There are screens on:" : "There is a screen on:");
+ break;
+ case 1:
+ Msg(0, nfound > 1 ? "There are several screens on:" : "There is a suitable screen on:");
+ break;
+ default:
+ Msg(0, "There are several suitable screens on:");
+ break;
+ }
+ for (sent = slist; sent; sent = sent->next)
+ {
+ switch (sent->mode)
+ {
+ case 0700:
+ printf("\t%s\t(Attached)\n", sent->name);
+ break;
+ case 0600:
+ printf("\t%s\t(Detached)\n", sent->name);
+ break;
+#ifdef MULTIUSER
+ case 0701:
+ printf("\t%s\t(Multi, attached)\n", sent->name);
+ break;
+ case 0601:
+ printf("\t%s\t(Multi, detached)\n", sent->name);
+ break;
+#endif
+ case -1:
+ /* No trigraphs here! */
+ printf("\t%s\t(Dead ?%c?)\n", sent->name, '?');
+ break;
+ case -2:
+ printf("\t%s\t(Removed)\n", sent->name);
+ break;
+ case -3:
+ printf("\t%s\t(Remote or dead)\n", sent->name);
+ break;
+ case -4:
+ printf("\t%s\t(Private)\n", sent->name);
+ break;
+ }
+ }
+ }
+ if (ndead && !quietflag)
+ {
+ char *m = "Remove dead screens with 'screen -wipe'.";
+ if (wipeflag)
+ Msg(0, "%d socket%s wiped out.", nwipe, nwipe > 1 ? "s" : "");
+ else
+ Msg(0, m, ndead > 1 ? "s" : "", ndead > 1 ? "" : "es"); /* other args for nethack */
+ }
+ if (firsts != -1)
+ {
+ sprintf(SockPath + sdirlen, "/%s", firstn);
+ *fdp = firsts;
+ }
+ else
+ SockPath[sdirlen] = 0;
+ for (sent = slist; sent; sent = nsent)
+ {
+ nsent = sent->next;
+ free(sent->name);
+ free((char *)sent);
+ }
+#ifdef USE_SETEUID
+ xseteuid(eff_uid);
+ xsetegid(eff_gid);
+#endif
+ if (notherp)
+ *notherp = npriv;
+ if (nfoundp)
+ *nfoundp = nfound - nwipe;
+ return ngood;
+}
+
+/* FIFO (legacy mode) */
+static int
+MakeServerFifo()
+{
+ register int s;
+ struct stat st;
+
+#ifdef USE_SETEUID
+ xseteuid(real_uid);
+ xsetegid(real_gid);
+#endif
+ s = open(SockPath, O_WRONLY | O_NONBLOCK);
+ if (s >= 0)
+ {
+ debug("huii, my fifo already exists??\n");
+ if (quietflag)
+ {
+ Kill(D_userpid, SIG_BYE);
+ eexit(11);
+ }
+
+ Msg(0, "There is already a screen running on %s.", Filename(SockPath));
+
+ if (stat(SockPath, &st) < 0)
+ Panic(errno, "stat");
+
+#ifdef SOCKDIR /* if SOCKDIR is not defined, the socket is in $HOME. \
+ in that case it does not make sense to compare uids. */
+ if ((int)st.st_uid != real_uid)
+ Panic(0, "Unfortunately you are not its owner.");
+#endif
+ if ((st.st_mode & 0700) == 0600)
+ Panic(0, "To resume it, use \"screen -r\"");
+ else
+ Panic(0, "It is not detached.");
+ /* NOTREACHED */
+ }
+# ifdef USE_SETEUID
+ (void) unlink(SockPath);
+ if (mkfifo(SockPath, SOCKMODE) < 0)
+ Panic(0, "mkfifo %s failed", SockPath);
+# ifdef BROKEN_PIPE
+ s = open(SockPath, O_RDWR | O_NONBLOCK, 0);
+# else
+ s = open(SockPath, O_RDONLY | O_NONBLOCK, 0);
+# endif
+ if (s < 0)
+ Panic(errno, "open fifo %s", SockPath);
+
+ xseteuid(eff_uid);
+ xsetegid(eff_gid);
+
+ return s;
+
+# else /* !USE_SETEUID */
+ if (UserContext() > 0)
+ {
+ (void) unlink(SockPath);
+ UserReturn(mkfifo(SockPath, SOCKMODE));
+ }
+ if (UserStatus())
+ Panic(0, "mkfifo %s failed", SockPath);
+# ifdef BROKEN_PIPE
+ s = secopen(SockPath, O_RDWR | O_NONBLOCK, 0);
+# else
+ s = secopen(SockPath, O_RDONLY | O_NONBLOCK, 0);
+# endif
+ if (s < 0)
+ Panic(errno, "open fifo %s", SockPath);
+
+ return s;
+# endif /* !USE_SETEUID */
+}
+
+static int
+MakeClientFifo(err)
+int err;
+{
+ register int s = 0;
+
+ s = secopen(SockPath, O_WRONLY | O_NONBLOCK, 0);
+ if (s >= 0)
+ {
+ (void) fcntl(s, F_SETFL, 0);
+ return s;
+ }
+
+ if (err)
+ Msg(errno, "%s", SockPath);
+ debug2("MakeClientSocket() open %s failed (%d)\n", SockPath, errno);
+
+ return -1;
+}
+
+/* Unix Domain Sockets */
+static int
+MakeServerUnixSocket()
+{
+ register int s;
+ struct sockaddr_un a;
+ struct stat st;
+
+ s = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (s < 0)
+ Panic(errno, "socket");
+
+ a.sun_family = AF_UNIX;
+ strncpy(a.sun_path, SockPath, sizeof(a.sun_path));
+ a.sun_path[sizeof(a.sun_path) - 1] = 0;
+
+# ifdef USE_SETEUID
+ xseteuid(real_uid);
+ xsetegid(real_gid);
+# endif
+ if (connect(s, (struct sockaddr *) &a, strlen(SockPath) + 2) != -1)
+ {
+ debug("oooooh! socket already is alive!\n");
+ if (quietflag)
+ {
+ Kill(D_userpid, SIG_BYE);
+ /*
+ * oh, well. nobody receives that return code. papa
+ * dies by signal.
+ */
+ eexit(11);
+ }
+ Msg(0, "There is already a screen running on %s.", Filename(SockPath));
+
+ if (stat(SockPath, &st) < 0)
+ Panic(errno, "stat");
+
+#ifdef SOCKDIR /* if SOCKDIR is not defined, the socket is in $HOME. \
+ in that case it does not make sense to compare uids. */
+ if (st.st_uid != real_uid)
+ Panic(0, "Unfortunately you are not its owner.");
+#endif
+ if ((st.st_mode & 0700) == 0600)
+ Panic(0, "To resume it, use \"screen -r\"");
+ else
+ Panic(0, "It is not detached.");
+ /* NOTREACHED */
+ }
+
+#if defined(m88k) || defined(sysV68)
+ close(s); /* we get bind: Invalid argument if this is not done */
+ s = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (s < 0)
+ Panic(errno, "reopen socket");
+#endif
+ (void) unlink(SockPath);
+ if (bind(s, (struct sockaddr *) & a, strlen(SockPath) + 2) == -1)
+ Panic(errno, "bind (%s)", SockPath);
+#ifdef SOCK_NOT_IN_FS
+ {
+ int f = secopen(SockPath, O_RDWR | O_CREAT, SOCKMODE);
+ if (f < 0)
+ Panic(errno, "shadow socket open");
+ close(f);
+ }
+#else
+ chmod(SockPath, SOCKMODE);
+#ifndef USE_SETEUID
+ chown(SockPath, real_uid, real_gid);
+#endif
+#endif /* SOCK_NOT_IN_FS */
+ if (listen(s, 5) == -1)
+ Panic(errno, "listen");
+#ifdef F_SETOWN
+ fcntl(s, F_SETOWN, getpid());
+ debug1("Serversocket owned by %d\n", fcntl(s, F_GETOWN, 0));
+#endif /* F_SETOWN */
+#ifdef USE_SETEUID
+ xseteuid(eff_uid);
+ xsetegid(eff_gid);
+#endif
+ return s;
+}
+
+static int
+MakeClientUnixSocket(err)
+int err;
+{
+ register int s;
+ struct sockaddr_un a;
+
+ s = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (s < 0)
+ Panic(errno, "socket");
+
+ a.sun_family = AF_UNIX;
+ strncpy(a.sun_path, SockPath, sizeof(a.sun_path));
+ a.sun_path[sizeof(a.sun_path) - 1] = 0;
+#ifdef USE_SETEUID
+ xseteuid(real_uid);
+ xsetegid(real_gid);
+#else
+ if (access(SockPath, W_OK))
+ {
+ if (err)
+ Msg(errno, "%s", SockPath);
+ debug2("MakeClientSocket: access(%s): %d.\n", SockPath, errno);
+ close(s);
+ return -1;
+ }
+#endif
+ if (connect(s, (struct sockaddr *)&a, strlen(SockPath) + 2) == -1)
+ {
+ if (err)
+ Msg(errno, "%s: connect", SockPath);
+ debug("MakeClientSocket: connect failed.\n");
+ close(s);
+ s = -1;
+ }
+#ifdef USE_SETEUID
+ xseteuid(eff_uid);
+ xsetegid(eff_gid);
+#endif
+ return s;
+}
+
+int
+MakeServerSocket(socket)
+bool socket;
+{
+ if (socket)
+ return MakeServerUnixSocket();
+
+ return MakeServerFifo();
+}
+
+int
+MakeClientSocket(err, socket)
+int err;
+bool socket;
+{
+ if (socket)
+ return MakeClientUnixSocket(err);
+
+ return MakeClientFifo(err);
+}
+
+/*
+**
+** Message send and receive routines
+**
+*/
+
+void
+SendCreateMsg(sty, nwin)
+char *sty;
+struct NewWindow *nwin;
+{
+ int s;
+ struct msg m;
+ register char *p;
+ register int len, n;
+ char **av;
+ bool is_socket;
+
+#ifdef NAME_MAX
+ if (strlen(sty) > NAME_MAX)
+ sty[NAME_MAX] = 0;
+#endif
+ if (strlen(sty) > 2 * MAXSTR - 1)
+ sty[2 * MAXSTR - 1] = 0;
+ sprintf(SockPath + strlen(SockPath), "/%s", sty);
+ is_socket = IsSocket(SockPath);
+ if ((s = MakeClientSocket(1, is_socket)) == -1)
+ exit(1);
+ debug1("SendCreateMsg() to '%s'\n", SockPath);
+ bzero((char *)&m, sizeof(m));
+ m.type = MSG_CREATE;
+ strncpy(m.m_tty, attach_tty, sizeof(m.m_tty) - 1);
+ m.m_tty[sizeof(m.m_tty) - 1] = 0;
+ p = m.m.create.line;
+ n = 0;
+ if (nwin->args != nwin_undef.args)
+ for (av = nwin->args; *av && n < MAXARGS - 1; ++av, ++n)
+ {
+ len = strlen(*av) + 1;
+ if (p + len >= m.m.create.line + sizeof(m.m.create.line) - 1)
+ break;
+ strcpy(p, *av);
+ p += len;
+ }
+ if (nwin->aka != nwin_undef.aka && p + strlen(nwin->aka) + 1 < m.m.create.line + sizeof(m.m.create.line))
+ strcpy(p, nwin->aka);
+ else
+ *p = '\0';
+ m.m.create.nargs = n;
+ m.m.create.aflag = nwin->aflag;
+ m.m.create.flowflag = nwin->flowflag;
+ m.m.create.lflag = nwin->lflag;
+ m.m.create.hheight = nwin->histheight;
+ if (getcwd(m.m.create.dir, sizeof(m.m.create.dir)) == 0)
+ {
+ Msg(errno, "getcwd");
+ return;
+ }
+ if (nwin->term != nwin_undef.term)
+ strncpy(m.m.create.screenterm, nwin->term, MAXTERMLEN);
+ m.m.create.screenterm[MAXTERMLEN] = '\0';
+ m.protocol_revision = MSG_REVISION;
+ debug1("SendCreateMsg writing '%s'\n", m.m.create.line);
+ if (write(s, (char *) &m, sizeof m) != sizeof m)
+ Msg(errno, "write");
+ close(s);
+}
+
+int
+SendErrorMsg(tty, buf)
+char *tty, *buf;
+{
+ int s;
+ struct msg m;
+ bool is_socket;
+
+ strncpy(m.m.message, buf, sizeof(m.m.message) - 1);
+ m.m.message[sizeof(m.m.message) - 1] = 0;
+ is_socket = IsSocket(SockPath);
+ s = MakeClientSocket(0, is_socket);
+ if (s < 0)
+ return -1;
+ m.type = MSG_ERROR;
+ strncpy(m.m_tty, tty, sizeof(m.m_tty) - 1);
+ m.m_tty[sizeof(m.m_tty) - 1] = 0;
+ m.protocol_revision = MSG_REVISION;
+ debug1("SendErrorMsg(): writing to '%s'\n", SockPath);
+ (void) write(s, (char *) &m, sizeof m);
+ close(s);
+ return 0;
+}
+
+static void
+ExecCreate(mp)
+struct msg *mp;
+{
+ struct NewWindow nwin;
+ char *args[MAXARGS];
+ register int n;
+ register char **pp = args, *p = mp->m.create.line;
+ char buf[20];
+
+ nwin = nwin_undef;
+ n = mp->m.create.nargs;
+ if (n > MAXARGS - 1)
+ n = MAXARGS - 1;
+ /* ugly hack alert... should be done by the frontend! */
+ if (n)
+ {
+ int l, num;
+
+ l = strlen(p);
+ if (IsNumColon(p, 10, buf, sizeof(buf)))
+ {
+ if (*buf)
+ nwin.aka = buf;
+ num = atoi(p);
+ if (num < 0 || num > maxwin - 1)
+ num = 0;
+ nwin.StartAt = num;
+ p += l + 1;
+ n--;
+ }
+ }
+ for (; n > 0; n--)
+ {
+ *pp++ = p;
+ p += strlen(p) + 1;
+ }
+ *pp = 0;
+ if (*p)
+ nwin.aka = p;
+ if (*args)
+ nwin.args = args;
+ nwin.aflag = mp->m.create.aflag;
+ nwin.flowflag = mp->m.create.flowflag;
+ if (*mp->m.create.dir)
+ nwin.dir = mp->m.create.dir;
+ nwin.lflag = mp->m.create.lflag;
+ nwin.histheight = mp->m.create.hheight;
+ if (*mp->m.create.screenterm)
+ nwin.term = mp->m.create.screenterm;
+ MakeWindow(&nwin);
+}
+
+static int
+CheckPid(pid)
+int pid;
+{
+ debug1("Checking pid %d\n", pid);
+ if (pid < 2)
+ return -1;
+ if (eff_uid == real_uid)
+ return kill(pid, 0);
+ if (UserContext() > 0)
+ UserReturn(kill(pid, 0));
+ return UserStatus();
+}
+
+#ifdef hpux
+/*
+ * From: "F. K. Bruner" <napalm@ugcs.caltech.edu>
+ * From: "Dan Egnor" <egnor@oracorp.com> Tue Aug 10 06:56:45 1993
+ * The problem is that under HPUX (and possibly other systems too) there are
+ * two equivalent device files for each pty/tty device:
+ * /dev/ttyxx == /dev/pty/ttyxx
+ * /dev/ptyxx == /dev/ptym/ptyxx
+ * I didn't look into the exact specifics, but I've run across this problem
+ * before: Even if you open /dev/ttyxx as fds 0 1 & 2 for a process, if that
+ * process calls the system to determine its tty, it'll get /dev/pty/ttyxx.
+ *
+ * Earlier versions seemed to work -- wonder what they did.
+ */
+static int
+ttycmp(s1, s2)
+char *s1, *s2;
+{
+ if (strlen(s1) > 5) s1 += strlen(s1) - 5;
+ if (strlen(s2) > 5) s2 += strlen(s2) - 5;
+ return strcmp(s1, s2);
+}
+# define TTYCMP(a, b) ttycmp(a, b)
+#else
+# define TTYCMP(a, b) strcmp(a, b)
+#endif
+
+static int
+CreateTempDisplay(m, recvfd, wi)
+struct msg *m;
+int recvfd;
+struct win *wi;
+{
+ int pid;
+ int attach;
+ char *user;
+ int i;
+ struct mode Mode;
+ struct display *olddisplays = displays;
+
+ switch (m->type)
+ {
+ case MSG_CONT:
+ case MSG_ATTACH:
+ pid = m->m.attach.apid;
+ user = m->m.attach.auser;
+ attach = 1;
+ break;
+#ifdef REMOTE_DETACH
+ case MSG_DETACH:
+# ifdef POW_DETACH
+ case MSG_POW_DETACH:
+# endif /* POW_DETACH */
+ pid = m->m.detach.dpid;
+ user = m->m.detach.duser;
+ attach = 0;
+ break;
+#endif
+ default:
+ return -1;
+ }
+
+ if (CheckPid(pid))
+ {
+ Msg(0, "Attach attempt with bad pid(%d)!", pid);
+ return -1;
+ }
+ if (recvfd != -1)
+ {
+ int ret;
+ char ttyname_in_ns[MAXPATHLEN];
+ char *myttyname;
+
+ i = recvfd;
+ recvfd = -1;
+ memset(&ttyname_in_ns, 0, sizeof(ttyname_in_ns));
+ errno = 0;
+ myttyname = GetPtsPathOrSymlink(i);
+ if (myttyname && errno == ENODEV)
+ {
+ ret = readlink(myttyname, ttyname_in_ns, sizeof(ttyname_in_ns));
+ if (ret < 0 || (size_t)ret >= sizeof(ttyname_in_ns))
+ {
+ Msg(errno, "Could not perform necessary sanity checks on pts device.");
+ close(i);
+ Kill(pid, SIG_BYE);
+ return -1;
+ }
+ if (strcmp(ttyname_in_ns, m->m_tty))
+ {
+ Msg(errno, "Attach: passed fd does not match tty: %s - %s!", ttyname_in_ns, m->m_tty[0] != '\0' ? m->m_tty : "(null)");
+ close(i);
+ Kill(pid, SIG_BYE);
+ return -1;
+ }
+ /* m->m_tty so far contains the actual name of the pts device in the
+ * its (e.g. /dev/pts/0). This name however is not valid in the
+ * current namespace. So after we verified that the symlink returned
+ * by GetPtsPathOrSymlink() refers to the same pts device in this
+ * namespace we need to update m->m_tty to use that symlink for all
+ * future operations.
+ */
+ strncpy(m->m_tty, myttyname, sizeof(m->m_tty) - 1);
+ m->m_tty[sizeof(m->m_tty) - 1] = 0;
+ }
+ else if (myttyname == 0 || strcmp(myttyname, m->m_tty))
+ {
+ Msg(errno, "Attach: passed fd does not match tty: %s - %s!", m->m_tty, myttyname ? myttyname : "NULL");
+ close(i);
+ Kill(pid, SIG_BYE);
+ return -1;
+ }
+ }
+ else if ((i = secopen(m->m_tty, O_RDWR | O_NONBLOCK, 0)) < 0)
+ {
+ Msg(errno, "Attach: Could not open %s!", m->m_tty);
+ Kill(pid, SIG_BYE);
+ return -1;
+ }
+#ifdef MULTIUSER
+ if (attach)
+ Kill(pid, SIGCONT);
+#endif
+
+#if defined(ultrix) || defined(pyr) || defined(NeXT)
+ brktty(i); /* for some strange reason this must be done */
+#endif
+
+ if (attach)
+ {
+ if (display || wi)
+ {
+ write(i, "Attaching from inside of screen?\n", 33);
+ close(i);
+ Kill(pid, SIG_BYE);
+ Msg(0, "Attach msg ignored: coming from inside.");
+ return -1;
+ }
+
+#ifdef MULTIUSER
+ if (strcmp(user, LoginName))
+ if (*FindUserPtr(user) == 0)
+ {
+ write(i, "Access to session denied.\n", 26);
+ close(i);
+ Kill(pid, SIG_BYE);
+ Msg(0, "Attach: access denied for user %s.", user);
+ return -1;
+ }
+#endif
+
+ debug2("RecMsg: apid %d is o.k. and we just opened '%s'\n", pid, m->m_tty);
+#ifndef MULTI
+ if (displays)
+ {
+ write(i, "Screen session in use.\n", 23);
+ close(i);
+ Kill(pid, SIG_BYE);
+ return -1;
+ }
+#endif
+ }
+
+ /* create new display */
+ GetTTY(i, &Mode);
+ if (MakeDisplay(user, m->m_tty, attach ? m->m.attach.envterm : "", i, pid, &Mode) == 0)
+ {
+ write(i, "Could not make display.\n", 24);
+ close(i);
+ Msg(0, "Attach: could not make display for user %s", user);
+ Kill(pid, SIG_BYE);
+ return -1;
+ }
+#ifdef ENCODINGS
+ if (attach)
+ {
+# ifdef UTF8
+ D_encoding = m->m.attach.encoding == 1 ? UTF8 : m->m.attach.encoding ? m->m.attach.encoding - 1 : 0;
+# else
+ D_encoding = m->m.attach.encoding ? m->m.attach.encoding - 1 : 0;
+# endif
+ if (D_encoding < 0 || !EncodingName(D_encoding))
+ D_encoding = 0;
+ }
+#endif
+
+ if (iflag && olddisplays)
+ {
+ iflag = 0;
+#if defined(TERMIO) || defined(POSIX)
+ olddisplays->d_NewMode.tio.c_cc[VINTR] = VDISABLE;
+ olddisplays->d_NewMode.tio.c_lflag &= ~ISIG;
+#else /* TERMIO || POSIX */
+ olddisplays->d_NewMode.m_tchars.t_intrc = -1;
+#endif /* TERMIO || POSIX */
+ SetTTY(olddisplays->d_userfd, &olddisplays->d_NewMode);
+ }
+ SetMode(&D_OldMode, &D_NewMode, D_flow, iflag);
+ SetTTY(D_userfd, &D_NewMode);
+ if (fcntl(D_userfd, F_SETFL, FNBLOCK))
+ Msg(errno, "Warning: NBLOCK fcntl failed");
+ return 0;
+}
+
+void
+ReceiveMsg()
+{
+ int left, len;
+ static struct msg m;
+ char *p;
+ int ns = ServerSocket;
+ struct win *wi;
+ int recvfd = -1;
+ struct acluser *user;
+ bool is_socket;
+
+ /* Socket specific variables. */
+ struct sockaddr_un a;
+ struct msghdr msg;
+ struct iovec iov;
+ char control[1024];
+
+ is_socket = IsSocket(SockPath);
+ if (!is_socket)
+ {
+ debug("Ha, there was someone knocking on my fifo??\n");
+ if (fcntl(ServerSocket, F_SETFL, 0) == -1)
+ Panic(errno, "BLOCK fcntl");
+ p = (char *)&m;
+ left = sizeof(m);
+ }
+ else
+ {
+ len = sizeof(a);
+ debug("Ha, there was someone knocking on my socket??\n");
+ if ((ns = accept(ns, (struct sockaddr *)&a, (void *)&len)) < 0)
+ {
+ Msg(errno, "accept");
+ return;
+ }
+
+ p = (char *)&m;
+ left = sizeof(m);
+ bzero(&msg, sizeof(msg));
+ iov.iov_base = &m;
+ iov.iov_len = left;
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_controllen = sizeof(control);
+ msg.msg_control = &control;
+ while (left > 0)
+ {
+ len = recvmsg(ns, &msg, 0);
+ if (len < 0 && errno == EINTR)
+ continue;
+ if (len < 0)
+ {
+ close(ns);
+ Msg(errno, "read");
+ return;
+ }
+ if (msg.msg_controllen)
+ {
+ struct cmsghdr *cmsg;
+ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg;
+ cmsg = CMSG_NXTHDR(&msg, cmsg))
+ {
+ int cl;
+ char *cp;
+ if (cmsg->cmsg_level != SOL_SOCKET ||
+ cmsg->cmsg_type != SCM_RIGHTS)
+ continue;
+ cp = (char *)CMSG_DATA(cmsg);
+ cl = cmsg->cmsg_len;
+ while (cl >= CMSG_LEN(sizeof(int)))
+ {
+ int passedfd;
+ bcopy(cp, &passedfd, sizeof(int));
+ if (recvfd >= 0 && passedfd != recvfd)
+ close(recvfd);
+ recvfd = passedfd;
+ cl -= CMSG_LEN(sizeof(int));
+ }
+ }
+ }
+ p += len;
+ left -= len;
+ break;
+ }
+ }
+
+ while (left > 0)
+ {
+ len = read(ns, p, left);
+ if (len < 0 && errno == EINTR)
+ continue;
+ if (len <= 0)
+ break;
+ p += len;
+ left -= len;
+ }
+
+ if (!is_socket)
+ {
+#ifndef BROKEN_PIPE
+ /* Reopen pipe to prevent EOFs at the select() call */
+ close(ServerSocket);
+ if ((ServerSocket = secopen(SockPath, O_RDONLY | O_NONBLOCK, 0)) < 0)
+ Panic(errno, "reopen fifo %s", SockPath);
+ evdeq(&serv_read);
+ serv_read.fd = ServerSocket;
+ evenq(&serv_read);
+#endif
+ }
+ else
+ {
+ close(ns);
+ }
+
+ if (len < 0)
+ {
+ Msg(errno, "read");
+ if (recvfd != -1)
+ close(recvfd);
+ return;
+ }
+ if (left > 0)
+ {
+ if (left != sizeof(m))
+ Msg(0, "Message %d of %d bytes too small", left, (int)sizeof(m));
+ else
+ debug("No data on socket.\n");
+ return;
+ }
+ if (m.protocol_revision != MSG_REVISION)
+ {
+ if (recvfd != -1)
+ close(recvfd);
+ Msg(0, "Invalid message (magic 0x%08x).", m.protocol_revision);
+ return;
+ }
+
+ debug2("*** RecMsg: type %d tty %s\n", m.type, m.m_tty);
+ if (m.type != MSG_ATTACH && recvfd != -1)
+ {
+ close(recvfd);
+ recvfd = -1;
+ }
+
+ for (display = displays; display; display = display->d_next)
+ if (TTYCMP(D_usertty, m.m_tty) == 0)
+ break;
+ debug2("display: %s display %sfound\n", m.m_tty, display ? "" : "not ");
+ wi = 0;
+ if (!display)
+ {
+ for (wi = windows; wi; wi = wi->w_next)
+ if (!TTYCMP(m.m_tty, wi->w_tty))
+ {
+ /* XXX: hmmm, rework this? */
+ display =
+ wi->w_layer.l_cvlist ? wi->w_layer.l_cvlist->c_display : 0;
+ debug2("but window %s %sfound.\n", m.m_tty,
+ display ? "" : "(backfacing)");
+ break;
+ }
+ }
+
+ /* Remove the status to prevent garbage on the screen */
+ if (display && D_status)
+ RemoveStatus();
+
+ if (display && !D_tcinited && m.type != MSG_HANGUP)
+ {
+ if (recvfd != -1)
+ close(recvfd);
+ return; /* ignore messages for bad displays */
+ }
+
+ switch (m.type)
+ {
+ case MSG_WINCH:
+ if (display)
+ CheckScreenSize(1); /* Change fore */
+ break;
+ case MSG_CREATE:
+ /*
+ * the window that issued the create message need not be an
+ * active
+ * window. Then we create the window without having a display.
+ * Resulting in another inactive window.
+ */
+ ExecCreate(&m);
+ break;
+ case MSG_CONT:
+ if (display && D_userpid != 0 && kill(D_userpid, 0) == 0)
+ break; /* Intruder Alert */
+ debug2("RecMsg: apid=%d,was %d\n", m.m.attach.apid,
+ display ? D_userpid : 0);
+ /* FALLTHROUGH */
+
+ case MSG_ATTACH:
+ if (CreateTempDisplay(&m, recvfd, wi))
+ break;
+#ifdef PASSWORD
+ if (D_user->u_password && *D_user->u_password)
+ AskPassword(&m);
+ else
+#endif
+ FinishAttach(&m);
+ break;
+ case MSG_ERROR:
+ Msg(0, "%s", m.m.message);
+ break;
+ case MSG_HANGUP:
+ if (!wi) /* ignore hangups from inside */
+ Hangup();
+ break;
+#ifdef REMOTE_DETACH
+ case MSG_DETACH:
+#ifdef POW_DETACH
+ case MSG_POW_DETACH:
+#endif /* POW_DETACH */
+#ifdef PASSWORD
+ user = *FindUserPtr(m.m.detach.duser);
+ if (user && user->u_password && *user->u_password)
+ {
+ if (CreateTempDisplay(&m, recvfd, 0))
+ break;
+ AskPassword(&m);
+ }
+ else
+#endif /* PASSWORD */
+ FinishDetach(&m);
+ break;
+#endif
+ case MSG_QUERY:
+ {
+ char *oldSockPath = SaveStr(SockPath);
+ strcpy(SockPath, m.m.command.writeback);
+ bool is_socket = IsSocket(SockPath);
+ int s = MakeClientSocket(0, is_socket);
+ strcpy(SockPath, oldSockPath);
+ Free(oldSockPath);
+ if (s >= 0)
+ {
+ queryflag = s;
+ DoCommandMsg(&m);
+ close(s);
+ }
+ else
+ queryflag = -1;
+
+ Kill(m.m.command.apid,
+ (queryflag >= 0)
+ ? SIGCONT
+ : SIG_BYE); /* Send SIG_BYE if an error happened */
+ queryflag = -1;
+ }
+ break;
+ case MSG_COMMAND:
+ DoCommandMsg(&m);
+ break;
+ default:
+ Msg(0, "Invalid message (type %d).", m.type);
+ }
+}
+
+void
+ReceiveRaw(s)
+int s;
+{
+ char rd[256];
+ int len = 0;
+ struct sockaddr_un a;
+ bool is_socket;
+
+ is_socket = IsSocket(SockPath);
+ if (!is_socket)
+ {
+ if (fcntl(s, F_SETFL, 0) < 0)
+ Panic(errno, "BLOCK fcntl");
+ }
+ else
+ {
+ len = sizeof(a);
+ s = accept(s, (struct sockaddr *)&a, (void *)&len);
+ if (s < 0)
+ {
+ Msg(errno, "accept");
+ return;
+ }
+ }
+
+ while ((len = read(s, rd, 255)) > 0)
+ {
+ rd[len] = 0;
+ printf("%s", rd);
+ }
+ close(s);
+}
+
+#if defined(_SEQUENT_)
+#undef connect
+/*
+ * sequent_ptx socket emulation must have mode 000 on the socket!
+ */
+static int
+sconnect(s, sapp, len)
+int s, len;
+struct sockaddr *sapp;
+{
+ register struct sockaddr_un *sap;
+ struct stat st;
+ int x;
+
+ sap = (struct sockaddr_un *)sapp;
+ if (stat(sap->sun_path, &st))
+ return -1;
+ chmod(sap->sun_path, 0);
+ x = connect(s, (struct sockaddr *) sap, len);
+ chmod(sap->sun_path, st.st_mode);
+ return x;
+}
+#endif
+
+
+/*
+ * Set the mode bits of the socket to the current status
+ */
+int
+chsock()
+{
+ int r, euid = geteuid();
+ if (euid != real_uid)
+ {
+ if (UserContext() <= 0)
+ return UserStatus();
+ }
+ r = chmod(SockPath, SOCKMODE);
+ /*
+ * Sockets usually reside in the /tmp/ area, where sysadmin scripts
+ * may be happy to remove old files. We manually prevent the socket
+ * from becoming old. (chmod does not touch mtime).
+ */
+ (void)utimes(SockPath, NULL);
+
+ if (euid != real_uid)
+ UserReturn(r);
+ return r;
+}
+
+/*
+ * Try to recreate the socket/pipe
+ */
+int
+RecoverSocket()
+{
+ bool is_socket;
+
+ close(ServerSocket);
+ if ((int)geteuid() != real_uid)
+ {
+ if (UserContext() > 0)
+ UserReturn(unlink(SockPath));
+ (void)UserStatus();
+ }
+ else
+ (void) unlink(SockPath);
+
+ is_socket = IsSocket(SockPath);
+ if ((ServerSocket = MakeServerSocket(is_socket)) < 0)
+ return 0;
+ evdeq(&serv_read);
+ serv_read.fd = ServerSocket;
+ evenq(&serv_read);
+ return 1;
+}
+
+
+static void
+FinishAttach(m)
+struct msg *m;
+{
+ char *p;
+ int pid;
+ int noshowwin;
+ struct win *wi;
+
+ ASSERT(display);
+ pid = D_userpid;
+
+#ifdef REMOTE_DETACH
+ if (m->m.attach.detachfirst == MSG_DETACH
+# ifdef POW_DETACH
+ || m->m.attach.detachfirst == MSG_POW_DETACH
+# endif
+ )
+ FinishDetach(m);
+#endif
+
+#if defined(pyr) || defined(xelos) || defined(sequent)
+ /*
+ * Kludge for systems with braindamaged termcap routines,
+ * which evaluate $TERMCAP, regardless whether it describes
+ * the correct terminal type or not.
+ */
+ debug("unsetenv(TERMCAP) in case of a different terminal");
+ unsetenv("TERMCAP");
+#endif
+
+ /*
+ * We reboot our Terminal Emulator. Forget all we knew about
+ * the old terminal, reread the termcap entries in .screenrc
+ * (and nothing more from .screenrc is read. Mainly because
+ * I did not check, whether a full reinit is safe. jw)
+ * and /etc/screenrc, and initialise anew.
+ */
+ if (extra_outcap)
+ free(extra_outcap);
+ if (extra_incap)
+ free(extra_incap);
+ extra_incap = extra_outcap = 0;
+ debug2("Message says size (%dx%d)\n", m->m.attach.columns, m->m.attach.lines);
+#ifdef ETCSCREENRC
+# ifdef ALLOW_SYSSCREENRC
+ if ((p = getenv("SYSSCREENRC")))
+ StartRc(p, 1);
+ else
+# endif
+ StartRc(ETCSCREENRC, 1);
+#endif
+ StartRc(RcFileName, 1);
+ if (InitTermcap(m->m.attach.columns, m->m.attach.lines))
+ {
+ FreeDisplay();
+ Kill(pid, SIG_BYE);
+ return;
+ }
+ MakeDefaultCanvas();
+ InitTerm(m->m.attach.adaptflag); /* write init string on fd */
+ if (displays->d_next == 0)
+ (void) chsock();
+ signal(SIGHUP, SigHup);
+ if (m->m.attach.esc != -1 && m->m.attach.meta_esc != -1)
+ {
+ D_user->u_Esc = m->m.attach.esc;
+ D_user->u_MetaEsc = m->m.attach.meta_esc;
+ }
+
+#ifdef UTMPOK
+ /*
+ * we set the Utmp slots again, if we were detached normally
+ * and if we were detached by ^Z.
+ * don't log zomies back in!
+ */
+ RemoveLoginSlot();
+ if (displays->d_next == 0)
+ for (wi = windows; wi; wi = wi->w_next)
+ if (wi->w_ptyfd >= 0 && wi->w_slot != (slot_t) -1)
+ SetUtmp(wi);
+#endif
+
+ D_fore = NULL;
+ if (layout_attach)
+ {
+ struct layout *lay = layout_attach;
+ if (lay == &layout_last_marker)
+ lay = layout_last;
+ if (lay)
+ {
+ LoadLayout(lay, &D_canvas);
+ SetCanvasWindow(D_forecv, 0);
+ }
+ }
+ /*
+ * there may be a window that we remember from last detach:
+ */
+ debug1("D_user->u_detachwin = %d\n", D_user->u_detachwin);
+ if (D_user->u_detachwin >= 0)
+ fore = wtab[D_user->u_detachwin];
+ else
+ fore = 0;
+
+ /* Wayne wants us to restore the other window too. */
+ if (D_user->u_detachotherwin >= 0)
+ D_other = wtab[D_user->u_detachotherwin];
+
+ noshowwin = 0;
+ if (*m->m.attach.preselect)
+ {
+ if (!strcmp(m->m.attach.preselect, "="))
+ fore = 0;
+ else if (!strcmp(m->m.attach.preselect, "-"))
+ {
+ fore = 0;
+ noshowwin = 1;
+ }
+ else if (!strcmp(m->m.attach.preselect, "+"))
+ {
+ struct action newscreen;
+ char *na = 0;
+ newscreen.nr = RC_SCREEN;
+ newscreen.args = &na;
+ newscreen.quiet = 0;
+ DoAction(&newscreen, -1);
+ }
+ else
+ fore = FindNiceWindow(fore, m->m.attach.preselect);
+ }
+ else
+ fore = FindNiceWindow(fore, 0);
+ if (fore)
+ SetForeWindow(fore);
+ else if (!noshowwin)
+ {
+#ifdef MULTIUSER
+ if (!AclCheckPermCmd(D_user, ACL_EXEC, &comms[RC_WINDOWLIST]))
+#endif
+ {
+ struct display *olddisplay = display;
+ flayer = D_forecv->c_layer;
+ display_windows(1, WLIST_NUM, (struct win *)0);
+ noshowwin = 1;
+ display = olddisplay; /* display_windows can change display */
+ }
+ }
+ Activate(0);
+ ResetIdle();
+ if (!D_fore && !noshowwin)
+ ShowWindows(-1);
+ if (displays->d_next == 0 && console_window)
+ {
+ if (TtyGrabConsole(console_window->w_ptyfd, 1, "reattach") == 0)
+ Msg(0, "console %s is on window %d", HostName, console_window->w_number);
+ }
+ debug("activated...\n");
+
+# if defined(DEBUG) && defined(SIG_NODEBUG)
+ if (!dfp)
+ {
+ sleep(1);
+ debug1("Attacher %d must not debug, as we have debug off.\n", pid);
+ kill(pid, SIG_NODEBUG);
+ }
+# endif /* SIG_NODEBUG */
+}
+
+static void
+FinishDetach(m)
+struct msg *m;
+{
+ struct display *next, **d, *det;
+ int pid;
+
+ if (m->type == MSG_ATTACH)
+ pid = D_userpid;
+ else
+ pid = m->m.detach.dpid;
+
+ /* Remove the temporary display prompting for the password from the list */
+ for (d = &displays; (det = *d); d = &det->d_next)
+ {
+ if (det->d_userpid == pid)
+ break;
+ }
+ if (det)
+ {
+ *d = det->d_next;
+ det->d_next = 0;
+ }
+
+ for (display = displays; display; display = next)
+ {
+ next = display->d_next;
+# ifdef POW_DETACH
+ if (m->type == MSG_POW_DETACH)
+ Detach(D_REMOTE_POWER);
+ else
+# endif /* POW_DETACH */
+ if (m->type == MSG_DETACH)
+ Detach(D_REMOTE);
+ else if (m->type == MSG_ATTACH)
+ {
+#ifdef POW_DETACH
+ if (m->m.attach.detachfirst == MSG_POW_DETACH)
+ Detach(D_REMOTE_POWER);
+ else
+#endif
+ if (m->m.attach.detachfirst == MSG_DETACH)
+ Detach(D_REMOTE);
+ }
+ }
+ display = displays = det;
+ if (m->type != MSG_ATTACH)
+ {
+ if (display)
+ FreeDisplay();
+ Kill(pid, SIGCONT);
+ }
+}
+
+#ifdef PASSWORD
+static void PasswordProcessInput __P((char *, int));
+
+struct pwdata {
+ int l;
+ char buf[MAXLOGINLEN + 1];
+ struct msg m;
+};
+
+static void
+AskPassword(m)
+struct msg *m;
+{
+ struct pwdata *pwdata;
+ ASSERT(display);
+ pwdata = (struct pwdata *)malloc(sizeof(struct pwdata));
+ if (!pwdata)
+ Panic(0, "%s", strnomem);
+ pwdata->l = 0;
+ pwdata->m = *m;
+ D_processinputdata = (char *)pwdata;
+ D_processinput = PasswordProcessInput;
+ AddStr("Screen password: ");
+}
+
+static void
+PasswordProcessInput(ibuf, ilen)
+char *ibuf;
+int ilen;
+{
+ struct pwdata *pwdata;
+ int c, l;
+ char *up;
+ int pid = D_userpid;
+
+ pwdata = (struct pwdata *)D_processinputdata;
+ l = pwdata->l;
+ while (ilen-- > 0)
+ {
+ c = *(unsigned char *)ibuf++;
+ if (c == '\r' || c == '\n')
+ {
+ char *buf = NULL;
+ up = D_user->u_password;
+ pwdata->buf[l] = 0;
+ buf = crypt(pwdata->buf, up);
+ if (!buf || strncmp(buf, up, strlen(up)))
+ {
+ /* uh oh, user failed */
+ bzero(pwdata->buf, sizeof(pwdata->buf));
+ if (!buf)
+ AddStr("\r\ncrypt() failed.\r\n");
+ else
+ AddStr("\r\nPassword incorrect.\r\n");
+ D_processinputdata = 0; /* otherwise freed by FreeDis */
+ FreeDisplay();
+ Msg(0, "Illegal reattach attempt from terminal %s.", pwdata->m.m_tty);
+ free(pwdata);
+ Kill(pid, SIG_BYE);
+ return;
+ }
+ /* great, pw matched, all is fine */
+ bzero(pwdata->buf, sizeof(pwdata->buf));
+ AddStr("\r\n");
+ D_processinputdata = 0;
+ D_processinput = ProcessInput;
+#ifdef REMOTE_DETACH
+ if (pwdata->m.type == MSG_DETACH
+# ifdef POW_DETACH
+ || pwdata->m.type == MSG_POW_DETACH
+# endif
+ )
+ FinishDetach(&pwdata->m);
+ else
+#endif
+ FinishAttach(&pwdata->m);
+ free(pwdata);
+ return;
+ }
+ if (c == Ctrl('c'))
+ {
+ AddStr("\r\n");
+ FreeDisplay();
+ Kill(pid, SIG_BYE);
+ return;
+ }
+ if (c == '\b' || c == 0177)
+ {
+ if (l > 0)
+ l--;
+ continue;
+ }
+ if (c == Ctrl('u'))
+ {
+ l = 0;
+ continue;
+ }
+ if (l < (int)sizeof(pwdata->buf) - 1)
+ pwdata->buf[l++] = c;
+ }
+ pwdata->l = l;
+}
+#endif
+
+/* 'end' is exclusive, i.e. you should *not* write in *end */
+static char *
+strncpy_escape_quote(dst, src, end)
+char *dst;
+const char *src, *end;
+{
+ while (*src && dst < end)
+ {
+ if (*src == '"')
+ {
+ if (dst + 2 < end) /* \\ \" \0 */
+ *dst++ = '\\';
+ else
+ return NULL;
+ }
+ *dst++ = *src++;
+ }
+ if (dst >= end)
+ return NULL;
+
+ *dst = '\0';
+ return dst;
+}
+
+static void
+DoCommandMsg(mp)
+struct msg *mp;
+{
+ char *args[MAXARGS];
+ int argl[MAXARGS];
+ char fullcmd[MAXSTR];
+ register char *fc;
+ int n;
+ register char *p = mp->m.command.cmd;
+ struct acluser *user;
+#ifdef MULTIUSER
+ extern struct acluser *EffectiveAclUser; /* acls.c */
+#else
+ extern struct acluser *users; /* acls.c */
+#endif
+
+ n = mp->m.command.nargs;
+ if (n > MAXARGS - 1)
+ n = MAXARGS - 1;
+ for (fc = fullcmd; n > 0; n--)
+ {
+ int len = strlen(p);
+ *fc++ = '"';
+ if (!(fc = strncpy_escape_quote(fc, p, fullcmd + sizeof(fullcmd) - 2))) /* '"' ' ' */
+ {
+ Msg(0, "Remote command too long.");
+ queryflag = -1;
+ return;
+ }
+ p += len + 1;
+ *fc++ = '"';
+ *fc++ = ' ';
+ }
+ if (fc != fullcmd)
+ *--fc = 0;
+ if (Parse(fullcmd, sizeof fullcmd, args, argl) <= 0)
+ {
+ queryflag = -1;
+ return;
+ }
+#ifdef MULTIUSER
+ user = *FindUserPtr(mp->m.attach.auser);
+ if (user == 0)
+ {
+ Msg(0, "Unknown user %s tried to send a command!", mp->m.attach.auser);
+ queryflag = -1;
+ return;
+ }
+#else
+ user = users;
+#endif
+#ifdef PASSWORD
+ if (user->u_password && *user->u_password)
+ {
+ Msg(0, "User %s has a password, cannot use remote commands (using -Q or -X option).", mp->m.attach.auser);
+ queryflag = -1;
+ return;
+ }
+#endif
+ if (!display)
+ for (display = displays; display; display = display->d_next)
+ if (D_user == user)
+ break;
+ for (fore = windows; fore; fore = fore->w_next)
+ if (!TTYCMP(mp->m_tty, fore->w_tty))
+ {
+ if (!display)
+ display = fore->w_layer.l_cvlist ? fore->w_layer.l_cvlist->c_display : 0;
+
+ /* If the window is not visibile in any display, then do not use the originating window as
+ * the foreground window for the command. This way, if there is an existing display, then
+ * the command will execute from the foreground window of that display. This is necessary so
+ * that commands that are relative to the window (e.g. 'next' etc.) do the right thing. */
+ if (!fore->w_layer.l_cvlist || !fore->w_layer.l_cvlist->c_display)
+ fore = NULL;
+ break;
+ }
+ if (!display)
+ display = displays; /* sigh */
+ if (*mp->m.command.preselect)
+ {
+ int i = -1;
+ if (strcmp(mp->m.command.preselect, "-"))
+ {
+ i = WindowByNoN(mp->m.command.preselect);
+ if (i < 0 || !wtab[i])
+ {
+ Msg(0, "Could not find pre-select window.");
+ queryflag = -1;
+ return;
+ }
+ }
+ fore = i >= 0 ? wtab[i] : 0;
+ }
+ else if (!fore)
+ {
+ if (display && D_user == user)
+ fore = Layer2Window(display->d_forecv->c_layer);
+ if (!fore)
+ {
+ fore = user->u_detachwin >= 0 ? wtab[user->u_detachwin] : 0;
+ fore = FindNiceWindow(fore, 0);
+ }
+ }
+ if (!fore)
+ fore = windows; /* sigh */
+#ifdef MULTIUSER
+ EffectiveAclUser = user;
+#endif
+ if (*args)
+ {
+ char *oldrcname = rc_name;
+ rc_name = "-X";
+ debug3("Running command on display %x window %x (%d)\n", display, fore, fore ? fore->w_number : -1);
+ flayer = fore ? &fore->w_layer : 0;
+ if (fore && fore->w_savelayer && (fore->w_blocked || fore->w_savelayer->l_cvlist == 0))
+ flayer = fore->w_savelayer;
+ DoCommand(args, argl);
+ rc_name = oldrcname;
+ }
+#ifdef MULTIUSER
+ EffectiveAclUser = 0;
+#endif
+}
+
+int
+SendAttachMsg(s, m, fd)
+int s;
+struct msg *m;
+int fd;
+{
+ int r;
+ struct msghdr msg;
+ struct iovec iov;
+ char buf[CMSG_SPACE(sizeof(int))];
+ struct cmsghdr *cmsg;
+
+ iov.iov_base = (char *)m;
+ iov.iov_len = sizeof(*m);
+ bzero(&msg, sizeof(msg));
+ msg.msg_name = 0;
+ msg.msg_namelen = 0;
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_control = buf;
+ msg.msg_controllen = sizeof(buf);
+ cmsg = CMSG_FIRSTHDR(&msg);
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(int));
+ bcopy(&fd, CMSG_DATA(cmsg), sizeof(int));
+ msg.msg_controllen = cmsg->cmsg_len;
+ while(1)
+ {
+ r = sendmsg(s, &msg, 0);
+ if (r == -1 && errno == EINTR)
+ continue;
+ if (r == -1)
+ return -1;
+ return 0;
+ }
+}
+
+bool
+IsSocket(path)
+const char *path;
+{
+ struct stat st;
+
+ if (stat(path, &st) < 0)
+ return false;
+
+ return S_ISSOCK(st.st_mode);
+}
diff --git a/teln.c b/teln.c
new file mode 100644
index 0000000..f61d22b
--- /dev/null
+++ b/teln.c
@@ -0,0 +1,578 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <stdio.h>
+
+#include "config.h"
+
+#ifdef BUILTIN_TELNET
+
+#include "screen.h"
+#include "extern.h"
+
+extern struct win *fore;
+extern struct layer *flayer;
+extern int visual_bell;
+extern char screenterm[];
+extern int af;
+
+static void TelReply __P((struct win *, char *, int));
+static void TelDocmd __P((struct win *, int, int));
+static void TelDosub __P((struct win *));
+
+// why TEL_DEFPORT has "
+#define TEL_DEFPORT "23"
+#define TEL_CONNECTING (-2)
+
+#define TC_IAC 255
+#define TC_DONT 254
+#define TC_DO 253
+#define TC_WONT 252
+#define TC_WILL 251
+#define TC_SB 250
+#define TC_BREAK 243
+#define TC_SE 240
+
+#define TC_S "S b swWdDc"
+
+#define TO_BINARY 0
+#define TO_ECHO 1
+#define TO_SGA 3
+#define TO_TM 6
+#define TO_TTYPE 24
+#define TO_NAWS 31
+#define TO_TSPEED 32
+#define TO_LFLOW 33
+#define TO_LINEMODE 34
+#define TO_XDISPLOC 35
+#define TO_NEWENV 39
+
+#define TO_S "be c t wsf xE E"
+
+
+static unsigned char tn_init[] = {
+ TC_IAC, TC_DO, TO_SGA,
+ TC_IAC, TC_WILL, TO_TTYPE,
+ TC_IAC, TC_WILL, TO_NAWS,
+ TC_IAC, TC_WILL, TO_LFLOW,
+};
+
+static void
+tel_connev_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ struct win *p = (struct win *)data;
+ if (connect(p->w_ptyfd, (struct sockaddr *)&p->w_telsa, sizeof(p->w_telsa)) && errno != EISCONN)
+ {
+ char buf[1024];
+ buf[0] = ' ';
+ strncpy(buf + 1, strerror(errno), sizeof(buf) - 2);
+ buf[sizeof(buf) - 1] = 0;
+ WriteString(p, buf, strlen(buf));
+ WindowDied(p, 0, 0);
+ return;
+ }
+ WriteString(p, "connected.\r\n", 12);
+ evdeq(&p->w_telconnev);
+ p->w_telstate = 0;
+}
+
+int
+TelOpenAndConnect(struct win *p) {
+ int fd, on = 1;
+ char buf[256];
+
+ struct addrinfo hints, *res0, *res;
+
+ if (!(p->w_cmdargs[1])) {
+ Msg(0, "Usage: screen //telnet host [port]");
+ return -1;
+ }
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = af;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = IPPROTO_TCP;
+
+ if(getaddrinfo(p->w_cmdargs[1], p->w_cmdargs[2] ? p->w_cmdargs[2] : TEL_DEFPORT, &hints, &res0)) {
+ Msg(0, "unknown host: %s", p->w_cmdargs[1]);
+ return -1;
+ }
+
+ for(res = res0; res; res = res->ai_next) {
+ if((fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) {
+ if(res->ai_next)
+ continue;
+ else {
+ Msg(errno, "TelOpenAndConnect: socket");
+ freeaddrinfo(res0);
+ return -1;
+ }
+ }
+
+ if (setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on)))
+ Msg(errno, "TelOpenAndConnect: setsockopt SO_OOBINLINE");
+
+ if (p->w_cmdargs[2] && strcmp(p->w_cmdargs[2], TEL_DEFPORT))
+ snprintf(buf, 256, "Trying %s %s...", p->w_cmdargs[1], p->w_cmdargs[2]);
+ else
+ snprintf(buf, 256, "Trying %s...", p->w_cmdargs[1]);
+
+ WriteString(p, buf, strlen(buf));
+ if (connect(fd, res->ai_addr, res->ai_addrlen)) {
+ if (errno == EINPROGRESS) {
+ p->w_telstate = TEL_CONNECTING;
+ p->w_telconnev.fd = fd;
+ p->w_telconnev.handler = tel_connev_fn;
+ p->w_telconnev.data = (char *)p;
+ p->w_telconnev.type = EV_WRITE;
+ p->w_telconnev.pri = 1;
+ debug("telnet connect in progress...\n");
+ evenq(&p->w_telconnev);
+ }
+ else {
+ close(fd);
+ if(res->ai_next)
+ continue;
+ else {
+ Msg(errno, "TelOpenAndConnect: connect");
+ freeaddrinfo(res0);
+ return -1;
+ }
+ }
+ }
+ else
+ WriteString(p, "connected.\r\n", 12);
+
+ if (!(p->w_cmdargs[2] && strcmp(p->w_cmdargs[2], TEL_DEFPORT)))
+ TelReply(p, (char *)tn_init, sizeof(tn_init));
+
+ p->w_ptyfd = fd;
+ memcpy(&p->w_telsa, &res->ai_addr, sizeof(res->ai_addr));
+ freeaddrinfo(res0);
+ return 0;
+ }
+ return -1;
+}
+
+int
+TelIsline(p)
+struct win *p;
+{
+ return !fore->w_telropts[TO_SGA];
+}
+
+void
+TelProcessLine(bufpp, lenp)
+char **bufpp;
+int *lenp;
+{
+ int echo = !fore->w_telropts[TO_ECHO];
+ unsigned char c;
+ char *tb;
+ int tl;
+
+ char *buf = *bufpp;
+ int l = *lenp;
+ while (l--)
+ {
+ c = *(unsigned char *)buf++;
+ if (fore->w_telbufl + 2 >= IOSIZE)
+ {
+ WBell(fore, visual_bell);
+ continue;
+ }
+ if (c == '\r')
+ {
+ if (echo)
+ WriteString(fore, "\r\n", 2);
+ fore->w_telbuf[fore->w_telbufl++] = '\r';
+ fore->w_telbuf[fore->w_telbufl++] = '\n';
+ tb = fore->w_telbuf;
+ tl = fore->w_telbufl;
+ LayProcess(&tb, &tl);
+ fore->w_telbufl = 0;
+ continue;
+ }
+ if (c == '\b' && fore->w_telbufl > 0)
+ {
+ if (echo)
+ {
+ WriteString(fore, (char *)&c, 1);
+ WriteString(fore, " ", 1);
+ WriteString(fore, (char *)&c, 1);
+ }
+ fore->w_telbufl--;
+ }
+ if ((c >= 0x20 && c <= 0x7e) || c >= 0xa0)
+ {
+ if (echo)
+ WriteString(fore, (char *)&c, 1);
+ fore->w_telbuf[fore->w_telbufl++] = c;
+ }
+ }
+ *lenp = 0;
+}
+
+int
+DoTelnet(buf, lenp, f)
+char *buf;
+int *lenp;
+int f;
+{
+ int echo = !fore->w_telropts[TO_ECHO];
+ int cmode = fore->w_telropts[TO_SGA];
+ int bin = fore->w_telropts[TO_BINARY];
+ char *p = buf, *sbuf;
+ int trunc = 0;
+ int c;
+ int l = *lenp;
+
+ sbuf = p;
+ while (l-- > 0)
+ {
+ c = *(unsigned char *)p++;
+ if (c == TC_IAC || (c == '\r' && (l ==0 || *p != '\n') && cmode && !bin))
+ {
+ if (cmode && echo)
+ {
+ WriteString(fore, sbuf, p - sbuf);
+ sbuf = p;
+ }
+ if (f-- <= 0)
+ {
+ trunc++;
+ l--;
+ }
+ if (l < 0)
+ {
+ p--; /* drop char */
+ break;
+ }
+ if (l)
+ bcopy(p, p + 1, l);
+ if (c == TC_IAC)
+ *p++ = c;
+ else if (c == '\r')
+ *p++ = 0;
+ else if (c == '\n')
+ {
+ p[-1] = '\r';
+ *p++ = '\n';
+ }
+ }
+ }
+ *lenp = p - buf;
+ return trunc;
+}
+
+/* modifies data in-place, returns new length */
+int
+TelIn(p, buf, len, free)
+struct win *p;
+char *buf;
+int len;
+int free;
+{
+ char *rp, *wp;
+ int c;
+
+ rp = wp = buf;
+ while (len-- > 0)
+ {
+ c = *(unsigned char *)rp++;
+
+ if (p->w_telstate >= TC_WILL && p->w_telstate <= TC_DONT)
+ {
+ TelDocmd(p, p->w_telstate, c);
+ p->w_telstate = 0;
+ continue;
+ }
+ if (p->w_telstate == TC_SB || p->w_telstate == TC_SE)
+ {
+ if (p->w_telstate == TC_SE && c == TC_IAC)
+ p->w_telsubidx--;
+ if (p->w_telstate == TC_SE && c == TC_SE)
+ {
+ p->w_telsubidx--;
+ TelDosub(p);
+ p->w_telstate = 0;
+ continue;
+ }
+ if (p->w_telstate == TC_SB && c == TC_IAC)
+ p->w_telstate = TC_SE;
+ else
+ p->w_telstate = TC_SB;
+ p->w_telsubbuf[p->w_telsubidx] = c;
+ if (p->w_telsubidx < sizeof(p->w_telsubbuf) - 1)
+ p->w_telsubidx++;
+ continue;
+ }
+ if (p->w_telstate == TC_IAC)
+ {
+ if ((c >= TC_WILL && c <= TC_DONT) || c == TC_SB)
+ {
+ p->w_telsubidx = 0;
+ p->w_telstate = c;
+ continue;
+ }
+ p->w_telstate = 0;
+ if (c != TC_IAC)
+ continue;
+ }
+ else if (c == TC_IAC)
+ {
+ p->w_telstate = c;
+ continue;
+ }
+ if (p->w_telstate == '\r')
+ {
+ p->w_telstate = 0;
+ if (c == 0)
+ continue; /* suppress trailing \0 */
+ }
+ else if (c == '\n' && !p->w_telropts[TO_SGA])
+ {
+ /* oops... simulate terminal line mode: insert \r */
+ if (wp + 1 == rp)
+ {
+ if (free-- > 0)
+ {
+ if (len)
+ bcopy(rp, rp + 1, len);
+ rp++;
+ *wp++ = '\r';
+ }
+ }
+ else
+ *wp++ = '\r';
+ }
+ if (c == '\r')
+ p->w_telstate = c;
+ *wp++ = c;
+ }
+ return wp - buf;
+}
+
+static void
+TelReply(p, str, len)
+struct win *p;
+char *str;
+int len;
+{
+ if (len <= 0)
+ return;
+ if (p->w_inlen + len > IOSIZE)
+ {
+ Msg(0, "Warning: telnet protocol overrun!");
+ return;
+ }
+ bcopy(str, p->w_inbuf + p->w_inlen, len);
+ p->w_inlen += len;
+}
+
+static void
+TelDocmd(p, cmd, opt)
+struct win *p;
+int cmd, opt;
+{
+ unsigned char b[3];
+ int repl = 0;
+
+ if (cmd == TC_WONT)
+ debug2("[<-WONT %c %d]\n", TO_S[opt], opt);
+ if (cmd == TC_WILL)
+ debug2("[<-WILL %c %d]\n", TO_S[opt], opt);
+ if (cmd == TC_DONT)
+ debug2("[<-DONT %c %d]\n", TO_S[opt], opt);
+ if (cmd == TC_DO)
+ debug2("[<-DO %c %d]\n", TO_S[opt], opt);
+
+ switch(cmd)
+ {
+ case TC_WILL:
+ if (p->w_telropts[opt] || opt == TO_TM)
+ return;
+ repl = TC_DONT;
+ if (opt == TO_ECHO || opt == TO_SGA || opt == TO_BINARY)
+ {
+ p->w_telropts[opt] = 1;
+ /* setcon(); */
+ repl = TC_DO;
+ }
+ break;
+ case TC_WONT:
+ if (!p->w_telropts[opt] || opt == TO_TM)
+ return;
+ repl = TC_DONT;
+#if 0
+ if (opt == TO_ECHO || opt == TO_SGA)
+ setcon();
+#endif
+ p->w_telropts[opt] = 0;
+ break;
+ case TC_DO:
+ if (p->w_telmopts[opt])
+ return;
+ repl = TC_WONT;
+ if (opt == TO_TTYPE || opt == TO_SGA || opt == TO_BINARY || opt == TO_NAWS || opt == TO_TM || opt == TO_LFLOW)
+ {
+ repl = TC_WILL;
+ p->w_telmopts[opt] = 1;
+ }
+ p->w_telmopts[TO_TM] = 0;
+ break;
+ case TC_DONT:
+ if (!p->w_telmopts[opt])
+ return;
+ repl = TC_WONT;
+ p->w_telmopts[opt] = 0;
+ break;
+ }
+ b[0] = TC_IAC;
+ b[1] = repl;
+ b[2] = opt;
+
+ if (repl == TC_WONT)
+ debug2("[->WONT %c %d]\n", TO_S[opt], opt);
+ if (repl == TC_WILL)
+ debug2("[->WILL %c %d]\n", TO_S[opt], opt);
+ if (repl == TC_DONT)
+ debug2("[->DONT %c %d]\n", TO_S[opt], opt);
+ if (repl == TC_DO)
+ debug2("[->DO %c %d]\n", TO_S[opt], opt);
+
+ TelReply(p, (char *)b, 3);
+ if (cmd == TC_DO && opt == TO_NAWS)
+ TelWindowSize(p);
+}
+
+
+static void
+TelDosub(p)
+struct win *p;
+{
+ char trepl[MAXTERMLEN + 6 + 1];
+ int l;
+
+ switch(p->w_telsubbuf[0])
+ {
+ case TO_TTYPE:
+ if (p->w_telsubidx != 2 || p->w_telsubbuf[1] != 1)
+ return;
+ l = strlen(screenterm);
+ if (l >= MAXTERMLEN)
+ break;
+ sprintf(trepl, "%c%c%c%c%s%c%c", TC_IAC, TC_SB, TO_TTYPE, 0, screenterm, TC_IAC, TC_SE);
+ TelReply(p, trepl, l + 6);
+ break;
+ case TO_LFLOW:
+ if (p->w_telsubidx != 2)
+ return;
+ debug1("[FLOW %d]\r\n", p->w_telsubbuf[1]);
+ break;
+ default:
+ break;
+ }
+}
+
+void
+TelBreak(p)
+struct win *p;
+{
+ static unsigned char tel_break[] = { TC_IAC, TC_BREAK };
+ TelReply(p, (char *)tel_break, 2);
+}
+
+void
+TelWindowSize(p)
+struct win *p;
+{
+ char s[20], trepl[20], *t;
+ int i;
+
+ debug2("TelWindowSize %d %d\n", p->w_width, p->w_height);
+ if (p->w_width == 0 || p->w_height == 0 || !p->w_telmopts[TO_NAWS])
+ return;
+ sprintf(s, "%c%c%c%c%c%c%c%c%c", TC_SB, TC_SB, TO_NAWS, p->w_width / 256, p->w_width & 255, p->w_height / 256, p->w_height & 255, TC_SE, TC_SE);
+ t = trepl;
+ for (i = 0; i < 9; i++)
+ if ((unsigned char)(*t++ = s[i]) == TC_IAC)
+ *t++ = TC_IAC;
+ trepl[0] = TC_IAC;
+ t[-2] = TC_IAC;
+ debug(" - sending");
+ for (i = 0; trepl + i < t; i++)
+ debug1(" %02x", (unsigned char)trepl[i]);
+ debug("\n");
+ TelReply(p, trepl, t - trepl);
+}
+
+static char tc_s[] = TC_S;
+static char to_s[] = TO_S;
+
+void
+TelStatus(p, buf, l)
+struct win *p;
+char *buf;
+int l;
+{
+ int i;
+
+ *buf++ = '[';
+ for (i = 0; to_s[i]; i++)
+ {
+ if (to_s[i] == ' ' || p->w_telmopts[i] == 0)
+ continue;
+ *buf++ = to_s[i];
+ }
+ *buf++ = ':';
+ for (i = 0; to_s[i]; i++)
+ {
+ if (to_s[i] == ' ' || p->w_telropts[i] == 0)
+ continue;
+ *buf++ = to_s[i];
+ }
+ if (p->w_telstate == TEL_CONNECTING)
+ buf[-1] = 'C';
+ else if (p->w_telstate && p->w_telstate != '\r')
+ {
+ *buf++ = ':';
+ *buf++ = tc_s[p->w_telstate - TC_SE];
+ }
+ *buf++ = ']';
+ *buf = 0;
+ return;
+}
+
+#endif /* BUILTIN_TELNET */
diff --git a/term.c b/term.c
new file mode 100644
index 0000000..c92d85a
--- /dev/null
+++ b/term.c
@@ -0,0 +1,297 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include "term.h"
+
+#define KMAPDEF(s)
+#define KMAPADEF(s)
+#define KMAPMDEF(s)
+
+struct term term[T_N] =
+{
+/* display size */
+ { "li", T_NUM },
+ { "co", T_NUM },
+
+/* terminal types*/
+ { "hc", T_FLG },
+ { "os", T_FLG },
+ { "ns", T_FLG },
+/* cursor movement */
+ { "cm", T_STR },
+ { "ho", T_STR },
+ { "cr", T_STR },
+ { "up", T_STR },
+ { "UP", T_STR },
+ { "do", T_STR },
+ { "DO", T_STR },
+ { "bs", T_FLG },
+ { "bc", T_STR },
+ { "le", T_STR },
+ { "LE", T_STR },
+ { "nd", T_STR },
+ { "RI", T_STR },
+
+/* scroll */
+ { "cs", T_STR },
+ { "nl", T_STR },
+ { "sf", T_STR },
+ { "sr", T_STR },
+ { "al", T_STR },
+ { "AL", T_STR },
+ { "dl", T_STR },
+ { "DL", T_STR },
+
+/* insert/delete */
+ { "in", T_FLG },
+ { "im", T_STR },
+ { "ei", T_STR },
+ { "ic", T_STR },
+ { "IC", T_STR },
+ { "dc", T_STR },
+ { "DC", T_STR },
+
+/* erase */
+ { "ut", T_FLG },
+ { "cl", T_STR },
+ { "cd", T_STR },
+ { "CD", T_STR },
+ { "ce", T_STR },
+ { "cb", T_STR },
+
+/* initialise */
+ { "is", T_STR },
+ { "ti", T_STR },
+ { "te", T_STR },
+
+/* bell */
+ { "bl", T_STR },
+ { "vb", T_STR },
+
+/* resizing */
+ { "WS", T_STR },
+ { "Z0", T_STR },
+ { "Z1", T_STR },
+
+/* attributes */
+/* define T_ATTR */
+ { "mh", T_STR },
+ { "us", T_STR },
+ { "md", T_STR },
+ { "mr", T_STR },
+ { "so", T_STR },
+ { "mb", T_STR },
+ { "ue", T_STR },
+ { "se", T_STR },
+ { "me", T_STR },
+ { "ms", T_FLG },
+ { "sg", T_NUM },
+ { "ug", T_NUM },
+ { "sa", T_STR },
+
+/* color */
+ { "AF", T_STR },
+ { "AB", T_STR },
+ { "Sf", T_STR },
+ { "Sb", T_STR },
+ { "op", T_STR },
+ { "Co", T_NUM },
+ { "be", T_FLG },
+ { "AX", T_FLG },
+ { "C8", T_FLG },
+
+/* keypad/cursorkeys */
+ { "ks", T_STR },
+ { "ke", T_STR },
+ { "CS", T_STR },
+ { "CE", T_STR },
+
+/* printer */
+ { "po", T_STR },
+ { "pf", T_STR },
+
+/* status line */
+ { "hs", T_FLG },
+ { "ws", T_NUM },
+ { "ts", T_STR },
+ { "fs", T_STR },
+ { "ds", T_STR },
+
+/* cursor visibility */
+ { "vi", T_STR },
+ { "vs", T_STR },
+ { "ve", T_STR },
+
+/* margin handling */
+ { "am", T_FLG },
+ { "xv", T_FLG },
+ { "xn", T_FLG },
+ { "OP", T_FLG },
+ { "LP", T_FLG },
+
+/* special settings */
+ { "NF", T_FLG },
+ { "nx", T_FLG },
+ { "AN", T_FLG },
+ { "OL", T_NUM },
+ { "KJ", T_STR },
+ { "VR", T_STR },
+ { "VN", T_STR },
+ { "TF", T_FLG },
+ { "XT", T_FLG },
+
+/* d_font setting */
+ { "G0", T_FLG },
+ { "S0", T_STR },
+ { "E0", T_STR },
+ { "C0", T_STR },
+ { "as", T_STR },
+ { "ae", T_STR },
+ { "ac", T_STR },
+ { "eA", T_STR },
+ { "XC", T_STR },
+
+/* keycaps */
+/* define T_CAPS */
+
+/* mouse */
+ { "Km", T_STR }, KMAPDEF("\033[M") KMAPMDEF("\222")
+
+/* nolist */
+ { "k0", T_STR }, KMAPDEF("\033[10~")
+ { "k1", T_STR }, KMAPDEF("\033OP")
+ { "k2", T_STR }, KMAPDEF("\033OQ")
+ { "k3", T_STR }, KMAPDEF("\033OR")
+ { "k4", T_STR }, KMAPDEF("\033OS")
+ { "k5", T_STR }, KMAPDEF("\033[15~")
+ { "k6", T_STR }, KMAPDEF("\033[17~")
+ { "k7", T_STR }, KMAPDEF("\033[18~")
+ { "k8", T_STR }, KMAPDEF("\033[19~")
+ { "k9", T_STR }, KMAPDEF("\033[20~")
+ { "k;", T_STR }, KMAPDEF("\033[21~")
+ { "F1", T_STR }, KMAPDEF("\033[23~")
+ { "F2", T_STR }, KMAPDEF("\033[24~")
+ /* extra keys for vt220 (David.Leonard@it.uq.edu.au) */
+ { "F3", T_STR },
+ { "F4", T_STR },
+ { "F5", T_STR },
+ { "F6", T_STR },
+ { "F7", T_STR },
+ { "F8", T_STR },
+ { "F9", T_STR },
+ { "FA", T_STR },
+ { "FB", T_STR },
+ { "FC", T_STR },
+ { "FD", T_STR },
+ { "FE", T_STR },
+
+ { "kb", T_STR },
+ { "K1", T_STR },
+ { "K2", T_STR },
+ { "K3", T_STR },
+ { "K4", T_STR },
+ { "K5", T_STR },
+/* more keys for Andrew A. Chernov (ache@astral.msk.su) */
+ { "kA", T_STR },
+ { "ka", T_STR },
+/* define T_BACKTAB */
+ { "kB", T_STR },
+ { "kC", T_STR },
+ { "kE", T_STR },
+ { "kF", T_STR }, KMAPMDEF("\004")
+ { "kL", T_STR },
+ { "kM", T_STR },
+ { "kR", T_STR }, KMAPMDEF("\025")
+ { "kS", T_STR },
+ { "kT", T_STR },
+ { "kt", T_STR },
+ { "*4", T_STR }, /* kDC */
+ { "*7", T_STR }, /* kEND */
+ { "#2", T_STR }, /* kHOM */
+ { "#3", T_STR }, /* kIC */
+ { "#4", T_STR }, /* kLFT */
+ { "%c", T_STR }, /* kNXT */
+ { "%e", T_STR }, /* kPRV */
+ { "%i", T_STR }, /* kRIT */
+
+/* keys above the cursor */
+/* define T_NAVIGATE */
+ { "kh", T_STR }, KMAPDEF("\033[1~") KMAPMDEF("\201")
+ { "@1", T_STR },
+ { "kH", T_STR }, KMAPDEF("\033[4~") KMAPMDEF("\205")
+ { "@7", T_STR }, KMAPDEF("\033[4~") KMAPMDEF("\205")
+ { "kN", T_STR }, KMAPDEF("\033[6~") KMAPMDEF("\006")
+ { "kP", T_STR }, KMAPDEF("\033[5~") KMAPMDEF("\002")
+ { "kI", T_STR }, KMAPDEF("\033[2~")
+/* define T_NAVIGATE_DELETE */
+ { "kD", T_STR }, KMAPDEF("\033[3~")
+
+/* keys that can have two bindings */
+/* define T_CURSOR */
+ { "ku", T_STR }, KMAPDEF("\033[A") KMAPADEF("\033OA") KMAPMDEF("\220")
+ { "kd", T_STR }, KMAPDEF("\033[B") KMAPADEF("\033OB") KMAPMDEF("\216")
+ { "kr", T_STR }, KMAPDEF("\033[C") KMAPADEF("\033OC") KMAPMDEF("\206")
+ { "kl", T_STR }, KMAPDEF("\033[D") KMAPADEF("\033OD") KMAPMDEF("\202")
+/* define T_KEYPAD */
+ { "f0", T_STR }, KMAPDEF("0") KMAPADEF("\033Op")
+ { "f1", T_STR }, KMAPDEF("1") KMAPADEF("\033Oq")
+ { "f2", T_STR }, KMAPDEF("2") KMAPADEF("\033Or")
+ { "f3", T_STR }, KMAPDEF("3") KMAPADEF("\033Os")
+ { "f4", T_STR }, KMAPDEF("4") KMAPADEF("\033Ot")
+ { "f5", T_STR }, KMAPDEF("5") KMAPADEF("\033Ou")
+ { "f6", T_STR }, KMAPDEF("6") KMAPADEF("\033Ov")
+ { "f7", T_STR }, KMAPDEF("7") KMAPADEF("\033Ow")
+ { "f8", T_STR }, KMAPDEF("8") KMAPADEF("\033Ox")
+ { "f9", T_STR }, KMAPDEF("9") KMAPADEF("\033Oy")
+ { "f+", T_STR }, KMAPDEF("+") KMAPADEF("\033Ok")
+ { "f-", T_STR }, KMAPDEF("-") KMAPADEF("\033Om")
+ { "f*", T_STR }, KMAPDEF("*") KMAPADEF("\033Oj")
+ { "f/", T_STR }, KMAPDEF("/") KMAPADEF("\033Oo")
+ { "fq", T_STR }, KMAPDEF("=") KMAPADEF("\033OX")
+ { "f.", T_STR }, KMAPDEF(".") KMAPADEF("\033On")
+ { "f,", T_STR }, KMAPDEF(",") KMAPADEF("\033Ol")
+ { "fe", T_STR }, KMAPDEF("\015") KMAPADEF("\033OM")
+/* other things related to keycaps */
+/* define T_OCAPS */
+ { "km", T_FLG },
+ { "ko", T_STR },
+ { "l0", T_STR },
+ { "l1", T_STR },
+ { "l2", T_STR },
+ { "l3", T_STR },
+ { "l4", T_STR },
+ { "l5", T_STR },
+ { "l6", T_STR },
+ { "l7", T_STR },
+ { "l8", T_STR },
+ { "l9", T_STR },
+ { "la", T_STR },
+/* list */
+/* define T_ECAPS */
+/* define T_N */
+};
diff --git a/term.sh b/term.sh
new file mode 100644
index 0000000..f5dfc4a
--- /dev/null
+++ b/term.sh
@@ -0,0 +1,169 @@
+#! /bin/sh
+
+if test -z "$AWK"; then
+ AWK=awk
+fi
+if test -z "$srcdir"; then
+ srcdir=.
+fi
+
+LC_ALL=C
+export LC_ALL
+
+rm -f term.h
+cat << EOF > term.h
+/*
+ * This file is automagically created from term.c -- DO NOT EDIT
+ */
+
+#define T_FLG 0
+#define T_NUM 1
+#define T_STR 2
+
+struct term
+{
+ char *tcname;
+ int type;
+};
+
+union tcu
+{
+ int flg;
+ int num;
+ char *str;
+};
+
+EOF
+
+#
+# SCO-Unix sufferers may need to use the following lines:
+# perl -p < ${srcdir}/term.c \
+# -e 's/"/"C/ if /"[A-Z]."/;' \
+# -e 'y/[a-z]/[A-Z]/ if /"/;' \
+#
+sed < ${srcdir}/term.c \
+ -e '/"[A-Z]."/s/"/"C/' \
+ -e '/"/y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \
+| $AWK '
+/^ [{] ".*KMAPDEF[(].*$/{
+ if (min == 0) min = s
+ max = s;
+}
+/^ [{] ".*KMAPADEF[(].*$/{
+ if (amin == 0) amin = s
+ amax = s;
+}
+/^ [{] ".*KMAPMDEF[(].*$/{
+ if (mmin == 0) mmin = s
+ mmax = s;
+}
+/^ [{] ".*$/{
+a=substr($2,2,length($2)-3);
+b=substr($3,3,3);
+if (nolist == 0) {
+ printf "#define d_%s d_tcs[%d].%s\n",a,s,b
+ printf "#define D_%s (D_tcs[%d].%s)\n",a,s,b
+ }
+s++;
+}
+/\/* define/{
+printf "#define %s %d\n",$3,s
+}
+/\/* nolist/{
+nolist = 1;
+}
+/\/* list/{
+nolist = 0;
+}
+END {
+ printf "\n#ifdef MAPKEYS\n"
+ printf "# define KMAPDEFSTART %d\n", min
+ printf "# define NKMAPDEF %d\n", max-min+1
+ printf "# define KMAPADEFSTART %d\n", amin
+ printf "# define NKMAPADEF %d\n", amax-amin+1
+ printf "# define KMAPMDEFSTART %d\n", mmin
+ printf "# define NKMAPMDEF %d\n", mmax-mmin+1
+ printf "#endif\n"
+}
+' | sed -e s/NUM/num/ -e s/STR/str/ -e s/FLG/flg/ \
+>> term.h
+
+rm -f kmapdef.c
+cat << EOF > kmapdef.c
+/*
+ * This file is automagically created from term.c -- DO NOT EDIT
+ */
+
+#include "config.h"
+
+#ifdef MAPKEYS
+
+EOF
+
+$AWK < ${srcdir}/term.c '
+/^ [{] ".*KMAP.*$/{
+ for (i = 0; i < 3; i++) {
+ q = $(5+i)
+ if (substr(q, 1, 5) == "KMAPD") {
+ if (min == 0) min = s
+ max = s
+ arr[s] = substr(q, 9, length(q)-9)
+ }
+ if (substr(q, 1, 5) == "KMAPA") {
+ if (amin == 0) amin = s
+ amax = s
+ anarr[s] = substr(q, 10, length(q)-10)
+ }
+ if (substr(q, 1, 5) == "KMAPM") {
+ if (mmin == 0) mmin = s
+ mmax = s
+ mnarr[s] = substr(q, 10, length(q)-10)
+ }
+ }
+}
+/^ [{] ".*$/{
+ s++;
+}
+END {
+ printf "char *kmapdef[] = {\n"
+ for (s = min; s <= max; s++) {
+ if (arr[s])
+ printf "%s", arr[s]
+ else
+ printf "0"
+ if (s < max)
+ printf ",\n"
+ else
+ printf "\n"
+ }
+ printf "};\n\n"
+ printf "char *kmapadef[] = {\n"
+ for (s = amin; s <= amax; s++) {
+ if (anarr[s])
+ printf "%s", anarr[s]
+ else
+ printf "0"
+ if (s < amax)
+ printf ",\n"
+ else
+ printf "\n"
+ }
+ printf "};\n\n"
+ printf "char *kmapmdef[] = {\n"
+ for (s = mmin; s <= mmax; s++) {
+ if (mnarr[s])
+ printf "%s", mnarr[s]
+ else
+ printf "0"
+ if (s < mmax)
+ printf ",\n"
+ else
+ printf "\n"
+ }
+ printf "};\n\n#endif\n"
+}
+' >> kmapdef.c
+
+chmod a-w kmapdef.c
+chmod a-w term.h
+
diff --git a/termcap.c b/termcap.c
new file mode 100644
index 0000000..1190960
--- /dev/null
+++ b/termcap.c
@@ -0,0 +1,1514 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+#include "config.h"
+#include "screen.h"
+#include "extern.h"
+
+extern struct display *display, *displays;
+extern int real_uid, real_gid, eff_uid, eff_gid;
+extern struct term term[]; /* terminal capabilities */
+extern struct NewWindow nwin_undef, nwin_default, nwin_options;
+extern int force_vt;
+extern int hardstatusemu;
+#ifdef MAPKEYS
+extern struct action umtab[];
+extern struct action mmtab[];
+extern struct action dmtab[];
+extern struct action ktab[];
+extern struct kmap_ext *kmap_exts;
+extern int kmap_extn;
+extern int DefaultEsc;
+#endif
+
+
+static void AddCap __P((char *));
+static void MakeString __P((char *, char *, int, char *));
+static char *findcap __P((char *, char **, int));
+static int copyarg __P((char **, char *));
+static int e_tgetent __P((char *, char *));
+static char *e_tgetstr __P((char *, char **));
+static int e_tgetflag __P((char *));
+static int e_tgetnum __P((char *));
+#ifdef MAPKEYS
+static int findseq_ge __P((char *, int, unsigned char **));
+static void setseqoff __P((unsigned char *, int, int));
+static int addmapseq __P((char *, int, int));
+static int remmapseq __P((char *, int));
+#ifdef DEBUGG
+static void dumpmap __P((void));
+#endif
+#endif
+
+
+char Termcap[TERMCAP_BUFSIZE + 8]; /* new termcap +8:"TERMCAP=" */
+static int Termcaplen;
+static int tcLineLen;
+char Term[MAXSTR+5]; /* +5: "TERM=" */
+char screenterm[MAXTERMLEN + 1]; /* new $TERM, usually "screen" */
+
+char *extra_incap, *extra_outcap;
+
+static const char TermcapConst[] = "\\\n\
+\t:DO=\\E[%dB:LE=\\E[%dD:RI=\\E[%dC:UP=\\E[%dA:bs:bt=\\E[Z:\\\n\
+\t:cd=\\E[J:ce=\\E[K:cl=\\E[H\\E[J:cm=\\E[%i%d;%dH:ct=\\E[3g:\\\n\
+\t:do=^J:nd=\\E[C:pt:rc=\\E8:rs=\\Ec:sc=\\E7:st=\\EH:up=\\EM:\\\n\
+\t:le=^H:bl=^G:cr=^M:it#8:ho=\\E[H:nw=\\EE:ta=^I:is=\\E)0:";
+
+char *
+gettermcapstring(s)
+char *s;
+{
+ int i;
+
+ if (display == 0 || s == 0)
+ return 0;
+ for (i = 0; i < T_N; i++)
+ {
+ if (term[i].type != T_STR)
+ continue;
+ if (strcmp(term[i].tcname, s) == 0)
+ return D_tcs[i].str;
+ }
+ return 0;
+}
+
+/*
+ * Compile the terminal capabilities for a display.
+ * Input: tgetent(, D_termname) extra_incap, extra_outcap.
+ * Effect: display initialisation.
+ */
+int
+InitTermcap(wi, he)
+int wi;
+int he;
+{
+ register char *s;
+ int i;
+ char tbuf[TERMCAP_BUFSIZE], *tp;
+ int t, xue, xse, xme;
+
+ ASSERT(display);
+ bzero(tbuf, sizeof(tbuf));
+ debug1("InitTermcap: looking for tgetent('%s')\n", D_termname);
+ if (*D_termname == 0 || e_tgetent(tbuf, D_termname) != 1)
+ {
+#ifdef TERMINFO
+ Msg(0, "Cannot find terminfo entry for '%s'.", D_termname);
+#else
+ Msg(0, "Cannot find termcap entry for '%s'.", D_termname);
+#endif
+ return -1;
+ }
+ debug1("got it:\n%s\n", tbuf);
+#ifdef DEBUG
+ if (extra_incap)
+ debug1("Extra incap: %s\n", extra_incap);
+ if (extra_outcap)
+ debug1("Extra outcap: %s\n", extra_outcap);
+#endif
+
+ if ((D_tentry = (char *)malloc(TERMCAP_BUFSIZE + (extra_incap ? strlen(extra_incap) + 1 : 0))) == 0)
+ {
+ Msg(0, "%s", strnomem);
+ return -1;
+ }
+
+ /*
+ * loop through all needed capabilities, record their values in the display
+ */
+ tp = D_tentry;
+ for (i = 0; i < T_N; i++)
+ {
+ switch(term[i].type)
+ {
+ case T_FLG:
+ D_tcs[i].flg = e_tgetflag(term[i].tcname);
+ break;
+ case T_NUM:
+ D_tcs[i].num = e_tgetnum(term[i].tcname);
+ break;
+ case T_STR:
+ D_tcs[i].str = e_tgetstr(term[i].tcname, &tp);
+ /* no empty strings, please */
+ if (D_tcs[i].str && *D_tcs[i].str == 0)
+ D_tcs[i].str = 0;
+ break;
+ default:
+ Panic(0, "Illegal tc type in entry #%d", i);
+ /*NOTREACHED*/
+ }
+ }
+
+ /*
+ * Now a good deal of sanity checks on the retrieved capabilities.
+ */
+ if (D_HC)
+ {
+ Msg(0, "You can't run screen on a hardcopy terminal.");
+ return -1;
+ }
+ if (D_OS)
+ {
+ Msg(0, "You can't run screen on a terminal that overstrikes.");
+ return -1;
+ }
+ if (!D_CL)
+ {
+ Msg(0, "Clear screen capability required.");
+ return -1;
+ }
+ if (!D_CM)
+ {
+ Msg(0, "Addressable cursor capability required.");
+ return -1;
+ }
+ if ((s = getenv("COLUMNS")) && (i = atoi(s)) > 0)
+ D_CO = i;
+ if ((s = getenv("LINES")) && (i = atoi(s)) > 0)
+ D_LI = i;
+ if (wi)
+ D_CO = wi;
+ if (he)
+ D_LI = he;
+ if (D_CO <= 0)
+ D_CO = 80;
+ if (D_LI <= 0)
+ D_LI = 24;
+
+ if (D_CTF)
+ {
+ /* standard fixes for xterms etc */
+ /* assume color for everything that looks ansi-compatible */
+ if (!D_CAF && D_ME && (InStr(D_ME, "\033[m") || InStr(D_ME, "\033[0m")))
+ {
+#ifdef TERMINFO
+ D_CAF = "\033[3%p1%dm";
+ D_CAB = "\033[4%p1%dm";
+#else
+ D_CAF = "\033[3%dm";
+ D_CAB = "\033[4%dm";
+#endif
+ }
+ if (D_OP && InStr(D_OP, "\033[39;49m"))
+ D_CAX = 1;
+ if (D_OP && (InStr(D_OP, "\033[m") || InStr(D_OP, "\033[0m")))
+ D_OP = 0;
+ /* ISO2022 */
+ if ((D_EA && InStr(D_EA, "\033(B")) || (D_AS && InStr(D_AS, "\033(0")))
+ D_CG0 = 1;
+ if (InStr(D_termname, "xterm") || InStr(D_termname, "rxvt") ||
+ (D_CKM && InStr(D_CKM, "\033[M")))
+ D_CXT = 1;
+ /* "be" seems to be standard for xterms... */
+ if (D_CXT)
+ D_BE = 1;
+ }
+ if (nwin_options.flowflag == nwin_undef.flowflag)
+ nwin_default.flowflag = D_CNF ? FLOW_NOW * 0 :
+ D_NX ? FLOW_NOW * 1 :
+ FLOW_AUTOFLAG;
+ D_CLP |= (!D_AM || D_XV || D_XN);
+ if (!D_BL)
+ D_BL = "\007";
+ if (!D_BC)
+ {
+ if (D_BS)
+ D_BC = "\b";
+ else
+ D_BC = D_LE;
+ }
+ if (!D_CR)
+ D_CR = "\r";
+ if (!D_NL)
+ D_NL = "\n";
+
+ /*
+ * Set up attribute handling.
+ * This is rather complicated because termcap has different
+ * attribute groups.
+ */
+
+ if (D_UG > 0)
+ D_US = D_UE = 0;
+ if (D_SG > 0)
+ D_SO = D_SE = 0;
+ /* Unfortunately there is no 'mg' capability.
+ * For now we think that mg > 0 if sg and ug > 0.
+ */
+ if (D_UG > 0 && D_SG > 0)
+ D_MH = D_MD = D_MR = D_MB = D_ME = 0;
+
+ xue = ATYP_U;
+ xse = ATYP_S;
+ xme = ATYP_M;
+
+ if (D_SO && D_SE == 0)
+ {
+ Msg(0, "Warning: 'so' but no 'se' capability.");
+ if (D_ME)
+ xse = xme;
+ else
+ D_SO = 0;
+ }
+ if (D_US && D_UE == 0)
+ {
+ Msg(0, "Warning: 'us' but no 'ue' capability.");
+ if (D_ME)
+ xue = xme;
+ else
+ D_US = 0;
+ }
+ if ((D_MH || D_MD || D_MR || D_MB) && D_ME == 0)
+ {
+ Msg(0, "Warning: 'm?' but no 'me' capability.");
+ D_MH = D_MD = D_MR = D_MB = 0;
+ }
+ /*
+ * Does ME also reverse the effect of SO and/or US? This is not
+ * clearly specified by the termcap manual. Anyway, we should at
+ * least look whether ME and SE/UE are equal:
+ */
+ if (D_UE && D_SE && strcmp(D_SE, D_UE) == 0)
+ xse = xue;
+ if (D_SE && D_ME && strcmp(D_ME, D_SE) == 0)
+ xse = xme;
+ if (D_UE && D_ME && strcmp(D_ME, D_UE) == 0)
+ xue = xme;
+
+ for (i = 0; i < NATTR; i++)
+ {
+ D_attrtab[i] = D_tcs[T_ATTR + i].str;
+ D_attrtyp[i] = i == ATTR_SO ? xse : (i == ATTR_US ? xue : xme);
+ }
+
+ /* Set up missing entries (attributes are priority ordered) */
+ s = 0;
+ t = 0;
+ for (i = 0; i < NATTR; i++)
+ if ((s = D_attrtab[i]))
+ {
+ t = D_attrtyp[i];
+ break;
+ }
+ for (i = 0; i < NATTR; i++)
+ {
+ if (D_attrtab[i] == 0)
+ {
+ D_attrtab[i] = s;
+ D_attrtyp[i] = t;
+ }
+ else
+ {
+ s = D_attrtab[i];
+ t = D_attrtyp[i];
+ }
+ }
+ if (D_CAF || D_CAB || D_CSF || D_CSB)
+ D_hascolor = 1;
+ if (D_UT)
+ D_BE = 1; /* screen erased with background color */
+
+ if (!D_DO)
+ D_DO = D_NL;
+ if (!D_SF)
+ D_SF = D_NL;
+ if (D_IN)
+ D_IC = D_IM = 0;
+ if (D_EI == 0)
+ D_IM = 0;
+ /* some strange termcap entries have IC == IM */
+ if (D_IC && D_IM && strcmp(D_IC, D_IM) == 0)
+ D_IC = 0;
+ if (D_KE == 0)
+ D_KS = 0;
+ if (D_CVN == 0)
+ D_CVR = 0;
+ if (D_VE == 0)
+ D_VI = D_VS = 0;
+ if (D_CCE == 0)
+ D_CCS = 0;
+
+#ifdef FONT
+ if (D_CG0)
+ {
+ if (D_CS0 == 0)
+#ifdef TERMINFO
+ D_CS0 = "\033(%p1%c";
+#else
+ D_CS0 = "\033(%.";
+#endif
+ if (D_CE0 == 0)
+ D_CE0 = "\033(B";
+ D_AC = 0;
+ D_EA = 0;
+ }
+ else if (D_AC || (D_AS && D_AE)) /* some kind of graphics */
+ {
+ D_CS0 = (D_AS && D_AE) ? D_AS : "";
+ D_CE0 = (D_AS && D_AE) ? D_AE : "";
+ D_CC0 = D_AC;
+ }
+ else
+ {
+ D_CS0 = D_CE0 = "";
+ D_CC0 = 0;
+ D_AC = ""; /* enable default string */
+ }
+
+ for (i = 0; i < 256; i++)
+ D_c0_tab[i] = i;
+ if (D_AC)
+ {
+ /* init with default string first */
+ s = "l+m+k+j+u+t+v+w+q-x|n+o~s_p\"r#`+a:f'g#~o.v-^+<,>h#I#0#y<z>";
+ for (i = (strlen(s) - 2) & ~1; i >= 0; i -= 2)
+ D_c0_tab[(int)(unsigned char)s[i]] = s[i + 1];
+ }
+ if (D_CC0)
+ for (i = (strlen(D_CC0) - 2) & ~1; i >= 0; i -= 2)
+ D_c0_tab[(int)(unsigned char)D_CC0[i]] = D_CC0[i + 1];
+ debug1("ISO2022 = %d\n", D_CG0);
+#endif /* FONT */
+ if (D_PF == 0)
+ D_PO = 0;
+ debug2("terminal size is %d, %d (says TERMCAP)\n", D_CO, D_LI);
+
+#ifdef FONT
+ if (D_CXC)
+ if (CreateTransTable(D_CXC))
+ return -1;
+#endif
+
+ /* Termcap fields Z0 & Z1 contain width-changing sequences. */
+ if (D_CZ1 == 0)
+ D_CZ0 = 0;
+
+ CheckScreenSize(0);
+
+ if (D_TS == 0 || D_FS == 0 || D_DS == 0)
+ D_HS = 0;
+ if (D_HS)
+ {
+ debug("oy! we have a hardware status line, says termcap\n");
+ if (D_WS < 0)
+ D_WS = 0;
+ }
+ D_has_hstatus = hardstatusemu & ~HSTATUS_ALWAYS;
+ if (D_HS && !(hardstatusemu & HSTATUS_ALWAYS))
+ D_has_hstatus = HSTATUS_HS;
+
+#ifdef ENCODINGS
+ if (D_CKJ)
+ {
+ int enc = FindEncoding(D_CKJ);
+ if (enc != -1)
+ D_encoding = enc;
+ }
+#endif
+ if (!D_tcs[T_NAVIGATE].str && D_tcs[T_NAVIGATE + 1].str)
+ D_tcs[T_NAVIGATE].str = D_tcs[T_NAVIGATE + 1].str; /* kh = @1 */
+ if (!D_tcs[T_NAVIGATE + 2].str && D_tcs[T_NAVIGATE + 3].str)
+ D_tcs[T_NAVIGATE + 2].str = D_tcs[T_NAVIGATE + 3].str; /* kH = @7 */
+
+ D_UPcost = CalcCost(D_UP);
+ D_DOcost = CalcCost(D_DO);
+ D_NLcost = CalcCost(D_NL);
+ D_LEcost = CalcCost(D_BC);
+ D_NDcost = CalcCost(D_ND);
+ D_CRcost = CalcCost(D_CR);
+ D_IMcost = CalcCost(D_IM);
+ D_EIcost = CalcCost(D_EI);
+
+#ifdef AUTO_NUKE
+ if (D_CAN)
+ {
+ debug("termcap has AN, setting autonuke\n");
+ D_auto_nuke = 1;
+ }
+#endif
+ if (D_COL > 0)
+ {
+ debug1("termcap has OL (%d), setting limit\n", D_COL);
+ D_obufmax = D_COL;
+ D_obuflenmax = D_obuflen - D_obufmax;
+ }
+
+ /* Some xterm entries set F0 and F10 to the same string. Nuke F0. */
+ if (D_tcs[T_CAPS].str && D_tcs[T_CAPS + 10].str && !strcmp(D_tcs[T_CAPS].str, D_tcs[T_CAPS + 10].str))
+ D_tcs[T_CAPS].str = 0;
+ /* Some xterm entries set kD to ^?. Nuke it. */
+ if (D_tcs[T_NAVIGATE_DELETE].str && !strcmp(D_tcs[T_NAVIGATE_DELETE].str, "\0177"))
+ D_tcs[T_NAVIGATE_DELETE].str = 0;
+ /* wyse52 entries have kcub1 == kb == ^H. Nuke... */
+ if (D_tcs[T_CURSOR + 3].str && !strcmp(D_tcs[T_CURSOR + 3].str, "\008"))
+ D_tcs[T_CURSOR + 3].str = 0;
+
+#ifdef MAPKEYS
+ D_nseqs = 0;
+ for (i = 0; i < T_OCAPS - T_CAPS; i++)
+ remap(i, 1);
+ for (i = 0; i < kmap_extn; i++)
+ remap(i + (KMAP_KEYS+KMAP_AKEYS), 1);
+ D_seqp = D_kmaps + 3;
+ D_seql = 0;
+ D_seqh = 0;
+#endif
+
+ D_tcinited = 1;
+ MakeTermcap(0);
+ /* Make sure libterm uses external term properties for our tputs() calls. */
+ e_tgetent(tbuf, D_termname);
+#ifdef MAPKEYS
+ CheckEscape();
+#endif
+ return 0;
+}
+
+#ifdef MAPKEYS
+
+int
+remap(n, map)
+int n;
+int map;
+{
+ char *s = 0;
+ int fl = 0, domap = 0;
+ struct action *a1, *a2, *tab;
+ int l = 0;
+ struct kmap_ext *kme = 0;
+
+ a1 = 0;
+ if (n >= KMAP_KEYS+KMAP_AKEYS)
+ {
+ kme = kmap_exts + (n - (KMAP_KEYS+KMAP_AKEYS));
+ s = kme->str;
+ l = kme->fl & ~KMAP_NOTIMEOUT;
+ fl = kme->fl & KMAP_NOTIMEOUT;
+ a1 = &kme->um;
+ }
+ tab = umtab;
+ for (;;)
+ {
+ a2 = 0;
+ if (n < KMAP_KEYS+KMAP_AKEYS)
+ {
+ a1 = &tab[n];
+ if (n >= KMAP_KEYS)
+ n -= T_OCAPS-T_CURSOR;
+ s = D_tcs[n + T_CAPS].str;
+ l = s ? strlen(s) : 0;
+ if (n >= T_CURSOR-T_CAPS)
+ a2 = &tab[n + (T_OCAPS-T_CURSOR)];
+ }
+ if (s == 0 || l == 0)
+ return 0;
+ if (a1 && a1->nr == RC_ILLEGAL)
+ a1 = 0;
+ if (a2 && a2->nr == RC_ILLEGAL)
+ a2 = 0;
+ if (a1 && a1->nr == RC_STUFF && a1->args[0] && strcmp(a1->args[0], s) == 0)
+ a1 = 0;
+ if (a2 && a2->nr == RC_STUFF && a2->args[0] && strcmp(a2->args[0], s) == 0)
+ a2 = 0;
+ domap |= (a1 || a2);
+ if (tab == umtab)
+ {
+ tab = dmtab;
+ a1 = kme ? &kme->dm : 0;
+ }
+ else if (tab == dmtab)
+ {
+ tab = mmtab;
+ a1 = kme ? &kme->mm : 0;
+ }
+ else
+ break;
+ }
+ if (n < KMAP_KEYS)
+ domap = 1;
+ if (map == 0 && domap)
+ return 0;
+ if (map && !domap)
+ return 0;
+ debug3("%smapping %s %#x\n", map? "" :"un",s,n);
+ if (map)
+ return addmapseq(s, l, n | fl);
+ else
+ return remmapseq(s, l);
+}
+
+void
+CheckEscape()
+{
+ struct display *odisplay;
+ int i, nr;
+
+ if (DefaultEsc >= 0)
+ return;
+
+ odisplay = display;
+ for (display = displays; display; display = display->d_next)
+ {
+ for (i = 0; i < D_nseqs; i += D_kmaps[i + 2] * 2 + 4)
+ {
+ nr = (D_kmaps[i] << 8 | D_kmaps[i + 1]) & ~KMAP_NOTIMEOUT;
+ if (nr < KMAP_KEYS+KMAP_AKEYS)
+ {
+ if (umtab[nr].nr == RC_COMMAND)
+ break;
+ if (umtab[nr].nr == RC_ILLEGAL && dmtab[nr].nr == RC_COMMAND)
+ break;
+ }
+ else
+ {
+ struct kmap_ext *kme = kmap_exts + nr - (KMAP_KEYS+KMAP_AKEYS);
+ if (kme->um.nr == RC_COMMAND)
+ break;
+ if (kme->um.nr == RC_ILLEGAL && kme->dm.nr == RC_COMMAND)
+ break;
+ }
+ }
+ }
+ if (display == 0)
+ {
+ display = odisplay;
+ return;
+ }
+ SetEscape((struct acluser *)0, Ctrl('a'), 'a');
+ if (odisplay->d_user->u_Esc == -1)
+ odisplay->d_user->u_Esc = DefaultEsc;
+ if (odisplay->d_user->u_MetaEsc == -1)
+ odisplay->d_user->u_MetaEsc = DefaultMetaEsc;
+ display = 0;
+ Msg(0, "Warning: escape char set back to ^A");
+ display = odisplay;
+}
+
+static int
+findseq_ge(seq, k, sp)
+char *seq;
+int k;
+unsigned char **sp;
+{
+ unsigned char *p;
+ int j, l;
+
+ p = D_kmaps;
+ while (p - D_kmaps < D_nseqs)
+ {
+ l = p[2];
+ p += 3;
+ for (j = 0; ; j++)
+ {
+ if (j == k || j == l)
+ j = l - k;
+ else if (p[j] != ((unsigned char *)seq)[j])
+ j = p[j] - ((unsigned char *)seq)[j];
+ else
+ continue;
+ break;
+ }
+ if (j >= 0)
+ {
+ *sp = p - 3;
+ return j;
+ }
+ p += 2 * l + 1;
+ }
+ *sp = p;
+ return -1;
+}
+
+static void
+setseqoff(p, i, o)
+unsigned char *p;
+int i;
+int o;
+{
+ unsigned char *q;
+ int l, k;
+
+ k = p[2];
+ if (o < 256)
+ {
+ p[k + 4 + i] = o;
+ return;
+ }
+ /* go for the biggest offset */
+ for (q = p + k * 2 + 4; ; q += l * 2 + 4)
+ {
+ l = q[2];
+ if ((q + l * 2 - p) / 2 >= 256)
+ {
+ p[k + 4 + i] = (q - p - 4) / 2;
+ return;
+ }
+ }
+}
+
+static int
+addmapseq(seq, k, nr)
+char *seq;
+int k;
+int nr;
+{
+ int i, j, l, mo, m;
+ unsigned char *p, *q;
+
+ if (k >= 254)
+ return -1;
+ j = findseq_ge(seq, k, &p);
+ if (j == 0)
+ {
+ p[0] = nr >> 8;
+ p[1] = nr;
+ return 0;
+ }
+ i = p - D_kmaps;
+ if (D_nseqs + 2 * k + 4 >= D_aseqs)
+ {
+ D_kmaps = (unsigned char *)xrealloc((char *)D_kmaps, D_aseqs + 256);
+ D_aseqs += 256;
+ p = D_kmaps + i;
+ }
+ D_seqp = D_kmaps + 3;
+ D_seql = 0;
+ D_seqh = 0;
+ evdeq(&D_mapev);
+ if (j > 0)
+ bcopy((char *)p, (char *)p + 2 * k + 4, D_nseqs - i);
+ p[0] = nr >> 8;
+ p[1] = nr;
+ p[2] = k;
+ bcopy(seq, (char *)p + 3, k);
+ bzero(p + k + 3, k + 1);
+ D_nseqs += 2 * k + 4;
+ if (j > 0)
+ {
+ q = p + 2 * k + 4;
+ l = q[2];
+ for (i = 0; i < k; i++)
+ {
+ if (p[3 + i] != q[3 + i])
+ {
+ p[k + 4 + i] = k;
+ break;
+ }
+ setseqoff(p, i, q[l + 4 + i] ? q[l + 4 + i] + k + 2: 0);
+ }
+ }
+ for (q = D_kmaps; q < p; q += 2 * l + 4)
+ {
+ l = q[2];
+ for (m = j = 0; j < l; j++)
+ {
+ mo = m;
+ if (!m && q[3 + j] != seq[j])
+ m = 1;
+ if (q[l + 4 + j] == 0)
+ {
+ if (!mo && m)
+ setseqoff(q, j, (p - q - 4) / 2);
+ }
+ else if (q + q[l + 4 + j] * 2 + 4 > p || (q + q[l + 4 + j] * 2 + 4 == p && !m))
+ setseqoff(q, j, q[l + 4 + j] + k + 2);
+ }
+ }
+#ifdef DEBUGG
+ dumpmap();
+#endif
+ return 0;
+}
+
+static int
+remmapseq(seq, k)
+char *seq;
+int k;
+{
+ int j, l;
+ unsigned char *p, *q;
+
+ if (k >= 254 || (j = findseq_ge(seq, k, &p)) != 0)
+ return -1;
+ for (q = D_kmaps; q < p; q += 2 * l + 4)
+ {
+ l = q[2];
+ for (j = 0; j < l; j++)
+ {
+ if (q + q[l + 4 + j] * 2 + 4 == p)
+ setseqoff(q, j, p[k + 4 + j] ? q[l + 4 + j] + p[k + 4 + j] - k : 0);
+ else if (q + q[l + 4 + j] * 2 + 4 > p)
+ q[l + 4 + j] -= k + 2;
+ }
+ }
+ if (D_kmaps + D_nseqs > p + 2 * k + 4)
+ bcopy((char *)p + 2 * k + 4, (char *)p, (D_kmaps + D_nseqs) - (p + 2 * k + 4));
+ D_nseqs -= 2 * k + 4;
+ D_seqp = D_kmaps + 3;
+ D_seql = 0;
+ D_seqh = 0;
+ evdeq(&D_mapev);
+#ifdef DEBUGG
+ dumpmap();
+#endif
+ return 0;
+}
+
+#ifdef DEBUGG
+static void
+dumpmap()
+{
+ unsigned char *p;
+ int j, n, l, o, oo;
+ debug("Mappings:\n");
+ p = D_kmaps;
+ if (!p)
+ return;
+ while (p < D_kmaps + D_nseqs)
+ {
+ l = p[2];
+ debug1("%d: ", p - D_kmaps + 3);
+ for (j = 0; j < l; j++)
+ {
+ o = oo = p[l + 4 + j];
+ if (o)
+ o = 2 * o + 4 + (p + 3 + j - D_kmaps);
+ if (p[j + 3] > ' ' && p[j + 3] < 0177)
+ {
+ debug3("%c[%d:%d] ", p[j + 3], oo, o);
+ }
+ else
+ debug3("\\%03o[%d:%d] ", p[j + 3], oo, o);
+ }
+ n = p[0] << 8 | p[1];
+ debug2(" ==> %d%s\n", n & ~KMAP_NOTIMEOUT, (n & KMAP_NOTIMEOUT) ? " (no timeout)" : "");
+ p += 2 * l + 4;
+ }
+}
+#endif /* DEBUGG */
+
+#endif /* MAPKEYS */
+
+/*
+ * Appends to the static variable Termcap
+ */
+static void
+AddCap(s)
+char *s;
+{
+ register int n;
+
+ if (tcLineLen + (n = strlen(s)) > 55 && Termcaplen < TERMCAP_BUFSIZE - 4 - 1)
+ {
+ strcpy(Termcap + Termcaplen, "\\\n\t:");
+ Termcaplen += 4;
+ tcLineLen = 0;
+ }
+ if (Termcaplen + n < TERMCAP_BUFSIZE - 1)
+ {
+ strcpy(Termcap + Termcaplen, s);
+ Termcaplen += n;
+ tcLineLen += n;
+ }
+ else
+ Panic(0, "TERMCAP overflow - sorry.");
+}
+
+/*
+ * Reads a displays capabilities and reconstructs a termcap entry in the
+ * global buffer "Termcap". A pointer to this buffer is returned.
+ */
+char *
+MakeTermcap(aflag)
+int aflag;
+{
+ char buf[TERMCAP_BUFSIZE];
+ register char *p, *cp, *s, ch, *tname;
+ int i, wi, he;
+#if 0
+ int found;
+#endif
+
+ if (display)
+ {
+ wi = D_width;
+ he = D_height;
+ tname = D_termname;
+ }
+ else
+ {
+ wi = 80;
+ he = 24;
+ tname = "vt100";
+ }
+ debug1("MakeTermcap(%d)\n", aflag);
+ if ((s = getenv("SCREENCAP")) && strlen(s) < TERMCAP_BUFSIZE)
+ {
+ sprintf(Termcap, "TERMCAP=%s", s);
+ strcpy(Term, "TERM=screen");
+ debug("getenvSCREENCAP o.k.\n");
+ return Termcap;
+ }
+ Termcaplen = 0;
+ debug1("MakeTermcap screenterm='%s'\n", screenterm);
+ debug1("MakeTermcap termname='%s'\n", tname);
+ if (*screenterm == '\0' || strlen(screenterm) > MAXSTR - 3)
+ {
+ debug("MakeTermcap sets screenterm=screen\n");
+ strncpy(screenterm, "screen", MAXTERMLEN);
+ screenterm[MAXTERMLEN] = '\0';
+ }
+#if 0
+ found = 1;
+#endif
+ do
+ {
+ strcpy(Term, "TERM=");
+ p = Term + 5;
+ if (!aflag && strlen(screenterm) + strlen(tname) < MAXSTR-1)
+ {
+ sprintf(p, "%s.%s", screenterm, tname);
+ if (e_tgetent(buf, p) == 1)
+ break;
+ }
+#ifdef COLOR
+ if (nwin_default.bce)
+ {
+ sprintf(p, "%s-bce", screenterm);
+ if (e_tgetent(buf, p) == 1)
+ break;
+ }
+#endif
+#ifdef CHECK_SCREEN_W
+ if (wi >= 132)
+ {
+ sprintf(p, "%s-w", screenterm);
+ if (e_tgetent(buf, p) == 1)
+ break;
+ }
+#endif
+ strcpy(p, screenterm);
+ if (e_tgetent(buf, p) == 1)
+ break;
+ strcpy(p, "vt100");
+#if 0
+ found = 0;
+#endif
+ }
+ while (0); /* Goto free programming... */
+
+#if 0
+#ifndef TERMINFO
+ /* check for compatibility problems, displays == 0 after fork */
+ if (found)
+ {
+ char xbuf[TERMCAP_BUFSIZE], *xbp = xbuf;
+ if (tgetstr("im", &xbp) && tgetstr("ic", &xbp) && displays)
+ {
+ Msg(0, "Warning: im and ic set in %s termcap entry", p);
+ }
+ }
+#endif
+#endif
+
+ tcLineLen = 100; /* Force NL */
+ if (strlen(Term) > TERMCAP_BUFSIZE - 40)
+ strcpy(Term, "too_long");
+ sprintf(Termcap, "TERMCAP=SC|%s|VT 100/ANSI X3.64 virtual terminal:", Term + 5);
+ Termcaplen = strlen(Termcap);
+ debug1("MakeTermcap decided '%s'\n", p);
+ if (extra_outcap && *extra_outcap)
+ {
+ for (cp = extra_outcap; (p = index(cp, ':')); cp = p)
+ {
+ ch = *++p;
+ *p = '\0';
+ AddCap(cp);
+ *p = ch;
+ }
+ tcLineLen = 100; /* Force NL */
+ }
+ debug1("MakeTermcap after outcap '%s'\n", (char *)TermcapConst);
+ if (Termcaplen + strlen(TermcapConst) < TERMCAP_BUFSIZE)
+ {
+ strcpy(Termcap + Termcaplen, (char *)TermcapConst);
+ Termcaplen += strlen(TermcapConst);
+ }
+ sprintf(buf, "li#%d:co#%d:", he, wi);
+ AddCap(buf);
+ AddCap("am:");
+ if (aflag || (force_vt && !D_COP) || D_CLP || !D_AM)
+ {
+ AddCap("xn:");
+ AddCap("xv:");
+ AddCap("LP:");
+ }
+ if (aflag || (D_CS && D_SR) || D_AL || D_CAL)
+ {
+ AddCap("sr=\\EM:");
+ AddCap("al=\\E[L:");
+ AddCap("AL=\\E[%dL:");
+ }
+ else if (D_SR)
+ AddCap("sr=\\EM:");
+ if (aflag || D_CS)
+ AddCap("cs=\\E[%i%d;%dr:");
+ if (aflag || D_CS || D_DL || D_CDL)
+ {
+ AddCap("dl=\\E[M:");
+ AddCap("DL=\\E[%dM:");
+ }
+ if (aflag || D_DC || D_CDC)
+ {
+ AddCap("dc=\\E[P:");
+ AddCap("DC=\\E[%dP:");
+ }
+ if (aflag || D_CIC || D_IC || D_IM)
+ {
+ AddCap("im=\\E[4h:");
+ AddCap("ei=\\E[4l:");
+ AddCap("mi:");
+ AddCap("IC=\\E[%d@:");
+ }
+#ifdef MAPKEYS
+ AddCap("ks=\\E[?1h\\E=:");
+ AddCap("ke=\\E[?1l\\E>:");
+#endif
+ AddCap("vi=\\E[?25l:");
+ AddCap("ve=\\E[34h\\E[?25h:");
+ AddCap("vs=\\E[34l:");
+ AddCap("ti=\\E[?1049h:");
+ AddCap("te=\\E[?1049l:");
+ if (display)
+ {
+ if (D_US)
+ {
+ AddCap("us=\\E[4m:");
+ AddCap("ue=\\E[24m:");
+ }
+ if (D_SO)
+ {
+ AddCap("so=\\E[3m:");
+ AddCap("se=\\E[23m:");
+ }
+ if (D_MB)
+ AddCap("mb=\\E[5m:");
+ if (D_MD)
+ AddCap("md=\\E[1m:");
+ if (D_MH)
+ AddCap("mh=\\E[2m:");
+ if (D_MR)
+ AddCap("mr=\\E[7m:");
+ if (D_MB || D_MD || D_MH || D_MR)
+ AddCap("me=\\E[m:ms:");
+ if (D_hascolor)
+ AddCap("Co#8:pa#64:AF=\\E[3%dm:AB=\\E[4%dm:op=\\E[39;49m:AX:");
+ if (D_VB)
+ AddCap("vb=\\Eg:");
+#ifndef MAPKEYS
+ if (D_KS)
+ {
+ AddCap("ks=\\E=:");
+ AddCap("ke=\\E>:");
+ }
+ if (D_CCS)
+ {
+ AddCap("CS=\\E[?1h:");
+ AddCap("CE=\\E[?1l:");
+ }
+#endif
+ if (D_CG0)
+ AddCap("G0:");
+ if (D_CC0 || (D_CS0 && *D_CS0))
+ {
+ AddCap("as=\\E(0:");
+ AddCap("ae=\\E(B:");
+ /* avoid `` because some shells dump core... */
+ AddCap("ac=\\140\\140aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~..--++,,hhII00:");
+ }
+ if (D_PO)
+ {
+ AddCap("po=\\E[5i:");
+ AddCap("pf=\\E[4i:");
+ }
+ if (D_CZ0)
+ {
+ AddCap("Z0=\\E[?3h:");
+ AddCap("Z1=\\E[?3l:");
+ }
+ if (D_CWS)
+ AddCap("WS=\\E[8;%d;%dt:");
+ }
+ for (i = T_CAPS; i < T_ECAPS; i++)
+ {
+#ifdef MAPKEYS
+ struct action *act;
+ if (i < T_OCAPS)
+ {
+ if (i >= T_KEYPAD) /* don't put keypad codes in TERMCAP */
+ continue; /* - makes it too big */
+ if (i >= T_CURSOR && i < T_OCAPS)
+ {
+ act = &umtab[i - (T_CURSOR - T_OCAPS + T_CAPS)];
+ if (act->nr == RC_ILLEGAL)
+ act = &dmtab[i - (T_CURSOR - T_OCAPS + T_CAPS)];
+ }
+ else
+ {
+ act = &umtab[i - T_CAPS];
+ if (act->nr == RC_ILLEGAL)
+ act = &dmtab[i - T_CAPS];
+ }
+ if (act->nr == RC_ILLEGAL && (i == T_NAVIGATE + 1 || i == T_NAVIGATE + 3))
+ {
+ /* kh -> @1, kH -> @7 */
+ act = &umtab[i - T_CAPS - 1];
+ if (act->nr == RC_ILLEGAL)
+ act = &dmtab[i - T_CAPS - 1];
+ }
+ if (act->nr != RC_ILLEGAL)
+ {
+ if (act->nr == RC_STUFF)
+ {
+ MakeString(term[i].tcname, buf, sizeof(buf), act->args[0]);
+ AddCap(buf);
+ }
+ continue;
+ }
+ }
+#endif
+ if (display == 0)
+ continue;
+ switch(term[i].type)
+ {
+ case T_STR:
+ if (D_tcs[i].str == 0)
+ break;
+ MakeString(term[i].tcname, buf, sizeof(buf), D_tcs[i].str);
+ AddCap(buf);
+ break;
+ case T_FLG:
+ if (D_tcs[i].flg == 0)
+ break;
+ sprintf(buf, "%s:", term[i].tcname);
+ AddCap(buf);
+ break;
+ default:
+ break;
+ }
+ }
+ debug("MakeTermcap: end\n");
+ return Termcap;
+}
+
+static void
+MakeString(cap, buf, buflen, s)
+char *cap, *buf;
+int buflen;
+char *s;
+{
+ register char *p, *pmax;
+ register unsigned int c;
+
+ p = buf;
+ pmax = p + buflen - (3+4+2);
+ *p++ = *cap++;
+ *p++ = *cap;
+ *p++ = '=';
+ while ((c = *s++) && (p < pmax))
+ {
+ switch (c)
+ {
+ case '\033':
+ *p++ = '\\';
+ *p++ = 'E';
+ break;
+ case ':':
+ strcpy(p, "\\072");
+ p += 4;
+ break;
+ case '^':
+ case '\\':
+ *p++ = '\\';
+ *p++ = c;
+ break;
+ default:
+ if (c >= 200)
+ {
+ sprintf(p, "\\%03o", c & 0377);
+ p += 4;
+ }
+ else if (c < ' ')
+ {
+ *p++ = '^';
+ *p++ = c + '@';
+ }
+ else
+ *p++ = c;
+ }
+ }
+ *p++ = ':';
+ *p = '\0';
+}
+
+
+#undef QUOTES
+#define QUOTES(p) \
+ (*p == '\\' && (p[1] == '\\' || p[1] == ',' || p[1] == '%'))
+
+#ifdef FONT
+int
+CreateTransTable(s)
+char *s;
+{
+ int curchar;
+ char *templ, *arg;
+ int templlen;
+ int templnsub;
+ char *p, *sx;
+ char **ctable;
+ int l, c;
+
+ if ((D_xtable = (char ***)calloc(256, sizeof(char **))) == 0)
+ {
+ Msg(0, "%s", strnomem);
+ return -1;
+ }
+
+ while (*s)
+ {
+ if (QUOTES(s))
+ s++;
+ curchar = (unsigned char)*s++;
+ if (curchar == 'B')
+ curchar = 0; /* ASCII */
+ templ = s;
+ templlen = 0;
+ templnsub = 0;
+ if (D_xtable[curchar] == 0)
+ {
+ if ((D_xtable[curchar] = (char **)calloc(257, sizeof(char *))) == 0)
+ {
+ Msg(0, "%s", strnomem);
+ FreeTransTable();
+ return -1;
+ }
+ }
+ ctable = D_xtable[curchar];
+ for(; *s && *s != ','; s++)
+ {
+ if (QUOTES(s))
+ s++;
+ else if (*s == '%')
+ {
+ templnsub++;
+ continue;
+ }
+ templlen++;
+ }
+ if (*s++ == 0)
+ break;
+ while (*s && *s != ',')
+ {
+ c = (unsigned char)*s++;
+ if (QUOTES((s - 1)))
+ c = (unsigned char)*s++;
+ else if (c == '%')
+ c = 256;
+ if (ctable[c])
+ free(ctable[c]);
+ arg = s;
+ l = copyarg(&s, (char *)0);
+ if (c != 256)
+ l = l * templnsub + templlen;
+ if ((ctable[c] = (char *)malloc(l + 1)) == 0)
+ {
+ Msg(0, "%s", strnomem);
+ FreeTransTable();
+ return -1;
+ }
+ sx = ctable[c];
+ for (p = ((c == 256) ? "%" : templ); *p && *p != ','; p++)
+ {
+ if (QUOTES(p))
+ p++;
+ else if (*p == '%')
+ {
+ s = arg;
+ sx += copyarg(&s, sx);
+ continue;
+ }
+ *sx++ = *p;
+ }
+ *sx = 0;
+ ASSERT(ctable[c] + l * templnsub + templlen == sx);
+ debug3("XC: %c %c->%s\n", curchar, c, ctable[c]);
+ }
+ if (*s == ',')
+ s++;
+ }
+ return 0;
+}
+
+void
+FreeTransTable()
+{
+ char ***p, **q;
+ int i, j;
+
+ if ((p = D_xtable) == 0)
+ return;
+ for (i = 0; i < 256; i++, p++)
+ {
+ if (*p == 0)
+ continue;
+ q = *p;
+ for (j = 0; j < 257; j++, q++)
+ if (*q)
+ free(*q);
+ free(*p);
+ }
+ free(D_xtable);
+ D_xtable = NULL;
+}
+#endif /* FONT */
+
+static int
+copyarg(pp, s)
+char **pp, *s;
+{
+ int l;
+ char *p;
+
+ for (l = 0, p = *pp; *p && *p != ','; p++)
+ {
+ if (QUOTES(p))
+ p++;
+ if (s)
+ *s++ = *p;
+ l++;
+ }
+ if (*p == ',')
+ p++;
+ *pp = p;
+ return l;
+}
+
+
+/*
+**
+** Termcap routines that use our extra_incap
+**
+*/
+
+static int
+e_tgetent(bp, name)
+char *bp, *name;
+{
+ int r;
+
+#ifdef USE_SETEUID
+ xseteuid(real_uid);
+ xsetegid(real_gid);
+#endif
+ r = tgetent(bp, name);
+#ifdef USE_SETEUID
+ xseteuid(eff_uid);
+ xsetegid(eff_gid);
+#endif
+ return r;
+}
+
+
+/* findcap:
+ * cap = capability we are looking for
+ * tepp = pointer to bufferpointer
+ * n = size of buffer (0 = infinity)
+ */
+
+static char *
+findcap(cap, tepp, n)
+char *cap;
+char **tepp;
+int n;
+{
+ char *tep;
+ char c, *p, *cp;
+ int mode; /* mode: 0=LIT 1=^ 2=\x 3,4,5=\nnn */
+ int num = 0, capl;
+
+ if (!extra_incap)
+ return 0;
+ tep = *tepp;
+ capl = strlen(cap);
+ cp = 0;
+ mode = 0;
+ for (p = extra_incap; *p; )
+ {
+ if (strncmp(p, cap, capl) == 0)
+ {
+ p += capl;
+ c = *p;
+ if (c && c != ':' && c != '@')
+ p++;
+ if (c == 0 || c == '@' || c == '=' || c == ':' || c == '#')
+ cp = tep;
+ }
+ while ((c = *p))
+ {
+ p++;
+ if (mode == 0)
+ {
+ if (c == ':')
+ break;
+ if (c == '^')
+ mode = 1;
+ if (c == '\\')
+ mode = 2;
+ }
+ else if (mode == 1)
+ {
+ mode = 0;
+ c = c & 0x1f;
+ }
+ else if (mode == 2)
+ {
+ mode = 0;
+ switch(c)
+ {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ mode = 3;
+ num = 0;
+ break;
+ case 'E':
+ c = 27;
+ break;
+ case 'n':
+ c = '\n';
+ break;
+ case 'r':
+ c = '\r';
+ break;
+ case 't':
+ c = '\t';
+ break;
+ case 'b':
+ c = '\b';
+ break;
+ case 'f':
+ c = '\f';
+ break;
+ }
+ }
+ if (mode > 2)
+ {
+ num = num * 8 + (c - '0');
+ if (mode++ == 5 || (*p < '0' || *p > '9'))
+ {
+ c = num;
+ mode = 0;
+ }
+ }
+ if (mode)
+ continue;
+
+ if (cp && n != 1)
+ {
+ *cp++ = c;
+ n--;
+ }
+ }
+ if (cp)
+ {
+ *cp++ = 0;
+ *tepp = cp;
+ debug2("'%s' found in extra_incap -> %s\n", cap, tep);
+ return tep;
+ }
+ }
+ return 0;
+}
+
+static char *
+e_tgetstr(cap, tepp)
+char *cap;
+char **tepp;
+{
+ char *tep;
+ if ((tep = findcap(cap, tepp, 0)))
+ return (*tep == '@') ? 0 : tep;
+ return tgetstr(cap, tepp);
+}
+
+static int
+e_tgetflag(cap)
+char *cap;
+{
+ char buf[2], *bufp;
+ char *tep;
+ bufp = buf;
+ if ((tep = findcap(cap, &bufp, 2)))
+ return (*tep == '@') ? 0 : 1;
+ return tgetflag(cap) > 0;
+}
+
+static int
+e_tgetnum(cap)
+char *cap;
+{
+ char buf[20], *bufp;
+ char *tep, c;
+ int res, base = 10;
+
+ bufp = buf;
+ if ((tep = findcap(cap, &bufp, 20)))
+ {
+ c = *tep;
+ if (c == '@')
+ return -1;
+ if (c == '0')
+ base = 8;
+ res = 0;
+ while ((c = *tep++) >= '0' && c <= '9')
+ res = res * base + (c - '0');
+ return res;
+ }
+ return tgetnum(cap);
+}
+
diff --git a/terminfo/8bits b/terminfo/8bits
new file mode 100644
index 0000000..b616622
--- /dev/null
+++ b/terminfo/8bits
@@ -0,0 +1,17 @@
+
+We test some umlauts and other characters coded in
+the ISO 8859-1 (Latin 1) standard:
+
+umlaut A Ä umlaut a ä
+umlaut O Ö umlaut o ö
+umlaut U Ü umlaut u ü
+sharp s ß paragraph §
+e + / é e + \ è
+e + ^ ê a + \ à
+u + \ ù degree °
+log. not ¬ + over - ±
+<< « >> »
+fraction 1/2 ½ fraction 1/4 ¼
+power of 2 ² middle dot ·
+
+---
diff --git a/terminfo/README b/terminfo/README
new file mode 100644
index 0000000..45b39e6
--- /dev/null
+++ b/terminfo/README
@@ -0,0 +1,20 @@
+
+This directory contains various file for termcap/terminfo installation
+and testing:
+
+screencap Termcap entry for screen. Add it to /etc/termcap.
+ On NetBSD, you should run /usr/bin/cap_mkdb afterwards.
+
+screeninfo.src Terminfo entry. Use 'tic screeninfo.src'
+ to install (Sun: /usr/5bin/tic).
+
+checktc.c Termcap/info test program. Checks margin
+ handling and other things.
+
+8bits Some chars from the ISO 8859-1 charset.
+
+test.txt Test file for alternate charset.
+
+tetris.c The popular game, by John Tromp. This is one of
+ the winners of the 1989 IOCCC contest.
+
diff --git a/terminfo/checktc.c b/terminfo/checktc.c
new file mode 100644
index 0000000..ccc9485
--- /dev/null
+++ b/terminfo/checktc.c
@@ -0,0 +1,204 @@
+#include <stdio.h>
+
+char *CL, *CM, *CS, *SR;
+int CO, LI, AM, XN;
+
+char *tgetstr(), *getenv();
+void PutStr(), CPutStr(), CCPutStr(), GotoPos(), RETURN();
+
+main()
+{
+ char *term, *s;
+ char tcbuf[1024];
+ char tcstr[1024], *tp;
+
+ if ((term = getenv("TERM")) == 0)
+ {
+ fprintf(stderr, "No $TERM set\n");
+ exit(1);
+ }
+ switch (tgetent(tcbuf, term))
+ {
+ case -1:
+ fprintf(stderr, "Could not open termcap file\n");
+ exit(1);
+ case 0:
+ fprintf(stderr, "I don't know what a '%s' terminal is.\n", term);
+ exit(1);
+ }
+ tp = tcstr;
+ if ((CL = tgetstr("cl", &tp)) == 0)
+ {
+ fprintf(stderr, "cl capability required\n");
+ exit(1);
+ }
+ if ((CM = tgetstr("cm", &tp)) == 0)
+ {
+ fprintf(stderr, "cm capability required\n");
+ exit(1);
+ }
+
+ if ((s = getenv("COLUMNS")))
+ CO = atoi(s);
+ if ((s = getenv("LINES")))
+ LI = atoi(s);
+ if (CO == 0)
+ CO = tgetnum("co");
+ if (LI == 0)
+ LI = tgetnum("li");
+ if (CO == 0)
+ CO = 80;
+ if (LI == 0)
+ LI = 24;
+ GotoPos(5, 1);
+ printf("******* cl capability does not work !!! *******");
+ GotoPos(5, 2);
+ PutStr(CL);
+ printf("******* cl capability does not home cursor *******");
+ GotoPos(0, 0);
+ printf(" ");
+ GotoPos(5, 4);
+ printf("******* cm capability does not work !!! *******");
+ GotoPos(5, 4);
+ printf(" ");
+ GotoPos(CO/2-12, LI/2);
+ printf("Your terminal size is");
+ GotoPos(CO/2-3, LI/2+1);
+ printf("%dx%d", CO, LI);
+ GotoPos(CO/2-2, 0);
+ printf("top");
+ GotoPos(CO/2-3, LI-1);
+ printf("bottom");
+ GotoPos(0, LI/2-2);printf("l");
+ GotoPos(0, LI/2-1);printf("e");
+ GotoPos(0, LI/2+0);printf("f");
+ GotoPos(0, LI/2+1);printf("t");
+ GotoPos(CO-1, LI/2-2);printf("r");
+ GotoPos(CO-1, LI/2-1);printf("i");
+ GotoPos(CO-1, LI/2+0);printf("g");
+ GotoPos(CO-1, LI/2+1);printf("h");
+ GotoPos(CO-1, LI/2+2);printf("t");
+ GotoPos(CO/2-15, LI/2+3);
+ RETURN();
+ AM = tgetflag("am");
+ printf("Termcap: terminal does %sauto-wrap", AM ? "" : "not ");
+ GotoPos(0, 5);
+ if (AM)
+ {
+ printf(" am capability set, but terminal does not wrap");
+ GotoPos(CO-1, 3);
+ }
+ else
+ {
+ printf(" am capability not set, but terminal does wrap");
+ GotoPos(CO-1, 4);
+ }
+ printf(" \n ");
+ GotoPos(0, 10);
+ RETURN();
+ if (AM)
+ {
+ XN = tgetflag("xn");
+ printf("Termcap: terminal has %smagic margins", XN ? "" : "no ");
+ GotoPos(0, 5);
+ if ((XN = tgetflag("xn")))
+ {
+ printf(" xn capability set, but terminal has no magic-margins");
+ GotoPos(CO-1, 4);
+ }
+ else
+ {
+ printf(" xn capability not set, but terminal has magic-margins");
+ GotoPos(CO-1, 3);
+ }
+ printf(" \n");
+ printf(" ");
+ GotoPos(0, 10);
+ RETURN();
+ if (XN)
+ {
+ GotoPos(0, 6);
+ printf(" last col in last row is not usable");
+ GotoPos(CO-1, LI-1);
+ printf(" ");
+ GotoPos(0, 6);
+ printf(" ");
+ GotoPos(0, 0);
+ printf("testing magic margins in last row");
+ GotoPos(0, 10);
+ RETURN();
+ }
+ }
+ if ((CS = tgetstr("cs", &tp)))
+ {
+ printf("Termcap: terminal has scrollregions");
+ GotoPos(0, 5);
+ printf(" cs capability set, but doesn't work");
+ CCPutStr(CS, 4, 5);
+ GotoPos(0, 5);
+ printf("\n\n");
+ CCPutStr(CS, 0, LI-1);
+ GotoPos(0, 10);
+ RETURN();
+ }
+ if ((SR = tgetstr("sr", &tp)))
+ {
+ GotoPos(0, 5);
+ printf(" sr capability set, but doesn't work");
+ GotoPos(0, 0);
+ PutStr(SR);
+ GotoPos(0, 6);
+ printf(" ");
+ GotoPos(0, 0);
+ printf("Termcap: terminal can scroll backwards");
+ GotoPos(0, 10);
+ RETURN();
+ }
+}
+
+void
+putcha(c)
+char c;
+{
+ putchar(c);
+}
+
+void
+PutStr(s)
+char *s;
+{
+ tputs(s, 1, putcha);
+ fflush(stdout);
+}
+
+void CPutStr(s, c)
+char *s;
+int c;
+{
+ tputs(tgoto(s, 0, c), 1, putcha);
+ fflush(stdout);
+}
+
+void CCPutStr(s, x, y)
+char *s;
+int x, y;
+{
+ tputs(tgoto(s, y, x), 1, putcha);
+ fflush(stdout);
+}
+
+void GotoPos(x,y)
+int x,y;
+{
+ tputs(tgoto(CM, x, y), 1, putcha);
+ fflush(stdout);
+}
+
+void
+RETURN()
+{
+ printf("Press <RETURN> to continue");
+ fflush(stdout);
+ while(getchar() != '\n');
+ PutStr(CL);
+}
diff --git a/terminfo/screencap b/terminfo/screencap
new file mode 100644
index 0000000..4820d92
--- /dev/null
+++ b/terminfo/screencap
@@ -0,0 +1,23 @@
+SC|screen|VT 100/ANSI X3.64 virtual terminal:\
+ :am:xn:ms:mi:G0:km:\
+ :DO=\E[%dB:LE=\E[%dD:RI=\E[%dC:UP=\E[%dA:bs:bt=\E[Z:\
+ :cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:cm=\E[%i%d;%dH:ct=\E[3g:\
+ :do=^J:nd=\E[C:pt:rc=\E8:rs=\Ec:sc=\E7:st=\EH:up=\EM:\
+ :le=^H:bl=^G:cr=^M:it#8:ho=\E[H:nw=\EE:ta=^I:is=\E)0:\
+ :li#24:co#80:us=\E[4m:ue=\E[24m:so=\E[3m:se=\E[23m:\
+ :mb=\E[5m:md=\E[1m:mr=\E[7m:me=\E[m:sr=\EM:al=\E[L:\
+ :AL=\E[%dL:dl=\E[M:DL=\E[%dM:cs=\E[%i%d;%dr:dc=\E[P:\
+ :DC=\E[%dP:im=\E[4h:ei=\E[4l:IC=\E[%d@:\
+ :ks=\E[?1h\E=:ke=\E[?1l\E>:vb=\Eg:\
+ :ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:\
+ :k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:k5=\E[15~:k6=\E[17~:\
+ :k7=\E[18~:k8=\E[19~:k9=\E[20~:k;=\E[21~:F1=\E[23~:F2=\E[24~:\
+ :kh=\E[1~:kI=\E[2~:kD=\E[3~:kH=\E[4~:@7=\E[4~:kP=\E[5~:\
+ :kN=\E[6~:eA=\E(B\E)0:as=^N:ae=^O:ti=\E[?1049h:te=\E[?1049l:\
+ :vi=\E[?25l:ve=\E[34h\E[?25h:vs=\E[34l:\
+ :Co#8:pa#64:AF=\E[3%dm:AB=\E[4%dm:op=\E[39;49m:AX:\
+ :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~..--++,,hhII00:
+SB|screen-bce|VT 100/ANSI X3.64 virtual terminal with bce:\
+ :ut:tc=screen:
+SH|screen-s|VT 100/ANSI X3.64 virtual terminal with hardstatus line:\
+ :ts=\E_:fs=\E\\:ds=\E_\E\\:tc=screen:
diff --git a/terminfo/screeninfo.src b/terminfo/screeninfo.src
new file mode 100644
index 0000000..c5f254a
--- /dev/null
+++ b/terminfo/screeninfo.src
@@ -0,0 +1,80 @@
+screen|VT 100/ANSI X3.64 virtual terminal,
+ am, km, mir, msgr, xenl,
+ cols#80, it#8, lines#24, colors#8, pairs#64,
+ bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z,
+ clear=\E[H\E[J, cr=\r, csr=\E[%i%p1%d;%p2%dr,
+ cub=\E[%p1%dD, cub1=\b, cud=\E[%p1%dB, cud1=\n,
+ cuf=\E[%p1%dC, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH,
+ cuu=\E[%p1%dA, cuu1=\EM, dch=\E[%p1%dP, dch1=\E[P,
+ dl=\E[%p1%dM, dl1=\E[M, ed=\E[J, el=\E[K, el1=\E[1K,
+ enacs=\E(B\E)0, home=\E[H,
+ ht=\t, hts=\EH, ich=\E[%p1%d@, il=\E[%p1%dL, il1=\E[L,
+ ind=\n, is2=\E)0, kcub1=\EOD, kcud1=\EOB,
+ kcuf1=\EOC, kcuu1=\EOA, kdch1=\E[3~, kf1=\EOP,
+ kf10=\E[21~, kf11=\E[23~, kf12=\E[24~, kf2=\EOQ,
+ kf3=\EOR, kf4=\EOS, kf5=\E[15~, kf6=\E[17~,
+ kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, khome=\E[1~, kend=\E[4~,
+ kich1=\E[2~, knp=\E[6~, kpp=\E[5~, nel=\EE,
+ rc=\E8, rev=\E[7m, ri=\EM, rmcup=\E[?1049l, rmir=\E[4l,
+ rmkx=\E[?1l\E>, rmso=\E[23m, rmul=\E[24m, rs2=\Ec, sc=\E7,
+ sgr0=\E[m, smcup=\E[?1049h, smir=\E[4h, smkx=\E[?1h\E=,
+ smso=\E[3m, smul=\E[4m, tbc=\E[3g, smacs=^N, rmacs=^O, flash=\Eg,
+ civis=\E[?25l, cnorm=\E[34h\E[?25h, cvvis=\E[34l,
+ op=\E[39;49m, setab=\E[4%p1%dm, setaf=\E[3%p1%dm,
+ acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~..--++\054\054hhII00,
+screen-bce|VT 100/ANSI X3.64 virtual terminal with bce,
+ am, bce, km, mir, msgr, xenl,
+ cols#80, it#8, lines#24, colors#8, pairs#64,
+ bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z,
+ clear=\E[H\E[J, cr=\r, csr=\E[%i%p1%d;%p2%dr,
+ cub=\E[%p1%dD, cub1=\b, cud=\E[%p1%dB, cud1=\n,
+ cuf=\E[%p1%dC, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH,
+ cuu=\E[%p1%dA, cuu1=\EM, dch=\E[%p1%dP, dch1=\E[P,
+ dl=\E[%p1%dM, dl1=\E[M, ed=\E[J, el=\E[K, el1=\E[1K,
+ enacs=\E(B\E)0, home=\E[H,
+ ht=\t, hts=\EH, ich=\E[%p1%d@, il=\E[%p1%dL, il1=\E[L,
+ ind=\n, is2=\E)0, kcub1=\EOD, kcud1=\EOB,
+ kcuf1=\EOC, kcuu1=\EOA, kdch1=\E[3~, kf1=\EOP,
+ kf10=\E[21~, kf11=\E[23~, kf12=\E[24~, kf2=\EOQ,
+ kf3=\EOR, kf4=\EOS, kf5=\E[15~, kf6=\E[17~,
+ kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, khome=\E[1~, kend=\E[4~,
+ kich1=\E[2~, knp=\E[6~, kpp=\E[5~, nel=\EE,
+ rc=\E8, rev=\E[7m, ri=\EM, rmcup=\E[?1049l, rmir=\E[4l,
+ rmkx=\E[?1l\E>, rmso=\E[23m, rmul=\E[24m, rs2=\Ec, sc=\E7,
+ sgr0=\E[m, smcup=\E[?1049h, smir=\E[4h, smkx=\E[?1h\E=,
+ smso=\E[3m, smul=\E[4m, tbc=\E[3g, smacs=^N, rmacs=^O, flash=\Eg,
+ civis=\E[?25l, cnorm=\E[34h\E[?25h, cvvis=\E[34l,
+ op=\E[39;49m, setab=\E[4%p1%dm, setaf=\E[3%p1%dm,
+ acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~..--++\054\054hhII00,
+screen-s|VT 100/ANSI X3.64 virtual terminal with hardstatus line,
+ am, bce, hs, km, mir, msgr, xenl,
+ cols#80, it#8, lines#24, colors#8, pairs#64,
+ bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z,
+ clear=\E[H\E[J, cr=\r, csr=\E[%i%p1%d;%p2%dr,
+ cub=\E[%p1%dD, cub1=\b, cud=\E[%p1%dB, cud1=\n,
+ cuf=\E[%p1%dC, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH,
+ cuu=\E[%p1%dA, cuu1=\EM, dch=\E[%p1%dP, dch1=\E[P,
+ dl=\E[%p1%dM, dl1=\E[M, ed=\E[J, el=\E[K, el1=\E[1K,
+ enacs=\E(B\E)0, home=\E[H,
+ ht=\t, hts=\EH, ich=\E[%p1%d@, il=\E[%p1%dL, il1=\E[L,
+ ind=\n, is2=\E)0, kcub1=\EOD, kcud1=\EOB,
+ kcuf1=\EOC, kcuu1=\EOA, kdch1=\E[3~, kf1=\EOP,
+ kf10=\E[21~, kf11=\E[23~, kf12=\E[24~, kf2=\EOQ,
+ kf3=\EOR, kf4=\EOS, kf5=\E[15~, kf6=\E[17~,
+ kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, khome=\E[1~, kend=\E[4~,
+ kich1=\E[2~, knp=\E[6~, kpp=\E[5~, nel=\EE,
+ rc=\E8, rev=\E[7m, ri=\EM, rmcup=\E[?1049l, rmir=\E[4l,
+ rmkx=\E[?1l\E>, rmso=\E[23m, rmul=\E[24m, rs2=\Ec, sc=\E7,
+ sgr0=\E[m, smcup=\E[?1049h, smir=\E[4h, smkx=\E[?1h\E=,
+ smso=\E[3m, smul=\E[4m, tbc=\E[3g, smacs=^N, rmacs=^O, flash=\Eg,
+ tsl=\E_, fsl=\E\\, dsl=\E_\E\\,
+ civis=\E[?25l, cnorm=\E[34h\E[?25h, cvvis=\E[34l,
+ op=\E[39;49m, setab=\E[4%p1%dm, setaf=\E[3%p1%dm,
+ acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~..--++\054\054hhII00,
+screen-256color|VT 100/ANSI X3.64 virtual terminal,
+ ccc,
+ colors#256, pairs#32767,
+ initc=\E]4;%p1%d;rgb\:%p2%{255}%*%{1000}%/%2.2X/%p3%{255}%*%{1000}%/%2.2X/%p4%{255}%*%{1000}%/%2.2X\E\\,
+ setab=\E[48;5;%p1%dm, setaf=\E[38;5;%p1%dm,
+ setb=\E[48;5;%p1%dm, setf=\E[38;5;%p1%dm,
+ use=screen,
diff --git a/terminfo/test.txt b/terminfo/test.txt
new file mode 100644
index 0000000..2da65e5
--- /dev/null
+++ b/terminfo/test.txt
@@ -0,0 +1,603 @@
+
+ <(A)0[?4h[?5l
+
+
+
+
+
+
+
+
+
+ lqqqqqqqqqwwwqqqqqqqqqk sssssssssssssssssssssssssssss
+ xMerry Chrxxxmas * Merx \ /
+ xry Christxxx * Merry x pr rp
+ xChristmasxxxMerry Chrx oqrs srqo
+ xistmas * xxxry Christx ooppqqwqwqqppoo
+ tqqqqqqqqqjxmqqqqqqqqqu x x
+ tqqqqqqqqqq`qqqqqqqqqqu x x
+ tqqqqqqqqqkxlqqqqqqqqqu x x
+ xry Christxxx * Merry x x x
+ xChristmasxxxMerry Chrx x x
+ xistmas * xxxry Christx x x
+ xmas * MerxxxChristmasx srqqj mqqrs
+ mqqqqqqqqqvvvqqqqqqqqqj  rqpo opqr 
+lmxx
+lqmqx x
+lqwmqvx xx x
+lqwqmqvqx x x x
+lqwqmqvqx x x x
+lqwqmqvqx x x x
+lqwqmqvqx x x x
+lqwqmqvqx x x x
+lqwqmqvqx x x x
+lqwqmqvqx x x x
+//
+//
+//  / /
+//  / ///
+//  ////
+//  //// //
+/  //// / /
+ // / //
+// / // /
+//s/ // 
+sssssssssss
+/ / //  // /
+ss
+ / //  //  //
+rrrrrrrrrrr
+/ /s //  //
+qqqqqqqqq
+//  //  //
+srqqqqqqqqqrs
+  //  ///
+srrs
+//  //// //
+rrqqqqrr
+/  //// / /
+ppppppp
+ // / //
+rrqqrr
+// / // /
+rqppppqr
+//s/ // 
+
+rqpppooooooopppqr
+/ / //  // /
+qppoooooooooooppq
+ / //  //  //
+
+
+
+sssssssooo ooo. o f
+
+/ /s //  //.f
+
+ssss .f
+
+//  //  // f
+
+ssssrrrrqqqqqrrrrsssss s
+
+  //  ///. . .
+
+sssrrrrqqqqqqqqqrrrrsssf f . f
+
+//  //// / f .
+
+rrrqqqqpppppppppqqqqrss. . o f
+
+/  //// / /f .f
+
+qqqppppooooooooopppqrss .f .
+
+s// / // f f
+
+sssssssssqppoooo oopqrss.o .
+
+// / // /f f. .
+
+ssrrrrrrrrrsqpooo opqrssf f f . f
+
+//s/ // f o o f .
+
+ssssssrrrrssssss   f o o .. . o f
+
+s/ //  /  . o o ff .f
+
+srrrrrrqqqqqqqqqqqqqqrrssrqf o o .  .f .
+
+/ //  / mqvqqqqqq lqwqqqqqq x x x x . o f
+
+rqqqqqqppppppppppppppq mqvqqqqq lqwqqqqq x x x xf .o . o
+
+/s /  mqvqqqq lqwqqqq x x x x f f [14;51
+
+qppppppoooooooooooooo mqvqqq lqwqqq x x x xf  .f f . f
+
+s /  mqvqq lqwqq x x x x. o f o o f f
+
+poooooo  mqvq lqwq x x x x o o of o o .
+
+rrrrrrrrrrrrrrrrrrrrrrrrrrrrr   mqv lqw x x x xo
+ mq lq x  x  . o o of o o .  .f .
+ m l x x. o o f o . . . o ff f
+    f o o f . ff .o . o
+#3 Cheers!
+#4 Cheers! 
+
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+
+ . o o . o f  f f . . .
+#5
+#5
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ /ooooooooooooooo\
+ o o of o o .. . o f
+ / sss sss \
+o o o . o o ff .f
+ x (sOs) (sOs) x
+ . o o of o o .  .f .
+ x ` x
+. o o f o . . . o ff f
+ \ \sssssssss/ /
+f o o f . ff .o . o
+ \ /
+ . o o . o f  f f . . .
+ \sssssssssss/
+f . o . f o ff  .f f . f
+ ooppqqrrsss
+ f f f . o f o o f f .
+ ooppqqrrsss
+ o o of o o .. . o f
+ ooppqqrrsss
+o o o . o o ff .f
+ ooppqqrrsss
+ . o o of o o .  .f .
+ ooppqqrrsss
+. o o f o . . . o ff f
+ ooppqqrrsss
+f o o f . ff .o . o
+ ooppqqrrsss . o o . o f  f f . . .
+M x ` x
+f . o . f o ff  .f f . f
+M x (sOs) (sOs) x
+ f f f . o f o o f f .
+M / sss sss \
+ o o of o o .. . o f
+M /ooooooooooooooo\
+o o o . o o ff .f
+M
+ . o o of o o .  .f .
+M
+. o o f o . . . o ff f
+M
+f o o f . ff .o . o
+M
+ . o o . o f  f f . . .
+ \ /
+f . o . f o ff  .f f . f
+ \sssssssssss/
+ f f f . o f o o f f .
+ ooppqqrrsss
+ o o of o o .. . o f
+ ooppqqrrsss
+o o o . o o ff .f
+ ooppqqrrsss
+ . o o of o o .  .f .
+ ooppqqrrsss
+. o o f o . . . o ff f
+ ooppqqrrsssf o o f . ff .o . o
+M / sss sss \
+ . o o . o f  f f . . .
+M /ooooooooooooooo\
+f . o . f o ff  .f f . f
+M
+ f f f . o f o o f f .
+M
+ o o of o o .. . o f
+ ooppqqrrsss
+o o o . o o ff .f
+ ooppqqrrsss
+ . o o of o o .  .f .
+ ooppqqrrsss
+. o o f o . . . o ff f
+ ooppqqrrsssf o o f . ff .o . o
+M /ooooooooooooooo\
+ . o o . o f  f f . . .
+M
+f . o . f o ff  .f f . f
+M
+ f f f . o f o o f f .
+M
+ o o of o o .. . o f
+ \sssssssssss/
+o o o . o o ff .f
+ ooppqqrrsss
+ . o o of o o .  .f .
+ ooppqqrrsss
+. o o f o . . . o ff f
+f o o f . ff .o . o
+
+Jin
+ . o o . o f  f f . . .
+gle
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+Bells,
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+Jin
+ . o o of o o .  .f .
+gle
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+Bells,
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+Jin
+ f f f . o f o o f f .
+gle
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+all
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+the
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+way,
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+Oh!
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+What
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+fun
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+it
+ o o of o o .. . o f
+is
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+to
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+ride,
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+On
+o o o . o o ff .f
+a
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+one-
+f . o . f o ff  .f f . f
+horse
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+op
+ f f f . o f o o f f .
+en
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+sleigh.
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff f
+
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff f
+
+ o o of o o 
+. o o o  
+f o o   
+
+o o o . o o ff f
+
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff f
+
+ o o of o o 
+. o o o  
+f o o   
+
+
+Merry Christmas
+
+-
+
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff f
+
+ o o of o o 
+. o o o  
+f o o   
+
+o o o . o o ff f
+
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff .f
+ . o o of o o .  .f .
+. o o f o . . . o ff f
+f o o f . ff .o . o
+ . o o . o f  f f . . .
+f . o . f o ff  .f f . f
+ f f f . o f o o f f .
+ o o of o o .. . o f
+o o o . o o ff f
+
+ o o of o o 
+. o o o  
+f o o   
+
+[?4l
+
diff --git a/terminfo/tetris.c b/terminfo/tetris.c
new file mode 100644
index 0000000..e230373
--- /dev/null
+++ b/terminfo/tetris.c
@@ -0,0 +1,20 @@
+long h[4];t(){h[3]-=h[3]/3000;setitimer(0,h,0);}c,d,l,v[]={(int)t,0,2},w,s,I,K
+=0,i=276,j,k,q[276],Q[276],*n=q,*m,x=17,f[]={7,-13,-12,1,8,-11,-12,-1,9,-1,1,
+12,3,-13,-12,-1,12,-1,11,1,15,-1,13,1,18,-1,1,2,0,-12,-1,11,1,-12,1,13,10,-12,
+1,12,11,-12,-1,1,2,-12,-1,12,13,-12,12,13,14,-11,-1,1,4,-13,-12,12,16,-11,-12,
+12,17,-13,1,-1,5,-12,12,11,6,-12,12,24};u(){for(i=11;++i<264;)if((k=q[i])-Q[i]
+){Q[i]=k;if(i-++I||i%12<1)printf("\033[%d;%dH",(I=i)/12,i%12*2+28);printf(
+"\033[%dm "+(K-k?0:5),k);K=k;}Q[263]=c=getchar();}G(b){for(i=4;i--;)if(q[i?b+
+n[i]:b])return 0;return 1;}g(b){for(i=4;i--;q[i?x+n[i]:x]=b);}main(C,V,a)char*
+*V,*a;{h[3]=1000000/(l=C>1?atoi(V[1]):2);for(a=C>2?V[2]:"jkl pq";i;i--)*n++=i<
+25||i%12<2?7:0;srand(getpid());system("stty cbreak -echo stop u");sigvec(14,v,
+0);t();puts("\033[H\033[J");for(n=f+rand()%7*4;;g(7),u(),g(0)){if(c<0){if(G(x+
+12))x+=12;else{g(7);++w;for(j=0;j<252;j=12*(j/12+1))for(;q[++j];)if(j%12==10){
+for(;j%12;q[j--]=0);u();for(;--j;q[j+12]=q[j]);u();}n=f+rand()%7*4;G(x=17)||(c
+=a[5]);}}if(c==*a)G(--x)||++x;if(c==a[1])n=f+4**(m=n),G(x)||(n=m);if(c==a[2])G
+(++x)||--x;if(c==a[3])for(;G(x+12);++w)x+=12;if(c==a[4]||c==a[5]){s=sigblock(
+8192);printf("\033[H\033[J\033[0m%d\n",w);if(c==a[5])break;for(j=264;j--;Q[j]=
+0);while(getchar()-a[4]);puts("\033[H\033[J\033[7m");sigsetmask(s);}}d=popen(
+"stty -cbreak echo stop \023;sort -mnr -o HI - HI;cat HI","w");fprintf(d,
+"%4d from level %1d by %s\n",w,l,getlogin());pclose(d);}
+
diff --git a/tty.sh b/tty.sh
new file mode 100644
index 0000000..affadb7
--- /dev/null
+++ b/tty.sh
@@ -0,0 +1,1604 @@
+#! /bin/sh
+# sh tty.sh tty.c
+# This inserts all the needed #ifdefs for IF{} statements
+# and generates tty.c
+
+#
+# Stupid cpp on A/UX barfs on ``#if defined(FOO) && FOO < 17'' when
+# FOO is undefined. Reported by Robert C. Tindall (rtindall@uidaho.edu)
+#
+rm -f $1
+sed -e '1,26d' \
+-e 's%^IF{\([^}]*\)}\(.*\)%#if defined(\1)\
+\2\
+#endif /* \1 */%' \
+-e 's%^IFN{\([^}]*\)}\(.*\)%#if !defined(\1)\
+\2\
+#endif /* \1 */%' \
+-e 's%^XIF{\([^}]*\)}\(.*\)%#if defined(\1)\
+#if (\1 < MAXCC)\
+\2\
+#endif \
+#endif /* \1 */%' \
+ < $0 > $1
+chmod -w $1
+exit 0
+
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+/*
+ * NOTICE: tty.c is automatically generated from tty.sh
+ * Do not change anything here. If you then change tty.sh.
+ */
+
+#include <sys/types.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#ifndef sgi
+# include <sys/file.h>
+#endif
+#if !defined(sun) || defined(SUNOS3)
+# include <sys/ioctl.h> /* collosions with termios.h */
+#else
+# ifndef TIOCEXCL
+# include <sys/ttold.h> /* needed for TIOCEXCL */
+# endif
+#endif
+#ifdef __hpux
+# include <sys/modem.h>
+#endif
+#include <limits.h>
+
+#ifdef ISC
+# include <sys/tty.h>
+# include <sys/sioctl.h>
+# include <sys/pty.h>
+#endif
+
+#include "config.h"
+#ifdef HAVE_STROPTS_H
+#include <sys/stropts.h> /* for I_POP */
+#endif
+
+#include "screen.h"
+#include "extern.h"
+
+#if !defined(TIOCCONS) && defined(sun) && defined(SVR4)
+# include <sys/strredir.h>
+#endif
+
+extern struct display *display, *displays;
+extern int iflag;
+#if (!defined(TIOCCONS) && defined(SRIOCSREDIR)) || defined(linux)
+extern struct win *console_window;
+static void consredir_readev_fn __P((struct event *, char *));
+#endif
+
+int separate_sids = 1;
+
+static void DoSendBreak __P((int, int, int));
+static sigret_t SigAlrmDummy __P(SIGPROTOARG);
+
+
+/* Frank Schulz (fschulz@pyramid.com):
+ * I have no idea why VSTART is not defined and my fix is probably not
+ * the cleanest, but it works.
+ */
+#if !defined(VSTART) && defined(_VSTART)
+#define VSTART _VSTART
+#endif
+#if !defined(VSTOP) && defined(_VSTOP)
+#define VSTOP _VSTOP
+#endif
+
+#ifndef O_NOCTTY
+# define O_NOCTTY 0
+#endif
+
+#ifndef TTYVMIN
+# define TTYVMIN 1
+#endif
+#ifndef TTYVTIME
+#define TTYVTIME 0
+#endif
+
+
+static sigret_t
+SigAlrmDummy SIGDEFARG
+{
+ debug("SigAlrmDummy()\n");
+ SIGRETURN;
+}
+
+/*
+ * Carefully open a charcter device. Not used to open display ttys.
+ * The second parameter is parsed for a few stty style options.
+ */
+
+int
+OpenTTY(line, opt)
+char *line, *opt;
+{
+ int f;
+ struct mode Mode;
+ sigret_t (*sigalrm)__P(SIGPROTOARG);
+
+ sigalrm = signal(SIGALRM, SigAlrmDummy);
+ alarm(2);
+
+ /* this open only succeeds, if real uid is allowed */
+ if ((f = secopen(line, O_RDWR | O_NONBLOCK | O_NOCTTY, 0)) == -1)
+ {
+ if (errno == EINTR)
+ Msg(0, "Cannot open line '%s' for R/W: open() blocked, aborted.", line);
+ else
+ Msg(errno, "Cannot open line '%s' for R/W", line);
+ alarm(0);
+ signal(SIGALRM, sigalrm);
+ return -1;
+ }
+ if (!isatty(f))
+ {
+ Msg(0, "'%s' is not a tty", line);
+ alarm(0);
+ signal(SIGALRM, sigalrm);
+ close(f);
+ return -1;
+ }
+#if defined(I_POP) && defined(POP_TTYMODULES)
+ debug("OpenTTY I_POP\n");
+ while (ioctl(f, I_POP, (char *)0) >= 0)
+ ;
+#endif
+ /*
+ * We come here exclusively. This is to stop all kermit and cu type things
+ * accessing the same tty line.
+ * Perhaps we should better create a lock in some /usr/spool/locks directory?
+ */
+#ifdef TIOCEXCL
+ errno = 0;
+ if (ioctl(f, TIOCEXCL, (char *) 0) < 0)
+ Msg(errno, "%s: ioctl TIOCEXCL failed", line);
+ debug3("%d %d %d\n", getuid(), geteuid(), getpid());
+ debug2("%s TIOCEXCL errno %d\n", line, errno);
+#endif /* TIOCEXCL */
+ /*
+ * We create a sane tty mode. We do not copy things from the display tty
+ */
+#if WE_REALLY_WANT_TO_COPY_THE_TTY_MODE
+ if (display)
+ {
+ debug1("OpenTTY: using mode of display for %s\n", line);
+ Mode = D_NewMode;
+ }
+ else
+#endif
+ InitTTY(&Mode, W_TYPE_PLAIN);
+
+ SttyMode(&Mode, opt);
+#ifdef DEBUG
+ DebugTTY(&Mode);
+#endif
+ SetTTY(f, &Mode);
+
+#if defined(linux) && defined(TIOCMSET)
+ {
+ int mcs = 0;
+ ioctl(f, TIOCMGET, &mcs);
+ mcs |= TIOCM_RTS;
+ ioctl(f, TIOCMSET, &mcs);
+ }
+#endif
+
+ brktty(f);
+ alarm(0);
+ signal(SIGALRM, sigalrm);
+ debug2("'%s' CONNECT fd=%d.\n", line, f);
+ return f;
+}
+
+
+/*
+ * Tty mode handling
+ */
+
+void
+InitTTY(m, ttyflag)
+struct mode *m;
+int ttyflag;
+{
+ bzero((char *)m, sizeof(*m));
+#ifdef POSIX
+ /* struct termios tio
+ * defaults, as seen on SunOS 4.1.3
+ */
+ debug1("InitTTY: POSIX: termios defaults based on SunOS 4.1.3, but better (%d)\n", ttyflag);
+IF{BRKINT} m->tio.c_iflag |= BRKINT;
+IF{IGNPAR} m->tio.c_iflag |= IGNPAR;
+/* IF{ISTRIP} m->tio.c_iflag |= ISTRIP; may be needed, let's try. jw. */
+IF{IXON} m->tio.c_iflag |= IXON;
+/* IF{IMAXBEL} m->tio.c_iflag |= IMAXBEL; sorry, this one is ridiculus. jw */
+
+ if (!ttyflag) /* may not even be good for ptys.. */
+ {
+IF{ICRNL} m->tio.c_iflag |= ICRNL;
+IF{ONLCR} m->tio.c_oflag |= ONLCR;
+IF{TAB3} m->tio.c_oflag |= TAB3;
+IF{OXTABS} m->tio.c_oflag |= OXTABS;
+/* IF{PARENB} m->tio.c_cflag |= PARENB; nah! jw. */
+IF{OPOST} m->tio.c_oflag |= OPOST;
+ }
+
+
+/*
+ * Or-ing the speed into c_cflags is dangerous.
+ * It breaks on bsdi, where c_ispeed and c_ospeed are extra longs.
+ *
+ * IF{B9600} m->tio.c_cflag |= B9600;
+ * IF{IBSHIFT) && defined(B9600} m->tio.c_cflag |= B9600 << IBSHIFT;
+ *
+ * We hope that we have the posix calls to do it right:
+ * If these are not available you might try the above.
+ */
+IF{B9600} cfsetospeed(&m->tio, B9600);
+IF{B9600} cfsetispeed(&m->tio, B9600);
+
+IF{CS8} m->tio.c_cflag |= CS8;
+IF{CREAD} m->tio.c_cflag |= CREAD;
+IF{CLOCAL} m->tio.c_cflag |= CLOCAL;
+
+IF{ECHOCTL} m->tio.c_lflag |= ECHOCTL;
+IF{ECHOKE} m->tio.c_lflag |= ECHOKE;
+
+ if (!ttyflag)
+ {
+IF{ISIG} m->tio.c_lflag |= ISIG;
+IF{ICANON} m->tio.c_lflag |= ICANON;
+IF{ECHO} m->tio.c_lflag |= ECHO;
+ }
+IF{ECHOE} m->tio.c_lflag |= ECHOE;
+IF{ECHOK} m->tio.c_lflag |= ECHOK;
+IF{IEXTEN} m->tio.c_lflag |= IEXTEN;
+
+XIF{VINTR} m->tio.c_cc[VINTR] = Ctrl('C');
+XIF{VQUIT} m->tio.c_cc[VQUIT] = Ctrl('\\');
+XIF{VERASE} m->tio.c_cc[VERASE] = 0x7f; /* DEL */
+XIF{VKILL} m->tio.c_cc[VKILL] = Ctrl('U');
+XIF{VEOF} m->tio.c_cc[VEOF] = Ctrl('D');
+XIF{VEOL} m->tio.c_cc[VEOL] = VDISABLE;
+XIF{VEOL2} m->tio.c_cc[VEOL2] = VDISABLE;
+XIF{VSWTCH} m->tio.c_cc[VSWTCH] = VDISABLE;
+XIF{VSTART} m->tio.c_cc[VSTART] = Ctrl('Q');
+XIF{VSTOP} m->tio.c_cc[VSTOP] = Ctrl('S');
+XIF{VSUSP} m->tio.c_cc[VSUSP] = Ctrl('Z');
+XIF{VDSUSP} m->tio.c_cc[VDSUSP] = Ctrl('Y');
+XIF{VREPRINT} m->tio.c_cc[VREPRINT] = Ctrl('R');
+XIF{VDISCARD} m->tio.c_cc[VDISCARD] = Ctrl('O');
+XIF{VWERASE} m->tio.c_cc[VWERASE] = Ctrl('W');
+XIF{VLNEXT} m->tio.c_cc[VLNEXT] = Ctrl('V');
+XIF{VSTATUS} m->tio.c_cc[VSTATUS] = Ctrl('T');
+
+ if (ttyflag)
+ {
+ m->tio.c_cc[VMIN] = TTYVMIN;
+ m->tio.c_cc[VTIME] = TTYVTIME;
+ }
+
+# ifdef HPUX_LTCHARS_HACK
+ m->m_ltchars.t_suspc = Ctrl('Z');
+ m->m_ltchars.t_dsuspc = Ctrl('Y');
+ m->m_ltchars.t_rprntc = Ctrl('R');
+ m->m_ltchars.t_flushc = Ctrl('O');
+ m->m_ltchars.t_werasc = Ctrl('W');
+ m->m_ltchars.t_lnextc = Ctrl('V');
+# endif /* HPUX_LTCHARS_HACK */
+
+#else /* POSIX */
+
+# ifdef TERMIO
+ debug1("InitTTY: nonPOSIX, struct termio a la Motorola SYSV68 (%d)\n", ttyflag);
+ /* struct termio tio
+ * defaults, as seen on Mototola SYSV68:
+ * input: 7bit, CR->NL, ^S/^Q flow control
+ * output: POSTprocessing: NL->NL-CR, Tabs to spaces
+ * control: 9600baud, 8bit CSIZE, enable input
+ * local: enable signals, erase/kill processing, echo on.
+ */
+IF{ISTRIP} m->tio.c_iflag |= ISTRIP;
+IF{IXON} m->tio.c_iflag |= IXON;
+
+ if (!ttyflag) /* may not even be good for ptys.. */
+ {
+IF{OPOST} m->tio.c_oflag |= OPOST;
+IF{ICRNL} m->tio.c_iflag |= ICRNL;
+IF{ONLCR} m->tio.c_oflag |= ONLCR;
+IF{TAB3} m->tio.c_oflag |= TAB3;
+ }
+
+#ifdef __bsdi__
+ )-: cannot handle BSDI without POSIX
+#else
+IF{B9600} m->tio.c_cflag = B9600;
+#endif
+IF{CS8} m->tio.c_cflag |= CS8;
+IF{CREAD} m->tio.c_cflag |= CREAD;
+
+ if (!ttyflag)
+ {
+IF{ISIG} m->tio.c_lflag |= ISIG;
+IF{ICANON} m->tio.c_lflag |= ICANON;
+IF{ECHO} m->tio.c_lflag |= ECHO;
+ }
+IF{ECHOE} m->tio.c_lflag |= ECHOE;
+IF{ECHOK} m->tio.c_lflag |= ECHOK;
+
+XIF{VINTR} m->tio.c_cc[VINTR] = Ctrl('C');
+XIF{VQUIT} m->tio.c_cc[VQUIT] = Ctrl('\\');
+XIF{VERASE} m->tio.c_cc[VERASE] = 0177; /* DEL */
+XIF{VKILL} m->tio.c_cc[VKILL] = Ctrl('U');
+XIF{VEOF} m->tio.c_cc[VEOF] = Ctrl('D');
+XIF{VEOL} m->tio.c_cc[VEOL] = VDISABLE;
+XIF{VEOL2} m->tio.c_cc[VEOL2] = VDISABLE;
+XIF{VSWTCH} m->tio.c_cc[VSWTCH] = VDISABLE;
+
+ if (ttyflag)
+ {
+ m->tio.c_cc[VMIN] = TTYVMIN;
+ m->tio.c_cc[VTIME] = TTYVTIME;
+ }
+
+# else /* TERMIO */
+ debug1("InitTTY: BSD: defaults a la SunOS 4.1.3 (%d)\n", ttyflag);
+ m->m_ttyb.sg_ispeed = B9600;
+ m->m_ttyb.sg_ospeed = B9600;
+ m->m_ttyb.sg_erase = 0177; /*DEL */
+ m->m_ttyb.sg_kill = Ctrl('U');
+ if (!ttyflag)
+ m->m_ttyb.sg_flags = CRMOD | ECHO
+IF{ANYP} | ANYP
+ ;
+ else
+ m->m_ttyb.sg_flags = CBREAK
+IF{ANYP} | ANYP
+ ;
+
+ m->m_tchars.t_intrc = Ctrl('C');
+ m->m_tchars.t_quitc = Ctrl('\\');
+ m->m_tchars.t_startc = Ctrl('Q');
+ m->m_tchars.t_stopc = Ctrl('S');
+ m->m_tchars.t_eofc = Ctrl('D');
+ m->m_tchars.t_brkc = -1;
+
+ m->m_ltchars.t_suspc = Ctrl('Z');
+ m->m_ltchars.t_dsuspc = Ctrl('Y');
+ m->m_ltchars.t_rprntc = Ctrl('R');
+ m->m_ltchars.t_flushc = Ctrl('O');
+ m->m_ltchars.t_werasc = Ctrl('W');
+ m->m_ltchars.t_lnextc = Ctrl('V');
+
+IF{NTTYDISC} m->m_ldisc = NTTYDISC;
+
+ m->m_lmode = 0
+IF{LDECCTQ} | LDECCTQ
+IF{LCTLECH} | LCTLECH
+IF{LPASS8} | LPASS8
+IF{LCRTKIL} | LCRTKIL
+IF{LCRTERA} | LCRTERA
+IF{LCRTBS} | LCRTBS
+ ;
+# endif /* TERMIO */
+#endif /* POSIX */
+
+#if defined(ENCODINGS) && defined(TIOCKSET)
+ m->m_jtchars.t_ascii = 'J';
+ m->m_jtchars.t_kanji = 'B';
+ m->m_knjmode = KM_ASCII | KM_SYSSJIS;
+#endif
+}
+
+void
+SetTTY(fd, mp)
+int fd;
+struct mode *mp;
+{
+ errno = 0;
+#ifdef POSIX
+ tcsetattr(fd, TCSADRAIN, &mp->tio);
+# ifdef HPUX_LTCHARS_HACK
+ ioctl(fd, TIOCSLTC, (char *)&mp->m_ltchars);
+# endif
+#else
+# ifdef TERMIO
+ ioctl(fd, TCSETAW, (char *)&mp->tio);
+# ifdef CYTERMIO
+ if (mp->tio.c_line == 3)
+ {
+ ioctl(fd, LDSETMAPKEY, (char *)&mp->m_mapkey);
+ ioctl(fd, LDSETMAPSCREEN, (char *)&mp->m_mapscreen);
+ ioctl(fd, LDSETBACKSPACE, (char *)&mp->m_backspace);
+ }
+# endif
+# else
+ /* ioctl(fd, TIOCSETP, (char *)&mp->m_ttyb); */
+ ioctl(fd, TIOCSETC, (char *)&mp->m_tchars);
+ ioctl(fd, TIOCLSET, (char *)&mp->m_lmode);
+ ioctl(fd, TIOCSETD, (char *)&mp->m_ldisc);
+ ioctl(fd, TIOCSETP, (char *)&mp->m_ttyb);
+ ioctl(fd, TIOCSLTC, (char *)&mp->m_ltchars); /* moved here for apollo. jw */
+# endif
+#endif
+#if defined(ENCODINGS) && defined(TIOCKSET)
+ ioctl(fd, TIOCKSETC, &mp->m_jtchars);
+ ioctl(fd, TIOCKSET, &mp->m_knjmode);
+#endif
+ if (errno)
+ Msg(errno, "SetTTY (fd %d): ioctl failed", fd);
+}
+
+void
+GetTTY(fd, mp)
+int fd;
+struct mode *mp;
+{
+ errno = 0;
+#ifdef POSIX
+ tcgetattr(fd, &mp->tio);
+# ifdef HPUX_LTCHARS_HACK
+ ioctl(fd, TIOCGLTC, (char *)&mp->m_ltchars);
+# endif
+#else
+# ifdef TERMIO
+ ioctl(fd, TCGETA, (char *)&mp->tio);
+# ifdef CYTERMIO
+ if (mp->tio.c_line == 3)
+ {
+ ioctl(fd, LDGETMAPKEY, (char *)&mp->m_mapkey);
+ ioctl(fd, LDGETMAPSCREEN, (char *)&mp->m_mapscreen);
+ ioctl(fd, LDGETBACKSPACE, (char *)&mp->m_backspace);
+ }
+ else
+ {
+ mp->m_mapkey = NOMAPKEY;
+ mp->m_mapscreen = NOMAPSCREEN;
+ mp->m_backspace = '\b';
+ }
+# endif
+# else
+ ioctl(fd, TIOCGETP, (char *)&mp->m_ttyb);
+ ioctl(fd, TIOCGETC, (char *)&mp->m_tchars);
+ ioctl(fd, TIOCGLTC, (char *)&mp->m_ltchars);
+ ioctl(fd, TIOCLGET, (char *)&mp->m_lmode);
+ ioctl(fd, TIOCGETD, (char *)&mp->m_ldisc);
+# endif
+#endif
+#if defined(ENCODINGS) && defined(TIOCKSET)
+ ioctl(fd, TIOCKGETC, &mp->m_jtchars);
+ ioctl(fd, TIOCKGET, &mp->m_knjmode);
+#endif
+ if (errno)
+ Msg(errno, "GetTTY (fd %d): ioctl failed", fd);
+}
+
+/*
+ * needs interrupt = iflag and flow = d->d_flow
+ */
+void
+SetMode(op, np, flow, interrupt)
+struct mode *op, *np;
+int flow, interrupt;
+{
+ *np = *op;
+
+ ASSERT(display);
+#if defined(TERMIO) || defined(POSIX)
+# ifdef CYTERMIO
+ np->m_mapkey = NOMAPKEY;
+ np->m_mapscreen = NOMAPSCREEN;
+ np->tio.c_line = 0;
+# endif
+IF{ICRNL} np->tio.c_iflag &= ~ICRNL;
+IF{ISTRIP} np->tio.c_iflag &= ~ISTRIP;
+IF{ONLCR} np->tio.c_oflag &= ~ONLCR;
+ np->tio.c_lflag &= ~(ICANON | ECHO);
+ /*
+ * From Andrew Myers (andru@tonic.lcs.mit.edu)
+ * to avoid ^V^V-Problem on OSF1
+ */
+IF{IEXTEN} np->tio.c_lflag &= ~IEXTEN;
+
+ /*
+ * Unfortunately, the master process never will get SIGINT if the real
+ * terminal is different from the one on which it was originaly started
+ * (process group membership has not been restored or the new tty could not
+ * be made controlling again). In my solution, it is the attacher who
+ * receives SIGINT (because it is always correctly associated with the real
+ * tty) and forwards it to the master [kill(MasterPid, SIGINT)].
+ * Marc Boucher (marc@CAM.ORG)
+ */
+ if (interrupt)
+ np->tio.c_lflag |= ISIG;
+ else
+ np->tio.c_lflag &= ~ISIG;
+ /*
+ * careful, careful catche monkey..
+ * never set VMIN and VTIME to zero, if you want blocking io.
+ *
+ * We may want to do a VMIN > 0, VTIME > 0 read on the ptys too, to
+ * reduce interrupt frequency. But then we would not know how to
+ * handle read returning 0. jw.
+ */
+ np->tio.c_cc[VMIN] = 1;
+ np->tio.c_cc[VTIME] = 0;
+ if (!interrupt || !flow)
+ np->tio.c_cc[VINTR] = VDISABLE;
+ np->tio.c_cc[VQUIT] = VDISABLE;
+ if (flow == 0)
+ {
+XIF{VSTART} np->tio.c_cc[VSTART] = VDISABLE;
+XIF{VSTOP} np->tio.c_cc[VSTOP] = VDISABLE;
+ np->tio.c_iflag &= ~IXON;
+ }
+XIF{VDISCARD} np->tio.c_cc[VDISCARD] = VDISABLE;
+XIF{VLNEXT} np->tio.c_cc[VLNEXT] = VDISABLE;
+XIF{VSTATUS} np->tio.c_cc[VSTATUS] = VDISABLE;
+XIF{VSUSP} np->tio.c_cc[VSUSP] = VDISABLE;
+ /* Set VERASE to DEL, rather than VDISABLE, to avoid libvte
+ "autodetect" issues. */
+XIF{VERASE} np->tio.c_cc[VERASE] = 0x7f;
+XIF{VKILL} np->tio.c_cc[VKILL] = VDISABLE;
+# ifdef HPUX_LTCHARS_HACK
+ np->m_ltchars.t_suspc = VDISABLE;
+ np->m_ltchars.t_dsuspc = VDISABLE;
+ np->m_ltchars.t_rprntc = VDISABLE;
+ np->m_ltchars.t_flushc = VDISABLE;
+ np->m_ltchars.t_werasc = VDISABLE;
+ np->m_ltchars.t_lnextc = VDISABLE;
+# else /* HPUX_LTCHARS_HACK */
+XIF{VDSUSP} np->tio.c_cc[VDSUSP] = VDISABLE;
+XIF{VREPRINT} np->tio.c_cc[VREPRINT] = VDISABLE;
+XIF{VWERASE} np->tio.c_cc[VWERASE] = VDISABLE;
+# endif /* HPUX_LTCHARS_HACK */
+#else /* TERMIO || POSIX */
+ if (!interrupt || !flow)
+ np->m_tchars.t_intrc = -1;
+ np->m_ttyb.sg_flags &= ~(CRMOD | ECHO);
+ np->m_ttyb.sg_flags |= CBREAK;
+# if defined(CYRILL) && defined(CSTYLE) && defined(CS_8BITS)
+ np->m_ttyb.sg_flags &= ~CSTYLE;
+ np->m_ttyb.sg_flags |= CS_8BITS;
+# endif
+ np->m_tchars.t_quitc = -1;
+ if (flow == 0)
+ {
+ np->m_tchars.t_startc = -1;
+ np->m_tchars.t_stopc = -1;
+ }
+ np->m_ltchars.t_suspc = -1;
+ np->m_ltchars.t_dsuspc = -1;
+ np->m_ltchars.t_flushc = -1;
+ np->m_ltchars.t_lnextc = -1;
+#endif /* defined(TERMIO) || defined(POSIX) */
+}
+
+/* operates on display */
+void
+SetFlow(on)
+int on;
+{
+ ASSERT(display);
+ if (D_flow == on)
+ return;
+#if defined(TERMIO) || defined(POSIX)
+ if (on)
+ {
+ D_NewMode.tio.c_cc[VINTR] = iflag ? D_OldMode.tio.c_cc[VINTR] : VDISABLE;
+XIF{VSTART} D_NewMode.tio.c_cc[VSTART] = D_OldMode.tio.c_cc[VSTART];
+XIF{VSTOP} D_NewMode.tio.c_cc[VSTOP] = D_OldMode.tio.c_cc[VSTOP];
+ D_NewMode.tio.c_iflag |= D_OldMode.tio.c_iflag & IXON;
+ }
+ else
+ {
+ D_NewMode.tio.c_cc[VINTR] = VDISABLE;
+XIF{VSTART} D_NewMode.tio.c_cc[VSTART] = VDISABLE;
+XIF{VSTOP} D_NewMode.tio.c_cc[VSTOP] = VDISABLE;
+ D_NewMode.tio.c_iflag &= ~IXON;
+ }
+# ifdef POSIX
+# ifdef TCOON
+ if (!on)
+ tcflow(D_userfd, TCOON);
+# endif
+ if (tcsetattr(D_userfd, TCSANOW, &D_NewMode.tio))
+# else
+ if (ioctl(D_userfd, TCSETAW, (char *)&D_NewMode.tio) != 0)
+# endif
+ debug1("SetFlow: ioctl errno %d\n", errno);
+#else /* POSIX || TERMIO */
+ if (on)
+ {
+ D_NewMode.m_tchars.t_intrc = iflag ? D_OldMode.m_tchars.t_intrc : -1;
+ D_NewMode.m_tchars.t_startc = D_OldMode.m_tchars.t_startc;
+ D_NewMode.m_tchars.t_stopc = D_OldMode.m_tchars.t_stopc;
+ }
+ else
+ {
+ D_NewMode.m_tchars.t_intrc = -1;
+ D_NewMode.m_tchars.t_startc = -1;
+ D_NewMode.m_tchars.t_stopc = -1;
+ }
+ if (ioctl(D_userfd, TIOCSETC, (char *)&D_NewMode.m_tchars) != 0)
+ debug1("SetFlow: ioctl errno %d\n", errno);
+#endif /* POSIX || TERMIO */
+ D_flow = on;
+}
+
+/* parse commands from opt and modify m */
+int
+SttyMode(m, opt)
+struct mode *m;
+char *opt;
+{
+ static const char sep[] = " \t:;,";
+
+ if (!opt)
+ return 0;
+
+ while (*opt)
+ {
+ while (index(sep, *opt)) opt++;
+ if (*opt >= '0' && *opt <= '9')
+ {
+ if (SetBaud(m, atoi(opt), atoi(opt)))
+ return -1;
+ }
+ else if (!strncmp("cs7", opt, 3))
+ {
+#if defined(POSIX) || defined(TERMIO)
+ m->tio.c_cflag &= ~CSIZE;
+ m->tio.c_cflag |= CS7;
+#else
+ m->m_lmode &= ~LPASS8;
+#endif
+ }
+ else if (!strncmp("cs8", opt, 3))
+ {
+#if defined(POSIX) || defined(TERMIO)
+ m->tio.c_cflag &= ~CSIZE;
+ m->tio.c_cflag |= CS8;
+#else
+ m->m_lmode |= LPASS8;
+#endif
+ }
+ else if (!strncmp("istrip", opt, 6))
+ {
+#if defined(POSIX) || defined(TERMIO)
+ m->tio.c_iflag |= ISTRIP;
+#else
+ m->m_lmode &= ~LPASS8;
+#endif
+ }
+ else if (!strncmp("-istrip", opt, 7))
+ {
+#if defined(POSIX) || defined(TERMIO)
+ m->tio.c_iflag &= ~ISTRIP;
+#else
+ m->m_lmode |= LPASS8;
+#endif
+ }
+ else if (!strncmp("ixon", opt, 4))
+ {
+#if defined(POSIX) || defined(TERMIO)
+ m->tio.c_iflag |= IXON;
+#else
+ debug("SttyMode: no ixon in old bsd land.\n");
+#endif
+ }
+ else if (!strncmp("-ixon", opt, 5))
+ {
+#if defined(POSIX) || defined(TERMIO)
+ m->tio.c_iflag &= ~IXON;
+#else
+ debug("SttyMode: no -ixon in old bsd land.\n");
+#endif
+ }
+ else if (!strncmp("ixoff", opt, 5))
+ {
+#if defined(POSIX) || defined(TERMIO)
+ m->tio.c_iflag |= IXOFF;
+#else
+ m->m_ttyb.sg_flags |= TANDEM;
+#endif
+ }
+ else if (!strncmp("-ixoff", opt, 6))
+ {
+#if defined(POSIX) || defined(TERMIO)
+ m->tio.c_iflag &= ~IXOFF;
+#else
+ m->m_ttyb.sg_flags &= ~TANDEM;
+#endif
+ }
+ else if (!strncmp("crtscts", opt, 7))
+ {
+#if (defined(POSIX) || defined(TERMIO)) && defined(CRTSCTS)
+ m->tio.c_cflag |= CRTSCTS;
+#endif
+ }
+ else if (!strncmp("-crtscts", opt, 8))
+ {
+#if (defined(POSIX) || defined(TERMIO)) && defined(CRTSCTS)
+ m->tio.c_cflag &= ~CRTSCTS;
+#endif
+ }
+ else
+ return -1;
+ while (*opt && !index(sep, *opt)) opt++;
+ }
+ return 0;
+}
+
+/*
+ * Job control handling
+ *
+ * Somehow the ultrix session handling is broken, so use
+ * the bsdish variant.
+ */
+
+/*ARGSUSED*/
+void
+brktty(fd)
+int fd;
+{
+#if defined(POSIX) && !defined(ultrix)
+ if (separate_sids)
+ setsid(); /* will break terminal affiliation */
+ /* GNU added for Hurd systems 2001-10-10 */
+# if defined(BSD) && defined(TIOCSCTTY) && !defined(__GNU__)
+ ioctl(fd, TIOCSCTTY, (char *)0);
+# endif /* BSD && TIOCSCTTY */
+#else /* POSIX */
+# ifdef SYSV
+ if (separate_sids)
+ setpgrp(); /* will break terminal affiliation */
+# else /* SYSV */
+# ifdef BSDJOBS
+ int devtty;
+
+ if ((devtty = open("/dev/tty", O_RDWR | O_NONBLOCK)) >= 0)
+ {
+ if (ioctl(devtty, TIOCNOTTY, (char *)0))
+ debug2("brktty: ioctl(devtty=%d, TIOCNOTTY, 0) = %d\n", devtty, errno);
+ close(devtty);
+ }
+# endif /* BSDJOBS */
+# endif /* SYSV */
+#endif /* POSIX */
+}
+
+int
+fgtty(fd)
+int fd;
+{
+#ifdef BSDJOBS
+ int mypid;
+
+ mypid = getpid();
+
+ /*
+ * Under BSD we have to set the controlling terminal again explicitly.
+ */
+# if (defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__GNU__)) && defined(TIOCSCTTY)
+ ioctl(fd, TIOCSCTTY, (char *)0);
+# endif
+
+# ifdef POSIX
+ if (separate_sids)
+ if (tcsetpgrp(fd, mypid))
+ {
+ debug1("fgtty: tcsetpgrp: %d\n", errno);
+ return -1;
+ }
+# else /* POSIX */
+ if (ioctl(fd, TIOCSPGRP, (char *)&mypid) != 0)
+ debug1("fgtty: TIOSETPGRP: %d\n", errno);
+# ifndef SYSV /* Already done in brktty():setpgrp() */
+ if (separate_sids)
+ if (setpgrp(fd, mypid))
+ debug1("fgtty: setpgrp: %d\n", errno);
+# endif
+# endif /* POSIX */
+#endif /* BSDJOBS */
+ return 0;
+}
+
+/*
+ * The alm boards on our sparc center 1000 have a lousy driver.
+ * We cannot generate long breaks unless we use the most ugly form
+ * of ioctls. jw.
+ */
+#ifdef POSIX
+int breaktype = 2;
+#else /* POSIX */
+# ifdef TCSBRK
+int breaktype = 1;
+# else
+int breaktype = 0;
+# endif
+#endif /* POSIX */
+
+#if defined(sun) && !defined(SVR4)
+# define HAVE_SUPER_TCSENDBREAK
+#endif
+
+/*
+ * type:
+ * 0: TIOCSBRK / TIOCCBRK
+ * 1: TCSBRK
+ * 2: tcsendbreak()
+ * n: approximate duration in 1/4 seconds.
+ */
+static void
+DoSendBreak(fd, n, type)
+int fd, n, type;
+{
+ switch (type)
+ {
+ case 2: /* tcsendbreak() =============================== */
+#ifdef POSIX
+# ifdef HAVE_SUPER_TCSENDBREAK
+ /* There is one rare case that I have tested, where tcsendbreak works
+ * really great: this was an alm driver that came with SunOS 4.1.3
+ * If you have this one, define the above symbol.
+ * here we can use the second parameter to specify the duration.
+ */
+ debug2("tcsendbreak(fd=%d, %d)\n", fd, n);
+ if (tcsendbreak(fd, n) < 0)
+ Msg(errno, "cannot send BREAK (tcsendbreak)");
+# else
+ /*
+ * here we hope, that multiple calls to tcsendbreak() can
+ * be concatenated to form a long break, as we do not know
+ * what exact interpretation the second parameter has:
+ *
+ * - sunos 4: duration in quarter seconds
+ * - sunos 5: 0 a short break, nonzero a tcdrain()
+ * - hpux, irix: ignored
+ * - mot88: duration in milliseconds
+ * - aix: duration in milliseconds, but 0 is 25 milliseconds.
+ */
+ debug2("%d * tcsendbreak(fd=%d, 0)\n", n, fd);
+ {
+ int i;
+
+ if (!n)
+ n++;
+ for (i = 0; i < n; i++)
+ if (tcsendbreak(fd, 0) < 0)
+ {
+ Msg(errno, "cannot send BREAK (tcsendbreak SVR4)");
+ return;
+ }
+ }
+# endif
+#else /* POSIX */
+ Msg(0, "tcsendbreak() not available, change breaktype");
+#endif /* POSIX */
+ break;
+
+ case 1: /* TCSBRK ======================================= */
+#ifdef TCSBRK
+ if (!n)
+ n++;
+ /*
+ * Here too, we assume that short breaks can be concatenated to
+ * perform long breaks. But for SOLARIS, this is not true, of course.
+ */
+ debug2("%d * TCSBRK fd=%d\n", n, fd);
+ {
+ int i;
+
+ for (i = 0; i < n; i++)
+ if (ioctl(fd, TCSBRK, (char *)0) < 0)
+ {
+ Msg(errno, "Cannot send BREAK (TCSBRK)");
+ return;
+ }
+ }
+#else /* TCSBRK */
+ Msg(0, "TCSBRK not available, change breaktype");
+#endif /* TCSBRK */
+ break;
+
+ case 0: /* TIOCSBRK / TIOCCBRK ========================== */
+#if defined(TIOCSBRK) && defined(TIOCCBRK)
+ /*
+ * This is very rude. Screen actively celebrates the break.
+ * But it may be the only save way to issue long breaks.
+ */
+ debug("TIOCSBRK TIOCCBRK\n");
+ if (ioctl(fd, TIOCSBRK, (char *)0) < 0)
+ {
+ Msg(errno, "Can't send BREAK (TIOCSBRK)");
+ return;
+ }
+ sleep1000(n ? n * 250 : 250);
+ if (ioctl(fd, TIOCCBRK, (char *)0) < 0)
+ {
+ Msg(errno, "BREAK stuck!!! -- HELP! (TIOCCBRK)");
+ return;
+ }
+#else /* TIOCSBRK && TIOCCBRK */
+ Msg(0, "TIOCSBRK/CBRK not available, change breaktype");
+#endif /* TIOCSBRK && TIOCCBRK */
+ break;
+
+ default: /* unknown ========================== */
+ Msg(0, "Internal SendBreak error: method %d unknown", type);
+ }
+}
+
+/*
+ * Send a break for n * 0.25 seconds. Tty must be PLAIN.
+ * The longest possible break allowed here is 15 seconds.
+ */
+
+void
+SendBreak(wp, n, closeopen)
+struct win *wp;
+int n, closeopen;
+{
+ sigret_t (*sigalrm)__P(SIGPROTOARG);
+
+#ifdef BUILTIN_TELNET
+ if (wp->w_type == W_TYPE_TELNET)
+ {
+ TelBreak(wp);
+ return;
+ }
+#endif
+ if (wp->w_type != W_TYPE_PLAIN)
+ return;
+
+ debug3("break(%d, %d) fd %d\n", n, closeopen, wp->w_ptyfd);
+
+#ifdef POSIX
+ (void) tcflush(wp->w_ptyfd, TCIOFLUSH);
+#else
+# ifdef TIOCFLUSH
+ (void) ioctl(wp->w_ptyfd, TIOCFLUSH, (char *)0);
+# endif /* TIOCFLUSH */
+#endif /* POSIX */
+
+ if (closeopen)
+ {
+ close(wp->w_ptyfd);
+ sleep1000(n ? n * 250 : 250);
+ if ((wp->w_ptyfd = OpenTTY(wp->w_tty, wp->w_cmdargs[1])) < 1)
+ {
+ Msg(0, "Ouch, cannot reopen line %s, please try harder", wp->w_tty);
+ return;
+ }
+ (void) fcntl(wp->w_ptyfd, F_SETFL, FNBLOCK);
+ }
+ else
+ {
+ sigalrm = signal(SIGALRM, SigAlrmDummy);
+ alarm(15);
+
+ DoSendBreak(wp->w_ptyfd, n, breaktype);
+
+ alarm(0);
+ signal(SIGALRM, sigalrm);
+ }
+ debug(" broken.\n");
+}
+
+/*
+ * Console grabbing
+ */
+
+#if (!defined(TIOCCONS) && defined(SRIOCSREDIR)) || defined(linux)
+
+static struct event consredir_ev;
+static int consredirfd[2] = {-1, -1};
+
+static void
+consredir_readev_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ char *p, *n, buf[256];
+ int l;
+
+ if (!console_window || (l = read(consredirfd[0], buf, sizeof(buf))) <= 0)
+ {
+ close(consredirfd[0]);
+ close(consredirfd[1]);
+ consredirfd[0] = consredirfd[1] = -1;
+ evdeq(ev);
+ return;
+ }
+ for (p = n = buf; l > 0; n++, l--)
+ if (*n == '\n')
+ {
+ if (n > p)
+ WriteString(console_window, p, n - p);
+ WriteString(console_window, "\r\n", 2);
+ p = n + 1;
+ }
+ if (n > p)
+ WriteString(console_window, p, n - p);
+}
+
+#endif
+
+/*ARGSUSED*/
+int
+TtyGrabConsole(fd, on, rc_name)
+int fd, on;
+char *rc_name;
+{
+#if defined(TIOCCONS) && !defined(linux)
+ struct display *d;
+ int ret = 0;
+ int sfd = -1;
+
+ if (on < 0)
+ return 0; /* pty close will ungrab */
+ if (on)
+ {
+ if (displays == 0)
+ {
+ Msg(0, "I need a display");
+ return -1;
+ }
+ for (d = displays; d; d = d->d_next)
+ if (strcmp(d->d_usertty, "/dev/console") == 0)
+ break;
+ if (d)
+ {
+ Msg(0, "too dangerous - screen is running on /dev/console");
+ return -1;
+ }
+ }
+
+ if (!on)
+ {
+ char *slave;
+ if ((fd = OpenPTY(&slave)) < 0)
+ {
+ Msg(errno, "%s: could not open detach pty master", rc_name);
+ return -1;
+ }
+ if ((sfd = open(slave, O_RDWR | O_NOCTTY)) < 0)
+ {
+ Msg(errno, "%s: could not open detach pty slave", rc_name);
+ close(fd);
+ return -1;
+ }
+ }
+ if (UserContext() == 1)
+ UserReturn(ioctl(fd, TIOCCONS, (char *)&on));
+ ret = UserStatus();
+ if (ret)
+ Msg(errno, "%s: ioctl TIOCCONS failed", rc_name);
+ if (!on)
+ {
+ close(sfd);
+ close(fd);
+ }
+ return ret;
+
+#else
+# if defined(SRIOCSREDIR) || defined(linux)
+ struct display *d;
+# ifdef SRIOCSREDIR
+ int cfd;
+# else
+ struct mode new1, new2;
+ char *slave;
+# endif
+
+ if (on > 0)
+ {
+ if (displays == 0)
+ {
+ Msg(0, "I need a display");
+ return -1;
+ }
+ for (d = displays; d; d = d->d_next)
+ if (strcmp(d->d_usertty, "/dev/console") == 0)
+ break;
+ if (d)
+ {
+ Msg(0, "too dangerous - screen is running on /dev/console");
+ return -1;
+ }
+ }
+ if (consredirfd[0] >= 0)
+ {
+ evdeq(&consredir_ev);
+ close(consredirfd[0]);
+ close(consredirfd[1]);
+ consredirfd[0] = consredirfd[1] = -1;
+ }
+ if (on <= 0)
+ return 0;
+# ifdef SRIOCSREDIR
+ if ((cfd = secopen("/dev/console", O_RDWR|O_NOCTTY, 0)) == -1)
+ {
+ Msg(errno, "/dev/console");
+ return -1;
+ }
+ if (pipe(consredirfd))
+ {
+ Msg(errno, "pipe");
+ close(cfd);
+ consredirfd[0] = consredirfd[1] = -1;
+ return -1;
+ }
+ if (ioctl(cfd, SRIOCSREDIR, consredirfd[1]))
+ {
+ Msg(errno, "SRIOCSREDIR ioctl");
+ close(cfd);
+ close(consredirfd[0]);
+ close(consredirfd[1]);
+ consredirfd[0] = consredirfd[1] = -1;
+ return -1;
+ }
+ close(cfd);
+# else
+ /* special linux workaround for a too restrictive kernel */
+ if ((consredirfd[0] = OpenPTY(&slave)) < 0)
+ {
+ Msg(errno, "%s: could not open detach pty master", rc_name);
+ return -1;
+ }
+ if ((consredirfd[1] = open(slave, O_RDWR | O_NOCTTY)) < 0)
+ {
+ Msg(errno, "%s: could not open detach pty slave", rc_name);
+ close(consredirfd[0]);
+ return -1;
+ }
+ InitTTY(&new1, 0);
+ SetMode(&new1, &new2, 0, 0);
+ SetTTY(consredirfd[1], &new2);
+ if (UserContext() == 1)
+ UserReturn(ioctl(consredirfd[1], TIOCCONS, (char *)&on));
+ if (UserStatus())
+ {
+ Msg(errno, "%s: ioctl TIOCCONS failed", rc_name);
+ close(consredirfd[0]);
+ close(consredirfd[1]);
+ return -1;
+ }
+# endif
+ consredir_ev.fd = consredirfd[0];
+ consredir_ev.type = EV_READ;
+ consredir_ev.handler = consredir_readev_fn;
+ evenq(&consredir_ev);
+ return 0;
+# else
+ if (on > 0)
+ Msg(0, "%s: don't know how to grab the console", rc_name);
+ return -1;
+# endif
+#endif
+}
+
+/*
+ * Read modem control lines of a physical tty and write them to buf
+ * in a readable format.
+ * Will not write more than 256 characters to buf.
+ * Returns buf;
+ */
+char *
+TtyGetModemStatus(fd, buf)
+int fd;
+char *buf;
+{
+ char *p = buf;
+#ifdef TIOCGSOFTCAR
+ unsigned int softcar;
+#endif
+#if defined(TIOCMGET) || defined(TIOCMODG)
+ unsigned int mflags;
+#else
+# ifdef MCGETA
+ /* this is yet another interface, found on hpux. grrr */
+ mflag mflags;
+IF{MDTR}# define TIOCM_DTR MDTR
+IF{MRTS}# define TIOCM_RTS MRTS
+IF{MDSR}# define TIOCM_DSR MDSR
+IF{MDCD}# define TIOCM_CAR MDCD
+IF{MRI}# define TIOCM_RNG MRI
+IF{MCTS}# define TIOCM_CTS MCTS
+# endif
+#endif
+#if defined(CLOCAL) || defined(CRTSCTS)
+ struct mode mtio; /* screen.h */
+#endif
+#if defined(CRTSCTS) || defined(TIOCM_CTS)
+ int rtscts;
+#endif
+ int clocal;
+
+#if defined(CLOCAL) || defined(CRTSCTS)
+ GetTTY(fd, &mtio);
+#endif
+ clocal = 0;
+#ifdef CLOCAL
+ if (mtio.tio.c_cflag & CLOCAL)
+ {
+ clocal = 1;
+ *p++ = '{';
+ }
+#endif
+
+#ifdef TIOCM_CTS
+# ifdef CRTSCTS
+ if (!(mtio.tio.c_cflag & CRTSCTS))
+ rtscts = 0;
+ else
+# endif /* CRTSCTS */
+ rtscts = 1;
+#endif /* TIOCM_CTS */
+
+#ifdef TIOCGSOFTCAR
+ if (ioctl(fd, TIOCGSOFTCAR, (char *)&softcar) < 0)
+ softcar = 0;
+#endif
+
+#if defined(TIOCMGET) || defined(TIOCMODG) || defined(MCGETA)
+# ifdef TIOCMGET
+ if (ioctl(fd, TIOCMGET, (char *)&mflags) < 0)
+# else
+# ifdef TIOCMODG
+ if (ioctl(fd, TIOCMODG, (char *)&mflags) < 0)
+# else
+ if (ioctl(fd, MCGETA, &mflags) < 0)
+# endif
+# endif
+ {
+#ifdef TIOCGSOFTCAR
+ sprintf(p, "NO-TTY? %s", softcar ? "(CD)" : "CD");
+#else
+ sprintf(p, "NO-TTY?");
+#endif
+ p += strlen(p);
+ }
+ else
+ {
+ char *s;
+# ifdef FANCY_MODEM
+# ifdef TIOCM_LE
+ if (!(mflags & TIOCM_LE))
+ for (s = "!LE "; *s; *p++ = *s++);
+# endif
+# endif /* FANCY_MODEM */
+
+# ifdef TIOCM_RTS
+ s = "!RTS "; if (mflags & TIOCM_RTS) s++;
+ while (*s) *p++ = *s++;
+# endif
+# ifdef TIOCM_CTS
+ s = "!CTS ";
+ if (!rtscts)
+ {
+ *p++ = '(';
+ s = "!CTS) ";
+ }
+ if (mflags & TIOCM_CTS) s++;
+ while (*s) *p++ = *s++;
+# endif
+
+# ifdef TIOCM_DTR
+ s = "!DTR "; if (mflags & TIOCM_DTR) s++;
+ while (*s) *p++ = *s++;
+# endif
+# ifdef TIOCM_DSR
+ s = "!DSR "; if (mflags & TIOCM_DSR) s++;
+ while (*s) *p++ = *s++;
+# endif
+# if defined(TIOCM_CD) || defined(TIOCM_CAR)
+ s = "!CD ";
+# ifdef TIOCGSOFTCAR
+ if (softcar)
+ {
+ *p++ = '(';
+ s = "!CD) ";
+ }
+# endif
+# ifdef TIOCM_CD
+ if (mflags & TIOCM_CD) s++;
+# else
+ if (mflags & TIOCM_CAR) s++;
+# endif
+ while (*s) *p++ = *s++;
+# endif
+# if defined(TIOCM_RI) || defined(TIOCM_RNG)
+# ifdef TIOCM_RI
+ if (mflags & TIOCM_RI)
+# else
+ if (mflags & TIOCM_RNG)
+# endif
+ for (s = "RI "; *s; *p++ = *s++);
+# endif
+# ifdef FANCY_MODEM
+# ifdef TIOCM_ST
+ s = "!ST "; if (mflags & TIOCM_ST) s++;
+ while (*s) *p++ = *s++;
+# endif
+# ifdef TIOCM_SR
+ s = "!SR "; if (mflags & TIOCM_SR) s++;
+ while (*s) *p++ = *s++;
+# endif
+# endif /* FANCY_MODEM */
+ if (p > buf && p[-1] == ' ')
+ p--;
+ *p = '\0';
+ }
+#else
+# ifdef TIOCGSOFTCAR
+ sprintf(p, " %s", softcar ? "(CD)", "CD");
+ p += strlen(p);
+# endif
+#endif
+ if (clocal)
+ *p++ = '}';
+ *p = '\0';
+ return buf;
+}
+
+/*
+ * Old bsd-ish machines may not have any of the baudrate B... symbols.
+ * We hope to detect them here, so that the btable[] below always has
+ * many entries.
+ */
+#ifndef POSIX
+# ifndef TERMIO
+# if !defined(B9600) && !defined(B2400) && !defined(B1200) && !defined(B300)
+IFN{B0}#define B0 0
+IFN{B50}#define B50 1
+IFN{B75}#define B75 2
+IFN{B110}#define B110 3
+IFN{B134}#define B134 4
+IFN{B150}#define B150 5
+IFN{B200}#define B200 6
+IFN{B300}#define B300 7
+IFN{B600}#define B600 8
+IFN{B1200}#define B1200 9
+IFN{B1800}#define B1800 10
+IFN{B2400}#define B2400 11
+IFN{B4800}#define B4800 12
+IFN{B9600}#define B9600 13
+IFN{EXTA}#define EXTA 14
+IFN{EXTB}#define EXTB 15
+# endif
+# endif
+#endif
+
+/*
+ * On hpux, idx and sym will be different.
+ * Rumor has it that, we need idx in D_dospeed to make tputs
+ * padding correct.
+ * Frequently used entries come first.
+ */
+static struct baud_values btable[] =
+{
+IF{B4000000} { 33, 4000000, B4000000},
+IF{B3500000} { 32, 3500000, B3500000},
+IF{B3000000} { 31, 3000000, B3000000},
+IF{B2500000} { 30, 2500000, B2500000},
+IF{B2000000} { 29, 2000000, B2000000},
+IF{B1500000} { 28, 1500000, B1500000},
+IF{B1152000} { 27, 1152000, B1152000},
+IF{B1000000} { 26, 1000000, B1000000},
+IF{B921600} { 25, 921600, B921600 },
+IF{B576000} { 24, 576000, B576000 },
+IF{B500000} { 23, 500000, B500000 },
+IF{B460800} { 22, 460800, B460800 },
+IF{B230400} { 21, 230400, B230400 },
+IF{B115200} { 20, 115200, B115200 },
+IF{B57600} { 19, 57600, B57600 },
+IF{EXTB} { 18, 38400, EXTB },
+IF{B38400} { 18, 38400, B38400 },
+IF{EXTA} { 17, 19200, EXTA },
+IF{B19200} { 17, 19200, B19200 },
+IF{B9600} { 16, 9600, B9600 },
+IF{B7200} { 15, 7200, B7200 },
+IF{B4800} { 14, 4800, B4800 },
+IF{B3600} { 13, 3600, B3600 },
+IF{B2400} { 12, 2400, B2400 },
+IF{B1800} { 11, 1800, B1800 },
+IF{B1200} { 10, 1200, B1200 },
+IF{B900} { 9, 900, B900 },
+IF{B600} { 8, 600, B600 },
+IF{B300} { 7, 300, B300 },
+IF{B200} { 6, 200, B200 },
+IF{B150} { 5, 150, B150 },
+IF{B134} { 4, 134, B134 },
+IF{B110} { 3, 110, B110 },
+IF{B75} { 2, 75, B75 },
+IF{B50} { 1, 50, B50 },
+IF{B0} { 0, 0, B0 },
+ { -1, -1, -1 }
+};
+
+/*
+ * baud may either be a bits-per-second value or a symbolic
+ * value as returned by cfget?speed()
+ */
+struct baud_values *
+lookup_baud(baud)
+int baud;
+{
+ struct baud_values *p;
+
+ for (p = btable; p->idx >= 0; p++)
+ if (baud == p->bps || baud == p->sym)
+ return p;
+ return NULL;
+}
+
+/*
+ * change the baud rate in a mode structure.
+ * ibaud and obaud are given in bit/second, or at your option as
+ * termio B... symbols as defined in e.g. suns sys/ttydev.h
+ * -1 means don't change.
+ */
+int
+SetBaud(m, ibaud, obaud)
+struct mode *m;
+int ibaud, obaud;
+{
+ struct baud_values *ip, *op;
+
+ if ((!(ip = lookup_baud(ibaud)) && ibaud != -1) ||
+ (!(op = lookup_baud(obaud)) && obaud != -1))
+ return -1;
+
+#ifdef POSIX
+ if (ip) cfsetispeed(&m->tio, ip->sym);
+ if (op) cfsetospeed(&m->tio, op->sym);
+#else /* POSIX */
+# ifdef TERMIO
+ if (ip)
+ {
+# ifdef IBSHIFT
+ m->tio.c_cflag &= ~(CBAUD << IBSHIFT);
+ m->tio.c_cflag |= (ip->sym & CBAUD) << IBSHIFT;
+# else /* IBSHIFT */
+ if (ibaud != obaud)
+ return -1;
+# endif /* IBSHIFT */
+ }
+ if (op)
+ {
+ m->tio.c_cflag &= ~CBAUD;
+ m->tio.c_cflag |= op->sym & CBAUD;
+ }
+# else /* TERMIO */
+ if (ip) m->m_ttyb.sg_ispeed = ip->idx;
+ if (op) m->m_ttyb.sg_ospeed = op->idx;
+# endif /* TERMIO */
+#endif /* POSIX */
+ return 0;
+}
+
+
+int
+CheckTtyname (tty)
+char *tty;
+{
+ struct stat st;
+ char realbuf[PATH_MAX];
+ const char *real;
+ int rc;
+
+ real = realpath(tty, realbuf);
+ if (!real)
+ return -1;
+ realbuf[sizeof(realbuf)-1]='\0';
+
+ if (lstat(real, &st) || !S_ISCHR(st.st_mode) ||
+ (st.st_nlink > 1 && strncmp(real, "/dev", 4)))
+ rc = -1;
+ else
+ rc = 0;
+
+ return rc;
+}
+
+/*
+ * Write out the mode struct in a readable form
+ */
+
+#ifdef DEBUG
+void
+DebugTTY(m)
+struct mode *m;
+{
+ int i;
+
+#ifdef POSIX
+ debug("struct termios tio:\n");
+ debug1("c_iflag = %#x\n", (unsigned int)m->tio.c_iflag);
+ debug1("c_oflag = %#x\n", (unsigned int)m->tio.c_oflag);
+ debug1("c_cflag = %#x\n", (unsigned int)m->tio.c_cflag);
+ debug1("c_lflag = %#x\n", (unsigned int)m->tio.c_lflag);
+ debug1("cfgetospeed() = %d\n", (int)cfgetospeed(&m->tio));
+ debug1("cfgetispeed() = %d\n", (int)cfgetispeed(&m->tio));
+ for (i = 0; i < sizeof(m->tio.c_cc)/sizeof(*m->tio.c_cc); i++)
+ {
+ debug2("c_cc[%d] = %#x\n", i, m->tio.c_cc[i]);
+ }
+# ifdef HPUX_LTCHARS_HACK
+ debug1("suspc = %#02x\n", m->m_ltchars.t_suspc);
+ debug1("dsuspc = %#02x\n", m->m_ltchars.t_dsuspc);
+ debug1("rprntc = %#02x\n", m->m_ltchars.t_rprntc);
+ debug1("flushc = %#02x\n", m->m_ltchars.t_flushc);
+ debug1("werasc = %#02x\n", m->m_ltchars.t_werasc);
+ debug1("lnextc = %#02x\n", m->m_ltchars.t_lnextc);
+# endif /* HPUX_LTCHARS_HACK */
+#else /* POSIX */
+# ifdef TERMIO
+ debug("struct termio tio:\n");
+ debug1("c_iflag = %04o\n", m->tio.c_iflag);
+ debug1("c_oflag = %04o\n", m->tio.c_oflag);
+ debug1("c_cflag = %04o\n", m->tio.c_cflag);
+ debug1("c_lflag = %04o\n", m->tio.c_lflag);
+ for (i = 0; i < sizeof(m->tio.c_cc)/sizeof(*m->tio.c_cc); i++)
+ {
+ debug2("c_cc[%d] = %04o\n", i, m->tio.c_cc[i]);
+ }
+# else /* TERMIO */
+ debug1("sg_ispeed = %d\n", m->m_ttyb.sg_ispeed);
+ debug1("sg_ospeed = %d\n", m->m_ttyb.sg_ospeed);
+ debug1("sg_erase = %#02x\n", m->m_ttyb.sg_erase);
+ debug1("sg_kill = %#02x\n", m->m_ttyb.sg_kill);
+ debug1("sg_flags = %#04x\n", (unsigned short)m->m_ttyb.sg_flags);
+ debug1("intrc = %#02x\n", m->m_tchars.t_intrc);
+ debug1("quitc = %#02x\n", m->m_tchars.t_quitc);
+ debug1("startc = %#02x\n", m->m_tchars.t_startc);
+ debug1("stopc = %#02x\n", m->m_tchars.t_stopc);
+ debug1("eofc = %#02x\n", m->m_tchars.t_eofc);
+ debug1("brkc = %#02x\n", m->m_tchars.t_brkc);
+ debug1("suspc = %#02x\n", m->m_ltchars.t_suspc);
+ debug1("dsuspc = %#02x\n", m->m_ltchars.t_dsuspc);
+ debug1("rprntc = %#02x\n", m->m_ltchars.t_rprntc);
+ debug1("flushc = %#02x\n", m->m_ltchars.t_flushc);
+ debug1("werasc = %#02x\n", m->m_ltchars.t_werasc);
+ debug1("lnextc = %#02x\n", m->m_ltchars.t_lnextc);
+ debug1("ldisc = %d\n", m->m_ldisc);
+ debug1("lmode = %#x\n", m->m_lmode);
+# endif /* TERMIO */
+#endif /* POSIX */
+}
+#endif /* DEBUG */
diff --git a/utf8encodings/01 b/utf8encodings/01
new file mode 100644
index 0000000..a6dde0f
--- /dev/null
+++ b/utf8encodings/01
Binary files differ
diff --git a/utf8encodings/02 b/utf8encodings/02
new file mode 100644
index 0000000..78a5cc0
--- /dev/null
+++ b/utf8encodings/02
Binary files differ
diff --git a/utf8encodings/03 b/utf8encodings/03
new file mode 100644
index 0000000..4c04358
--- /dev/null
+++ b/utf8encodings/03
Binary files differ
diff --git a/utf8encodings/04 b/utf8encodings/04
new file mode 100644
index 0000000..233f2ae
--- /dev/null
+++ b/utf8encodings/04
Binary files differ
diff --git a/utf8encodings/18 b/utf8encodings/18
new file mode 100644
index 0000000..9c7e9c0
--- /dev/null
+++ b/utf8encodings/18
Binary files differ
diff --git a/utf8encodings/19 b/utf8encodings/19
new file mode 100644
index 0000000..65167a6
--- /dev/null
+++ b/utf8encodings/19
Binary files differ
diff --git a/utf8encodings/a1 b/utf8encodings/a1
new file mode 100644
index 0000000..f39ce11
--- /dev/null
+++ b/utf8encodings/a1
Binary files differ
diff --git a/utf8encodings/bf b/utf8encodings/bf
new file mode 100644
index 0000000..397c128
--- /dev/null
+++ b/utf8encodings/bf
Binary files differ
diff --git a/utf8encodings/c2 b/utf8encodings/c2
new file mode 100644
index 0000000..58e8ffd
--- /dev/null
+++ b/utf8encodings/c2
Binary files differ
diff --git a/utf8encodings/c3 b/utf8encodings/c3
new file mode 100644
index 0000000..9407ed8
--- /dev/null
+++ b/utf8encodings/c3
Binary files differ
diff --git a/utf8encodings/c4 b/utf8encodings/c4
new file mode 100644
index 0000000..1dcd5fa
--- /dev/null
+++ b/utf8encodings/c4
Binary files differ
diff --git a/utf8encodings/c6 b/utf8encodings/c6
new file mode 100644
index 0000000..12159ca
--- /dev/null
+++ b/utf8encodings/c6
Binary files differ
diff --git a/utf8encodings/c7 b/utf8encodings/c7
new file mode 100644
index 0000000..e8f2b37
--- /dev/null
+++ b/utf8encodings/c7
Binary files differ
diff --git a/utf8encodings/c8 b/utf8encodings/c8
new file mode 100644
index 0000000..36a74b6
--- /dev/null
+++ b/utf8encodings/c8
Binary files differ
diff --git a/utf8encodings/cc b/utf8encodings/cc
new file mode 100644
index 0000000..fc16e8f
--- /dev/null
+++ b/utf8encodings/cc
Binary files differ
diff --git a/utf8encodings/cd b/utf8encodings/cd
new file mode 100644
index 0000000..b9d3e80
--- /dev/null
+++ b/utf8encodings/cd
Binary files differ
diff --git a/utf8encodings/d6 b/utf8encodings/d6
new file mode 100644
index 0000000..4025ca0
--- /dev/null
+++ b/utf8encodings/d6
Binary files differ
diff --git a/utmp.c b/utmp.c
new file mode 100644
index 0000000..8ec2de4
--- /dev/null
+++ b/utmp.c
@@ -0,0 +1,893 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "config.h"
+#include "screen.h"
+#include "extern.h"
+
+#ifdef HAVE_UTEMPTER
+#include <utempter.h>
+#endif
+
+
+extern struct display *display;
+#ifdef CAREFULUTMP
+extern struct win *windows;
+#endif
+extern struct win *fore;
+extern char *LoginName;
+extern int real_uid, eff_uid;
+
+
+/*
+ * UTNOKEEP: A (ugly) hack for apollo that does two things:
+ * 1) Always close and reopen the utmp file descriptor. (I don't know
+ * for what reason this is done...)
+ * 2) Implement an unsorted utmp file much like GETUTENT.
+ * (split into UT_CLOSE and UT_UNSORTED)
+ */
+
+
+#ifdef UTNOKEEP
+# define UT_CLOSE
+# define UT_UNSORTED
+#endif
+
+#ifdef UT_CLOSE
+# undef UT_CLOSE
+# define UT_CLOSE endutent()
+#else
+# define UT_CLOSE
+#endif
+
+
+/*
+ * we have a suid-root helper app that changes the utmp for us
+ * (won't work for login-slots)
+ */
+#if (defined(sun) && defined(SVR4) && defined(GETUTENT)) || defined(HAVE_UTEMPTER)
+# define UTMP_HELPER
+#endif
+
+
+
+#ifdef UTMPOK
+
+
+static slot_t TtyNameSlot __P((char *));
+static void makeuser __P((struct utmp *, char *, char *, int));
+static void makedead __P((struct utmp *));
+static int pututslot __P((slot_t, struct utmp *, char *, struct win *));
+static struct utmp *getutslot __P((slot_t));
+#ifndef GETUTENT
+static struct utmp *getutent __P((void));
+static void endutent __P((void));
+static int initutmp __P((void));
+static void setutent __P((void));
+#endif
+#if defined(linux) && defined(GETUTENT)
+static struct utmp *xpututline __P((struct utmp *utmp));
+# define pututline xpututline
+#endif
+
+
+static int utmpok;
+static char UtmpName[] = UTMPFILE;
+#ifndef UTMP_HELPER
+static int utmpfd = -1;
+#endif
+
+
+# if defined(GETUTENT) && (!defined(SVR4) || defined(__hpux)) && ! defined(__CYGWIN__)
+# if defined(hpux) /* cruel hpux release 8.0 */
+# define pututline _pututline
+# endif /* hpux */
+extern struct utmp *getutline(), *pututline();
+# if defined(_SEQUENT_)
+extern struct utmp *ut_add_user(), *ut_delete_user();
+extern char *ut_find_host();
+# ifndef UTHOST
+# define UTHOST /* _SEQUENT_ has ut_find_host() */
+# endif
+# endif /* _SEQUENT_ */
+# endif /* GETUTENT && !SVR4 */
+
+# if !defined(GETUTENT) && !defined(UT_UNSORTED)
+# ifdef GETTTYENT
+# include <ttyent.h>
+# else
+struct ttyent { char *ty_name; };
+static void setttyent __P((void));
+static struct ttyent *getttyent __P((void));
+# endif
+# endif /* !GETUTENT && !UT_UNSORTED */
+
+#ifndef _SEQUENT_
+# undef D_loginhost
+# define D_loginhost D_utmp_logintty.ut_host
+#endif
+#ifndef UTHOST
+# undef D_loginhost
+# define D_loginhost ((char *)0)
+#endif
+
+
+#endif /* UTMPOK */
+
+
+/*
+ * SlotToggle - modify the utmp slot of the fore window.
+ *
+ * how > 0 do try to set a utmp slot.
+ * how = 0 try to withdraw a utmp slot.
+ *
+ * w_slot = -1 window not logged in.
+ * w_slot = 0 window not logged in, but should be logged in.
+ * (unable to write utmp, or detached).
+ */
+
+#ifndef UTMPOK
+void
+SlotToggle(how)
+int how;
+{
+ debug1("SlotToggle (!UTMPOK) %d\n", how);
+# ifdef UTMPFILE
+ Msg(0, "Unable to modify %s.\n", UTMPFILE);
+# else
+ Msg(0, "Unable to modify utmp-database.\n");
+# endif
+}
+#endif
+
+
+
+#ifdef UTMPOK
+
+void
+SlotToggle(how)
+int how;
+{
+ debug1("SlotToggle %d\n", how);
+ if (fore->w_type != W_TYPE_PTY)
+ {
+ Msg(0, "Can only work with normal windows.\n");
+ return;
+ }
+ if (how)
+ {
+ debug(" try to log in\n");
+ if ((fore->w_slot == (slot_t) -1) || (fore->w_slot == (slot_t) 0))
+ {
+#ifdef USRLIMIT
+ if (CountUsers() >= USRLIMIT)
+ {
+ Msg(0, "User limit reached.");
+ return;
+ }
+#endif
+ if (SetUtmp(fore) == 0)
+ Msg(0, "This window is now logged in.");
+ else
+ Msg(0, "This window should now be logged in.");
+ WindowChanged(fore, 'f');
+ }
+ else
+ Msg(0, "This window is already logged in.");
+ }
+ else
+ {
+ debug(" try to log out\n");
+ if (fore->w_slot == (slot_t) -1)
+ Msg(0, "This window is already logged out\n");
+ else if (fore->w_slot == (slot_t) 0)
+ {
+ debug("What a relief! In fact, it was not logged in\n");
+ Msg(0, "This window is not logged in.");
+ fore->w_slot = (slot_t) -1;
+ }
+ else
+ {
+ RemoveUtmp(fore);
+ if (fore->w_slot != (slot_t) -1)
+ Msg(0, "What? Cannot remove Utmp slot?");
+ else
+ Msg(0, "This window is no longer logged in.");
+#ifdef CAREFULUTMP
+ CarefulUtmp();
+#endif
+ WindowChanged(fore, 'f');
+ }
+ }
+}
+
+
+#ifdef CAREFULUTMP
+
+/* CAREFULUTMP: goodie for paranoid sysadmins: always leave one
+ * window logged in
+ */
+void
+CarefulUtmp()
+{
+ struct win *p;
+
+ if (!windows) /* hopeless */
+ return;
+ debug("CarefulUtmp counting slots\n");
+ for (p = windows; p; p = p->w_next)
+ if (p->w_ptyfd >= 0 && p->w_slot != (slot_t)-1)
+ return; /* found one, nothing to do */
+
+ debug("CarefulUtmp: no slots, log one in again.\n");
+ for (p = windows; p; p = p->w_next)
+ if (p->w_ptyfd >= 0) /* no zombies please */
+ break;
+ if (!p)
+ return; /* really hopeless */
+ SetUtmp(p);
+ Msg(0, "Window %d is now logged in.\n", p->w_number);
+}
+#endif /* CAREFULUTMP */
+
+
+void
+InitUtmp()
+{
+ debug1("InitUtmp testing '%s'...\n", UtmpName);
+#ifndef UTMP_HELPER
+ if ((utmpfd = open(UtmpName, O_RDWR)) == -1)
+ {
+ if (errno != EACCES)
+ Msg(errno, "%s", UtmpName);
+ debug("InitUtmp failed.\n");
+ utmpok = 0;
+ return;
+ }
+# ifdef GETUTENT
+ close(utmpfd); /* it was just a test */
+ utmpfd = -1;
+# endif /* GETUTENT */
+#endif /* UTMP_HELPER */
+ utmpok = 1;
+}
+
+
+#ifdef USRLIMIT
+int
+CountUsers()
+{
+ struct utmp *ut;
+ int UserCount;
+
+ debug1("CountUsers() - utmpok=%d\n", utmpok);
+ if (!utmpok)
+ return 0;
+ UserCount = 0;
+ setutent();
+ while (ut = getutent())
+ if (SLOT_USED(ut))
+ UserCount++;
+ UT_CLOSE;
+ return UserCount;
+}
+#endif /* USRLIMIT */
+
+
+
+/*
+ * the utmp entry for tty is located and removed.
+ * it is stored in D_utmp_logintty.
+ */
+void
+RemoveLoginSlot()
+{
+ struct utmp u, *uu;
+
+ ASSERT(display);
+ debug("RemoveLoginSlot: removing your logintty\n");
+ D_loginslot = TtyNameSlot(D_usertty);
+ if (D_loginslot == (slot_t)0 || D_loginslot == (slot_t)-1)
+ return;
+#ifdef UTMP_HELPER
+ if (eff_uid) /* helpers can't do login slots. sigh. */
+#else
+ if (!utmpok)
+#endif
+ {
+ D_loginslot = 0;
+ debug("RemoveLoginSlot: utmpok == 0\n");
+ }
+ else
+ {
+#ifdef _SEQUENT_
+ {
+ char *p;
+ if ((p = ut_find_host(D_loginslot)) != 0)
+ strncpy(D_loginhost, p, sizeof(D_loginhost) - 1);
+ D_loginhost[sizeof(D_loginhost) - 1] = 0;
+ }
+#endif /* _SEQUENT_ */
+
+ if ((uu = getutslot(D_loginslot)) == 0)
+ {
+ debug("Utmp slot not found -> not removed");
+ D_loginslot = 0;
+ }
+ else
+ {
+ D_utmp_logintty = *uu;
+ u = *uu;
+ makedead(&u);
+ if (pututslot(D_loginslot, &u, (char *)0, (struct win *)0) == 0)
+ D_loginslot = 0;
+ }
+ UT_CLOSE;
+ }
+ debug1(" slot %d zapped\n", (int)D_loginslot);
+ if (D_loginslot == (slot_t)0)
+ {
+ /* couldn't remove slot, do a 'mesg n' at least. */
+ struct stat stb;
+ char *tty;
+ debug("couln't zap slot -> do mesg n\n");
+ D_loginttymode = 0;
+ if ((tty = GetPtsPathOrSymlink(D_userfd)) && stat(tty, &stb) == 0 && (int)stb.st_uid == real_uid && !CheckTtyname(tty) && ((int)stb.st_mode & 0777) != 0666)
+ {
+ D_loginttymode = (int)stb.st_mode & 0777;
+ chmod(D_usertty, stb.st_mode & 0600);
+ }
+ }
+}
+
+/*
+ * D_utmp_logintty is reinserted into utmp
+ */
+void
+RestoreLoginSlot()
+{
+ char *tty;
+
+ debug("RestoreLoginSlot()\n");
+ ASSERT(display);
+ if (utmpok && D_loginslot != (slot_t)0 && D_loginslot != (slot_t)-1)
+ {
+ debug1(" logging you in again (slot %#x)\n", (int)D_loginslot);
+ if (pututslot(D_loginslot, &D_utmp_logintty, D_loginhost, (struct win *)0) == 0)
+ Msg(errno,"Could not write %s", UtmpName);
+ }
+ UT_CLOSE;
+ D_loginslot = (slot_t)0;
+ if (D_loginttymode && (tty = GetPtsPathOrSymlink(D_userfd)) && !CheckTtyname(tty))
+ chmod(tty, D_loginttymode);
+}
+
+
+
+/*
+ * Construct a utmp entry for window wi.
+ * the hostname field reflects what we know about the user (display)
+ * location. If d_loginhost is not set, then he is local and we write
+ * down the name of his terminal line; else he is remote and we keep
+ * the hostname here. The letter S and the window id will be appended.
+ * A saved utmp entry in wi->w_savut serves as a template, usually.
+ */
+
+int
+SetUtmp(wi)
+struct win *wi;
+{
+ register slot_t slot;
+ struct utmp u;
+ int saved_ut;
+#ifdef UTHOST
+ char *p;
+ char host[sizeof(D_loginhost) + 15];
+#else
+ char *host = 0;
+#endif /* UTHOST */
+
+ wi->w_slot = (slot_t)0;
+ if (!utmpok || wi->w_type != W_TYPE_PTY)
+ return -1;
+ if ((slot = TtyNameSlot(wi->w_tty)) == (slot_t)0)
+ {
+ debug1("SetUtmp failed (tty %s).\n",wi->w_tty);
+ return -1;
+ }
+ debug2("SetUtmp %d will get slot %d...\n", wi->w_number, (int)slot);
+
+ bzero((char *)&u, sizeof(u));
+ if ((saved_ut = bcmp((char *) &wi->w_savut, (char *)&u, sizeof(u))))
+ /* restore original, of which we will adopt all fields but ut_host */
+ bcopy((char *)&wi->w_savut, (char *) &u, sizeof(u));
+
+ if (!saved_ut)
+ makeuser(&u, stripdev(wi->w_tty), LoginName, wi->w_pid);
+
+#ifdef UTHOST
+ host[sizeof(host) - 15] = '\0';
+ if (display)
+ {
+ strncpy(host, D_loginhost, sizeof(host) - 15);
+ if (D_loginslot != (slot_t)0 && D_loginslot != (slot_t)-1 && host[0] != '\0')
+ {
+ /*
+ * we want to set our ut_host field to something like
+ * ":ttyhf:s.0" or
+ * "faui45:s.0" or
+ * "132.199.81.4:s.0" (even this may hurt..), but not
+ * "faui45.informati"......:s.0
+ * HPUX uses host:0.0, so chop at "." and ":" (Eric Backus)
+ */
+ for (p = host; *p; p++)
+ if ((*p < '0' || *p > '9') && (*p != '.'))
+ break;
+ if (*p)
+ {
+ for (p = host; *p; p++)
+ if (*p == '.' || (*p == ':' && p != host))
+ {
+ *p = '\0';
+ break;
+ }
+ }
+ }
+ else
+ {
+ strncpy(host + 1, stripdev(D_usertty), sizeof(host) - 15 - 1);
+ host[0] = ':';
+ }
+ }
+ else
+ strncpy(host, "local", sizeof(host) - 15);
+
+ sprintf(host + strlen(host), ":S.%d", wi->w_number);
+ debug1("rlogin hostname: '%s'\n", host);
+
+# if !defined(_SEQUENT_) && !defined(sequent)
+ strncpy(u.ut_host, host, sizeof(u.ut_host));
+# endif
+#endif /* UTHOST */
+
+ if (pututslot(slot, &u, host, wi) == 0)
+ {
+ Msg(errno,"Could not write %s", UtmpName);
+ UT_CLOSE;
+ return -1;
+ }
+ debug("SetUtmp successful\n");
+ wi->w_slot = slot;
+ bcopy((char *)&u, (char *)&wi->w_savut, sizeof(u));
+ UT_CLOSE;
+ return 0;
+}
+
+/*
+ * if slot could be removed or was 0, wi->w_slot = -1;
+ * else not changed.
+ */
+
+int
+RemoveUtmp(wi)
+struct win *wi;
+{
+ struct utmp u, *uu;
+ slot_t slot;
+
+ slot = wi->w_slot;
+ debug1("RemoveUtmp slot=%#x\n", slot);
+ if (!utmpok)
+ return -1;
+ if (slot == (slot_t)0 || slot == (slot_t)-1)
+ {
+ wi->w_slot = (slot_t)-1;
+ return 0;
+ }
+ bzero((char *) &u, sizeof(u));
+#ifdef sgi
+ bcopy((char *)&wi->w_savut, (char *)&u, sizeof(u));
+ uu = &u;
+#else
+ if ((uu = getutslot(slot)) == 0)
+ {
+ Msg(0, "Utmp slot not found -> not removed");
+ return -1;
+ }
+ bcopy((char *)uu, (char *)&wi->w_savut, sizeof(wi->w_savut));
+#endif
+ u = *uu;
+ makedead(&u);
+ if (pututslot(slot, &u, (char *)0, wi) == 0)
+ {
+ Msg(errno,"Could not write %s", UtmpName);
+ UT_CLOSE;
+ return -1;
+ }
+ debug("RemoveUtmp successfull\n");
+ wi->w_slot = (slot_t)-1;
+ UT_CLOSE;
+ return 0;
+}
+
+
+
+/*********************************************************************
+ *
+ * routines using the getut* api
+ */
+
+#ifdef GETUTENT
+
+#define SLOT_USED(u) (u->ut_type == USER_PROCESS)
+
+static struct utmp *
+getutslot(slot)
+slot_t slot;
+{
+ struct utmp u;
+ bzero((char *)&u, sizeof(u));
+ strncpy(u.ut_line, slot, sizeof(u.ut_line));
+ setutent();
+ return getutline(&u);
+}
+
+static int
+pututslot(slot, u, host, wi)
+slot_t slot;
+struct utmp *u;
+char *host;
+struct win *wi;
+{
+#ifdef _SEQUENT_
+ if (SLOT_USED(u) && host && *host)
+ return ut_add_user(u.ut_name, slot, u.ut_pid, host) != 0;
+ if (!SLOT_USED(u))
+ return ut_delete_user(slot, u.ut_pid, 0, 0) != 0;
+#endif
+#ifdef HAVE_UTEMPTER
+ if (eff_uid && wi && wi->w_ptyfd != -1)
+ {
+ /* sigh, linux hackers made the helper functions void */
+ if (SLOT_USED(u))
+ addToUtmp(wi->w_tty, host, wi->w_ptyfd);
+ else
+ removeLineFromUtmp(wi->w_tty, wi->w_ptyfd);
+ return 1; /* pray for success */
+ }
+#endif
+ setutent();
+#ifndef __CYGWIN__
+ return pututline(u) != 0;
+#else
+ return 1;
+#endif
+}
+
+static void
+makedead(u)
+struct utmp *u;
+{
+ u->ut_type = DEAD_PROCESS;
+#if (!defined(linux) || defined(EMPTY)) && !defined(__CYGWIN__)
+ u->ut_exit.e_termination = 0;
+ u->ut_exit.e_exit = 0;
+#endif
+#if !defined(sun) || !defined(SVR4)
+ u->ut_user[0] = 0; /* for Digital UNIX, kilbi@rad.rwth-aachen.de */
+#endif
+}
+
+static void
+makeuser(u, line, user, pid)
+struct utmp *u;
+char *line, *user;
+int pid;
+{
+ time_t now;
+ u->ut_type = USER_PROCESS;
+ strncpy(u->ut_user, user, sizeof(u->ut_user));
+ /* Now the tricky part... guess ut_id */
+#if defined(sgi) || defined(linux)
+ strncpy(u->ut_id, line + 3, sizeof(u->ut_id));
+#else /* sgi */
+# ifdef _IBMR2
+ strncpy(u->ut_id, line, sizeof(u->ut_id));
+# else
+ strncpy(u->ut_id, line + strlen(line) - 2, sizeof(u->ut_id));
+# endif
+#endif /* sgi */
+ strncpy(u->ut_line, line, sizeof(u->ut_line));
+ u->ut_pid = pid;
+ /* must use temp variable because of NetBSD/sparc64, where
+ * ut_xtime is long(64) but time_t is int(32) */
+ (void)time(&now);
+ u->ut_time = now;
+}
+
+static slot_t
+TtyNameSlot(nam)
+char *nam;
+{
+ return stripdev(nam);
+}
+
+
+#else /* GETUTENT */
+
+/*********************************************************************
+ *
+ * getut emulation for systems lacking the api
+ */
+
+static struct utmp uent;
+
+#define SLOT_USED(u) (u.ut_name[0] != 0)
+
+static int
+initutmp()
+{
+ if (utmpfd >= 0)
+ return 1;
+ return (utmpfd = open(UtmpName, O_RDWR)) >= 0;
+}
+
+static void
+setutent()
+{
+ if (utmpfd >= 0)
+ (void)lseek(utmpfd, (off_t)0, 0);
+}
+
+static void
+endutent()
+{
+ if (utmpfd >= 0)
+ close(utmpfd);
+ utmpfd = -1;
+}
+
+static struct utmp *
+getutent()
+{
+ if (utmpfd < 0 && !initutmp())
+ return 0;
+ if (read(utmpfd, &uent, sizeof(uent)) != sizeof(uent))
+ return 0;
+ return &uent;
+}
+
+static struct utmp *
+getutslot(slot)
+slot_t slot;
+{
+ if (utmpfd < 0 && !initutmp())
+ return 0;
+ lseek(utmpfd, (off_t)(slot * sizeof(struct utmp)), 0);
+ if (read(utmpfd, &uent, sizeof(uent)) != sizeof(uent))
+ return 0;
+ return &uent;
+}
+
+static int
+pututslot(slot, u, host, wi)
+slot_t slot;
+struct utmp *u;
+char *host;
+struct win *wi;
+{
+#ifdef sequent
+ if (SLOT_USED(u))
+ return add_utmp(slot, u) != -1;
+#endif
+ if (utmpfd < 0 && !initutmp())
+ return 0;
+ lseek(utmpfd, (off_t)(slot * sizeof(*u)), 0);
+ if (write(utmpfd, u, sizeof(*u)) != sizeof(*u))
+ return 0;
+ return 1;
+}
+
+
+static void
+makedead(u)
+struct utmp *u;
+{
+#ifdef UT_UNSORTED
+ bzero(u->ut_name, sizeof(u->ut_name));
+# ifdef UTHOST
+ bzero(u->ut_host, sizeof(u->ut_host));
+# endif
+#else
+ bzero((char *)u, sizeof(*u));
+#endif
+}
+
+
+static void
+makeuser(u, line, user, pid)
+struct utmp *u;
+char *line, *user;
+int pid;
+{
+ time_t now;
+ strncpy(u->ut_line, line, sizeof(u->ut_line));
+ strncpy(u->ut_name, user, sizeof(u->ut_name));
+ (void)time(&now);
+ u->ut_time = now;
+}
+
+static slot_t
+TtyNameSlot(nam)
+char *nam;
+{
+ slot_t slot;
+ char *line;
+#ifndef UT_UNSORTED
+ struct ttyent *tp;
+#endif
+
+ line = stripdev(nam);
+#ifdef UT_UNSORTED
+ setutent();
+ if (utmpfd < 0)
+ return -1;
+ for (slot = 0; getutent(); slot++)
+ if (strcmp(uent.ut_line, line) == 0)
+ break;
+ UT_CLOSE;
+#else
+ slot = 1;
+ setttyent();
+ while ((tp = getttyent()) != 0 && strcmp(line, tp->ty_name) != 0)
+ slot++;
+#endif
+ return slot;
+}
+
+#endif /* GETUTENT */
+
+
+
+/*********************************************************************
+ *
+ * Cheap plastic imitation of ttyent routines.
+ */
+
+#if !defined(GETTTYENT) && !defined(GETUTENT) && !defined(UT_UNSORTED)
+
+
+static char *tt, *ttnext;
+static char ttys[] = "/etc/ttys";
+
+static void
+setttyent()
+{
+ if (ttnext == 0)
+ {
+ struct stat s;
+ register int f;
+ register char *p, *ep;
+
+ if ((f = open(ttys, O_RDONLY)) == -1 || fstat(f, &s) == -1)
+ Panic(errno, ttys);
+ if ((tt = malloc((unsigned) s.st_size + 1)) == 0)
+ Panic(0, strnomem);
+ if (read(f, tt, s.st_size) != s.st_size)
+ Panic(errno, ttys);
+ close(f);
+ for (p = tt, ep = p + s.st_size; p < ep; p++)
+ if (*p == '\n')
+ *p = '\0';
+ *p = '\0';
+ }
+ ttnext = tt;
+}
+
+static struct ttyent *
+getttyent()
+{
+ static struct ttyent t;
+
+ if (*ttnext == '\0')
+ return NULL;
+ t.ty_name = ttnext + 2;
+ ttnext += strlen(ttnext) + 1;
+ return &t;
+}
+
+#endif /* !GETTTYENT && !GETUTENT && !UT_UNSORTED*/
+
+
+
+#endif /* UTMPOK */
+
+
+
+
+/*********************************************************************
+ *
+ * getlogin() replacement (for SVR4 machines)
+ */
+
+# if defined(BUGGYGETLOGIN) && defined(UTMP_FILE)
+char *
+getlogin()
+{
+ char *tty = NULL;
+#ifdef utmp
+# undef utmp
+#endif
+ struct utmp u;
+ static char retbuf[sizeof(u.ut_user)+1];
+ int fd;
+
+ for (fd = 0; fd <= 2 && (tty = GetPtsPathOrSymlink(fd)) == NULL; fd++)
+ ;
+ if ((tty == NULL) || CheckTtyname(tty) || ((fd = open(UTMP_FILE, O_RDONLY)) < 0))
+ return NULL;
+ tty = stripdev(tty);
+ retbuf[0] = '\0';
+ while (read(fd, (char *)&u, sizeof(struct utmp)) == sizeof(struct utmp))
+ {
+ if (!strncmp(tty, u.ut_line, sizeof(u.ut_line)))
+ {
+ strncpy(retbuf, u.ut_user, sizeof(u.ut_user));
+ retbuf[sizeof(u.ut_user)] = '\0';
+ if (u.ut_type == USER_PROCESS)
+ break;
+ }
+ }
+ close(fd);
+
+ return *retbuf ? retbuf : NULL;
+}
+# endif /* BUGGYGETLOGIN */
+
+#if defined(linux) && defined(GETUTENT)
+# undef pututline
+
+/* aargh, linux' pututline returns void! */
+struct utmp *
+xpututline(u)
+struct utmp *u;
+{
+ struct utmp *u2;
+ pututline(u);
+ setutent();
+ u2 = getutline(u);
+ if (u2 == 0)
+ return u->ut_type == DEAD_PROCESS ? u : 0;
+ return u->ut_type == u2->ut_type ? u : 0;
+}
+#endif
+
diff --git a/viewport.c b/viewport.c
new file mode 100644
index 0000000..125ae36
--- /dev/null
+++ b/viewport.c
@@ -0,0 +1,129 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include "config.h"
+#include "screen.h"
+#include "extern.h"
+#include "viewport.h"
+
+extern struct display *display;
+
+int RethinkDisplayViewports() {
+ struct canvas *cv;
+ struct viewport *vp, *vpn;
+
+ /* free old viewports */
+ for (cv = display->d_cvlist; cv; cv = cv->c_next) {
+ for (vp = cv->c_vplist; vp; vp = vpn) {
+ vp->v_canvas = 0;
+ vpn = vp->v_next;
+ bzero((char *)vp, sizeof(*vp));
+ free(vp);
+ }
+ cv->c_vplist = 0;
+ }
+ display->d_vpxmin = -1;
+ display->d_vpxmax = -1;
+
+ for (cv = display->d_cvlist; cv; cv = cv->c_next) {
+ if ((vp = (struct viewport *)malloc(sizeof *vp)) == 0)
+ return -1;
+#ifdef HOLE
+ vp->v_canvas = cv;
+ vp->v_xs = cv->c_xs;
+ vp->v_ys = (cv->c_ys + cv->c_ye) / 2;
+ vp->v_xe = cv->c_xe;
+ vp->v_ye = cv->c_ye;
+ vp->v_xoff = cv->c_xoff;
+ vp->v_yoff = cv->c_yoff;
+ vp->v_next = cv->c_vplist;
+ cv->c_vplist = vp;
+
+ if ((vp = (struct viewport *)malloc(sizeof *vp)) == 0)
+ return -1;
+ vp->v_canvas = cv;
+ vp->v_xs = (cv->c_xs + cv->c_xe) / 2;
+ vp->v_ys = (3 * cv->c_ys + cv->c_ye) / 4;
+ vp->v_xe = cv->c_xe;
+ vp->v_ye = (cv->c_ys + cv->c_ye) / 2 - 1;
+ vp->v_xoff = cv->c_xoff;
+ vp->v_yoff = cv->c_yoff;
+ vp->v_next = cv->c_vplist;
+ cv->c_vplist = vp;
+
+ if ((vp = (struct viewport *)malloc(sizeof *vp)) == 0)
+ return -1;
+ vp->v_canvas = cv;
+ vp->v_xs = cv->c_xs;
+ vp->v_ys = (3 * cv->c_ys + cv->c_ye) / 4;
+ vp->v_xe = (3 * cv->c_xs + cv->c_xe) / 4 - 1;
+ vp->v_ye = (cv->c_ys + cv->c_ye) / 2 - 1;
+ vp->v_xoff = cv->c_xoff;
+ vp->v_yoff = cv->c_yoff;
+ vp->v_next = cv->c_vplist;
+ cv->c_vplist = vp;
+
+ if ((vp = (struct viewport *)malloc(sizeof *vp)) == 0)
+ return -1;
+ vp->v_canvas = cv;
+ vp->v_xs = cv->c_xs;
+ vp->v_ys = cv->c_ys;
+ vp->v_xe = cv->c_xe;
+ vp->v_ye = (3 * cv->c_ys + cv->c_ye) / 4 - 1;
+ vp->v_xoff = cv->c_xoff;
+ vp->v_yoff = cv->c_yoff;
+ vp->v_next = cv->c_vplist;
+ cv->c_vplist = vp;
+#else
+ vp->v_canvas = cv;
+ vp->v_xs = cv->c_xs;
+ vp->v_ys = cv->c_ys;
+ vp->v_xe = cv->c_xe;
+ vp->v_ye = cv->c_ye;
+ vp->v_xoff = cv->c_xoff;
+ vp->v_yoff = cv->c_yoff;
+ vp->v_next = cv->c_vplist;
+ cv->c_vplist = vp;
+#endif
+
+ if (cv->c_xs < display->d_vpxmin || display->d_vpxmin == -1)
+ display->d_vpxmin = cv->c_xs;
+ if (cv->c_xe > display->d_vpxmax || display->d_vpxmax == -1)
+ display->d_vpxmax = cv->c_xe;
+ }
+ return 0;
+}
+
+void RethinkViewportOffsets(struct canvas *cv)
+{
+ struct viewport *vp;
+ for (vp = cv->c_vplist; vp; vp = vp->v_next) {
+ vp->v_xoff = cv->c_xoff;
+ vp->v_yoff = cv->c_yoff;
+ }
+}
diff --git a/viewport.h b/viewport.h
new file mode 100644
index 0000000..a19b6b8
--- /dev/null
+++ b/viewport.h
@@ -0,0 +1,51 @@
+/* Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+#ifndef SCREEN_VIEWPORT_H
+#define SCREEN_VIEWPORT_H
+
+#include "canvas.h"
+
+struct viewport
+{
+ struct viewport *v_next; /* next vp on canvas */
+ struct canvas *v_canvas; /* back pointer to canvas */
+ int v_xoff; /* layer x offset on display */
+ int v_yoff; /* layer y offset on display */
+ int v_xs; /* vp upper left */
+ int v_xe; /* vp upper right */
+ int v_ys; /* vp lower left */
+ int v_ye; /* vp lower right */
+};
+
+extern int RethinkDisplayViewports __P((void));
+extern void RethinkViewportOffsets __P((struct canvas *));
+
+#endif /* SCREEN_VIEWPORT_H */
+
diff --git a/window.c b/window.c
new file mode 100644
index 0000000..3a64b26
--- /dev/null
+++ b/window.c
@@ -0,0 +1,2357 @@
+/* Copyright (c) 2010
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <fcntl.h>
+#ifndef sun
+# include <sys/ioctl.h>
+#endif
+
+#include "config.h"
+
+#include "screen.h"
+#include "extern.h"
+#include "logfile.h" /* logfopen() */
+
+extern struct display *displays, *display;
+extern struct win *windows, *fore, *console_window;
+extern char *ShellArgs[];
+extern char *ShellProg;
+extern char screenterm[];
+extern char *screenlogfile;
+extern char HostName[];
+extern int TtyMode;
+extern int SilenceWait;
+extern int real_uid, real_gid, eff_uid, eff_gid;
+extern char Termcap[];
+extern char **NewEnv;
+extern int visual_bell, maxwin;
+extern struct event logflushev;
+extern int log_flush, logtstamp_after;
+extern int ZombieKey_destroy, ZombieKey_resurrect, ZombieKey_onerror;
+extern struct layer *flayer;
+extern int maxusercount;
+extern int pty_preopen;
+#ifdef ZMODEM
+extern int zmodem_mode;
+extern struct mchar mchar_blank;
+extern char *zmodem_sendcmd;
+extern char *zmodem_recvcmd;
+#endif
+
+#if defined(TIOCSWINSZ) || defined(TIOCGWINSZ)
+extern struct winsize glwz;
+#endif
+
+#ifdef O_NOCTTY
+extern int separate_sids;
+#endif
+
+static void WinProcess __P((char **, int *));
+static void WinRedisplayLine __P((int, int, int, int));
+static void WinClearLine __P((int, int, int, int));
+static int WinRewrite __P((int, int, int, struct mchar *, int));
+static int WinResize __P((int, int));
+static void WinRestore __P((void));
+static int DoAutolf __P((char *, int *, int));
+static void ZombieProcess __P((char **, int *));
+static void win_readev_fn __P((struct event *, char *));
+static void win_writeev_fn __P((struct event *, char *));
+static void win_resurrect_zombie_fn __P((struct event *, char *));
+static int muchpending __P((struct win *, struct event *));
+#ifdef COPY_PASTE
+static void paste_slowev_fn __P((struct event *, char *));
+#endif
+#ifdef PSEUDOS
+static void pseu_readev_fn __P((struct event *, char *));
+static void pseu_writeev_fn __P((struct event *, char *));
+#endif
+static void win_silenceev_fn __P((struct event *, char *));
+static void win_destroyev_fn __P((struct event *, char *));
+
+static int OpenDevice __P((char **, int, int *, char **));
+static int ForkWindow __P((struct win *, char **, char *));
+#ifdef ZMODEM
+static void zmodem_found __P((struct win *, int, char *, int));
+static void zmodem_fin __P((char *, int, char *));
+static int zmodem_parse __P((struct win *, char *, int));
+#endif
+
+
+struct win **wtab; /* window table */
+
+int VerboseCreate = 0; /* XXX move this to user.h */
+
+char DefaultShell[] = "/bin/sh";
+#ifndef HAVE_EXECVPE
+static char DefaultPath[] = ":/usr/ucb:/bin:/usr/bin";
+#endif
+
+/* keep this in sync with the structure definition in window.h */
+struct NewWindow nwin_undef =
+{
+ -1, /* StartAt */
+ (char *)0, /* aka */
+ (char **)0, /* args */
+ (char *)0, /* dir */
+ (char *)0, /* term */
+ -1, /* aflag */
+ -1, /* dynamicaka */
+ -1, /* flowflag */
+ -1, /* lflag */
+ -1, /* histheight */
+ -1, /* monitor */
+ -1, /* wlock */
+ -1, /* silence */
+ -1, /* wrap */
+ -1, /* logging */
+ -1, /* slowpaste */
+ -1, /* gr */
+ -1, /* c1 */
+ -1, /* bce */
+ -1, /* encoding */
+ (char *)0, /* hstatus */
+ (char *)0, /* charset */
+ 0 /* poll_zombie_timeout */
+};
+
+struct NewWindow nwin_default =
+{
+ 0, /* StartAt */
+ 0, /* aka */
+ ShellArgs, /* args */
+ 0, /* dir */
+ screenterm, /* term */
+ 0, /* aflag */
+ 1, /* dynamicaka */
+ 1*FLOW_NOW, /* flowflag */
+ LOGINDEFAULT, /* lflag */
+ DEFAULTHISTHEIGHT, /* histheight */
+ MON_OFF, /* monitor */
+ WLOCK_OFF, /* wlock */
+ 0, /* silence */
+ 1, /* wrap */
+ 0, /* logging */
+ 0, /* slowpaste */
+ 0, /* gr */
+ 1, /* c1 */
+ 0, /* bce */
+ 0, /* encoding */
+ (char *)0, /* hstatus */
+ (char *)0 /* charset */
+};
+
+struct NewWindow nwin_options;
+
+static int const_IOSIZE = IOSIZE;
+static int const_one = 1;
+
+void
+nwin_compose(def, new, res)
+struct NewWindow *def, *new, *res;
+{
+#define COMPOSE(x) res->x = new->x != nwin_undef.x ? new->x : def->x
+ COMPOSE(StartAt);
+ COMPOSE(aka);
+ COMPOSE(args);
+ COMPOSE(dir);
+ COMPOSE(term);
+ COMPOSE(aflag);
+ COMPOSE(dynamicaka);
+ COMPOSE(flowflag);
+ COMPOSE(lflag);
+ COMPOSE(histheight);
+ COMPOSE(monitor);
+ COMPOSE(wlock);
+ COMPOSE(silence);
+ COMPOSE(wrap);
+ COMPOSE(Lflag);
+ COMPOSE(slow);
+ COMPOSE(gr);
+ COMPOSE(c1);
+ COMPOSE(bce);
+ COMPOSE(encoding);
+ COMPOSE(hstatus);
+ COMPOSE(charset);
+ COMPOSE(poll_zombie_timeout);
+#undef COMPOSE
+}
+
+/*****************************************************************
+ *
+ * The window layer functions
+ */
+
+struct LayFuncs WinLf =
+{
+ WinProcess,
+ 0,
+ WinRedisplayLine,
+ WinClearLine,
+ WinRewrite,
+ WinResize,
+ WinRestore,
+ 0
+};
+
+static int
+DoAutolf(buf, lenp, fr)
+char *buf;
+int *lenp;
+int fr;
+{
+ char *p;
+ int len = *lenp;
+ int trunc = 0;
+
+ for (p = buf; len > 0; p++, len--)
+ {
+ if (*p != '\r')
+ continue;
+ if (fr-- <= 0)
+ {
+ trunc++;
+ len--;
+ }
+ if (len == 0)
+ break;
+ bcopy(p, p + 1, len++);
+ p[1] = '\n';
+ }
+ *lenp = p - buf;
+ return trunc;
+}
+
+static void
+WinProcess(bufpp, lenp)
+char **bufpp;
+int *lenp;
+{
+ int l2 = 0, f, *ilen, l = *lenp, trunc;
+ char *ibuf;
+
+ debug1("WinProcess: %d bytes\n", *lenp);
+ fore = (struct win *)flayer->l_data;
+
+ if (fore->w_type == W_TYPE_GROUP)
+ {
+ *bufpp += *lenp;
+ *lenp = 0;
+ return;
+ }
+ if (fore->w_ptyfd < 0) /* zombie? */
+ {
+ ZombieProcess(bufpp, lenp);
+ return;
+ }
+#ifdef MULTIUSER
+ /* a pending writelock is this:
+ * fore->w_wlock == WLOCK_AUTO, fore->w_wlockuse = NULL
+ * The user who wants to use this window next, will get the lock, if he can.
+ */
+ if (display && fore->w_wlock == WLOCK_AUTO &&
+ !fore->w_wlockuser && !AclCheckPermWin(D_user, ACL_WRITE, fore))
+ {
+ fore->w_wlockuser = D_user;
+ debug2("window %d: pending writelock grabbed by user %s\n",
+ fore->w_number, fore->w_wlockuser->u_name);
+ }
+ /* if w_wlock is set, only one user may write, else we check acls */
+ if (display && ((fore->w_wlock == WLOCK_OFF) ?
+ AclCheckPermWin(D_user, ACL_WRITE, fore) :
+ (D_user != fore->w_wlockuser)))
+ {
+ debug2("window %d, user %s: ", fore->w_number, D_user->u_name);
+ debug2("writelock %d (wlockuser %s)\n", fore->w_wlock,
+ fore->w_wlockuser ? fore->w_wlockuser->u_name : "NULL");
+ Msg(0, "write: permission denied (user %s)", D_user->u_name);
+ *bufpp += *lenp;
+ *lenp = 0;
+ return;
+ }
+#endif /* MULTIUSER */
+
+#ifdef BUILTIN_TELNET
+ if (fore->w_type == W_TYPE_TELNET && TelIsline(fore) && *bufpp != fore->w_telbuf)
+ {
+ TelProcessLine(bufpp, lenp);
+ return;
+ }
+#endif
+
+#ifdef PSEUDOS
+ if (W_UWP(fore))
+ {
+ /* we send the user input to our pseudowin */
+ ibuf = fore->w_pwin->p_inbuf; ilen = &fore->w_pwin->p_inlen;
+ f = sizeof(fore->w_pwin->p_inbuf) - *ilen;
+ }
+ else
+#endif /* PSEUDOS */
+ {
+ /* we send the user input to the window */
+ ibuf = fore->w_inbuf; ilen = &fore->w_inlen;
+ f = sizeof(fore->w_inbuf) - *ilen;
+ }
+
+ if (l > f)
+ l = f;
+#ifdef BUILTIN_TELNET
+ while (l > 0)
+#else
+ if (l > 0)
+#endif
+ {
+ l2 = l;
+ bcopy(*bufpp, ibuf + *ilen, l2);
+ if (fore->w_autolf && (trunc = DoAutolf(ibuf + *ilen, &l2, f - l2)))
+ l -= trunc;
+#ifdef BUILTIN_TELNET
+ if (fore->w_type == W_TYPE_TELNET && (trunc = DoTelnet(ibuf + *ilen, &l2, f - l2)))
+ {
+ l -= trunc;
+ if (fore->w_autolf)
+ continue; /* need exact value */
+ }
+#endif
+ *ilen += l2;
+ *bufpp += l;
+ *lenp -= l;
+ return;
+ }
+}
+
+static void
+ZombieProcess(bufpp, lenp)
+char **bufpp;
+int *lenp;
+{
+ int l = *lenp;
+ char *buf = *bufpp, b1[10], b2[10];
+
+ debug1("ZombieProcess: %d bytes\n", *lenp);
+ fore = (struct win *)flayer->l_data;
+
+ ASSERT(fore->w_ptyfd < 0);
+ *bufpp += *lenp;
+ *lenp = 0;
+ for (; l-- > 0; buf++)
+ {
+ if (*(unsigned char *)buf == ZombieKey_destroy)
+ {
+ debug1("Turning undead: %d\n", fore->w_number);
+ KillWindow(fore);
+ return;
+ }
+ if (*(unsigned char *)buf == ZombieKey_resurrect)
+ {
+ debug1("Resurrecting Zombie: %d\n", fore->w_number);
+ WriteString(fore, "\r\n", 2);
+ RemakeWindow(fore);
+ return;
+ }
+ }
+ b1[AddXChar(b1, ZombieKey_destroy)] = '\0';
+ b2[AddXChar(b2, ZombieKey_resurrect)] = '\0';
+ Msg(0, "Press %s to destroy or %s to resurrect window", b1, b2);
+}
+
+static void
+WinRedisplayLine(y, from, to, isblank)
+int y, from, to, isblank;
+{
+ debug3("WinRedisplayLine %d %d %d\n", y, from, to);
+ if (y < 0)
+ return;
+ fore = (struct win *)flayer->l_data;
+ if (from == 0 && y > 0 && fore->w_mlines[y - 1].image[fore->w_width] == 0)
+ LCDisplayLineWrap(&fore->w_layer, &fore->w_mlines[y], y, from, to, isblank);
+ else
+ LCDisplayLine(&fore->w_layer, &fore->w_mlines[y], y, from, to, isblank);
+}
+
+static int
+WinRewrite(y, x1, x2, rend, doit)
+int y, x1, x2, doit;
+struct mchar *rend;
+{
+ register int cost, dx;
+ register unsigned char *p, *i;
+#ifdef FONT
+ register unsigned char *f;
+ register unsigned char *fx;
+#endif
+#ifdef COLOR
+ register unsigned char *c;
+# ifdef COLORS256
+ register unsigned char *cx;
+# endif
+#endif
+
+ debug3("WinRewrite %d, %d-%d\n", y, x1, x2);
+ fore = (struct win *)flayer->l_data;
+ dx = x2 - x1 + 1;
+ if (doit)
+ {
+ i = fore->w_mlines[y].image + x1;
+ while (dx-- > 0)
+ PUTCHAR(*i++);
+ return 0;
+ }
+ p = fore->w_mlines[y].attr + x1;
+#ifdef FONT
+ f = fore->w_mlines[y].font + x1;
+ fx = fore->w_mlines[y].fontx + x1;
+# ifdef DW_CHARS
+ if (is_dw_font(rend->font))
+ return EXPENSIVE;
+# endif
+# ifdef UTF8
+ if (fore->w_encoding && fore->w_encoding != UTF8 && D_encoding == UTF8 && ContainsSpecialDeffont(fore->w_mlines + y, x1, x2, fore->w_encoding))
+ return EXPENSIVE;
+# endif
+#endif
+#ifdef COLOR
+ c = fore->w_mlines[y].color + x1;
+# ifdef COLORS256
+ cx = fore->w_mlines[y].colorx + x1;
+# endif
+#endif
+
+ cost = dx = x2 - x1 + 1;
+ while(dx-- > 0)
+ {
+ if (*p++ != rend->attr)
+ return EXPENSIVE;
+#ifdef FONT
+ if (*f++ != rend->font)
+ return EXPENSIVE;
+ if (*fx++ != rend->fontx)
+ return EXPENSIVE;
+#endif
+#ifdef COLOR
+ if (*c++ != rend->color)
+ return EXPENSIVE;
+# ifdef COLORS256
+ if (*cx++ != rend->colorx)
+ return EXPENSIVE;
+# endif
+#endif
+ }
+ return cost;
+}
+
+static void
+WinClearLine(y, xs, xe, bce)
+int y, xs, xe, bce;
+{
+ fore = (struct win *)flayer->l_data;
+ debug3("WinClearLine %d %d-%d\n", y, xs, xe);
+ LClearLine(flayer, y, xs, xe, bce, &fore->w_mlines[y]);
+}
+
+static int
+WinResize(wi, he)
+int wi, he;
+{
+ fore = (struct win *)flayer->l_data;
+ ChangeWindowSize(fore, wi, he, fore->w_histheight);
+ return 0;
+}
+
+static void
+WinRestore()
+{
+ struct canvas *cv;
+ fore = (struct win *)flayer->l_data;
+ debug1("WinRestore: win %p\n", fore);
+ for (cv = flayer->l_cvlist; cv; cv = cv->c_next)
+ {
+ display = cv->c_display;
+ if (cv != D_forecv)
+ continue;
+ /* ChangeScrollRegion(fore->w_top, fore->w_bot); */
+ KeypadMode(fore->w_keypad);
+ CursorkeysMode(fore->w_cursorkeys);
+ SetFlow(fore->w_flow & FLOW_NOW);
+ InsertMode(fore->w_insert);
+ ReverseVideo(fore->w_revvid);
+ CursorVisibility(fore->w_curinv ? -1 : fore->w_curvvis);
+ MouseMode(fore->w_mouse);
+ }
+}
+
+/*****************************************************************/
+
+
+/*
+ * DoStartLog constructs a path for the "want to be logfile" in buf and
+ * attempts logfopen.
+ *
+ * returns 0 on success.
+ */
+int
+DoStartLog(w, buf, bufsize)
+struct win *w;
+char *buf;
+int bufsize;
+{
+ int n;
+ if (!w || !buf)
+ return -1;
+
+ strncpy(buf, MakeWinMsg(screenlogfile, w, '%'), bufsize - 1);
+ buf[bufsize - 1] = 0;
+
+ debug2("DoStartLog: win %d, file %s\n", w->w_number, buf);
+
+ if (w->w_log != NULL)
+ logfclose(w->w_log);
+
+ if ((w->w_log = logfopen(buf, islogfile(buf) ? NULL : secfopen(buf, "a"))) == NULL)
+ return -2;
+ if (!logflushev.queued)
+ {
+ n = log_flush ? log_flush : (logtstamp_after + 4) / 5;
+ if (n)
+ {
+ SetTimeout(&logflushev, n * 1000);
+ evenq(&logflushev);
+ }
+ }
+ return 0;
+}
+
+/*
+ * Umask & wlock are set for the user of the display,
+ * The display d (if specified) switches to that window.
+ */
+int
+MakeWindow(newwin)
+struct NewWindow *newwin;
+{
+ register struct win **pp, *p;
+ register int n, i;
+ int f = -1;
+ struct NewWindow nwin;
+ int type, startat;
+ char *TtyName;
+#ifdef MULTIUSER
+ extern struct acluser *users;
+#endif
+
+ if (!wtab)
+ {
+ if (!maxwin)
+ maxwin = MAXWIN;
+ wtab = calloc(maxwin, sizeof(struct win *));
+ }
+
+ debug1("NewWindow: StartAt %d\n", newwin->StartAt);
+ debug1("NewWindow: aka %s\n", newwin->aka?newwin->aka:"NULL");
+ debug1("NewWindow: dir %s\n", newwin->dir?newwin->dir:"NULL");
+ debug1("NewWindow: term %s\n", newwin->term?newwin->term:"NULL");
+
+ nwin_compose(&nwin_default, newwin, &nwin);
+ debug1("NWin: aka %s\n", nwin.aka ? nwin.aka : "NULL");
+ debug1("NWin: wlock %d\n", nwin.wlock);
+ debug1("NWin: Lflag %d\n", nwin.Lflag);
+
+ startat = nwin.StartAt < maxwin ? nwin.StartAt : 0;
+ pp = wtab + startat;
+
+ do
+ {
+ if (*pp == 0)
+ break;
+ if (++pp == wtab + maxwin)
+ pp = wtab;
+ }
+ while (pp != wtab + startat);
+ if (*pp)
+ {
+ Msg(0, "No more windows.");
+ return -1;
+ }
+
+#if defined(USRLIMIT) && defined(UTMPOK)
+ /*
+ * Count current number of users, if logging windows in.
+ */
+ if (nwin.lflag && CountUsers() >= USRLIMIT)
+ {
+ Msg(0, "User limit reached. Window will not be logged in.");
+ nwin.lflag = 0;
+ }
+#endif
+ n = pp - wtab;
+ debug1("Makewin creating %d\n", n);
+
+#ifdef BUILTIN_TELNET
+ if(!strcmp(nwin.args[0], "//telnet")) {
+ type = W_TYPE_TELNET;
+ TtyName = "telnet";
+ }
+ else
+#endif
+ if ((f = OpenDevice(nwin.args, nwin.lflag, &type, &TtyName)) < 0)
+ return -1;
+ if (type == W_TYPE_GROUP)
+ f = -1;
+
+ if ((p = (struct win *)calloc(1, sizeof(struct win))) == 0)
+ {
+ close(f);
+ Msg(0, "%s", strnomem);
+ return -1;
+ }
+
+#ifdef UTMPOK
+ if (type != W_TYPE_PTY)
+ nwin.lflag = 0;
+#endif
+
+ p->w_type = type;
+
+ /* save the command line so that zombies can be resurrected */
+ for (i = 0; nwin.args[i] && i < MAXARGS - 1; i++)
+ p->w_cmdargs[i] = SaveStr(nwin.args[i]);
+ p->w_cmdargs[i] = 0;
+ if (nwin.dir)
+ p->w_dir = SaveStr(nwin.dir);
+ if (nwin.term)
+ p->w_term = SaveStr(nwin.term);
+
+ p->w_number = n;
+ p->w_group = 0;
+ if (fore && fore->w_type == W_TYPE_GROUP)
+ p->w_group = fore;
+ else if (fore && fore->w_group)
+ p->w_group = fore->w_group;
+#ifdef MULTIUSER
+ /*
+ * This is dangerous: without a display we use creators umask
+ * This is intended to be useful for detached startup.
+ * But is still better than default bits with a NULL user.
+ */
+ if (NewWindowAcl(p, display ? D_user : users))
+ {
+ free((char *)p);
+ close(f);
+ Msg(0, "%s", strnomem);
+ return -1;
+ }
+#endif
+ p->w_layer.l_next = 0;
+ p->w_layer.l_bottom = &p->w_layer;
+ p->w_layer.l_layfn = &WinLf;
+ p->w_layer.l_data = (char *)p;
+ p->w_savelayer = &p->w_layer;
+ p->w_pdisplay = 0;
+ p->w_lastdisp = 0;
+
+#ifdef MULTIUSER
+ if (display && !AclCheckPermWin(D_user, ACL_WRITE, p))
+ p->w_wlockuser = D_user;
+ p->w_wlock = nwin.wlock;
+#endif
+ p->w_ptyfd = f;
+ p->w_aflag = nwin.aflag;
+ p->w_dynamicaka = nwin.dynamicaka;
+ p->w_flow = nwin.flowflag | ((nwin.flowflag & FLOW_AUTOFLAG) ? (FLOW_AUTO|FLOW_NOW) : FLOW_AUTO);
+ if (!nwin.aka)
+ nwin.aka = Filename(nwin.args[0]);
+ strncpy(p->w_akabuf, nwin.aka, sizeof(p->w_akabuf) - 1);
+ if ((nwin.aka = rindex(p->w_akabuf, '|')) != NULL)
+ {
+ p->w_autoaka = 0;
+ *nwin.aka++ = 0;
+ p->w_title = nwin.aka;
+ p->w_akachange = nwin.aka + strlen(nwin.aka);
+ }
+ else
+ p->w_title = p->w_akachange = p->w_akabuf;
+ if (nwin.hstatus)
+ p->w_hstatus = SaveStr(nwin.hstatus);
+ p->w_monitor = nwin.monitor;
+#ifdef MULTIUSER
+ if (p->w_monitor == MON_ON)
+ {
+ /* always tell all users */
+ for (i = 0; i < maxusercount; i++)
+ ACLBYTE(p->w_mon_notify, i) |= ACLBIT(i);
+ }
+#endif
+ /*
+ * defsilence by Lloyd Zusman (zusman_lloyd@jpmorgan.com)
+ */
+ p->w_silence = nwin.silence;
+ p->w_silencewait = SilenceWait;
+#ifdef MULTIUSER
+ if (p->w_silence == SILENCE_ON)
+ {
+ /* always tell all users */
+ for (i = 0; i < maxusercount; i++)
+ ACLBYTE(p->w_lio_notify, i) |= ACLBIT(i);
+ }
+#endif
+#ifdef COPY_PASTE
+ p->w_slowpaste = nwin.slow;
+#else
+ nwin.histheight = 0;
+#endif
+
+ p->w_norefresh = 0;
+ strncpy(p->w_tty, TtyName, MAXSTR - 1);
+
+#if 0
+ /* XXX Fixme display resize */
+ if (ChangeWindowSize(p, display ? D_defwidth : 80,
+ display ? D_defheight : 24,
+ nwin.histheight))
+ {
+ FreeWindow(p);
+ return -1;
+ }
+#else
+ if (ChangeWindowSize(p, display ? D_forecv->c_xe - D_forecv->c_xs + 1: 80,
+ display ? D_forecv->c_ye - D_forecv->c_ys + 1 : 24,
+ nwin.histheight))
+ {
+ FreeWindow(p);
+ return -1;
+ }
+#endif
+
+ p->w_encoding = nwin.encoding;
+ ResetWindow(p); /* sets w_wrap, w_c1, w_gr, w_bce */
+
+#ifdef FONT
+ if (nwin.charset)
+ SetCharsets(p, nwin.charset);
+#endif
+
+ if (VerboseCreate && type != W_TYPE_GROUP)
+ {
+ struct display *d = display; /* WriteString zaps display */
+
+ WriteString(p, ":screen (", 9);
+ WriteString(p, p->w_title, strlen(p->w_title));
+ WriteString(p, "):", 2);
+ for (f = 0; p->w_cmdargs[f]; f++)
+ {
+ WriteString(p, " ", 1);
+ WriteString(p, p->w_cmdargs[f], strlen(p->w_cmdargs[f]));
+ }
+ WriteString(p, "\r\n", 2);
+ display = d;
+ }
+
+ p->w_deadpid = 0;
+ p->w_pid = 0;
+#ifdef PSEUDOS
+ p->w_pwin = 0;
+#endif
+
+#ifdef BUILTIN_TELNET
+ if (type == W_TYPE_TELNET)
+ {
+ if (TelOpenAndConnect(p))
+ {
+ FreeWindow(p);
+ return -1;
+ }
+ }
+ else
+#endif
+ if (type == W_TYPE_PTY)
+ {
+ p->w_pid = ForkWindow(p, nwin.args, TtyName);
+ if (p->w_pid < 0)
+ {
+ FreeWindow(p);
+ return -1;
+ }
+ }
+
+ /*
+ * Place the new window at the head of the most-recently-used list.
+ */
+ if (display && D_fore)
+ D_other = D_fore;
+ *pp = p;
+ p->w_next = windows;
+ windows = p;
+
+ if (type == W_TYPE_GROUP)
+ {
+ SetForeWindow(p);
+ Activate(p->w_norefresh);
+ WindowChanged((struct win*)0, 'w');
+ WindowChanged((struct win*)0, 'W');
+ WindowChanged((struct win*)0, 0);
+ return n;
+ }
+
+ p->w_lflag = nwin.lflag;
+#ifdef UTMPOK
+ p->w_slot = (slot_t)-1;
+# ifdef LOGOUTOK
+ debug1("MakeWindow will %slog in.\n", nwin.lflag?"":"not ");
+ if (nwin.lflag & 1)
+# else /* LOGOUTOK */
+ debug1("MakeWindow will log in, LOGOUTOK undefined in config.h%s.\n",
+ nwin.lflag?"":" (although lflag=0)");
+# endif /* LOGOUTOK */
+ {
+ p->w_slot = (slot_t)0;
+ if (display || (p->w_lflag & 2))
+ SetUtmp(p);
+ }
+# ifdef CAREFULUTMP
+ CarefulUtmp(); /* If all 've been zombies, we've had no slot */
+# endif
+#endif /* UTMPOK */
+
+ if (nwin.Lflag)
+ {
+ char buf[1024];
+ DoStartLog(p, buf, sizeof(buf));
+ }
+
+ /* Is this all where I have to init window poll timeout? */
+ if (nwin.poll_zombie_timeout)
+ p->w_poll_zombie_timeout = nwin.poll_zombie_timeout;
+
+ p->w_zombieev.type = EV_TIMEOUT;
+ p->w_zombieev.data = (char *)p;
+ p->w_zombieev.handler = win_resurrect_zombie_fn;
+
+ p->w_readev.fd = p->w_writeev.fd = p->w_ptyfd;
+ p->w_readev.type = EV_READ;
+ p->w_writeev.type = EV_WRITE;
+ p->w_readev.data = p->w_writeev.data = (char *)p;
+ p->w_readev.handler = win_readev_fn;
+ p->w_writeev.handler = win_writeev_fn;
+ p->w_writeev.condpos = &p->w_inlen;
+ evenq(&p->w_readev);
+ evenq(&p->w_writeev);
+#ifdef COPY_PASTE
+ p->w_paster.pa_slowev.type = EV_TIMEOUT;
+ p->w_paster.pa_slowev.data = (char *)&p->w_paster;
+ p->w_paster.pa_slowev.handler = paste_slowev_fn;
+#endif
+ p->w_silenceev.type = EV_TIMEOUT;
+ p->w_silenceev.data = (char *)p;
+ p->w_silenceev.handler = win_silenceev_fn;
+ if (p->w_silence > 0)
+ {
+ debug("New window has silence enabled.\n");
+ SetTimeout(&p->w_silenceev, p->w_silencewait * 1000);
+ evenq(&p->w_silenceev);
+ }
+ p->w_destroyev.type = EV_TIMEOUT;
+ p->w_destroyev.data = 0;
+ p->w_destroyev.handler = win_destroyev_fn;
+
+ SetForeWindow(p);
+ Activate(p->w_norefresh);
+ WindowChanged((struct win*)0, 'w');
+ WindowChanged((struct win*)0, 'W');
+ WindowChanged((struct win*)0, 0);
+ return n;
+}
+
+/*
+ * Resurrect a window from Zombie state.
+ * The command vector is therefore stored in the window structure.
+ * Note: The terminaltype defaults to screenterm again, the current
+ * working directory is lost.
+ */
+int
+RemakeWindow(p)
+struct win *p;
+{
+ char *TtyName;
+ int lflag, f;
+
+ lflag = nwin_default.lflag;
+#ifdef BUILTIN_TELNET
+ if(!strcmp(p->w_cmdargs[0], "//telnet")) {
+ p->w_type = W_TYPE_TELNET;
+ TtyName = "telnet";
+ }
+ else
+#endif
+ if ((f = OpenDevice(p->w_cmdargs, lflag, &p->w_type, &TtyName)) < 0)
+ return -1;
+
+ evdeq(&p->w_destroyev); /* no re-destroy of resurrected zombie */
+
+ strncpy(p->w_tty, *TtyName ? TtyName : p->w_title, MAXSTR - 1);
+ p->w_ptyfd = f;
+ p->w_readev.fd = f;
+ p->w_writeev.fd = f;
+ evenq(&p->w_readev);
+ evenq(&p->w_writeev);
+
+ if (VerboseCreate)
+ {
+ struct display *d = display; /* WriteString zaps display */
+
+ WriteString(p, ":screen (", 9);
+ WriteString(p, p->w_title, strlen(p->w_title));
+ WriteString(p, "):", 2);
+ for (f = 0; p->w_cmdargs[f]; f++)
+ {
+ WriteString(p, " ", 1);
+ WriteString(p, p->w_cmdargs[f], strlen(p->w_cmdargs[f]));
+ }
+ WriteString(p, "\r\n", 2);
+ display = d;
+ }
+
+ p->w_deadpid = 0;
+ p->w_pid = 0;
+#ifdef BUILTIN_TELNET
+ if (p->w_type == W_TYPE_TELNET)
+ {
+ if (TelOpenAndConnect(p))
+ return -1;
+ }
+ else
+#endif
+ if (p->w_type == W_TYPE_PTY)
+ {
+ p->w_pid = ForkWindow(p, p->w_cmdargs, TtyName);
+ if (p->w_pid < 0)
+ return -1;
+ }
+
+#ifdef UTMPOK
+ if (p->w_slot == (slot_t)0 && (display || (p->w_lflag & 2)))
+ SetUtmp(p);
+# ifdef CAREFULUTMP
+ CarefulUtmp(); /* If all 've been zombies, we've had no slot */
+# endif
+#endif
+ WindowChanged(p, 'f');
+ return p->w_number;
+}
+
+void
+CloseDevice(wp)
+struct win *wp;
+{
+ if (wp->w_ptyfd < 0)
+ return;
+ if (wp->w_type == W_TYPE_PTY)
+ {
+ /* pty 4 SALE */
+ (void)chmod(wp->w_tty, 0666);
+ (void)chown(wp->w_tty, 0, 0);
+ }
+ close(wp->w_ptyfd);
+ wp->w_ptyfd = -1;
+ wp->w_tty[0] = 0;
+ evdeq(&wp->w_readev);
+ evdeq(&wp->w_writeev);
+#ifdef BUILTIN_TELNET
+ evdeq(&wp->w_telconnev);
+#endif
+ wp->w_readev.fd = wp->w_writeev.fd = -1;
+}
+
+void
+FreeWindow(wp)
+struct win *wp;
+{
+ struct display *d;
+ int i;
+ struct canvas *cv, *ncv;
+ struct layer *l;
+
+ debug1("FreeWindow %d\n", wp ? wp->w_number: -1);
+#ifdef PSEUDOS
+ if (wp->w_pwin)
+ FreePseudowin(wp);
+#endif
+#ifdef UTMPOK
+ RemoveUtmp(wp);
+#endif
+ CloseDevice(wp);
+
+ if (wp == console_window)
+ {
+ TtyGrabConsole(-1, -1, "free");
+ console_window = 0;
+ }
+ if (wp->w_log != NULL)
+ logfclose(wp->w_log);
+ ChangeWindowSize(wp, 0, 0, 0);
+
+ if (wp->w_type == W_TYPE_GROUP)
+ {
+ struct win *win;
+ for (win = windows; win; win = win->w_next)
+ if (win->w_group == wp)
+ win->w_group = wp->w_group;
+ }
+
+ if (wp->w_hstatus)
+ free(wp->w_hstatus);
+ for (i = 0; wp->w_cmdargs[i]; i++)
+ free(wp->w_cmdargs[i]);
+ if (wp->w_dir)
+ free(wp->w_dir);
+ if (wp->w_term)
+ free(wp->w_term);
+ for (d = displays; d; d = d->d_next)
+ {
+ if (d->d_other == wp)
+ d->d_other = d->d_fore && d->d_fore->w_next != wp ? d->d_fore->w_next : wp->w_next;
+ if (d->d_fore == wp)
+ d->d_fore = NULL;
+ for (cv = d->d_cvlist; cv; cv = cv->c_next)
+ {
+ for (l = cv->c_layer; l; l = l->l_next)
+ if (l->l_layfn == &WinLf)
+ break;
+ if (!l)
+ continue;
+ if ((struct win *)l->l_data != wp)
+ continue;
+ if (cv->c_layer == wp->w_savelayer)
+ wp->w_savelayer = 0;
+ KillLayerChain(cv->c_layer);
+ }
+ }
+ if (wp->w_savelayer)
+ KillLayerChain(wp->w_savelayer);
+ for (cv = wp->w_layer.l_cvlist; cv; cv = ncv)
+ {
+ ncv = cv->c_lnext;
+ cv->c_layer = &cv->c_blank;
+ cv->c_blank.l_cvlist = cv;
+ cv->c_lnext = 0;
+ cv->c_xoff = cv->c_xs;
+ cv->c_yoff = cv->c_ys;
+ RethinkViewportOffsets(cv);
+ }
+ wp->w_layer.l_cvlist = 0;
+ if (flayer == &wp->w_layer)
+ flayer = 0;
+ LayerCleanupMemory(&wp->w_layer);
+
+#ifdef MULTIUSER
+ FreeWindowAcl(wp);
+#endif /* MULTIUSER */
+ evdeq(&wp->w_readev); /* just in case */
+ evdeq(&wp->w_writeev); /* just in case */
+ evdeq(&wp->w_silenceev);
+ evdeq(&wp->w_zombieev);
+ evdeq(&wp->w_destroyev);
+#ifdef COPY_PASTE
+ FreePaster(&wp->w_paster);
+#endif
+ free((char *)wp);
+}
+
+static int
+OpenDevice(args, lflag, typep, namep)
+char **args;
+int lflag;
+int *typep;
+char **namep;
+{
+ char *arg = args[0];
+ struct stat st;
+ int f;
+
+ if (!arg)
+ return -1;
+ if (strcmp(arg, "//group") == 0)
+ {
+ *typep = W_TYPE_GROUP;
+ *namep = "telnet";
+ return 0;
+ }
+ if (strncmp(arg, "//", 2) == 0)
+ {
+ Msg(0, "Invalid argument '%s'", arg);
+ return -1;
+ }
+ else if ((stat(arg, &st)) == 0 && S_ISCHR(st.st_mode))
+ {
+ if (access(arg, R_OK | W_OK) == -1)
+ {
+ Msg(errno, "Cannot access line '%s' for R/W", arg);
+ return -1;
+ }
+ debug("OpenDevice: OpenTTY\n");
+ if ((f = OpenTTY(arg, args[1])) < 0)
+ return -1;
+ lflag = 0;
+ *typep = W_TYPE_PLAIN;
+ *namep = arg;
+ }
+ else
+ {
+ *typep = W_TYPE_PTY;
+ f = OpenPTY(namep);
+ if (f == -1)
+ {
+ Msg(0, "No more PTYs.");
+ return -1;
+ }
+#ifdef TIOCPKT
+ {
+ int flag = 1;
+ if (ioctl(f, TIOCPKT, (char *)&flag))
+ {
+ Msg(errno, "TIOCPKT ioctl");
+ close(f);
+ return -1;
+ }
+ }
+#endif /* TIOCPKT */
+ }
+ debug1("fcntl(%d, F_SETFL, FNBLOCK)\n", f);
+ (void) fcntl(f, F_SETFL, FNBLOCK);
+#ifdef linux
+ /*
+ * Tenebreux (zeus@ns.acadiacom.net) has Linux 1.3.70 where select
+ * gets confused in the following condition:
+ * Open a pty-master side, request a flush on it, then set packet
+ * mode and call select(). Select will return a possible read, where
+ * the one byte response to the flush can be found. Select will
+ * thereafter return a possible read, which yields I/O error.
+ *
+ * If we request another flush *after* switching into packet mode,
+ * this I/O error does not occur. We receive a single response byte
+ * although we send two flush requests now.
+ *
+ * Maybe we should not flush at all.
+ *
+ * 10.5.96 jw.
+ */
+ if (*typep == W_TYPE_PTY || *typep == W_TYPE_PLAIN)
+ tcflush(f, TCIOFLUSH);
+#endif
+
+ if (*typep != W_TYPE_PTY)
+ return f;
+
+#ifndef PTYROFS
+#ifdef PTYGROUP
+ if (chown(*namep, real_uid, PTYGROUP) && !eff_uid)
+#else
+ if (chown(*namep, real_uid, real_gid) && !eff_uid)
+#endif
+ {
+ Msg(errno, "chown tty");
+ close(f);
+ return -1;
+ }
+#ifdef UTMPOK
+ if (chmod(*namep, lflag ? TtyMode : (TtyMode & ~022)) && !eff_uid)
+#else
+ if (chmod(*namep, TtyMode) && !eff_uid)
+#endif
+ {
+ Msg(errno, "chmod tty");
+ close(f);
+ return -1;
+ }
+#endif
+ return f;
+}
+
+/*
+ * Fields w_width, w_height, aflag, number (and w_tty)
+ * are read from struct win *win. No fields written.
+ * If pwin is nonzero, filedescriptors are distributed
+ * between win->w_tty and open(ttyn)
+ *
+ */
+static int
+ForkWindow(win, args, ttyn)
+struct win *win;
+char **args, *ttyn;
+{
+ int pid;
+ char tebuf[MAXTERMLEN + 5 + 1]; /* MAXTERMLEN + strlen("TERM=") + '\0' */
+ char ebuf[20];
+ char shellbuf[7 + MAXPATHLEN];
+ char *proc;
+#ifndef TIOCSWINSZ
+ char libuf[20], cobuf[20];
+#endif
+ int newfd;
+ int w = win->w_width;
+ int h = win->w_height;
+#ifdef PSEUDOS
+ int i, pat, wfdused;
+ struct pseudowin *pwin = win->w_pwin;
+#endif
+ int slave = -1;
+
+#ifdef O_NOCTTY
+ if (pty_preopen)
+ {
+ debug("pre-opening slave...\n");
+ if ((slave = open(ttyn, O_RDWR|O_NOCTTY)) == -1)
+ {
+ Msg(errno, "ttyn");
+ return -1;
+ }
+ }
+#endif
+ debug("forking...\n");
+ proc = *args;
+ if (proc == 0)
+ {
+ args = ShellArgs;
+ proc = *args;
+ }
+ fflush(stdout);
+ fflush(stderr);
+ switch (pid = fork())
+ {
+ case -1:
+ Msg(errno, "fork");
+ break;
+ case 0:
+ signal(SIGHUP, SIG_DFL);
+ signal(SIGINT, SIG_DFL);
+ signal(SIGQUIT, SIG_DFL);
+ signal(SIGTERM, SIG_DFL);
+#ifdef BSDJOBS
+ signal(SIGTTIN, SIG_DFL);
+ signal(SIGTTOU, SIG_DFL);
+#endif
+#ifdef SIGPIPE
+ signal(SIGPIPE, SIG_DFL);
+#endif
+#ifdef SIGXFSZ
+ signal(SIGXFSZ, SIG_DFL);
+#endif
+
+ displays = 0; /* beware of Panic() */
+ if (setgid(real_gid) || setuid(real_uid))
+ Panic(errno, "Setuid/gid");
+ eff_uid = real_uid;
+ eff_gid = real_gid;
+#ifdef PSEUDOS
+ if (!pwin) /* ignore directory if pseudo */
+#endif
+ if (win->w_dir && *win->w_dir && chdir(win->w_dir))
+ Panic(errno, "Cannot chdir to %s", win->w_dir);
+
+ if (display)
+ {
+ brktty(D_userfd);
+ freetty();
+ }
+ else
+ brktty(-1);
+#ifdef DEBUG
+ if (dfp && dfp != stderr)
+ fclose(dfp);
+#endif
+ if (slave != -1)
+ {
+ close(0);
+ dup(slave);
+ close(slave);
+ closeallfiles(win->w_ptyfd);
+ slave = dup(0);
+ }
+ else
+ closeallfiles(win->w_ptyfd);
+#ifdef DEBUG
+ if (dfp) /* do not produce child debug, when debug is "off" */
+ {
+ char buf[256];
+
+ sprintf(buf, "%s/screen.child", DEBUGDIR);
+ if ((dfp = fopen(buf, "a")) == 0)
+ dfp = stderr;
+ else
+ (void) chmod(buf, 0666);
+ }
+ debug1("=== ForkWindow: pid %d\n", (int)getpid());
+#endif
+ /* Close the three /dev/null descriptors */
+ close(0);
+ close(1);
+ close(2);
+ newfd = -1;
+ /*
+ * distribute filedescriptors between the ttys
+ */
+#ifdef PSEUDOS
+ pat = pwin ? pwin->p_fdpat :
+ ((F_PFRONT<<(F_PSHIFT*2)) | (F_PFRONT<<F_PSHIFT) | F_PFRONT);
+ debug1("Using window pattern 0x%x\n", pat);
+ wfdused = 0;
+ for(i = 0; i < 3; i++)
+ {
+ if (pat & F_PFRONT << F_PSHIFT * i)
+ {
+ if (newfd < 0)
+ {
+# ifdef O_NOCTTY
+ if (separate_sids)
+ newfd = open(ttyn, O_RDWR);
+ else
+ newfd = open(ttyn, O_RDWR|O_NOCTTY);
+# else
+ newfd = open(ttyn, O_RDWR);
+# endif
+ if (newfd < 0)
+ Panic(errno, "Cannot open %s", ttyn);
+ }
+ else
+ dup(newfd);
+ }
+ else
+ {
+ dup(win->w_ptyfd);
+ wfdused = 1;
+ }
+ }
+ if (wfdused)
+ {
+ /*
+ * the pseudo window process should not be surprised with a
+ * nonblocking filedescriptor. Poor Backend!
+ */
+ debug1("Clearing NBLOCK on window-fd(%d)\n", win->w_ptyfd);
+ if (fcntl(win->w_ptyfd, F_SETFL, 0))
+ Msg(errno, "Warning: clear NBLOCK fcntl failed");
+ }
+#else /* PSEUDOS */
+# ifdef O_NOCTTY
+ if (separate_sids)
+ newfd = open(ttyn, O_RDWR);
+ else
+ newfd = open(ttyn, O_RDWR|O_NOCTTY);
+# else
+ newfd = open(ttyn, O_RDWR);
+# endif
+ if (newfd != 0)
+ Panic(errno, "Cannot open %s", ttyn);
+ dup(0);
+ dup(0);
+#endif /* PSEUDOS */
+ close(win->w_ptyfd);
+ if (slave != -1)
+ close(slave);
+ if (newfd >= 0)
+ {
+ struct mode fakemode, *modep;
+ InitPTY(newfd);
+ if (fgtty(newfd))
+ Msg(errno, "fgtty");
+ if (display)
+ {
+ debug("ForkWindow: using display tty mode for new child.\n");
+ modep = &D_OldMode;
+ }
+ else
+ {
+ debug("No display - creating tty setting\n");
+ modep = &fakemode;
+ InitTTY(modep, 0);
+#ifdef DEBUG
+ DebugTTY(modep);
+#endif
+ }
+ /* We only want echo if the users input goes to the pseudo
+ * and the pseudo's stdout is not send to the window.
+ */
+#ifdef PSEUDOS
+ if (pwin && (!(pat & F_UWP) || (pat & F_PBACK << F_PSHIFT)))
+ {
+ debug1("clearing echo on pseudywin fd (pat %x)\n", pat);
+# if defined(POSIX) || defined(TERMIO)
+ modep->tio.c_lflag &= ~ECHO;
+ modep->tio.c_iflag &= ~ICRNL;
+# else
+ modep->m_ttyb.sg_flags &= ~ECHO;
+# endif
+ }
+#endif
+ SetTTY(newfd, modep);
+#ifdef TIOCSWINSZ
+ glwz.ws_col = w;
+ glwz.ws_row = h;
+ (void) ioctl(newfd, TIOCSWINSZ, (char *)&glwz);
+#endif
+ /* Always turn off nonblocking mode */
+ (void)fcntl(newfd, F_SETFL, 0);
+ }
+#ifndef TIOCSWINSZ
+ sprintf(libuf, "LINES=%d", h);
+ sprintf(cobuf, "COLUMNS=%d", w);
+ NewEnv[5] = libuf;
+ NewEnv[6] = cobuf;
+#endif
+#ifdef MAPKEYS
+ NewEnv[2] = MakeTermcap(display == 0 || win->w_aflag);
+#else
+ if (win->w_aflag)
+ NewEnv[2] = MakeTermcap(1);
+ else
+ NewEnv[2] = Termcap;
+#endif
+ strcpy(shellbuf, "SHELL=");
+ strncpy(shellbuf + 6, ShellProg + (*ShellProg == '-'), sizeof(shellbuf) - 7);
+ shellbuf[sizeof(shellbuf) - 1] = 0;
+ NewEnv[4] = shellbuf;
+ debug1("ForkWindow: NewEnv[4] = '%s'\n", shellbuf);
+ if (win->w_term && *win->w_term && strcmp(screenterm, win->w_term) &&
+ (strlen(win->w_term) < MAXTERMLEN))
+ {
+ char *s1, *s2, tl;
+
+ snprintf(tebuf, sizeof(tebuf), "TERM=%s", win->w_term);
+ debug2("Makewindow %d with %s\n", win->w_number, tebuf);
+ tl = strlen(win->w_term);
+ NewEnv[1] = tebuf;
+ if ((s1 = index(NewEnv[2], '|')))
+ {
+ if ((s2 = index(++s1, '|')))
+ {
+ if (strlen(NewEnv[2]) - (s2 - s1) + tl < 1024)
+ {
+ bcopy(s2, s1 + tl, strlen(s2) + 1);
+ bcopy(win->w_term, s1, tl);
+ }
+ }
+ }
+ }
+ snprintf(ebuf, sizeof(ebuf), "WINDOW=%d", win->w_number);
+ NewEnv[3] = ebuf;
+
+ if (*proc == '-')
+ proc++;
+ if (!*proc)
+ proc = DefaultShell;
+ debug1("calling execvpe %s\n", proc);
+ execvpe(proc, args, NewEnv);
+ debug1("exec error: %d\n", errno);
+ Panic(errno, "Cannot exec '%s'", proc);
+ default:
+ break;
+ }
+ if (slave != -1)
+ close(slave);
+ return pid;
+}
+
+#ifndef HAVE_EXECVPE
+void
+execvpe(prog, args, env)
+char *prog, **args, **env;
+{
+ register char *path = NULL, *p;
+ char buf[1024];
+ char *shargs[MAXARGS + 1];
+ register int i, eaccess = 0;
+
+ if (rindex(prog, '/'))
+ path = "";
+ if (!path && !(path = getenv("PATH")))
+ path = DefaultPath;
+ do
+ {
+ for (p = buf; *path && *path != ':'; path++)
+ if (p - buf < (int)sizeof(buf) - 2)
+ *p++ = *path;
+ if (p > buf)
+ *p++ = '/';
+ if (p - buf + strlen(prog) >= sizeof(buf) - 1)
+ continue;
+ strcpy(p, prog);
+ execve(buf, args, env);
+ switch (errno)
+ {
+ case ENOEXEC:
+ shargs[0] = DefaultShell;
+ shargs[1] = buf;
+ for (i = 1; (shargs[i + 1] = args[i]) != NULL; ++i)
+ ;
+ execve(DefaultShell, shargs, env);
+ return;
+ case EACCES:
+ eaccess = 1;
+ break;
+ case ENOMEM:
+ case E2BIG:
+ case ETXTBSY:
+ return;
+ }
+ } while (*path++);
+ if (eaccess)
+ errno = EACCES;
+}
+#endif
+
+#ifdef PSEUDOS
+
+int
+winexec(av)
+char **av;
+{
+ char **pp;
+ char *p, *s, *t;
+ int i, r = 0, l = 0;
+ struct win *w;
+ extern struct display *display;
+ extern struct win *windows;
+ struct pseudowin *pwin;
+ int type;
+
+ if ((w = display ? fore : windows) == NULL)
+ return -1;
+ if (!*av || w->w_pwin)
+ {
+ Msg(0, "Filter running: %s", w->w_pwin ? w->w_pwin->p_cmd : "(none)");
+ return -1;
+ }
+ if (w->w_ptyfd < 0)
+ {
+ Msg(0, "You feel dead inside.");
+ return -1;
+ }
+ if (!(pwin = (struct pseudowin *)calloc(1, sizeof(struct pseudowin))))
+ {
+ Msg(0, "%s", strnomem);
+ return -1;
+ }
+
+ /* allow ^a:!!./ttytest as a short form for ^a:exec !.. ./ttytest */
+ for (s = *av; *s == ' '; s++)
+ ;
+ for (p = s; *p == ':' || *p == '.' || *p == '!'; p++)
+ ;
+ if (*p != '|')
+ while (*p && p > s && p[-1] == '.')
+ p--;
+ if (*p == '|')
+ {
+ l = F_UWP;
+ p++;
+ }
+ if (*p)
+ av[0] = p;
+ else
+ av++;
+
+ t = pwin->p_cmd;
+ for (i = 0; i < 3; i++)
+ {
+ *t = (s < p) ? *s++ : '.';
+ switch (*t++)
+ {
+ case '.':
+ case '|':
+ l |= F_PFRONT << (i * F_PSHIFT);
+ break;
+ case '!':
+ l |= F_PBACK << (i * F_PSHIFT);
+ break;
+ case ':':
+ l |= F_PBOTH << (i * F_PSHIFT);
+ break;
+ }
+ }
+
+ if (l & F_UWP)
+ {
+ *t++ = '|';
+ if ((l & F_PMASK) == F_PFRONT)
+ {
+ *pwin->p_cmd = '!';
+ l ^= F_PFRONT | F_PBACK;
+ }
+ }
+ if (!(l & F_PBACK))
+ l |= F_UWP;
+ *t++ = ' ';
+ pwin->p_fdpat = l;
+ debug1("winexec: '%#x'\n", pwin->p_fdpat);
+
+ l = MAXSTR - 4;
+ for (pp = av; *pp; pp++)
+ {
+ p = *pp;
+ while (*p && l-- > 0)
+ *t++ = *p++;
+ if (l <= 0)
+ break;
+ *t++ = ' ';
+ }
+ *--t = '\0';
+ debug1("%s\n", pwin->p_cmd);
+
+ if ((pwin->p_ptyfd = OpenDevice(av, 0, &type, &t)) < 0)
+ {
+ free((char *)pwin);
+ return -1;
+ }
+ strncpy(pwin->p_tty, t, MAXSTR - 1);
+ w->w_pwin = pwin;
+ if (type != W_TYPE_PTY)
+ {
+ FreePseudowin(w);
+ Msg(0, "Cannot only use commands as pseudo win.");
+ return -1;
+ }
+ if (!(pwin->p_fdpat & F_PFRONT))
+ evdeq(&w->w_readev);
+#ifdef TIOCPKT
+ {
+ int flag = 0;
+
+ if (ioctl(pwin->p_ptyfd, TIOCPKT, (char *)&flag))
+ {
+ Msg(errno, "TIOCPKT pwin ioctl");
+ FreePseudowin(w);
+ return -1;
+ }
+ if (w->w_type == W_TYPE_PTY && !(pwin->p_fdpat & F_PFRONT))
+ {
+ if (ioctl(w->w_ptyfd, TIOCPKT, (char *)&flag))
+ {
+ Msg(errno, "TIOCPKT win ioctl");
+ FreePseudowin(w);
+ return -1;
+ }
+ }
+ }
+#endif /* TIOCPKT */
+
+ pwin->p_readev.fd = pwin->p_writeev.fd = pwin->p_ptyfd;
+ pwin->p_readev.type = EV_READ;
+ pwin->p_writeev.type = EV_WRITE;
+ pwin->p_readev.data = pwin->p_writeev.data = (char *)w;
+ pwin->p_readev.handler = pseu_readev_fn;
+ pwin->p_writeev.handler = pseu_writeev_fn;
+ pwin->p_writeev.condpos = &pwin->p_inlen;
+ if (pwin->p_fdpat & (F_PFRONT << F_PSHIFT * 2 | F_PFRONT << F_PSHIFT))
+ evenq(&pwin->p_readev);
+ evenq(&pwin->p_writeev);
+ r = pwin->p_pid = ForkWindow(w, av, t);
+ if (r < 0)
+ FreePseudowin(w);
+ return r;
+}
+
+void
+FreePseudowin(w)
+struct win *w;
+{
+ struct pseudowin *pwin = w->w_pwin;
+
+ ASSERT(pwin);
+ if (fcntl(w->w_ptyfd, F_SETFL, FNBLOCK))
+ Msg(errno, "Warning: FreePseudowin: NBLOCK fcntl failed");
+#ifdef TIOCPKT
+ if (w->w_type == W_TYPE_PTY && !(pwin->p_fdpat & F_PFRONT))
+ {
+ int flag = 1;
+ if (ioctl(w->w_ptyfd, TIOCPKT, (char *)&flag))
+ Msg(errno, "Warning: FreePseudowin: TIOCPKT win ioctl");
+ }
+#endif
+ /* should be able to use CloseDevice() here */
+ (void)chmod(pwin->p_tty, 0666);
+ (void)chown(pwin->p_tty, 0, 0);
+ if (pwin->p_ptyfd >= 0)
+ close(pwin->p_ptyfd);
+ evdeq(&pwin->p_readev);
+ evdeq(&pwin->p_writeev);
+ if (w->w_readev.condneg == &pwin->p_inlen)
+ w->w_readev.condpos = w->w_readev.condneg = 0;
+ evenq(&w->w_readev);
+ free((char *)pwin);
+ w->w_pwin = NULL;
+}
+
+#endif /* PSEUDOS */
+
+
+#ifdef MULTIUSER
+/*
+ * returns 0, if the lock really has been released
+ */
+int
+ReleaseAutoWritelock(dis, w)
+struct display *dis;
+struct win *w;
+{
+ debug2("ReleaseAutoWritelock: user %s, window %d\n",
+ dis->d_user->u_name, w->w_number);
+
+ /* release auto writelock when user has no other display here */
+ if (w->w_wlock == WLOCK_AUTO && w->w_wlockuser == dis->d_user)
+ {
+ struct display *d;
+
+ for (d = displays; d; d = d->d_next)
+ if (( d != dis) && (d->d_fore == w) && (d->d_user == dis->d_user))
+ break;
+ debug3("%s %s autolock on win %d\n",
+ dis->d_user->u_name, d ? "keeps" : "releases", w->w_number);
+ if (!d)
+ {
+ w->w_wlockuser = NULL;
+ return 0;
+ }
+ }
+ return 1;
+}
+
+/*
+ * returns 0, if the lock really could be obtained
+ */
+int
+ObtainAutoWritelock(d, w)
+struct display *d;
+struct win *w;
+{
+ if ((w->w_wlock == WLOCK_AUTO) &&
+ !AclCheckPermWin(d->d_user, ACL_WRITE, w) &&
+ !w->w_wlockuser)
+ {
+ debug2("%s obtained auto writelock for exported window %d\n",
+ d->d_user->u_name, w->w_number);
+ w->w_wlockuser = d->d_user;
+ return 0;
+ }
+ return 1;
+}
+
+#endif /* MULTIUSER */
+
+
+
+/********************************************************************/
+
+#ifdef COPY_PASTE
+static void
+paste_slowev_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ struct paster *pa = (struct paster *)data;
+ struct win *p;
+
+ int l = 1;
+ flayer = pa->pa_pastelayer;
+ if (!flayer)
+ pa->pa_pastelen = 0;
+ if (!pa->pa_pastelen)
+ return;
+ p = Layer2Window(flayer);
+ DoProcess(p, &pa->pa_pasteptr, &l, pa);
+ pa->pa_pastelen -= 1 - l;
+ if (pa->pa_pastelen > 0)
+ {
+ SetTimeout(&pa->pa_slowev, p->w_slowpaste);
+ evenq(&pa->pa_slowev);
+ }
+}
+#endif
+
+
+static int
+muchpending(p, ev)
+struct win *p;
+struct event *ev;
+{
+ struct canvas *cv;
+ for (cv = p->w_layer.l_cvlist; cv; cv = cv->c_lnext)
+ {
+ display = cv->c_display;
+ if (D_status == STATUS_ON_WIN && !D_status_bell)
+ {
+ /* wait 'til status is gone */
+ debug("BLOCKING because of status\n");
+ ev->condpos = &const_one;
+ ev->condneg = &D_status;
+ return 1;
+ }
+ debug2("muchpending %s %d: ", D_usertty, D_blocked);
+ debug3("%d %d %d\n", D_obufp - D_obuf, D_obufmax, D_blocked_fuzz);
+ if (D_blocked)
+ continue;
+ if (D_obufp - D_obuf > D_obufmax + D_blocked_fuzz)
+ {
+ if (D_nonblock == 0)
+ {
+ debug1("obuf is full, stopping output to display %s\n", D_usertty);
+ D_blocked = 1;
+ continue;
+ }
+ debug("BLOCKING because of full obuf\n");
+ ev->condpos = &D_obuffree;
+ ev->condneg = &D_obuflenmax;
+ if (D_nonblock > 0 && !D_blockedev.queued)
+ {
+ debug1("created timeout of %g secs\n", D_nonblock/1000.);
+ SetTimeout(&D_blockedev, D_nonblock);
+ evenq(&D_blockedev);
+ }
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static void
+win_readev_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ struct win *p = (struct win *)data;
+ char buf[IOSIZE], *bp;
+ int size, len;
+#ifdef PSEUDOS
+ int wtop;
+#endif
+
+ bp = buf;
+ size = IOSIZE;
+
+#ifdef PSEUDOS
+ wtop = p->w_pwin && W_WTOP(p);
+ if (wtop)
+ {
+ ASSERT(sizeof(p->w_pwin->p_inbuf) == IOSIZE);
+ size = IOSIZE - p->w_pwin->p_inlen;
+ if (size <= 0)
+ {
+ ev->condpos = &const_IOSIZE;
+ ev->condneg = &p->w_pwin->p_inlen;
+ return;
+ }
+ }
+#endif
+ if (p->w_layer.l_cvlist && muchpending(p, ev))
+ return;
+#ifdef ZMODEM
+ if (!p->w_zdisplay)
+#endif
+ if (p->w_blocked)
+ {
+ ev->condpos = &const_one;
+ ev->condneg = &p->w_blocked;
+ return;
+ }
+ if (ev->condpos)
+ ev->condpos = ev->condneg = 0;
+
+ if ((len = p->w_outlen))
+ {
+ p->w_outlen = 0;
+ WriteString(p, p->w_outbuf, len);
+ return;
+ }
+
+ debug1("going to read from window fd %d\n", ev->fd);
+ if ((len = read(ev->fd, buf, size)) < 0)
+ {
+ if (errno == EINTR || errno == EAGAIN)
+ return;
+#if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
+ if (errno == EWOULDBLOCK)
+ return;
+#endif
+ debug2("Window %d: read error (errno %d) - killing window\n", p->w_number, errno);
+#ifdef BSDWAIT
+ WindowDied(p, (union wait)0, 0);
+#else
+ WindowDied(p, 0, 0);
+#endif
+ return;
+ }
+ if (len == 0)
+ {
+ debug1("Window %d: EOF - killing window\n", p->w_number);
+#ifdef BSDWAIT
+ WindowDied(p, (union wait)0, 0);
+#else
+ WindowDied(p, 0, 0);
+#endif
+ return;
+ }
+ debug1(" -> %d bytes\n", len);
+#ifdef TIOCPKT
+ if (p->w_type == W_TYPE_PTY)
+ {
+ if (buf[0])
+ {
+ debug1("PAKET %x\n", buf[0]);
+ if (buf[0] & TIOCPKT_NOSTOP)
+ WNewAutoFlow(p, 0);
+ if (buf[0] & TIOCPKT_DOSTOP)
+ WNewAutoFlow(p, 1);
+ }
+ bp++;
+ len--;
+ }
+#endif
+#ifdef BUILTIN_TELNET
+ if (p->w_type == W_TYPE_TELNET)
+ len = TelIn(p, bp, len, buf + sizeof(buf) - (bp + len));
+#endif
+ if (len == 0)
+ return;
+#ifdef ZMODEM
+ if (zmodem_mode && zmodem_parse(p, bp, len))
+ return;
+#endif
+#ifdef PSEUDOS
+ if (wtop)
+ {
+ debug("sending input to pwin\n");
+ bcopy(bp, p->w_pwin->p_inbuf + p->w_pwin->p_inlen, len);
+ p->w_pwin->p_inlen += len;
+ }
+#endif
+
+ LayPause(&p->w_layer, 1);
+ WriteString(p, bp, len);
+ LayPause(&p->w_layer, 0);
+
+ return;
+}
+
+static void
+win_resurrect_zombie_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ struct win *p = (struct win *)data;
+ debug2("Try to resurrecting Zombie event: %d [%s]\n",
+ p->w_number, p->w_title);
+ /* Already reconnected? */
+ if (p->w_deadpid != p->w_pid)
+ return;
+ debug1("Resurrecting Zombie: %d\n", p->w_number);
+ WriteString(p, "\r\n", 2);
+ RemakeWindow(p);
+}
+
+static void
+win_writeev_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ struct win *p = (struct win *)data;
+ int len;
+ if (p->w_inlen)
+ {
+ debug2("writing %d bytes to win %d\n", p->w_inlen, p->w_number);
+ if ((len = write(ev->fd, p->w_inbuf, p->w_inlen)) <= 0)
+ len = p->w_inlen; /* dead window */
+ if ((p->w_inlen -= len))
+ bcopy(p->w_inbuf + len, p->w_inbuf, p->w_inlen);
+ }
+#ifdef COPY_PASTE
+ if (p->w_paster.pa_pastelen && !p->w_slowpaste)
+ {
+ struct paster *pa = &p->w_paster;
+ flayer = pa->pa_pastelayer;
+ if (flayer)
+ DoProcess(p, &pa->pa_pasteptr, &pa->pa_pastelen, pa);
+ }
+#endif
+ return;
+}
+
+
+
+#ifdef PSEUDOS
+
+static void
+pseu_readev_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ struct win *p = (struct win *)data;
+ char buf[IOSIZE];
+ int size, ptow, len;
+
+ size = IOSIZE;
+
+ ptow = W_PTOW(p);
+ if (ptow)
+ {
+ ASSERT(sizeof(p->w_inbuf) == IOSIZE);
+ size = IOSIZE - p->w_inlen;
+ if (size <= 0)
+ {
+ ev->condpos = &const_IOSIZE;
+ ev->condneg = &p->w_inlen;
+ return;
+ }
+ }
+ if (p->w_layer.l_cvlist && muchpending(p, ev))
+ return;
+ if (p->w_blocked)
+ {
+ ev->condpos = &const_one;
+ ev->condneg = &p->w_blocked;
+ return;
+ }
+ if (ev->condpos)
+ ev->condpos = ev->condneg = 0;
+
+ if ((len = p->w_outlen))
+ {
+ p->w_outlen = 0;
+ WriteString(p, p->w_outbuf, len);
+ return;
+ }
+
+ if ((len = read(ev->fd, buf, size)) <= 0)
+ {
+ if (errno == EINTR || errno == EAGAIN)
+ return;
+#if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
+ if (errno == EWOULDBLOCK)
+ return;
+#endif
+ debug2("Window %d: pseudowin read error (errno %d) -- removing pseudowin\n", p->w_number, len ? errno : 0);
+ FreePseudowin(p);
+ return;
+ }
+ /* no packet mode on pseudos! */
+ if (ptow)
+ {
+ bcopy(buf, p->w_inbuf + p->w_inlen, len);
+ p->w_inlen += len;
+ }
+ WriteString(p, buf, len);
+ return;
+}
+
+static void
+pseu_writeev_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ struct win *p = (struct win *)data;
+ struct pseudowin *pw = p->w_pwin;
+ int len;
+
+ ASSERT(pw);
+ if (pw->p_inlen == 0)
+ return;
+ if ((len = write(ev->fd, pw->p_inbuf, pw->p_inlen)) <= 0)
+ len = pw->p_inlen; /* dead pseudo */
+ if ((p->w_pwin->p_inlen -= len))
+ bcopy(p->w_pwin->p_inbuf + len, p->w_pwin->p_inbuf, p->w_pwin->p_inlen);
+}
+
+
+#endif /* PSEUDOS */
+
+static void
+win_silenceev_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ struct win *p = (struct win *)data;
+ struct canvas *cv;
+ debug1("FOUND silence win %d\n", p->w_number);
+ for (display = displays; display; display = display->d_next)
+ {
+ for (cv = D_cvlist; cv; cv = cv->c_next)
+ if (cv->c_layer->l_bottom == &p->w_layer)
+ break;
+ if (cv)
+ continue; /* user already sees window */
+#ifdef MULTIUSER
+ if (!(ACLBYTE(p->w_lio_notify, D_user->u_id) & ACLBIT(D_user->u_id)))
+ continue;
+#endif
+ Msg(0, "Window %d: silence for %d seconds", p->w_number, p->w_silencewait);
+ p->w_silence = SILENCE_FOUND;
+ WindowChanged(p, 'f');
+ }
+}
+
+static void
+win_destroyev_fn(ev, data)
+struct event *ev;
+char *data;
+{
+ struct win *p = (struct win *)ev->data;
+ WindowDied(p, p->w_exitstatus, 1);
+}
+
+#ifdef ZMODEM
+
+static int
+zmodem_parse(p, bp, len)
+struct win *p;
+char *bp;
+int len;
+{
+ int i;
+ char *b2 = bp;
+ for (i = 0; i < len; i++, b2++)
+ {
+ if (p->w_zauto == 0)
+ {
+ for (; i < len; i++, b2++)
+ if (*b2 == 030)
+ break;
+ if (i == len)
+ break;
+ if (i > 1 && b2[-1] == '*' && b2[-2] == '*')
+ p->w_zauto = 3;
+ continue;
+ }
+ if (p->w_zauto > 5 || *b2 == "**\030B00"[p->w_zauto] || (p->w_zauto == 5 && *b2 == '1') || (p->w_zauto == 5 && p->w_zdisplay && *b2 == '8'))
+ {
+ if (++p->w_zauto < 6)
+ continue;
+ if (p->w_zauto == 6)
+ p->w_zauto = 0;
+ if (!p->w_zdisplay)
+ {
+ if (i > 6)
+ WriteString(p, bp, i + 1 - 6);
+ WriteString(p, "\r\n", 2);
+ zmodem_found(p, *b2 == '1', b2 + 1, len - i - 1);
+ return 1;
+ }
+ else if (p->w_zauto == 7 || *b2 == '8')
+ {
+ int se = p->w_zdisplay->d_blocked == 2 ? 'O' : '\212';
+ for (; i < len; i++, b2++)
+ if (*b2 == se)
+ break;
+ if (i < len)
+ {
+ zmodem_abort(p, 0);
+ D_blocked = 0;
+ D_readev.condpos = D_readev.condneg = 0;
+ while (len-- > 0)
+ AddChar(*bp++);
+ Flush(0);
+ Activate(D_fore ? D_fore->w_norefresh : 0);
+ return 1;
+ }
+ p->w_zauto = 6;
+ }
+ }
+ else
+ p->w_zauto = *b2 == '*' ? (p->w_zauto == 2 ? 2 : 1) : 0;
+ }
+ if (p->w_zauto == 0 && bp[len - 1] == '*')
+ p->w_zauto = len > 1 && bp[len - 2] == '*' ? 2 : 1;
+ if (p->w_zdisplay)
+ {
+ display = p->w_zdisplay;
+ while (len-- > 0)
+ AddChar(*bp++);
+ return 1;
+ }
+ return 0;
+}
+
+static void
+zmodem_fin(buf, len, data)
+char *buf;
+int len;
+char *data;
+{
+ char *s;
+ int n;
+
+ if (len)
+ RcLine(buf, strlen(buf) + 1);
+ else
+ {
+ s = "\030\030\030\030\030\030\030\030\030\030";
+ n = strlen(s);
+ LayProcess(&s, &n);
+ }
+}
+
+static void
+zmodem_found(p, send, bp, len)
+struct win *p;
+int send;
+char *bp;
+int len;
+{
+ char *s;
+ int i, n;
+ extern int zmodem_mode;
+
+ /* check for abort sequence */
+ n = 0;
+ for (i = 0; i < len ; i++)
+ if (bp[i] != 030)
+ n = 0;
+ else if (++n > 4)
+ return;
+ if (zmodem_mode == 3 || (zmodem_mode == 1 && p->w_type != W_TYPE_PLAIN))
+ {
+ struct display *d, *olddisplay;
+
+ olddisplay = display;
+ d = p->w_lastdisp;
+ if (!d || d->d_fore != p)
+ for (d = displays; d; d = d->d_next)
+ if (d->d_fore == p)
+ break;
+ if (!d && p->w_layer.l_cvlist)
+ d = p->w_layer.l_cvlist->c_display;
+ if (!d)
+ d = displays;
+ if (!d)
+ return;
+ display = d;
+ RemoveStatus();
+ p->w_zdisplay = display;
+ D_blocked = 2 + send;
+ flayer = &p->w_layer;
+ ZmodemPage();
+ display = d;
+ evdeq(&D_blockedev);
+ D_readev.condpos = &const_IOSIZE;
+ D_readev.condneg = &p->w_inlen;
+ ClearAll();
+ GotoPos(0, 0);
+ SetRendition(&mchar_blank);
+ AddStr("Zmodem active\r\n\r\n");
+ AddStr(send ? "**\030B01" : "**\030B00");
+ while (len-- > 0)
+ AddChar(*bp++);
+ display = olddisplay;
+ return;
+ }
+ flayer = &p->w_layer;
+ Input(":", MAXSTR, INP_COOKED, zmodem_fin, NULL, 0);
+ s = send ? zmodem_sendcmd : zmodem_recvcmd;
+ n = strlen(s);
+ LayProcess(&s, &n);
+}
+
+void
+zmodem_abort(p, d)
+struct win *p;
+struct display *d;
+{
+ struct display *olddisplay = display;
+ struct layer *oldflayer = flayer;
+ if (p)
+ {
+ if (p->w_savelayer && p->w_savelayer->l_next)
+ {
+ if (oldflayer == p->w_savelayer)
+ oldflayer = flayer->l_next;
+ flayer = p->w_savelayer;
+ ExitOverlayPage();
+ }
+ p->w_zdisplay = 0;
+ p->w_zauto = 0;
+ LRefreshAll(&p->w_layer, 0);
+ }
+ if (d)
+ {
+ display = d;
+ D_blocked = 0;
+ D_readev.condpos = D_readev.condneg = 0;
+ Activate(D_fore ? D_fore->w_norefresh : 0);
+ }
+ display = olddisplay;
+ flayer = oldflayer;
+}
+
+#endif
+
+int
+WindowChangeNumber(int old, int dest)
+{
+ struct win *p, *win_old;
+
+ if (dest < 0 || dest >= maxwin)
+ {
+ Msg(0, "Given window position is invalid.");
+ return 0;
+ }
+
+ win_old = wtab[old];
+ p = wtab[dest];
+ wtab[dest] = win_old;
+ win_old->w_number = dest;
+ wtab[old] = p;
+ if (p)
+ p->w_number = old;
+#ifdef MULTIUSER
+ /* exchange the acls for these windows. */
+ AclWinSwap(old, dest);
+#endif
+#ifdef UTMPOK
+ /* exchange the utmp-slots for these windows */
+ if ((win_old->w_slot != (slot_t) -1) && (win_old->w_slot != (slot_t) 0))
+ {
+ RemoveUtmp(win_old);
+ SetUtmp(win_old);
+ }
+ if (p && (p->w_slot != (slot_t) -1) && (p->w_slot != (slot_t) 0))
+ {
+ display = win_old->w_layer.l_cvlist ? win_old->w_layer.l_cvlist->c_display : 0;
+ RemoveUtmp(p);
+ SetUtmp(p);
+ }
+#endif
+
+ WindowChanged(win_old, 'n');
+ WindowChanged((struct win *)0, 'w');
+ WindowChanged((struct win *)0, 'W');
+ WindowChanged((struct win *)0, 0);
+ return 1;
+}
+
diff --git a/window.h b/window.h
new file mode 100644
index 0000000..bd10dcd
--- /dev/null
+++ b/window.h
@@ -0,0 +1,355 @@
+/* Copyright (c) 2010
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 2008, 2009
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Micah Cowan (micah@cowan.name)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
+ * Copyright (c) 1987 Oliver Laumann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, see
+ * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ ****************************************************************
+ * $Id$ GNU
+ */
+
+#ifndef SCREEN_WINDOW_H
+#define SCREEN_WINDOW_H
+
+/* keep this in sync with the initialisations in window.c */
+struct NewWindow
+{
+ int StartAt; /* where to start the search for the slot */
+ char *aka; /* aka string */
+ char **args; /* argv vector */
+ char *dir; /* directory for chdir */
+ char *term; /* TERM to be set instead of "screen" */
+ int aflag;
+ int dynamicaka;
+ int flowflag;
+ int lflag;
+ int histheight;
+ int monitor;
+ int wlock; /* default writelock setting */
+ int silence;
+ int wrap;
+ int Lflag; /* logging */
+ int slow; /* inter character milliseconds */
+ int gr;
+ int c1;
+ int bce;
+ int encoding;
+ char *hstatus;
+ char *charset;
+ int poll_zombie_timeout;
+};
+
+#ifdef PSEUDOS
+
+struct pseudowin
+{
+ int p_fdpat;
+ int p_pid;
+ int p_ptyfd;
+ struct event p_readev;
+ struct event p_writeev;
+ char p_cmd[MAXSTR];
+ char p_tty[MAXSTR];
+ char p_inbuf[IOSIZE]; /* buffered writing to p_ptyfd */
+ int p_inlen;
+};
+
+/* bits for fdpat: */
+#define F_PMASK 0x0003
+#define F_PSHIFT 2
+#define F_PFRONT 0x0001 /* . */
+#define F_PBACK 0x0002 /* ! */
+#define F_PBOTH (F_PFRONT | F_PBACK) /* : */
+
+#define F_UWP 0x1000 /* | */
+
+/* The screen process ...)
+ * ... wants to write to pseudo */
+#define W_WP(w) ((w)->w_pwin && ((w)->w_pwin->p_fdpat & F_PFRONT))
+
+/* ... wants to write to window: user writes to window
+ * or stdout/stderr of pseudo are duplicated to window */
+#define W_WW(w) (!((w)->w_pwin) || \
+(((w)->w_pwin->p_fdpat & F_PMASK) == F_PBACK) || \
+((((w)->w_pwin->p_fdpat >> F_PSHIFT) & F_PMASK) == F_PBOTH) || \
+((((w)->w_pwin->p_fdpat >> (F_PSHIFT * 2)) & F_PMASK) == F_PBOTH))
+
+/* ... wants to read from pseudowin */
+#define W_RP(w) ((w)->w_pwin && ((w)->w_pwin->p_fdpat & \
+((F_PFRONT << (F_PSHIFT * 2)) | (F_PFRONT << F_PSHIFT)) ))
+
+/* ... wants to read from window */
+#define W_RW(w) (!((w)->w_pwin) || ((w)->w_pwin->p_fdpat & F_PFRONT))
+
+/* user input is written to pseudo */
+#define W_UWP(w) ((w)->w_pwin && ((w)->w_pwin->p_fdpat & F_UWP))
+
+/* pseudo output has to be stuffed in window */
+#define W_PTOW(w) (\
+((w)->w_pwin->p_fdpat & F_PMASK << F_PSHIFT) == F_PBOTH << F_PSHIFT || \
+((w)->w_pwin->p_fdpat & F_PMASK << F_PSHIFT * 2) == F_PBOTH << F_PSHIFT * 2 )
+
+/* window output has to be stuffed in pseudo */
+#define W_WTOP(w) (((w)->w_pwin->p_fdpat & F_PMASK) == F_PBOTH)
+
+#endif /* PSEUDOS */
+
+/* definitions for wlocktype */
+#define WLOCK_OFF 0 /* all in w_userbits can write */
+#define WLOCK_AUTO 1 /* who selects first, can write */
+#define WLOCK_ON 2 /* user writes even if deselected */
+
+
+#ifdef COPY_PASTE
+struct paster
+{
+ char *pa_pastebuf; /* this gets pasted in the window */
+ char *pa_pasteptr; /* pointer in pastebuf */
+ int pa_pastelen; /* bytes left to paste */
+ struct layer *pa_pastelayer; /* layer to paste into */
+ struct event pa_slowev; /* slowpaste event */
+};
+#else
+struct paster;
+#endif
+
+struct win
+{
+ struct win *w_next; /* next window */
+ int w_type; /* type of window */
+ void *w_data;
+ struct layer w_layer; /* our layer */
+ struct layer *w_savelayer; /* the layer to keep */
+ int w_blocked; /* block input */
+#ifdef PSEUDOS
+ struct pseudowin *w_pwin; /* ptr to pseudo */
+#endif
+ struct display *w_pdisplay; /* display for printer relay */
+ struct display *w_lastdisp; /* where the last input was made */
+ int w_number; /* window number */
+ struct event w_readev;
+ struct event w_writeev;
+ struct event w_silenceev; /* silence event */
+ struct event w_zombieev; /* event to try to resurrect window */
+ int w_poll_zombie_timeout;
+ int w_ptyfd; /* fd of the master pty */
+ char w_inbuf[IOSIZE];
+ int w_inlen;
+ char w_outbuf[IOSIZE];
+ int w_outlen;
+ int w_aflag; /* (-a option) */
+ int w_dynamicaka; /* should we change name */
+ char *w_title; /* name of the window */
+ char *w_akachange; /* autoaka hack */
+ char w_akabuf[MAXSTR]; /* aka buffer */
+ int w_autoaka; /* autoaka hack */
+ struct win *w_group; /* window group we belong to */
+ int w_intermediate; /* char used while parsing ESC-seq */
+ int w_args[MAXARGS]; /* emulator args */
+ int w_NumArgs;
+
+#ifdef MULTIUSER
+ int w_wlock; /* WLOCK_AUTO, WLOCK_OFF, WLOCK_ON */
+ struct acluser *w_wlockuser; /* NULL when unlocked or user who writes */
+ AclBits w_userbits[ACL_BITS_PER_WIN];
+ AclBits w_lio_notify; /* whom to tell when lastio+seconds < time() */
+ AclBits w_mon_notify; /* whom to tell monitor statis */
+#endif
+
+ enum state_t w_state; /* parser state */
+ enum string_t w_StringType;
+ struct mline *w_mlines;
+ struct mchar w_rend; /* current rendition */
+#ifdef FONT
+ char w_FontL; /* character font GL */
+ char w_FontR; /* character font GR */
+# ifdef ENCODINGS
+ char w_FontE; /* character font GR locked */
+# endif
+ int w_Charset; /* charset number GL */
+ int w_CharsetR; /* charset number GR */
+ int w_charsets[4]; /* Font = charsets[Charset] */
+#endif
+ int w_ss;
+ struct cursor {
+ int on;
+ int x, y;
+ struct mchar Rend;
+#ifdef FONT
+ int Charset;
+ int CharsetR;
+ int Charsets[4];
+#endif
+ } w_saved;
+ int w_top, w_bot; /* scrollregion */
+ int w_wrap; /* autowrap */
+ int w_origin; /* origin mode */
+ int w_insert; /* window is in insert mode */
+ int w_keypad; /* keypad mode */
+ int w_cursorkeys; /* appl. cursorkeys mode */
+ int w_revvid; /* reverse video */
+ int w_curinv; /* cursor invisible */
+ int w_curvvis; /* cursor very visible */
+ int w_autolf; /* automatic linefeed */
+ char *w_hstatus; /* hardstatus line */
+ int w_gr; /* enable GR flag */
+ int w_c1; /* enable C1 flag */
+ int w_bce; /* enable backcol erase */
+#if 0
+ int w_encoding; /* for input and paste */
+#endif
+ int w_decodestate; /* state of our input decoder */
+#ifdef DW_CHARS
+ int w_mbcs; /* saved char for multibytes charset */
+#endif
+ char w_string[MAXSTR];
+ char *w_stringp;
+ char *w_tabs; /* line with tabs */
+ int w_bell; /* bell status of this window */
+ int w_flow; /* flow flags */
+ struct logfile *w_log; /* log to file */
+ int w_logsilence; /* silence in secs */
+ int w_monitor; /* monitor status */
+ int w_silencewait; /* wait for silencewait secs */
+ int w_silence; /* silence status (Lloyd Zusman) */
+ char w_vbwait;
+ char w_norefresh; /* dont redisplay when switching to that win */
+#ifdef RXVT_OSC
+ char w_xtermosc[4][MAXSTR]; /* special xterm/rxvt escapes */
+#endif
+ int w_mouse; /* mouse mode 0,9,1000 */
+#ifdef HAVE_BRAILLE
+ int w_bd_x, w_bd_y; /* Braille cursor position */
+#endif
+
+#ifdef COPY_PASTE
+ int w_slowpaste; /* do careful writes to the window */
+ int w_histheight; /* all histbases are malloced with width * histheight */
+ int w_histidx; /* 0 <= histidx < histheight; where we insert lines */
+ int w_scrollback_height; /* number of lines of output stored, to be updated with w_histidx, w_histheight */
+ struct mline *w_hlines; /* history buffer */
+ struct paster w_paster; /* paste info */
+#else
+ int w_histheight; /* always 0 */
+#endif
+ int w_pid; /* process at the other end of ptyfd */
+ int w_deadpid; /* saved w_pid of a process that closed the ptyfd to us */
+
+ char *w_cmdargs[MAXARGS]; /* command line argument vector */
+ char *w_dir; /* directory for chdir */
+ char *w_term; /* TERM to be set instead of "screen" */
+
+ int w_lflag; /* login flag */
+ slot_t w_slot; /* utmp slot */
+#if defined (UTMPOK)
+ struct utmp w_savut; /* utmp entry of this window */
+#endif
+
+ char w_tty[MAXSTR];
+
+ int w_zauto;
+#ifdef ZMODEM
+ struct display *w_zdisplay;
+#endif
+#ifdef BUILTIN_TELNET
+ struct sockaddr_storage w_telsa;
+ char w_telbuf[IOSIZE];
+ int w_telbufl;
+ char w_telmopts[256];
+ char w_telropts[256];
+ int w_telstate;
+ char w_telsubbuf[128];
+ int w_telsubidx;
+ struct event w_telconnev;
+#endif
+ struct {
+ int on; /* Is the alternate buffer currently being used? */
+ struct mline *mlines;
+ int width;
+ int height;
+#ifdef COPY_PASTE
+ int histheight;
+ struct mline *hlines;
+ int histidx;
+#else
+ int histheight; /* 0 */
+#endif
+ struct cursor cursor;
+ } w_alt;
+
+ struct event w_destroyev; /* window destroy event */
+#ifdef BSDWAIT
+ union wait w_exitstatus; /* window exit status */
+#else
+ int w_exitstatus;
+#endif
+};
+
+
+#define w_encoding w_layer.l_encoding
+#define w_width w_layer.l_width
+#define w_height w_layer.l_height
+#define w_x w_layer.l_x
+#define w_y w_layer.l_y
+
+/* definitions for w_type */
+#define W_TYPE_PTY 0
+#define W_TYPE_PLAIN 1
+#define W_TYPE_TELNET 2
+#define W_TYPE_GROUP 3
+
+
+/*
+ * Definitions for flow
+ * 000 -(-) flow off, auto would be off
+ * 001 +(-) flow on , auto would be off
+ * 010 -(+) flow off, auto would be on
+ * 011 +(+) flow on , auto would be on
+ * 100 - flow auto, currently off
+ * 111 + flow auto, currently on
+ * Application controls auto_flow via TIOCPKT, if available,
+ * else via application keypad mode.
+ */
+#define FLOW_NOW (1<<0)
+#define FLOW_AUTO (1<<1)
+#define FLOW_AUTOFLAG (1<<2)
+
+
+/*
+ * WIN gives us a reference to line y of the *whole* image
+ * where line 0 is the oldest line in our history.
+ * y must be in whole image coordinate system, not in display.
+ */
+
+#define WIN(y) ((y < fore->w_histheight) ? \
+ &fore->w_hlines[(fore->w_histidx + y) % fore->w_histheight] \
+ : &fore->w_mlines[y - fore->w_histheight])
+
+#define Layer2Window(l) ((struct win *)(l)->l_bottom->l_data)
+
+int WindowChangeNumber __P((int, int));
+
+#endif /* SCREEN_WINDOW_H */
+