diff options
author | Peter Wemm <peter@FreeBSD.org> | 1999-08-24 01:06:48 +0000 |
---|---|---|
committer | Peter Wemm <peter@FreeBSD.org> | 1999-08-24 01:06:48 +0000 |
commit | 0e3d540892016a47f6a68ec9ba2879d35ce5f7c2 (patch) | |
tree | ad214c5b2c8142ad6dc6d2ce3a9c83e6317d7f77 /contrib/ncurses/ncurses/base | |
download | src-0e3d540892016a47f6a68ec9ba2879d35ce5f7c2.tar.gz src-0e3d540892016a47f6a68ec9ba2879d35ce5f7c2.zip |
Import unmodified (but trimmed) ncurses 5.0 prerelease 990821.vendor/ncurses/5.0-19990821
This contains the full eti (panel, form, menu) extensions.
bmake glue to follow.
Obtained from: ftp://ftp.clark.net/pub/dickey/ncurses
Notes
Notes:
svn path=/vendor/ncurses/dist/; revision=50276
svn path=/vendor/ncurses/5.0-19990821/; revision=50278; tag=vendor/ncurses/5.0-19990821
Diffstat (limited to 'contrib/ncurses/ncurses/base')
85 files changed, 9906 insertions, 0 deletions
diff --git a/contrib/ncurses/ncurses/base/MKkeyname.awk b/contrib/ncurses/ncurses/base/MKkeyname.awk new file mode 100644 index 000000000000..aaeb4743cdfe --- /dev/null +++ b/contrib/ncurses/ncurses/base/MKkeyname.awk @@ -0,0 +1,74 @@ +# $Id: MKkeyname.awk,v 1.17 1999/02/18 11:18:06 tom Exp $ +############################################################################## +# Copyright (c) 1999 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## +BEGIN { + print "/* generated by MKkeyname.awk */" + print "" + print "#include <ncurses_cfg.h>" + print "#include <stdlib.h>" + print "#include <string.h>" + print "#include <curses.h>" + print "#include <tic.h>" + print "" + print "const struct kn _nc_key_names[] = {" +} + +/^[^#]/ { + printf "\t{ \"%s\", %s },\n", $1, $1; + } + +END { + printf "\t{ 0, 0 }};\n" + print "" + print "NCURSES_CONST char *keyname(int c)" + print "{" + print "int i;" + print "static char name[20];" + print "char *p;" + print "" + print "\tfor (i = 0; _nc_key_names[i].name != 0; i++)" + print "\t\tif (_nc_key_names[i].code == c)" + print "\t\t\treturn (NCURSES_CONST char *)_nc_key_names[i].name;" + print "\tif (c >= 256) return \"UNKNOWN KEY\";" + print "\tp = name;" + print "\tif (c >= 128) {" + print "\t\tstrcpy(p, \"M-\");" + print "\t\tp += 2;" + print "\t\tc -= 128;" + print "\t}" + print "\tif (c < 0)" + print "\t\tsprintf(p, \"%d\", c);" + print "\telse if (c < 32)" + print "\t\tsprintf(p, \"^%c\", c + '@');" + print "\telse if (c == 127)" + print "\t\tstrcpy(p, \"^?\");" + print "\telse" + print "\t\tsprintf(p, \"%c\", c);" + print "\treturn (NCURSES_CONST char *)name;" + print "}" +} diff --git a/contrib/ncurses/ncurses/base/MKlib_gen.sh b/contrib/ncurses/ncurses/base/MKlib_gen.sh new file mode 100755 index 000000000000..0a29c6085f62 --- /dev/null +++ b/contrib/ncurses/ncurses/base/MKlib_gen.sh @@ -0,0 +1,254 @@ +#!/bin/sh +# +# MKlib_gen.sh -- generate sources from curses.h macro definitions +# +# ($Id: MKlib_gen.sh,v 1.11 1998/01/17 14:16:52 Juan.Jose.Garcia.Ripoll Exp $) +# +# The XSI Curses standard requires all curses entry points to exist as +# functions, even though many definitions would normally be shadowed +# by macros. Rather than hand-hack all that code, we actually +# generate functions from the macros. +# +# This script accepts a file of prototypes on standard input. It discards +# any that don't have a `generated' comment attached. It then parses each +# prototype (relying on the fact that none of the macros take function +# pointer or array arguments) and generates C source from it. +# +# Here is what the pipeline stages are doing: +# +# 1. sed: extract prototypes of generated functions +# 2. sed: decorate prototypes with generated arguments a1. a2,...z +# 3. awk: generate the calls with args matching the formals +# 4. sed: prefix function names in prototypes so the preprocessor won't expand +# them. +# 5. cpp: macro-expand the file so the macro calls turn into C calls +# 6. awk: strip the expansion junk off the front and add the new header +# 7. sed: squeeze spaces, strip off gen_ prefix, create needed #undef +# + +preprocessor="$1 -I../include" +AWK="$2" +ED1=sed1$$.sed +ED2=sed2$$.sed +ED3=sed3$$.sed +AW1=awk1$$.awk +TMP=gen$$.c +trap "rm -f $ED1 $ED2 $ED3 $AW1 $TMP" 0 1 2 5 15 + +(cat <<EOF +#include <ncurses_cfg.h> +#include <curses.h> + +DECLARATIONS + +EOF +cat >$ED1 <<EOF1 +/^extern.*generated/{ + h + s/^.*generated:\([^ *]*\).*/P_#if_USE_\1_SUPPORT/p + g + s/^extern \([^;]*\);.*/\1/p + g + s/^.*generated:\([^ *]*\).*/P_#endif/p +} +EOF1 + +cat >$ED2 <<EOF2 +/^P_/b nc +/(void)/b nc + s/,/ a1% / + s/,/ a2% / + s/,/ a3% / + s/,/ a4% / + s/,/ a5% / + s/,/ a6% / + s/,/ a7% / + s/,/ a8% / + s/,/ a9% / + s/,/ a10% / + s/,/ a11% / + s/,/ a12% / + s/,/ a13% / + s/,/ a14% / + s/,/ a15% / + s/*/ * /g + s/%/ , /g + s/)/ z)/ +:nc + /(/s// ( / + s/)/ )/ +EOF2 + +cat >$ED3 <<EOF3 +/^P_/{ + s/^P_#if_/#if / + s/^P_// + b done +} + s/ */ /g + s/ */ /g + s/ ,/,/g + s/ )/)/g + s/ gen_/ / + s/^M_/#undef / + /^%%/s// / +:done +EOF3 + +cat >$AW1 <<\EOF1 +BEGIN { + skip=0; + } + /^P_#if/ { + print "\n" + print $0 + skip=0; + } + /^P_#endif/ { + print $0 + skip=1; + } + $0 !~ /^P_/ { + if (skip) + print "\n" + skip=1; + + print "M_" $2 + print $0; + print "{"; + argcount = 1; + if (NF == 5 && $4 == "void") + argcount = 0; + if (argcount != 0) { + for (i = 1; i <= NF; i++) + if ($i == ",") + argcount++; + } + + # suppress trace-code for functions that we cannot do properly here, + # since they return data. + dotrace = 1; + if ($2 == "innstr") + dotrace = 0; + + call = "%%T((T_CALLED(\"" + args = "" + comma = "" + num = 0; + pointer = 0; + argtype = "" + for (i = 1; i <= NF; i++) { + ch = $i; + if ( ch == "*" ) + pointer = 1; + else if ( ch == "va_list" ) + pointer = 1; + else if ( ch == "char" ) + argtype = "char"; + else if ( ch == "int" ) + argtype = "int"; + else if ( ch == "short" ) + argtype = "short"; + else if ( ch == "chtype" ) + argtype = "chtype"; + else if ( ch == "attr_t" || ch == "NCURSES_ATTR_T" ) + argtype = "attr"; + + if ( ch == "," || ch == ")" ) { + if (pointer) { + if ( argtype == "char" ) { + call = call "%s" + comma = comma "_nc_visbuf2(" num "," + pointer = 0; + } else + call = call "%p" + } else if (argcount != 0) { + if ( argtype == "int" || argtype == "short" ) { + call = call "%d" + argtype = "" + } else if ( argtype != "" ) { + call = call "%s" + comma = comma "_trace" argtype "2(" num "," + } else { + call = call "%#lx" + comma = comma "(long)" + } + } + if (ch == ",") + args = args comma "a" ++num; + else if (argcount != 0) + args = args comma "z" + call = call ch + if (pointer == 0 && argcount != 0 && argtype != "" ) + args = args ")" + if (args != "") + comma = ", " + pointer = 0; + argtype = "" + } + if ( i == 2 || ch == "(" ) + call = call ch + } + call = call "\")" + if (args != "") + call = call ", " args + call = call ")); " + + if (dotrace) + printf "%s", call + + if (match($0, "^void")) + call = "" + else if (dotrace) + call = "returnCode( "; + else + call = "%%return "; + + call = call $2 "("; + for (i = 1; i < argcount; i++) + call = call "a" i ", "; + if (argcount != 0) + call = call "z"; + if (!match($0, "^void")) + call = call ") "; + if (dotrace) + call = call ")"; + print call ";" + + if (match($0, "^void")) + print "%%returnVoid;" + print "}"; +} +EOF1 + +sed -n -f $ED1 | sed -f $ED2 \ +| $AWK -f $AW1 ) \ +| sed \ + -e '/^\([a-z_][a-z_]*\) /s//\1 gen_/' >$TMP + $preprocessor $TMP 2>/dev/null \ +| $AWK ' +BEGIN { + print "/*" + print " * DO NOT EDIT THIS FILE BY HAND!" + print " * It is generated by MKlib_gen.sh." + print " *" + print " * This is a file of trivial functions generated from macro" + print " * definitions in curses.h to satisfy the XSI Curses requirement" + print " * that every macro also exist as a callable function." + print " *" + print " * It will never be linked unless you call one of the entry" + print " * points with its normal macro definition disabled. In that" + print " * case, if you have no shared libraries, it will indirectly" + print " * pull most of the rest of the library into your link image." + print " */" + print "#include <curses.priv.h>" + print "" + } +/^DECLARATIONS/ {start = 1; next;} + {if (start) print $0;} +' \ +| sed -f $ED3 \ +| sed \ + -e 's/^.*T_CALLED.*returnCode( \([a-z].*) \));/ return \1;/' \ + -e 's/^.*T_CALLED.*returnCode( \((wmove.*) \));/ return \1;/' + diff --git a/contrib/ncurses/ncurses/base/MKunctrl.awk b/contrib/ncurses/ncurses/base/MKunctrl.awk new file mode 100644 index 000000000000..0f4419242a99 --- /dev/null +++ b/contrib/ncurses/ncurses/base/MKunctrl.awk @@ -0,0 +1,67 @@ +# $Id: MKunctrl.awk,v 1.6 1998/06/06 18:18:07 tom Exp $ +############################################################################## +# Copyright (c) 1998 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## +# +# Author: Thomas E. Dickey <dickey@clark.net> 1997 +# + +BEGIN { + print "/* generated by MKunctrl.awk */" + print "" + print "#include <curses.priv.h>" + print "" + print "#undef unctrl" + print "" + } +END { + print "NCURSES_CONST char *unctrl(register chtype ch)" + print "{" + printf "static const char* const table[] = {" + for ( ch = 0; ch < 256; ch++ ) { + gap = "," + if ((ch % 8) == 0) + printf "\n " + if (ch < 32) { + printf "\"^\\%03o\"", ch + 64 + } else if (ch == 127) { + printf "\"^?\"" + } else { + printf "\"\\%03o\"", ch + gap = gap " " + } + if (ch == 255) + gap = "\n" + else if (((ch + 1) % 8) != 0) + gap = gap " " + printf "%s", gap + } + print "};" + print "" + print "\treturn (NCURSES_CONST char *)table[TextOf(ch)];" + print "}" + } diff --git a/contrib/ncurses/ncurses/base/README b/contrib/ncurses/ncurses/base/README new file mode 100644 index 000000000000..ffa16963e9e3 --- /dev/null +++ b/contrib/ncurses/ncurses/base/README @@ -0,0 +1,7 @@ +-- $Id: README,v 1.1 1998/11/14 22:58:22 tom Exp $ + +The functions in this directory are the generic (not device-specific) modules +of ncurses. + +As a rule, these modules should not depend directly on term.h references and +associated terminfo function and variables. diff --git a/contrib/ncurses/ncurses/base/define_key.c b/contrib/ncurses/ncurses/base/define_key.c new file mode 100644 index 000000000000..52dc6927bd55 --- /dev/null +++ b/contrib/ncurses/ncurses/base/define_key.c @@ -0,0 +1,59 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: define_key.c,v 1.4 1999/02/21 13:03:55 tom Exp $") + +int +define_key(char *str, int keycode) +{ + int code = ERR; + + T((T_CALLED("define_key(%s,%d)"), _nc_visbuf(str), keycode)); + if (keycode > 0) { + if (str != 0) { + define_key(str, 0); + } else if (has_key(keycode)) { + while (_nc_remove_key(&(SP->_keytry), keycode)) + code = OK; + } + if (str != 0) { + (void) _nc_add_to_try(&(SP->_keytry), str, keycode); + code = OK; + } + } else { + while (_nc_remove_string(&(SP->_keytry), str)) + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/keybound.c b/contrib/ncurses/ncurses/base/keybound.c new file mode 100644 index 000000000000..c9aa02292118 --- /dev/null +++ b/contrib/ncurses/ncurses/base/keybound.c @@ -0,0 +1,45 @@ +/**************************************************************************** + * Copyright (c) 1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1999 * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: keybound.c,v 1.1 1999/02/19 11:55:56 tom Exp $") + +/* + * Returns the count'th string definition which is associated with the + * given keycode. The result is malloc'd, must be freed by the caller. + */ + +char *keybound(int code, int count) +{ + return _nc_expand_try(SP->_key_ok, code, &count, 0); +} diff --git a/contrib/ncurses/ncurses/base/keyok.c b/contrib/ncurses/ncurses/base/keyok.c new file mode 100644 index 000000000000..a1385769781f --- /dev/null +++ b/contrib/ncurses/ncurses/base/keyok.c @@ -0,0 +1,72 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: keyok.c,v 1.3 1999/02/19 11:29:48 tom Exp $") + +/* + * Enable (or disable) ncurses' interpretation of a keycode by adding (or + * removing) the corresponding 'tries' entry. + * + * Do this by storing a second tree of tries, which records the disabled keys. + * The simplest way to copy is to make a function that returns the string (with + * nulls set to 0200), then use that to reinsert the string into the + * corresponding tree. + */ + +int keyok(int c, bool flag) +{ + int code = ERR; + int count = 0; + char *s; + + T((T_CALLED("keyok(%d,%d)"), c, flag)); + if (flag) { + while ((s = _nc_expand_try(SP->_key_ok, c, &count, 0)) != 0 + && _nc_remove_key(&(SP->_key_ok), c)) { + _nc_add_to_try(&(SP->_keytry), s, c); + free(s); + code = OK; + count = 0; + } + } else { + while ((s = _nc_expand_try(SP->_keytry, c, &count, 0)) != 0 + && _nc_remove_key(&(SP->_keytry), c)) { + _nc_add_to_try(&(SP->_key_ok), s, c); + free(s); + code = OK; + count = 0; + } + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_addch.c b/contrib/ncurses/ncurses/base/lib_addch.c new file mode 100644 index 000000000000..101d75ef29a9 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_addch.c @@ -0,0 +1,293 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_addch.c +** +** The routine waddch(). +** +*/ + +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("$Id: lib_addch.c,v 1.42 1999/07/24 20:01:05 tom Exp $") + +/* + * Ugly microtweaking alert. Everything from here to end of module is + * likely to be speed-critical -- profiling data sure says it is! + * Most of the important screen-painting functions are shells around + * waddch(). So we make every effort to reduce function-call overhead + * by inlining stuff, even at the cost of making wrapped copies for + * export. Also we supply some internal versions that don't call the + * window sync hook, for use by string-put functions. + */ + +/* Return bit mask for clearing color pair number if given ch has color */ +#define COLOR_MASK(ch) (~(chtype)((ch)&A_COLOR?A_COLOR:0)) + +static inline chtype render_char(WINDOW *win, chtype ch) +/* compute a rendition of the given char correct for the current context */ +{ + chtype a = win->_attrs; + + if (ch == ' ') + { + /* color in attrs has precedence over bkgd */ + ch = a | (win->_bkgd & COLOR_MASK(a)); + } + else + { + /* color in attrs has precedence over bkgd */ + a |= (win->_bkgd & A_ATTRIBUTES) & COLOR_MASK(a); + /* color in ch has precedence */ + ch |= (a & COLOR_MASK(ch)); + } + + TR(TRACE_VIRTPUT, ("bkg = %lx, attrs = %lx -> ch = %lx", win->_bkgd, + win->_attrs, ch)); + + return(ch); +} + +chtype _nc_background(WINDOW *win) +/* make render_char() visible while still allowing us to inline it below */ +{ + return (win->_bkgd); +} + +chtype _nc_render(WINDOW *win, chtype ch) +/* make render_char() visible while still allowing us to inline it below */ +{ + return render_char(win, ch); +} + +/* check if position is legal; if not, return error */ +#ifndef NDEBUG /* treat this like an assertion */ +#define CHECK_POSITION(win, x, y) \ + if (y > win->_maxy \ + || x > win->_maxx \ + || y < 0 \ + || x < 0) { \ + TR(TRACE_VIRTPUT, ("Alert! Win=%p _curx = %d, _cury = %d " \ + "(_maxx = %d, _maxy = %d)", win, x, y, \ + win->_maxx, win->_maxy)); \ + return(ERR); \ + } +#else +#define CHECK_POSITION(win, x, y) /* nothing */ +#endif + +static inline +int waddch_literal(WINDOW *win, chtype ch) +{ + int x; + struct ldat *line; + + x = win->_curx; + + CHECK_POSITION(win, x, win->_cury); + + /* + * If we're trying to add a character at the lower-right corner more + * than once, fail. (Moving the cursor will clear the flag). + */ + if (win->_flags & _WRAPPED) { + if (x >= win->_maxx) + return (ERR); + win->_flags &= ~_WRAPPED; + } + + ch = render_char(win, ch); + TR(TRACE_VIRTPUT, ("win attr = %s", _traceattr(win->_attrs))); + + line = win->_line+win->_cury; + + CHANGED_CELL(line,x); + + line->text[x++] = ch; + + TR(TRACE_VIRTPUT, ("(%d, %d) = %s", win->_cury, x, _tracechtype(ch))); + if (x > win->_maxx) { + /* + * The _WRAPPED flag is useful only for telling an application + * that we've just wrapped the cursor. We don't do anything + * with this flag except set it when wrapping, and clear it + * whenever we move the cursor. If we try to wrap at the + * lower-right corner of a window, we cannot move the cursor + * (since that wouldn't be legal). So we return an error + * (which is what SVr4 does). Unlike SVr4, we can successfully + * add a character to the lower-right corner. + */ + win->_flags |= _WRAPPED; + if (++win->_cury > win->_regbottom) { + win->_cury = win->_regbottom; + win->_curx = win->_maxx; + if (!win->_scroll) + return (ERR); + scroll(win); + } + win->_curx = 0; + return (OK); + } + win->_curx = x; + return OK; +} + +static inline +int waddch_nosync(WINDOW *win, const chtype ch) +/* the workhorse function -- add a character to the given window */ +{ + int x, y; + int t = 0; + const char *s = 0; + + if ((ch & A_ALTCHARSET) + || ((t = TextOf(ch)) > 127) + || ((s = unctrl(t))[1] == 0)) + return waddch_literal(win, ch); + + x = win->_curx; + y = win->_cury; + + switch (t) { + case '\t': + x += (TABSIZE-(x%TABSIZE)); + + /* + * Space-fill the tab on the bottom line so that we'll get the + * "correct" cursor position. + */ + if ((! win->_scroll && (y == win->_regbottom)) + || (x <= win->_maxx)) { + chtype blank = (' ' | AttrOf(ch)); + while (win->_curx < x) { + if (waddch_literal(win, blank) == ERR) + return(ERR); + } + break; + } else { + wclrtoeol(win); + win->_flags |= _WRAPPED; + if (++y > win->_regbottom) { + x = win->_maxx; + y--; + if (win->_scroll) { + scroll(win); + x = 0; + } + } else { + x = 0; + } + } + break; + case '\n': + wclrtoeol(win); + if (++y > win->_regbottom) { + y--; + if (win->_scroll) + scroll(win); + else + return (ERR); + } + /* FALLTHRU */ + case '\r': + x = 0; + win->_flags &= ~_WRAPPED; + break; + case '\b': + if (x == 0) + return (OK); + x--; + win->_flags &= ~_WRAPPED; + break; + default: + while (*s) + if (waddch_literal(win, (*s++)|AttrOf(ch)) == ERR) + return ERR; + return(OK); + } + + win->_curx = x; + win->_cury = y; + + return(OK); +} + +int _nc_waddch_nosync(WINDOW *win, const chtype c) +/* export copy of waddch_nosync() so the string-put functions can use it */ +{ + return(waddch_nosync(win, c)); +} + +/* + * The versions below call _nc_synhook(). We wanted to avoid this in the + * version exported for string puts; they'll call _nc_synchook once at end + * of run. + */ + +/* These are actual entry points */ + +int waddch(WINDOW *win, const chtype ch) +{ + int code = ERR; + + TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_CALLED("waddch(%p, %s)"), win, _tracechtype(ch))); + + if (win && (waddch_nosync(win, ch) != ERR)) + { + _nc_synchook(win); + code = OK; + } + + TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_RETURN("%d"), code)); + return(code); +} + +int wechochar(WINDOW *win, const chtype ch) +{ + int code = ERR; + + TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_CALLED("wechochar(%p, %s)"), win, _tracechtype(ch))); + + if (win && (waddch_nosync(win, ch) != ERR)) + { + bool save_immed = win->_immed; + win->_immed = TRUE; + _nc_synchook(win); + win->_immed = save_immed; + code = OK; + } + TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_RETURN("%d"), code)); + return(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_addstr.c b/contrib/ncurses/ncurses/base/lib_addstr.c new file mode 100644 index 000000000000..9ac55e42aba7 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_addstr.c @@ -0,0 +1,103 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_addstr.c +* +** The routines waddnstr(), waddchnstr(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_addstr.c,v 1.16 1998/06/28 00:38:29 tom Exp $") + +int +waddnstr(WINDOW *win, const char *const astr, int n) +{ +unsigned const char *str = (unsigned const char *)astr; +int code = ERR; + + T((T_CALLED("waddnstr(%p,%s,%d)"), win, _nc_visbuf(astr), n)); + + if (win && (str != 0)) { + T(("... current %s", _traceattr(win->_attrs))); + TR(TRACE_VIRTPUT, ("str is not null")); + code = OK; + if (n < 0) + n = (int)strlen(astr); + + while((n-- > 0) && (*str != '\0')) { + TR(TRACE_VIRTPUT, ("*str = %#x", *str)); + if (_nc_waddch_nosync(win, (chtype)*str++) == ERR) { + code = ERR; + break; + } + } + _nc_synchook(win); + } + TR(TRACE_VIRTPUT, ("waddnstr returns %d", code)); + returnCode(code); +} + +int +waddchnstr(WINDOW *win, const chtype *const astr, int n) +{ +short y = win->_cury; +short x = win->_curx; +int code = OK; +struct ldat *line; + + T((T_CALLED("waddchnstr(%p,%p,%d)"), win, astr, n)); + + if (!win) + returnCode(ERR); + + if (n < 0) { + const chtype *str; + n = 0; + for (str=(const chtype *)astr; *str!=0; str++) + n++; + } + if (n > win->_maxx - x + 1) + n = win->_maxx - x + 1; + if (n == 0) + returnCode(code); + + line = &(win->_line[y]); + memcpy(line->text+x, astr, n*sizeof(*astr)); + CHANGED_RANGE(line, x, x+n-1); + + _nc_synchook(win); + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_beep.c b/contrib/ncurses/ncurses/base/lib_beep.c new file mode 100644 index 000000000000..9b89496608da --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_beep.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * beep.c + * + * The routine beep(). + * + */ + +#include <curses.priv.h> +#include <term.h> /* beep, flash */ + +MODULE_ID("$Id: lib_beep.c,v 1.6 1998/06/29 19:34:16 Alexander.V.Lukyanov Exp $") + +/* + * beep() + * + * Sound the current terminal's audible bell if it has one. If not, + * flash the screen if possible. + * + */ + +int beep(void) +{ + int res = ERR; + + T((T_CALLED("beep()"))); + + /* FIXME: should make sure that we are not in altchar mode */ + if (bell) { + TPUTS_TRACE("bell"); + res = putp(bell); + fflush(SP->_ofp); + } else if (flash_screen) { + TPUTS_TRACE("flash_screen"); + res = putp(flash_screen); + fflush(SP->_ofp); + } + + returnCode(res); +} diff --git a/contrib/ncurses/ncurses/base/lib_bkgd.c b/contrib/ncurses/ncurses/base/lib_bkgd.c new file mode 100644 index 000000000000..410ee0580433 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_bkgd.c @@ -0,0 +1,86 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_bkgd.c,v 1.12 1998/02/11 12:13:54 tom Exp $") + +void wbkgdset(WINDOW *win, chtype ch) +{ + T((T_CALLED("wbkgdset(%p,%s)"), win, _tracechtype(ch))); + + if (win) { + chtype off = AttrOf(win->_bkgd); + chtype on = AttrOf(ch); + + toggle_attr_off(win->_attrs,off); + toggle_attr_on (win->_attrs,on); + + if (TextOf(ch)==0) + ch |= BLANK; + win->_bkgd = ch; + } + returnVoid; +} + +int wbkgd(WINDOW *win, const chtype ch) +{ + int code = ERR; + int x, y; + chtype new_bkgd = ch; + + T((T_CALLED("wbkgd(%p,%s)"), win, _tracechtype(new_bkgd))); + + if (win) { + chtype old_bkgd = getbkgd(win); + + wbkgdset(win, new_bkgd); + wattrset(win, AttrOf(win->_bkgd)); + + for (y = 0; y <= win->_maxy; y++) { + for (x = 0; x <= win->_maxx; x++) { + if (win->_line[y].text[x] == old_bkgd) + win->_line[y].text[x] = win->_bkgd; + else + win->_line[y].text[x] = + _nc_render(win,(A_ALTCHARSET & + AttrOf(win->_line[y].text[x])) + | TextOf(win->_line[y].text[x])); + } + } + touchwin(win); + _nc_synchook(win); + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_box.c b/contrib/ncurses/ncurses/base/lib_box.c new file mode 100644 index 000000000000..bcd96416f954 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_box.c @@ -0,0 +1,110 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_box.c +** +** The routine wborder(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_box.c,v 1.10 1998/02/11 12:13:56 tom Exp $") + +int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, + chtype bs, chtype tl, chtype tr, chtype bl, chtype br) +{ +short i; +short endx, endy; + + T((T_CALLED("wborder(%p,%s,%s,%s,%s,%s,%s,%s,%s)"), + win, + _tracechtype2(1,ls), + _tracechtype2(2,rs), + _tracechtype2(3,ts), + _tracechtype2(4,bs), + _tracechtype2(5,tl), + _tracechtype2(6,tr), + _tracechtype2(7,bl), + _tracechtype2(8,br))); + + if (!win) + returnCode(ERR); + + if (ls == 0) ls = ACS_VLINE; + if (rs == 0) rs = ACS_VLINE; + if (ts == 0) ts = ACS_HLINE; + if (bs == 0) bs = ACS_HLINE; + if (tl == 0) tl = ACS_ULCORNER; + if (tr == 0) tr = ACS_URCORNER; + if (bl == 0) bl = ACS_LLCORNER; + if (br == 0) br = ACS_LRCORNER; + + ls = _nc_render(win, ls); + rs = _nc_render(win, rs); + ts = _nc_render(win, ts); + bs = _nc_render(win, bs); + tl = _nc_render(win, tl); + tr = _nc_render(win, tr); + bl = _nc_render(win, bl); + br = _nc_render(win, br); + + T(("using %#lx, %#lx, %#lx, %#lx, %#lx, %#lx, %#lx, %#lx", ls, rs, ts, bs, tl, tr, bl, br)); + + endx = win->_maxx; + endy = win->_maxy; + + for (i = 0; i <= endx; i++) { + win->_line[0].text[i] = ts; + win->_line[endy].text[i] = bs; + } + win->_line[endy].firstchar = win->_line[0].firstchar = 0; + win->_line[endy].lastchar = win->_line[0].lastchar = endx; + + for (i = 0; i <= endy; i++) { + win->_line[i].text[0] = ls; + win->_line[i].text[endx] = rs; + win->_line[i].firstchar = 0; + win->_line[i].lastchar = endx; + } + win->_line[0].text[0] = tl; + win->_line[0].text[endx] = tr; + win->_line[endy].text[0] = bl; + win->_line[endy].text[endx] = br; + + _nc_synchook(win); + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_chgat.c b/contrib/ncurses/ncurses/base/lib_chgat.c new file mode 100644 index 000000000000..7690ae4a2af3 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_chgat.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_chgat.c +** +** The routine wchgat(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_chgat.c,v 1.2 1998/02/11 12:14:00 tom Exp $") + +int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts GCC_UNUSED) +{ + int i; + + T((T_CALLED("wchgat(%p,%d,%s,%d)"), win, n, _traceattr(attr), color)); + + if (win) { + toggle_attr_on(attr,COLOR_PAIR(color)); + + for (i = win->_curx; i <= win->_maxx && (n == -1 || (n-- > 0)); i++) + win->_line[win->_cury].text[i] + = TextOf(win->_line[win->_cury].text[i]) | attr; + + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_clear.c b/contrib/ncurses/ncurses/base/lib_clear.c new file mode 100644 index 000000000000..9c07cf0890e4 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_clear.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_clear.c +** +** The routine wclear(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_clear.c,v 1.5 1998/02/11 12:13:53 tom Exp $") + +int wclear(WINDOW *win) +{ +int code = ERR; + + T((T_CALLED("wclear(%p)"), win)); + + if ((code = werase(win))!=ERR) + win->_clear = TRUE; + + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_clearok.c b/contrib/ncurses/ncurses/base/lib_clearok.c new file mode 100644 index 000000000000..cc904b1d7dc7 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_clearok.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_clearok.c +** +** The routine clearok. +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_clearok.c,v 1.2 1998/02/11 12:14:00 tom Exp $") + +int clearok(WINDOW *win, bool flag) +{ + T((T_CALLED("clearok(%p,%d)"), win, flag)); + + if (win) { + win->_clear = flag; + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_clrbot.c b/contrib/ncurses/ncurses/base/lib_clrbot.c new file mode 100644 index 000000000000..cec34161acef --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_clrbot.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_clrbot.c +** +** The routine wclrtobot(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_clrbot.c,v 1.14 1998/06/28 00:36:26 tom Exp $") + +int wclrtobot(WINDOW *win) +{ +int code = ERR; + + T((T_CALLED("wclrtobot(%p)"), win)); + + if (win) { + short y; + short startx = win->_curx; + chtype blank = _nc_background(win); + + T(("clearing from y = %d to y = %d with maxx = %d", win->_cury, win->_maxy, win->_maxx)); + + for (y = win->_cury; y <= win->_maxy; y++) { + struct ldat *line = &(win->_line[y]); + chtype *ptr = &(line->text[startx]); + chtype *end = &(line->text[win->_maxx]); + + CHANGED_TO_EOL(line, startx, win->_maxx); + + while (ptr <= end) + *ptr++ = blank; + + startx = 0; + } + _nc_synchook(win); + code = OK; + } + returnCode(code); +} + diff --git a/contrib/ncurses/ncurses/base/lib_clreol.c b/contrib/ncurses/ncurses/base/lib_clreol.c new file mode 100644 index 000000000000..0c7522278e38 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_clreol.c @@ -0,0 +1,91 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_clreol.c +** +** The routine wclrtoeol(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_clreol.c,v 1.15 1998/06/28 00:32:20 tom Exp $") + +int wclrtoeol(WINDOW *win) +{ +int code = ERR; + + T((T_CALLED("wclrtoeol(%p)"), win)); + + if (win) { + chtype blank; + chtype *ptr, *end; + struct ldat *line; + short y = win->_cury; + short x = win->_curx; + + /* + * If we have just wrapped the cursor, the clear applies to the + * new line, unless we are at the lower right corner. + */ + if (win->_flags & _WRAPPED + && y < win->_maxy) { + win->_flags &= ~_WRAPPED; + } + + /* + * There's no point in clearing if we're not on a legal + * position, either. + */ + if (win->_flags & _WRAPPED + || y > win->_maxy + || x > win->_maxx) + returnCode(ERR); + + blank = _nc_background(win); + line = &win->_line[y]; + CHANGED_TO_EOL(line, x, win->_maxx); + + ptr = &(line->text[x]); + end = &(line->text[win->_maxx]); + + while (ptr <= end) + *ptr++ = blank; + + _nc_synchook(win); + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_color.c b/contrib/ncurses/ncurses/base/lib_color.c new file mode 100644 index 000000000000..cdc943adc6ee --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_color.c @@ -0,0 +1,429 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* lib_color.c + * + * Handles color emulation of SYS V curses + * + */ + +#include <curses.priv.h> + +#include <term.h> + +MODULE_ID("$Id: lib_color.c,v 1.35 1999/03/15 01:45:14 Alexander.V.Lukyanov Exp $") + +/* + * These should be screen structure members. They need to be globals for + * hystorical reasons. So we assign them in start_color() and also in + * set_term()'s screen-switching logic. + */ +int COLOR_PAIRS; +int COLORS; + +/* + * Given a RGB range of 0..1000, we'll normally set the individual values + * to about 2/3 of the maximum, leaving full-range for bold/bright colors. + */ +#define RGB_ON 680 +#define RGB_OFF 0 + +static const color_t cga_palette[] = +{ + /* R G B */ + {RGB_OFF, RGB_OFF, RGB_OFF}, /* COLOR_BLACK */ + {RGB_ON, RGB_OFF, RGB_OFF}, /* COLOR_RED */ + {RGB_OFF, RGB_ON, RGB_OFF}, /* COLOR_GREEN */ + {RGB_ON, RGB_ON, RGB_OFF}, /* COLOR_YELLOW */ + {RGB_OFF, RGB_OFF, RGB_ON}, /* COLOR_BLUE */ + {RGB_ON, RGB_OFF, RGB_ON}, /* COLOR_MAGENTA */ + {RGB_OFF, RGB_ON, RGB_ON}, /* COLOR_CYAN */ + {RGB_ON, RGB_ON, RGB_ON}, /* COLOR_WHITE */ +}; +static const color_t hls_palette[] = +{ + /* H L S */ + {0, 0, 0}, /* COLOR_BLACK */ + {120, 50, 100}, /* COLOR_RED */ + {240, 50, 100}, /* COLOR_GREEN */ + {180, 50, 100}, /* COLOR_YELLOW */ + {330, 50, 100}, /* COLOR_BLUE */ + {60, 50, 100}, /* COLOR_MAGENTA */ + {300, 50, 100}, /* COLOR_CYAN */ + {0, 50, 100}, /* COLOR_WHITE */ +}; + +/* + * SVr4 curses is known to interchange color codes (1,4) and (3,6), possibly + * to maintain compatibility with a pre-ANSI scheme. The same scheme is + * also used in the FreeBSD syscons. + */ +static int toggled_colors(int c) +{ + if (c < 16) { + static const int table[] = + { 0, 4, 2, 6, 1, 5, 3, 7, + 8, 12, 10, 14, 9, 13, 11, 15}; + c = table[c]; + } + return c; +} + +static void set_background_color(int bg, int (*outc)(int)) +{ + if (set_a_background) + { + TPUTS_TRACE("set_a_background"); + tputs(tparm(set_a_background, bg), 1, outc); + } + else + { + TPUTS_TRACE("set_background"); + tputs(tparm(set_background, toggled_colors(bg)), 1, outc); + } +} + +static void set_foreground_color(int fg, int (*outc)(int)) +{ + if (set_a_foreground) + { + TPUTS_TRACE("set_a_foreground"); + tputs(tparm(set_a_foreground, fg), 1, outc); + } + else + { + TPUTS_TRACE("set_foreground"); + tputs(tparm(set_foreground, toggled_colors(fg)), 1, outc); + } +} + +static bool set_original_colors(void) +{ + if (orig_pair != 0) { + TPUTS_TRACE("orig_pair"); + putp(orig_pair); + return TRUE; + } + else if (orig_colors != NULL) + { + TPUTS_TRACE("orig_colors"); + putp(orig_colors); + return TRUE; + } + return FALSE; +} + +int start_color(void) +{ + T((T_CALLED("start_color()"))); + + if (set_original_colors() != TRUE) + { + set_foreground_color(COLOR_WHITE, _nc_outch); + set_background_color(COLOR_BLACK, _nc_outch); + } + + if (max_pairs != -1) + COLOR_PAIRS = SP->_pair_count = max_pairs; + else + returnCode(ERR); + if ((SP->_color_pairs = typeCalloc(unsigned short, max_pairs)) == 0) + returnCode(ERR); + SP->_color_pairs[0] = PAIR_OF(COLOR_WHITE, COLOR_BLACK); + if (max_colors != -1) + COLORS = SP->_color_count = max_colors; + else + returnCode(ERR); + SP->_coloron = 1; + + if ((SP->_color_table = typeMalloc(color_t, COLORS)) == 0) + returnCode(ERR); + if (hue_lightness_saturation) + memcpy(SP->_color_table, hls_palette, sizeof(color_t) * COLORS); + else + memcpy(SP->_color_table, cga_palette, sizeof(color_t) * COLORS); + + T(("started color: COLORS = %d, COLOR_PAIRS = %d", COLORS, COLOR_PAIRS)); + + returnCode(OK); +} + +/* This function was originally written by Daniel Weaver <danw@znyx.com> */ +static void rgb2hls(short r, short g, short b, short *h, short *l, short *s) +/* convert RGB to HLS system */ +{ + short min, max, t; + + if ((min = g < r ? g : r) > b) min = b; + if ((max = g > r ? g : r) < b) max = b; + + /* calculate lightness */ + *l = (min + max) / 20; + + if (min == max) /* black, white and all shades of gray */ + { + *h = 0; + *s = 0; + return; + } + + /* calculate saturation */ + if (*l < 50) + *s = ((max - min) * 100) / (max + min); + else *s = ((max - min) * 100) / (2000 - max - min); + + /* calculate hue */ + if (r == max) + t = 120 + ((g - b) * 60) / (max - min); + else + if (g == max) + t = 240 + ((b - r) * 60) / (max - min); + else + t = 360 + ((r - g) * 60) / (max - min); + + *h = t % 360; +} + +/* + * Extension (1997/1/18) - Allow negative f/b values to set default color + * values. + */ +int init_pair(short pair, short f, short b) +{ + unsigned result; + + T((T_CALLED("init_pair(%d,%d,%d)"), pair, f, b)); + + if ((pair < 1) || (pair >= COLOR_PAIRS)) + returnCode(ERR); + if (SP->_default_color) + { + if (f < 0) + f = C_MASK; + if (b < 0) + b = C_MASK; + if (f >= COLORS && f != C_MASK) + returnCode(ERR); + if (b >= COLORS && b != C_MASK) + returnCode(ERR); + } + else + if ((f < 0) || (f >= COLORS) + || (b < 0) || (b >= COLORS)) + returnCode(ERR); + + /* + * When a pair's content is changed, replace its colors (if pair was + * initialized before a screen update is performed replacing original + * pair colors with the new ones). + */ + result = PAIR_OF(f,b); + if (SP->_color_pairs[pair] != 0 + && SP->_color_pairs[pair] != result) { + int y, x; + attr_t z = COLOR_PAIR(pair); + + for (y = 0; y <= curscr->_maxy; y++) { + struct ldat *ptr = &(curscr->_line[y]); + bool changed = FALSE; + for (x = 0; x <= curscr->_maxx; x++) { + if ((ptr->text[x] & A_COLOR) == z) { + /* Set the old cell to zero to ensure it will be + updated on the next doupdate() */ + ptr->text[x] = 0; + CHANGED_CELL(ptr,x); + changed = TRUE; + } + } + if (changed) + _nc_make_oldhash(y); + } + } + SP->_color_pairs[pair] = result; + + if (initialize_pair) + { + const color_t *tp = hue_lightness_saturation ? hls_palette : cga_palette; + + T(("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)", + pair, + tp[f].red, tp[f].green, tp[f].blue, + tp[b].red, tp[b].green, tp[b].blue)); + + if (initialize_pair) + { + TPUTS_TRACE("initialize_pair"); + putp(tparm(initialize_pair, + pair, + tp[f].red, tp[f].green, tp[f].blue, + tp[b].red, tp[b].green, tp[b].blue)); + } + } + + returnCode(OK); +} + +int init_color(short color, short r, short g, short b) +{ + T((T_CALLED("init_color(%d,%d,%d,%d)"), color, r, g, b)); + + if (initialize_color == NULL) + returnCode(ERR); + + if (color < 0 || color >= COLORS) + returnCode(ERR); + if (r < 0 || r > 1000 || g < 0 || g > 1000 || b < 0 || b > 1000) + returnCode(ERR); + + if (hue_lightness_saturation) + rgb2hls(r, g, b, + &SP->_color_table[color].red, + &SP->_color_table[color].green, + &SP->_color_table[color].blue); + else + { + SP->_color_table[color].red = r; + SP->_color_table[color].green = g; + SP->_color_table[color].blue = b; + } + + if (initialize_color) + { + TPUTS_TRACE("initialize_color"); + putp(tparm(initialize_color, color, r, g, b)); + } + returnCode(OK); +} + +bool can_change_color(void) +{ + T((T_CALLED("can_change_color()"))); + returnCode ((can_change != 0) ? TRUE : FALSE); +} + +bool has_colors(void) +{ + T((T_CALLED("has_colors()"))); + returnCode (((max_colors != -1) && (max_pairs != -1) + && (((set_foreground != NULL) + && (set_background != NULL)) + || ((set_a_foreground != NULL) + && (set_a_background != NULL)) + || set_color_pair)) ? TRUE : FALSE); +} + +int color_content(short color, short *r, short *g, short *b) +{ + T((T_CALLED("color_content(%d,%p,%p,%p)"), color, r, g, b)); + if (color < 0 || color > COLORS) + returnCode(ERR); + + if (r) *r = SP->_color_table[color].red; + if (g) *g = SP->_color_table[color].green; + if (b) *b = SP->_color_table[color].blue; + returnCode(OK); +} + +int pair_content(short pair, short *f, short *b) +{ + T((T_CALLED("pair_content(%d,%p,%p)"), pair, f, b)); + + if ((pair < 0) || (pair > COLOR_PAIRS)) + returnCode(ERR); + if (f) *f = ((SP->_color_pairs[pair] >> C_SHIFT) & C_MASK); + if (b) *b = (SP->_color_pairs[pair] & C_MASK); + + returnCode(OK); +} + +void _nc_do_color(int pair, bool reverse, int (*outc)(int)) +{ + short fg, bg; + + if (pair == 0) + { + if (orig_pair) + { + TPUTS_TRACE("orig_pair"); + tputs(orig_pair, 1, outc); + } + else if (set_color_pair) + { + TPUTS_TRACE("set_color_pair"); + tputs(tparm(set_color_pair, pair), 1, outc); + } + else + { + set_foreground_color(COLOR_WHITE, outc); + set_background_color(COLOR_BLACK, outc); + } + } + else + { + if (set_color_pair) + { + TPUTS_TRACE("set_color_pair"); + tputs(tparm(set_color_pair, pair), 1, outc); + } + else + { + pair_content(pair, &fg, &bg); + if (reverse) { + short xx = fg; + fg = bg; + bg = xx; + } + + T(("setting colors: pair = %d, fg = %d, bg = %d", pair, fg, bg)); + + if (fg == C_MASK || bg == C_MASK) + { + if (set_original_colors() != TRUE) + { + if (fg == C_MASK) + set_foreground_color(COLOR_WHITE, outc); + if (bg == C_MASK) + set_background_color(COLOR_BLACK, outc); + } + } + if (fg != C_MASK) + { + set_foreground_color(fg, outc); + } + if (bg != C_MASK) + { + set_background_color(bg, outc); + } + } + } +} diff --git a/contrib/ncurses/ncurses/base/lib_colorset.c b/contrib/ncurses/ncurses/base/lib_colorset.c new file mode 100644 index 000000000000..d9fc5c28dc01 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_colorset.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1998 * + ****************************************************************************/ + +/* +** lib_colorset.c +** +** The routine wcolor_set(). +** +*/ + +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("$Id: lib_colorset.c,v 1.5 1999/05/16 17:13:43 juergen Exp $") + +int wcolor_set(WINDOW *win, short color_pair_number, void *opts) +{ + T((T_CALLED("wcolor_set(%p,%d)"), win, color_pair_number)); + if (win && !opts && (color_pair_number >= 0) && (color_pair_number < COLOR_PAIRS)) { + T(("... current %ld", (long) PAIR_NUMBER(win->_attrs))); + toggle_attr_on(win->_attrs,COLOR_PAIR(color_pair_number)); + returnCode(OK); + } else + returnCode(ERR); +} + + diff --git a/contrib/ncurses/ncurses/base/lib_delch.c b/contrib/ncurses/ncurses/base/lib_delch.c new file mode 100644 index 000000000000..0169d31ac6d5 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_delch.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_delch.c +** +** The routine wdelch(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_delch.c,v 1.8 1998/06/28 00:28:17 tom Exp $") + +int wdelch(WINDOW *win) +{ +int code = ERR; + + T((T_CALLED("wdelch(%p)"), win)); + + if (win) { + chtype blank = _nc_background(win); + struct ldat *line = &(win->_line[win->_cury]); + chtype *end = &(line->text[win->_maxx]); + chtype *temp2 = &(line->text[win->_curx + 1]); + chtype *temp1 = temp2 - 1; + + CHANGED_TO_EOL(line, win->_curx, win->_maxx); + while (temp1 < end) + *temp1++ = *temp2++; + + *temp1 = blank; + + _nc_synchook(win); + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_delwin.c b/contrib/ncurses/ncurses/base/lib_delwin.c new file mode 100644 index 000000000000..7bab0c77b02b --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_delwin.c @@ -0,0 +1,72 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_delwin.c +** +** The routine delwin(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_delwin.c,v 1.9 1998/02/11 12:13:53 tom Exp $") + +static bool have_children(WINDOW *win) +{ + WINDOWLIST *p; + for (p = _nc_windows; p != 0; p = p->next) { + if (p->win->_flags & _SUBWIN + && p->win->_parent == win) + return TRUE; + } + return FALSE; +} + +int delwin(WINDOW *win) +{ + T((T_CALLED("delwin(%p)"), win)); + + if (win == 0 + || have_children(win)) + returnCode(ERR); + + if (win->_flags & _SUBWIN) + touchwin(win->_parent); + else if (curscr != 0) + touchwin(curscr); + + _nc_freewin(win); + + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_dft_fgbg.c b/contrib/ncurses/ncurses/base/lib_dft_fgbg.c new file mode 100644 index 000000000000..a2dfbd218f74 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_dft_fgbg.c @@ -0,0 +1,60 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ +#include <curses.priv.h> +#include <term.h> + +MODULE_ID("$Id: lib_dft_fgbg.c,v 1.3 1998/02/11 12:13:54 tom Exp $") + +/* + * Modify the behavior of color-pair 0 so that the library doesn't assume that + * it is black on white. This is an extension to XSI curses. + * + * Invoke this function after 'start_color()'. + */ +int +use_default_colors(void) +{ + T((T_CALLED("use_default_colors()"))); + + if (!SP->_coloron) + returnCode(ERR); + + if (!orig_pair && !orig_colors) + returnCode(ERR); + + if (initialize_pair) /* don't know how to handle this */ + returnCode(ERR); + + SP->_default_color = TRUE; + SP->_color_pairs[0] = PAIR_OF(C_MASK, C_MASK); + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_echo.c b/contrib/ncurses/ncurses/base/lib_echo.c new file mode 100644 index 000000000000..4ccf97ff64c0 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_echo.c @@ -0,0 +1,60 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * echo.c + * + * Routines: + * echo() + * noecho() + * + */ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_echo.c,v 1.3 1998/10/12 13:15:33 Alexander.V.Lukyanov Exp $") + +int echo(void) +{ + T((T_CALLED("echo()"))); + SP->_echo = TRUE; + returnCode(OK); +} + +int noecho(void) +{ + T((T_CALLED("noecho()"))); + SP->_echo = FALSE; + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_endwin.c b/contrib/ncurses/ncurses/base/lib_endwin.c new file mode 100644 index 000000000000..31b6e516cc1d --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_endwin.c @@ -0,0 +1,61 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_endwin.c +** +** The routine endwin(). +** +*/ + +#include <curses.priv.h> +#include <term.h> + +MODULE_ID("$Id: lib_endwin.c,v 1.17 1999/06/12 23:01:46 tom Exp $") + +int +endwin(void) +{ + T((T_CALLED("endwin()"))); + + if (SP) { + SP->_endwin = TRUE; + SP->_mouse_wrap(SP); + _nc_screen_wrap(); + _nc_mvcur_wrap(); /* wrap up cursor addressing */ + returnCode(reset_shell_mode()); + } + + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_erase.c b/contrib/ncurses/ncurses/base/lib_erase.c new file mode 100644 index 000000000000..1e4237bf8056 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_erase.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_erase.c +** +** The routine werase(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_erase.c,v 1.11 1998/02/11 12:13:54 tom Exp $") + +int werase(WINDOW *win) +{ +int code = ERR; +int y; +chtype blank; +chtype *sp, *end, *start; + + T((T_CALLED("werase(%p)"), win)); + + if (win) { + blank = _nc_background(win); + for (y = 0; y <= win->_maxy; y++) { + start = win->_line[y].text; + end = &start[win->_maxx]; + + for (sp = start; sp <= end; sp++) + *sp = blank; + + win->_line[y].firstchar = 0; + win->_line[y].lastchar = win->_maxx; + } + win->_curx = win->_cury = 0; + win->_flags &= ~_WRAPPED; + _nc_synchook(win); + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_flash.c b/contrib/ncurses/ncurses/base/lib_flash.c new file mode 100644 index 000000000000..faf381f3a645 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_flash.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * flash.c + * + * The routine flash(). + * + */ + +#include <curses.priv.h> +#include <term.h> /* beep, flash */ + +MODULE_ID("$Id: lib_flash.c,v 1.3 1998/06/29 19:34:16 Alexander.V.Lukyanov Exp $") + +/* + * flash() + * + * Flash the current terminal's screen if possible. If not, + * sound the audible bell if one exists. + * + */ + +int flash(void) +{ + int res = ERR; + + T((T_CALLED("flash()"))); + + /* FIXME: should make sure that we are not in altchar mode */ + if (flash_screen) { + TPUTS_TRACE("flash_screen"); + res = putp(flash_screen); + fflush(SP->_ofp); + } else if (bell) { + TPUTS_TRACE("bell"); + res = putp(bell); + fflush(SP->_ofp); + } + + returnCode(res); +} diff --git a/contrib/ncurses/ncurses/base/lib_freeall.c b/contrib/ncurses/ncurses/base/lib_freeall.c new file mode 100644 index 000000000000..e9a11ac36f26 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_freeall.c @@ -0,0 +1,134 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 * + ****************************************************************************/ + +#include <curses.priv.h> +#include <term_entry.h> + +#if HAVE_NC_FREEALL + +#if HAVE_LIBDBMALLOC +extern int malloc_errfd; /* FIXME */ +#endif + +MODULE_ID("$Id: lib_freeall.c,v 1.14 1999/04/03 23:17:06 tom Exp $") + +static void free_slk(SLK *p) +{ + if (p != 0) { + FreeIfNeeded(p->ent); + FreeIfNeeded(p->buffer); + free(p); + } +} + +static void free_tries(struct tries *p) +{ + struct tries *q; + + while (p != 0) { + q = p->sibling; + if (p->child != 0) + free_tries(p->child); + free(p); + p = q; + } +} + +/* + * Free all ncurses data. This is used for testing only (there's no practical + * use for it as an extension). + */ +void _nc_freeall(void) +{ + WINDOWLIST *p, *q; + +#if NO_LEAKS + _nc_free_tparm(); +#endif + while (_nc_windows != 0) { + /* Delete only windows that're not a parent */ + for (p = _nc_windows; p != 0; p = p->next) { + bool found = FALSE; + + for (q = _nc_windows; q != 0; q = q->next) { + if ((p != q) + && (q->win->_flags & _SUBWIN) + && (p->win == q->win->_parent)) { + found = TRUE; + break; + } + } + + if (!found) { + delwin(p->win); + break; + } + } + } + + if (SP != 0) { + free_tries (SP->_keytry); + free_tries (SP->_key_ok); + free_slk(SP->_slk); + FreeIfNeeded(SP->_color_pairs); + FreeIfNeeded(SP->_color_table); + /* it won't free buffer anyway */ +/* _nc_set_buffer(SP->_ofp, FALSE);*/ +#if !BROKEN_LINKER + FreeAndNull(SP); +#endif + } + + if (cur_term != 0) { + _nc_free_termtype(&(cur_term->type)); + free(cur_term); + } + +#ifdef TRACE + (void) _nc_trace_buf(-1, 0); +#endif +#if HAVE_LIBDBMALLOC + malloc_dump(malloc_errfd); +#elif HAVE_LIBDMALLOC +#elif HAVE_PURIFY + purify_all_inuse(); +#endif +} + +void _nc_free_and_exit(int code) +{ + _nc_freeall(); + exit(code); +} +#else +void _nc_freeall(void) { } +#endif diff --git a/contrib/ncurses/ncurses/base/lib_getch.c b/contrib/ncurses/ncurses/base/lib_getch.c new file mode 100644 index 000000000000..b740885b8166 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_getch.c @@ -0,0 +1,414 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_getch.c +** +** The routine getch(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_getch.c,v 1.43 1999/03/08 02:35:10 tom Exp $") + +#include <fifo_defs.h> + +int ESCDELAY = 1000; /* max interval betw. chars in funkeys, in millisecs */ + +#ifdef USE_EMX_MOUSE +# include <sys/select.h> +static int +kbd_mouse_read(unsigned char *p) +{ +fd_set fdset; +int nums = SP->_ifd+1; + + for (;;) { + FD_ZERO(&fdset); + FD_SET(SP->_checkfd, &fdset); + if (SP->_mouse_fd >= 0) { + FD_SET(SP->_mouse_fd, &fdset); + if (SP->_mouse_fd > SP->_checkfd) + nums = SP->_mouse_fd+1; + } + if (select(nums, &fdset, NULL, NULL, NULL) >= 0) { + int n; + + if (FD_ISSET(SP->_mouse_fd, &fdset)) /* Prefer mouse */ + n = read(SP->_mouse_fd, p, 1); + else + n = read(SP->_ifd, p, 1); + return n; + } + if (errno != EINTR) + return -1; + } +} +#endif /* USE_EMX_MOUSE */ + +static inline int fifo_peek(void) +{ + int ch = SP->_fifo[peek]; + T(("peeking at %d", peek)); + + p_inc(); + return ch; +} + + +static inline int fifo_pull(void) +{ +int ch; + ch = SP->_fifo[head]; + T(("pulling %d from %d", ch, head)); + + if (peek == head) + { + h_inc(); + peek = head; + } + else + h_inc(); + +#ifdef TRACE + if (_nc_tracing & TRACE_IEVENT) _nc_fifo_dump(); +#endif + return ch; +} + +static inline int fifo_push(void) +{ +int n; +unsigned int ch; + + if (tail == -1) return ERR; + +#ifdef HIDE_EINTR +again: + errno = 0; +#endif + +#if USE_GPM_SUPPORT + if ((SP->_mouse_fd >= 0) + && (_nc_timed_wait(3, -1, (int *)0) & 2)) + { + SP->_mouse_event(SP); + ch = KEY_MOUSE; + n = 1; + } else +#endif + { + unsigned char c2=0; +#ifdef USE_EMX_MOUSE + n = kbd_mouse_read(&c2); +#else + n = read(SP->_ifd, &c2, 1); +#endif + ch = c2 & 0xff; + } + +#ifdef HIDE_EINTR + /* + * Under System V curses with non-restarting signals, getch() returns + * with value ERR when a handled signal keeps it from completing. + * If signals restart system calls, OTOH, the signal is invisible + * except to its handler. + * + * We don't want this difference to show. This piece of code + * tries to make it look like we always have restarting signals. + */ + if (n <= 0 && errno == EINTR) + goto again; +#endif + + if ((n == -1) || (n == 0)) + { + T(("read(%d,&ch,1)=%d, errno=%d", SP->_ifd, n, errno)); + return ERR; + } + T(("read %d characters", n)); + + SP->_fifo[tail] = ch; + SP->_fifohold = 0; + if (head == -1) + head = peek = tail; + t_inc(); + T(("pushed %#x at %d", ch, tail)); +#ifdef TRACE + if (_nc_tracing & TRACE_IEVENT) _nc_fifo_dump(); +#endif + return ch; +} + +static inline void fifo_clear(void) +{ +int i; + for (i = 0; i < FIFO_SIZE; i++) + SP->_fifo[i] = 0; + head = -1; tail = peek = 0; +} + +static int kgetch(WINDOW *); + +#define wgetch_should_refresh(win) (\ + (is_wintouched(win) || (win->_flags & _HASMOVED)) \ + && !(win->_flags & _ISPAD)) + +int +wgetch(WINDOW *win) +{ +int ch; + + T((T_CALLED("wgetch(%p)"), win)); + + if (!win) + returnCode(ERR); + + if (cooked_key_in_fifo()) + { + if (wgetch_should_refresh(win)) + wrefresh(win); + + ch = fifo_pull(); + T(("wgetch returning (pre-cooked): %#x = %s", ch, _trace_key(ch));) + returnCode(ch); + } + + /* + * Handle cooked mode. Grab a string from the screen, + * stuff its contents in the FIFO queue, and pop off + * the first character to return it. + */ + if (head == -1 && !SP->_raw && !SP->_cbreak) + { + char buf[MAXCOLUMNS], *sp; + + T(("filling queue in cooked mode")); + + wgetnstr(win, buf, MAXCOLUMNS); + + /* ungetch in reverse order */ + ungetch('\n'); + for (sp = buf+strlen(buf); sp>buf; sp--) + ungetch(sp[-1]); + + returnCode(fifo_pull()); + } + + if (wgetch_should_refresh(win)) + wrefresh(win); + + if (!win->_notimeout && (win->_delay >= 0 || SP->_cbreak > 1)) + { + int delay; + + T(("timed delay in wgetch()")); + if (SP->_cbreak > 1) + delay = (SP->_cbreak - 1) * 100; + else + delay = win->_delay; + + T(("delay is %d milliseconds", delay)); + + if (head == -1) /* fifo is empty */ + if (!_nc_timed_wait(3, delay, (int *)0)) + returnCode(ERR); + /* else go on to read data available */ + } + + if (win->_use_keypad) + { + /* + * This is tricky. We only want to get special-key + * events one at a time. But we want to accumulate + * mouse events until either (a) the mouse logic tells + * us it's picked up a complete gesture, or (b) + * there's a detectable time lapse after one. + * + * Note: if the mouse code starts failing to compose + * press/release events into clicks, you should probably + * increase the wait with mouseinterval(). + */ + int runcount = 0; + + do { + ch = kgetch(win); + if (ch == KEY_MOUSE) + { + ++runcount; + if (SP->_mouse_inline(SP)) + break; + } + } while + (ch == KEY_MOUSE + && (_nc_timed_wait(3, SP->_maxclick, (int *)0) + || !SP->_mouse_parse(runcount))); + if (runcount > 0 && ch != KEY_MOUSE) + { + /* mouse event sequence ended by keystroke, push it */ + ungetch(ch); + ch = KEY_MOUSE; + } + } else { + if (head == -1) + fifo_push(); + ch = fifo_pull(); + } + + if (ch == ERR) + { +#if USE_SIZECHANGE + if(SP->_sig_winch) + { + _nc_update_screensize(); + /* resizeterm can push KEY_RESIZE */ + if(cooked_key_in_fifo()) + { + ch = fifo_pull(); + T(("wgetch returning (pre-cooked): %#x = %s", ch, _trace_key(ch));) + returnCode(ch); + } + } +#endif + T(("wgetch returning ERR")); + returnCode(ERR); + } + + /* + * Simulate ICRNL mode + */ + if ((ch == '\r') && SP->_nl) + ch = '\n'; + + /* Strip 8th-bit if so desired. We do this only for characters that + * are in the range 128-255, to provide compatibility with terminals + * that display only 7-bit characters. Note that 'ch' may be a + * function key at this point, so we mustn't strip _those_. + */ + if ((ch < KEY_MIN) && (ch & 0x80)) + if (!SP->_use_meta) + ch &= 0x7f; + + if (SP->_echo && ch < KEY_MIN && !(win->_flags & _ISPAD)) + wechochar(win, (chtype)ch); + + T(("wgetch returning : %#x = %s", ch, _trace_key(ch))); + + returnCode(ch); +} + + +/* +** int +** kgetch() +** +** Get an input character, but take care of keypad sequences, returning +** an appropriate code when one matches the input. After each character +** is received, set an alarm call based on ESCDELAY. If no more of the +** sequence is received by the time the alarm goes off, pass through +** the sequence gotten so far. +** +** This function must be called when there is no cooked keys in queue. +** (that is head==-1 || peek==head) +** +*/ + +static int +kgetch(WINDOW *win GCC_UNUSED) +{ +struct tries *ptr; +int ch = 0; +int timeleft = ESCDELAY; + + TR(TRACE_IEVENT, ("kgetch(%p) called", win)); + + ptr = SP->_keytry; + + for(;;) + { + if (!raw_key_in_fifo()) + { + if(fifo_push() == ERR) + { + peek = head; /* the keys stay uninterpreted */ + return ERR; + } + } + ch = fifo_peek(); + if (ch >= KEY_MIN) + { + peek = head; + /* assume the key is the last in fifo */ + t_dec(); /* remove the key */ + return ch; + } + + TR(TRACE_IEVENT, ("ch: %s", _trace_key((unsigned char)ch))); + while ((ptr != NULL) && (ptr->ch != (unsigned char)ch)) + ptr = ptr->sibling; +#ifdef TRACE + if (ptr == NULL) + {TR(TRACE_IEVENT, ("ptr is null"));} + else + TR(TRACE_IEVENT, ("ptr=%p, ch=%d, value=%d", + ptr, ptr->ch, ptr->value)); +#endif /* TRACE */ + + if (ptr == NULL) + break; + + if (ptr->value != 0) { /* sequence terminated */ + TR(TRACE_IEVENT, ("end of sequence")); + if (peek == tail) + fifo_clear(); + else + head = peek; + return(ptr->value); + } + + ptr = ptr->child; + + if (!raw_key_in_fifo()) + { + TR(TRACE_IEVENT, ("waiting for rest of sequence")); + if (!_nc_timed_wait(3, timeleft, &timeleft)) { + TR(TRACE_IEVENT, ("ran out of time")); + break; + } + } + } + ch = fifo_pull(); + peek = head; + return ch; +} diff --git a/contrib/ncurses/ncurses/base/lib_getstr.c b/contrib/ncurses/ncurses/base/lib_getstr.c new file mode 100644 index 000000000000..485c6e35c8ff --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_getstr.c @@ -0,0 +1,192 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_getstr.c +** +** The routine wgetstr(). +** +*/ + +#include <curses.priv.h> +#include <term.h> + +MODULE_ID("$Id: lib_getstr.c,v 1.20 1998/12/20 00:16:01 tom Exp $") + +/* + * This wipes out the last character, no matter whether it was a tab, control + * or other character, and handles reverse wraparound. + */ +static char *WipeOut(WINDOW *win, int y, int x, char *first, char *last, bool echoed) +{ + if (last > first) { + *--last = '\0'; + if (echoed) { + int y1 = win->_cury; + int x1 = win->_curx; + + wmove(win, y, x); + waddstr(win, first); + getyx(win, y, x); + while (win->_cury < y1 + || (win->_cury == y1 && win->_curx < x1)) + waddch(win, ' '); + + wmove(win, y, x); + } + } + return last; +} + +int wgetnstr(WINDOW *win, char *str, int maxlen) +{ +TTY buf; +bool oldnl, oldecho, oldraw, oldcbreak; +char erasec; +char killc; +char *oldstr; +int ch; +int y, x; + + T((T_CALLED("wgetnstr(%p,%p, %d)"), win, str, maxlen)); + + if (!win) + returnCode(ERR); + + _nc_get_tty_mode(&buf); + + oldnl = SP->_nl; + oldecho = SP->_echo; + oldraw = SP->_raw; + oldcbreak = SP->_cbreak; + nl(); + noecho(); + noraw(); + cbreak(); + + erasec = erasechar(); + killc = killchar(); + + oldstr = str; + getyx(win, y, x); + + if (is_wintouched(win) || (win->_flags & _HASMOVED)) + wrefresh(win); + + while ((ch = wgetch(win)) != ERR) { + /* + * Some terminals (the Wyse-50 is the most common) generate + * a \n from the down-arrow key. With this logic, it's the + * user's choice whether to set kcud=\n for wgetch(); + * terminating *getstr() with \n should work either way. + */ + if (ch == '\n' + || ch == '\r' + || ch == KEY_DOWN + || ch == KEY_ENTER) { + if (oldecho == TRUE + && win->_cury == win->_maxy + && win->_scroll) + wechochar(win, '\n'); + break; + } + if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) { + if (str > oldstr) { + str = WipeOut(win, y, x, oldstr, str, oldecho); + } + } else if (ch == killc) { + while (str > oldstr) { + str = WipeOut(win, y, x, oldstr, str, oldecho); + } + } else if (ch >= KEY_MIN + || (maxlen >= 0 && str - oldstr >= maxlen)) { + beep(); + } else { + *str++ = ch; + if (oldecho == TRUE) { + int oldy = win->_cury; + if (waddch(win, ch) == ERR) { + /* + * We can't really use the lower-right + * corner for input, since it'll mess + * up bookkeeping for erases. + */ + win->_flags &= ~_WRAPPED; + waddch(win, ' '); + str = WipeOut(win, y, x, oldstr, str, oldecho); + continue; + } else if (win->_flags & _WRAPPED) { + /* + * If the last waddch forced a wrap & + * scroll, adjust our reference point + * for erasures. + */ + if (win->_scroll + && oldy == win->_maxy + && win->_cury == win->_maxy) { + if (--y <= 0) { + y = 0; + } + } + win->_flags &= ~_WRAPPED; + } + wrefresh(win); + } + } + } + + win->_curx = 0; + win->_flags &= ~_WRAPPED; + if (win->_cury < win->_maxy) + win->_cury++; + wrefresh(win); + + /* Restore with a single I/O call, to fix minor asymmetry between + * raw/noraw, etc. + */ + SP->_nl = oldnl; + SP->_echo = oldecho; + SP->_raw = oldraw; + SP->_cbreak = oldcbreak; + + _nc_set_tty_mode(&buf); + + *str = '\0'; + if (ch == ERR) + returnCode(ERR); + + T(("wgetnstr returns %s", _nc_visbuf(oldstr))); + + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_hline.c b/contrib/ncurses/ncurses/base/lib_hline.c new file mode 100644 index 000000000000..3b0a602eeee9 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_hline.c @@ -0,0 +1,76 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_hline.c +** +** The routine whline(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_hline.c,v 1.4 1998/06/28 00:11:01 tom Exp $") + +int whline(WINDOW *win, chtype ch, int n) +{ +int code = ERR; +short start; +short end; + + T((T_CALLED("whline(%p,%s,%d)"), win, _tracechtype(ch), n)); + + if (win) { + struct ldat *line = &(win->_line[win->_cury]); + + start = win->_curx; + end = start + n - 1; + if (end > win->_maxx) + end = win->_maxx; + + CHANGED_RANGE(line, start, end); + + if (ch == 0) + ch = ACS_HLINE; + ch = _nc_render(win, ch); + + while ( end >= start) { + line->text[end] = ch; + end--; + } + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_immedok.c b/contrib/ncurses/ncurses/base/lib_immedok.c new file mode 100644 index 000000000000..5590ec9f5406 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_immedok.c @@ -0,0 +1,54 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_immedok.c +** +** The routine immedok. +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_immedok.c,v 1.2 1998/02/11 12:14:01 tom Exp $") + +void immedok(WINDOW *win, bool flag) +{ + T((T_CALLED("immedok(%p,%d)"), win, flag)); + + if (win) + win->_immed = flag; + + returnVoid; +} diff --git a/contrib/ncurses/ncurses/base/lib_inchstr.c b/contrib/ncurses/ncurses/base/lib_inchstr.c new file mode 100644 index 000000000000..4779ae09d75b --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_inchstr.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_inchstr.c +** +** The routine winchnstr(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_inchstr.c,v 1.7 1998/02/11 12:13:55 tom Exp $") + +int winchnstr(WINDOW *win, chtype *str, int n) +{ + int i = 0; + + T((T_CALLED("winchnstr(%p,%p,%d)"), win, str, n)); + + if (!str) + returnCode(0); + + if (win) { + for (; (n < 0 || (i < n)) && (win->_curx + i <= win->_maxx); i++) + str[i] = win->_line[win->_cury].text[win->_curx + i]; + } + str[i] = (chtype)0; + + returnCode(i); +} diff --git a/contrib/ncurses/ncurses/base/lib_initscr.c b/contrib/ncurses/ncurses/base/lib_initscr.c new file mode 100644 index 000000000000..9a89a077cd44 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_initscr.c @@ -0,0 +1,78 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_initscr.c +** +** The routines initscr(), and termname(). +** +*/ + +#include <curses.priv.h> +#include <tic.h> /* for MAX_ALIAS */ + +#if HAVE_SYS_TERMIO_H +#include <sys/termio.h> /* needed for ISC */ +#endif + +MODULE_ID("$Id: lib_initscr.c,v 1.26 1998/12/19 23:10:09 tom Exp $") + +WINDOW *initscr(void) +{ +static bool initialized = FALSE; +NCURSES_CONST char *name; +int value; + + T((T_CALLED("initscr()"))); + /* Portable applications must not call initscr() more than once */ + if (!initialized) { + initialized = TRUE; + + if ((name = getenv("TERM")) == 0 + || *name == '\0') + name = "unknown"; + if (newterm(name, stdout, stdin) == 0) { + fprintf(stderr, "Error opening terminal: %s.\n", name); + exit(EXIT_FAILURE); + } + + /* allow user to set maximum escape delay from the environment */ + if ((value = _nc_getenv_num("ESCDELAY")) >= 0) { + ESCDELAY = value; + } + + /* def_shell_mode - done in newterm/_nc_setupscreen */ + def_prog_mode(); + } + returnWin(stdscr); +} diff --git a/contrib/ncurses/ncurses/base/lib_insch.c b/contrib/ncurses/ncurses/base/lib_insch.c new file mode 100644 index 000000000000..ccc5ff5d024d --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_insch.c @@ -0,0 +1,67 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_insch.c +** +** The routine winsch(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_insch.c,v 1.10 1998/06/28 00:26:52 tom Exp $") + +int winsch(WINDOW *win, chtype c) +{ +int code = ERR; + + T((T_CALLED("winsch(%p, %s)"), win, _tracechtype(c))); + + if (win) { + struct ldat *line = &(win->_line[win->_cury]); + chtype *end = &(line->text[win->_curx]); + chtype *temp1 = &(line->text[win->_maxx]); + chtype *temp2 = temp1 - 1; + + CHANGED_TO_EOL(line, win->_curx, win->_maxx); + while (temp1 > end) + *temp1-- = *temp2--; + + *temp1 = _nc_render(win, c); + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_insdel.c b/contrib/ncurses/ncurses/base/lib_insdel.c new file mode 100644 index 000000000000..48e108de8d9b --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_insdel.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_insdel.c +** +** The routine winsdelln(win, n). +** positive n insert n lines above current line +** negative n delete n lines starting from current line +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_insdel.c,v 1.8 1998/02/11 12:13:55 tom Exp $") + +int +winsdelln(WINDOW *win, int n) +{ +int code = ERR; + + T((T_CALLED("winsdel(%p,%d)"), win, n)); + + if (win) { + if (n != 0) { + _nc_scroll_window(win, -n, win->_cury, win->_maxy, _nc_background(win)); + _nc_synchook(win); + } + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_insstr.c b/contrib/ncurses/ncurses/base/lib_insstr.c new file mode 100644 index 000000000000..cba147318b8e --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_insstr.c @@ -0,0 +1,81 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_insstr.c +** +** The routine winsnstr(). +** +*/ + +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("$Id: lib_insstr.c,v 1.13 1999/03/14 00:27:21 tom Exp $") + +int winsnstr(WINDOW *win, const char *s, int n) +{ +int code = ERR; +short oy; +short ox ; +const unsigned char *str = (const unsigned char *)s; +const unsigned char *cp; + + T((T_CALLED("winsnstr(%p,%s,%d)"), win, _nc_visbuf(s), n)); + + if (win && str) { + oy = win->_cury; ox = win->_curx; + for (cp = str; *cp && (n <= 0 || (cp - str) < n); cp++) { + if (*cp == '\n' || *cp == '\r' || *cp == '\t' || *cp == '\b') + _nc_waddch_nosync(win, (chtype)(*cp)); + else if (is7bits(*cp) && iscntrl(*cp)) { + winsch(win, ' ' + (chtype)(*cp)); + winsch(win, '^'); + win->_curx += 2; + } else { + winsch(win, (chtype)(*cp)); + win->_curx++; + } + if (win->_curx > win->_maxx) + win->_curx = win->_maxx; + } + + win->_curx = ox; + win->_cury = oy; + _nc_synchook(win); + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_instr.c b/contrib/ncurses/ncurses/base/lib_instr.c new file mode 100644 index 000000000000..b3e1d030a4b6 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_instr.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_instr.c +** +** The routine winnstr(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_instr.c,v 1.8 1998/02/11 12:13:54 tom Exp $") + +int winnstr(WINDOW *win, char *str, int n) +{ + int i=0, row, col; + + T((T_CALLED("winnstr(%p,%p,%d)"), win, str, n)); + + if (!str) + returnCode(0); + + if (win) { + getyx(win, row, col); + + if (n < 0) + n = win->_maxx - win->_curx + 1; + + for (; i < n;) { + str[i++] = TextOf(win->_line[row].text[col]); + if (++col > win->_maxx) { + col = 0; + if (++row > win->_maxy) + break; + } + } + } + str[i] = '\0'; /* SVr4 does not seem to count the null */ + returnCode(i); +} + diff --git a/contrib/ncurses/ncurses/base/lib_isendwin.c b/contrib/ncurses/ncurses/base/lib_isendwin.c new file mode 100644 index 000000000000..60015fca55b9 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_isendwin.c @@ -0,0 +1,51 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_endwin.c +** +** The routine endwin(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_isendwin.c,v 1.4 1998/04/11 22:52:32 tom Exp $") + +bool isendwin(void) +{ + if (SP == NULL) + return FALSE; + return SP->_endwin; +} diff --git a/contrib/ncurses/ncurses/base/lib_leaveok.c b/contrib/ncurses/ncurses/base/lib_leaveok.c new file mode 100644 index 000000000000..e83285d714f4 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_leaveok.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_leaveok.c +** +** The routine leaveok. +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_leaveok.c,v 1.3 1998/03/21 22:54:20 jtc Exp $") + +int leaveok(WINDOW *win, bool flag) +{ + T((T_CALLED("leaveok(%p,%d)"), win, flag)); + + if (win) { + win->_leaveok = flag; + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_mouse.c b/contrib/ncurses/ncurses/base/lib_mouse.c new file mode 100644 index 000000000000..0aefdf3d8219 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_mouse.c @@ -0,0 +1,964 @@ +/**************************************************************************** + * Copyright (c) 1998,1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * This module is intended to encapsulate ncurses's interface to pointing + * devices. + * + * The first method used is xterm's internal mouse-tracking facility. + * The second is Alessandro Rubini's GPM server. + * + * Notes for implementors of new mouse-interface methods: + * + * The code is logically split into a lower level that accepts event reports + * in a device-dependent format and an upper level that parses mouse gestures + * and filters events. The mediating data structure is a circular queue of + * MEVENT structures. + * + * Functionally, the lower level's job is to pick up primitive events and + * put them on the circular queue. This can happen in one of two ways: + * either (a) _nc_mouse_event() detects a series of incoming mouse reports + * and queues them, or (b) code in lib_getch.c detects the kmous prefix in + * the keyboard input stream and calls _nc_mouse_inline to queue up a series + * of adjacent mouse reports. + * + * In either case, _nc_mouse_parse() should be called after the series is + * accepted to parse the digested mouse reports (low-level MEVENTs) into + * a gesture (a high-level or composite MEVENT). + * + * Don't be too shy about adding new event types or modifiers, if you can find + * room for them in the 32-bit mask. The API is written so that users get + * feedback on which theoretical event types they won't see when they call + * mousemask. There's one bit per button (the RESERVED_EVENT bit) not being + * used yet, and a couple of bits open at the high end. + */ + +#ifdef __EMX__ +# include "io.h" +# include "fcntl.h" +# define INCL_DOS +# define INCL_VIO +# define INCL_KBD +# define INCL_MOU +# define INCL_DOSPROCESS +# include <os2.h> /* Need to include before the others */ +#endif + +#include <curses.priv.h> +#include <term.h> + +#if USE_GPM_SUPPORT +#ifndef LINT /* don't need this for llib-lncurses */ +#undef buttons /* term.h defines this, and gpm uses it! */ +#include <gpm.h> +#include <linux/keyboard.h> /* defines KG_* macros */ +#endif +#endif + +MODULE_ID("$Id: lib_mouse.c,v 1.44 1999/07/24 21:10:48 tom Exp $") + +#define MY_TRACE TRACE_ICALLS|TRACE_IEVENT + +#define INVALID_EVENT -1 + +static int mousetype; +#define M_XTERM -1 /* use xterm's mouse tracking? */ +#define M_NONE 0 /* no mouse device */ +#define M_GPM 1 /* use GPM */ +#define M_QNX 2 /* QNX mouse on console */ +#define M_QNX_TERM 3 /* QNX mouse on pterm/xterm (using qansi-m) */ + +#if USE_GPM_SUPPORT +#ifndef LINT +static Gpm_Connect gpm_connect; +#endif +#endif + +static mmask_t eventmask; /* current event mask */ + +static bool _nc_mouse_parse(int); +static void _nc_mouse_resume(SCREEN *); +static void _nc_mouse_wrap(SCREEN *); + +/* maintain a circular list of mouse events */ + +/* The definition of the circular list size (EV_MAX), is in curses.priv.h, so + * wgetch() may refer to the size and call _nc_mouse_parse() before circular + * list overflow. + */ +static MEVENT events[EV_MAX]; /* hold the last mouse event seen */ +static MEVENT *eventp = events; /* next free slot in event queue */ +#define NEXT(ep) ((ep == events + EV_MAX - 1) ? events : ep + 1) +#define PREV(ep) ((ep == events) ? events + EV_MAX - 1 : ep - 1) + +#ifdef TRACE +static void _trace_slot(const char *tag) +{ + MEVENT *ep; + + _tracef(tag); + + for (ep = events; ep < events + EV_MAX; ep++) + _tracef("mouse event queue slot %ld = %s", + (long) (ep - events), + _tracemouse(ep)); +} +#endif + +#ifdef USE_EMX_MOUSE + +# define TOP_ROW 0 +# define LEFT_COL 0 + +static int mouse_wfd; +static int mouse_thread; +static int mouse_activated; +static char mouse_buttons[] = { 0, 1, 3, 2}; + + +# define M_FD(sp) sp->_mouse_fd + +static void +write_event(int down, int button, int x, int y) +{ + char buf[6]; + unsigned long ignore; + + strcpy(buf, key_mouse); + buf[3] = ' ' + (button - 1) + (down ? 0 : 0x40); + buf[4] = ' ' + x - LEFT_COL + 1; + buf[5] = ' ' + y - TOP_ROW + 1; + DosWrite(mouse_wfd, buf, 6, &ignore); +} + +static void +mouse_server(unsigned long ignored GCC_UNUSED) +{ + unsigned short fWait = MOU_WAIT; + /* NOPTRRECT mourt = { 0,0,24,79 }; */ + MOUEVENTINFO mouev; + HMOU hmou; + unsigned short mask = MOUSE_BN1_DOWN | MOUSE_BN2_DOWN | MOUSE_BN3_DOWN; + int oldstate = 0; + char errmess[] = "Unexpected termination of mouse thread\r\n"; + unsigned long ignore; + + /* open the handle for the mouse */ + if (MouOpen(NULL,&hmou) == 0) { + + if (MouSetEventMask(&mask,hmou) == 0 + && MouDrawPtr(hmou) == 0) { + + for (;;) { + /* sit and wait on the event queue */ + if (MouReadEventQue(&mouev,&fWait,hmou)) + break; + if (!mouse_activated) + goto finish; + + /* + * OS/2 numbers a 3-button mouse inconsistently from other + * platforms: + * 1 = left + * 2 = right + * 3 = middle. + */ + if ((mouev.fs ^ oldstate) & MOUSE_BN1_DOWN) + write_event(mouev.fs & MOUSE_BN1_DOWN, + mouse_buttons[1], mouev.col, mouev.row); + if ((mouev.fs ^ oldstate) & MOUSE_BN2_DOWN) + write_event(mouev.fs & MOUSE_BN2_DOWN, + mouse_buttons[3], mouev.col, mouev.row); + if ((mouev.fs ^ oldstate) & MOUSE_BN3_DOWN) + write_event(mouev.fs & MOUSE_BN3_DOWN, + mouse_buttons[2], mouev.col, mouev.row); + + finish: + oldstate = mouev.fs; + } + } + + DosWrite(2, errmess, strlen(errmess), &ignore); + MouClose(hmou); + } + DosExit(EXIT_THREAD, 0L ); +} +static void +server_state(const int state) +{ /* It would be nice to implement pointer-off and stop looping... */ + mouse_activated = state; +} + +#endif + +static int initialized; + +static void _nc_mouse_init(void) +/* initialize the mouse */ +{ + int i; + + if (initialized) { + return; + } + initialized = TRUE; + + TR(MY_TRACE, ("_nc_mouse_init() called")); + + for (i = 0; i < EV_MAX; i++) + events[i].id = INVALID_EVENT; + + /* we know how to recognize mouse events under xterm */ + if (key_mouse != 0 + && getenv("DISPLAY") != 0) + mousetype = M_XTERM; + +#if USE_GPM_SUPPORT + else if (!strncmp(cur_term->type.term_names, "linux", 5)) + { + /* GPM: initialize connection to gpm server */ + gpm_connect.eventMask = GPM_DOWN|GPM_UP; + gpm_connect.defaultMask = ~(gpm_connect.eventMask|GPM_HARD); + gpm_connect.minMod = 0; + gpm_connect.maxMod = ~((1<<KG_SHIFT)|(1<<KG_SHIFTL)|(1<<KG_SHIFTR)); + if (Gpm_Open (&gpm_connect, 0) >= 0) { /* returns the file-descriptor */ + mousetype = M_GPM; + SP->_mouse_fd = gpm_fd; + } + } +#endif + + /* OS/2 VIO */ +#ifdef USE_EMX_MOUSE + if (!mouse_thread && mousetype != M_XTERM && key_mouse) { + int handles[2]; + if (pipe(handles) < 0) { + perror("mouse pipe error"); + } else { + int rc; + + if (!mouse_buttons[0]) { + char *s = getenv("MOUSE_BUTTONS_123"); + + mouse_buttons[0] = 1; + if (s && strlen(s) >= 3) { + mouse_buttons[1] = s[0] - '0'; + mouse_buttons[2] = s[1] - '0'; + mouse_buttons[3] = s[2] - '0'; + } + } + mouse_wfd = handles[1]; + M_FD(SP) = handles[0]; + /* Needed? */ + setmode(handles[0], O_BINARY); + setmode(handles[1], O_BINARY); + /* Do not use CRT functions, we may single-threaded. */ + rc = DosCreateThread((unsigned long*)&mouse_thread, mouse_server, 0, 0, 8192); + if (rc) + printf("mouse thread error %d=%#x", rc, rc); + else + mousetype = M_XTERM; + } + } +#endif + + T(("_nc_mouse_init() set mousetype to %d", mousetype)); +} + +static bool _nc_mouse_event(SCREEN *sp GCC_UNUSED) +/* query to see if there is a pending mouse event */ +{ +#if USE_GPM_SUPPORT + /* GPM: query server for event, return TRUE if we find one */ + Gpm_Event ev; + + if (gpm_fd >= 0 + && _nc_timed_wait(2, 0, (int *)0) + && Gpm_GetEvent(&ev) == 1) + { + eventp->id = 0; /* there's only one mouse... */ + + eventp->bstate = 0; + switch (ev.type & 0x0f) + { + case(GPM_DOWN): + if (ev.buttons & GPM_B_LEFT) eventp->bstate |= BUTTON1_PRESSED; + if (ev.buttons & GPM_B_MIDDLE) eventp->bstate |= BUTTON2_PRESSED; + if (ev.buttons & GPM_B_RIGHT) eventp->bstate |= BUTTON3_PRESSED; + break; + case(GPM_UP): + if (ev.buttons & GPM_B_LEFT) eventp->bstate |= BUTTON1_RELEASED; + if (ev.buttons & GPM_B_MIDDLE) eventp->bstate |= BUTTON2_RELEASED; + if (ev.buttons & GPM_B_RIGHT) eventp->bstate |= BUTTON3_RELEASED; + break; + default: + break; + } + + eventp->x = ev.x - 1; + eventp->y = ev.y - 1; + eventp->z = 0; + + /* bump the next-free pointer into the circular list */ + eventp = NEXT(eventp); + return (TRUE); + } +#endif + + /* xterm: never have to query, mouse events are in the keyboard stream */ + return(FALSE); /* no event waiting */ +} + +static bool _nc_mouse_inline(SCREEN *sp) +/* mouse report received in the keyboard stream -- parse its info */ +{ + TR(MY_TRACE, ("_nc_mouse_inline() called")); + + if (mousetype == M_XTERM) + { + unsigned char kbuf[4]; + MEVENT *prev; + size_t grabbed; + int res; + + /* This code requires that your xterm entry contain the kmous + * capability and that it be set to the \E[M documented in the + * Xterm Control Sequences reference. This is how we + * arrange for mouse events to be reported via a KEY_MOUSE + * return value from wgetch(). After this value is received, + * _nc_mouse_inline() gets called and is immediately + * responsible for parsing the mouse status information + * following the prefix. + * + * The following quotes from the ctrlseqs.ms document in the + * X distribution, describing the X mouse tracking feature: + * + * Parameters for all mouse tracking escape sequences + * generated by xterm encode numeric parameters in a single + * character as value+040. For example, ! is 1. + * + * On button press or release, xterm sends ESC [ M CbCxCy. + * The low two bits of Cb encode button information: 0=MB1 + * pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release. The + * upper bits encode what modifiers were down when the + * button was pressed and are added together. 4=Shift, + * 8=Meta, 16=Control. Cx and Cy are the x and y coordinates + * of the mouse event. The upper left corner is (1,1). + * + * (End quote) By the time we get here, we've eaten the + * key prefix. FYI, the loop below is necessary because + * mouse click info isn't guaranteed to present as a + * single clist item. It always does under Linux but often + * fails to under Solaris. + */ + for (grabbed = 0; grabbed < 3; grabbed += res) + { + + /* For VIO mouse we add extra bit 64 to disambiguate button-up. */ +#ifdef USE_EMX_MOUSE + res = read( M_FD(sp) >= 0 ? M_FD(sp) : sp->_ifd, &kbuf, 3); +#else + res = read(sp->_ifd, kbuf + grabbed, 3-grabbed); +#endif + if (res == -1) + break; + } + kbuf[3] = '\0'; + + TR(TRACE_IEVENT, ("_nc_mouse_inline sees the following xterm data: '%s'", kbuf)); + + eventp->id = 0; /* there's only one mouse... */ + + /* processing code goes here */ + eventp->bstate = 0; + switch (kbuf[0] & 0x3) + { + case 0x0: + eventp->bstate = BUTTON1_PRESSED; +#ifdef USE_EMX_MOUSE + if (kbuf[0] & 0x40) + eventp->bstate = BUTTON1_RELEASED; +#endif + break; + + case 0x1: + eventp->bstate = BUTTON2_PRESSED; +#ifdef USE_EMX_MOUSE + if (kbuf[0] & 0x40) + eventp->bstate = BUTTON2_RELEASED; +#endif + break; + + case 0x2: + eventp->bstate = BUTTON3_PRESSED; +#ifdef USE_EMX_MOUSE + if (kbuf[0] & 0x40) + eventp->bstate = BUTTON3_RELEASED; +#endif + break; + + case 0x3: + /* + * Release events aren't reported for individual buttons, + * just for the button set as a whole... + */ + eventp->bstate = + (BUTTON1_RELEASED | + BUTTON2_RELEASED | + BUTTON3_RELEASED); + /* + * ...however, because there are no kinds of mouse events under + * xterm that can intervene between press and release, we can + * deduce which buttons were actually released by looking at the + * previous event. + */ + prev = PREV(eventp); + if (!(prev->bstate & BUTTON1_PRESSED)) + eventp->bstate &=~ BUTTON1_RELEASED; + if (!(prev->bstate & BUTTON2_PRESSED)) + eventp->bstate &=~ BUTTON2_RELEASED; + if (!(prev->bstate & BUTTON3_PRESSED)) + eventp->bstate &=~ BUTTON3_RELEASED; + break; + } + + if (kbuf[0] & 4) { + eventp->bstate |= BUTTON_SHIFT; + } + if (kbuf[0] & 8) { + eventp->bstate |= BUTTON_ALT; + } + if (kbuf[0] & 16) { + eventp->bstate |= BUTTON_CTRL; + } + + eventp->x = (kbuf[1] - ' ') - 1; + eventp->y = (kbuf[2] - ' ') - 1; + TR(MY_TRACE, ("_nc_mouse_inline: primitive mouse-event %s has slot %ld", + _tracemouse(eventp), + (long) (eventp - events))); + + /* bump the next-free pointer into the circular list */ + eventp = NEXT(eventp); +#if 0 /* this return would be needed for QNX's mods to lib_getch.c */ + return(TRUE); +#endif + } + + return(FALSE); +} + +static void mouse_activate(bool on) +{ + if (!on && !initialized) + return; + + _nc_mouse_init(); + + if (on) { + + switch (mousetype) { + case M_XTERM: +#ifdef NCURSES_EXT_FUNCS + keyok(KEY_MOUSE, on); +#endif + TPUTS_TRACE("xterm mouse initialization"); +#ifdef USE_EMX_MOUSE + server_state(1); +#else + putp("\033[?1000h"); +#endif + break; +#if USE_GPM_SUPPORT + case M_GPM: + SP->_mouse_fd = gpm_fd; + break; +#endif + } + /* Make runtime binding to cut down on object size of applications that + * do not use the mouse (e.g., 'clear'). + */ + SP->_mouse_event = _nc_mouse_event; + SP->_mouse_inline = _nc_mouse_inline; + SP->_mouse_parse = _nc_mouse_parse; + SP->_mouse_resume = _nc_mouse_resume; + SP->_mouse_wrap = _nc_mouse_wrap; + + } else { + + switch (mousetype) { + case M_XTERM: + TPUTS_TRACE("xterm mouse deinitialization"); +#ifdef USE_EMX_MOUSE + server_state(0); +#else + putp("\033[?1000l"); +#endif + break; +#if USE_GPM_SUPPORT + case M_GPM: + break; +#endif + } + } + (void) fflush(SP->_ofp); +} + +/************************************************************************** + * + * Device-independent code + * + **************************************************************************/ + +static bool _nc_mouse_parse(int runcount) +/* parse a run of atomic mouse events into a gesture */ +{ + MEVENT *ep, *runp, *next, *prev = PREV(eventp); + int n; + bool merge; + + TR(MY_TRACE, ("_nc_mouse_parse(%d) called", runcount)); + + /* + * When we enter this routine, the event list next-free pointer + * points just past a run of mouse events that we know were separated + * in time by less than the critical click interval. The job of this + * routine is to collaps this run into a single higher-level event + * or gesture. + * + * We accomplish this in two passes. The first pass merges press/release + * pairs into click events. The second merges runs of click events into + * double or triple-click events. + * + * It's possible that the run may not resolve to a single event (for + * example, if the user quadruple-clicks). If so, leading events + * in the run are ignored. + * + * Note that this routine is independent of the format of the specific + * format of the pointing-device's reports. We can use it to parse + * gestures on anything that reports press/release events on a per- + * button basis, as long as the device-dependent mouse code puts stuff + * on the queue in MEVENT format. + */ + if (runcount == 1) + { + TR(MY_TRACE, ("_nc_mouse_parse: returning simple mouse event %s at slot %ld", + _tracemouse(prev), + (long) (prev - events))); + return (prev->id >= 0) + ? ((prev->bstate & eventmask) ? TRUE : FALSE) + : FALSE; + } + + /* find the start of the run */ + runp = eventp; + for (n = runcount; n > 0; n--) { + runp = PREV(runp); + } + +#ifdef TRACE + if (_nc_tracing & TRACE_IEVENT) + { + _trace_slot("before mouse press/release merge:"); + _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d", + (long) (runp - events), + (long) ((eventp - events) + (EV_MAX-1)) % EV_MAX, + runcount); + } +#endif /* TRACE */ + + /* first pass; merge press/release pairs */ + do { + merge = FALSE; + for (ep = runp; next = NEXT(ep), next != eventp; ep = next) + { + if (ep->x == next->x && ep->y == next->y + && (ep->bstate & (BUTTON1_PRESSED|BUTTON2_PRESSED|BUTTON3_PRESSED)) + && (!(ep->bstate & BUTTON1_PRESSED) + == !(next->bstate & BUTTON1_RELEASED)) + && (!(ep->bstate & BUTTON2_PRESSED) + == !(next->bstate & BUTTON2_RELEASED)) + && (!(ep->bstate & BUTTON3_PRESSED) + == !(next->bstate & BUTTON3_RELEASED)) + ) + { + if ((eventmask & BUTTON1_CLICKED) + && (ep->bstate & BUTTON1_PRESSED)) + { + ep->bstate &=~ BUTTON1_PRESSED; + ep->bstate |= BUTTON1_CLICKED; + merge = TRUE; + } + if ((eventmask & BUTTON2_CLICKED) + && (ep->bstate & BUTTON2_PRESSED)) + { + ep->bstate &=~ BUTTON2_PRESSED; + ep->bstate |= BUTTON2_CLICKED; + merge = TRUE; + } + if ((eventmask & BUTTON3_CLICKED) + && (ep->bstate & BUTTON3_PRESSED)) + { + ep->bstate &=~ BUTTON3_PRESSED; + ep->bstate |= BUTTON3_CLICKED; + merge = TRUE; + } + if (merge) + next->id = INVALID_EVENT; + } + } + } while + (merge); + +#ifdef TRACE + if (_nc_tracing & TRACE_IEVENT) + { + _trace_slot("before mouse click merge:"); + _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d", + (long) (runp - events), + (long) ((eventp - events) + (EV_MAX-1)) % EV_MAX, + runcount); + } +#endif /* TRACE */ + + /* + * Second pass; merge click runs. At this point, click events are + * each followed by one invalid event. We merge click events + * forward in the queue. + * + * NOTE: There is a problem with this design! If the application + * allows enough click events to pile up in the circular queue so + * they wrap around, it will cheerfully merge the newest forward + * into the oldest, creating a bogus doubleclick and confusing + * the queue-traversal logic rather badly. Generally this won't + * happen, because calling getmouse() marks old events invalid and + * ineligible for merges. The true solution to this problem would + * be to timestamp each MEVENT and perform the obvious sanity check, + * but the timer element would have to have sub-second resolution, + * which would get us into portability trouble. + */ + do { + MEVENT *follower; + + merge = FALSE; + for (ep = runp; next = NEXT(ep), next != eventp; ep = next) + if (ep->id != INVALID_EVENT) + { + if (next->id != INVALID_EVENT) + continue; + follower = NEXT(next); + if (follower->id == INVALID_EVENT) + continue; + + /* merge click events forward */ + if ((ep->bstate & + (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED)) + && (follower->bstate & + (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED))) + { + if ((eventmask & BUTTON1_DOUBLE_CLICKED) + && (follower->bstate & BUTTON1_CLICKED)) + { + follower->bstate &=~ BUTTON1_CLICKED; + follower->bstate |= BUTTON1_DOUBLE_CLICKED; + merge = TRUE; + } + if ((eventmask & BUTTON2_DOUBLE_CLICKED) + && (follower->bstate & BUTTON2_CLICKED)) + { + follower->bstate &=~ BUTTON2_CLICKED; + follower->bstate |= BUTTON2_DOUBLE_CLICKED; + merge = TRUE; + } + if ((eventmask & BUTTON3_DOUBLE_CLICKED) + && (follower->bstate & BUTTON3_CLICKED)) + { + follower->bstate &=~ BUTTON3_CLICKED; + follower->bstate |= BUTTON3_DOUBLE_CLICKED; + merge = TRUE; + } + if (merge) + ep->id = INVALID_EVENT; + } + + /* merge double-click events forward */ + if ((ep->bstate & + (BUTTON1_DOUBLE_CLICKED + | BUTTON2_DOUBLE_CLICKED + | BUTTON3_DOUBLE_CLICKED)) + && (follower->bstate & + (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED))) + { + if ((eventmask & BUTTON1_TRIPLE_CLICKED) + && (follower->bstate & BUTTON1_CLICKED)) + { + follower->bstate &=~ BUTTON1_CLICKED; + follower->bstate |= BUTTON1_TRIPLE_CLICKED; + merge = TRUE; + } + if ((eventmask & BUTTON2_TRIPLE_CLICKED) + && (follower->bstate & BUTTON2_CLICKED)) + { + follower->bstate &=~ BUTTON2_CLICKED; + follower->bstate |= BUTTON2_TRIPLE_CLICKED; + merge = TRUE; + } + if ((eventmask & BUTTON3_TRIPLE_CLICKED) + && (follower->bstate & BUTTON3_CLICKED)) + { + follower->bstate &=~ BUTTON3_CLICKED; + follower->bstate |= BUTTON3_TRIPLE_CLICKED; + merge = TRUE; + } + if (merge) + ep->id = INVALID_EVENT; + } + } + } while + (merge); + +#ifdef TRACE + if (_nc_tracing & TRACE_IEVENT) + { + _trace_slot("before mouse event queue compaction:"); + _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d", + (long) (runp - events), + (long) ((eventp - events) + (EV_MAX-1)) % EV_MAX, + runcount); + } +#endif /* TRACE */ + + /* + * Now try to throw away trailing events flagged invalid, or that + * don't match the current event mask. + */ + for (; runcount; prev = PREV(eventp), runcount--) + if (prev->id == INVALID_EVENT || !(prev->bstate & eventmask)) { + eventp = prev; + } + +#ifdef TRACE + if (_nc_tracing & TRACE_IEVENT) + { + _trace_slot("after mouse event queue compaction:"); + _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d", + (long) (runp - events), + (long) ((eventp - events) + (EV_MAX-1)) % EV_MAX, + runcount); + } + for (ep = runp; ep != eventp; ep = NEXT(ep)) + if (ep->id != INVALID_EVENT) + TR(MY_TRACE, ("_nc_mouse_parse: returning composite mouse event %s at slot %ld", + _tracemouse(ep), + (long) (ep - events))); +#endif /* TRACE */ + + /* after all this, do we have a valid event? */ + return(PREV(eventp)->id != INVALID_EVENT); +} + +static void _nc_mouse_wrap(SCREEN *sp GCC_UNUSED) +/* release mouse -- called by endwin() before shellout/exit */ +{ + TR(MY_TRACE, ("_nc_mouse_wrap() called")); + + switch (mousetype) { + case M_XTERM: + if (eventmask) + mouse_activate(FALSE); + break; +#if USE_GPM_SUPPORT + /* GPM: pass all mouse events to next client */ + case M_GPM: + break; +#endif + } +} + +static void _nc_mouse_resume(SCREEN *sp GCC_UNUSED) +/* re-connect to mouse -- called by doupdate() after shellout */ +{ + TR(MY_TRACE, ("_nc_mouse_resume() called")); + + /* xterm: re-enable reporting */ + if (mousetype == M_XTERM && eventmask) + mouse_activate(TRUE); + + /* GPM: reclaim our event set */ +} + +/************************************************************************** + * + * Mouse interface entry points for the API + * + **************************************************************************/ + +int getmouse(MEVENT *aevent) +/* grab a copy of the current mouse event */ +{ + T((T_CALLED("getmouse(%p)"), aevent)); + + if (aevent && (mousetype != M_NONE)) + { + /* compute the current-event pointer */ + MEVENT *prev = PREV(eventp); + + /* copy the event we find there */ + *aevent = *prev; + + TR(TRACE_IEVENT, ("getmouse: returning event %s from slot %ld", + _tracemouse(prev), + (long) (prev - events))); + + prev->id = INVALID_EVENT; /* so the queue slot becomes free */ + returnCode(OK); + } + returnCode(ERR); +} + +int ungetmouse(MEVENT *aevent) +/* enqueue a synthesized mouse event to be seen by the next wgetch() */ +{ + /* stick the given event in the next-free slot */ + *eventp = *aevent; + + /* bump the next-free pointer into the circular list */ + eventp = NEXT(eventp); + + /* push back the notification event on the keyboard queue */ + return ungetch(KEY_MOUSE); +} + +mmask_t mousemask(mmask_t newmask, mmask_t *oldmask) +/* set the mouse event mask */ +{ + mmask_t result = 0; + + T((T_CALLED("mousemask(%#lx,%p)"), newmask, oldmask)); + + if (oldmask) + *oldmask = eventmask; + + if (!newmask && !initialized) + returnCode(0); + + _nc_mouse_init(); + if ( mousetype != M_NONE ) + { + eventmask = newmask & + (BUTTON_ALT | BUTTON_CTRL | BUTTON_SHIFT + | BUTTON1_PRESSED | BUTTON1_RELEASED | BUTTON1_CLICKED + | BUTTON1_DOUBLE_CLICKED | BUTTON1_TRIPLE_CLICKED + | BUTTON2_PRESSED | BUTTON2_RELEASED | BUTTON2_CLICKED + | BUTTON2_DOUBLE_CLICKED | BUTTON2_TRIPLE_CLICKED + | BUTTON3_PRESSED | BUTTON3_RELEASED | BUTTON3_CLICKED + | BUTTON3_DOUBLE_CLICKED | BUTTON3_TRIPLE_CLICKED); + + mouse_activate(eventmask != 0); + + result = eventmask; + } + + returnCode(result); +} + +bool wenclose(const WINDOW *win, int y, int x) +/* check to see if given window encloses given screen location */ +{ + if (win) + { + y -= win->_yoffset; + return ((win->_begy <= y && + win->_begx <= x && + (win->_begx + win->_maxx) >= x && + (win->_begy + win->_maxy) >= y) ? TRUE : FALSE); + } + return FALSE; +} + +int mouseinterval(int maxclick) +/* set the maximum mouse interval within which to recognize a click */ +{ + int oldval; + + if (SP != 0) { + oldval = SP->_maxclick; + if (maxclick >= 0) + SP->_maxclick = maxclick; + } else { + oldval = DEFAULT_MAXCLICK; + } + + return(oldval); +} + +/* This may be used by other routines to ask for the existence of mouse + support */ +int _nc_has_mouse(void) { + return (mousetype==M_NONE ? 0:1); +} + +bool wmouse_trafo(const WINDOW* win, int* pY, int* pX, bool to_screen) +{ + bool result = FALSE; + + if (win && pY && pX) + { + int y = *pY; int x = *pX; + + if (to_screen) + { + y += win->_begy + win->_yoffset; + x += win->_begx; + if (wenclose(win,y,x)) + result = TRUE; + } + else + { + if (wenclose(win,y,x)) + { + y -= (win->_begy + win->_yoffset); + x -= win->_begx; + result = TRUE; + } + } + if (result) + { + *pX = x; + *pY = y; + } + } + return(result); +} + +/* lib_mouse.c ends here */ diff --git a/contrib/ncurses/ncurses/base/lib_move.c b/contrib/ncurses/ncurses/base/lib_move.c new file mode 100644 index 000000000000..6f5bddff33ea --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_move.c @@ -0,0 +1,63 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_move.c +** +** The routine wmove(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_move.c,v 1.8 1998/02/11 12:13:53 tom Exp $") + +int +wmove(WINDOW *win, int y, int x) +{ + T((T_CALLED("wmove(%p,%d,%d)"), win, y, x)); + + if (win && + x >= 0 && x <= win->_maxx && + y >= 0 && y <= win->_maxy) + { + win->_curx = (short)x; + win->_cury = (short)y; + + win->_flags &= ~_WRAPPED; + win->_flags |= _HASMOVED; + returnCode(OK); + } else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_mvwin.c b/contrib/ncurses/ncurses/base/lib_mvwin.c new file mode 100644 index 000000000000..9774d9f58dfe --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_mvwin.c @@ -0,0 +1,109 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_mvwin.c +** +** The routine mvwin(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_mvwin.c,v 1.7 1998/02/11 12:13:55 tom Exp $") + +int mvwin(WINDOW *win, int by, int bx) +{ + T((T_CALLED("mvwin(%p,%d,%d)"), win, by, bx)); + + if (!win || (win->_flags & _ISPAD)) + returnCode(ERR); + + /* Copying subwindows is allowed, but it is expensive... */ + if (win->_flags & _SUBWIN) { + int err = ERR; + WINDOW *parent = win->_parent; + if (parent) + { /* Now comes the complicated and costly part, you should really + * try to avoid to move subwindows. Because a subwindow shares + * the text buffers with its parent, one can't do a simple + * memmove of the text buffers. One has to create a copy, then + * to relocate the subwindow and then to do a copy. + */ + if ((by - parent->_begy == win->_pary) && + (bx - parent->_begx == win->_parx)) + err=OK; /* we don't actually move */ + else { + WINDOW* clone = dupwin(win); + if (clone) { + /* now we have the clone, so relocate win */ + + werase(win); /* Erase the original place */ + wbkgd(win,parent->_bkgd);/* fill with parents background */ + wsyncup(win); /* Tell the parent(s) */ + + err = mvderwin(win, + by - parent->_begy, + bx - parent->_begx); + if (err!=ERR) { + err = copywin(clone,win, + 0, 0, 0, 0, win->_maxy, win->_maxx, 0); + if (ERR!=err) + wsyncup(win); + } + if (ERR==delwin(clone)) + err=ERR; + } + } + } + returnCode(err); + } + + if (by + win->_maxy > screen_lines - 1 + || bx + win->_maxx > screen_columns - 1 + || by < 0 + || bx < 0) + returnCode(ERR); + + /* + * Whether or not the window is moved, touch the window's contents so + * that a following call to 'wrefresh()' will paint the window at the + * new location. This ensures that if the caller has refreshed another + * window at the same location, that this one will be displayed. + */ + win->_begy = by; + win->_begx = bx; + returnCode(touchwin(win)); +} diff --git a/contrib/ncurses/ncurses/base/lib_newterm.c b/contrib/ncurses/ncurses/base/lib_newterm.c new file mode 100644 index 000000000000..9a4919bf5292 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_newterm.c @@ -0,0 +1,206 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_newterm.c +** +** The newterm() function. +** +*/ + +#include <curses.priv.h> + +#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE) +#define _POSIX_SOURCE +#endif + +#include <term.h> /* clear_screen, cup & friends, cur_term */ + +MODULE_ID("$Id: lib_newterm.c,v 1.41 1999/07/24 20:07:48 tom Exp $") + +#ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */ +#define ONLCR 0 +#endif + +/* + * SVr4/XSI Curses specify that hardware echo is turned off in initscr, and not + * restored during the curses session. The library simulates echo in software. + * (The behavior is unspecified if the application enables hardware echo). + * + * The newterm function also initializes terminal settings, and since initscr + * is supposed to behave as if it calls newterm, we do it here. + */ +static inline int _nc_initscr(void) +{ + /* for extended XPG4 conformance requires cbreak() at this point */ + /* (SVr4 curses does this anyway) */ + cbreak(); + +#ifdef TERMIOS + cur_term->Nttyb.c_lflag &= ~(ECHO|ECHONL); + cur_term->Nttyb.c_iflag &= ~(ICRNL|INLCR|IGNCR); + cur_term->Nttyb.c_oflag &= ~(ONLCR); +#else + cur_term->Nttyb.sg_flags &= ~(ECHO|CRMOD); +#endif + return _nc_set_tty_mode(&cur_term->Nttyb); +} + +/* + * filter() has to be called before either initscr() or newterm(), so there is + * apparently no way to make this flag apply to some terminals and not others, + * aside from possibly delaying a filter() call until some terminals have been + * initialized. + */ +static int filter_mode = FALSE; + +void filter(void) +{ + filter_mode = TRUE; +} + +SCREEN * newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp) +{ +int errret; +int slk_format = _nc_slk_format; +SCREEN* current; +#ifdef TRACE +int t = _nc_getenv_num("NCURSES_TRACE"); + + if (t >= 0) + trace(t); +#endif + + T((T_CALLED("newterm(\"%s\",%p,%p)"), name, ofp, ifp)); + + /* this loads the capability entry, then sets LINES and COLS */ + if (setupterm(name, fileno(ofp), &errret) == ERR) + return 0; + + /* implement filter mode */ + if (filter_mode) { + LINES = 1; + + if (init_tabs != -1) + TABSIZE = init_tabs; + else + TABSIZE = 8; + + T(("TABSIZE = %d", TABSIZE)); + + clear_screen = 0; + cursor_down = parm_down_cursor = 0; + cursor_address = 0; + cursor_up = parm_up_cursor = 0; + row_address = 0; + + cursor_home = carriage_return; + } + + /* If we must simulate soft labels, grab off the line to be used. + We assume that we must simulate, if it is none of the standard + formats (4-4 or 3-2-3) for which there may be some hardware + support. */ + if (num_labels <= 0 || !SLK_STDFMT(slk_format)) + if (slk_format) + { + if (ERR==_nc_ripoffline(-SLK_LINES(slk_format), + _nc_slk_initialize)) + return 0; + } + /* this actually allocates the screen structure, and saves the + * original terminal settings. + */ + current = SP; + _nc_set_screen(0); + if (_nc_setupscreen(LINES, COLS, ofp) == ERR) { + _nc_set_screen(current); + return 0; + } + + /* if the terminal type has real soft labels, set those up */ + if (slk_format && num_labels > 0 && SLK_STDFMT(slk_format)) + _nc_slk_initialize(stdscr, COLS); + + SP->_ifd = fileno(ifp); + SP->_checkfd = fileno(ifp); + typeahead(fileno(ifp)); +#ifdef TERMIOS + SP->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 && + !(cur_term->Ottyb.c_iflag & ISTRIP)); +#else + SP->_use_meta = FALSE; +#endif + SP->_endwin = FALSE; + + /* Check whether we can optimize scrolling under dumb terminals in case + * we do not have any of these capabilities, scrolling optimization + * will be useless. + */ + SP->_scrolling = ((scroll_forward && scroll_reverse) || + ((parm_rindex || parm_insert_line || insert_line) && + (parm_index || parm_delete_line || delete_line))); + + baudrate(); /* sets a field in the SP structure */ + + SP->_keytry = 0; + + /* + * Check for mismatched graphic-rendition capabilities. Most SVr4 + * terminfo trees contain entries that have rmul or rmso equated to + * sgr0 (Solaris curses copes with those entries). We do this only for + * curses, since many termcap applications assume that smso/rmso and + * smul/rmul are paired, and will not function properly if we remove + * rmso or rmul. Curses applications shouldn't be looking at this + * detail. + */ +#define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode)) + SP->_use_rmso = SGR0_TEST(exit_standout_mode); + SP->_use_rmul = SGR0_TEST(exit_underline_mode); + + /* compute movement costs so we can do better move optimization */ + _nc_mvcur_init(); + + /* initialize terminal to a sane state */ + _nc_screen_init(); + + /* Initialize the terminal line settings. */ + _nc_initscr(); + + _nc_signal_handler(TRUE); + + T((T_RETURN("%p"), SP)); + return(SP); +} diff --git a/contrib/ncurses/ncurses/base/lib_newwin.c b/contrib/ncurses/ncurses/base/lib_newwin.c new file mode 100644 index 000000000000..61c0eb3ed548 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_newwin.c @@ -0,0 +1,271 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_newwin.c +** +** The routines newwin(), subwin() and their dependent +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_newwin.c,v 1.20 1998/05/23 23:21:32 Alexander.V.Lukyanov Exp $") + +void _nc_freewin(WINDOW *win) +{ +WINDOWLIST *p, *q; +int i; + + if (win != 0) { + for (p = _nc_windows, q = 0; p != 0; q = p, p = p->next) { + if (p->win == win) { + if (q == 0) + _nc_windows = p->next; + else + q->next = p->next; + free(p); + + if (! (win->_flags & _SUBWIN)) { + for (i = 0; i <= win->_maxy && win->_line[i].text; i++) + free(win->_line[i].text); + } + free(win->_line); + free(win); + + if (win == curscr) curscr = 0; + if (win == stdscr) stdscr = 0; + if (win == newscr) newscr = 0; + + T(("...deleted win=%p", win)); + break; + } + } + } +} + +WINDOW * newwin(int num_lines, int num_columns, int begy, int begx) +{ +WINDOW *win; +chtype *ptr; +int i; + + T((T_CALLED("newwin(%d,%d,%d,%d)"), num_lines, num_columns, begy, begx)); + + if (begy < 0 || begx < 0 || num_lines < 0 || num_columns < 0) + returnWin(0); + + if (num_lines == 0) + num_lines = SP->_lines_avail - begy; + if (num_columns == 0) + num_columns = screen_columns - begx; + + if (num_columns + begx > SP->_columns || num_lines + begy > SP->_lines_avail) + returnWin(0); + + if ((win = _nc_makenew(num_lines, num_columns, begy, begx, 0)) == 0) + returnWin(0); + + for (i = 0; i < num_lines; i++) { + if ((win->_line[i].text = typeCalloc(chtype, (unsigned)num_columns)) == 0) { + _nc_freewin(win); + returnWin(0); + } + for (ptr = win->_line[i].text; ptr < win->_line[i].text + num_columns; ) + *ptr++ = ' '; + } + + T(("newwin: returned window is %p", win)); + + returnWin(win); +} + +WINDOW * derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx) +{ +WINDOW *win; +int i; +int flags = _SUBWIN; + + T((T_CALLED("derwin(%p,%d,%d,%d,%d)"), orig, num_lines, num_columns, begy, begx)); + + /* + ** make sure window fits inside the original one + */ + if ( begy < 0 || begx < 0 || orig == 0 || num_lines < 0 || num_columns < 0) + returnWin(0); + if ( begy + num_lines > orig->_maxy + 1 + || begx + num_columns > orig->_maxx + 1) + returnWin(0); + + if (num_lines == 0) + num_lines = orig->_maxy + 1 - begy; + + if (num_columns == 0) + num_columns = orig->_maxx + 1 - begx; + + if (orig->_flags & _ISPAD) + flags |= _ISPAD; + + if ((win = _nc_makenew(num_lines, num_columns, orig->_begy + begy, orig->_begx + begx, flags)) == 0) + returnWin(0); + + win->_pary = begy; + win->_parx = begx; + win->_attrs = orig->_attrs; + win->_bkgd = orig->_bkgd; + + for (i = 0; i < num_lines; i++) + win->_line[i].text = &orig->_line[begy++].text[begx]; + + win->_parent = orig; + + T(("derwin: returned window is %p", win)); + + returnWin(win); +} + + +WINDOW *subwin(WINDOW *w, int l, int c, int y, int x) +{ + T((T_CALLED("subwin(%p, %d, %d, %d, %d)"), w, l, c, y, x)); + T(("parent has begy = %d, begx = %d", w->_begy, w->_begx)); + + returnWin(derwin(w, l, c, y - w->_begy, x - w->_begx)); +} + +WINDOW * +_nc_makenew(int num_lines, int num_columns, int begy, int begx, int flags) +{ +int i; +WINDOWLIST *wp; +WINDOW *win; +bool is_pad = (flags & _ISPAD); + + T(("_nc_makenew(%d,%d,%d,%d)", num_lines, num_columns, begy, begx)); + + if (num_lines <= 0 || num_columns <= 0) + return 0; + + if ((wp = typeCalloc(WINDOWLIST, 1)) == 0) + return 0; + + if ((win = typeCalloc(WINDOW, 1)) == 0) + return 0; + + if ((win->_line = typeCalloc(struct ldat, ((unsigned)num_lines))) == 0) { + free(win); + return 0; + } + + win->_curx = 0; + win->_cury = 0; + win->_maxy = num_lines - 1; + win->_maxx = num_columns - 1; + win->_begy = begy; + win->_begx = begx; + win->_yoffset = SP->_topstolen; + + win->_flags = flags; + win->_attrs = A_NORMAL; + win->_bkgd = BLANK; + + win->_clear = is_pad ? FALSE : (num_lines == screen_lines && num_columns == screen_columns); + win->_idlok = FALSE; + win->_idcok = TRUE; + win->_scroll = FALSE; + win->_leaveok = FALSE; + win->_use_keypad = FALSE; + win->_delay = -1; + win->_immed = FALSE; + win->_sync = 0; + win->_parx = -1; + win->_pary = -1; + win->_parent = 0; + + win->_regtop = 0; + win->_regbottom = num_lines - 1; + + win->_pad._pad_y = -1; + win->_pad._pad_x = -1; + win->_pad._pad_top = -1; + win->_pad._pad_bottom = -1; + win->_pad._pad_left = -1; + win->_pad._pad_right = -1; + + for (i = 0; i < num_lines; i++) + { + /* + * This used to do + * + * win->_line[i].firstchar = win->_line[i].lastchar = _NOCHANGE; + * + * which marks the whole window unchanged. That's how + * SVr1 curses did it, but SVr4 curses marks the whole new + * window changed. + * + * With the old SVr1-like code, say you have stdscr full of + * characters, then create a new window with newwin(), + * then do a printw(win, "foo ");, the trailing spaces are + * completely ignored by the following refreshes. So, you + * get "foojunkjunk" on the screen instead of "foo " as + * you actually intended. + * + * SVr4 doesn't do this. Instead the spaces are actually written. + * So that's how we want ncurses to behave. + */ + win->_line[i].firstchar = 0; + win->_line[i].lastchar = num_columns-1; + + if_USE_SCROLL_HINTS(win->_line[i].oldindex = i); + } + + if (!is_pad && (begx + num_columns == screen_columns)) { + win->_flags |= _ENDLINE; + + if (begx == 0 && num_lines == screen_lines && begy == 0) + win->_flags |= _FULLWIN; + + if (begy + num_lines == screen_lines) + win->_flags |= _SCROLLWIN; + } + + wp->next = _nc_windows; + wp->win = win; + _nc_windows = wp; + + T((T_CREATE("window %p"), win)); + + return(win); +} diff --git a/contrib/ncurses/ncurses/base/lib_nl.c b/contrib/ncurses/ncurses/base/lib_nl.c new file mode 100644 index 000000000000..d5c426632f5d --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_nl.c @@ -0,0 +1,79 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * nl.c + * + * Routines: + * nl() + * nonl() + * + */ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_nl.c,v 1.3 1998/10/14 15:14:08 Alexander.V.Lukyanov Exp $") + +#ifdef __EMX__ +#include <io.h> +#include <fcntl.h> +#endif + +int nl(void) +{ + T((T_CALLED("nl()"))); + + SP->_nl = TRUE; + +#ifdef __EMX__ + fflush(SP->_ofp); + _fsetmode(SP->_ofp, "t"); +#endif + + returnCode(OK); +} + +int nonl(void) +{ + T((T_CALLED("nonl()"))); + + SP->_nl = FALSE; + +#ifdef __EMX__ + fflush(SP->_ofp); + _fsetmode(SP->_ofp, "b"); +#endif + + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_overlay.c b/contrib/ncurses/ncurses/base/lib_overlay.c new file mode 100644 index 000000000000..db2dce1b79f6 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_overlay.c @@ -0,0 +1,161 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_overlay.c +** +** The routines overlay(), copywin(), and overwrite(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_overlay.c,v 1.12 1998/02/11 12:13:59 tom Exp $") + +static int overlap(const WINDOW *const s, WINDOW *const d, int const flag) +{ +int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol; + + T(("overlap : sby %d, sbx %d, smy %d, smx %d, dby %d, dbx %d, dmy %d, dmx %d", + s->_begy, s->_begx, s->_maxy, s->_maxx, + d->_begy, d->_begx, d->_maxy, d->_maxx)); + + if (!s || !d) + returnCode(ERR); + + sminrow = max(s->_begy, d->_begy) - s->_begy; + smincol = max(s->_begx, d->_begx) - s->_begx; + dminrow = max(s->_begy, d->_begy) - d->_begy; + dmincol = max(s->_begx, d->_begx) - d->_begx; + dmaxrow = min(s->_maxy+s->_begy, d->_maxy+d->_begy) - d->_begy; + dmaxcol = min(s->_maxx+s->_begx, d->_maxx+d->_begx) - d->_begx; + + return(copywin(s, d, + sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, + flag)); +} + +/* +** +** overlay(win1, win2) +** +** +** overlay() writes the overlapping area of win1 behind win2 +** on win2 non-destructively. +** +**/ + +int overlay(const WINDOW *win1, WINDOW *win2) +{ + T((T_CALLED("overlay(%p,%p)"), win1, win2)); + returnCode(overlap(win1, win2, TRUE)); +} + +/* +** +** overwrite(win1, win2) +** +** +** overwrite() writes the overlapping area of win1 behind win2 +** on win2 destructively. +** +**/ + +int overwrite(const WINDOW *win1, WINDOW *win2) +{ + T((T_CALLED("overwrite(%p,%p)"), win1, win2)); + returnCode(overlap(win1, win2, FALSE)); +} + +int copywin(const WINDOW *src, WINDOW *dst, + int sminrow, int smincol, + int dminrow, int dmincol, int dmaxrow, int dmaxcol, + int over) +{ +int sx, sy, dx, dy; +bool touched; +chtype bk = AttrOf(dst->_bkgd); +chtype mask = ~(chtype)((bk&A_COLOR) ? A_COLOR : 0); + + T((T_CALLED("copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)"), + src, dst, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, over)); + + if (!src || !dst) + returnCode(ERR); + + /* make sure rectangle exists in source */ + if ((sminrow + dmaxrow - dminrow) > (src->_maxy + 1) || + (smincol + dmaxcol - dmincol) > (src->_maxx + 1)) { + returnCode(ERR); + } + + T(("rectangle exists in source")); + + /* make sure rectangle fits in destination */ + if (dmaxrow > dst->_maxy || dmaxcol > dst->_maxx) { + returnCode(ERR); + } + + T(("rectangle fits in destination")); + + for (dy = dminrow, sy = sminrow; dy <= dmaxrow; sy++, dy++) { + touched = FALSE; + for(dx=dmincol, sx=smincol; dx <= dmaxcol; sx++, dx++) + { + if (over) + { + if ((TextOf(src->_line[sy].text[sx]) != ' ') && + (dst->_line[dy].text[dx]!=src->_line[sy].text[sx])) + { + dst->_line[dy].text[dx] = + (src->_line[sy].text[sx] & mask) | bk; + touched = TRUE; + } + } + else { + if (dst->_line[dy].text[dx] != src->_line[sy].text[sx]) + { + dst->_line[dy].text[dx] = src->_line[sy].text[sx]; + touched = TRUE; + } + } + } + if (touched) + { + touchline(dst,0,getmaxy(dst)); + } + } + T(("finished copywin")); + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_pad.c b/contrib/ncurses/ncurses/base/lib_pad.c new file mode 100644 index 000000000000..d4e341c05c75 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_pad.c @@ -0,0 +1,280 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * lib_pad.c + * newpad -- create a new pad + * pnoutrefresh -- refresh a pad, no update + * pechochar -- add a char to a pad and refresh + */ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_pad.c,v 1.27 1998/06/28 00:10:16 tom Exp $") + +WINDOW *newpad(int l, int c) +{ +WINDOW *win; +chtype *ptr; +int i; + + T((T_CALLED("newpad(%d, %d)"), l, c)); + + if (l <= 0 || c <= 0) + returnWin(0); + + if ((win = _nc_makenew(l,c,0,0,_ISPAD)) == NULL) + returnWin(0); + + for (i = 0; i < l; i++) { + if_USE_SCROLL_HINTS(win->_line[i].oldindex = _NEWINDEX); + if ((win->_line[i].text = typeCalloc(chtype, ((size_t)c))) == 0) { + _nc_freewin(win); + returnWin(0); + } + for (ptr = win->_line[i].text; ptr < win->_line[i].text + c; ) + *ptr++ = ' '; + } + + returnWin(win); +} + +WINDOW *subpad(WINDOW *orig, int l, int c, int begy, int begx) +{ +WINDOW *win = (WINDOW *)0; + + T((T_CALLED("subpad(%d, %d)"), l, c)); + + if (orig) { + if (!(orig->_flags & _ISPAD) || ((win = derwin(orig, l, c, begy, begx)) == NULL)) + returnWin(0); + } + returnWin(win); +} + +int prefresh(WINDOW *win, int pminrow, int pmincol, + int sminrow, int smincol, int smaxrow, int smaxcol) +{ + T((T_CALLED("prefresh()"))); + if (pnoutrefresh(win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol) != ERR + && doupdate() != ERR) { + returnCode(OK); + } + returnCode(ERR); +} + +int pnoutrefresh(WINDOW *win, int pminrow, int pmincol, + int sminrow, int smincol, int smaxrow, int smaxcol) +{ +const int my_len = 2; /* parameterize the threshold for hardscroll */ +short i, j; +short m, n; +short pmaxrow; +short pmaxcol; +short displaced; +bool wide; + + T((T_CALLED("pnoutrefresh(%p, %d, %d, %d, %d, %d, %d)"), + win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)); + + if (win == 0) + returnCode(ERR); + + if (!(win->_flags & _ISPAD)) + returnCode(ERR); + + /* negative values are interpreted as zero */ + if (pminrow < 0) pminrow = 0; + if (pmincol < 0) pmincol = 0; + if (sminrow < 0) sminrow = 0; + if (smincol < 0) smincol = 0; + + pmaxrow = pminrow + smaxrow - sminrow; + pmaxcol = pmincol + smaxcol - smincol; + + T((" pminrow + smaxrow - sminrow %d, win->_maxy %d", pmaxrow, win->_maxy)); + T((" pmincol + smaxcol - smincol %d, win->_maxx %d", pmaxcol, win->_maxx)); + + /* + * Trim the caller's screen size back to the actual limits. + */ + if (pmaxrow > win->_maxy) { + smaxrow -= (pmaxrow - win->_maxy); + pmaxrow = pminrow + smaxrow - sminrow; + } + if (pmaxcol > win->_maxx) { + smaxcol -= (pmaxcol - win->_maxx); + pmaxcol = pmincol + smaxcol - smincol; + } + + if (smaxrow > screen_lines + || smaxcol > screen_columns + || sminrow > smaxrow + || smincol > smaxcol) + returnCode(ERR); + + T(("pad being refreshed")); + + if (win->_pad._pad_y >= 0) { + displaced = pminrow - win->_pad._pad_y + -(sminrow - win->_pad._pad_top); + T(("pad being shifted by %d line(s)", displaced)); + } else + displaced = 0; + + /* + * For pure efficiency, we'd want to transfer scrolling information + * from the pad to newscr whenever the window is wide enough that + * its update will dominate the cost of the update for the horizontal + * band of newscr that it occupies. Unfortunately, this threshold + * tends to be complex to estimate, and in any case scrolling the + * whole band and rewriting the parts outside win's image would look + * really ugly. So. What we do is consider the pad "wide" if it + * either (a) occupies the whole width of newscr, or (b) occupies + * all but at most one column on either vertical edge of the screen + * (this caters to fussy people who put boxes around full-screen + * windows). Note that changing this formula will not break any code, + * merely change the costs of various update cases. + */ + wide = (smincol < my_len && smaxcol > (newscr->_maxx - my_len)); + + for (i = pminrow, m = sminrow + win->_yoffset; + i <= pmaxrow && m <= newscr->_maxy; + i++, m++) { + register struct ldat *nline = &newscr->_line[m]; + register struct ldat *oline = &win->_line[i]; + + for (j = pmincol, n = smincol; j <= pmaxcol; j++, n++) { + if (oline->text[j] != nline->text[n]) { + nline->text[n] = oline->text[j]; + CHANGED_CELL(nline,n); + } + } + +#if USE_SCROLL_HINTS + if (wide) { + int nind = m + displaced; + if (oline->oldindex < 0 + || nind < sminrow + || nind > smaxrow) { + nind = _NEWINDEX; + } else if (displaced) { + register struct ldat *pline = &curscr->_line[nind]; + for (j = 0; j <= my_len; j++) { + int k = newscr->_maxx - j; + if (pline->text[j] != nline->text[j] + || pline->text[k] != nline->text[k]) { + nind = _NEWINDEX; + break; + } + } + } + + nline->oldindex = nind; + } +#endif /* USE_SCROLL_HINTS */ + oline->firstchar = oline->lastchar = _NOCHANGE; + if_USE_SCROLL_HINTS(oline->oldindex = i); + } + + /* + * Clean up debris from scrolling or resizing the pad, so we do not + * accidentally pick up the index value during the next call to this + * procedure. The only rows that should have an index value are those + * that are displayed during this cycle. + */ +#if USE_SCROLL_HINTS + for (i = pminrow-1; (i >= 0) && (win->_line[i].oldindex >= 0); i--) + win->_line[i].oldindex = _NEWINDEX; + for (i = pmaxrow+1; (i <= win->_maxy) && (win->_line[i].oldindex >= 0); i++) + win->_line[i].oldindex = _NEWINDEX; +#endif + + win->_begx = smincol; + win->_begy = sminrow; + + if (win->_clear) { + win->_clear = FALSE; + newscr->_clear = TRUE; + } + + /* + * Use the pad's current position, if it will be visible. + * If not, don't do anything; it's not an error. + */ + if (win->_leaveok == FALSE + && win->_cury >= pminrow + && win->_curx >= pmincol + && win->_cury <= pmaxrow + && win->_curx <= pmaxcol) { + newscr->_cury = win->_cury - pminrow + win->_begy + win->_yoffset; + newscr->_curx = win->_curx - pmincol + win->_begx; + } + win->_flags &= ~_HASMOVED; + + /* + * Update our cache of the line-numbers that we displayed from the pad. + * We will use this on subsequent calls to this function to derive + * values to stuff into 'oldindex[]' -- for scrolling optimization. + */ + win->_pad._pad_y = pminrow; + win->_pad._pad_x = pmincol; + win->_pad._pad_top = sminrow; + win->_pad._pad_left = smincol; + win->_pad._pad_bottom = smaxrow; + win->_pad._pad_right = smaxcol; + + returnCode(OK); +} + +int pechochar(WINDOW *pad, const chtype ch) +{ + T((T_CALLED("pechochar(%p, %s)"), pad, _tracechtype(ch))); + + if (pad == 0) + returnCode(ERR); + + if (!(pad->_flags & _ISPAD)) + returnCode(wechochar(pad,ch)); + + waddch(pad, ch); + prefresh(pad, pad->_pad._pad_y, + pad->_pad._pad_x, + pad->_pad._pad_top, + pad->_pad._pad_left, + pad->_pad._pad_bottom, + pad->_pad._pad_right); + + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_printw.c b/contrib/ncurses/ncurses/base/lib_printw.c new file mode 100644 index 000000000000..8d28f288d3c1 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_printw.c @@ -0,0 +1,110 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ + +/* +** lib_printw.c +** +** The routines printw(), wprintw() and friends. +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_printw.c,v 1.7 1998/04/11 22:53:44 tom Exp $") + +int printw(NCURSES_CONST char *fmt, ...) +{ + va_list argp; + int code; + + T(("printw(%s,...) called", _nc_visbuf(fmt))); + + va_start(argp, fmt); + code = vwprintw(stdscr, fmt, argp); + va_end(argp); + + return code; +} + +int wprintw(WINDOW *win, NCURSES_CONST char *fmt, ...) +{ + va_list argp; + int code; + + T(("wprintw(%p,%s,...) called", win, _nc_visbuf(fmt))); + + va_start(argp, fmt); + code = vwprintw(win, fmt, argp); + va_end(argp); + + return code; +} + +int mvprintw(int y, int x, NCURSES_CONST char *fmt, ...) +{ + va_list argp; + int code = move(y, x); + + if (code != ERR) { + va_start(argp, fmt); + code = vwprintw(stdscr, fmt, argp); + va_end(argp); + } + return code; +} + +int mvwprintw(WINDOW *win, int y, int x, NCURSES_CONST char *fmt, ...) +{ + va_list argp; + int code = wmove(win, y, x); + + if (code != ERR) { + va_start(argp, fmt); + code = vwprintw(win, fmt, argp); + va_end(argp); + } + return code; +} + +int vwprintw(WINDOW *win, NCURSES_CONST char *fmt, va_list argp) +{ + char *buf = _nc_printf_string(fmt, argp); + int code = ERR; + + if (buf != 0) { + code = waddstr(win, buf); +#if USE_SAFE_SPRINTF + free(buf); +#endif + } + return code; +} diff --git a/contrib/ncurses/ncurses/base/lib_redrawln.c b/contrib/ncurses/ncurses/base/lib_redrawln.c new file mode 100644 index 000000000000..10fda917984e --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_redrawln.c @@ -0,0 +1,69 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ + +/* + * lib_redrawln.c + * + * The routine wredrawln(). + * + */ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_redrawln.c,v 1.7 1998/09/19 20:09:50 Alexander.V.Lukyanov Exp $") + +int wredrawln(WINDOW *win, int beg, int num) +{ + int i; + int end; + size_t len = (win->_maxx + 1) * sizeof(chtype); + + T((T_CALLED("wredrawln(%p,%d,%d)"), win, beg, num)); + + if (beg < 0) + beg = 0; + + if (touchline (win, beg, num) == ERR) + returnCode(ERR); + + end = beg + num; + if (end > win->_maxy + 1) + end = win->_maxy + 1; + + for (i = beg; i < end; i++) + { + memset (curscr->_line[i+win->_begy].text+win->_begx, 0, len); + _nc_make_oldhash(i+win->_begy); + } + + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_refresh.c b/contrib/ncurses/ncurses/base/lib_refresh.c new file mode 100644 index 000000000000..88e3b75a56a1 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_refresh.c @@ -0,0 +1,183 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* + * lib_refresh.c + * + * The routines wrefresh() and wnoutrefresh(). + * + */ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_refresh.c,v 1.24 1999/07/31 11:36:37 juergen Exp $") + +int wrefresh(WINDOW *win) +{ +int code; + + T((T_CALLED("wrefresh(%p)"), win)); + + if (win == curscr) { + curscr->_clear = TRUE; + code = doupdate(); + } else if ((code = wnoutrefresh(win)) == OK) { + if (win->_clear) + newscr->_clear = TRUE; + code = doupdate(); + /* + * Reset the clearok() flag in case it was set for the special + * case in hardscroll.c (if we don't reset it here, we'll get 2 + * refreshes because the flag is copied from stdscr to newscr). + * Resetting the flag shouldn't do any harm, anyway. + */ + win->_clear = FALSE; + } + returnCode(code); +} + +int wnoutrefresh(WINDOW *win) +{ +short limit_x; +short i, j; +short begx; +short begy; +short m, n; +bool wide; + + T((T_CALLED("wnoutrefresh(%p)"), win)); +#ifdef TRACE + if (_nc_tracing & TRACE_UPDATE) + _tracedump("...win", win); +#endif /* TRACE */ + + /* + * This function will break badly if we try to refresh a pad. + */ + if ((win == 0) + || (win->_flags & _ISPAD)) + returnCode(ERR); + + /* put them here so "win == 0" won't break our code */ + begx = win->_begx; + begy = win->_begy; + + newscr->_bkgd = win->_bkgd; + newscr->_attrs = win->_attrs; + + /* merge in change information from all subwindows of this window */ + wsyncdown(win); + + /* + * For pure efficiency, we'd want to transfer scrolling information + * from the window to newscr whenever the window is wide enough that + * its update will dominate the cost of the update for the horizontal + * band of newscr that it occupies. Unfortunately, this threshold + * tends to be complex to estimate, and in any case scrolling the + * whole band and rewriting the parts outside win's image would look + * really ugly. So. What we do is consider the window "wide" if it + * either (a) occupies the whole width of newscr, or (b) occupies + * all but at most one column on either vertical edge of the screen + * (this caters to fussy people who put boxes around full-screen + * windows). Note that changing this formula will not break any code, + * merely change the costs of various update cases. + */ + wide = (begx <= 1 && win->_maxx >= (newscr->_maxx - 1)); + + win->_flags &= ~_HASMOVED; + + /* + * Microtweaking alert! This double loop is one of the genuine + * hot spots in the code. Even gcc doesn't seem to do enough + * common-subexpression chunking to make it really tense, + * so we'll force the issue. + */ + + /* limit(n) */ + limit_x = win->_maxx; + /* limit(j) */ + if (limit_x > win->_maxx) + limit_x = win->_maxx; + + for (i = 0, m = begy + win->_yoffset; + i <= win->_maxy && m <= newscr->_maxy; + i++, m++) { + register struct ldat *nline = &newscr->_line[m]; + register struct ldat *oline = &win->_line[i]; + + if (oline->firstchar != _NOCHANGE) { + int last = oline->lastchar; + + if (last > limit_x) + last = limit_x; + + for (j = oline->firstchar, n = j + begx; j <= last; j++, n++) { + if (oline->text[j] != nline->text[n]) { + nline->text[n] = oline->text[j]; + CHANGED_CELL(nline, n); + } + } + + } + +#if USE_SCROLL_HINTS + if (wide) { + int oind = oline->oldindex; + + nline->oldindex = (oind == _NEWINDEX) ? _NEWINDEX : begy + oind + win->_yoffset; + } +#endif /* USE_SCROLL_HINTS */ + + oline->firstchar = oline->lastchar = _NOCHANGE; + if_USE_SCROLL_HINTS(oline->oldindex = i); + } + + if (win->_clear) { + win->_clear = FALSE; + newscr->_clear = TRUE; + } + + if (! win->_leaveok) { + newscr->_cury = win->_cury + win->_begy + win->_yoffset; + newscr->_curx = win->_curx + win->_begx; + } + newscr->_leaveok = win->_leaveok; + +#ifdef TRACE + if (_nc_tracing & TRACE_UPDATE) + _tracedump("newscr", newscr); +#endif /* TRACE */ + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_restart.c b/contrib/ncurses/ncurses/base/lib_restart.c new file mode 100644 index 000000000000..de0182f42691 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_restart.c @@ -0,0 +1,90 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * Terminfo-only terminal setup routines: + * + * int restartterm(const char *, int, int *) + * TERMINAL *set_curterm(TERMINAL *) + * int del_curterm(TERMINAL *) + */ + +#include <curses.priv.h> + +#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE) +#define _POSIX_SOURCE +#endif + +#include <term.h> /* lines, columns, cur_term */ + +MODULE_ID("$Id: lib_restart.c,v 1.2 1999/07/24 20:10:04 tom Exp $") + +int restartterm(NCURSES_CONST char *termp, int filenum, int *errret) +{ +int saveecho = SP->_echo; +int savecbreak = SP->_cbreak; +int saveraw = SP->_raw; +int savenl = SP->_nl; + + T((T_CALLED("restartterm(%s,%d,%p)"), termp, filenum, errret)); + + setupterm(termp, filenum, errret); + + if (saveecho) + echo(); + else + noecho(); + + if (savecbreak) { + cbreak(); + noraw(); + } else if (saveraw) { + nocbreak(); + raw(); + } else { + nocbreak(); + noraw(); + } + if (savenl) + nl(); + else + nonl(); + + reset_prog_mode(); + +#if USE_SIZECHANGE + _nc_update_screensize(); +#endif + + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_scanw.c b/contrib/ncurses/ncurses/base/lib_scanw.c new file mode 100644 index 000000000000..cc66613ff52f --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_scanw.c @@ -0,0 +1,111 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_scanw.c +** +** The routines scanw(), wscanw() and friends. +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_scanw.c,v 1.8 1998/04/11 22:54:18 tom Exp $") + +#if !HAVE_VSSCANF +#if defined(__QNX__) +extern int vsscanf(const char *str, const char *format, __va_list __arg); +#else +extern int vsscanf(const char *str, const char *format, ...); +#endif +#endif + +int vwscanw(WINDOW *win, NCURSES_CONST char *fmt, va_list argp) +{ +char buf[BUFSIZ]; + + if (wgetnstr(win, buf, sizeof(buf)-1) == ERR) + return(ERR); + + return(vsscanf(buf, fmt, argp)); +} + +int scanw(NCURSES_CONST char *fmt, ...) +{ +int code; +va_list ap; + + T(("scanw(\"%s\",...) called", fmt)); + + va_start(ap, fmt); + code = vwscanw(stdscr, fmt, ap); + va_end(ap); + return (code); +} + +int wscanw(WINDOW *win, NCURSES_CONST char *fmt, ...) +{ +int code; +va_list ap; + + T(("wscanw(%p,\"%s\",...) called", win, fmt)); + + va_start(ap, fmt); + code = vwscanw(win, fmt, ap); + va_end(ap); + return (code); +} + +int mvscanw(int y, int x, NCURSES_CONST char *fmt, ...) +{ +int code; +va_list ap; + + va_start(ap, fmt); + code = (move(y, x) == OK) ? vwscanw(stdscr, fmt, ap) : ERR; + va_end(ap); + return (code); +} + +int mvwscanw(WINDOW *win, int y, int x, NCURSES_CONST char *fmt, ...) +{ +int code; +va_list ap; + + va_start(ap, fmt); + code = (wmove(win, y, x) == OK) ? vwscanw(win, fmt, ap) : ERR; + va_end(ap); + return (code); +} diff --git a/contrib/ncurses/ncurses/base/lib_screen.c b/contrib/ncurses/ncurses/base/lib_screen.c new file mode 100644 index 000000000000..3038393c2266 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_screen.c @@ -0,0 +1,198 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +#include <curses.priv.h> + +#include <sys/stat.h> +#include <time.h> +#include <term.h> /* exit_ca_mode, non_rev_rmcup */ + +MODULE_ID("$Id: lib_screen.c,v 1.15 1999/07/24 20:05:29 tom Exp $") + +static time_t dumptime; + +WINDOW *getwin(FILE *filep) +{ + WINDOW tmp, *nwin; + int n; + + T((T_CALLED("getwin(%p)"), filep)); + + (void) fread(&tmp, sizeof(WINDOW), 1, filep); + if (ferror(filep)) + returnWin(0); + + if ((nwin = newwin(tmp._maxy+1, tmp._maxx+1, 0, 0)) == 0) + returnWin(0); + + /* + * We deliberately do not restore the _parx, _pary, or _parent + * fields, because the window hierarchy within which they + * made sense is probably gone. + */ + nwin->_curx = tmp._curx; + nwin->_cury = tmp._cury; + nwin->_maxy = tmp._maxy; + nwin->_maxx = tmp._maxx; + nwin->_begy = tmp._begy; + nwin->_begx = tmp._begx; + nwin->_yoffset = tmp._yoffset; + nwin->_flags = tmp._flags & ~(_SUBWIN|_ISPAD); + + nwin->_attrs = tmp._attrs; + nwin->_bkgd = tmp._bkgd; + + nwin->_clear = tmp._clear; + nwin->_scroll = tmp._scroll; + nwin->_leaveok = tmp._leaveok; + nwin->_use_keypad = tmp._use_keypad; + nwin->_delay = tmp._delay; + nwin->_immed = tmp._immed; + nwin->_sync = tmp._sync; + + nwin->_regtop = tmp._regtop; + nwin->_regbottom = tmp._regbottom; + + for (n = 0; n < nwin->_maxy + 1; n++) + { + (void) fread(nwin->_line[n].text, + sizeof(chtype), (size_t)(nwin->_maxx + 1), filep); + if (ferror(filep)) + { + delwin(nwin); + returnWin(0); + } + } + touchwin(nwin); + + returnWin(nwin); +} + +int putwin(WINDOW *win, FILE *filep) +{ + int code = ERR; + int n; + + T((T_CALLED("putwin(%p,%p)"), win, filep)); + + if (win) { + (void) fwrite(win, sizeof(WINDOW), 1, filep); + if (ferror(filep)) + returnCode(code); + + for (n = 0; n < win->_maxy + 1; n++) + { + (void) fwrite(win->_line[n].text, + sizeof(chtype), (size_t)(win->_maxx + 1), filep); + if (ferror(filep)) + returnCode(code); + } + code = OK; + } + returnCode(code); +} + +int scr_restore(const char *file) +{ + FILE *fp = 0; + + T((T_CALLED("scr_restore(%s)"), _nc_visbuf(file))); + + if (_nc_access(file, R_OK) < 0 + || (fp = fopen(file, "rb")) == 0) + returnCode(ERR); + else + { + delwin(newscr); + newscr = getwin(fp); + (void) fclose(fp); + returnCode(OK); + } +} + +int scr_dump(const char *file) +{ + FILE *fp = 0; + + T((T_CALLED("scr_dump(%s)"), _nc_visbuf(file))); + + if (_nc_access(file, W_OK) < 0 + || (fp = fopen(file, "wb")) == 0) + returnCode(ERR); + else + { + (void) putwin(newscr, fp); + (void) fclose(fp); + dumptime = time((time_t *)0); + returnCode(OK); + } +} + +int scr_init(const char *file) +{ + FILE *fp = 0; + struct stat stb; + + T((T_CALLED("scr_init(%s)"), _nc_visbuf(file))); + + if (exit_ca_mode && non_rev_rmcup) + returnCode(ERR); + + if (_nc_access(file, R_OK) < 0 + || (fp = fopen(file, "rb")) == 0) + returnCode(ERR); + else if (fstat(STDOUT_FILENO, &stb) || stb.st_mtime > dumptime) + returnCode(ERR); + else + { + delwin(curscr); + curscr = getwin(fp); + (void) fclose(fp); + returnCode(OK); + } +} + +int scr_set(const char *file) +{ + T((T_CALLED("scr_set(%s)"), _nc_visbuf(file))); + + if (scr_init(file) == ERR) + returnCode(ERR); + else + { + delwin(newscr); + newscr = dupwin(curscr); + returnCode(OK); + } +} diff --git a/contrib/ncurses/ncurses/base/lib_scroll.c b/contrib/ncurses/ncurses/base/lib_scroll.c new file mode 100644 index 000000000000..197bb221a07c --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_scroll.c @@ -0,0 +1,118 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_scroll.c +** +** The routine wscrl(win, n). +** positive n scroll the window up (ie. move lines down) +** negative n scroll the window down (ie. move lines up) +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_scroll.c,v 1.16 1998/02/11 12:13:55 tom Exp $") + +void _nc_scroll_window(WINDOW *win, int const n, short const top, short const bottom, chtype blank) +{ +int line, j; +size_t to_copy = (size_t)(sizeof(chtype) * (win->_maxx + 1)); + + TR(TRACE_MOVE, ("_nc_scroll_window(%p, %d, %d, %d)", win, n, top,bottom)); + + /* + * This used to do a line-text pointer-shuffle instead of text copies. + * That (a) doesn't work when the window is derived and doesn't have + * its own storage, (b) doesn't save you a lot on modern machines + * anyway. Your typical memcpy implementations are coded in + * assembler using a tight BLT loop; for the size of copies we're + * talking here, the total execution time is dominated by the one-time + * setup cost. So there is no point in trying to be excessively + * clever -- esr. + */ + + /* shift n lines downwards */ + if (n < 0) { + for (line = bottom; line >= top-n; line--) { + memcpy(win->_line[line].text, + win->_line[line+n].text, + to_copy); + if_USE_SCROLL_HINTS(win->_line[line].oldindex = win->_line[line+n].oldindex); + } + for (line = top; line < top-n; line++) { + for (j = 0; j <= win->_maxx; j ++) + win->_line[line].text[j] = blank; + if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX); + } + } + + /* shift n lines upwards */ + if (n > 0) { + for (line = top; line <= bottom-n; line++) { + memcpy(win->_line[line].text, + win->_line[line+n].text, + to_copy); + if_USE_SCROLL_HINTS(win->_line[line].oldindex = win->_line[line+n].oldindex); + } + for (line = bottom; line > bottom-n; line--) { + for (j = 0; j <= win->_maxx; j ++) + win->_line[line].text[j] = blank; + if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX); + } + } + touchline(win, top, bottom-top+1); +} + +int +wscrl(WINDOW *win, int n) +{ + T((T_CALLED("wscrl(%p,%d)"), win, n)); + + if (!win || !win->_scroll) + returnCode(ERR); + + if (n == 0) + returnCode(OK); + + if ((n > (win->_regbottom - win->_regtop)) || + (-n > (win->_regbottom - win->_regtop))) + returnCode(ERR); + + _nc_scroll_window(win, n, win->_regtop, win->_regbottom, _nc_background(win)); + + _nc_synchook(win); + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_scrollok.c b/contrib/ncurses/ncurses/base/lib_scrollok.c new file mode 100644 index 000000000000..f24eb8ebb0c6 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_scrollok.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_scrollok.c +** +** The routine scrollok. +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_scrollok.c,v 1.2 1998/02/11 12:14:01 tom Exp $") + +int scrollok(WINDOW *win, bool flag) +{ + T((T_CALLED("scrollok(%p,%d)"), win, flag)); + + if (win) { + win->_scroll = flag; + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_scrreg.c b/contrib/ncurses/ncurses/base/lib_scrreg.c new file mode 100644 index 000000000000..ddeab2498bfd --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_scrreg.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_scrreg.c +** +** The routine wsetscrreg(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_scrreg.c,v 1.7 1998/02/11 12:13:53 tom Exp $") + +int wsetscrreg(WINDOW *win, int top, int bottom) +{ + T((T_CALLED("wsetscrreg(%p,%d,%d)"), win, top, bottom)); + + if (win && + top >= 0 && top <= win->_maxy && + bottom >= 0 && bottom <= win->_maxy && + bottom > top) + { + win->_regtop = (short)top; + win->_regbottom = (short)bottom; + + returnCode(OK); + } else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_set_term.c b/contrib/ncurses/ncurses/base/lib_set_term.c new file mode 100644 index 000000000000..443236cf9cda --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_set_term.c @@ -0,0 +1,315 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_set_term.c +** +** The routine set_term(). +** +*/ + +#include <curses.priv.h> + +#include <term.h> /* cur_term */ + +MODULE_ID("$Id: lib_set_term.c,v 1.46 1999/07/24 20:05:49 tom Exp $") + +SCREEN * set_term(SCREEN *screenp) +{ +SCREEN *oldSP; + + T((T_CALLED("set_term(%p)"), screenp)); + + oldSP = SP; + _nc_set_screen(screenp); + + set_curterm(SP->_term); + curscr = SP->_curscr; + newscr = SP->_newscr; + stdscr = SP->_stdscr; + COLORS = SP->_color_count; + COLOR_PAIRS = SP->_pair_count; + memcpy(acs_map, SP->_acs_map, sizeof(chtype)*ACS_LEN); + + T((T_RETURN("%p"), oldSP)); + return(oldSP); +} + +static void _nc_free_keytry(struct tries *kt) +{ + if (kt != 0) { + _nc_free_keytry(kt->child); + _nc_free_keytry(kt->sibling); + free(kt); + } +} + +/* + * Free the storage associated with the given SCREEN sp. + */ +void delscreen(SCREEN *sp) +{ + SCREEN **scan = &_nc_screen_chain; + + T((T_CALLED("delscreen(%p)"), sp)); + + while(*scan) + { + if (*scan == sp) + { + *scan = sp->_next_screen; + break; + } + scan = &(*scan)->_next_screen; + } + + _nc_freewin(sp->_curscr); + _nc_freewin(sp->_newscr); + _nc_freewin(sp->_stdscr); + _nc_free_keytry(sp->_keytry); + _nc_free_keytry(sp->_key_ok); + + FreeIfNeeded(sp->_color_table); + FreeIfNeeded(sp->_color_pairs); + + FreeIfNeeded(sp->oldhash); + FreeIfNeeded(sp->newhash); + + del_curterm(sp->_term); + + free(sp); + + /* + * If this was the current screen, reset everything that the + * application might try to use (except cur_term, which may have + * multiple references in different screens). + */ + if (sp == SP) { + curscr = 0; + newscr = 0; + stdscr = 0; + COLORS = 0; + COLOR_PAIRS = 0; + _nc_set_screen(0); + } + returnVoid; +} + +static ripoff_t rippedoff[5]; +static ripoff_t *rsp = rippedoff; +#define N_RIPS SIZEOF(rippedoff) + +static bool no_mouse_event (SCREEN *sp GCC_UNUSED) { return FALSE; } +static bool no_mouse_inline(SCREEN *sp GCC_UNUSED) { return FALSE; } +static bool no_mouse_parse (int code GCC_UNUSED) { return TRUE; } +static void no_mouse_resume(SCREEN *sp GCC_UNUSED) { } +static void no_mouse_wrap (SCREEN *sp GCC_UNUSED) { } + +int _nc_setupscreen(short slines, short const scolumns, FILE *output) +/* OS-independent screen initializations */ +{ +int bottom_stolen = 0; +size_t i; + + assert(SP==0); /* has been reset in newterm() ! */ + if (!_nc_alloc_screen()) + return ERR; + + SP->_next_screen = _nc_screen_chain; + _nc_screen_chain = SP; + + _nc_set_buffer(output, TRUE); + SP->_term = cur_term; + SP->_lines = slines; + SP->_lines_avail = slines; + SP->_columns = scolumns; + SP->_cursrow = -1; + SP->_curscol = -1; + SP->_nl = TRUE; + SP->_raw = FALSE; + SP->_cbreak = 0; + SP->_echo = TRUE; + SP->_fifohead = -1; + SP->_endwin = TRUE; + SP->_ofp = output; + SP->_cursor = -1; /* cannot know real cursor shape */ +#ifdef NCURSES_NO_PADDING + SP->_no_padding = getenv("NCURSES_NO_PADDING") != 0; +#endif + + SP->_maxclick = DEFAULT_MAXCLICK; + SP->_mouse_event = no_mouse_event; + SP->_mouse_inline = no_mouse_inline; + SP->_mouse_parse = no_mouse_parse; + SP->_mouse_resume = no_mouse_resume; + SP->_mouse_wrap = no_mouse_wrap; + SP->_mouse_fd = -1; + + /* initialize the panel hooks */ + SP->_panelHook.top_panel = (struct panel*)0; + SP->_panelHook.bottom_panel = (struct panel*)0; + SP->_panelHook.stdscr_pseudo_panel = (struct panel*)0; + + /* + * If we've no magic cookie support, we suppress attributes that xmc + * would affect, i.e., the attributes that affect the rendition of a + * space. Note that this impacts the alternate character set mapping + * as well. + */ + if (magic_cookie_glitch > 0) { + + SP->_xmc_triggers = termattrs() & ( + A_ALTCHARSET | + A_BLINK | + A_BOLD | + A_REVERSE | + A_STANDOUT | + A_UNDERLINE + ); + SP->_xmc_suppress = SP->_xmc_triggers & (chtype)~(A_BOLD); + + T(("magic cookie attributes %s", _traceattr(SP->_xmc_suppress))); +#if USE_XMC_SUPPORT + /* + * To keep this simple, suppress all of the optimization hooks + * except for clear_screen and the cursor addressing. + */ + clr_eol = 0; + clr_eos = 0; + set_attributes = 0; +#else + magic_cookie_glitch = -1; + acs_chars = 0; +#endif + } + _nc_init_acs(); + memcpy(SP->_acs_map, acs_map, sizeof(chtype)*ACS_LEN); + + _nc_idcok = TRUE; + _nc_idlok = FALSE; + + _nc_windows = 0; /* no windows yet */ + + SP->oldhash = 0; + SP->newhash = 0; + + T(("creating newscr")); + if ((newscr = newwin(slines, scolumns, 0, 0)) == 0) + return ERR; + + T(("creating curscr")); + if ((curscr = newwin(slines, scolumns, 0, 0)) == 0) + return ERR; + + SP->_newscr = newscr; + SP->_curscr = curscr; +#if USE_SIZECHANGE + SP->_resize = resizeterm; +#endif + + newscr->_clear = TRUE; + curscr->_clear = FALSE; + + for (i=0, rsp = rippedoff; rsp->line && (i < N_RIPS); rsp++, i++) { + if (rsp->hook) { + WINDOW *w; + int count = (rsp->line < 0) ? -rsp->line : rsp->line; + + if (rsp->line < 0) { + w = newwin(count,scolumns,SP->_lines_avail - count,0); + if (w) { + rsp->w = w; + rsp->hook(w, scolumns); + bottom_stolen += count; + } + else + return ERR; + } else { + w = newwin(count,scolumns, 0, 0); + if (w) { + rsp->w = w; + rsp->hook(w, scolumns); + SP->_topstolen += count; + } + else + return ERR; + } + SP->_lines_avail -= count; + } + rsp->line = 0; + } + /* reset the stack */ + rsp = rippedoff; + + T(("creating stdscr")); + assert ((SP->_lines_avail + SP->_topstolen + bottom_stolen) == slines); + if ((stdscr = newwin(LINES = SP->_lines_avail, scolumns, 0, 0)) == 0) + return ERR; + SP->_stdscr = stdscr; + + def_shell_mode(); + def_prog_mode(); + + return OK; +} + +/* The internal implementation interprets line as the number of + lines to rip off from the top or bottom. + */ +int +_nc_ripoffline(int line, int (*init)(WINDOW *,int)) +{ + if (line == 0) + return(OK); + + if (rsp >= rippedoff + N_RIPS) + return(ERR); + + rsp->line = line; + rsp->hook = init; + rsp->w = 0; + rsp++; + + return(OK); +} + +int +ripoffline(int line, int (*init)(WINDOW *, int)) +{ + T((T_CALLED("ripoffline(%d,%p)"), line, init)); + + if (line == 0) + returnCode(OK); + + returnCode(_nc_ripoffline ((line<0) ? -1 : 1, init)); +} diff --git a/contrib/ncurses/ncurses/base/lib_slk.c b/contrib/ncurses/ncurses/base/lib_slk.c new file mode 100644 index 000000000000..9b9b09a4d064 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slk.c @@ -0,0 +1,214 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slk.c + * Soft key routines. + */ + +#include <curses.priv.h> + +#include <ctype.h> +#include <term.h> /* num_labels, label_*, plab_norm */ + +MODULE_ID("$Id: lib_slk.c,v 1.16 1999/03/03 23:44:22 juergen Exp $") + +/* + * We'd like to move these into the screen context structure, but cannot, + * because slk_init() is called before initscr()/newterm(). + */ +int _nc_slk_format; /* one more than format specified in slk_init() */ + +/* + * Paint the info line for the PC style SLK emulation. + * + */ +static void +slk_paint_info(WINDOW *win) +{ + if (win && SP->slk_format==4) + { + int i; + + mvwhline (win,0,0,0,getmaxx(win)); + wmove (win,0,0); + + for (i = 0; i < SP->_slk->maxlab; i++) { + if (win && SP->slk_format==4) + { + mvwaddch(win,0,SP->_slk->ent[i].x,'F'); + if (i<9) + waddch(win,'1'+i); + else + { + waddch(win,'1'); + waddch(win,'0' + (i-9)); + } + } + } + } +} + +/* + * Initialize soft labels. + * Called from newterm() + */ +int +_nc_slk_initialize(WINDOW *stwin, int cols) +{ +int i, x; +int res = OK; +char *p; + + T(("slk_initialize()")); + + if (SP->_slk) + { /* we did this already, so simply return */ + return(OK); + } + else + if ((SP->_slk = typeCalloc(SLK, 1)) == 0) + return(ERR); + + SP->_slk->ent = NULL; + SP->_slk->buffer = NULL; + SP->_slk->attr = A_STANDOUT; + + SP->_slk->maxlab = (num_labels > 0) ? + num_labels : MAX_SKEY(_nc_slk_format); + SP->_slk->maxlen = (num_labels > 0) ? + label_width * label_height : MAX_SKEY_LEN(_nc_slk_format); + SP->_slk->labcnt = (SP->_slk->maxlab < MAX_SKEY(_nc_slk_format)) ? + MAX_SKEY(_nc_slk_format) : SP->_slk->maxlab; + + SP->_slk->ent = typeCalloc(slk_ent, SP->_slk->labcnt); + if (SP->_slk->ent == NULL) + goto exception; + + p = SP->_slk->buffer = (char*) calloc(2*SP->_slk->labcnt,(1+SP->_slk->maxlen)); + if (SP->_slk->buffer == NULL) + goto exception; + + for (i = 0; i < SP->_slk->labcnt; i++) { + SP->_slk->ent[i].text = p; + p += (1 + SP->_slk->maxlen); + SP->_slk->ent[i].form_text = p; + p += (1 + SP->_slk->maxlen); + memset(SP->_slk->ent[i].form_text, ' ', (unsigned)(SP->_slk->maxlen)); + SP->_slk->ent[i].visible = (i < SP->_slk->maxlab); + } + if (_nc_slk_format >= 3) /* PC style */ + { + int gap = (cols - 3 * (3 + 4*SP->_slk->maxlen))/2; + + if (gap < 1) + gap = 1; + + for (i = x = 0; i < SP->_slk->maxlab; i++) { + SP->_slk->ent[i].x = x; + x += SP->_slk->maxlen; + x += (i==3 || i==7) ? gap : 1; + } + if (_nc_slk_format == 4) + slk_paint_info (stwin); + } + else { + if (_nc_slk_format == 2) { /* 4-4 */ + int gap = cols - (SP->_slk->maxlab * SP->_slk->maxlen) - 6; + + if (gap < 1) + gap = 1; + for (i = x = 0; i < SP->_slk->maxlab; i++) { + SP->_slk->ent[i].x = x; + x += SP->_slk->maxlen; + x += (i == 3) ? gap : 1; + } + } + else + { + if (_nc_slk_format == 1) { /* 1 -> 3-2-3 */ + int gap = (cols - (SP->_slk->maxlab * SP->_slk->maxlen) - 5) / 2; + + if (gap < 1) + gap = 1; + for (i = x = 0; i < SP->_slk->maxlab; i++) { + SP->_slk->ent[i].x = x; + x += SP->_slk->maxlen; + x += (i == 2 || i == 4) ? gap : 1; + } + } + else + goto exception; + } + } + SP->_slk->dirty = TRUE; + if ((SP->_slk->win = stwin) == NULL) + { + exception: + if (SP->_slk) + { + FreeIfNeeded(SP->_slk->buffer); + FreeIfNeeded(SP->_slk->ent); + free(SP->_slk); + SP->_slk = (SLK*)0; + res = (ERR); + } + } + + /* We now reset the format so that the next newterm has again + * per default no SLK keys and may call slk_init again to + * define a new layout. (juergen 03-Mar-1999) + */ + SP->slk_format = _nc_slk_format; + _nc_slk_format = 0; + return(res); +} + + +/* + * Restore the soft labels on the screen. + */ +int +slk_restore(void) +{ + T((T_CALLED("slk_restore()"))); + + if (SP->_slk == NULL) + return(ERR); + SP->_slk->hidden = FALSE; + SP->_slk->dirty = TRUE; + /* we have to repaint info line eventually */ + slk_paint_info(SP->_slk->win); + + returnCode(slk_refresh()); +} diff --git a/contrib/ncurses/ncurses/base/lib_slkatr_set.c b/contrib/ncurses/ncurses/base/lib_slkatr_set.c new file mode 100644 index 000000000000..0695d186bb5d --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkatr_set.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1998 * + ****************************************************************************/ + +/* + * lib_slkatr_set.c + * Soft key routines. + * Set the labels attributes + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slkatr_set.c,v 1.3 1999/05/16 17:13:59 juergen Exp $") + +int +slk_attr_set(const attr_t attr, short color_pair_number, void* opts) +{ + T((T_CALLED("slk_attr_set(%s,%d)"), _traceattr(attr), color_pair_number)); + + if (SP!=0 && SP->_slk!=0 && !opts && + color_pair_number>=0 && color_pair_number<COLOR_PAIRS) + { + SP->_slk->attr = attr; + toggle_attr_on(SP->_slk->attr,COLOR_PAIR(color_pair_number)); + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_slkatrof.c b/contrib/ncurses/ncurses/base/lib_slkatrof.c new file mode 100644 index 000000000000..5e4f5f5593a3 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkatrof.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slkatrof.c + * Soft key routines. + * Switch off labels attributes + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slkatrof.c,v 1.4 1998/03/11 19:26:07 juergen Exp $") + +int +slk_attroff(const chtype attr) +{ + T((T_CALLED("slk_attroff(%s)"), _traceattr(attr))); + + if (SP!=0 && SP->_slk!=0) + { + toggle_attr_off(SP->_slk->attr,attr); + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_slkatron.c b/contrib/ncurses/ncurses/base/lib_slkatron.c new file mode 100644 index 000000000000..a24886522cde --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkatron.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slkatron.c + * Soft key routines. + * Switch on labels attributes + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slkatron.c,v 1.4 1998/03/11 19:26:07 juergen Exp $") + +int +slk_attron(const chtype attr) +{ + T((T_CALLED("slk_attron(%s)"), _traceattr(attr))); + + if (SP!=0 && SP->_slk!=0) + { + toggle_attr_on(SP->_slk->attr,attr); + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_slkatrset.c b/contrib/ncurses/ncurses/base/lib_slkatrset.c new file mode 100644 index 000000000000..391c7ffe8cb7 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkatrset.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slkatrset.c + * Soft key routines. + * Set the labels attributes + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slkatrset.c,v 1.4 1998/03/11 19:26:01 juergen Exp $") + +int +slk_attrset(const chtype attr) +{ + T((T_CALLED("slk_attrset(%s)"), _traceattr(attr))); + + if (SP!=0 && SP->_slk!=0) + { + SP->_slk->attr = attr; + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_slkattr.c b/contrib/ncurses/ncurses/base/lib_slkattr.c new file mode 100644 index 000000000000..a13240324e51 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkattr.c @@ -0,0 +1,54 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slkattr.c + * Soft key routines. + * Fetch the labels attributes + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slkattr.c,v 1.3 1998/02/11 12:13:56 tom Exp $") + +attr_t +slk_attr(void) +{ + T((T_CALLED("slk_attr()"))); + + if (SP!=0 && SP->_slk!=0) + { + returnAttr(SP->_slk->attr); + } + else + returnAttr(0); +} diff --git a/contrib/ncurses/ncurses/base/lib_slkclear.c b/contrib/ncurses/ncurses/base/lib_slkclear.c new file mode 100644 index 000000000000..ac6e414beaa2 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkclear.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slkclear.c + * Soft key routines. + * Remove soft labels from the screen. + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slkclear.c,v 1.4 1999/03/03 23:44:22 juergen Exp $") + +int +slk_clear(void) +{ + T((T_CALLED("slk_clear()"))); + + if (SP == NULL || SP->_slk == NULL) + returnCode(ERR); + SP->_slk->hidden = TRUE; + /* For simulated SLK's it's looks much more natural to + inherit those attributes from the standard screen */ + SP->_slk->win->_bkgd = stdscr->_bkgd; + SP->_slk->win->_attrs = stdscr->_attrs; + if (SP->_slk->win == stdscr) { + returnCode(OK); + } + else { + werase(SP->_slk->win); + returnCode(wrefresh(SP->_slk->win)); + } +} diff --git a/contrib/ncurses/ncurses/base/lib_slkcolor.c b/contrib/ncurses/ncurses/base/lib_slkcolor.c new file mode 100644 index 000000000000..3728808f9b6c --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkcolor.c @@ -0,0 +1,54 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1998 * + ****************************************************************************/ + +/* + * lib_slkcolor.c + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slkcolor.c,v 1.5 1999/05/16 17:14:13 juergen Exp $") + +int +slk_color(short color_pair_number) +{ + T((T_CALLED("slk_color(%d)"), color_pair_number)); + + if (SP!=0 && SP->_slk!=0 && + color_pair_number>=0 && color_pair_number<COLOR_PAIRS) + { + T(("... current %ld", (long) PAIR_NUMBER(SP->_slk->attr))); + toggle_attr_on(SP->_slk->attr,COLOR_PAIR(color_pair_number)); + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_slkinit.c b/contrib/ncurses/ncurses/base/lib_slkinit.c new file mode 100644 index 000000000000..708442604d91 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkinit.c @@ -0,0 +1,51 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slkinit.c + * Soft key routines. + * Initialize soft labels. Called by the user before initscr(). + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slkinit.c,v 1.3 1998/02/11 12:13:56 tom Exp $") + +int +slk_init(int format) +{ + T((T_CALLED("slk_init(%d)"), format)); + if (format < 0 || format > 3) + returnCode(ERR); + _nc_slk_format = 1 + format; + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_slklab.c b/contrib/ncurses/ncurses/base/lib_slklab.c new file mode 100644 index 000000000000..03039ad696ca --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slklab.c @@ -0,0 +1,51 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slklab.c + * Soft key routines. + * Fetch the label text. + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slklab.c,v 1.4 1998/02/11 12:13:54 tom Exp $") + +char* +slk_label(int n) +{ + T((T_CALLED("slk_label(%d)"), n)); + + if (SP == NULL || SP->_slk == NULL || n < 1 || n > SP->_slk->labcnt) + returnPtr(0); + returnPtr(SP->_slk->ent[n-1].text); +} diff --git a/contrib/ncurses/ncurses/base/lib_slkrefr.c b/contrib/ncurses/ncurses/base/lib_slkrefr.c new file mode 100644 index 000000000000..ee3c91dbee67 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkrefr.c @@ -0,0 +1,126 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slkrefr.c + * Write SLK window to the (virtual) screen. + */ +#include <curses.priv.h> +#include <term.h> /* num_labels, label_*, plab_norm */ + +MODULE_ID("$Id: lib_slkrefr.c,v 1.8 1999/03/14 00:10:27 Alexander.V.Lukyanov Exp $") + +/* + * Write the soft labels to the soft-key window. + */ +static void +slk_intern_refresh(SLK *slk) +{ +int i; +int fmt = SP->slk_format; + + for (i = 0; i < slk->labcnt; i++) { + if (slk->dirty || slk->ent[i].dirty) { + if (slk->ent[i].visible) { + if (num_labels > 0 && SLK_STDFMT(fmt)) + { + if (i < num_labels) { + TPUTS_TRACE("plab_norm"); + putp(tparm(plab_norm, i+1, slk->ent[i].form_text)); + } + } + else + { + wmove(slk->win,SLK_LINES(fmt)-1,slk->ent[i].x); + if (SP && SP->_slk) + wattrset(slk->win,SP->_slk->attr); + waddnstr(slk->win,slk->ent[i].form_text, + MAX_SKEY_LEN(fmt)); + /* if we simulate SLK's, it's looking much more + natural to use the current ATTRIBUTE also + for the label window */ + wattrset(slk->win,stdscr->_attrs); + } + } + slk->ent[i].dirty = FALSE; + } + } + slk->dirty = FALSE; + + if (num_labels > 0) { + if (slk->hidden) + { + TPUTS_TRACE("label_off"); + putp(label_off); + } + else + { + TPUTS_TRACE("label_on"); + putp(label_on); + } + } +} + +/* + * Refresh the soft labels. + */ +int +slk_noutrefresh(void) +{ + T((T_CALLED("slk_noutrefresh()"))); + + if (SP == NULL || SP->_slk == NULL) + returnCode(ERR); + if (SP->_slk->hidden) + returnCode(OK); + slk_intern_refresh(SP->_slk); + + returnCode(wnoutrefresh(SP->_slk->win)); +} + +/* + * Refresh the soft labels. + */ +int +slk_refresh(void) +{ + T((T_CALLED("slk_refresh()"))); + + if (SP == NULL || SP->_slk == NULL) + returnCode(ERR); + if (SP->_slk->hidden) + returnCode(OK); + slk_intern_refresh(SP->_slk); + + returnCode(wrefresh(SP->_slk->win)); +} diff --git a/contrib/ncurses/ncurses/base/lib_slkset.c b/contrib/ncurses/ncurses/base/lib_slkset.c new file mode 100644 index 000000000000..27471add77fa --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkset.c @@ -0,0 +1,95 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slkset.c + * Set soft label text. + */ +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("$Id: lib_slkset.c,v 1.3 1998/02/11 12:13:56 tom Exp $") + +int +slk_set(int i, const char *astr, int format) +{ +SLK *slk = SP->_slk; +size_t len; +const char *str = astr; +const char *p; + + T((T_CALLED("slk_set(%d, \"%s\", %d)"), i, str, format)); + + if (slk == NULL || i < 1 || i > slk->labcnt || format < 0 || format > 2) + returnCode(ERR); + if (str == NULL) + str = ""; + + while (isspace(*str)) str++; /* skip over leading spaces */ + p = str; + while (isprint(*p)) p++; /* The first non-print stops */ + + --i; /* Adjust numbering of labels */ + + len = (size_t)(p - str); + if (len > (unsigned)slk->maxlen) + len = slk->maxlen; + if (len==0) + slk->ent[i].text[0] = 0; + else + (void) strncpy(slk->ent[i].text, str, len); + memset(slk->ent[i].form_text,' ', (unsigned)slk->maxlen); + slk->ent[i].text[slk->maxlen] = 0; + /* len = strlen(slk->ent[i].text); */ + + switch(format) { + case 0: /* left-justified */ + memcpy(slk->ent[i].form_text, + slk->ent[i].text, + len); + break; + case 1: /* centered */ + memcpy(slk->ent[i].form_text+(slk->maxlen - len)/2, + slk->ent[i].text, + len); + break; + case 2: /* right-justified */ + memcpy(slk->ent[i].form_text+ slk->maxlen - len, + slk->ent[i].text, + len); + break; + } + slk->ent[i].form_text[slk->maxlen] = 0; + slk->ent[i].dirty = TRUE; + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_slktouch.c b/contrib/ncurses/ncurses/base/lib_slktouch.c new file mode 100644 index 000000000000..c2829aed0e18 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slktouch.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slktouch.c + * Soft key routines. + * Force the code to believe that the soft keys have been changed. + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slktouch.c,v 1.3 1998/02/11 12:13:56 tom Exp $") + +int +slk_touch(void) +{ + T((T_CALLED("slk_touch()"))); + + if (SP == NULL || SP->_slk == NULL) + returnCode(ERR); + SP->_slk->dirty = TRUE; + + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_touch.c b/contrib/ncurses/ncurses/base/lib_touch.c new file mode 100644 index 000000000000..7ce863d06f10 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_touch.c @@ -0,0 +1,87 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_touch.c +** +** The routines untouchwin(), +** wtouchln(), +** is_linetouched() +** is_wintouched(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_touch.c,v 1.6 1998/04/11 22:55:02 tom Exp $") + +bool is_linetouched(WINDOW *win, int line) +{ + T((T_CALLED("is_linetouched(%p,%d)"), win, line)); + + /* XSI doesn't define any error */ + if (!win || (line > win->_maxy) || (line < 0)) + returnCode(ERR); + + returnCode(win->_line[line].firstchar != _NOCHANGE ? TRUE : FALSE); +} + +bool is_wintouched(WINDOW *win) +{ +int i; + + T((T_CALLED("is_wintouched(%p)"), win)); + + if (win) + for (i = 0; i <= win->_maxy; i++) + if (win->_line[i].firstchar != _NOCHANGE) + returnCode(TRUE); + returnCode(FALSE); +} + +int wtouchln(WINDOW *win, int y, int n, int changed) +{ +int i; + + T((T_CALLED("wtouchln(%p,%d,%d,%d)"), win, y, n, changed)); + + if (!win || (n<0) || (y<0) || (y>win->_maxy)) + returnCode(ERR); + + for (i = y; i < y+n; i++) { + if (i>win->_maxy) break; + win->_line[i].firstchar = changed ? 0 : _NOCHANGE; + win->_line[i].lastchar = changed ? win->_maxx : _NOCHANGE; + } + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_ungetch.c b/contrib/ncurses/ncurses/base/lib_ungetch.c new file mode 100644 index 000000000000..5fdfb47d490f --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_ungetch.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_ungetch.c +** +** The routine ungetch(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_ungetch.c,v 1.2 1998/02/11 12:13:56 tom Exp $") + +#include <fifo_defs.h> + +#ifdef TRACE +void _nc_fifo_dump(void) +{ +int i; + T(("head = %d, tail = %d, peek = %d", head, tail, peek)); + for (i = 0; i < 10; i++) + T(("char %d = %s", i, _trace_key(SP->_fifo[i]))); +} +#endif /* TRACE */ + +int ungetch(int ch) +{ + if (tail == -1) + return ERR; + if (head == -1) { + head = 0; + t_inc() + peek = tail; /* no raw keys */ + } else + h_dec(); + + SP->_fifo[head] = ch; + T(("ungetch %#x ok", ch)); +#ifdef TRACE + if (_nc_tracing & TRACE_IEVENT) _nc_fifo_dump(); +#endif + return OK; +} diff --git a/contrib/ncurses/ncurses/base/lib_vline.c b/contrib/ncurses/ncurses/base/lib_vline.c new file mode 100644 index 000000000000..007ef55cd3ba --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_vline.c @@ -0,0 +1,77 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_vline.c +** +** The routine wvline(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_vline.c,v 1.4 1998/06/28 00:10:12 tom Exp $") + +int wvline(WINDOW *win, chtype ch, int n) +{ +int code = ERR; +short row, col; +short end; + + T((T_CALLED("wvline(%p,%s,%d)"), win, _tracechtype(ch), n)); + + if (win) { + row = win->_cury; + col = win->_curx; + end = row + n - 1; + if (end > win->_maxy) + end = win->_maxy; + + if (ch == 0) + ch = ACS_VLINE; + ch = _nc_render(win, ch); + + while(end >= row) { + struct ldat *line = &(win->_line[end]); + line->text[col] = ch; + CHANGED_CELL(line, col); + end--; + } + + _nc_synchook(win); + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_wattroff.c b/contrib/ncurses/ncurses/base/lib_wattroff.c new file mode 100644 index 000000000000..a6c9f0f1804e --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_wattroff.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_wattroff.c +** +** The routine wattr_off(). +** +*/ + +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("$Id: lib_wattroff.c,v 1.4 1998/05/10 12:02:11 tom Exp $") + +int wattr_off(WINDOW *win, NCURSES_CONST attr_t at, void *opts GCC_UNUSED) +{ + T((T_CALLED("wattr_off(%p,%s)"), win, _traceattr(at))); + if (win) { + T(("... current %s", _traceattr(win->_attrs))); + toggle_attr_off(win->_attrs,at); + returnCode(OK); + } else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_wattron.c b/contrib/ncurses/ncurses/base/lib_wattron.c new file mode 100644 index 000000000000..a951c576fa44 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_wattron.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_wattron.c +** +** The routines wattr_on(). +** +*/ + +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("$Id: lib_wattron.c,v 1.4 1998/05/10 12:02:28 tom Exp $") + +int wattr_on(WINDOW *win, NCURSES_CONST attr_t at, void *opts GCC_UNUSED) +{ + T((T_CALLED("wattr_on(%p,%s)"), win, _traceattr(at))); + if (win) { + T(("... current %s", _traceattr(win->_attrs))); + toggle_attr_on(win->_attrs,at); + returnCode(OK); + } else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_winch.c b/contrib/ncurses/ncurses/base/lib_winch.c new file mode 100644 index 000000000000..119c731ebe3b --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_winch.c @@ -0,0 +1,52 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1998 * + ****************************************************************************/ + +/* +** lib_winch.c +** +** The routine winch(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_winch.c,v 1.1 1998/11/14 22:06:09 tom Exp $") + +chtype winch(WINDOW *win) +{ + T((T_CALLED("winch(%p)"), win)); + if (win != 0) { + returnCode(win->_line[win->_cury].text[win->_curx]); + } else { + returnCode(0); + } +} diff --git a/contrib/ncurses/ncurses/base/lib_window.c b/contrib/ncurses/ncurses/base/lib_window.c new file mode 100644 index 000000000000..5eae9b1a57fb --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_window.c @@ -0,0 +1,221 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_window.c +** +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_window.c,v 1.13 1998/06/28 00:10:59 tom Exp $") + +void _nc_synchook(WINDOW *win) +/* hook to be called after each window change */ +{ + if (win->_immed) wrefresh(win); + if (win->_sync) wsyncup(win); +} + +int mvderwin(WINDOW *win, int y, int x) +/* move a derived window */ +{ + WINDOW *orig; + int i; + + T((T_CALLED("mvderwin(%p,%d,%d)"), win, y, x)); + + if (win && (orig = win->_parent)) + { + if (win->_parx==x && win->_pary==y) + returnCode(OK); + if (x<0 || y<0) + returnCode(ERR); + if ( (x+getmaxx(win) > getmaxx(orig)) || + (y+getmaxy(win) > getmaxy(orig)) ) + returnCode(ERR); + } + else + returnCode(ERR); + wsyncup(win); + win->_parx = x; + win->_pary = y; + for(i=0;i<getmaxy(win);i++) + win->_line[i].text = &(orig->_line[y++].text[x]); + returnCode(OK); +} + +int syncok(WINDOW *win, bool bf) +/* enable/disable automatic wsyncup() on each change to window */ +{ + T((T_CALLED("syncok(%p,%d)"), win, bf)); + + if (win) { + win->_sync = bf; + returnCode(OK); + } else + returnCode(ERR); +} + +void wsyncup(WINDOW *win) +/* mark changed every cell in win's ancestors that is changed in win */ +/* Rewritten by J. Pfeifer, 1-Apr-96 (don't even think that...) */ +{ + WINDOW *wp; + + if (win && win->_parent) + for (wp = win; wp->_parent; wp = wp->_parent) + { + int y; + WINDOW *pp = wp->_parent; + + assert((wp->_pary <= pp->_maxy) && + ((wp->_pary+wp->_maxy) <= pp->_maxy)); + + for (y = 0; y <= wp->_maxy; y++) + { + int left = wp->_line[y].firstchar; + if (left >= 0) /* line is touched */ + { + struct ldat *line = &(pp->_line[wp->_pary + y]); + /* left & right character in parent window coordinates */ + int right = wp->_line[y].lastchar + wp->_parx; + left += wp->_parx; + + CHANGED_RANGE(line, left, right); + } + } + } +} + +void wsyncdown(WINDOW *win) +/* mark changed every cell in win that is changed in any of its ancestors */ +/* Rewritten by J. Pfeifer, 1-Apr-96 (don't even think that...) */ +{ + if (win && win->_parent) + { + WINDOW *pp = win->_parent; + int y; + + /* This recursion guarantees, that the changes are propagated down- + wards from the root to our direct parent. */ + wsyncdown(pp); + + /* and now we only have to propagate the changes from our direct + parent, if there are any. */ + assert((win->_pary <= pp->_maxy) && + ((win->_pary + win->_maxy) <= pp->_maxy)); + + for (y = 0; y <= win->_maxy; y++) + { + if (pp->_line[win->_pary + y].firstchar >= 0) /* parent changed */ + { + struct ldat *line = &(win->_line[y]); + /* left and right character in child coordinates */ + int left = pp->_line[win->_pary + y].firstchar - win->_parx; + int right = pp->_line[win->_pary + y].lastchar - win->_parx; + /* The change maybe outside the childs range */ + if (left<0) + left = 0; + if (right > win->_maxx) + right = win->_maxx; + CHANGED_RANGE(line, left, right); + } + } + } +} + +void wcursyncup(WINDOW *win) +/* sync the cursor in all derived windows to its value in the base window */ +{ + WINDOW *wp; + for( wp = win; wp && wp->_parent; wp = wp->_parent ) { + wmove( wp->_parent, wp->_pary + wp->_cury, wp->_parx + wp->_curx ); + } +} + +WINDOW *dupwin(WINDOW *win) +/* make an exact duplicate of the given window */ +{ +WINDOW *nwin; +size_t linesize; +int i; + + T((T_CALLED("dupwin(%p)"), win)); + + if ((win==NULL) || + ((nwin = newwin(win->_maxy + 1, win->_maxx + 1, win->_begy, win->_begx)) == NULL)) + returnWin(0); + + nwin->_curx = win->_curx; + nwin->_cury = win->_cury; + nwin->_maxy = win->_maxy; + nwin->_maxx = win->_maxx; + nwin->_begy = win->_begy; + nwin->_begx = win->_begx; + nwin->_yoffset = win->_yoffset; + + nwin->_flags = win->_flags & ~_SUBWIN; + /* Due to the use of newwin(), the clone is not a subwindow. + * The text is really copied into the clone. + */ + + nwin->_attrs = win->_attrs; + nwin->_bkgd = win->_bkgd; + + nwin->_clear = win->_clear; + nwin->_scroll = win->_scroll; + nwin->_leaveok = win->_leaveok; + nwin->_use_keypad = win->_use_keypad; + nwin->_delay = win->_delay; + nwin->_immed = win->_immed; + nwin->_sync = win->_sync; + + nwin->_parx = 0; + nwin->_pary = 0; + nwin->_parent = (WINDOW*)0; + /* See above: the clone isn't a subwindow! */ + + nwin->_regtop = win->_regtop; + nwin->_regbottom = win->_regbottom; + + linesize = (win->_maxx + 1) * sizeof(chtype); + for (i = 0; i <= nwin->_maxy; i++) { + memcpy(nwin->_line[i].text, win->_line[i].text, linesize); + nwin->_line[i].firstchar = win->_line[i].firstchar; + nwin->_line[i].lastchar = win->_line[i].lastchar; + } + + returnWin(nwin); +} diff --git a/contrib/ncurses/ncurses/base/memmove.c b/contrib/ncurses/ncurses/base/memmove.c new file mode 100644 index 000000000000..55a410632f98 --- /dev/null +++ b/contrib/ncurses/ncurses/base/memmove.c @@ -0,0 +1,63 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: memmove.c,v 1.2 1999/02/27 19:55:57 tom Exp $") + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1998 * + ****************************************************************************/ + +#if USE_MY_MEMMOVE +#define DST ((char *)s1) +#define SRC ((const char *)s2) +void * _nc_memmove(void * s1, const void * s2, size_t n) +{ + if (n != 0) { + if ((DST+n > SRC) && (SRC+n > DST)) { + static char *bfr; + static size_t length; + register size_t j; + if (length < n) { + length = (n * 3) / 2; + bfr = typeRealloc(char,length,bfr); + } + for (j = 0; j < n; j++) + bfr[j] = SRC[j]; + SRC = bfr; + } + while (n-- != 0) + DST[n] = SRC[n]; + } + return s1; +} +#else +extern void _nc_memmove(void); /* quiet's gcc warning */ +void _nc_memmove(void) { } /* nonempty for strict ANSI compilers */ +#endif /* USE_MY_MEMMOVE */ diff --git a/contrib/ncurses/ncurses/base/nc_panel.c b/contrib/ncurses/ncurses/base/nc_panel.c new file mode 100644 index 000000000000..536aab385dfd --- /dev/null +++ b/contrib/ncurses/ncurses/base/nc_panel.c @@ -0,0 +1,41 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: nc_panel.c,v 1.2 1998/02/11 12:13:56 tom Exp $") + +struct panelhook* +_nc_panelhook(void) +{ + return (SP ? &(SP->_panelHook) : NULL); +} diff --git a/contrib/ncurses/ncurses/base/resizeterm.c b/contrib/ncurses/ncurses/base/resizeterm.c new file mode 100644 index 000000000000..860355024cc3 --- /dev/null +++ b/contrib/ncurses/ncurses/base/resizeterm.c @@ -0,0 +1,121 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 * + ****************************************************************************/ + +/* + * This is an extension to the curses library. It provides callers with a hook + * into the NCURSES data to resize windows, primarily for use by programs + * running in an X Window terminal (e.g., xterm). I abstracted this module + * from my application library for NCURSES because it must be compiled with + * the private data structures -- T.Dickey 1995/7/4. + */ + +#include <curses.priv.h> +#include <term.h> + +MODULE_ID("$Id: resizeterm.c,v 1.7 1998/09/19 19:27:43 Alexander.V.Lukyanov Exp $") + +/* + * This function reallocates NCURSES window structures. It is invoked in + * response to a SIGWINCH interrupt. Other user-defined windows may also need + * to be reallocated. + * + * Because this performs memory allocation, it should not (in general) be + * invoked directly from the signal handler. + */ +int +resizeterm(int ToLines, int ToCols) +{ + int stolen = screen_lines - SP->_lines_avail; + int bottom = screen_lines + SP->_topstolen - stolen; + + T((T_CALLED("resizeterm(%d,%d) old(%d,%d)"), + ToLines, ToCols, + screen_lines, screen_columns)); + + SP->_sig_winch = FALSE; + + if (ToLines != screen_lines + || ToCols != screen_columns) { + WINDOWLIST *wp; + +#if USE_SIGWINCH + ungetch(KEY_RESIZE); /* so application can know this */ + clearok(curscr, TRUE); /* screen contents are unknown */ +#endif + + for (wp = _nc_windows; wp != 0; wp = wp->next) { + WINDOW *win = wp->win; + int myLines = win->_maxy + 1; + int myCols = win->_maxx + 1; + + /* pads aren't treated this way */ + if (win->_flags & _ISPAD) + continue; + + if (win->_begy >= bottom) { + win->_begy += (ToLines - screen_lines); + } else { + if (myLines == screen_lines - stolen + && ToLines != screen_lines) + myLines = ToLines - stolen; + else + if (myLines == screen_lines + && ToLines != screen_lines) + myLines = ToLines; + } + + if (myCols == screen_columns + && ToCols != screen_columns) + myCols = ToCols; + + if (wresize(win, myLines, myCols) != OK) + returnCode(ERR); + } + + screen_lines = lines = ToLines; + screen_columns = columns = ToCols; + + SP->_lines_avail = lines - stolen; + + if (SP->oldhash) { FreeAndNull(SP->oldhash); } + if (SP->newhash) { FreeAndNull(SP->newhash); } + } + + /* + * Always update LINES, to allow for call from lib_doupdate.c which + * needs to have the count adjusted by the stolen (ripped off) lines. + */ + LINES = ToLines - stolen; + COLS = ToCols; + + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/safe_sprintf.c b/contrib/ncurses/ncurses/base/safe_sprintf.c new file mode 100644 index 000000000000..0809225cd94c --- /dev/null +++ b/contrib/ncurses/ncurses/base/safe_sprintf.c @@ -0,0 +1,243 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ + +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("$Id: safe_sprintf.c,v 1.10 1999/02/27 19:56:37 tom Exp $") + +#if USE_SAFE_SPRINTF + +typedef enum { Flags, Width, Prec, Type, Format } PRINTF; + +#define VA_INTGR(type) ival = va_arg(ap, type) +#define VA_FLOAT(type) fval = va_arg(ap, type) +#define VA_POINT(type) pval = (void *)va_arg(ap, type) + +/* + * Scan a variable-argument list for printf to determine the number of + * characters that would be emitted. + */ +static int +_nc_printf_length(const char *fmt, va_list ap) +{ + size_t length = BUFSIZ; + char *buffer; + char *format; + int len = 0; + + if (fmt == 0 || *fmt == '\0') + return -1; + if ((format = typeMalloc(char, strlen(fmt)+1)) == 0) + return -1; + if ((buffer = typeMalloc(char, length)) == 0) { + free(format); + return -1; + } + + while (*fmt != '\0') { + if (*fmt == '%') { + static char dummy[] = ""; + PRINTF state = Flags; + char *pval = dummy; /* avoid const-cast */ + double fval = 0.0; + int done = FALSE; + int ival = 0; + int prec = -1; + int type = 0; + int used = 0; + int width = -1; + size_t f = 0; + + format[f++] = *fmt; + while (*++fmt != '\0' && len >= 0 && !done) { + format[f++] = *fmt; + + if (isdigit(*fmt)) { + int num = *fmt - '0'; + if (state == Flags && num != 0) + state = Width; + if (state == Width) { + if (width < 0) + width = 0; + width = (width * 10) + num; + } else if (state == Prec) { + if (prec < 0) + prec = 0; + prec = (prec * 10) + num; + } + } else if (*fmt == '*') { + VA_INTGR(int); + if (state == Flags) + state = Width; + if (state == Width) { + width = ival; + } else if (state == Prec) { + prec = ival; + } + sprintf(&format[--f], "%d", ival); + f = strlen(format); + } else if (isalpha(*fmt)) { + done = TRUE; + switch (*fmt) { + case 'Z': /* FALLTHRU */ + case 'h': /* FALLTHRU */ + case 'l': /* FALLTHRU */ + case 'L': /* FALLTHRU */ + done = FALSE; + type = *fmt; + break; + case 'i': /* FALLTHRU */ + case 'd': /* FALLTHRU */ + case 'u': /* FALLTHRU */ + case 'x': /* FALLTHRU */ + case 'X': /* FALLTHRU */ + if (type == 'l') + VA_INTGR(long); + else if (type == 'Z') + VA_INTGR(size_t); + else + VA_INTGR(int); + used = 'i'; + break; + case 'f': /* FALLTHRU */ + case 'e': /* FALLTHRU */ + case 'E': /* FALLTHRU */ + case 'g': /* FALLTHRU */ + case 'G': /* FALLTHRU */ + if (type == 'L') + VA_FLOAT(long double); + else + VA_FLOAT(double); + used = 'f'; + break; + case 'c': + VA_INTGR(int); + used = 'i'; + break; + case 's': + VA_POINT(char *); + if (prec < 0) + prec = strlen(pval); + if (prec > (int)length) { + length = length + prec; + buffer = typeRealloc(char, length, buffer); + if (buffer == 0) { + free(format); + return -1; + } + } + used = 'p'; + break; + case 'p': + VA_POINT(void *); + used = 'p'; + break; + case 'n': + VA_POINT(int *); + used = 0; + break; + default: + break; + } + } else if (*fmt == '.') { + state = Prec; + } else if (*fmt == '%') { + done = TRUE; + used = 'p'; + } + } + format[f] = '\0'; + switch (used) { + case 'i': + sprintf(buffer, format, ival); + break; + case 'f': + sprintf(buffer, format, fval); + break; + default: + sprintf(buffer, format, pval); + break; + } + len += (int)strlen(buffer); + } else { + fmt++; + len++; + } + } + + free(buffer); + free(format); + return len; +} +#endif + +/* + * Wrapper for vsprintf that allocates a buffer big enough to hold the result. + */ +char * +_nc_printf_string(const char *fmt, va_list ap) +{ +#if USE_SAFE_SPRINTF + char *buf = 0; + int len = _nc_printf_length(fmt, ap); + + if (len > 0) { + if ((buf = typeMalloc(char, len+1)) == 0) + return(0); + vsprintf(buf, fmt, ap); + } +#else + static int rows, cols; + static char *buf; + static size_t len; + + if (screen_lines > rows || screen_columns > cols) { + if (screen_lines > rows) rows = screen_lines; + if (screen_columns > cols) cols = screen_columns; + len = (rows * (cols + 1)) + 1; + buf = typeRealloc(char, len, buf); + if (buf == 0) { + return(0); + } + } + + if (buf != 0) { +# if HAVE_VSNPRINTF + vsnprintf(buf, len, fmt, ap); /* GNU extension */ +# else + vsprintf(buf, fmt, ap); /* ANSI */ +# endif + } +#endif + return buf; +} diff --git a/contrib/ncurses/ncurses/base/sigaction.c b/contrib/ncurses/ncurses/base/sigaction.c new file mode 100644 index 000000000000..ab1e569fae6a --- /dev/null +++ b/contrib/ncurses/ncurses/base/sigaction.c @@ -0,0 +1,106 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +#include <curses.priv.h> + +#include <signal.h> +#include <SigAction.h> + +/* This file provides sigaction() emulation using sigvec() */ +/* Use only if this is non POSIX system */ + +#if !HAVE_SIGACTION && HAVE_SIGVEC + +MODULE_ID("$Id: sigaction.c,v 1.9 1999/06/19 23:05:16 tom Exp $") + +int +sigaction (int sig, sigaction_t * sigact, sigaction_t * osigact) +{ + return sigvec(sig, sigact, osigact); +} + +int +sigemptyset (sigset_t * mask) +{ + *mask = 0; + return 0; +} + +int +sigprocmask (int mode, sigset_t * mask, sigset_t * omask) +{ + sigset_t current = sigsetmask(0); + + if (omask) *omask = current; + + if (mode==SIG_BLOCK) + current |= *mask; + else if (mode==SIG_UNBLOCK) + current &= ~*mask; + else if (mode==SIG_SETMASK) + current = *mask; + + sigsetmask(current); + return 0; +} + +int +sigsuspend (sigset_t * mask) +{ + return sigpause (*mask); +} + +int +sigdelset (sigset_t * mask, int sig) +{ + *mask &= ~sigmask (sig); + return 0; +} + +int +sigaddset (sigset_t * mask, int sig) +{ + *mask |= sigmask (sig); + return 0; +} + +int +sigismember (sigset_t * mask, int sig) +{ + return (*mask & sigmask (sig)) != 0; +} + +#else +extern void _nc_sigaction(void); /* quiet's gcc warning */ +void _nc_sigaction(void) { } /* nonempty for strict ANSI compilers */ +#endif diff --git a/contrib/ncurses/ncurses/base/tries.c b/contrib/ncurses/ncurses/base/tries.c new file mode 100644 index 000000000000..3c396529d654 --- /dev/null +++ b/contrib/ncurses/ncurses/base/tries.c @@ -0,0 +1,138 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ + +/* +** tries.c +** +** Functions to manage the tree of partial-completions for keycodes. +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: tries.c,v 1.12 1999/03/01 23:23:59 tom Exp $") + +/* + * Expand a keycode into the string that it corresponds to, returning null if + * no match was found, otherwise allocating a string of the result. + */ +char *_nc_expand_try(struct tries *tree, unsigned short code, int *count, size_t len) +{ + struct tries *ptr = tree; + char *result = 0; + + if (code != 0) { + while (ptr != 0) { + if ((result = _nc_expand_try(ptr->child, code, count, len + 1)) != 0) { + break; + } + if (ptr->value == code) { + *count -= 1; + if (*count == -1) { + result = typeCalloc(char, len+2); + break; + } + } + ptr = ptr->sibling; + } + } + if (result != 0) { + if ((result[len] = ptr->ch) == 0) + *((unsigned char *)(result+len)) = 128; +#ifdef TRACE + if (len == 0) + _tracef("expand_key %s %s", _trace_key(code), _nc_visbuf(result)); +#endif + } + return result; +} + +/* + * Remove a code from the specified tree, freeing the unused nodes. Returns + * true if the code was found/removed. + */ +int _nc_remove_key(struct tries **tree, unsigned short code) +{ + T((T_CALLED("_nc_remove_key(%p,%d)"), tree, code)); + + if (code == 0) + returnCode(FALSE); + + while (*tree != 0) { + if (_nc_remove_key(&(*tree)->child, code)) { + returnCode(TRUE); + } + if ((*tree)->value == code) { + if((*tree)->child) { + /* don't cut the whole sub-tree */ + (*tree)->value = 0; + } else { + struct tries *to_free = *tree; + *tree = (*tree)->sibling; + free(to_free); + } + returnCode(TRUE); + } + tree = &(*tree)->sibling; + } + returnCode(FALSE); +} + +/* + * Remove a string from the specified tree, freeing the unused nodes. Returns + * true if the string was found/removed. + */ +int _nc_remove_string(struct tries **tree, char *string) +{ + T((T_CALLED("_nc_remove_string(%p,%s)"), tree, _nc_visbuf(string))); + + if (string == 0 || *string == 0) + returnCode(FALSE); + + while (*tree != 0) { + if ((unsigned char)(*tree)->ch == (unsigned char)*string) { + if (string[1] != 0) + returnCode(_nc_remove_string(&(*tree)->child, string+1)); + if((*tree)->child) { + /* don't cut the whole sub-tree */ + (*tree)->value = 0; + } else { + struct tries *to_free = *tree; + *tree = (*tree)->sibling; + free(to_free); + } + returnCode(TRUE); + } + tree = &(*tree)->sibling; + } + returnCode(FALSE); +} diff --git a/contrib/ncurses/ncurses/base/vsscanf.c b/contrib/ncurses/ncurses/base/vsscanf.c new file mode 100644 index 000000000000..ac2bf9f2e783 --- /dev/null +++ b/contrib/ncurses/ncurses/base/vsscanf.c @@ -0,0 +1,47 @@ +/* + * This function is needed to support vwscanw + */ + +#include <curses.priv.h> + +#if !HAVE_VSSCANF + +MODULE_ID("$Id: vsscanf.c,v 1.10 1996/12/21 14:24:06 tom Exp $") + +#if defined(_IOREAD) && defined(_NFILE) +/*VARARGS2*/ +int vsscanf(const char *str, const char *format, va_list ap) +{ + /* + * This code should work on anything descended from AT&T SVr1. + */ + FILE strbuf; + + strbuf._flag = _IOREAD; + strbuf._ptr = strbuf._base = (unsigned char*)str; + strbuf._cnt = strlen(str); + strbuf._file = _NFILE; + +#if HAVE_VFSCANF + return(vfscanf(&strbuf, format, ap)); +#else + return(_doscan(&strbuf, format, ap)); +#endif +} +#else +/*VARARGS2*/ +int vsscanf(const char *str, const char *format, va_list ap) +{ + /* + * You don't have a native vsscanf(3), and you don't have System-V + * compatible stdio internals. You're probably using a BSD + * older than 4.4 or a really old Linux. You lose. Upgrade + * to a current C library to win. + */ + return -1; /* not implemented */ +} +#endif +#else +extern void _nc_vsscanf(void); /* quiet's gcc warning */ +void _nc_vsscanf(void) { } /* nonempty for strict ANSI compilers */ +#endif /* !HAVE_VSSCANF */ diff --git a/contrib/ncurses/ncurses/base/wresize.c b/contrib/ncurses/ncurses/base/wresize.c new file mode 100644 index 000000000000..1b91476cbfd3 --- /dev/null +++ b/contrib/ncurses/ncurses/base/wresize.c @@ -0,0 +1,166 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: wresize.c,v 1.12 1999/02/27 18:57:31 tom Exp $") + +/* + * Reallocate a curses WINDOW struct to either shrink or grow to the specified + * new lines/columns. If it grows, the new character cells are filled with + * blanks. The application is responsible for repainting the blank area. + */ + +#define DOALLOC(p,t,n) typeRealloc(t, n, p) +#define ld_ALLOC(p,n) DOALLOC(p,struct ldat,n) +#define c_ALLOC(p,n) DOALLOC(p,chtype,n) + +int +wresize(WINDOW *win, int ToLines, int ToCols) +{ + register int row; + int size_x, size_y; + struct ldat *pline; + chtype blank; + +#ifdef TRACE + T((T_CALLED("wresize(%p,%d,%d)"), win, ToLines, ToCols)); + if (win) { + TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)", + win->_begy, win->_begx, + win->_maxy, win->_maxx, + win->_regtop, win->_regbottom)); + if (_nc_tracing & TRACE_UPDATE) + _tracedump("...before", win); + } +#endif + + if (!win || --ToLines < 0 || --ToCols < 0) + returnCode(ERR); + + size_x = win->_maxx; + size_y = win->_maxy; + + if (ToLines == size_y + && ToCols == size_x) + returnCode(OK); + + pline = (win->_flags & _SUBWIN) ? win->_parent->_line : 0; + + /* + * If the number of lines has changed, adjust the size of the overall + * vector: + */ + if (ToLines != size_y) { + if (! (win->_flags & _SUBWIN)) { + for (row = ToLines+1; row <= size_y; row++) + free((char *)(win->_line[row].text)); + } + + win->_line = ld_ALLOC(win->_line, ToLines+1); + if (win->_line == 0) + returnCode(ERR); + + for (row = size_y+1; row <= ToLines; row++) { + win->_line[row].text = 0; + win->_line[row].firstchar = 0; + win->_line[row].lastchar = ToCols; + if ((win->_flags & _SUBWIN)) { + win->_line[row].text = + &pline[win->_begy + row].text[win->_begx]; + } + } + } + + /* + * Adjust the width of the columns: + */ + blank = _nc_background(win); + for (row = 0; row <= ToLines; row++) { + chtype *s = win->_line[row].text; + int begin = (s == 0) ? 0 : size_x + 1; + int end = ToCols; + + if_USE_SCROLL_HINTS(win->_line[row].oldindex = row); + + if (ToCols != size_x || s == 0) { + if (! (win->_flags & _SUBWIN)) { + win->_line[row].text = s = c_ALLOC(s, ToCols+1); + if (win->_line[row].text == 0) + returnCode(ERR); + } else if (s == 0) { + win->_line[row].text = s = + &pline[win->_begy + row].text[win->_begx]; + } + + if (end >= begin) { /* growing */ + if (win->_line[row].firstchar < begin) + win->_line[row].firstchar = begin; + win->_line[row].lastchar = ToCols; + do { + s[end] = blank; + } while (--end >= begin); + } else { /* shrinking */ + win->_line[row].firstchar = 0; + win->_line[row].lastchar = ToCols; + } + } + } + + /* + * Finally, adjust the parameters showing screen size and cursor + * position: + */ + win->_maxx = ToCols; + win->_maxy = ToLines; + + if (win->_regtop > win->_maxy) + win->_regtop = win->_maxy; + if (win->_regbottom > win->_maxy + || win->_regbottom == size_y) + win->_regbottom = win->_maxy; + + if (win->_curx > win->_maxx) + win->_curx = win->_maxx; + if (win->_cury > win->_maxy) + win->_cury = win->_maxy; + +#ifdef TRACE + TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)", + win->_begy, win->_begx, + win->_maxy, win->_maxx, + win->_regtop, win->_regbottom)); + if (_nc_tracing & TRACE_UPDATE) + _tracedump("...after:", win); +#endif + returnCode(OK); +} |